Add option to unify tray menus
* Don't create context menu * Show the "Close" action and the "Internal errors" action in the tray widget * Use this by default on Mac OS
This commit is contained in:
parent
038225936e
commit
708334443f
|
@ -102,8 +102,22 @@ use_syncthingwidgets()
|
|||
# link also explicitely against the following Qt 5 modules
|
||||
list(APPEND ADDITIONAL_QT_MODULES Network)
|
||||
|
||||
# include modules to apply configuration
|
||||
# apply basic configuration
|
||||
include(BasicConfig)
|
||||
|
||||
# add an option to unify left- and right-click context menus useful on Mac OS
|
||||
if (APPLE)
|
||||
set(UNIFY_TRAY_MENUS_BY_DEFAULT ON)
|
||||
else ()
|
||||
set(UNIFY_TRAY_MENUS_BY_DEFAULT OFF)
|
||||
endif ()
|
||||
option(UNIFY_TRAY_MENUS "unifies the left- and right-click tray menus" ${UNIFY_TRAY_MENUS_BY_DEFAULT})
|
||||
if (UNIFY_TRAY_MENUS)
|
||||
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_UNIFY_TRAY_MENUS)
|
||||
message(STATUS "left- and right-click context menus will be unified")
|
||||
endif ()
|
||||
|
||||
# include modules to apply configuration
|
||||
include(QtGuiConfig)
|
||||
include(QtConfig)
|
||||
include(WindowsResources)
|
||||
|
|
|
@ -51,6 +51,7 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent)
|
|||
updateStatusIconAndText();
|
||||
|
||||
// set context menu
|
||||
#ifndef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
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(
|
||||
|
@ -80,6 +81,7 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent)
|
|||
tr("Close")),
|
||||
&QAction::triggered, this, &TrayIcon::deleteLater);
|
||||
setContextMenu(&m_contextMenu);
|
||||
#endif
|
||||
|
||||
// connect signals and slots
|
||||
connect(this, &TrayIcon::activated, this, &TrayIcon::handleActivated);
|
||||
|
@ -189,7 +191,9 @@ void TrayIcon::showSyncComplete(const QString &message)
|
|||
|
||||
void TrayIcon::handleErrorsCleared()
|
||||
{
|
||||
#ifndef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
m_errorsAction->setVisible(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TrayIcon::showInternalError(
|
||||
|
@ -209,7 +213,11 @@ void TrayIcon::showInternalError(
|
|||
showMessage(tr("Error"), errorMessage, QSystemTrayIcon::Critical);
|
||||
}
|
||||
InternalErrorsDialog::addError(move(error));
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
m_trayMenu.widget().showInternalErrorsButton();
|
||||
#else
|
||||
m_errorsAction->setVisible(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TrayIcon::showLauncherError(const QString &errorMessage, const QString &additionalInfo)
|
||||
|
|
|
@ -50,8 +50,10 @@ private slots:
|
|||
|
||||
private:
|
||||
TrayMenu m_trayMenu;
|
||||
#ifndef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
QMenu m_contextMenu;
|
||||
QAction *m_errorsAction;
|
||||
#endif
|
||||
#ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS
|
||||
DBusStatusNotifier m_dbusNotifier;
|
||||
bool &m_dbusNotificationsEnabled;
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
#include "../../widgets/settings/settingsdialog.h"
|
||||
#include "../../widgets/webview/webviewdialog.h"
|
||||
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
#include "../../widgets/misc/internalerrorsdialog.h"
|
||||
#endif
|
||||
|
||||
#include "../../model/syncthingicons.h"
|
||||
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
|
@ -137,6 +141,25 @@ TrayWidget::TrayWidget(TrayMenu *parent)
|
|||
QIcon::fromTheme(QStringLiteral("user-home"), QIcon(QStringLiteral(":/icons/hicolor/scalable/places/user-home.svg"))).pixmap(16));
|
||||
updateTraffic();
|
||||
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
// add actions from right-click menu if it is not available
|
||||
m_internalErrorsButton = new QPushButton(m_cornerFrame);
|
||||
m_internalErrorsButton->setToolTip(tr("Show internal errors"));
|
||||
m_internalErrorsButton->setIcon(
|
||||
QIcon::fromTheme(QStringLiteral("emblem-error"), QIcon(QStringLiteral(":/icons/hicolor/scalable/emblems/8/emblem-error.svg"))));
|
||||
m_internalErrorsButton->setFlat(true);
|
||||
m_internalErrorsButton->setVisible(false);
|
||||
connect(m_internalErrorsButton, &QPushButton::clicked, this, &TrayWidget::showInternalErrorsDialog);
|
||||
cornerFrameLayout->addWidget(m_internalErrorsButton);
|
||||
auto *quitButton = new QPushButton(m_cornerFrame);
|
||||
quitButton->setToolTip(tr("Quit Syncthing Tray"));
|
||||
quitButton->setIcon(
|
||||
QIcon::fromTheme(QStringLiteral("window-close"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/window-close.svg"))));
|
||||
quitButton->setFlat(true);
|
||||
connect(quitButton, &QPushButton::clicked, this, &TrayWidget::quitTray);
|
||||
cornerFrameLayout->addWidget(quitButton);
|
||||
#endif
|
||||
|
||||
// connect signals and slots
|
||||
connect(m_ui->statusPushButton, &QPushButton::clicked, this, &TrayWidget::changeStatus);
|
||||
connect(m_ui->aboutPushButton, &QPushButton::clicked, this, &TrayWidget::showAboutDialog);
|
||||
|
@ -266,6 +289,21 @@ void TrayWidget::showAtCursor()
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
void TrayWidget::showInternalErrorsButton()
|
||||
{
|
||||
m_internalErrorsButton->setVisible(true);
|
||||
}
|
||||
|
||||
void TrayWidget::showInternalErrorsDialog()
|
||||
{
|
||||
auto *const errorViewDlg = InternalErrorsDialog::instance();
|
||||
connect(errorViewDlg, &InternalErrorsDialog::errorsCleared, this, &TrayWidget::handleErrorsCleared);
|
||||
centerWidget(errorViewDlg);
|
||||
errorViewDlg->show();
|
||||
}
|
||||
#endif
|
||||
|
||||
void TrayWidget::dismissNotifications()
|
||||
{
|
||||
m_connection.considerAllNotificationsRead();
|
||||
|
@ -333,6 +371,13 @@ void TrayWidget::handleStatusChanged(SyncthingStatus status)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
void TrayWidget::handleErrorsCleared()
|
||||
{
|
||||
m_internalErrorsButton->setVisible(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
void TrayWidget::applySettings(const QString &connectionConfig)
|
||||
{
|
||||
// update connections menu
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
QT_FORWARD_DECLARE_CLASS(QFrame)
|
||||
QT_FORWARD_DECLARE_CLASS(QMenu)
|
||||
QT_FORWARD_DECLARE_CLASS(QActionGroup)
|
||||
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
||||
|
||||
namespace CppUtilities {
|
||||
class QtConfigArguments;
|
||||
|
@ -60,6 +61,10 @@ public slots:
|
|||
void showLog();
|
||||
void showNotifications();
|
||||
void showAtCursor();
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
void showInternalErrorsButton();
|
||||
void showInternalErrorsDialog();
|
||||
#endif
|
||||
void dismissNotifications();
|
||||
void restartSyncthing();
|
||||
void quitTray();
|
||||
|
@ -67,6 +72,9 @@ public slots:
|
|||
|
||||
private slots:
|
||||
void handleStatusChanged(Data::SyncthingStatus status);
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
void handleErrorsCleared();
|
||||
#endif
|
||||
static void applySettingsOnAllInstances();
|
||||
void openDir(const Data::SyncthingDir &dir);
|
||||
void openItemDir(const Data::SyncthingItemDownloadProgress &item);
|
||||
|
@ -100,6 +108,9 @@ private:
|
|||
WebViewDialog *m_webViewDlg;
|
||||
#endif
|
||||
QFrame *m_cornerFrame;
|
||||
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
|
||||
QPushButton *m_internalErrorsButton;
|
||||
#endif
|
||||
Data::SyncthingConnection m_connection;
|
||||
Data::SyncthingNotifier m_notifier;
|
||||
Data::SyncthingDirectoryModel m_dirModel;
|
||||
|
|
Loading…
Reference in New Issue