Allow opening internal error log via context menu

This commit is contained in:
Martchus 2017-09-05 00:24:52 +02:00
parent 62b94b8460
commit f4df2bbf21
7 changed files with 48 additions and 2 deletions

View File

@ -61,6 +61,7 @@ set(REQUIRED_ICONS
dialog-ok-apply
edit-copy
edit-paste
emblem-error
folder
folder-download
folder-open

View File

@ -60,6 +60,11 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent)
QIcon::fromTheme(QStringLiteral("text-x-generic"), QIcon(QStringLiteral(":/icons/hicolor/scalable/mimetypes/text-x-generic.svg"))),
tr("Log")),
&QAction::triggered, m_trayMenu.widget(), &TrayWidget::showLog);
m_errorsAction = m_contextMenu.addAction(
QIcon::fromTheme(QStringLiteral("emblem-error"), QIcon(QStringLiteral(":/icons/hicolor/scalable/emblems/8/emblem-error.svg"))),
tr("Show internal errors"));
m_errorsAction->setVisible(false);
connect(m_errorsAction, &QAction::triggered, this, &TrayIcon::showInternalErrorsDialog);
m_contextMenu.addMenu(m_trayMenu.widget()->connectionsMenu());
connect(m_contextMenu.addAction(
QIcon::fromTheme(QStringLiteral("help-about"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/help-about.svg"))), tr("About")),
@ -86,7 +91,7 @@ TrayIcon::TrayIcon(const QString &connectionConfig, QObject *parent)
static_cast<void (SyncthingConnection::*)(void)>(&SyncthingConnection::connect));
connect(&m_dbusNotifier, &DBusStatusNotifier::dismissNotificationsRequested, m_trayMenu.widget(), &TrayWidget::dismissNotifications);
connect(&m_dbusNotifier, &DBusStatusNotifier::showNotificationsRequested, m_trayMenu.widget(), &TrayWidget::showNotifications);
connect(&m_dbusNotifier, &DBusStatusNotifier::errorDetailsRequested, &ErrorViewDialog::showInstance);
connect(&m_dbusNotifier, &DBusStatusNotifier::errorDetailsRequested, this, &TrayIcon::showInternalErrorsDialog);
#endif
m_initialized = true;
}
@ -134,7 +139,7 @@ void TrayIcon::handleMessageClicked()
m_trayMenu.widget()->dismissNotifications();
break;
case TrayIconMessageClickedAction::ShowInternalErrors:
ErrorViewDialog::instance()->show();
showInternalErrorsDialog();
break;
}
}
@ -149,6 +154,11 @@ void TrayIcon::handleConnectionStatusChanged(SyncthingStatus status)
m_status = status;
}
void TrayIcon::handleErrorsCleared()
{
m_errorsAction->setVisible(false);
}
void TrayIcon::showInternalError(
const QString &errorMsg, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response)
{
@ -178,6 +188,7 @@ void TrayIcon::showInternalError(
showMessage(tr("Error"), errorMsg, QSystemTrayIcon::Critical);
}
ErrorViewDialog::addError(move(error));
m_errorsAction->setVisible(true);
}
}
@ -272,4 +283,12 @@ void TrayIcon::showStatusNotification(SyncthingStatus status)
}
}
}
void TrayIcon::showInternalErrorsDialog()
{
auto *const errorViewDlg = ErrorViewDialog::instance();
connect(errorViewDlg, &ErrorViewDialog::errorsCleared, this, &TrayIcon::handleErrorsCleared);
centerWidget(errorViewDlg);
errorViewDlg->show();
}
}

View File

@ -34,17 +34,20 @@ public slots:
const QString &errorMsg, Data::SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response);
void showSyncthingNotification(ChronoUtilities::DateTime when, const QString &message);
void showStatusNotification(Data::SyncthingStatus status);
void showInternalErrorsDialog();
void updateStatusIconAndText();
private slots:
void handleActivated(QSystemTrayIcon::ActivationReason reason);
void handleMessageClicked();
void handleConnectionStatusChanged(Data::SyncthingStatus status);
void handleErrorsCleared();
private:
bool m_initialized;
TrayMenu m_trayMenu;
QMenu m_contextMenu;
QAction *m_errorsAction;
Data::SyncthingStatus m_status;
#ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS
DBusStatusNotifier m_dbusNotifier;

View File

@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8">
<defs id="defs3051">
<style type="text/css" id="current-color-scheme">
.ColorScheme-NegativeText {
color:#da4453;
}
</style>
</defs>
<path
style="fill:currentColor;fill-opacity:1;stroke:none"
class="ColorScheme-NegativeText"
d="M 1 0 C 0.4459807 0 0 0.446 0 1 L 0 7 C 0 7.5541 0.4459807 8 1 8 L 7 8 C 7.554019 8 8 7.5541 8 7 L 8 1 C 8 0.446 7.554019 0 7 0 L 1 0 z "
/>
<path
style="fill:#ffffff;fill-opacity:1;stroke:none"
d="M 2 1 L 1 2 L 3 4 L 1 6 L 2 7 L 4 5 L 6 7 L 7 6 L 5 4 L 7 2 L 6 1 L 4 3 L 2 1 z "
/>
</svg>

After

Width:  |  Height:  |  Size: 661 B

View File

@ -16,5 +16,6 @@
<file>icons/hicolor/scalable/places/network-workgroup.svg</file>
<file>icons/hicolor/scalable/actions/network-connect.svg</file>
<file>icons/hicolor/scalable/places/folder-download.svg</file>
<file>icons/hicolor/scalable/emblems/8/emblem-error.svg</file>
</qresource>
</RCC>

View File

@ -56,6 +56,7 @@ ErrorViewDialog::ErrorViewDialog()
buttonLayout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
buttonLayout->addWidget(clearButton);
connect(clearButton, &QPushButton::clicked, &ErrorViewDialog::clearErrors);
connect(clearButton, &QPushButton::clicked, this, &ErrorViewDialog::errorsCleared);
}
layout()->addItem(buttonLayout);

View File

@ -17,6 +17,9 @@ public:
static ErrorViewDialog *instance();
static void addError(InternalError &&newError);
Q_SIGNALS:
void errorsCleared();
public Q_SLOTS:
static void showInstance();
static void clearErrors();