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
)
35 const auto filelightService
= KService::serviceByDesktopName("org.kde.filelight");
36 if (filelightService
&& filelightService
->isApplication()) {
37 const auto filelightIcon
= QIcon::fromTheme(filelightService
->icon());
39 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
40 // add action and connect signals
42 const auto startFilelightDirectoryAction
= addAction(i18nc("@action:inmenu %1 service name", "%1 - current folder", filelightService
->genericName()));
43 startFilelightDirectoryAction
->setIcon(filelightIcon
);
45 connect(startFilelightDirectoryAction
, &QAction::triggered
, this, [filelightService
, url
](bool) {
46 KRun::runService(*filelightService
, { url
}, nullptr);
50 if (url
.isLocalFile()) { // makes no sense for non-local URLs (e.g. FTP server), so we don't offer it in this case
51 // add action and connect signals
53 const auto startFilelightDeviceAction
= addAction(i18nc("@action:inmenu %1 service name", "%1 - current device", filelightService
->genericName()));
54 startFilelightDeviceAction
->setIcon(filelightIcon
);
56 connect(startFilelightDeviceAction
, &QAction::triggered
, this, [filelightService
, url
](bool) {
57 KMountPoint::Ptr mountPoint
= KMountPoint::currentMountPoints().findByPath(url
.toLocalFile());
58 KRun::runService(*filelightService
, { mountPoint
->mountPoint() }, nullptr);
62 // add action and connect signals
64 const auto startFilelightAllDevicesAction
= addAction(i18nc("@action:inmenu %1 service name", "%1 - all devices", filelightService
->genericName()));
65 startFilelightAllDevicesAction
->setIcon(filelightIcon
);
67 connect(startFilelightAllDevicesAction
, &QAction::triggered
, this, [filelightService
](bool) {
68 KRun::runService(*filelightService
, { }, nullptr);
71 const auto startFilelightDirectoryAction
= addAction(i18nc("@action:inmenu", "Filelight [not installed]"));
72 startFilelightDirectoryAction
->setEnabled(false);
77 const auto kdiskfreeService
= KService::serviceByDesktopName("kdf");
78 if (kdiskfreeService
&& kdiskfreeService
->isApplication()) {
80 // add action and connect signals
82 const auto startKDiskFreeAction
= addAction(kdiskfreeService
->genericName());
83 startKDiskFreeAction
->setIcon(QIcon::fromTheme(kdiskfreeService
->icon()));
85 connect(startKDiskFreeAction
, &QAction::triggered
, this, [kdiskfreeService
](bool) {
86 KRun::runService(*kdiskfreeService
, { }, nullptr);
89 const auto startKDiskFreeAction
= addAction(i18nc("@action:inmenu", "KDiskFree [not installed]"));
90 startKDiskFreeAction
->setEnabled(false);
94 SpaceInfoToolsMenu::~SpaceInfoToolsMenu()