]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add disk usage statistics menu to SpaceInfo widget in the status bar:
authorGregor Mi <codestruct@posteo.org>
Mon, 12 Jan 2015 15:18:50 +0000 (16:18 +0100)
committerGregor Mi <codestruct@posteo.org>
Mon, 12 Jan 2015 15:18:50 +0000 (16:18 +0100)
the menu has the following entries:

1. Filelight location
2. Filelight device
3. Filelight
4. KDiskFree

KService is used to find the applications and display proper
translations.
KRun is used to run the applications.

REVIEW: 121478
CHANGELOG: Add a menu on left-click on the SpaceInfo widget in the status bar to show Disk Usage statistics.

src/CMakeLists.txt
src/statusbar/spaceinfotoolsmenu.cpp [new file with mode: 0644]
src/statusbar/spaceinfotoolsmenu.h [new file with mode: 0644]
src/statusbar/statusbarspaceinfo.cpp
src/statusbar/statusbarspaceinfo.h

index f132e2844d54d08fa99b6c5ef8c5da6dfdb07514..d2ea4931431bf6b73ec9fa46ae84a7a65d142d6b 100644 (file)
@@ -198,6 +198,7 @@ set(dolphin_SRCS
     statusbar/dolphinstatusbar.cpp
     statusbar/mountpointobserver.cpp
     statusbar/mountpointobservercache.cpp
     statusbar/dolphinstatusbar.cpp
     statusbar/mountpointobserver.cpp
     statusbar/mountpointobservercache.cpp
+    statusbar/spaceinfotoolsmenu.cpp
     statusbar/spaceinfoobserver.cpp
     statusbar/statusbarspaceinfo.cpp
     views/zoomlevelinfo.cpp
     statusbar/spaceinfoobserver.cpp
     statusbar/statusbarspaceinfo.cpp
     views/zoomlevelinfo.cpp
diff --git a/src/statusbar/spaceinfotoolsmenu.cpp b/src/statusbar/spaceinfotoolsmenu.cpp
new file mode 100644 (file)
index 0000000..bd3d648
--- /dev/null
@@ -0,0 +1,103 @@
+/***************************************************************************
+ *   Copyright (C) 2014 by Gregor Mi <codestruct@posteo.org>               *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#include "spaceinfotoolsmenu.h"
+
+#include <QAction>
+#include <QUrl>
+
+#include <KMountPoint>
+#include <KLocalizedString>
+#include <KRun>
+#include <KService>
+
+SpaceInfoToolsMenu::SpaceInfoToolsMenu(QWidget* parent, QUrl url)
+    : QMenu(parent)
+{
+    const QString notInstalled = " [" + i18nc("@action:inmenu", "not installed") + "]";
+
+    // find service
+    //
+    const auto filelightService = KService::serviceByDesktopName("filelight");
+    if (filelightService && filelightService->isApplication()) {
+        const auto filelightIcon = QIcon::fromTheme(filelightService->icon());
+
+        if (url.isLocalFile()) { // 2015-01-12: Filelight can handle FTP connections but KIO/kioexec cannot (bug or feature?), so we don't offer it in this case
+            // add action and connect signals
+            //
+            const auto startFilelightDirectoryAction = addAction(filelightService->genericName() + " - "
+                    + i18nc("@action:inmenu", "current folder"));
+            startFilelightDirectoryAction->setIcon(filelightIcon);
+
+            connect(startFilelightDirectoryAction, &QAction::triggered, this, [filelightService, url](bool) {
+                KRun::runService(*filelightService, { url }, nullptr);
+            });
+        }
+
+        if (url.isLocalFile()) { // makes no sense for non-local URLs (e.g. FTP server), so we don't offer it in this case
+            // add action and connect signals
+            //
+            const auto startFilelightDeviceAction = addAction(filelightService->genericName() + " - "
+                                                    + i18nc("@action:inmenu", "current device"));
+            startFilelightDeviceAction->setIcon(filelightIcon);
+
+            connect(startFilelightDeviceAction, &QAction::triggered, this, [filelightService, url](bool) {
+                KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(url.toLocalFile());
+                KRun::runService(*filelightService, { mountPoint->mountPoint() }, nullptr);
+            });
+        }
+
+        // add action and connect signals
+        //
+        const auto startFilelightAllDevicesAction = addAction(filelightService->genericName() + " - "
+                + i18nc("@action:inmenu", "all devices"));
+        startFilelightAllDevicesAction->setIcon(filelightIcon);
+
+        connect(startFilelightAllDevicesAction, &QAction::triggered, this, [filelightService](bool) {
+            KRun::runService(*filelightService, { }, nullptr);
+        });
+    } else {
+        const auto startFilelightDirectoryAction = addAction("Filelight" + notInstalled);
+        startFilelightDirectoryAction->setEnabled(false);
+    }
+
+    // find service
+    //
+    const auto kdiskfreeService = KService::serviceByDesktopName("kdf");
+    if (kdiskfreeService && kdiskfreeService->isApplication()) {
+        //
+        // add action and connect signals
+        //
+        const auto startKDiskFreeAction = addAction(kdiskfreeService->genericName());
+        startKDiskFreeAction->setIcon(QIcon::fromTheme(kdiskfreeService->icon()));
+
+        connect(startKDiskFreeAction, &QAction::triggered, this, [kdiskfreeService](bool) {
+            KRun::runService(*kdiskfreeService, { }, nullptr);
+        });
+    } else {
+        const auto startKDiskFreeAction = addAction("KDiskFree" + notInstalled);
+        startKDiskFreeAction->setEnabled(false);
+    }
+}
+
+SpaceInfoToolsMenu::~SpaceInfoToolsMenu()
+{
+}
+
+
diff --git a/src/statusbar/spaceinfotoolsmenu.h b/src/statusbar/spaceinfotoolsmenu.h
new file mode 100644 (file)
index 0000000..3ca2e18
--- /dev/null
@@ -0,0 +1,41 @@
+/***************************************************************************
+ *   Copyright (C) 2014 by Gregor Mi <codestruct@posteo.org>               *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#ifndef SPACEINFOTOOLSMENU_H
+#define SPACEINFOTOOLSMENU_H
+
+#include <QObject>
+#include <QMenu>
+
+class QWidget;
+class QUrl;
+
+/**
+ * A menu with tools that help to find out more about free disk space for the given url.
+ */
+class SpaceInfoToolsMenu : public QMenu
+{
+    Q_OBJECT
+
+public:
+    explicit SpaceInfoToolsMenu(QWidget* parent, QUrl url);
+    virtual ~SpaceInfoToolsMenu();
+};
+
+#endif
index 046cbbb23072648aece5677defb1b9074baa9482..127641e601d1468479ef925f9539ecd31dc12fb7 100644 (file)
@@ -21,6 +21,9 @@
 #include "statusbarspaceinfo.h"
 
 #include "spaceinfoobserver.h"
 #include "statusbarspaceinfo.h"
 
 #include "spaceinfoobserver.h"
+#include "spaceinfotoolsmenu.h"
+
+#include <QMouseEvent>
 
 #include <KLocalizedString>
 #include <KIO/Job>
 
 #include <KLocalizedString>
 #include <KIO/Job>
@@ -65,6 +68,14 @@ void StatusBarSpaceInfo::hideEvent(QHideEvent* event)
     KCapacityBar::hideEvent(event);
 }
 
     KCapacityBar::hideEvent(event);
 }
 
