]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Merge branch 'KDE/4.13'
[dolphin.git] / src / dolphinmainwindow.cpp
index 5cc608fd490e4d547cb613665977f2ba68f5f4ab..0ad224cbcae2760abcf1559557cbd9cbae4653d0 100644 (file)
@@ -35,6 +35,7 @@
 #include "views/dolphinremoteencoding.h"
 #include "views/draganddrophelper.h"
 #include "views/viewproperties.h"
+#include "views/dolphinnewfilemenuobserver.h"
 
 #ifndef Q_OS_WIN
 #include "panels/terminal/terminalpanel.h"
@@ -126,6 +127,9 @@ DolphinMainWindow::DolphinMainWindow() :
     ViewTab& viewTab = m_viewTab[m_tabIndex];
     viewTab.wasActive = true; // The first opened tab is automatically active
 
+    connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(errorMessage(QString)),
+            this, SLOT(showErrorMessage(QString)));
+
     KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
     undoManager->setUiInterface(new UndoUiInterface());
 
@@ -213,6 +217,7 @@ DolphinMainWindow::DolphinMainWindow() :
         toggleSplitView();
     }
     updateEditActions();
+    updatePasteAction();
     updateViewActions();
     updateGoActions();
 
@@ -254,12 +259,12 @@ void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
 
     // Open each directory inside a new tab. If the "split view" option has been enabled,
     // always show two directories within one tab.
