File: MessageBox.h

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (209 lines) | stat: -rw-r--r-- 7,399 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/***************************************************************************
            MessageBox.h -  threasafe wrapper for KMessageBox
                             -------------------
    begin                : Sun Apr 13 2008
    copyright            : (C) 2008 by Thomas Eschenbacher
    email                : Thomas.Eschenbacher@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef MESSAGE_BOX_H
#define MESSAGE_BOX_H

#include "config.h"
#include "libkwave_export.h"

#include <QtGlobal>
#include <QObject>
#include <QSemaphore>
#include <QString>

#include <KMessageBox>

class QWidget;

namespace Kwave
{

    class LIBKWAVE_EXPORT MessageBox: public QObject
    {
    Q_OBJECT

    public:

        /** @see KMessageBox::questionYesNo */
        static int questionYesNo(QWidget *widget,
            QString message, QString caption = QString(),
            const QString buttonYes = QString(),
            const QString buttonNo  = QString(),
            const QString &dontAskAgainName = QString());

        /** @see KMessageBox::questionYesNoCancel */
        static int questionYesNoCancel(QWidget *widget,
            QString message, QString caption = QString(),
            const QString buttonYes = QString(),
            const QString buttonNo = QString(),
            const QString &dontAskAgainName = QString());

        /** @see KMessageBox::error */
        static int sorry(QWidget *widget,
            QString message, QString caption = QString());

        /** @see KMessageBox::warningYesNo */
        static int warningYesNo(QWidget *widget,
            QString message, QString caption = QString(),
            const QString buttonYes = QString(),
            const QString buttonNo = QString(),
            const QString &dontAskAgainName = QString());

        /** @see KMessageBox::warningYesNoCancel */
        static int warningYesNoCancel(QWidget *widget,
            QString message, QString caption = QString(),
            const QString buttonYes = QString(),
            const QString buttonNo = QString(),
            const QString &dontAskAgainName = QString());

        /** @see KMessageBox::warningContinueCancel */
        static int warningContinueCancel(QWidget *widget,
            QString message, QString caption = QString(),
            const QString buttonContinue = QString(),
            const QString buttonCancel = QString(),
            const QString &dontAskAgainName = QString());

        /** @see KMessageBox::error */
        static int error(QWidget *widget,
            QString message, QString caption = QString());

    private:

        /** Default constructor (not implemented) */
        MessageBox();

        /**
         * Constructor
         * @param mode the mode of the message box, error/warning/etc...
         * @param parent parent widget
         * @param message the message text of the box
         * @param caption title of the window
         * @param button1 a KGuiItem for the first button (optional)
         * @param button2 a KGuiItem for the second button (optional)
         * @param dontAskAgainName tag name for "do not ask again"
         */
        MessageBox(KMessageBox::DialogType mode, QWidget *parent,
            QString message, QString caption,
            const QString &button1 = QString(),
            const QString &button2 = QString(),
            const QString &dontAskAgainName = QString());

        /** Destructor */
        ~MessageBox() override;

        /** returns the return value of the KMessageBox */
        virtual int retval() const;

        /**
         * Creates and executes a KMessageBox in the same thread or via
         * a blocking signal, depending on whether the current context
         * is the GUI thread or not.
         *
         * @param mode type of the message box @see KMessageBox::DialogType
         * @param parent the parent widget
         * @param message the text of the message box
         * @param caption the window title (optional)
         * @param button1 a KGuiItem for the first button (optional)
         * @param button2 a KGuiItem for the second button (optional)
         * @param dontAskAgainName tag name for "do not ask again"
         * @return the result of the call to KMessageBox::xxx or -1
         */
        static int exec(KMessageBox::DialogType mode, QWidget *parent,
            QString message, QString caption = QString(),
            const QString &button1 = QString(),
            const QString &button2 = QString(),
            const QString &dontAskAgainName = QString());

        /**
         * replacement for KStandardGuiItem::yes(), which has been deprecated
         */
        static KGuiItem yes();

        /**
         * replacement for KStandardGuiItem::no(), which has been deprecated
         */
        static KGuiItem no();

    protected:
        /**
         * shows the KMessageBox, always called in the GUI
         * thread context.
         */
        void show();

    private:

        /** internal helper for showing the KMessageBox in the GUI thread */
        class Trigger: public QObject
        {
        public:
            /**
             * Constructor, re-parents itself to the GUI thread
             * @param box the Kwave::MessageBox to use
             */
            explicit Trigger(Kwave::MessageBox &box);

            /**
             * Destructor. Will always be executed in the GUI thread,
             * because the instance of this object is moved to the GUI
             * thread and deleteLater() is called. This calls the "show()"
             * method of the Kwave::MessageBox in a safe context.
             */
            virtual ~Trigger() override;

        private:

            /** reference to the Kwave::MessageBox instance */
            Kwave::MessageBox &m_box;
        };

    private:

        /** semaphore for waiting on the GUI thread */
        QSemaphore m_semaphore;

        /** return value of the execution of the message box */
        int m_retval;

        /** @see KMessageBox::DialogType */
        KMessageBox::DialogType m_mode;

        /** the parent widget */
        QWidget *m_parent;

        /** the text of the message box */
        QString m_message;

        /** the window title (optional) */
        QString m_caption;

        /** first button (optional) */
        const QString m_button1;

        /** second button (optional) */
        const QString m_button2;

        /** tag for "do not ask again" (optional) */
        const QString m_dont_ask_again_name;
    };
}

#endif /* MESSAGE_BOX_H */

//***************************************************************************
//***************************************************************************