X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/21a5a890b3010e591e139724d5c6f555df4481f9..47d7cdffdd2d2c04067a5088eaeff67add53dde3:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 4c551b2c3..6800daefb 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -103,18 +104,6 @@ namespace { const int CurrentDolphinVersion = 200; }; -/* - * Menu shown when pressing the configure-button in the toolbar. - */ -class ToolBarMenu : public KMenu -{ -public: - ToolBarMenu(QWidget* parent); - virtual ~ToolBarMenu(); -protected: - virtual void showEvent(QShowEvent* event); -}; - /* * Remembers the tab configuration if a tab has been closed. * Each closed tab can be restored by the menu @@ -139,8 +128,7 @@ DolphinMainWindow::DolphinMainWindow() : m_actionHandler(0), m_remoteEncoding(0), m_settingsDialog(), - m_toolBarSpacer(0), - m_openToolBarMenuButton(0), + m_controlButton(0), m_updateToolBarTimer(0), m_lastHandleUrlStatJob(0), m_searchDockIsTemporaryVisible(false) @@ -263,7 +251,7 @@ DolphinMainWindow::DolphinMainWindow() : QAction* showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar)); showMenuBarAction->setChecked(showMenu); // workaround for bug #171080 if (!showMenu) { - createToolBarMenuButton(); + createControlButton(); } } @@ -344,29 +332,23 @@ void DolphinMainWindow::showCommand(CommandType command) DolphinStatusBar* statusBar = m_activeViewContainer->statusBar(); switch (command) { case KIO::FileUndoManager::Copy: - statusBar->setMessage(i18nc("@info:status", "Successfully copied."), - DolphinStatusBar::OperationCompleted); + statusBar->setText(i18nc("@info:status", "Successfully copied.")); break; case KIO::FileUndoManager::Move: - statusBar->setMessage(i18nc("@info:status", "Successfully moved."), - DolphinStatusBar::OperationCompleted); + statusBar->setText(i18nc("@info:status", "Successfully moved.")); break; case KIO::FileUndoManager::Link: - statusBar->setMessage(i18nc("@info:status", "Successfully linked."), - DolphinStatusBar::OperationCompleted); + statusBar->setText(i18nc("@info:status", "Successfully linked.")); break; case KIO::FileUndoManager::Trash: - statusBar->setMessage(i18nc("@info:status", "Successfully moved to trash."), - DolphinStatusBar::OperationCompleted); + statusBar->setText(i18nc("@info:status", "Successfully moved to trash.")); break; case KIO::FileUndoManager::Rename: - statusBar->setMessage(i18nc("@info:status", "Successfully renamed."), - DolphinStatusBar::OperationCompleted); + statusBar->setText(i18nc("@info:status", "Successfully renamed.")); break; case KIO::FileUndoManager::Mkdir: - statusBar->setMessage(i18nc("@info:status", "Created folder."), - DolphinStatusBar::OperationCompleted); + statusBar->setText(i18nc("@info:status", "Created folder.")); break; default: @@ -742,10 +724,7 @@ void DolphinMainWindow::quit() void DolphinMainWindow::showErrorMessage(const QString& message) { - if (!message.isEmpty()) { - DolphinStatusBar* statusBar = m_activeViewContainer->statusBar(); - statusBar->setMessage(message, DolphinStatusBar::Error); - } + m_activeViewContainer->showMessage(message, DolphinViewContainer::Error); } void DolphinMainWindow::slotUndoAvailable(bool available) @@ -1093,9 +1072,9 @@ void DolphinMainWindow::toggleShowMenuBar() const bool visible = menuBar()->isVisible(); menuBar()->setVisible(!visible); if (visible) { - createToolBarMenuButton(); + createControlButton(); } else { - deleteToolBarMenuButton(); + deleteControlButton(); } } @@ -1306,11 +1285,14 @@ void DolphinMainWindow::handleUrl(const KUrl& url) } else if (KProtocolManager::supportsListing(url)) { // stat the URL to see if it is a dir or not m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo); + if (m_lastHandleUrlStatJob->ui()) { + m_lastHandleUrlStatJob->ui()->setWindow(this); + } connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)), this, SLOT(slotHandleUrlStatFinished(KJob*))); } else { - new KRun(url, this); + new KRun(url, this); // Automatically deletes itself after being finished } } @@ -1322,7 +1304,7 @@ void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job) if (entry.isDir()) { activeViewContainer()->setUrl(url); } else { - new KRun(url, this); + new KRun(url, this); // Automatically deletes itself after being finished } } @@ -1333,7 +1315,10 @@ void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event) const ViewTab& viewTab = m_viewTab[tab]; const DolphinView* view = viewTab.isPrimaryViewActive ? viewTab.primaryView->view() : viewTab.secondaryView->view(); - DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event); + const QString error = DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event); + if (!error.isEmpty()) { + activeViewContainer()->showMessage(error, DolphinViewContainer::Error); + } } } @@ -1415,7 +1400,7 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos, delete contextMenu.data(); } -void DolphinMainWindow::updateToolBarMenu() +void DolphinMainWindow::updateControlMenu() { KMenu* menu = qobject_cast(sender()); Q_ASSERT(menu); @@ -1514,29 +1499,16 @@ void DolphinMainWindow::updateToolBarMenu() void DolphinMainWindow::updateToolBar() { if (!menuBar()->isVisible()) { - createToolBarMenuButton(); + createControlButton(); } } -void DolphinMainWindow::slotToolBarSpacerDeleted() -{ - m_toolBarSpacer = 0; - m_updateToolBarTimer->start(); -} - -void DolphinMainWindow::slotToolBarMenuButtonDeleted() +void DolphinMainWindow::slotControlButtonDeleted() { - m_openToolBarMenuButton = 0; + m_controlButton = 0; m_updateToolBarTimer->start(); } -void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize& iconSize) -{ - if (m_openToolBarMenuButton) { - m_openToolBarMenuButton->setIconSize(iconSize); - } -} - void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer) { Q_ASSERT(viewContainer); @@ -1957,48 +1929,43 @@ void DolphinMainWindow::updateGoActions() goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); } -void DolphinMainWindow::createToolBarMenuButton() +void DolphinMainWindow::createControlButton() { - if (m_toolBarSpacer && m_openToolBarMenuButton) { + if (m_controlButton) { return; } - Q_ASSERT(!m_toolBarSpacer); - Q_ASSERT(!m_openToolBarMenuButton); + Q_ASSERT(!m_controlButton); - m_toolBarSpacer = new QWidget(this); - m_toolBarSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + m_controlButton = new QToolButton(this); + m_controlButton->setIcon(KIcon("applications-system")); + m_controlButton->setText(i18nc("@action", "Control")); + m_controlButton->setPopupMode(QToolButton::InstantPopup); + m_controlButton->setToolButtonStyle(toolBar()->toolButtonStyle()); - m_openToolBarMenuButton = new QToolButton(this); - m_openToolBarMenuButton->setIcon(KIcon("configure")); - m_openToolBarMenuButton->setPopupMode(QToolButton::InstantPopup); - m_openToolBarMenuButton->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin")); + KMenu* controlMenu = new KMenu(m_controlButton); + connect(controlMenu, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu())); - KMenu* toolBarMenu = new ToolBarMenu(m_openToolBarMenuButton); - connect(toolBarMenu, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu())); + m_controlButton->setMenu(controlMenu); - m_openToolBarMenuButton->setMenu(toolBarMenu); - - toolBar()->addWidget(m_toolBarSpacer); - toolBar()->addWidget(m_openToolBarMenuButton); - connect(toolBar(), SIGNAL(iconSizeChanged(QSize)), this, SLOT(slotToolBarIconSizeChanged(QSize))); + toolBar()->addWidget(m_controlButton); + connect(toolBar(), SIGNAL(iconSizeChanged(QSize)), + m_controlButton, SLOT(setIconSize(QSize))); + connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), + m_controlButton, SLOT(setToolButtonStyle(Qt::ToolButtonStyle))); // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar // gets edited. In this case we must add them again. The adding is done asynchronously by // m_updateToolBarTimer. - connect(m_toolBarSpacer, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted())); - connect(m_openToolBarMenuButton, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted())); + connect(m_controlButton, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted())); m_updateToolBarTimer = new QTimer(this); m_updateToolBarTimer->setInterval(500); connect(m_updateToolBarTimer, SIGNAL(timeout()), this, SLOT(updateToolBar())); } -void DolphinMainWindow::deleteToolBarMenuButton() +void DolphinMainWindow::deleteControlButton() { - delete m_toolBarSpacer; - m_toolBarSpacer = 0; - - delete m_openToolBarMenuButton; - m_openToolBarMenuButton = 0; + delete m_controlButton; + m_controlButton = 0; delete m_updateToolBarTimer; m_updateToolBarTimer = 0; @@ -2092,7 +2059,7 @@ void DolphinMainWindow::refreshViews() void DolphinMainWindow::clearStatusBar() { - m_activeViewContainer->statusBar()->clear(); + m_activeViewContainer->statusBar()->resetToDefaultText(); } void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container) @@ -2119,10 +2086,14 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container) this, SLOT(openNewTab(KUrl))); connect(view, SIGNAL(requestContextMenu(QPoint,KFileItem,KUrl,QList)), this, SLOT(openContextMenu(QPoint,KFileItem,KUrl,QList))); - connect(view, SIGNAL(startedPathLoading(KUrl)), + connect(view, SIGNAL(directoryLoadingStarted()), this, SLOT(enableStopAction())); - connect(view, SIGNAL(finishedPathLoading(KUrl)), + connect(view, SIGNAL(directoryLoadingCompleted()), this, SLOT(disableStopAction())); + connect(view, SIGNAL(goBackRequested()), + this, SLOT(goBack())); + connect(view, SIGNAL(goForwardRequested()), + this, SLOT(goForward())); const KUrlNavigator* navigator = container->urlNavigator(); connect(navigator, SIGNAL(urlChanged(KUrl)), @@ -2260,54 +2231,11 @@ void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job) { DolphinMainWindow* mainWin= qobject_cast(parentWidget()); if (mainWin) { - DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar(); - statusBar->setMessage(job->errorString(), DolphinStatusBar::Error); + DolphinViewContainer* container = mainWin->activeViewContainer(); + container->showMessage(job->errorString(), DolphinViewContainer::Error); } else { KIO::FileUndoManager::UiInterface::jobError(job); } } -ToolBarMenu::ToolBarMenu(QWidget* parent) : - KMenu(parent) -{ -} - -ToolBarMenu::~ToolBarMenu() -{ -} - -void ToolBarMenu::showEvent(QShowEvent* event) -{ - KMenu::showEvent(event); - - // Adjust the position of the menu to be shown within the - // Dolphin window to reduce the cases that sub-menus might overlap - // the right screen border. - QPoint pos; - QWidget* button = parentWidget(); - if (layoutDirection() == Qt::RightToLeft) { - pos = button->mapToGlobal(QPoint(0, button->height())); - } else { - pos = button->mapToGlobal(QPoint(button->width(), button->height())); - pos.rx() -= width(); - } - - // Assure that the menu is not shown outside the screen boundaries and - // that it does not overlap with the parent button. - const QRect screen = QApplication::desktop()->screenGeometry(QCursor::pos()); - if (pos.x() < screen.x()) { - pos.rx() = screen.x(); - } else if (pos.x() + width() > screen.x() + screen.width()) { - pos.rx() = screen.x() + screen.width() - width(); - } - - if (pos.y() < screen.y()) { - pos.ry() = screen.y(); - } else if (pos.y() + height() > screen.y() + screen.height()) { - pos.ry() = button->mapToGlobal(QPoint(0, 0)).y() - height(); - } - - move(pos); -} - #include "dolphinmainwindow.moc"