]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Show a progress information when doing a Nepomuk search. As "sideeffect" some KDE3...
[dolphin.git] / src / dolphinmainwindow.cpp
index 3ce1e9f2d80dcdef55689348c0cf06f9ec99f56e..ee5994955ae69f9322c938e8a69eff67ae05b228 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 "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
@@ -84,7 +86,6 @@
 #include <QDBusMessage>
 #include <QKeyEvent>
 #include <QClipboard>
-#include <QLineEdit>
 #include <QSplitter>
 #include <QDockWidget>
 #include <kacceleratormanager.h>
@@ -110,6 +111,7 @@ DolphinMainWindow::DolphinMainWindow(int id) :
     m_activeViewContainer(0),
     m_centralWidgetLayout(0),
     m_searchBox(0),
+    m_searchOptionsConfigurator(0),
     m_id(id),
     m_tabIndex(0),
     m_viewTab(),
@@ -166,23 +168,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;
 
@@ -238,7 +240,7 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
         updateGoActions();
         setUrlAsCaption(url);
         if (m_viewTab.count() > 1) {
-            m_tabBar->setTabText(m_tabIndex, tabName(url));
+            m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(m_activeViewContainer->url())));
         }
         const QString iconName = KMimeType::iconNameForUrl(url);
         m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName));
@@ -275,8 +277,6 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
         compareFilesAction->setEnabled(false);
     }
 
-    m_activeViewContainer->updateStatusBar();
-
     emit selectionChanged(selection);
 }
 
@@ -300,11 +300,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);
     }
@@ -340,11 +342,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, tabName(m_activeViewContainer->url()));
+        m_tabBar->addTab(icon, squeezedText(tabName(m_activeViewContainer->url())));
         m_tabBar->blockSignals(false);
     }
 
-    m_tabBar->addTab(icon, tabName(url));
+    m_tabBar->addTab(icon, squeezedText(tabName(url)));
 
     ViewTab viewTab;
     viewTab.splitter = new QSplitter(this);
@@ -429,7 +431,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
@@ -646,7 +656,7 @@ void DolphinMainWindow::selectAll()
     // URL instead of all items of the view
 
     KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
-    QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
+    QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses
     const bool selectUrl = urlNavigator->isUrlEditable() &&
                            lineEdit->hasFocus();
     if (selectUrl) {
@@ -722,7 +732,7 @@ void DolphinMainWindow::replaceLocation()
     navigator->setFocus();
 
     // select the whole text of the combo box editor
-    QLineEdit* lineEdit = navigator->editor()->lineEdit();
+    QLineEdit* lineEdit = navigator->editor()->lineEdit();  // krazy:exclude=qclasses
     const QString text = lineEdit->text();
     lineEdit->setSelection(0, text.length());
 }
@@ -745,6 +755,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();
@@ -813,7 +849,18 @@ void DolphinMainWindow::toggleShowMenuBar()
 
 void DolphinMainWindow::openTerminal()
 {
-    KToolInvocation::invokeTerminal(QString(), m_activeViewContainer->url().path());
+    QString dir(QDir::homePath());
+
+    // If the given directory is not local, it can still be the URL of an
+    // ioslave using UDS_LOCAL_PATH which to be converted first.
+    KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
+
+    //If the URL is local after the above conversion, set the directory.
+    if (url.isLocalFile()) {
+        dir = url.toLocalFile();
+    }
+
+    KToolInvocation::invokeTerminal(QString(), dir);
 }
 
 void DolphinMainWindow::editSettings()
@@ -851,7 +898,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();
@@ -959,6 +1006,12 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can
 void DolphinMainWindow::searchItems(const KUrl& url)
 {
     m_activeViewContainer->setUrl(url);
+
+    // The Nepomuk IO-slave does not provide any progress information. Give
+    // an immediate hint to the user that a searching is done:
+    DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
+    statusBar->setProgressText(i18nc("@info", "Searching..."));
+    statusBar->setProgress(-1);
 }
 
 void DolphinMainWindow::slotTabMoved(int from, int to)
@@ -967,6 +1020,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();
@@ -1007,6 +1067,11 @@ void DolphinMainWindow::init()
     connect(this, SIGNAL(urlChanged(const KUrl&)),
             m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
 
+#ifdef HAVE_NEPOMUK
+    m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this);
+    m_searchOptionsConfigurator->hide();
+#endif
+
     m_tabBar = new KTabBar(this);
     m_tabBar->setMovable(true);
     m_tabBar->setTabsClosable(true);
@@ -1033,8 +1098,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();
@@ -1044,6 +1112,8 @@ void DolphinMainWindow::init()
 
     m_searchBox->setParent(toolBar("searchToolBar"));
     m_searchBox->show();
+    connect(m_searchBox, SIGNAL(requestSearchOptions()),
+            this, SLOT(showSearchOptions()));
 
     stateChanged("new_file");
 
@@ -1148,7 +1218,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"));
@@ -1176,6 +1250,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()));
 
@@ -1191,6 +1266,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);
@@ -1208,8 +1284,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
@@ -1220,6 +1300,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)));
 
@@ -1231,7 +1312,7 @@ void DolphinMainWindow::setupActions()
 
     KAction* openTerminal = actionCollection()->addAction("open_terminal");
     openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
-    openTerminal->setIcon(KIcon("terminal"));
+    openTerminal->setIcon(KIcon("utilities-terminal"));
     openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
     connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
 
@@ -1331,7 +1412,7 @@ void DolphinMainWindow::setupDockWidgets()
     QAction* terminalAction = terminalDock->toggleViewAction();
     terminalAction->setText(i18nc("@title:window Shell terminal", "Terminal"));
     terminalAction->setShortcut(Qt::Key_F4);
-    terminalAction->setIcon(KIcon("terminal"));
+    terminalAction->setIcon(KIcon("utilities-terminal"));
     actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
 
     addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
@@ -1424,10 +1505,7 @@ void DolphinMainWindow::rememberClosedTab(int index)
     const QString primaryPath = m_viewTab[index].primaryView->url().path();
     const QString iconName = KMimeType::iconNameForUrl(primaryPath);
 
-    const QFontMetrics fm = fontMetrics();
-    const QString actionText = fm.elidedText(primaryPath, Qt::ElideMiddle, fm.maxWidth() * 20);
-
-    QAction* action = new QAction(actionText, tabsMenu);
+    QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
 
     ClosedTab closedTab;
     closedTab.primaryUrl = m_viewTab[index].primaryView->url();
@@ -1493,13 +1571,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"));
     }
 }
@@ -1508,7 +1589,7 @@ QString DolphinMainWindow::tabName(const KUrl& url) const
 {
     QString name;
     if (url.equals(KUrl("file:///"))) {
-        name = "/";
+        name = '/';
     } else {
         name = url.fileName();
         if (name.isEmpty()) {
@@ -1570,6 +1651,12 @@ void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
     setCaption(caption);
 }
 
+QString DolphinMainWindow::squeezedText(const QString& text) const
+{
+    const QFontMetrics fm = fontMetrics();
+    return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
+}
+
 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
     KIO::FileUndoManager::UiInterface()
 {