]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbar/spaceinfotoolsmenu.cpp
Update desktop filename for filelight.
[dolphin.git] / src / statusbar / spaceinfotoolsmenu.cpp
1 /***************************************************************************
2 * Copyright (C) 2014 by Gregor Mi <codestruct@posteo.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "spaceinfotoolsmenu.h"
21
22 #include <QAction>
23 #include <QUrl>
24
25 #include <KMountPoint>
26 #include <KLocalizedString>
27 #include <KRun>
28 #include <KService>
29
30 SpaceInfoToolsMenu::SpaceInfoToolsMenu(QWidget* parent, QUrl url)
31 : QMenu(parent)
32 {
33 const QString notInstalled = " [" + i18nc("@action:inmenu", "not installed") + "]";
34
35 // find service
36 //
37 const auto filelightService = KService::serviceByDesktopName("org.kde.filelight");
38 if (filelightService && filelightService->isApplication()) {
39 const auto filelightIcon = QIcon::fromTheme(filelightService->icon());
40
41 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
42 // add action and connect signals
43 //
44 const auto startFilelightDirectoryAction = addAction(filelightService->genericName() + " - "
45 + i18nc("@action:inmenu", "current folder"));
46 startFilelightDirectoryAction->setIcon(filelightIcon);
47
48 connect(startFilelightDirectoryAction, &QAction::triggered, this, [filelightService, url](bool) {
49 KRun::runService(*filelightService, { url }, nullptr);
50 });
51 }
52
53 if (url.isLocalFile()) { // makes no sense for non-local URLs (e.g. FTP server), so we don't offer it in this case
54 // add action and connect signals
55 //
56 const auto startFilelightDeviceAction = addAction(filelightService->genericName() + " - "
57 + i18nc("@action:inmenu", "current device"));
58 startFilelightDeviceAction->setIcon(filelightIcon);
59
60 connect(startFilelightDeviceAction, &QAction::triggered, this, [filelightService, url](bool) {
61 KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(url.toLocalFile());
62 KRun::runService(*filelightService, { mountPoint->mountPoint() }, nullptr);
63 });
64 }
65
66 // add action and connect signals
67 //
68 const auto startFilelightAllDevicesAction = addAction(filelightService->genericName() + " - "
69 + i18nc("@action:inmenu", "all devices"));
70 startFilelightAllDevicesAction->setIcon(filelightIcon);
71
72 connect(startFilelightAllDevicesAction, &QAction::triggered, this, [filelightService](bool) {
73 KRun::runService(*filelightService, { }, nullptr);
74 });
75 } else {
76 const auto startFilelightDirectoryAction = addAction("Filelight" + notInstalled);
77 startFilelightDirectoryAction->setEnabled(false);
78 }
79
80 // find service
81 //
82 const auto kdiskfreeService = KService::serviceByDesktopName("kdf");
83 if (kdiskfreeService && kdiskfreeService->isApplication()) {
84 //
85 // add action and connect signals
86 //
87 const auto startKDiskFreeAction = addAction(kdiskfreeService->genericName());
88 startKDiskFreeAction->setIcon(QIcon::fromTheme(kdiskfreeService->icon()));
89
90 connect(startKDiskFreeAction, &QAction::triggered, this, [kdiskfreeService](bool) {
91 KRun::runService(*kdiskfreeService, { }, nullptr);
92 });
93 } else {
94 const auto startKDiskFreeAction = addAction("KDiskFree" + notInstalled);
95 startKDiskFreeAction->setEnabled(false);
96 }
97 }
98
99 SpaceInfoToolsMenu::~SpaceInfoToolsMenu()
100 {
101 }
102
103