1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     Rosegarden
5     A MIDI and audio sequencer and musical notation editor.
6     Copyright 2000-2021 the Rosegarden development team.
7 
8     Other copyrights also apply to some parts of this work.  Please
9     see the AUTHORS file and individual file headers for details.
10 
11     This program is free software; you can redistribute it and/or
12     modify it under the terms of the GNU General Public License as
13     published by the Free Software Foundation; either version 2 of the
14     License, or (at your option) any later version.  See the file
15     COPYING included with this distribution for more information.
16 */
17 
18 #ifndef RG_WARNING_WIDGET_H
19 #define RG_WARNING_WIDGET_H
20 
21 #include "WarningDialog.h"
22 
23 #include <QLabel>
24 #include <QToolButton>
25 #include <QQueue>
26 
27 
28 namespace Rosegarden
29 {
30 
31 
32 /** Fed with data from the sequence manager, this widget displays the status of
33  * various environmental runtime factors, and provides detailed information to
34  * users when sub-optimal runtime conditions are detected.  This mechanism
35  * replaces the tedious parade of startup warning dialogs we used to dump in the
36  * user's face the first time they tried to run Rosegarden on an ordinary
37  * everyday desktop-oriented distro.
38  *
39  * This widget is managed by RosegardenMainWindow, which receives signals
40  * primarily from SequenceManager and passes them through into here, calling
41  * set___Warning(true) as appropriate, and adding a new warning message to our
42  * queue.
43  *
44  * Adding a message to the queue causes the warning button to show itself, and
45  * when clicked, the queued warning messages are displayed in a tabbed dialog.
46  *
47  * \author D. Michael Mcintyre
48  */
49 class WarningWidget : public QWidget
50 {
51     Q_OBJECT
52 public:
53 
54     typedef enum { Midi, Audio, Timer, Other, Info } WarningType;
55 
56     /** Constructs a WarningWidget in a default all clear state that assumes
57      * MIDI, audio, and the system timer are all functioning correctly.  This
58      * widget is intended to be displayed on the status bar in the main window.
59      */
60     WarningWidget(QWidget *parent = nullptr);
61     ~WarningWidget() override;
62 
63     void setMidiWarning(const bool status);
64     void setAudioWarning(const bool status);
65     void setTimerWarning(const bool status);
66 
67     /** Add a message (consisting of a text and an informative text) to the
68      * queue.  These will be displayed via displayMessageQueue() when the user
69      * clicks the warning icon
70      */
71     void queueMessage(const int type, const QString text, const QString informativeText);
72 
73     /** We'll build the message queue out of these for convenience, so both the
74      * text and informative text can be tossed about as one unit, along with a
75      * flag indicating the type of warning
76      */
77     typedef std::pair<std::pair<QString, QString>, int> Message;
78 
79 protected:
80     QLabel *m_midiIcon;
81     QLabel *m_audioIcon;
82     QLabel *m_timerIcon;
83 
84     QToolButton *m_warningButton;
85     QToolButton *m_infoButton;
86 
87     QString m_text;
88     QString m_informativeText;
89 
90     /** The message queue itself
91      */
92     QQueue<Message> m_queue;
93 
94     WarningDialog *m_warningDialog;
95 
96 protected slots:
97 
98     /** Display the message queue in a suitable dialog, on demand
99      */
100     void displayMessageQueue();
101 };
102 
103 
104 }
105 
106 #endif
107