1 /***************************************************************************
2 * Copyright (C) 2014 by Gregor Mi <codestruct@posteo.org> *
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. *
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. *
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 ***************************************************************************/
20 #include "spaceinfotoolsmenu.h"
25 #include <KMountPoint>
26 #include <KLocalizedString>
30 SpaceInfoToolsMenu::SpaceInfoToolsMenu(QWidget
* parent
, QUrl url
)
33 const QString notInstalled
= " [" + i18nc("@action:inmenu", "not installed") + "]";
37 const auto filelightService
= KService::serviceByDesktopName("org.kde.filelight");
38 if (filelightService
&& filelightService
->isApplication()) {
39 const auto filelightIcon
= QIcon::fromTheme(filelightService
->icon());
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
44 const auto startFilelightDirectoryAction
= addAction(filelightService
->genericName() + " - "
45 + i18nc("@action:inmenu", "current folder"));
46 startFilelightDirectoryAction
->setIcon(filelightIcon
);
48 connect(startFilelightDirectoryAction
, &QAction::triggered
, this, [filelightService
, url
](bool) {
49 KRun::runService(*filelightService
, { url
}, nullptr);
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
56 const auto startFilelightDeviceAction
= addAction(filelightService
->genericName() + " - "
57 + i18nc("@action:inmenu", "current device"));
58 startFilelightDeviceAction
->setIcon(filelightIcon
);
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);
66 // add action and connect signals
68 const auto startFilelightAllDevicesAction
= addAction(filelightService
->genericName() + " - "
69 + i18nc("@action:inmenu", "all devices"));
70 startFilelightAllDevicesAction
->setIcon(filelightIcon
);
72 connect(startFilelightAllDevicesAction
, &QAction::triggered
, this, [filelightService
](bool) {
73 KRun::runService(*filelightService
, { }, nullptr);
76 const auto startFilelightDirectoryAction
= addAction("Filelight" + notInstalled
);
77 startFilelightDirectoryAction
->setEnabled(false);
82 const auto kdiskfreeService
= KService::serviceByDesktopName("kdf");
83 if (kdiskfreeService
&& kdiskfreeService
->isApplication()) {
85 // add action and connect signals
87 const auto startKDiskFreeAction
= addAction(kdiskfreeService
->genericName());
88 startKDiskFreeAction
->setIcon(QIcon::fromTheme(kdiskfreeService
->icon()));
90 connect(startKDiskFreeAction
, &QAction::triggered
, this, [kdiskfreeService
](bool) {
91 KRun::runService(*kdiskfreeService
, { }, nullptr);
94 const auto startKDiskFreeAction
= addAction("KDiskFree" + notInstalled
);
95 startKDiskFreeAction
->setEnabled(false);
99 SpaceInfoToolsMenu::~SpaceInfoToolsMenu()