Fix showing error dialog minimized when main window is not active
Fixes #1739
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2013-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2013-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -296,6 +296,9 @@ MainWindow::MainWindow(Application *app,
|
||||
#ifdef HAVE_DISCORD_RPC
|
||||
discord_rich_presence_(discord_rich_presence),
|
||||
#endif
|
||||
error_dialog_([this]() {
|
||||
return new ErrorDialog(this);
|
||||
}),
|
||||
console_([app, this]() {
|
||||
Console *console = new Console(app->database());
|
||||
QObject::connect(console, &Console::Error, this, &MainWindow::ShowErrorDialog);
|
||||
@@ -1684,17 +1687,6 @@ void MainWindow::StopAfterCurrent() {
|
||||
Q_EMIT StopAfterToggled(app_->playlist_manager()->active()->stop_after_current());
|
||||
}
|
||||
|
||||
void MainWindow::showEvent(QShowEvent *e) {
|
||||
|
||||
if (error_dialog_ && error_dialog_->isVisible() && error_dialog_->isMinimized()) {
|
||||
error_dialog_->raise();
|
||||
error_dialog_->activateWindow();
|
||||
}
|
||||
|
||||
QMainWindow::showEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::hideEvent(QHideEvent *e) {
|
||||
|
||||
// Some window managers don't remember maximized state between
|
||||
@@ -1717,6 +1709,16 @@ void MainWindow::closeEvent(QCloseEvent *e) {
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::changeEvent(QEvent *e) {
|
||||
|
||||
if (e->type() == QEvent::Show || e->type() == QEvent::WindowStateChange || e->type() == QEvent::WindowActivate) {
|
||||
CheckShowErrorDialog();
|
||||
}
|
||||
|
||||
QMainWindow::changeEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::SetHiddenInTray(const bool hidden) {
|
||||
|
||||
if (hidden && isVisible()) {
|
||||
@@ -1737,6 +1739,7 @@ void MainWindow::SetHiddenInTray(const bool hidden) {
|
||||
else {
|
||||
show();
|
||||
}
|
||||
CheckShowErrorDialog();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2990,6 +2993,14 @@ void MainWindow::ShowErrorDialog(const QString &message) {
|
||||
error_dialog_->ShowMessage(message);
|
||||
}
|
||||
|
||||
void MainWindow::CheckShowErrorDialog() {
|
||||
|
||||
if (isVisible() && !isMinimized() && error_dialog_ && error_dialog_->isVisible() && !error_dialog_->isActiveWindow()) {
|
||||
error_dialog_->ShowDialog();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::CheckFullRescanRevisions() {
|
||||
|
||||
int from = app_->database()->startup_schema_version();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2013-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2013-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -124,9 +124,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
void CommandlineOptionsReceived(const CommandlineOptions &options);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
void hideEvent(QHideEvent *e) override;
|
||||
void closeEvent(QCloseEvent *e) override;
|
||||
void changeEvent(QEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
#ifdef Q_OS_WIN32
|
||||
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
|
||||
@@ -236,6 +236,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
|
||||
void ShowAboutDialog();
|
||||
void ShowErrorDialog(const QString &message);
|
||||
void CheckShowErrorDialog();
|
||||
void ShowTranscodeDialog();
|
||||
SettingsDialog *CreateSettingsDialog();
|
||||
EditTagDialog *CreateEditTagDialog();
|
||||
@@ -315,6 +316,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
#ifdef HAVE_DISCORD_RPC
|
||||
discord::RichPresence *discord_rich_presence_;
|
||||
#endif
|
||||
Lazy<ErrorDialog> error_dialog_;
|
||||
Lazy<About> about_dialog_;
|
||||
Lazy<Console> console_;
|
||||
Lazy<EditTagDialog> edit_tag_dialog_;
|
||||
@@ -329,7 +331,6 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
PlaylistListContainer *playlist_list_;
|
||||
QueueView *queue_view_;
|
||||
|
||||
Lazy<ErrorDialog> error_dialog_;
|
||||
Lazy<SettingsDialog> settings_dialog_;
|
||||
Lazy<AlbumCoverManager> cover_manager_;
|
||||
SharedPtr<Equalizer> equalizer_;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2017-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -32,14 +33,16 @@
|
||||
#include <QTextEdit>
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include "utilities/screenutils.h"
|
||||
|
||||
#include "errordialog.h"
|
||||
#include "ui_errordialog.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
ErrorDialog::ErrorDialog(QWidget *parent)
|
||||
ErrorDialog::ErrorDialog(QWidget *mainwindow, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
parent_(parent),
|
||||
mainwindow_(mainwindow),
|
||||
ui_(new Ui_ErrorDialog) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
@@ -59,6 +62,18 @@ ErrorDialog::~ErrorDialog() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void ErrorDialog::ShowDialog() {
|
||||
|
||||
if (screen() && mainwindow_->screen() && screen() != mainwindow_->screen()) {
|
||||
Utilities::CenterWidgetOnScreen(mainwindow_->screen(), this);
|
||||
}
|
||||
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||||
show();
|
||||
raise();
|
||||
activateWindow();
|
||||
|
||||
}
|
||||
|
||||
void ErrorDialog::ShowMessage(const QString &message) {
|
||||
|
||||
if (message.isEmpty()) return;
|
||||
@@ -66,11 +81,11 @@ void ErrorDialog::ShowMessage(const QString &message) {
|
||||
current_messages_ << message;
|
||||
UpdateContent();
|
||||
|
||||
show();
|
||||
|
||||
if (parent_ && parent_->isMaximized()) {
|
||||
raise();
|
||||
activateWindow();
|
||||
if (mainwindow_->isActiveWindow()) {
|
||||
ShowDialog();
|
||||
}
|
||||
else if (!isVisible()) {
|
||||
showMinimized();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2017-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -36,10 +37,11 @@ class ErrorDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ErrorDialog(QWidget *parent = nullptr);
|
||||
explicit ErrorDialog(QWidget *mainwindow, QWidget *parent = nullptr);
|
||||
~ErrorDialog() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void ShowDialog();
|
||||
void ShowMessage(const QString &message);
|
||||
|
||||
protected:
|
||||
@@ -48,7 +50,7 @@ class ErrorDialog : public QDialog {
|
||||
private:
|
||||
void UpdateContent();
|
||||
|
||||
QWidget *parent_;
|
||||
QWidget *mainwindow_;
|
||||
Ui_ErrorDialog *ui_;
|
||||
|
||||
QStringList current_messages_;
|
||||
|
||||
Reference in New Issue
Block a user