From 0c55297ce40847a9af1e00f233c3943f66ab577f Mon Sep 17 00:00:00 2001 From: Erik Hahn Date: Sun, 13 Oct 2013 10:44:13 +0200 Subject: Files passed as arguments: Ignore unsupported files With this patch, Dolphin ignores all files passed to it that it can't Also, archives are now opened inside Dolphin so it can be used as an archive manager at least for local files. If the user tries to open a remote archive Dolphin still opens it externally; I have observed that if it receives one as an argument, it will display a pseudo-folder that contains only said archive. So having it set as the archive handler is still broken, but in a less annoying way. CCBUG: 318683 REVIEW: 113191 FIXED-IN: 4.11.3 --- src/dolphinmainwindow.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 73001bf54..a11fb0c5b 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -31,6 +31,7 @@ #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" @@ -243,8 +244,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 +267,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.begin(); + while (it != urlsToOpen.end()) { openNewTab(*it); ++it; - if (hasSplitView && (it != dirs.end())) { + if (hasSplitView && (it != urlsToOpen.end())) { const int tabIndex = m_viewTab.count() - 1; m_viewTab[tabIndex].secondaryView->setUrl(*it); ++it; -- cgit v1.3 From 96ba990d865b2dfb966961061ba5154dcd3187b4 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Sun, 13 Oct 2013 10:55:21 +0200 Subject: Fix crash when triggereing the "Compare files" action via D-Bus If the number of selected items is not two, Dolphin disables this action. However, it is still possible to trigger it via D-Bus, and this could cause a crash in DolphinMainWindow::compareFiles() because this function did not test at all if there are really two items selected. This patch adds such a check and simplifies the code in that function. BUG: 325517 FIXED-IN: 4.11.3 --- src/dolphinmainwindow.cpp | 51 +++++++++++------------------------------------ 1 file changed, 12 insertions(+), 39 deletions(-) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index a11fb0c5b..ccef356ea 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -999,50 +999,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; - } - - 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()); -- cgit v1.3