]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
- When the filterbar has been activated as startup setting, still the view should...
[dolphin.git] / src / dolphinmainwindow.cpp
index 2b60044ce386e50a7b34c806bbd7aedad33a7c8f..0523085ae7a46d8c6ae39a025e199ebc8fc59ab5 100644 (file)
@@ -24,7 +24,9 @@
 #include "dolphinremoteencoding.h"
 
 #include <config-nepomuk.h>
+#ifdef HAVE_NEPOMUK
 #include "search/dolphinsearchoptionsconfigurator.h"
+#endif
 
 #include "dolphinapplication.h"
 #include "dolphinnewmenu.h"
@@ -109,7 +111,9 @@ DolphinMainWindow::DolphinMainWindow(int id) :
     m_activeViewContainer(0),
     m_centralWidgetLayout(0),
     m_searchBox(0),
+#ifdef HAVE_NEPOMUK
     m_searchOptionsConfigurator(0),
+#endif
     m_id(id),
     m_tabIndex(0),
     m_viewTab(),
@@ -146,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) {
@@ -246,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 =
@@ -336,15 +397,19 @@ void DolphinMainWindow::openNewTab()
 
 void DolphinMainWindow::openNewTab(const KUrl& url)
 {
-    const KIcon icon = KIcon(KMimeType::iconNameForUrl(m_activeViewContainer->url()));
+    QWidget* focusWidget = QApplication::focusWidget();
+
     if (m_viewTab.count() == 1) {
         // Only one view is open currently and hence no tab is shown at
         // all. Before creating a tab for 'url', provide a tab for the current URL.
-        m_tabBar->addTab(icon, squeezedText(tabName(m_activeViewContainer->url())));
+        const KUrl currentUrl = m_activeViewContainer->url();
+        m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl)),
+                         squeezedText(tabName(currentUrl)));
         m_tabBar->blockSignals(false);
     }
 
-    m_tabBar->addTab(icon, squeezedText(tabName(url)));
+    m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(url)),
+                     squeezedText(tabName(url)));
 
     ViewTab viewTab;
     viewTab.splitter = new QSplitter(this);
@@ -366,6 +431,12 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
         m_viewTab[tabIndex].secondaryView->setActive(true);
         m_viewTab[tabIndex].isPrimaryViewActive = false;
     }
+
+    if (focusWidget != 0) {
+        // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
+        // in background, assure that the previous focused widget gets the focus back.
+        focusWidget->setFocus();
+    }
 }
 
 void DolphinMainWindow::activateNextTab()
@@ -424,6 +495,14 @@ void DolphinMainWindow::toggleActiveView()
     setActiveViewContainer(m_activeViewContainer == right ? left : right);
 }
 
+void DolphinMainWindow::showEvent(QShowEvent* event)
+{
+    KXmlGuiWindow::showEvent(event);
+    if (!event->spontaneous()) {
+        m_activeViewContainer->view()->setFocus();
+    }
+}
+
 void DolphinMainWindow::closeEvent(QCloseEvent* event)
 {
     DolphinSettings& settings = DolphinSettings::instance();
@@ -548,12 +627,14 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group)
 
 void DolphinMainWindow::updateNewMenu()
 {
+    m_newMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
     m_newMenu->slotCheckUpToDate();
     m_newMenu->setPopupFiles(activeViewContainer()->url());
 }
 
 void DolphinMainWindow::createDirectory()
 {
+    m_newMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
     m_newMenu->setPopupFiles(activeViewContainer()->url());
     m_newMenu->createDirectory();
 }
@@ -1003,18 +1084,10 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can
 
 void DolphinMainWindow::searchItems()
 {
-    const QString searchOptions = m_searchOptionsConfigurator->options();
-
-    QString searchString = m_searchBox->text();
-    if (!searchString.isEmpty() && !searchOptions.isEmpty()) {
-        searchString += ' ' + searchOptions;
-    } else if (!searchOptions.isEmpty()) {
-        searchString += searchOptions;
-    }
-
-    if (!searchString.isEmpty()) {
-        m_activeViewContainer->setUrl(KUrl("nepomuksearch:/" + searchString));
-    }
+#ifdef HAVE_NEPOMUK
+    const KUrl nepomukSearchUrl = m_searchOptionsConfigurator->nepomukSearchUrl();
+    m_activeViewContainer->setUrl(nepomukSearchUrl);
+#endif
 }
 
 void DolphinMainWindow::slotTabMoved(int from, int to)
@@ -1073,8 +1146,9 @@ void DolphinMainWindow::init()
 #ifdef HAVE_NEPOMUK
     m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this);
     m_searchOptionsConfigurator->hide();
-    connect(m_searchOptionsConfigurator, SIGNAL(searchOptionsChanged(QString)),
+    connect(m_searchOptionsConfigurator, SIGNAL(searchOptionsChanged()),
             this, SLOT(searchItems()));
+    connect(this, SIGNAL(urlChanged(KUrl)), m_searchOptionsConfigurator, SLOT(setDirectory(KUrl)));
 #endif
 
     m_tabBar = new KTabBar(this);
@@ -1119,6 +1193,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");
 
@@ -1367,6 +1445,7 @@ void DolphinMainWindow::setupDockWidgets()
     infoDock->setObjectName("infoDock");
     infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     Panel* infoPanel = new InformationPanel(infoDock);
+    connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
     infoDock->setWidget(infoPanel);
 
     QAction* infoAction = infoDock->toggleViewAction();
@@ -1401,8 +1480,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
@@ -1652,10 +1729,20 @@ void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
             caption = url.protocol();
        }
     }
-    
+
     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();