]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Prevent black borders when compositing has been disabled.
[dolphin.git] / src / dolphinmainwindow.cpp
index df73804dcbadc2ae6360ffe73f816d4b6be5307f..e1cc13095648e7526276355b6f3b469614861c25 100644 (file)
@@ -31,7 +31,6 @@
 #include "dolphinapplication.h"
 #include "dolphinnewmenu.h"
 #include "search/dolphinsearchbox.h"
-#include "search/dolphinsearchoptionsconfigurator.h"
 #include "settings/dolphinsettings.h"
 #include "settings/dolphinsettingsdialog.h"
 #include "dolphinviewcontainer.h"
@@ -151,6 +150,68 @@ DolphinMainWindow::~DolphinMainWindow()
     DolphinApplication::app()->removeMainWindow(this);
 }
 
+void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
+{
+    if (dirs.isEmpty()) {
+        return;
+    }
+
+    const int oldOpenTabsCount = m_viewTab.count();
+
+    const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
+    const bool hasSplitView = generalSettings->splitView();
+
+    // 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()) {
+        openNewTab(*it);
+        ++it;
+
+        if (hasSplitView && (it != dirs.end())) {
+            const int tabIndex = m_viewTab.count() - 1;
+            m_viewTab[tabIndex].secondaryView->setUrl(*it);
+            ++it;
+        }
+    }
+
+    // remove the previously opened tabs
+    for (int i = 0; i < oldOpenTabsCount; ++i) {
+        closeTab(0);
+    }
+}
+
+void DolphinMainWindow::openFiles(const QList<KUrl>& files)
+{
+    if (files.isEmpty()) {
+        return;
+    }
+
+    // Get all distinct directories from 'files' and open a tab
+    // for each directory. If the "split view" option is enabled, two
+    // directories are shown inside one tab (see openDirectories()).
+    QList<KUrl> dirs;
+    foreach (const KUrl& url, files) {
+        const KUrl dir(url.directory());
+        if (!dirs.contains(dir)) {
+            dirs.append(dir);
+        }
+    }
+
+    openDirectories(dirs);
+
+    // Select the files. Although the files can be split between several
+    // tabs, there is no need to split 'files' accordingly, as
+    // the DolphinView will just ignore invalid selections.
+    const int tabCount = m_viewTab.count();
+    for (int i = 0; i < tabCount; ++i) {
+        m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
+        if (m_viewTab[i].secondaryView != 0) {
+            m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
+        }
+    }
+}
+
 void DolphinMainWindow::toggleViews()
 {
     if (m_viewTab[m_tabIndex].primaryView == 0) {
@@ -251,11 +312,6 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
     }
 }
 
-void DolphinMainWindow::changeSelection(const KFileItemList& selection)
-{
-    activeViewContainer()->view()->changeSelection(selection);
-}
-
 void DolphinMainWindow::slotEditableStateChanged(bool editable)
 {
     KToggleAction* editableLocationAction =
@@ -1011,8 +1067,8 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can
 void DolphinMainWindow::searchItems()
 {
 #ifdef HAVE_NEPOMUK
-    const KUrl nepomukUrl = m_searchOptionsConfigurator->nepomukUrl();
-    m_activeViewContainer->setUrl(nepomukUrl);
+    const KUrl nepomukSearchUrl = m_searchOptionsConfigurator->nepomukSearchUrl();
+    m_activeViewContainer->setUrl(nepomukSearchUrl);
 #endif
 }
 
@@ -1074,6 +1130,7 @@ void DolphinMainWindow::init()
     m_searchOptionsConfigurator->hide();
     connect(m_searchOptionsConfigurator, SIGNAL(searchOptionsChanged()),
             this, SLOT(searchItems()));
+    connect(this, SIGNAL(urlChanged(KUrl)), m_searchOptionsConfigurator, SLOT(setDirectory(KUrl)));
 #endif
 
     m_tabBar = new KTabBar(this);
@@ -1118,8 +1175,10 @@ void DolphinMainWindow::init()
     m_searchBox->show();
     connect(m_searchBox, SIGNAL(requestSearchOptions()),
             this, SLOT(showSearchOptions()));
+#ifdef HAVE_NEPOMUK
     connect(m_searchBox, SIGNAL(searchTextChanged(QString)),
             m_searchOptionsConfigurator, SLOT(setCustomSearchQuery(QString)));
+#endif
 
     stateChanged("new_file");
 
@@ -1368,7 +1427,7 @@ void DolphinMainWindow::setupDockWidgets()
     infoDock->setObjectName("infoDock");
     infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     Panel* infoPanel = new InformationPanel(infoDock);
-    connect(infoPanel, SIGNAL(urlActivated(KUrl)), activeViewContainer(), SLOT(setUrl(KUrl)));
+    connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
     infoDock->setWidget(infoPanel);
 
     QAction* infoAction = infoDock->toggleViewAction();
@@ -1403,8 +1462,6 @@ void DolphinMainWindow::setupDockWidgets()
             foldersPanel, SLOT(setUrl(KUrl)));
     connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
             this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
-    connect(foldersPanel, SIGNAL(changeSelection(KFileItemList)),
-            this, SLOT(changeSelection(KFileItemList)));
 
     // setup "Terminal"
 #ifndef Q_OS_WIN
@@ -1658,6 +1715,16 @@ void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
     setCaption(caption);
 }
 
+void DolphinMainWindow::handleUrl(const KUrl& url)
+{
+    if (KProtocolManager::supportsListing(url)) {
+        activeViewContainer()->setUrl(url);
+    }
+    else {
+        new KRun(url, this);
+    }
+}
+
 QString DolphinMainWindow::squeezedText(const QString& text) const
 {
     const QFontMetrics fm = fontMetrics();