]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
use DBus interface instead of KRun::runCommand()
[dolphin.git] / src / dolphinmainwindow.cpp
index 95108724ee4b520e23c8447411c8d83b74d6d5a6..e14cb1c2d36fa95424bd368a14064b8708b3541e 100644 (file)
@@ -75,6 +75,7 @@
 #include <kurl.h>
 #include <kurlcombobox.h>
 
+#include <QDBusMessage>
 #include <QKeyEvent>
 #include <QClipboard>
 #include <QLineEdit>
@@ -201,9 +202,9 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
     updateEditActions();
 
     Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
-    int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedUrls().count();
+    int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
     if (m_viewTab[m_tabIndex].secondaryView != 0) {
-        selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls().count();
+        selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
     }
 
     QAction* compareFilesAction = actionCollection()->action("compare_files");
@@ -213,6 +214,9 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
         compareFilesAction->setEnabled(false);
     }
 
+    const bool activeViewHasSelection = (activeViewContainer()->view()->selectedItemsCount() > 0);
+    actionCollection()->action("quick_view")->setEnabled(activeViewHasSelection);
+
     m_activeViewContainer->updateStatusBar();
 
     emit selectionChanged(selection);
@@ -626,6 +630,19 @@ void DolphinMainWindow::compareFiles()
     KRun::runCommand(command, "Kompare", "kompare", this);
 }
 
+void DolphinMainWindow::quickView()
+{
+    const KUrl::List urls = activeViewContainer()->view()->selectedUrls();
+    Q_ASSERT(urls.count() > 0);
+
+    QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.plasma", "/Previewer", "", "openFile");
+    foreach (const KUrl& url, urls) {
+        QList<QVariant> args;
+        msg.setArguments(QList<QVariant>() << url.prettyUrl());
+        QDBusConnection::sessionBus().send(msg);
+    }
+}
+
 void DolphinMainWindow::toggleShowMenuBar()
 {
     const bool visible = menuBar()->isVisible();
@@ -977,6 +994,13 @@ void DolphinMainWindow::setupActions()
     compareFiles->setEnabled(false);
     connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
 
+    KAction* quickView = actionCollection()->addAction("quick_view");
+    quickView->setText(i18nc("@action:inmenu Tools", "Quick View"));
+    quickView->setIcon(KIcon("view-preview"));
+    quickView->setShortcut(Qt::Key_Space);
+    quickView->setEnabled(false);
+    connect(quickView, SIGNAL(triggered()), this, SLOT(quickView()));
+
     // setup 'Settings' menu
     m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
     KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());