From 3e97a65baea1019faefed117f146639dba707d20 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 27 Feb 2019 20:42:41 +0100 Subject: [PATCH] Use font awesome icons for global stats in plasmoid --- plasmoid/lib/CMakeLists.txt | 1 + plasmoid/lib/syncthingapplet.cpp | 19 +++++++--- plasmoid/lib/syncthingapplet.h | 11 +++--- .../contents/ui/FullRepresentation.qml | 11 ++++-- .../package/contents/ui/StatisticsView.qml | 38 +++++++++++++++++++ 5 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 plasmoid/package/contents/ui/StatisticsView.qml diff --git a/plasmoid/lib/CMakeLists.txt b/plasmoid/lib/CMakeLists.txt index 48dc21a..df27653 100644 --- a/plasmoid/lib/CMakeLists.txt +++ b/plasmoid/lib/CMakeLists.txt @@ -17,6 +17,7 @@ set(PLASMOID_FILES ../package/contents/ui/TinyButton.qml ../package/contents/ui/TinyButtonStyle.qml ../package/contents/ui/ButtonShadow.qml + ../package/contents/ui/StatisticsView.qml ../package/contents/ui/main.qml) list(APPEND QML_SRC_FILES ${PLASMOID_FILES}) diff --git a/plasmoid/lib/syncthingapplet.cpp b/plasmoid/lib/syncthingapplet.cpp index 16aa929..f9776e8 100644 --- a/plasmoid/lib/syncthingapplet.cpp +++ b/plasmoid/lib/syncthingapplet.cpp @@ -23,6 +23,7 @@ #include #include +#include #include @@ -41,6 +42,7 @@ using namespace Data; using namespace Plasma; using namespace Dialogs; using namespace QtGui; +using namespace ConversionUtilities; using namespace ChronoUtilities; namespace Plasmoid { @@ -146,14 +148,14 @@ bool SyncthingApplet::hasOutgoingTraffic() const return m_connection.totalOutgoingRate() > 0.0; } -QString SyncthingApplet::globalStatistics() const +SyncthingStatistics SyncthingApplet::globalStatistics() const { - return directoryStatusString(m_overallStats.global); + return m_overallStats.global; } -QString SyncthingApplet::localStatistics() const +SyncthingStatistics SyncthingApplet::localStatistics() const { - return directoryStatusString(m_overallStats.local); + return m_overallStats.local; } QStringList SyncthingApplet::connectionConfigNames() const @@ -239,9 +241,14 @@ void SyncthingApplet::updateStatusIconAndTooltip() emit connectionStatusChanged(); } -QIcon SyncthingApplet::loadFontAwesomeIcon(const QString &name) +QIcon SyncthingApplet::loadFontAwesomeIcon(const QString &name, bool solid) const { - return Data::renderSvgImage(Data::loadFontAwesomeIcon(name, QGuiApplication::palette().color(QPalette::Foreground)), QSize(16, 13)); + return Data::renderSvgImage(Data::loadFontAwesomeIcon(name, QGuiApplication::palette().color(QPalette::Foreground), solid), QSize(32, 32), 8); +} + +QString SyncthingApplet::formatFileSize(quint64 fileSizeInByte) const +{ + return QString::fromStdString(dataSizeToString(fileSizeInByte)); } void SyncthingApplet::showSettingsDlg() diff --git a/plasmoid/lib/syncthingapplet.h b/plasmoid/lib/syncthingapplet.h index 3f697df..7c3f613 100644 --- a/plasmoid/lib/syncthingapplet.h +++ b/plasmoid/lib/syncthingapplet.h @@ -55,8 +55,8 @@ class SyncthingApplet : public Plasma::Applet { Q_PROPERTY(bool hasIncomingTraffic READ hasIncomingTraffic NOTIFY trafficChanged) Q_PROPERTY(QString outgoingTraffic READ outgoingTraffic NOTIFY trafficChanged) Q_PROPERTY(bool hasOutgoingTraffic READ hasOutgoingTraffic NOTIFY trafficChanged) - Q_PROPERTY(QString globalStatistics READ globalStatistics NOTIFY statisticsChanged) - Q_PROPERTY(QString localStatistics READ localStatistics NOTIFY statisticsChanged) + Q_PROPERTY(Data::SyncthingStatistics globalStatistics READ globalStatistics NOTIFY statisticsChanged) + Q_PROPERTY(Data::SyncthingStatistics localStatistics READ localStatistics NOTIFY statisticsChanged) Q_PROPERTY(QStringList connectionConfigNames READ connectionConfigNames NOTIFY settingsChanged) Q_PROPERTY(QString currentConnectionConfigName READ currentConnectionConfigName NOTIFY currentConnectionConfigIndexChanged) Q_PROPERTY(int currentConnectionConfigIndex READ currentConnectionConfigIndex WRITE setCurrentConnectionConfigIndex NOTIFY @@ -86,8 +86,8 @@ public: bool hasIncomingTraffic() const; QString outgoingTraffic() const; bool hasOutgoingTraffic() const; - QString globalStatistics() const; - QString localStatistics() const; + Data::SyncthingStatistics globalStatistics() const; + Data::SyncthingStatistics localStatistics() const; QStringList connectionConfigNames() const; QString currentConnectionConfigName() const; int currentConnectionConfigIndex() const; @@ -115,7 +115,8 @@ public Q_SLOTS: void showDirectoryErrors(unsigned int directoryIndex); void copyToClipboard(const QString &text); void updateStatusIconAndTooltip(); - QIcon loadFontAwesomeIcon(const QString &name); + QIcon loadFontAwesomeIcon(const QString &name, bool solid = true) const; + QString formatFileSize(quint64 fileSizeInByte) const; Q_SIGNALS: /// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..." diff --git a/plasmoid/package/contents/ui/FullRepresentation.qml b/plasmoid/package/contents/ui/FullRepresentation.qml index 4b79f45..84d4cf9 100644 --- a/plasmoid/package/contents/ui/FullRepresentation.qml +++ b/plasmoid/package/contents/ui/FullRepresentation.qml @@ -430,6 +430,7 @@ ColumnLayout { // global statistics and traffic GridLayout { + Layout.leftMargin: 5 Layout.fillWidth: true Layout.fillHeight: false columns: 4 @@ -441,8 +442,9 @@ ColumnLayout { Layout.preferredHeight: 16 source: "globe" } - PlasmaComponents.Label { - text: plasmoid.nativeInterface.globalStatistics + StatisticsView { + Layout.leftMargin: 4 + statistics: plasmoid.nativeInterface.globalStatistics } PlasmaCore.IconItem { @@ -462,8 +464,9 @@ ColumnLayout { Layout.preferredHeight: 16 source: "user-home-symbolic" } - PlasmaComponents.Label { - text: plasmoid.nativeInterface.localStatistics + StatisticsView { + Layout.leftMargin: 4 + statistics: plasmoid.nativeInterface.localStatistics } PlasmaCore.IconItem { diff --git a/plasmoid/package/contents/ui/StatisticsView.qml b/plasmoid/package/contents/ui/StatisticsView.qml new file mode 100644 index 0000000..c9256ee --- /dev/null +++ b/plasmoid/package/contents/ui/StatisticsView.qml @@ -0,0 +1,38 @@ +import QtQuick 2.7 +import QtQuick.Layouts 1.1 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +RowLayout { + property var statistics + + PlasmaCore.IconItem { + Layout.preferredWidth: 16 + Layout.preferredHeight: 16 + source: plasmoid.nativeInterface.loadFontAwesomeIcon("file", false) + opacity: 0.7 + } + PlasmaComponents.Label { + text: statistics.files !== undefined ? statistics.files : "?" + } + PlasmaCore.IconItem { + Layout.preferredWidth: 16 + Layout.preferredHeight: 16 + source: plasmoid.nativeInterface.loadFontAwesomeIcon("folder", false) + opacity: 0.7 + } + PlasmaComponents.Label { + text: statistics.dirs !== undefined ? statistics.dirs : "?" + } + PlasmaCore.IconItem { + Layout.preferredWidth: 16 + Layout.preferredHeight: 16 + source: plasmoid.nativeInterface.loadFontAwesomeIcon("hdd", false) + opacity: 0.7 + } + PlasmaComponents.Label { + text: statistics.bytes !== undefined ? plasmoid.nativeInterface.formatFileSize( + statistics.bytes) : "?" + } +}