]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Remove SpaceInfoToolsMenu and use KMoreToolsMenuFactory instead
authorGregor Mi <codestruct@posteo.org>
Sun, 3 May 2015 18:40:04 +0000 (20:40 +0200)
committerGregor Mi <codestruct@posteo.org>
Sun, 3 May 2015 18:42:23 +0000 (20:42 +0200)
Reduces the amount of needed code.
NEW: by using KMoreTools the menu is now user-configurable and
will automatically extended when KMoreToolsPresets gets new tools.
REVIEW: 122911

src/CMakeLists.txt
src/statusbar/spaceinfotoolsmenu.cpp [deleted file]
src/statusbar/spaceinfotoolsmenu.h [deleted file]
src/statusbar/statusbarspaceinfo.cpp

index 560545aed687c081fef50cf9fa5afa212ee0fb18..498e7c596edcd3c4d6d8793a7af49a8ca9ccd083 100644 (file)
@@ -242,7 +242,6 @@ set(dolphin_SRCS
     statusbar/dolphinstatusbar.cpp
     statusbar/mountpointobserver.cpp
     statusbar/mountpointobservercache.cpp
-    statusbar/spaceinfotoolsmenu.cpp
     statusbar/spaceinfoobserver.cpp
     statusbar/statusbarspaceinfo.cpp
     views/zoomlevelinfo.cpp
diff --git a/src/statusbar/spaceinfotoolsmenu.cpp b/src/statusbar/spaceinfotoolsmenu.cpp
deleted file mode 100644 (file)
index 40ca56e..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/***************************************************************************
- *   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)
-{
-    // find service
-    //
-    const auto filelightService = KService::serviceByDesktopName("org.kde.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(i18nc("@action:inmenu %1 service name", "%1 - current folder", filelightService->genericName()));
-            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(i18nc("@action:inmenu %1 service name", "%1 - current device", filelightService->genericName()));
-            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(i18nc("@action:inmenu %1 service name", "%1 - all devices", filelightService->genericName()));
-        startFilelightAllDevicesAction->setIcon(filelightIcon);
-
-        connect(startFilelightAllDevicesAction, &QAction::triggered, this, [filelightService](bool) {
-            KRun::runService(*filelightService, { }, nullptr);
-        });
-    } else {
-        const auto startFilelightDirectoryAction = addAction(i18nc("@action:inmenu", "Filelight [not installed]"));
-        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(i18nc("@action:inmenu", "KDiskFree [not installed]"));
-        startKDiskFreeAction->setEnabled(false);
-    }
-}
-
-SpaceInfoToolsMenu::~SpaceInfoToolsMenu()
-{
-}
-
-
diff --git a/src/statusbar/spaceinfotoolsmenu.h b/src/statusbar/spaceinfotoolsmenu.h
deleted file mode 100644 (file)
index 3ca2e18..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/***************************************************************************
- *   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 127641e601d1468479ef925f9539ecd31dc12fb7..29135566f1a0ea26e5609f62900e19062940a9c0 100644 (file)
 #include "statusbarspaceinfo.h"
 
 #include "spaceinfoobserver.h"
-#include "spaceinfotoolsmenu.h"
 
 #include <QMouseEvent>
 
 #include <KLocalizedString>
+#include <KNS3/KMoreToolsMenuFactory>
 #include <KIO/Job>
 
 
@@ -71,8 +71,16 @@ void StatusBarSpaceInfo::hideEvent(QHideEvent* event)
 void StatusBarSpaceInfo::mousePressEvent(QMouseEvent* event)
 {
     if (event->button() == Qt::LeftButton) {
-        SpaceInfoToolsMenu spaceInfoToolsMenu(this, m_url);
-        spaceInfoToolsMenu.exec(QCursor::pos());
+        // Creates a menu with tools that help to find out more about free
+        // disk space for the given url.
+
+        // Note that this object must live long enough in case the user opens
+        // the "Configure..." dialog
+        KMoreToolsMenuFactory menuFactory("dolphin/statusbar-diskspace-menu");
+        auto menu = menuFactory.createMenuFromGroupingNames(
+            { "disk-usage", "more:", "disk-partitions" }, m_url);
+
+        menu->exec(QCursor::pos());
     }
 }