]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
allow to restrict the search results by the current folder (including all sub folders)
[dolphin.git] / src / dolphinmainwindow.cpp
index 1c310b5b39ffbd2edb99dba08e7fdb99925185e8..5e08a9e2e5d292c922dac15b64ca2fed6d5f8f81 100644 (file)
 #include "dolphinremoteencoding.h"
 
 #include <config-nepomuk.h>
+#ifdef HAVE_NEPOMUK
+#include "search/dolphinsearchoptionsconfigurator.h"
+#endif
 
 #include "dolphinapplication.h"
 #include "dolphinnewmenu.h"
+#include "search/dolphinsearchbox.h"
+#include "search/dolphinsearchoptionsconfigurator.h"
 #include "settings/dolphinsettings.h"
 #include "settings/dolphinsettingsdialog.h"
-#include "dolphinsearchbox.h"
-#include "dolphinstatusbar.h"
 #include "dolphinviewcontainer.h"
 #include "panels/folders/folderspanel.h"
 #include "panels/places/placespanel.h"
 #include "panels/information/informationpanel.h"
-#include "panels/information/metadatawidget.h"
 #include "mainwindowadaptor.h"
+#include "statusbar/dolphinstatusbar.h"
 #include "viewproperties.h"
 
 #ifndef Q_OS_WIN
@@ -109,6 +112,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(),
@@ -165,23 +171,23 @@ void DolphinMainWindow::showCommand(CommandType command)
     DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
     switch (command) {
     case KIO::FileUndoManager::Copy:
-        statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
+        statusBar->setMessage(i18nc("@info:status", "Successfully copied."),
                               DolphinStatusBar::OperationCompleted);
         break;
     case KIO::FileUndoManager::Move:
-        statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
+        statusBar->setMessage(i18nc("@info:status", "Successfully moved."),
                               DolphinStatusBar::OperationCompleted);
         break;
     case KIO::FileUndoManager::Link:
-        statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
+        statusBar->setMessage(i18nc("@info:status", "Successfully linked."),
                               DolphinStatusBar::OperationCompleted);
         break;
     case KIO::FileUndoManager::Trash:
-        statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
+        statusBar->setMessage(i18nc("@info:status", "Successfully moved to trash."),
                               DolphinStatusBar::OperationCompleted);
         break;
     case KIO::FileUndoManager::Rename:
-        statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
+        statusBar->setMessage(i18nc("@info:status", "Successfully renamed."),
                               DolphinStatusBar::OperationCompleted);
         break;
 
@@ -237,7 +243,7 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
         updateGoActions();
         setUrlAsCaption(url);
         if (m_viewTab.count() > 1) {
-            m_tabBar->setTabText(m_tabIndex, squeezeText(tabName(m_activeViewContainer->url())));
+            m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(m_activeViewContainer->url())));
         }
         const QString iconName = KMimeType::iconNameForUrl(url);
         m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName));
@@ -274,8 +280,6 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
         compareFilesAction->setEnabled(false);
     }
 
-    m_activeViewContainer->updateStatusBar();
-
     emit selectionChanged(selection);
 }
 
@@ -299,11 +303,13 @@ void DolphinMainWindow::updateHistory()
     const int index = urlNavigator->historyIndex();
 
     QAction* backAction = actionCollection()->action("go_back");
+    backAction->setToolTip(i18nc("@info", "Go back"));
     if (backAction != 0) {
         backAction->setEnabled(index < urlNavigator->historySize() - 1);
     }
 
     QAction* forwardAction = actionCollection()->action("go_forward");
+    forwardAction->setToolTip(i18nc("@info", "Go forward"));
     if (forwardAction != 0) {
         forwardAction->setEnabled(index > 0);
     }
@@ -339,11 +345,11 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
     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, squeezeText(tabName(m_activeViewContainer->url())));
+        m_tabBar->addTab(icon, squeezedText(tabName(m_activeViewContainer->url())));
         m_tabBar->blockSignals(false);
     }
 
-    m_tabBar->addTab(icon, squeezeText(tabName(url)));
+    m_tabBar->addTab(icon, squeezedText(tabName(url)));
 
     ViewTab viewTab;
     viewTab.splitter = new QSplitter(this);
