[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdeplasma-addons/dhaumann/quotamonitor] applets/diskquota: launch filelight on click, if installed
From: Dominik Haumann <dhaumann () kde ! org>
Date: 2015-07-31 20:42:25
Message-ID: E1ZLH8L-0002PX-Sy () scm ! kde ! org
[Download RAW message or body]
Git commit e7c8dd091a4e821631b1ded08ebdba0b4fd72862 by Dominik Haumann.
Committed on 31/07/2015 at 20:42.
Pushed by dhaumann into branch 'dhaumann/quotamonitor'.
launch filelight on click, if installed
M +1 -1 applets/diskquota/Messages.sh
M +13 -5 applets/diskquota/package/contents/ui/ListDelegateItem.qml
M +17 -21 applets/diskquota/package/contents/ui/main.qml
M +2 -2 applets/diskquota/package/metadata.desktop
M +32 -8 applets/diskquota/plugin/DiskQuota.cpp
M +42 -24 applets/diskquota/plugin/DiskQuota.h
http://commits.kde.org/kdeplasma-addons/e7c8dd091a4e821631b1ded08ebdba0b4fd72862
diff --git a/applets/diskquota/Messages.sh b/applets/diskquota/Messages.sh
index 927e5b4..7e94d9f 100755
--- a/applets/diskquota/Messages.sh
+++ b/applets/diskquota/Messages.sh
@@ -1,2 +1,2 @@
#! /usr/bin/env bash
-$XGETTEXT `find . -name \*.qml -o -name \*.cpp` -o \
$podir/plasma_applet_org.kde.plasma.quotawatch.pot +$XGETTEXT `find . -name \*.qml -o \
-name \*.cpp` -o $podir/plasma_applet_org.kde.plasma.diskquota.pot
diff --git a/applets/diskquota/package/contents/ui/ListDelegateItem.qml \
b/applets/diskquota/package/contents/ui/ListDelegateItem.qml index cd293e9..9181479 \
100644
--- a/applets/diskquota/package/contents/ui/ListDelegateItem.qml
+++ b/applets/diskquota/package/contents/ui/ListDelegateItem.qml
@@ -25,13 +25,14 @@ import org.kde.plasma.components 2.0 as Components
import org.kde.plasma.private.diskquota 1.0
Components.ListItem {
+ id: quotaItem
property string mountPoint
+ property string details
property string iconName
property string usedString
property string freeString
property int usage
- enabled: true
onContainsMouseChanged: {
if (containsMouse) {
ListView.view.currentIndex = index
@@ -39,11 +40,11 @@ Components.ListItem {
ListView.view.currentIndex = -1
}
}
-
+
onClicked: {
- kRun.openUrl(apps.data[apps.connectedSources[0]].entryPath)
+ diskQuota.openCleanUpTool(mountPoint);
}
-
+
RowLayout {
id: contents
anchors.left: parent.left
@@ -66,7 +67,7 @@ Components.ListItem {
Components.Label {
Layout.fillWidth: true
height: paintedHeight
- text: mountPoint
+ text: details
}
Components.Label {
Layout.fillWidth: true
@@ -81,6 +82,13 @@ Components.ListItem {
value: usage
minimumValue: 0
maximumValue: 100
+ // HACK to make progressbar clickable
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ quotaItem.clicked()
+ }
+ }
}
Components.Label {
height: paintedHeight
diff --git a/applets/diskquota/package/contents/ui/main.qml \
b/applets/diskquota/package/contents/ui/main.qml index 1b92a68..c5e7794 100644
--- a/applets/diskquota/package/contents/ui/main.qml
+++ b/applets/diskquota/package/contents/ui/main.qml
@@ -22,13 +22,13 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.components 2.0 as Components
import org.kde.plasma.extras 2.0 as PlasmaExtras
-import org.kde.kio 1.0 as Kio
import org.kde.plasma.private.diskquota 1.0
Item {
+ id: quotaApplet
Component.onCompleted: plasmoid.removeAction("configure")
- Plasmoid.status: (diskQuota.status == "status-critical") ? \
PlasmaCore.Types.NeedsAttentionStatus : (diskQuota.status == "status-ok") ? \
PlasmaCore.Types.PassiveStatus : PlasmaCore.Types.ActiveStatus + Plasmoid.status: \
(diskQuota.status === DiskQuota.ActiveStatus) ? PlasmaCore.Types.ActiveStatus : \
((diskQuota.status === DiskQuota.PassiveStatus) ? PlasmaCore.Types.PassiveStatus : \
PlasmaCore.Types.NeedsAttentionStatus)
Layout.minimumWidth: units.gridUnit * 10
Layout.minimumHeight: units.gridUnit * 2
@@ -40,20 +40,7 @@ Item {
id: diskQuota
}
- PlasmaCore.DataSource {
- id: apps
- engine: "apps"
- connectedSources: ["org.kde.filelight.desktop"]
- }
-
- Plasmoid.compactRepresentation: MouseArea {
- PlasmaCore.IconItem {
- source: diskQuota.iconName
- anchors.fill: parent
- }
-
- onClicked: plasmoid.expanded = !plasmoid.expanded
- }
+ Plasmoid.icon: diskQuota.iconName
Plasmoid.fullRepresentation: Item {
id: root
@@ -61,6 +48,17 @@ Item {
width: units.gridUnit * 20
height: units.gridUnit * 14
+ // HACK: connection to reset currentIndex to -1. Without this, when
+ // uninstalling filelight, the selection highlight remains fixed (which is \
wrong) + Connections {
+ target: diskQuota
+ onCleanUpToolInstalledChanged: {
+ if (!diskQuota.cleanUpToolInstalled) {
+ listView.currentIndex = -1
+ }
+ }
+ }
+
ColumnLayout {
anchors.fill: root
Components.Label {
@@ -82,8 +80,10 @@ Item {
highlightResizeDuration: 0
currentIndex: -1
delegate: ListDelegateItem {
+ enabled: diskQuota.cleanUpToolInstalled
width: listView.width
- mountPoint: model.details
+ mountPoint: model.mountPoint
+ details: model.details
iconName: model.icon
usedString: model.used
freeString: model.free
@@ -94,10 +94,6 @@ Item {
}
}
- Kio.KRun {
- id: kRun
- }
-
Plasmoid.toolTipMainText: diskQuota.toolTip
Plasmoid.toolTipSubText: diskQuota.subToolTip
}
diff --git a/applets/diskquota/package/metadata.desktop \
b/applets/diskquota/package/metadata.desktop index b4422f6..d111d29 100644
--- a/applets/diskquota/package/metadata.desktop
+++ b/applets/diskquota/package/metadata.desktop
@@ -1,7 +1,7 @@
[Desktop Entry]
Name=Disk Quota
Comment=Shows details about disk quota
-Icon=network-server-database
+Icon=quota
Type=Service
X-Plasma-API=declarativeappletscript
@@ -17,7 +17,7 @@ X-KDE-PluginInfo-Version=2.0
X-KDE-PluginInfo-Website=http://plasma.kde.org/
X-KDE-PluginInfo-Category=Utilities
X-KDE-PluginInfo-Depends=
-X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-License=LGPL
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-Requires-FileDialog=Unused
X-Plasma-Requires-LaunchApp=Unused
diff --git a/applets/diskquota/plugin/DiskQuota.cpp \
b/applets/diskquota/plugin/DiskQuota.cpp index a62549d..17fcebb 100644
--- a/applets/diskquota/plugin/DiskQuota.cpp
+++ b/applets/diskquota/plugin/DiskQuota.cpp
@@ -32,7 +32,8 @@ DiskQuota::DiskQuota(QObject * parent)
: QObject(parent)
, m_timer(new QTimer(this))
, m_quotaInstalled(true)
- , m_status(QStringLiteral("quota-ok"))
+ , m_cleanUpToolInstalled(true)
+ , m_status(PassiveStatus)
, m_iconName(QStringLiteral("quota"))
, m_model(new QuotaListModel(this))
{
@@ -53,7 +54,7 @@ void DiskQuota::setQuotaInstalled(bool installed)
if (! installed) {
m_model->clear();
- setStatus(QStringLiteral("status-not-installed"));
+ setStatus(PassiveStatus);
setToolTip(i18n("Disk Quota"));
setSubToolTip(i18n("Please install 'quota'"));
}
@@ -62,12 +63,25 @@ void DiskQuota::setQuotaInstalled(bool installed)
}
}
-QString DiskQuota::status() const
+bool DiskQuota::cleanUpToolInstalled() const
+{
+ return m_cleanUpToolInstalled;
+}
+
+void DiskQuota::setCleanUpToolInstalled(bool installed)
+{
+ if (m_cleanUpToolInstalled != installed) {
+ m_cleanUpToolInstalled = installed;
+ emit cleanUpToolInstalledChanged();
+ }
+}
+
+DiskQuota::TrayStatus DiskQuota::status() const
{
return m_status;
}
-void DiskQuota::setStatus(const QString & status)
+void DiskQuota::setStatus(TrayStatus status)
{
if (m_status != status) {
m_status = status;
@@ -173,6 +187,9 @@ void DiskQuota::updateQuota()
return;
}
+ // for now, only filelight is supported
+ setCleanUpToolInstalled(! \
QStandardPaths::findExecutable(QStringLiteral("filelight")).isEmpty()); +
// get quota output
QString rawData;
const bool success = runQuotaApp(rawData);
@@ -254,10 +271,9 @@ void DiskQuota::updateQuota()
setIconName(iconNameForQuota(maxQuota));
// update status
- setStatus(maxQuota < 50 ? QStringLiteral("status-ok")
- : maxQuota < 75 ? QStringLiteral("status-75")
- : maxQuota < 90 ? QStringLiteral("status-90")
- : QStringLiteral("status-critical"));
+ setStatus(maxQuota < 50 ? PassiveStatus
+ : maxQuota < 98 ? ActiveStatus
+ : NeedsAttentionStatus);
if (!items.isEmpty()) {
setToolTip(i18nc("example: Quota: 83% used",
@@ -277,3 +293,11 @@ QuotaListModel * DiskQuota::model() const
return m_model;
}
+void DiskQuota::openCleanUpTool(const QString & mountPoint)
+{
+ if (!cleanUpToolInstalled()) {
+ return;
+ }
+
+ QProcess::startDetached(QStringLiteral("filelight"), {mountPoint});
+}
diff --git a/applets/diskquota/plugin/DiskQuota.h \
b/applets/diskquota/plugin/DiskQuota.h index c02f4bb..0809982 100644
--- a/applets/diskquota/plugin/DiskQuota.h
+++ b/applets/diskquota/plugin/DiskQuota.h
@@ -15,8 +15,8 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef PLASMA_QUOTA_WATCH_H
-#define PLASMA_QUOTA_WATCH_H
+#ifndef PLASMA_DISK_QUOTA_H
+#define PLASMA_DISK_QUOTA_H
#include <QObject>
@@ -33,45 +33,62 @@ class DiskQuota : public QObject
Q_OBJECT
Q_PROPERTY(bool quotaInstalled READ quotaInstalled WRITE setQuotaInstalled \
NOTIFY quotaInstalledChanged)
- Q_PROPERTY(QString status READ status WRITE setStatus NOTIFY statusChanged)
+ Q_PROPERTY(bool cleanUpToolInstalled READ cleanUpToolInstalled WRITE \
setCleanUpToolInstalled NOTIFY cleanUpToolInstalledChanged) +
+ Q_PROPERTY(TrayStatus status READ status WRITE setStatus NOTIFY statusChanged)
Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY toolTipChanged)
Q_PROPERTY(QString subToolTip READ subToolTip WRITE setSubToolTip NOTIFY \
subToolTipChanged)
Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY \
iconNameChanged)
+ Q_ENUMS(TrayStatus)
+
public:
DiskQuota(QObject * parent = nullptr);
- /**
- * Checks whether 'quota' is installed or not.
- */
- bool quotaInstalled() const;
-
- /**
- * Returns the current status of the notification. Valid notifications
- * are, with increasing priority:
- * - "status-not-installed": quota is not installed
- * - "status-ok": quota is still ok (enough spaces free)
- * - "status-75": geting closer to quota limit (>= 75% used)
- * - "status-90": geting closer to quota limit (>= 90% used)
- * - "status-critical": close to critical limit (>= 98% used)
- */
- QString status() const;
- QString toolTip() const;
- QString subToolTip() const;
- QString iconName() const;
+public:
+ enum TrayStatus {
+ ActiveStatus = 0,
+ PassiveStatus,
+ NeedsAttentionStatus
+ };
public Q_SLOTS:
+ bool quotaInstalled() const;
void setQuotaInstalled(bool installed);
- void setStatus(const QString & status);
+
+ bool cleanUpToolInstalled() const;
+ void setCleanUpToolInstalled(bool installed);
+
+ TrayStatus status() const;
+ void setStatus(TrayStatus status);
+
+ QString toolTip() const;
void setToolTip(const QString & toolTip);
+
+ QString subToolTip() const;
void setSubToolTip(const QString & subToolTip);
+
+ QString iconName() const;
void setIconName(const QString & name);
+ /**
+ * Called every timer timeout to update the data model.
+ */
void updateQuota();
+
+ /**
+ * Getter function for the model that is used in QML.
+ */
QuotaListModel * model() const;
+ /**
+ * Opens the cleanup tool (filelight) at the folder @p mountPoint.
+ */
+ void openCleanUpTool(const QString & mountPoint);
+
Q_SIGNALS:
void quotaInstalledChanged();
+ void cleanUpToolInstalledChanged();
void statusChanged();
void toolTipChanged();
void subToolTipChanged();
@@ -80,11 +97,12 @@ Q_SIGNALS:
private:
QTimer * m_timer;
bool m_quotaInstalled;
- QString m_status;
+ bool m_cleanUpToolInstalled;
+ TrayStatus m_status;
QString m_iconName;
QString m_toolTip;
QString m_subToolTip;
QuotaListModel * m_model;
};
-#endif // PLASMA_QUOTA_WATCH_H
+#endif // PLASMA_DISK_QUOTA_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic