From 3bcdf26cca046e80ee0420c2d94c58c45c6f1282 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 18 Feb 2019 00:35:32 +0100 Subject: [PATCH] Show global statistics on widgets-based GUI --- README.md | 5 +- tray/CMakeLists.txt | 5 +- tray/gui/trayicon.cpp | 4 +- tray/gui/traywidget.cpp | 29 ++- tray/gui/traywidget.h | 1 + tray/gui/traywidget.ui | 192 ++++++++++-------- .../hicolor/scalable/devices/network-card.svg | 55 ----- tray/resources/syncthingtrayicons.qrc | 1 - .../icons/hicolor/scalable/actions/globe.svg | 16 ++ .../hicolor/scalable/places/user-home.svg | 13 ++ widgets/resources/syncthingwidgetsicons.qrc | 2 + 11 files changed, 164 insertions(+), 159 deletions(-) delete mode 100644 tray/resources/icons/hicolor/scalable/devices/network-card.svg create mode 100644 widgets/resources/icons/hicolor/scalable/actions/globe.svg create mode 100644 widgets/resources/icons/hicolor/scalable/places/user-home.svg diff --git a/README.md b/README.md index ee6efac..21557a2 100644 --- a/README.md +++ b/README.md @@ -253,5 +253,6 @@ on GitHub. Syncthing again. This is caused by Qt bug https://bugreports.qt.io/browse/QTBUG-60949. ## Attribution for 3rd party content -* This project uses icons from the Syncthing project. -* This project uses some icons from [Font Awesome](https://fontawesome.com) (see [their license](https://fontawesome.com/license)). +* Some icons are taken from the Syncthing project. +* Some icons are taken from [Font Awesome](https://fontawesome.com) (see [their license](https://fontawesome.com/license)). +* Fallback icons are taken from KDE/Breeze project. diff --git a/tray/CMakeLists.txt b/tray/CMakeLists.txt index c726065..0f4a9af 100644 --- a/tray/CMakeLists.txt +++ b/tray/CMakeLists.txt @@ -52,6 +52,7 @@ set(REQUIRED_ICONS folder-download folder-open folder-sync + globe go-down go-up help-about @@ -60,7 +61,6 @@ set(REQUIRED_ICONS list-remove media-playback-pause media-playback-start - network-card network-connect network-disconnect network-server @@ -74,6 +74,7 @@ set(REQUIRED_ICONS system-search system-file-manager text-plain + user-home view-barcode view-refresh window-close) @@ -84,7 +85,7 @@ find_package(c++utilities 4.11.0 REQUIRED) use_cpp_utilities() # find qtutilities -find_package(qtutilities 5.10.0 REQUIRED) +find_package(qtutilities 5.13.0 REQUIRED) use_qt_utilities() # find backend libraries diff --git a/tray/gui/trayicon.cpp b/tray/gui/trayicon.cpp index edde451..dd61685 100644 --- a/tray/gui/trayicon.cpp +++ b/tray/gui/trayicon.cpp @@ -54,9 +54,7 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent) updateStatusIconAndText(); // set context menu - connect(m_contextMenu.addAction(QIcon::fromTheme(QStringLiteral("internet-web-browser"), - QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/internet-web-browser.svg"))), - tr("Web UI")), + connect(m_contextMenu.addAction(QIcon(QStringLiteral(":/icons/hicolor/scalable/status/syncthing-default.svg")), tr("Open Syncthing")), &QAction::triggered, &widget, &TrayWidget::showWebUi); connect(m_contextMenu.addAction( QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/preferences-other.svg"))), diff --git a/tray/gui/traywidget.cpp b/tray/gui/traywidget.cpp index e4d35fc..aedb37d 100644 --- a/tray/gui/traywidget.cpp +++ b/tray/gui/traywidget.cpp @@ -128,20 +128,24 @@ TrayWidget::TrayWidget(TrayMenu *parent) // setup other widgets m_ui->notificationsPushButton->setHidden(true); - m_ui->trafficIconLabel->setPixmap( - QIcon::fromTheme(QStringLiteral("network-card"), QIcon(QStringLiteral(":/icons/hicolor/scalable/devices/network-card.svg"))).pixmap(32)); + m_ui->globalTextLabel->setPixmap( + QIcon::fromTheme(QStringLiteral("globe"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/globe.svg"))).pixmap(16)); + m_ui->localTextLabel->setPixmap( + QIcon::fromTheme(QStringLiteral("user-home"), QIcon(QStringLiteral(":/icons/hicolor/scalable/places/user-home.svg"))).pixmap(16)); + m_ui->trafficInTextLabel->setPixmap(QIcon(QStringLiteral(":/icons/hicolor/scalable/fa/cloud-download-alt-solid.svg")).pixmap(16)); + m_ui->trafficOutTextLabel->setPixmap(QIcon(QStringLiteral(":/icons/hicolor/scalable/fa/cloud-upload-alt-solid.svg")).pixmap(16)); #ifndef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD delete m_ui->startStopPushButton; #endif // connect signals and slots connect(m_ui->statusPushButton, &QPushButton::clicked, this, &TrayWidget::changeStatus); - connect(m_ui->closePushButton, &QPushButton::clicked, this, &TrayWidget::quitTray); connect(m_ui->aboutPushButton, &QPushButton::clicked, this, &TrayWidget::showAboutDialog); connect(m_ui->webUiPushButton, &QPushButton::clicked, this, &TrayWidget::showWebUi); connect(m_ui->settingsPushButton, &QPushButton::clicked, this, &TrayWidget::showSettingsDialog); connect(&m_connection, &SyncthingConnection::statusChanged, this, &TrayWidget::handleStatusChanged); connect(&m_connection, &SyncthingConnection::trafficChanged, this, &TrayWidget::updateTraffic); + connect(&m_connection, &SyncthingConnection::dirStatisticsChanged, this, &TrayWidget::updateOverallStatistics); connect(&m_connection, &SyncthingConnection::newNotification, this, &TrayWidget::handleNewNotification); connect(m_ui->dirsTreeView, &DirView::openDir, this, &TrayWidget::openDir); connect(m_ui->dirsTreeView, &DirView::scanDir, this, &TrayWidget::scanDir); @@ -191,8 +195,12 @@ void TrayWidget::showAboutDialog() { if (!m_aboutDlg) { m_aboutDlg = new AboutDialog(this, QString(), - QStringLiteral(APP_AUTHOR "\nfallback icons from KDE/Breeze project\nSyncthing icons from Syncthing project"), QString(), - ApplicationUtilities::dependencyVersions2, QString(), QStringLiteral(APP_DESCRIPTION), + QStringLiteral( + "

Developed by " APP_AUTHOR + "
Fallback icons from KDE/Breeze project
Syncthing icons from Syncthing project
Using " + "icons from Font " + "Awesome (see their license)

"), + QString(), ApplicationUtilities::dependencyVersions2, QString(), QStringLiteral(APP_DESCRIPTION), QImage(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg"))); m_aboutDlg->setWindowTitle(tr("About") + QStringLiteral(" - " APP_NAME)); m_aboutDlg->setWindowIcon(QIcon(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg"))); @@ -388,7 +396,6 @@ void TrayWidget::applySettings(const QString &connectionConfig) // update visual appearance m_ui->trafficFormWidget->setVisible(settings.appearance.showTraffic); - m_ui->trafficIconLabel->setVisible(settings.appearance.showTraffic); m_ui->trafficHorizontalSpacer->changeSize( 0, 20, settings.appearance.showTraffic ? QSizePolicy::Expanding : QSizePolicy::Ignored, QSizePolicy::Minimum); if (settings.appearance.showTraffic) { @@ -495,6 +502,16 @@ void TrayWidget::updateTraffic() } m_ui->inTrafficLabel->setText(trafficString(m_connection.totalIncomingTraffic(), m_connection.totalIncomingRate())); m_ui->outTrafficLabel->setText(trafficString(m_connection.totalOutgoingTraffic(), m_connection.totalOutgoingRate())); + // FIXME: decrease opacity if rate is zero (the following code doesn't work) + //m_ui->trafficInTextLabel->setStyleSheet(m_connection.totalIncomingRate() > 0.0 ? QString() : QStringLiteral("opacity: 0.5;")); + //m_ui->trafficOutTextLabel->setStyleSheet(m_connection.totalOutgoingRate() > 0.0 ? QString() : QStringLiteral("opacity: 0.5;")); +} + +void TrayWidget::updateOverallStatistics() +{ + const auto overallStats = m_connection.computeOverallDirStatistics(); + m_ui->globalStatisticsLabel->setText(directoryStatusString(overallStats.global)); + m_ui->localStatisticsLabel->setText(directoryStatusString(overallStats.local)); } #ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD diff --git a/tray/gui/traywidget.h b/tray/gui/traywidget.h index 8948783..5e1081e 100644 --- a/tray/gui/traywidget.h +++ b/tray/gui/traywidget.h @@ -75,6 +75,7 @@ private slots: void pauseResumeDir(const Data::SyncthingDir &dir); void changeStatus(); void updateTraffic(); + void updateOverallStatistics(); #ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD bool handleSystemdStatusChanged(); bool applySystemdSettings(bool reconnectRequired = false); diff --git a/tray/gui/traywidget.ui b/tray/gui/traywidget.ui index d68488f..31ae9bd 100644 --- a/tray/gui/traywidget.ui +++ b/tray/gui/traywidget.ui @@ -52,47 +52,6 @@ 0 - - - - Close - - - - :/icons/hicolor/scalable/actions/window-close.svg:/icons/hicolor/scalable/actions/window-close.svg - - - true - - - - - - - About - - - - :/icons/hicolor/scalable/actions/help-about.svg:/icons/hicolor/scalable/actions/help-about.svg - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -134,6 +93,20 @@ + + + + About + + + + :/icons/hicolor/scalable/actions/help-about.svg:/icons/hicolor/scalable/actions/help-about.svg + + + true + + + @@ -162,6 +135,27 @@ + + + + + + + 0 + 0 + + + + + :/icons/hicolor/scalable/actions/network-connect.svg:/icons/hicolor/scalable/actions/network-connect.svg + + + true + + + + + @@ -174,6 +168,9 @@ QFrame::Sunken + + 8 + QLayout::SetDefaultConstraint @@ -190,26 +187,78 @@ 0 - + - + - + 0 0 - - - 32 - 32 - - - - Traffic - + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Global + + + + + + + Global overall statistics + + + unknown + + + + + + + Local + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Local overall statistics + + + unknown + + + + + + + + + + 6 + @@ -319,43 +368,6 @@ For <i>all</i> notifications, checkout the log - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 0 - 20 - - - - - - - - - 0 - 0 - - - - - :/icons/hicolor/scalable/actions/network-connect.svg:/icons/hicolor/scalable/actions/network-connect.svg - - - true - - - - - diff --git a/tray/resources/icons/hicolor/scalable/devices/network-card.svg b/tray/resources/icons/hicolor/scalable/devices/network-card.svg deleted file mode 100644 index 29b2ec2..0000000 --- a/tray/resources/icons/hicolor/scalable/devices/network-card.svg +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tray/resources/syncthingtrayicons.qrc b/tray/resources/syncthingtrayicons.qrc index 30acdad..12b3e29 100644 --- a/tray/resources/syncthingtrayicons.qrc +++ b/tray/resources/syncthingtrayicons.qrc @@ -9,7 +9,6 @@ icons/hicolor/scalable/actions/view-barcode.svg icons/hicolor/scalable/actions/window-close.svg icons/hicolor/scalable/apps/help-about.svg - icons/hicolor/scalable/devices/network-card.svg icons/hicolor/scalable/places/folder-open.svg icons/hicolor/scalable/places/folder.svg icons/hicolor/scalable/places/network-workgroup.svg diff --git a/widgets/resources/icons/hicolor/scalable/actions/globe.svg b/widgets/resources/icons/hicolor/scalable/actions/globe.svg new file mode 100644 index 0000000..543cc55 --- /dev/null +++ b/widgets/resources/icons/hicolor/scalable/actions/globe.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/widgets/resources/icons/hicolor/scalable/places/user-home.svg b/widgets/resources/icons/hicolor/scalable/places/user-home.svg new file mode 100644 index 0000000..c302502 --- /dev/null +++ b/widgets/resources/icons/hicolor/scalable/places/user-home.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/widgets/resources/syncthingwidgetsicons.qrc b/widgets/resources/syncthingwidgetsicons.qrc index 4b2e299..686ea4f 100644 --- a/widgets/resources/syncthingwidgetsicons.qrc +++ b/widgets/resources/syncthingwidgetsicons.qrc @@ -11,5 +11,7 @@ icons/hicolor/scalable/app/syncthingtray.svg icons/hicolor/scalable/fa/cloud-download-alt-solid.svg icons/hicolor/scalable/fa/cloud-upload-alt-solid.svg + icons/hicolor/scalable/actions/globe.svg + icons/hicolor/scalable/places/user-home.svg