@@ -428,7 +434,15 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event)
     DolphinSettings& settings = DolphinSettings::instance();
     GeneralSettings* generalSettings = settings.generalSettings();
 
-    if ((m_viewTab.count() > 1) && generalSettings->confirmClosingMultipleTabs()) {
+    // Find out if Dolphin is closed directly by the user or
+    // by the session manager because the session is closed
+    bool closedByUser = true;
+    DolphinApplication *application = qobject_cast<DolphinApplication*>(qApp);
+    if (application && application->sessionSaving()) {
+        closedByUser = false;
+    }
+
+    if ((m_viewTab.count() > 1) && generalSettings->confirmClosingMultipleTabs() && closedByUser) {
         // Ask the user if he really wants to quit and close all tabs.
         // Open a confirmation dialog with 3 buttons:
         // KDialog::Yes    -> Quit
@@ -539,12 +553,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();
 }
@@ -744,6 +760,32 @@ void DolphinMainWindow::goUp()
     m_activeViewContainer->urlNavigator()->goUp();
 }
 
+void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
+{
+    // The default case (left button pressed) is handled in goBack().
+    if (buttons == Qt::MidButton) {
+        KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
+        openNewTab(urlNavigator->historyUrl(urlNavigator->historyIndex() + 1));
+    }
+}
+
+void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
+{
+    // The default case (left button pressed) is handled in goForward().
+    if (buttons == Qt::MidButton) {
+        KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
+        openNewTab(urlNavigator->historyUrl(urlNavigator->historyIndex() - 1));
+    }
+}
+
+void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
+{
+    // The default case (left button pressed) is handled in goUp().
+    if (buttons == Qt::MidButton) {
+        openNewTab(activeViewContainer()->url().upUrl());
+    }
+}
+
 void DolphinMainWindow::goHome()
 {
     clearStatusBar();
@@ -861,7 +903,7 @@ void DolphinMainWindow::setActiveTab(int index)
     m_tabIndex = index;
 
     ViewTab& viewTab = m_viewTab[index];
-    m_centralWidgetLayout->addWidget(viewTab.splitter);
+    m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
     viewTab.primaryView->show();
     if (viewTab.secondaryView != 0) {
         viewTab.secondaryView->show();
@@ -966,9 +1008,12 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can
     canDecode = KUrl::List::canDecode(event->mimeData());
 }
 
-void DolphinMainWindow::searchItems(const KUrl& url)
+void DolphinMainWindow::searchItems()
 {
-    m_activeViewContainer->setUrl(url);
+#ifdef HAVE_NEPOMUK
+    const KUrl nepomukSearchUrl = m_searchOptionsConfigurator->nepomukSearchUrl();
+    m_activeViewContainer->setUrl(nepomukSearchUrl);
+#endif
 }
 
 void DolphinMainWindow::slotTabMoved(int from, int to)
@@ -977,6 +1022,13 @@ void DolphinMainWindow::slotTabMoved(int from, int to)
     m_tabIndex = m_tabBar->currentIndex();
 }
 
+void DolphinMainWindow::showSearchOptions()
+{
+#ifdef HAVE_NEPOMUK
+    m_searchOptionsConfigurator->show();
+#endif
+}
+
 void DolphinMainWindow::init()
 {
     DolphinSettings& settings = DolphinSettings::instance();
@@ -1017,6 +1069,14 @@ void DolphinMainWindow::init()
     connect(this, SIGNAL(urlChanged(const KUrl&)),
             m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
 
+#ifdef HAVE_NEPOMUK
+    m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this);
+    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);
     m_tabBar->setMovable(true);
     m_tabBar->setTabsClosable(true);
@@ -1043,8 +1103,11 @@ void DolphinMainWindow::init()
     m_centralWidgetLayout = new QVBoxLayout(centralWidget);
     m_centralWidgetLayout->setSpacing(0);
     m_centralWidgetLayout->setMargin(0);
+#ifdef HAVE_NEPOMUK
+    m_centralWidgetLayout->addWidget(m_searchOptionsConfigurator);
+#endif
     m_centralWidgetLayout->addWidget(m_tabBar);
