X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ebfcb5e19b345a0fbb2425f537232f45d3b3d62a..70cd04df40b152fd7a448964b9f9ca4948291eb3:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 5cc608fd4..0804f4be9 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -31,10 +31,12 @@ #include "panels/information/informationpanel.h" #include "settings/dolphinsettingsdialog.h" #include "statusbar/dolphinstatusbar.h" +#include "views/dolphinview.h" #include "views/dolphinviewactionhandler.h" #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 +128,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()); @@ -243,8 +248,20 @@ void DolphinMainWindow::openDirectories(const QList& dirs) return; } - if (dirs.count() == 1) { - m_activeViewContainer->setUrl(dirs.first()); + // dirs could contain URLs that actually point to archives or other files. + // Replace them by URLs we can open where possible and filter the rest out. + QList urlsToOpen; + foreach (const KUrl& rawUrl, dirs) { + const KFileItem& item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, rawUrl); + item.determineMimeType(); + const KUrl& url = DolphinView::openItemAsFolderUrl(item); + if (!url.isEmpty()) { + urlsToOpen.append(url); + } + } + + if (urlsToOpen.count() == 1) { + m_activeViewContainer->setUrl(urlsToOpen.first()); return; } @@ -254,12 +271,12 @@ void DolphinMainWindow::openDirectories(const QList& dirs) // Open each directory inside a new tab. If the "split view" option has been enabled, // always show two directories within one tab. - QList::const_iterator it = dirs.begin(); - while (it != dirs.end()) { + QList::const_iterator it = urlsToOpen.constBegin(); + while (it != urlsToOpen.constEnd()) { openNewTab(*it); ++it; - if (hasSplitView && (it != dirs.end())) { + if (hasSplitView && (it != urlsToOpen.constEnd())) { const int tabIndex = m_viewTab.count() - 1; m_viewTab[tabIndex].secondaryView->setUrl(*it); ++it; @@ -986,50 +1003,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; + const DolphinViewContainer* primaryViewContainer = m_viewTab[m_tabIndex].primaryView; + Q_ASSERT(primaryViewContainer); + KFileItemList items = primaryViewContainer->view()->selectedItems(); - KFileItemList items = m_viewTab[m_tabIndex].primaryView->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; - } - - 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; + const DolphinViewContainer* secondaryViewContainer = m_viewTab[m_tabIndex].secondaryView; + if (secondaryViewContainer) { + items.append(secondaryViewContainer->view()->selectedItems()); } - case 2: { - urlA = items[0].url(); - urlB = items[1].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; } - 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()); @@ -1297,8 +1287,6 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos, { QWeakPointer 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); @@ -1491,8 +1492,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")); @@ -1767,7 +1766,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)),