Skip to content

Commit

Permalink
ui-common: Append to existing error window (up to 10 lines). Closes: …
Browse files Browse the repository at this point in the history
…#1147
  • Loading branch information
jlindgren90 committed Jan 8, 2022
1 parent 75b5c39 commit 94453fe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
35 changes: 33 additions & 2 deletions src/ui-common/dialogs-qt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@

#include <libaudcore/i18n.h>
#include <libaudqt/libaudqt.h>
#include <QAbstractButton>

static QMessageBox * create_message_box (QMessageBox::Icon icon,
const QString & title, const QString & message, QWidget * parent)
{
auto msgbox = new QMessageBox (icon, title, message, QMessageBox::Close, parent);
msgbox->setAttribute (Qt::WA_DeleteOnClose);
msgbox->setTextInteractionFlags (Qt::TextSelectableByMouse);
msgbox->button (QMessageBox::Close)->setText (audqt::translate_str (N_("_Close")));
return msgbox;
}

static void add_message (QMessageBox * msgbox, QString message)
{
QString old = msgbox->text ();
if (old.count (QChar::LineFeed) >= 9)
message = _("\n(Further messages have been hidden.)");
if (! old.contains (message))
msgbox->setText (old + QChar::LineFeed + message);
}

void DialogWindows::create_progress ()
{
if (! m_progress)
{
m_progress = new QMessageBox (m_parent);
m_progress->setAttribute (Qt::WA_DeleteOnClose);
m_progress->setIcon (QMessageBox::Information);
m_progress->setWindowTitle (_("Working ..."));
m_progress->setWindowModality (Qt::WindowModal);
Expand All @@ -35,12 +56,22 @@ void DialogWindows::create_progress ()

void DialogWindows::show_error (const char * message)
{
audqt::simple_message (_("Error"), message, QMessageBox::Critical);
if (m_error)
add_message (m_error, message);
else
m_error = create_message_box (QMessageBox::Critical, _("Error"), message, m_parent);

m_error->show ();
}

void DialogWindows::show_info (const char * message)
{
audqt::simple_message (_("Information"), message, QMessageBox::Information);
if (m_info)
add_message (m_info, message);
else
m_info = create_message_box (QMessageBox::Information, _("Information"), message, m_parent);

m_info->show ();
}

void DialogWindows::show_progress (const char * message)
Expand Down
3 changes: 2 additions & 1 deletion src/ui-common/dialogs-qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define DIALOG_WINDOWS_H

#include <libaudcore/hook.h>
#include <QPointer>

class QMessageBox;
class QWidget;
Expand All @@ -33,7 +34,7 @@ class DialogWindows

private:
QWidget * m_parent;
QMessageBox * m_progress = nullptr;
QPointer<QMessageBox> m_progress, m_info, m_error;

void create_progress ();
void show_error (const char * message);
Expand Down

0 comments on commit 94453fe

Please sign in to comment.