1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2015-01-19
7  * Description : message box notification settings
8  *
9  * Copyright (C) 2015-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_DMESSAGE_BOX_H
25 #define DIGIKAM_DMESSAGE_BOX_H
26 
27 // Qt includes
28 
29 #include <QWidget>
30 #include <QString>
31 #include <QMessageBox>
32 #include <QListWidget>
33 
34 // Local includes
35 
36 #include "digikam_export.h"
37 
38 class QDialog;
39 class QDialogButtonBox;
40 
41 namespace Digikam
42 {
43 
44 class DIGIKAM_EXPORT DMessageBox
45 {
46 
47 public:
48 
49     /**
50      * @return true if the corresponding message box should be shown.
51      * @param dontShowAgainName the name that identify the message box. If
52      * empty, this method return false.
53      */
54     static bool readMsgBoxShouldBeShown(const QString& dontShowAgainName);
55 
56     /**
57      * Save the fact that the message box should not be shown again.
58      * @param dontShowAgainName the name that identify the message box. If
59      * empty, this method does nothing.
60      * @param value the value chosen in the message box to show it again next time.
61      */
62     static void saveMsgBoxShouldBeShown(const QString& dontShowAgainName, bool value);
63 
64 public:
65 
66     /**
67      * Show List of items into an informative message box.
68      */
69     static void showInformationList(QMessageBox::Icon icon,
70                                     QWidget* const parent,
71                                     const QString& caption,
72                                     const QString& text,
73                                     const QStringList& items,
74                                     const QString& dontShowAgainName = QString());
75 
76     /**
77      * Show widget into an informative message box.
78      */
79     static void showInformationWidget(QMessageBox::Icon icon,
80                                       QWidget* const parent,
81                                       const QString& caption,
82                                       const QString& text,
83                                       QWidget* const listWidget,
84                                       const QString& dontShowAgainName);
85 
86 public:
87 
88     /**
89      * Show a message box with Continue and Cancel buttons, and wait user feedback.
90      * Return QMessageBox::Yes or QMessageBox::Cancel.
91      */
92     static int showContinueCancel(QMessageBox::Icon icon,
93                                   QWidget* const parent,
94                                   const QString& caption,
95                                   const QString& text,
96                                   const QString& dontAskAgainName = QString());
97 
98     /**
99      * Show List of items to process into a message box with Continue and Cancel buttons,
100      * and wait user feedback.
101      * Return QMessageBox::Yes or QMessageBox::Cancel.
102      */
103     static int showContinueCancelList(QMessageBox::Icon icon,
104                                       QWidget* const parent,
105                                       const QString& caption,
106                                       const QString& text,
107                                       const QStringList& items,
108                                       const QString& dontAskAgainName = QString());
109 
110     /**
111      * Show widget into a message box with Continue and Cancel buttons,
112      * and wait user feedback.
113      * Return QMessageBox::Yes or QMessageBox::Cancel.
114      */
115     static int showContinueCancelWidget(QMessageBox::Icon icon,
116                                         QWidget* const parent,
117                                         const QString& caption,
118                                         const QString& text,
119                                         QWidget* const listWidget,
120                                         const QString& dontAskAgainName);
121 
122 public:
123 
124     /**
125      * Show a message box with Yes and No buttons, and wait user feedback.
126      * Return QMessageBox::Yes or QMessageBox::No.
127      */
128     static int showYesNo(QMessageBox::Icon icon,
129                          QWidget* const parent,
130                          const QString& caption,
131                          const QString& text,
132                          const QString& dontAskAgainName = QString());
133 
134     /**
135      * Show List of items to process into a message box with Yes and No buttons,
136      * and wait user feedback.
137      * Return QMessageBox::Yes or QMessageBox::No.
138      */
139     static int showYesNoList(QMessageBox::Icon icon,
140                              QWidget* const parent,
141                              const QString& caption,
142                              const QString& text,
143                              const QStringList& items,
144                              const QString& dontAskAgainName = QString());
145 
146     /**
147      * Show widget into a message box with Yes and No buttons,
148      * and wait user feedback.
149      * Return QMessageBox::Yes or QMessageBox::No.
150      */
151     static int showYesNoWidget(QMessageBox::Icon icon,
152                                QWidget* const parent,
153                                const QString& caption,
154                                const QString& text,
155                                QWidget* const listWidget,
156                                const QString& dontAskAgainName = QString());
157 
158 private:
159 
160     static int createMessageBox(QDialog* const dialog,
161                                 QDialogButtonBox* const buttons,
162                                 const QIcon& icon,
163                                 const QString& text,
164                                 QWidget* const listWidget,
165                                 const QString& ask,
166                                 bool* checkboxReturn);
167 
168     static QIcon createIcon(QMessageBox::Icon icon);
169 
170     static QListWidget* createWidgetList(const QStringList& items);
171 };
172 
173 } // namespace Digikam
174 
175 #endif // DIGIKAM_DMESSAGE_BOX_H
176