-    m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter);
+    m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
 
     setCentralWidget(centralWidget);
     setupDockWidgets();
@@ -1054,6 +1117,12 @@ void DolphinMainWindow::init()
 
     m_searchBox->setParent(toolBar("searchToolBar"));
     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");
 
@@ -1158,7 +1227,11 @@ void DolphinMainWindow::setupActions()
     cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
     cut->setShortcut(cutShortcut);
     KStandardAction::copy(this, SLOT(copy()), actionCollection());
-    KStandardAction::paste(this, SLOT(paste()), actionCollection());
+    KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
+    // The text of the paste-action is modified dynamically by Dolphin
+    // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
+    // due to the long text, the text "Paste" is used:
+    paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
 
     KAction* selectAll = actionCollection()->addAction("select_all");
     selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
@@ -1186,6 +1259,7 @@ void DolphinMainWindow::setupActions()
 
     KAction* stop = actionCollection()->addAction("stop");
     stop->setText(i18nc("@action:inmenu View", "Stop"));
+    stop->setToolTip(i18nc("@info", "Stop loading"));
     stop->setIcon(KIcon("process-stop"));
     connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
 
@@ -1201,6 +1275,7 @@ void DolphinMainWindow::setupActions()
 
     // setup 'Go' menu
     KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
+    connect(backAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
     KShortcut backShortcut = backAction->shortcut();
     backShortcut.setAlternate(Qt::Key_Backspace);
     backAction->setShortcut(backShortcut);
@@ -1218,8 +1293,12 @@ void DolphinMainWindow::setupActions()
     m_recentTabsMenu->addSeparator();
     m_recentTabsMenu->setEnabled(false);
 
-    KStandardAction::forward(this, SLOT(goForward()), actionCollection());
-    KStandardAction::up(this, SLOT(goUp()), actionCollection());
+    KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
+    connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
+
+    KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
+    connect(upAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
+
     KStandardAction::home(this, SLOT(goHome()), actionCollection());
 
     // setup 'Tools' menu
@@ -1230,6 +1309,7 @@ void DolphinMainWindow::setupActions()
 
     KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
     showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
+    showFilterBar->setIcon(KIcon("view-filter"));
     showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
     connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
 
@@ -1275,7 +1355,7 @@ void DolphinMainWindow::setupActions()
 
     // 'Search' toolbar
     m_searchBox = new DolphinSearchBox(this);
-    connect(m_searchBox, SIGNAL(search(KUrl)), this, SLOT(searchItems(KUrl)));
+    connect(m_searchBox, SIGNAL(search(QString)), this, SLOT(searchItems()));
 
     KAction* search = new KAction(this);
     actionCollection()->addAction("search_bar", search);
@@ -1291,6 +1371,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();
@@ -1434,7 +1515,7 @@ void DolphinMainWindow::rememberClosedTab(int index)
     const QString primaryPath = m_viewTab[index].primaryView->url().path();
     const QString iconName = KMimeType::iconNameForUrl(primaryPath);
 
-    QAction* action = new QAction(squeezeText(primaryPath), tabsMenu);
+    QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
 
     ClosedTab closedTab;
     closedTab.primaryUrl = m_viewTab[index].primaryView->url();
@@ -1500,13 +1581,16 @@ void DolphinMainWindow::updateSplitAction()
     if (m_viewTab[m_tabIndex].secondaryView != 0) {
         if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
             splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
+            splitAction->setToolTip(i18nc("@info", "Close right view"));
             splitAction->setIcon(KIcon("view-right-close"));
         } else {
             splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
+            splitAction->setToolTip(i18nc("@info", "Close left view"));
             splitAction->setIcon(KIcon("view-left-close"));
         }
     } else {
         splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
+        splitAction->setToolTip(i18nc("@info", "Split view"));
         splitAction->setIcon(KIcon("view-right-new"));
     }
 }
@@ -1573,15 +1657,24 @@ void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
             caption = url.protocol();
        }
     }
-    
+
     setCaption(caption);
 }
 
-QString DolphinMainWindow::squeezeText(const QString& text)
+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();
-    QString result = fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
-    return result;
+    return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
 }
 
 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :