1 /*
2  * Cantata
3  *
4  * Copyright (c) 2011-2020 Craig Drummond <craig.p.drummond@gmail.com>
5  *
6  * ----
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; see the file COPYING.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #ifndef MESSAGEBOX_H
25 #define MESSAGEBOX_H
26 
27 #include "dialog.h"
28 #include <QMessageBox>
29 
30 namespace MessageBox {
31     enum ButtonCode {
32         Yes=QMessageBox::Yes,
33         No=QMessageBox::No,
34         Cancel=QMessageBox::Cancel
35     };
36     enum Type {
37         Error = QMessageBox::Critical,
38         Question = QMessageBox::Question,
39         Warning = QMessageBox::Warning,
40         Information = QMessageBox::Information
41     };
42 
43     extern ButtonCode questionYesNoCancel(QWidget *parent, const QString &message, const QString &title=QString(),
44                                           const GuiItem &yesText=StdGuiItem::yes(), const GuiItem &noText=StdGuiItem::no(), bool showCancel=true, bool isWarning=false);
45     inline ButtonCode questionYesNo(QWidget *parent, const QString &message, const QString &title=QString(), const GuiItem &yesText=StdGuiItem::yes(), const GuiItem &noText=StdGuiItem::no()) {
46         return questionYesNoCancel(parent, message, title, yesText, noText, false);
47     }
48     inline ButtonCode warningYesNoCancel(QWidget *parent, const QString &message, const QString &title=QString(),
49                                const GuiItem &yesText=StdGuiItem::yes(), const GuiItem &noText=StdGuiItem::no()) {
50         return questionYesNoCancel(parent, message, title, yesText, noText, true, true);
51     }
52     inline ButtonCode warningYesNo(QWidget *parent, const QString &message, const QString &title=QString(), const GuiItem &yesText=StdGuiItem::yes(), const GuiItem &noText=StdGuiItem::no()) {
53         return questionYesNoCancel(parent, message, title, yesText, noText, false, true);
54     }
55     #ifdef Q_OS_MAC
56     extern void error(QWidget *parent, const QString &message, const QString &title=QString());
57     extern void information(QWidget *parent, const QString &message, const QString &title=QString());
58     #else
59     inline void error(QWidget *parent, const QString &message, const QString &title=QString()) {
60         QMessageBox::critical(parent, title.isEmpty() ? QObject::tr("Error") : title, message);
61     }
62     inline void information(QWidget *parent, const QString &message, const QString &title=QString()) {
63         QMessageBox::information(parent, title.isEmpty() ? QObject::tr("Information") : title, message);
64     }
65     #endif
66     extern ButtonCode msgListEx(QWidget *parent, Type type, const QString &message, const QStringList &strlist, const QString &title=QString());
67     inline void errorListEx(QWidget *parent, const QString &message, const QStringList &strlist, const QString &title=QString()) {
68         msgListEx(parent, Error, message, strlist, title);
69     }
70     inline void errorList(QWidget *parent, const QString &message, const QStringList &strlist, const QString &title=QString()) {
71         msgListEx(parent, Error, message, strlist, title);
72     }
73     inline ButtonCode questionYesNoList(QWidget *parent, const QString &message, const QStringList &strlist, const QString &title=QString()) {
74         return msgListEx(parent, Question, message, strlist, title);
75     }
76     inline ButtonCode warningYesNoList(QWidget *parent, const QString &message, const QStringList &strlist, const QString &title=QString()) {
77         return msgListEx(parent, Warning, message, strlist, title);
78     }
79     inline void informationList(QWidget *parent, const QString &message, const QStringList &strlist, const QString &title=QString()) {
80         msgListEx(parent, Information, message, strlist, title);
81     }
82 }
83 
84 #endif
85