diff --git a/freespacenotifier/CMakeLists.txt b/freespacenotifier/CMakeLists.txt index 259bc66f5..0ba68ed9f 100644 --- a/freespacenotifier/CMakeLists.txt +++ b/freespacenotifier/CMakeLists.txt @@ -1,27 +1,30 @@ add_definitions(-DTRANSLATION_DOMAIN=\"freespacenotifier\") set(kded_freespacenotifier_SRCS freespacenotifier.cpp module.cpp) ki18n_wrap_ui(kded_freespacenotifier_SRCS freespacenotifier_prefs_base.ui) +qt5_add_dbus_interface(kded_freespacenotifier_SRCS ${KDED_DBUS_INTERFACE} kded_interface) + kconfig_add_kcfg_files(kded_freespacenotifier_SRCS settings.kcfgc) add_library(freespacenotifier MODULE ${kded_freespacenotifier_SRCS}) kcoreaddons_desktop_to_json(freespacenotifier freespacenotifier.desktop) target_link_libraries(freespacenotifier KF5::ConfigWidgets KF5::DBusAddons KF5::I18n KF5::KIOCore - KF5::KIOWidgets + KF5::KIOGui KF5::Notifications + KF5::Service ) install(TARGETS freespacenotifier DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kded ) ########### install files ############### install( FILES freespacenotifier.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR} ) install( FILES freespacenotifier.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR} ) diff --git a/freespacenotifier/freespacenotifier.cpp b/freespacenotifier/freespacenotifier.cpp index fee305874..c34b6d001 100644 --- a/freespacenotifier/freespacenotifier.cpp +++ b/freespacenotifier/freespacenotifier.cpp @@ -1,259 +1,167 @@ /* This file is part of the KDE Project Copyright (c) 2006 Lukas Tinkl Copyright (c) 2008 Lubos Lunak Copyright (c) 2009 Ivo Anjo + Copyright (c) 2020 Kai Uwe Broulik 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, see . */ #include "freespacenotifier.h" -#include -#include -#include -#include - #include -#include -#include -#include #include +#include +#include +#include #include +#include + +#include #include "settings.h" -#include "ui_freespacenotifier_prefs_base.h" -FreeSpaceNotifier::FreeSpaceNotifier(QObject *parent) +FreeSpaceNotifier::FreeSpaceNotifier(const QString &path, const KLocalizedString ¬ificationText, QObject *parent) : QObject(parent) - , m_lastAvailTimer(nullptr) - , m_notification(nullptr) - , m_sni(nullptr) - , m_lastAvail(-1) + , m_path(path) + , m_notificationText(notificationText) { - // If we are running, notifications are enabled - FreeSpaceNotifierSettings::setEnableNotification(true); - - connect(&timer, &QTimer::timeout, this, &FreeSpaceNotifier::checkFreeDiskSpace); - timer.start(1000 * 60 /* 1 minute */); + connect(&m_timer, &QTimer::timeout, this, &FreeSpaceNotifier::checkFreeDiskSpace); + m_timer.start(std::chrono::minutes(1)); } FreeSpaceNotifier::~FreeSpaceNotifier() { - // The notification is automatically destroyed when it goes away, so we only need to do this if - // it is still being shown if (m_notification) { m_notification->close(); } - - if (m_sni) { - m_sni->deleteLater(); - } } void FreeSpaceNotifier::checkFreeDiskSpace() { if (!FreeSpaceNotifierSettings::enableNotification()) { // do nothing if notifying is disabled; // also stop the timer that probably got us here in the first place - timer.stop(); - + m_timer.stop(); return; } - auto *job = KIO::fileSystemFreeSpace(QUrl::fromLocalFile(QDir::homePath())); + auto *job = KIO::fileSystemFreeSpace(QUrl::fromLocalFile(m_path)); connect(job, &KIO::FileSystemFreeSpaceJob::result, this, [this](KIO::Job* job, KIO::filesize_t size, KIO::filesize_t available) { if (job->error()) { return; } - int limit = FreeSpaceNotifierSettings::minimumSpace(); // MiB - qint64 avail = available / (1024 * 1024); // to MiB - bool warn = false; + const int limit = FreeSpaceNotifierSettings::minimumSpace(); // MiB + const qint64 avail = available / (1024 * 1024); // to MiB - if (avail < limit) { - // avail disk space dropped under a limit - if (m_lastAvail < 0 || avail < m_lastAvail / 2) { // always warn the first time or when available dropped to a half of previous one, warn again - m_lastAvail = avail; - warn = true; - } else if (avail > m_lastAvail) { // the user freed some space - m_lastAvail = avail; // so warn if it goes low again - if (m_sni) { - // keep the SNI active, but don't blink - m_sni->setStatus(KStatusNotifierItem::Active); - m_sni->setToolTip(QStringLiteral("drive-harddisk"), i18n("Low Disk Space"), i18n("Remaining space in your Home folder: %1 MiB", QLocale::system().toString(avail))); - } + if (avail >= limit) { + if (m_notification) { + m_notification->close(); } - // do not change lastAvail otherwise, to handle free space slowly going down + return; + } - if (warn) { - int availpct = int(100 * available / size); - if (!m_sni) { - m_sni = new KStatusNotifierItem(QStringLiteral("freespacenotifier")); - m_sni->setIconByName(QStringLiteral("drive-harddisk")); - m_sni->setOverlayIconByName(QStringLiteral("dialog-warning")); - m_sni->setTitle(i18n("Low Disk Space")); - m_sni->setCategory(KStatusNotifierItem::Hardware); + const int availPercent = int(100 * available / size); + const QString text = m_notificationText.subs(avail).subs(availPercent).toString(); - QMenu *sniMenu = new QMenu(); - QAction *action = new QAction(i18nc("Opens a file manager like dolphin", "Open File Manager..."), nullptr); - connect(action, &QAction::triggered, this, &FreeSpaceNotifier::openFileManager); - sniMenu->addAction(action); + // Make sure the notification text is always up to date whenever we checked free space + if (m_notification) { + m_notification->setText(text); + } - action = new QAction(i18nc("Allows the user to configure the warning notification being shown", "Configure Warning..."), nullptr); - connect(action, &QAction::triggered, this, &FreeSpaceNotifier::showConfiguration); - sniMenu->addAction(action); + // User freed some space, warn if it goes low again + if (m_lastAvail > -1 && avail > m_lastAvail) { + m_lastAvail = avail; + return; + } - action = new QAction(i18nc("Allows the user to hide this notifier item", "Hide"), nullptr); - connect(action, &QAction::triggered, this, &FreeSpaceNotifier::hideSni); - sniMenu->addAction(action); + // Always warn the first time or when available space dropped to half of the previous time + const bool warn = (m_lastAvail < 0 || avail < m_lastAvail / 2); + if (!warn) { + return; + } - m_sni->setContextMenu(sniMenu); - m_sni->setStandardActionsEnabled(false); - } + m_lastAvail = avail; - m_sni->setStatus(KStatusNotifierItem::NeedsAttention); - m_sni->setToolTip(QStringLiteral("drive-harddisk"), i18n("Low Disk Space"), i18n("Remaining space in your Home folder: %1 MiB", QLocale::system().toString(avail))); + if (!m_notification) { + m_notification = new KNotification(QStringLiteral("freespacenotif")); + m_notification->setComponentName(QStringLiteral("freespacenotifier")); + m_notification->setText(text); - m_notification = new KNotification(QStringLiteral("freespacenotif")); + QStringList actions = {i18n("Configure Warning...")}; - m_notification->setText(i18nc("Warns the user that the system is running low on space on his home folder, indicating the percentage and absolute MiB size remaining", - "Your Home folder is running out of disk space, you have %1 MiB remaining (%2%)", QLocale::system().toString(avail), availpct)); + auto filelight = filelightService(); + if (filelight) { + actions.prepend(i18n("Open in Filelight")); + } else { + // Do we really want the user opening Root in a file manager? + actions.prepend(i18n("Open in File Manager")); + } - connect(m_notification, &KNotification::closed, this, &FreeSpaceNotifier::cleanupNotification); + m_notification->setActions(actions); - m_notification->setComponentName(QStringLiteral("freespacenotifier")); - m_notification->sendEvent(); - } - } else { - // free space is above limit again, remove the SNI - if (m_sni) { - m_sni->deleteLater(); - m_sni = nullptr; - } - } - }); -} + connect(m_notification, QOverload::of(&KNotification::activated), this, [this](uint actionId) { + if (actionId == 1) { + exploreDrive(); + // TODO once we have "configure" action support in KNotification, wire it up instead of a button + } else if (actionId == 2) { + emit configureRequested(); + } + }); -void FreeSpaceNotifier::hideSni() -{ - if (m_sni) { - m_sni->setStatus(KStatusNotifierItem::Passive); - QAction *action = qobject_cast(sender()); - if (action) { - action->setDisabled(true); + connect(m_notification, &KNotification::closed, this, &FreeSpaceNotifier::onNotificationClosed); + m_notification->sendEvent(); } - } + }); } -void FreeSpaceNotifier::openFileManager() +KService::Ptr FreeSpaceNotifier::filelightService() const { - cleanupNotification(); - new KRun(QUrl::fromLocalFile(QDir::homePath()), nullptr); - - if (m_sni) { - m_sni->setStatus(KStatusNotifierItem::Active); - } + return KService::serviceByDesktopName(QStringLiteral("org.kde.filelight")); } -void FreeSpaceNotifier::showConfiguration() +void FreeSpaceNotifier::exploreDrive() { - cleanupNotification(); - - if (KConfigDialog::showDialog(QStringLiteral("settings"))) { + auto service = filelightService(); + if (!service) { + auto *job = new KIO::OpenUrlJob({QUrl::fromLocalFile(m_path)}); + job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoErrorHandlingEnabled)); + job->start(); return; } - KConfigDialog *dialog = new KConfigDialog(nullptr, QStringLiteral("settings"), FreeSpaceNotifierSettings::self()); - QWidget *generalSettingsDlg = new QWidget(); - - Ui::freespacenotifier_prefs_base preferences; - preferences.setupUi(generalSettingsDlg); - - dialog->addPage(generalSettingsDlg, - i18nc("The settings dialog main page name, as in 'general settings'", "General"), - QStringLiteral("system-run")); - - connect(dialog, &KConfigDialog::finished, this, &FreeSpaceNotifier::configDialogClosed); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); - - if (m_sni) { - m_sni->setStatus(KStatusNotifierItem::Active); - } + auto *job = new KIO::ApplicationLauncherJob(service); + job->setUrls({QUrl::fromLocalFile(m_path)}); + job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoErrorHandlingEnabled)); + job->start(); } -void FreeSpaceNotifier::cleanupNotification() +void FreeSpaceNotifier::onNotificationClosed() { - if (m_notification) { - m_notification->close(); - } - m_notification = nullptr; - // warn again if constantly below limit for too long if (!m_lastAvailTimer) { m_lastAvailTimer = new QTimer(this); connect(m_lastAvailTimer, &QTimer::timeout, this, &FreeSpaceNotifier::resetLastAvailable); } - m_lastAvailTimer->start(1000 * 60 * 60 /* 1 hour*/); + m_lastAvailTimer->start(std::chrono::hours(1)); } void FreeSpaceNotifier::resetLastAvailable() { m_lastAvail = -1; m_lastAvailTimer->deleteLater(); m_lastAvailTimer = nullptr; } - -void FreeSpaceNotifier::configDialogClosed() -{ - if (!FreeSpaceNotifierSettings::enableNotification()) { - disableFSNotifier(); - } -} - -/* The idea here is to disable ourselves by telling kded to stop autostarting us, and - * to kill the current running instance. - */ -void FreeSpaceNotifier::disableFSNotifier() -{ - QDBusInterface iface(QStringLiteral("org.kde.kded5"), - QStringLiteral("/kded"), - QStringLiteral("org.kde.kded5") ); - if (dbusError(iface)) { - return; - } - - // Disable current module autoload - iface.call(QStringLiteral("setModuleAutoloading"), QStringLiteral("freespacenotifier"), false); - if (dbusError(iface)) { - return; - } - - // Unload current module - iface.call(QStringLiteral("unloadModule"), QStringLiteral("freespacenotifier")); - if (dbusError(iface)) { - return; - } -} - -bool FreeSpaceNotifier::dbusError(QDBusInterface &iface) -{ - const QDBusError err = iface.lastError(); - if (err.isValid()) { - qCritical() << "Failed to perform operation on kded [" << err.name() << "]:" << err.message(); - return true; - } - return false; -} diff --git a/freespacenotifier/freespacenotifier.h b/freespacenotifier/freespacenotifier.h index 4a222960b..8ccbeef59 100644 --- a/freespacenotifier/freespacenotifier.h +++ b/freespacenotifier/freespacenotifier.h @@ -1,57 +1,62 @@ /* This file is part of the KDE Project Copyright (c) 2006 Lukas Tinkl Copyright (c) 2008 Lubos Lunak Copyright (c) 2009 Ivo Anjo + Copyright (c) 2020 Kai Uwe Broulik 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, see . */ #ifndef _FREESPACENOTIFIER_H_ #define _FREESPACENOTIFIER_H_ #include +#include + +#include +#include class KNotification; -class KStatusNotifierItem; -class QDBusInterface; class FreeSpaceNotifier : public QObject { Q_OBJECT public: - explicit FreeSpaceNotifier(QObject *parent = nullptr); + explicit FreeSpaceNotifier(const QString &path, const KLocalizedString ¬ificationText, QObject *parent = nullptr); ~FreeSpaceNotifier() override; -private Q_SLOTS: +signals: + void configureRequested(); + +private: void checkFreeDiskSpace(); void resetLastAvailable(); - void openFileManager(); - void showConfiguration(); - void cleanupNotification(); - void configDialogClosed(); - void hideSni(); -private: - QTimer timer; - QTimer *m_lastAvailTimer; - KNotification *m_notification; - KStatusNotifierItem *m_sni; - qint64 m_lastAvail; // used to suppress repeated warnings when available space hasn't changed - - void disableFSNotifier(); - bool dbusError(QDBusInterface &iface); + KService::Ptr filelightService() const; + void exploreDrive(); + void onNotificationClosed(); + + QString m_path; + KLocalizedString m_notificationText; + + QTimer m_timer; + QTimer *m_lastAvailTimer = nullptr; + QPointer m_notification; + qint64 m_lastAvail = -1; // used to suppress repeated warnings when available space hasn't changed + + }; #endif diff --git a/freespacenotifier/freespacenotifier.notifyrc b/freespacenotifier/freespacenotifier.notifyrc index 511824f6b..3b9da4193 100644 --- a/freespacenotifier/freespacenotifier.notifyrc +++ b/freespacenotifier/freespacenotifier.notifyrc @@ -1,418 +1,419 @@ [Global] IconName=drive-harddisk Comment=KDE Free Space Notifier Daemon Comment[ar]=عفريت مُخطِر كدي للمساحة الحرة Comment[ast]=Degorriu del avisador d'espaciu llibre de KDE Comment[bg]=Демон на KDE за свободно пространство Comment[bn]=কে.ডি.ই. ফ্রী স্পেস বিজ্ঞপ্তি ডিমন Comment[bs]=KDE‑ov demon izveštavača o slobodnom prostoru Comment[ca]=Dimoni de notificacions d'espai lliure del KDE Comment[ca@valencia]=Dimoni de notificacions d'espai lliure de KDE Comment[cs]=Upozorňovací démon volného místa KDE Comment[da]=KDE dæmon til bekendtgørelse om ledig plads Comment[de]=KDE-Dienst für Speicherplatzbenachrichtigung Comment[el]=Δαίμονας ειδοποιήσεων ελευθέρου χώρου του KDE Comment[en_GB]=KDE Free Space Notifier Dæmon Comment[es]=Demonio de notificaciones de espacio libre de KDE Comment[et]=KDE vaba ruumi teavitamise deemon Comment[eu]=KDEren leku askea jakinarazteko daimona Comment[fi]=KDE:n vapaan tilan ilmoitustaustaprosessi Comment[fr]=Démon de notification d'espace libre de KDE Comment[ga]=Fógróir Spáis Shaoir KDE Comment[gl]=Servizo de KDE de notificación do espazo libre Comment[he]=KDE Free Space Notifier Daemon Comment[hi]=केडीई खाली स्थान सूचना डेमन Comment[hr]=KDE-ov servis za obavještavanje o slobodnom prostoru Comment[hu]=KDE szabad hely értesítő szolgáltatás Comment[ia]=Demone de notification de spatio libere de KDE Comment[id]=Daemon Notifikasi RUang Kosong KDE Comment[is]=KDE tilkynningaþjónn fyrir laust pláss Comment[it]=Demone di notifica dello spazio libero di KDE Comment[ja]=KDE 空き領域デーモン Comment[kk]=KDE-нің бос орын туралы құлақтандыру қызметі Comment[km]=ដេមិន​​ជូន​ដំណឹង​​ទំហំ​ទំនេរ​របស់ KDE Comment[kn]=ಕೆಡಿಇ ಖಾಲಿ ಜಾಗ ಸೂಚನಾ ನೇಪಥಿಕ (ಡೀಮನ್) Comment[ko]=KDE 남은 공간 알림 데몬 Comment[lt]=KDE laisvos vietos pranešėjo tarnyba Comment[lv]=KDE brīvās vietas paziņošanas dēmons Comment[ml]=കെഡിഇയിലെ ലഭ്യമായ സ്ഥലം അറിയിയ്ക്കുന്നതിനുള്ള നിരന്തര പ്രവൃത്തി Comment[mr]=केडीई मोकळी जागा निदर्शक डीमन Comment[nb]=KDEs varslingsdaemon for ledig plass Comment[nds]=KDE-Dämoon för Freeruumbescheden Comment[nl]=KDE-daemon voor het melden van vrije ruimte Comment[nn]=KDE-varsel om lite plass Comment[pa]=KDE ਖਾਲੀ ਥਾਂ ਨੋਟੀਫਿਕੇਸ਼ਨ ਡੈਮਨ Comment[pl]=Usługa powiadamiania o wolnym miejscu KDE Comment[pt]=Servidor de Notificação de Espaço Livre do KDE Comment[pt_BR]=Serviço de notificação de espaço livre do KDE Comment[ro]=Demon de notificare KDE a spațiului liber Comment[ru]=Служба уведомлений о свободном месте на диске Comment[si]=KDE හිස් ඉඩ දැනුම්දීමේ ඩීමනය Comment[sk]=Monitor voľného miesta KDE Comment[sl]=KDE-jev obvestilnik o neporabljenem prostoru Comment[sr]=КДЕ‑ов демон извештавача о слободном простору Comment[sr@ijekavian]=КДЕ‑ов демон извјештавача о слободном простору Comment[sr@ijekavianlatin]=KDE‑ov demon izvještavača o slobodnom prostoru Comment[sr@latin]=KDE‑ov demon izveštavača o slobodnom prostoru Comment[sv]=KDE:s demon för information om ledigt utrymme Comment[th]=ดีมอนการแจ้งพื้นที่ว่างของ KDE Comment[tr]=KDE Boş Alan Bildirme Servisi Comment[ug]=KDE بىكار بوشلۇق خەۋەرچى نازارەتچىسى Comment[uk]=Фонова служба сповіщення про переповнення диска KDE Comment[vi]=Trình nền thông báo không gian trống KDE Comment[wa]=Démon KDE notifieu del plaece di libe Comment[x-test]=xxKDE Free Space Notifier Daemonxx Comment[zh_CN]=KDE 空闲空间通知守护程序 Comment[zh_TW]=KDE 剩餘空間通知伺服程式 Name=Low Disk Space Name[ar]=مساحة القرص منخفضة Name[bg]=Дисковото пространство е твърде малко Name[bn]=ডিস্ক-এ জায়গা কম Name[bs]=Malo prostora na disku Name[ca]=Espai escàs al disc Name[ca@valencia]=Espai escàs al disc Name[cs]=Málo místa na disku Name[da]=Lav diskplads Name[de]=Wenig Speicherplatz Name[el]=Χαμηλή χωρητικότητα δίσκου Name[en_GB]=Low Disk Space Name[es]=Poco espacio en disco Name[et]=Kettaruumi napib Name[eu]=Leku gutxi diskoan Name[fi]=Vähäinen levytila Name[fr]=Espace disque faible Name[ga]=Easpa Spáis ar an Diosca Name[gl]=Pouco espazo no disco Name[he]=שטח מועט פנוי בדיסק Name[hi]=डिस्क जगह कम Name[hr]=Malo prostora na disku Name[hu]=Kevés a lemezterület Name[ia]=Spatio de disco basse Name[id]=Ruang Disk Rendah Name[is]=Lítið diskpláss Name[it]=Poco spazio su disco Name[ja]=ディスクの空き領域が少ないです Name[kk]=Дискіде орын тапшылығы Name[km]=ទំហំ​ថាស​ទាប Name[kn]=ಕಡಿಮೆ ಡಿಸ್ಕ್‌ ಜಾಗ Name[ko]=디스크 공간 부족 Name[lt]=Mažai vietos diske Name[lv]=Maz diska vietas Name[mai]=कम डिस्क स्थान Name[ml]=ഡിസ്കില്‍ സഥലം കുറവാണു് Name[mr]=डिस्कवर कमी जागा शिल्लक आहे Name[nb]=Lite diskplass Name[nds]=To minn free Ruum op de Fastplaat Name[nl]=Schijf bijna vol Name[nn]=Lite diskplass Name[pa]=ਘੱਟ ਡਿਸਕ ਥਾਂ Name[pl]=Mało miejsca na dysku Name[pt]=Pouco Espaço em Disco Name[pt_BR]=Pouco espaço em disco Name[ro]=Spațiu pe disc scăzut Name[ru]=Недостаточно места на диске Name[si]=පහත් තැටි ඉඩ Name[sk]=Nedostatok miesta na disku Name[sl]=Prostora na disku je malo Name[sr]=Мало простора на диску Name[sr@ijekavian]=Мало простора на диску Name[sr@ijekavianlatin]=Malo prostora na disku Name[sr@latin]=Malo prostora na disku Name[sv]=Ont om diskutrymme Name[th]=พื้นที่ดิสก์เหลือน้อย Name[tr]=Düşük Disk Alanı Name[ug]=دىسكىدىكى بوشلۇق ئاز Name[uk]=Замало місця на диску Name[vi]=Dung lượng đĩa trống thấp Name[wa]=Pus bråmint d' plaece sol plake Name[x-test]=xxLow Disk Spacexx Name[zh_CN]=磁盘空间低 Name[zh_TW]=磁碟空間過低 [Context/warningnot] Name=Warning Name[af]=Waarskuwing Name[ar]=تحذير Name[as]=সতৰ্কবাণী Name[be]=Папярэджанне Name[be@latin]=Uvaha Name[bg]=Предупреждение Name[bn]=সতর্কবার্তা Name[bn_IN]=সতর্কবার্তা Name[bs]=Upozorenje Name[ca]=Avís Name[ca@valencia]=Avís Name[cs]=Varování Name[csb]=Bôczënk Name[da]=Advarsel Name[de]=Warnung Name[el]=Προειδοποίηση Name[en_GB]=Warning Name[eo]=Averto Name[es]=Aviso Name[et]=Hoiatus Name[eu]=Abisua Name[fi]=Varoitus Name[fr]=Avertissement Name[fy]=Warskôging Name[ga]=Rabhadh Name[gl]=Aviso Name[gu]=ચેતવણી Name[he]=אזהרה Name[hi]=चेतावनी Name[hne]=चेतावनी Name[hr]=Upozorenje Name[hsb]=Kedźbu Name[hu]=Figyelmeztetés Name[ia]=Aviso Name[id]=Peringatan Name[is]=Aðvörun Name[it]=Avviso Name[ja]=警告 Name[kk]=Ескерту Name[km]=ការ​ព្រមាន Name[kn]=ಎಚ್ಚರಿಕೆ Name[ko]=경고 Name[ku]=Hişyarî Name[lt]=Įspėjimas Name[lv]=Brīdinājums Name[mai]=चेतावनी Name[mk]=Предупредување Name[ml]=മുന്നറിയിപ്പു് Name[mr]=इशारा Name[nb]=Advarsel Name[nds]=Wohrschoen Name[ne]=चेतावनी Name[nl]=Waarschuwing Name[nn]=Åtvaring Name[oc]=Alèrta Name[or]=ଚେତାବନୀ Name[pa]=ਚੇਤਾਵਨੀ Name[pl]=Ostrzeżenie Name[pt]=Aviso Name[pt_BR]=Aviso Name[ro]=Atenționare Name[ru]=Предупреждение Name[se]=Várrehus Name[si]=අවවාදය Name[sk]=Varovanie Name[sl]=Opozorilo Name[sr]=Упозорење Name[sr@ijekavian]=Упозорење Name[sr@ijekavianlatin]=Upozorenje Name[sr@latin]=Upozorenje Name[sv]=Varning Name[ta]=எச்சரிக்கை Name[te]=హెచ్చరిక Name[th]=คำเตือน Name[tr]=Uyarı Name[ug]=ئاگاھلاندۇرۇش Name[uk]=Попередження Name[uz]=Ogohnoma Name[uz@cyrillic]=Огоҳнома Name[vi]=Cảnh báo Name[wa]=Adviertixhmint Name[x-test]=xxWarningxx Name[zh_CN]=警告 Name[zh_TW]=警告 Comment=Used for warning notifications Comment[ar]=يُستخدَم لإخطارات التحذير Comment[be@latin]=Dla aścierahalnych paviedamleńniaŭ Comment[bg]=Използва се за предупреждения Comment[bn]=সতর্কীকরণ বিজ্ঞপ্তির জন্য ব্যবহৃত হয় Comment[bs]=Koristi se za obavještenja o upozorenjima Comment[ca]=S'usa per a les notificacions d'avís Comment[ca@valencia]=S'usa per a les notificacions d'avís Comment[cs]=Použito pro varování a upozornění Comment[da]=Bruges til advarselsbekendtgørelser Comment[de]=Verwendet für Warnmeldungen Comment[el]=Χρησιμοποιείται για τις προειδοποιήσεις Comment[en_GB]=Used for warning notifications Comment[eo]=Uzita por avertmesaĝoj Comment[es]=Usado para notificaciones de advertencia Comment[et]=Hoiatuste jaoks Comment[eu]=Abisu-jakinarazpenetarako erabiltzen da Comment[fi]=Käytetään varoitusilmoituksiin Comment[fr]=Utilisé pour les notifications d'avertissements Comment[fy]=Brûkt faor warskôging notifikaasjes Comment[ga]=Úsáidte do rabhaidh Comment[gl]=Emprégase para as notificacións de aviso Comment[gu]=ચેતવણી નોંધણીઓ આપવા માટે વપરાય છે Comment[he]=משמש להתרעות אזהרה Comment[hi]=चेतावनियाँ देने के लिए उपयोग में लिया जाता है Comment[hne]=चेतावनी सूचना बर उपयोग होथे Comment[hr]=Korišten za upozoravajuće obavijesti Comment[hu]=Kezelőprogram figyelmeztető üzenetekhez Comment[ia]=Usate pro notificationes de avisos Comment[id]=Digunakan untuk notifikasi peringatan Comment[is]=Notað fyrir aðvaranir Comment[it]=Usato per notifiche di avviso Comment[ja]=警告の通知に使用 Comment[kk]=Ескерту хабарларға қолданылады Comment[km]=បានប្រើ​សម្រាប់​ការ​ជូន​ព្រមាន Comment[kn]=ಎಚ್ಚರಿಕೆ ಸೂಚನೆಗಳಿಗೆ ಬಳಸಲಾಗುತ್ತದೆ Comment[ko]=경고 알림에 사용됨 Comment[lt]=Naudojama įspėjimo pranešimams Comment[lv]=Izmanto brīdinājumu paziņojumiem Comment[ml]=താക്കീത് അറിയിപ്പുകള്‍ക്കായി ഉപയോഗിക്കുന്നു Comment[mr]=इशारा सूचना करिता वापरले जाते Comment[nb]=Brukt til varselsmeldinger Comment[nds]=Bi Wohrschoen bruukt Comment[nl]=Wordt gebruikt voor waarschuwingsmeldingen Comment[nn]=Er brukt til åtvaringsvarsel Comment[or]=ଚେତାବନୀ ବିଜ୍ଞପ୍ତିଗୁଡ଼ିକ ପାଇଁ ବ୍ୟବହୃତ ହୋଇଥାଏ Comment[pa]=ਚੇਤਾਵਨੀ ਨੋਟੀਫਿਕੇਸ਼ਨ ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ Comment[pl]=Używane do ostrzeżeń Comment[pt]=Usado para as notificações de aviso Comment[pt_BR]=Usado para as notificações de aviso Comment[ro]=Utilizat pentru notificări de avertizare Comment[ru]=Используется для системных уведомлений Comment[si]=අවවාද පණිවුඩ සඳහා යොදාගනී Comment[sk]=Používa sa pre varovné upozornenia Comment[sl]=Uporabljeno za obvestila z opozorili Comment[sr]=Користи се за позорна обавештења Comment[sr@ijekavian]=Користи се за позорна обавјештења Comment[sr@ijekavianlatin]=Koristi se za pozorna obavještenja Comment[sr@latin]=Koristi se za pozorna obaveštenja Comment[sv]=Används för varningsmeddelanden Comment[ta]=Used for warning notifications Comment[te]=హెచ్చరిక నోటీసుల కొరకు వుపయోగించబడింది Comment[th]=ใช้สำหรับการแจ้งเตือนให้ทราบ Comment[tr]=Uyarı bildirimleri için kullanılır Comment[ug]=ئاگاھلاندۇرۇش ئۇقتۇرۇشلىرى ئۈچۈن ئىشلىتىلىدۇ. Comment[uk]=Використовується для попереджень Comment[vi]=Sử dụng cho thông tin cảnh báo Comment[wa]=Eployî po des notifiaedjes d' adviertixhmint Comment[x-test]=xxUsed for warning notificationsxx Comment[zh_CN]=用于发出警告通知 Comment[zh_TW]=用於警告通知 [Event/freespacenotif] Name=Running low on disk space Name[ar]=مساحة القرص منخفضة Name[ast]=Pocu espaciu nel discu Name[bg]=Дисковото пространство е твърде малко Name[bn]=ডিস্ক-এ বেশী জায়গা বাকি নেই Name[bs]=Ponestaje prostora na disku Name[ca]=S'està exhaurint l'espai del disc Name[ca@valencia]=S'està exhaurint l'espai del disc Name[cs]=Dochází místo na disku Name[da]=Ved at løbe tør for diskplads Name[de]=Speicherplatz wird knapp Name[el]=Τρέχον χωρητικότητα δίσκου χαμηλή Name[en_GB]=Running low on disk space Name[es]=Queda poco espacio en disco Name[et]=Kettaruumi napib Name[eu]=Leku gutxi gelditzen da diskoan Name[fi]=Levytila alkaa olla lopussa Name[fr]=L'espace disque commence à manquer Name[ga]=Tá an diosca ag éirí lán Name[gl]=Esgotando o espazo no disco Name[he]=השטח הפנוי בדיסק מועט Name[hi]=डिस्क में जगह कम हो गया है Name[hr]=Ponestajanje diskovnog prostora Name[hu]=Kezd fogyni a lemezterület Name[ia]=Exhauriente le spatio de disco Name[id]=Berjalan pada ruang kosong yang tinggal sedikit Name[is]=Lítið pláss eftir á diski Name[it]=Lo spazio su disco si sta esaurendo Name[ja]=ディスクの空き領域が少ないです Name[kk]=Диск орын тапшылығы Name[km]=ដំណើរការ​ទាប​លើ​ទំហំ​ថាស Name[kn]=ಮುದ್ರಿಕೆಯಲ್ಲಿ (ಡಿಸ್ಕ್) ಜಾಗ ಕಮ್ಮಿಯಾಗುತ್ತಿದೆ. Name[ko]=디스크 공간 거의 없음 Name[lt]=Baigiasi vieta diske Name[lv]=Ir palicis maz brīvas vietas Name[mr]=डिस्कवर कमी जागा शिल्लक आहे Name[nb]=Det er nå lite diskplass Name[nds]=De free Ruum op de Fastplaat geiht op de Neeg. Name[nl]=Bijna geen vrije schijfruimte meer Name[nn]=Det er lite diskplass att Name[pa]=ਡਿਸਕ ਥਾਂ ਖਤਮ ਹੋ ਰਹੀ ਹੈ Name[pl]=Zaczyna brakować miejsca na dysku Name[pt]=Pouco espaço livre em disco Name[pt_BR]=Pouco espaço livre em disco Name[ro]=Spațiu pe disc este scăzut Name[ru]=Недостаточно места на диске Name[si]=පහත් තැටි ඉඩෙන් ධාවනය කරමි Name[sk]=Dochádza voľné miesto na disku Name[sl]=Razpoložljivega prostora na disku je malo Name[sr]=Понестаје простора на диску Name[sr@ijekavian]=Понестаје простора на диску Name[sr@ijekavianlatin]=Ponestaje prostora na disku Name[sr@latin]=Ponestaje prostora na disku Name[sv]=Diskutrymmet håller på att ta slut Name[th]=พื้นที่ดิสก์กำลังเหลือน้อย Name[tr]=Düşük disk alanı üzerinde çalışıyor Name[ug]=دىسكىدىكى بوشلۇق ئاز ھالەتتە ئىجرا قىلىۋاتىدۇ Name[uk]=Замало місця на диску Name[vi]=Không gian đĩa trống sắp hết Name[wa]=Gn a pus bråmint d' plaece sol plake Name[x-test]=xxRunning low on disk spacexx Name[zh_CN]=磁盘空间过低 Name[zh_TW]=磁碟空間快用完了 Comment=You are running low on disk space Comment[ar]=أنت تعمل على مساحة قرص منخفضة Comment[ast]=Quédate pocu espaciu nel discu Comment[bg]=Дисковото Ви пространство е твърде малко Comment[bn]=আপনার ডিস্ক-এ বেশী জায়গা বাকি নেই Comment[bs]=Ponestaje vam prostora na disku Comment[ca]=L'espai del disc s'està exhaurint Comment[ca@valencia]=L'espai del disc s'està exhaurint Comment[cs]=Dochází vám místo na disku Comment[da]=Du er ved at løbe tør for diskplads Comment[de]=Ihr freier Speicherplatz wird knapp Comment[el]=Η τρέχουσα χωρητικότητα του δίσκου σας είναι χαμηλή Comment[en_GB]=You are running low on disk space Comment[es]=Se está quedando sin espacio en disco Comment[et]=Kettaruumi on vähe järele jäänud Comment[eu]=Diskoan lekurik gabe gelditzen ari zara Comment[fi]=Levytilasi alkaa loppua Comment[fr]=Vous manquez d'espace disque Comment[ga]=Tá an diosca ag éirí lán Comment[gl]=Está a quedar sen espazo no disco Comment[he]=השטח הפנוי בדיסק מתמעט Comment[hi]=आप कम डिस्क जगह पर चल रहे हैं Comment[hr]=Ponestaje vam diskovnog prostora Comment[hu]=A lemezterület kezd elfogyni Comment[ia]=Tu es exhauriente le spatio de disco Comment[id]=Anda berjalan pada ruang kosong yang tinggal sedikit Comment[is]=Þú ert að verða uppiskroppa með diskpláss Comment[it]=Stai esaurendo lo spazio su disco Comment[ja]=ディスクの空き領域が少なくなりました Comment[kk]=Диск орын тапшылықтасыз Comment[km]=អ្នក​កំពុង​ដំណើរការ​ទាប​​លើ​ទំហំ​ថាស Comment[kn]=ನಿಮ್ಮಲ್ಲಿ ಕಡಿಮೆ ಡಿಸ್ಕ್‍ ಸ್ಥಳವಿದೆ Comment[ko]=디스크 공간이 거의 없습니다 Comment[lt]=Jūsų diske liko mažai vietos Comment[lv]=Uz diska ir maz brīvas vietas Comment[mr]=तुमच्या डिस्कवर कमी जागा शिल्लक आहे Comment[nb]=Du har lite diskplass igjen Comment[nds]=De free Ruum op Dien Fastplaat geiht op de Neeg. Comment[nl]=U hebt bijna geen vrije schijfruimte meer Comment[nn]=Du har lite diskplass att Comment[pa]=ਤੁਹਾਡੇ ਕੋਲ ਡਿਸਕ ਖਾਲੀ ਥਾਂ ਘੱਟ ਰਹੀ ਹੈ Comment[pl]=Zaczyna brakować miejsca na dysku Comment[pt]=Está a ficar com pouco espaço livre em disco Comment[pt_BR]=Você tem pouco espaço livre em disco Comment[ro]=Spațiul dumneavoastră de stocare este pe cale să se termine Comment[ru]=На диске осталось мало свободного места Comment[si]=ඔබගේ තැටි ඉඩ අඩු වෙමින් පවතී Comment[sk]=Dochádza vám voľné miesto na disku Comment[sl]=Na disku imate le še malo razpoložljivega prostora Comment[sr]=Понестаје вам простора на диску Comment[sr@ijekavian]=Понестаје вам простора на диску Comment[sr@ijekavianlatin]=Ponestaje vam prostora na disku Comment[sr@latin]=Ponestaje vam prostora na disku Comment[sv]=Diskutrymmet håller på att ta slut Comment[th]=คุณกำลังทำงานด้วยพื้นที่ดิสก์ที่เหลือน้อย Comment[tr]=Düşük disk alanı üzerinde çalışıyorsunuz Comment[ug]=دىسكىدىكى بوشلۇق ئاز ھالەتتە ئىجرا قىلىۋاتىسىز Comment[uk]=На вашому диску залишилося замало місця Comment[vi]=Bạn đang dùng sắp hết không gian đĩa Comment[wa]=Vos estoz k' n' a pus bråmint d' plaece sol plake Comment[x-test]=xxYou are running low on disk spacexx Comment[zh_CN]=您现在的磁盘空间过低 Comment[zh_TW]=您的磁碟空間快用完了 Contexts=warningnot Action=Popup +Urgency=Critical diff --git a/freespacenotifier/module.cpp b/freespacenotifier/module.cpp index cdfb76155..2771992fd 100644 --- a/freespacenotifier/module.cpp +++ b/freespacenotifier/module.cpp @@ -1,31 +1,93 @@ /* This file is part of the KDE Project Copyright (c) 2006 Lukas Tinkl Copyright (c) 2008 Lubos Lunak Copyright (c) 2009 Ivo Anjo 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, see . */ #include "module.h" +#include +#include #include +#include + +#include "kded_interface.h" + +#include "ui_freespacenotifier_prefs_base.h" + +#include "settings.h" + K_PLUGIN_CLASS_WITH_JSON(FreeSpaceNotifierModule, "freespacenotifier.json") FreeSpaceNotifierModule::FreeSpaceNotifierModule(QObject* parent, const QList&) : KDEDModule(parent) { + // If the module is loaded, notifications are enabled + FreeSpaceNotifierSettings::setEnableNotification(true); + + const QString rootPath = QStringLiteral("/"); + const QString homePath = QDir::homePath(); + + auto *homeNotifier = new FreeSpaceNotifier(homePath, + ki18n("Your Home folder is running out of disk space, you have %1 MiB remaining (%2%)."), + this); + connect(homeNotifier, &FreeSpaceNotifier::configureRequested, this, &FreeSpaceNotifierModule::showConfiguration); + + // If Home is on a separate partition from Root, warn for it, too. + auto homeMountPoint = KMountPoint::currentMountPoints().findByPath(homePath); + if (!homeMountPoint || homeMountPoint->mountPoint() != rootPath) { + auto *rootNotifier = new FreeSpaceNotifier(rootPath, + ki18n("Your Root partition is running out of disk space, you have %1 MiB remaining (%2%)."), + this); + connect(rootNotifier, &FreeSpaceNotifier::configureRequested, this, &FreeSpaceNotifierModule::showConfiguration); + } + +} + +void FreeSpaceNotifierModule::showConfiguration() +{ + if (KConfigDialog::showDialog(QStringLiteral("settings"))) { + return; + } + + KConfigDialog *dialog = new KConfigDialog(nullptr, QStringLiteral("settings"), FreeSpaceNotifierSettings::self()); + QWidget *generalSettingsDlg = new QWidget(); + + Ui::freespacenotifier_prefs_base preferences; + preferences.setupUi(generalSettingsDlg); + + dialog->addPage(generalSettingsDlg, + i18nc("The settings dialog main page name, as in 'general settings'", "General"), + QStringLiteral("system-run")); + + connect(dialog, &KConfigDialog::finished, this, [this] { + if (!FreeSpaceNotifierSettings::enableNotification()) { + // The idea here is to disable ourselves by telling kded to stop autostarting us, and + // to kill the current running instance. + org::kde::kded5 kded(QStringLiteral("org.kde.kded5"), + QStringLiteral("/kded"), + QDBusConnection::sessionBus()); + kded.setModuleAutoloading(QStringLiteral("freespacenotifier"), false); + kded.unloadModule(QStringLiteral("freespacenotifier")); + } + }); + + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); } #include "module.moc" diff --git a/freespacenotifier/module.h b/freespacenotifier/module.h index 17606e583..aca41466b 100644 --- a/freespacenotifier/module.h +++ b/freespacenotifier/module.h @@ -1,38 +1,40 @@ /* This file is part of the KDE Project Copyright (c) 2006 Lukas Tinkl Copyright (c) 2008 Lubos Lunak Copyright (c) 2009 Ivo Anjo 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, see . */ #ifndef MODULE_H #define MODULE_H #include #include #include "freespacenotifier.h" class FreeSpaceNotifierModule : public KDEDModule { Q_OBJECT public: FreeSpaceNotifierModule(QObject* parent, const QList&); + private: - FreeSpaceNotifier notifier; + void showConfiguration(); + }; #endif