-    QList<KUrl>::const_iterator it = dirs.begin();
-    while (it != dirs.end()) {
+    QList<KUrl>::const_iterator it = dirs.constBegin();
+    while (it != dirs.constEnd()) {
         openNewTab(*it);
         ++it;
 
-        if (hasSplitView && (it != dirs.end())) {
+        if (hasSplitView && (it != dirs.constEnd())) {
             const int tabIndex = m_viewTab.count() - 1;
             m_viewTab[tabIndex].secondaryView->setUrl(*it);
             ++it;
@@ -352,6 +357,7 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
     if (view) {
         view->setUrl(url);
         updateEditActions();
+        updatePasteAction();
         updateViewActions();
         updateGoActions();
         setUrlAsCaption(url);
@@ -477,6 +483,8 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
     m_viewTab.append(viewTab);
 
     actionCollection()->action("close_tab")->setEnabled(true);
+    actionCollection()->action("activate_prev_tab")->setEnabled(true);
+    actionCollection()->action("activate_next_tab")->setEnabled(true);
 
     // Provide a split view, if the startup settings are set this way
     if (GeneralSettings::splitView()) {
@@ -673,6 +681,13 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group)
                 Q_ASSERT(cont);
             }
 
+            // The right view must be activated before the URL is set. Changing
+            // the URL in the right view will emit the right URL navigator's
+            // urlChanged(KUrl) signal, which is connected to the changeUrl(KUrl)
+            // slot. That slot will change the URL in the left view if it is still
+            // active. See https://bugs.kde.org/show_bug.cgi?id=330047.
+            setActiveViewContainer(cont);
+
             cont->setUrl(secondaryUrl);
             const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
             cont->urlNavigator()->setUrlEditable(editable);
@@ -986,50 +1001,23 @@ void DolphinMainWindow::goHome(Qt::MouseButtons buttons)
 
 void DolphinMainWindow::compareFiles()
 {
-    // The method is only invoked if exactly 2 files have
-    // been selected. The selected files may be:
-    // - both in the primary view
-    // - both in the secondary view
-    // - one in the primary view and the other in the secondary
-    //   view
-    Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
-
-    KUrl urlA;
-    KUrl urlB;
-
-    KFileItemList items = m_viewTab[m_tabIndex].primaryView->view()->selectedItems();
+    const DolphinViewContainer* primaryViewContainer = m_viewTab[m_tabIndex].primaryView;
+    Q_ASSERT(primaryViewContainer);
+    KFileItemList items = primaryViewContainer->view()->selectedItems();
 
-    switch (items.count()) {
-    case 0: {
-        Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
-        items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
-        Q_ASSERT(items.count() == 2);
-        urlA = items[0].url();
-        urlB = items[1].url();
-        break;
+    const DolphinViewContainer* secondaryViewContainer = m_viewTab[m_tabIndex].secondaryView;
+    if (secondaryViewContainer) {
+        items.append(secondaryViewContainer->view()->selectedItems());
     }
 
-    case 1: {
-        urlA = items[0].url();
-        Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
-        items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
-        Q_ASSERT(items.count() == 1);
-        urlB = items[0].url();
-        break;
+    if (items.count() != 2) {
+        // The action is disabled in this case, but it could have been triggered
+        // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
+        return;
     }
 
-    case 2: {
-        urlA = items[0].url();
-        urlB = items[1].url();
-        break;
-    }
-
-    default: {
-        // may not happen: compareFiles may only get invoked if 2
-        // files are selected
-        Q_ASSERT(false);
-    }
-    }
+    KUrl urlA = items.at(0).url();
+    KUrl urlB = items.at(1).url();
 
     QString command("kompare -c \"");
     command.append(urlA.pathOrUrl());
@@ -1171,6 +1159,8 @@ void DolphinMainWindow::closeTab(int index)
     if (m_viewTab.count() == 1) {
         m_tabBar->removeTab(0);
         actionCollection()->action("close_tab")->setEnabled(false);
+        actionCollection()->action("activate_prev_tab")->setEnabled(false);
+        actionCollection()->action("activate_next_tab")->setEnabled(false);
     } else {
         m_tabBar->blockSignals(false);
     }
@@ -1297,8 +1287,6 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos,
 {
     QWeakPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, pos, item, url);
     contextMenu.data()->setCustomActions(customActions);
-    connect(contextMenu.data(), SIGNAL(errorMessage(QString)),
-            this, SLOT(showErrorMessage(QString)));
     const DolphinContextMenu::Command command = contextMenu.data()->open();
 
     switch (command) {
@@ -1433,6 +1421,19 @@ void DolphinMainWindow::slotPanelErrorMessage(const QString& error)
     activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
 }
 
+void DolphinMainWindow::slotPlaceActivated(const KUrl& url)
+{
+    DolphinViewContainer* view = activeViewContainer();
+
+    if (view->url() == url) {
+        // We can end up here if the user clicked a device in the Places Panel
+        // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
+        reloadView();
+    } else {
+        changeUrl(url);
+    }
+}
+
 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
 {
     Q_ASSERT(viewContainer);
@@ -1456,6 +1457,7 @@ void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContain
 
     updateHistory();
     updateEditActions();
+    updatePasteAction();
     updateViewActions();
     updateGoActions();
 
@@ -1491,8 +1493,6 @@ void DolphinMainWindow::setupActions()
     m_newFileMenu->setDelayed(false);
     connect(menu, SIGNAL(aboutToShow()),
             this, SLOT(updateNewMenu()));
-    connect(m_newFileMenu, SIGNAL(errorMessage(QString)),
-            this, SLOT(showErrorMessage(QString)));
 
     KAction* newWindow = actionCollection()->addAction("new_window");
     newWindow->setIcon(KIcon("window-new"));
@@ -1640,12 +1640,16 @@ void DolphinMainWindow::setupActions()
     prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
 
     KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
+    activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
     activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
+    activateNextTab->setEnabled(false);
     connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
     activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
 
     KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
+    activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
     activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
+    activatePrevTab->setEnabled(false);
     connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
     activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
 
@@ -1767,7 +1771,7 @@ void DolphinMainWindow::setupDockWidgets()
 
     addDockWidget(Qt::LeftDockWidgetArea, placesDock);
     connect(placesPanel, SIGNAL(placeActivated(KUrl)),
-            this, SLOT(changeUrl(KUrl)));
+            this, SLOT(slotPlaceActivated(KUrl)));
     connect(placesPanel, SIGNAL(placeMiddleClicked(KUrl)),
             this, SLOT(openNewTab(KUrl)));
     connect(placesPanel, SIGNAL(errorMessage(QString)),
@@ -1818,7 +1822,6 @@ void DolphinMainWindow::updateEditActions()
         deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
         cutAction->setEnabled(capabilities.supportsMoving());
     }
-    updatePasteAction();
 }
 
 void DolphinMainWindow::updateViewActions()