Make internal errors also accessible when starting with `--windowed`

* Show the button for the internal errors dialog in the tray widget like it
  is done when the `UNIFY_TRAY_MENUS` config is activated
This commit is contained in:
Martchus 2021-10-09 01:14:33 +02:00
parent c63719e2d1
commit 0b801bc505
4 changed files with 47 additions and 29 deletions

View File

@ -74,6 +74,7 @@ TrayWidget::TrayWidget(TrayMenu *parent)
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
, m_webViewDlg(nullptr)
#endif
, m_internalErrorsButton(nullptr)
, m_notifier(m_connection)
, m_dirModel(m_connection)
, m_sortFilterDirModel(&m_dirModel)
@ -159,16 +160,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);
#ifndef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
if (!m_menu) {
#endif
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);
if (!m_menu) {
connect(&m_connection, &SyncthingConnection::error, this, &TrayWidget::showInternalError);
}
#ifndef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
}
#endif
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
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"))));
@ -320,19 +330,29 @@ void TrayWidget::showUsingPositioningSettings()
}
}
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
void TrayWidget::showInternalError(
const QString &errorMessage, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response)
{
if (!InternalError::isRelevant(connection(), category, networkError)) {
return;
}
InternalErrorsDialog::addError(errorMessage, request.url(), response);
showInternalErrorsButton();
}
void TrayWidget::showInternalErrorsButton()
{
m_internalErrorsButton->setVisible(true);
if (m_internalErrorsButton) {
m_internalErrorsButton->setVisible(true);
}
}
#endif
void TrayWidget::showInternalErrorsDialog()
{
auto *const errorViewDlg = InternalErrorsDialog::instance();
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
connect(errorViewDlg, &InternalErrorsDialog::errorsCleared, this, &TrayWidget::handleErrorsCleared);
#endif
if (m_internalErrorsButton) {
connect(errorViewDlg, &InternalErrorsDialog::errorsCleared, m_internalErrorsButton, &QWidget::hide);
}
showDialog(errorViewDlg, centerWidgetAvoidingOverflow(errorViewDlg));
}
@ -404,13 +424,6 @@ 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

View File

@ -65,9 +65,9 @@ public Q_SLOTS:
void showLog();
void showNotifications();
void showUsingPositioningSettings();
#ifdef SYNCTHINGTRAY_UNIFY_TRAY_MENUS
void showInternalError(const QString &errorMessage, Data::SyncthingErrorCategory category, int networkError, const QNetworkRequest &request,
const QByteArray &response);
void showInternalErrorsButton();
#endif
void showInternalErrorsDialog();
void dismissNotifications();
void restartSyncthing();
@ -76,9 +76,6 @@ public Q_SLOTS:
private Q_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);
@ -115,9 +112,7 @@ 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;

View File

@ -80,6 +80,15 @@ void InternalErrorsDialog::addError(InternalError &&newError)
}
}
void InternalErrorsDialog::addError(const QString &message, const QUrl &url, const QByteArray &response)
{
s_internalErrors.emplace_back(message, url, response);
if (s_instance) {
s_instance->internalAddError(s_internalErrors.back());
s_instance->updateStatusLabel();
}
}
void InternalErrorsDialog::internalAddError(const InternalError &error)
{
const QString url = error.url.toString();

View File

@ -17,6 +17,7 @@ public:
static InternalErrorsDialog *instance();
static bool hasInstance();
static void addError(InternalError &&newError);
static void addError(const QString &message = QString(), const QUrl &url = QUrl(), const QByteArray &response = QByteArray());
Q_SIGNALS:
void errorsCleared();