+void StatusBarSpaceInfo::mousePressEvent(QMouseEvent* event)
+{
+    if (event->button() == Qt::LeftButton) {
+        SpaceInfoToolsMenu spaceInfoToolsMenu(this, m_url);
+        spaceInfoToolsMenu.exec(QCursor::pos());
+    }
+}
+
 void StatusBarSpaceInfo::slotValuesChanged()
 {
     Q_ASSERT(m_observer);
 void StatusBarSpaceInfo::slotValuesChanged()
 {
     Q_ASSERT(m_observer);
index 5d571beba9b936c52dd3279e370c39a1bfd50827..2ba7cbf0b25488a843faf6a00a4ff8aa999beb12 100644 (file)
@@ -27,6 +27,7 @@
 
 class QHideEvent;
 class QShowEvent;
 
 class QHideEvent;
 class QShowEvent;
+class QMouseEvent;
 
 class SpaceInfoObserver;
 
 
 class SpaceInfoObserver;
 
@@ -48,6 +49,7 @@ public:
 protected:
     void showEvent(QShowEvent* event) Q_DECL_OVERRIDE;
     void hideEvent(QHideEvent* event) Q_DECL_OVERRIDE;
 protected:
     void showEvent(QShowEvent* event) Q_DECL_OVERRIDE;
     void hideEvent(QHideEvent* event) Q_DECL_OVERRIDE;
+    void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
 
 private slots:
     void slotValuesChanged();
 
 private slots:
     void slotValuesChanged();