removed doxygen; distcheck bugfix
[chaz/yoink] / src / Moof / ModalDialog.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_MODALDIALOG_HH_
13 #define _MOOF_MODALDIALOG_HH_
14
15 #include <string>
16
17 #if HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #if defined(_WIN32)
22 #include <windows.h>
23 #elif defined(__APPLE__) && defined(__MACH__)
24 #include <Carbon/Carbon.h>
25 #elif USE_GTK
26 #include <gtk/gtk.h>
27 #elif USE_QT4
28 #include <QApplication>
29 #include <QIcon>
30 #include <QMessageBox>
31 #endif
32
33 #include <Moof/Log.hh>
34 #include <Moof/Resource.hh>
35
36
37 namespace Mf {
38
39
40 /**
41 * Small wrapper over various user interface modal dialog windows.
42 */
43
44 struct ModalDialog
45 {
46 enum Type
47 {
48 INFO = 1,
49 WARNING = 2,
50 CRITICAL = 3
51 };
52
53
54 std::string title;
55 Type type;
56 std::string text1;
57 std::string text2;
58
59
60
61 ModalDialog(Type pType = INFO,
62 const std::string& pTitle = "",
63 const std::string& pText1 = "",
64 const std::string& pText2 = "") :
65 title(pTitle),
66 type(pType),
67 text1(pText1),
68 text2(pText2) {}
69
70
71 void run() const
72 {
73 switch (type)
74 {
75 case WARNING:
76 logWarning(text1);
77 logWarning(text2);
78 break;
79 case CRITICAL:
80 logError(text1);
81 logError(text2);
82 break;
83 default:
84 logInfo(text1);
85 logInfo(text2);
86 break;
87 }
88
89 #if defined(_WIN32)
90
91 int iconType;
92 switch (type)
93 {
94 case WARNING:
95 iconType = MB_ICONWARNING;
96 break;
97 case CRITICAL:
98 iconType = MB_ICONERROR;
99 break;
100 default:
101 iconType = MB_ICONINFORMATION;
102 break;
103 }
104
105 MessageBox(0, (text1 + "\n" + text2).c_str(), title.c_str(),
106 MB_OK | iconType);
107
108 #elif USE_GTK
109
110 int argc = 0;
111 char** argv;
112 gtk_init(&argc, &argv);
113
114 GtkMessageType iconType;
115 switch (type)
116 {
117 case WARNING:
118 iconType = GTK_MESSAGE_WARNING;
119 break;
120 case CRITICAL:
121 iconType = GTK_MESSAGE_ERROR;
122 break;
123 default:
124 iconType = GTK_MESSAGE_INFO;
125 break;
126 }
127
128 GtkWidget* dialog = gtk_message_dialog_new(NULL,
129 GTK_DIALOG_DESTROY_WITH_PARENT, iconType,
130 GTK_BUTTONS_CLOSE, "%s", text1.c_str());
131 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
132 "%s", text2.c_str());
133 gtk_window_set_title(GTK_WINDOW(dialog), title.c_str());
134
135 std::string iconPath(PACKAGE".png");
136 if (Resource::getPath(iconPath))
137 {
138 GdkPixbuf* iconPixbuf = gdk_pixbuf_new_from_file(iconPath.c_str(),
139 NULL);
140 gtk_window_set_icon(GTK_WINDOW(dialog), iconPixbuf);
141 }
142
143 gtk_dialog_run(GTK_DIALOG(dialog));
144 gtk_widget_destroy(dialog);
145 // FIXME - this doesn't seem to actually remove the window from the
146 // screen when it closes
147
148 #elif USE_QT4
149
150 int argc = 0;
151 char** argv;
152 QApplication qtApp(argc, argv);
153
154 QMessageBox::Icon iconType;
155 switch (type)
156 {
157 case WARNING:
158 iconType = QMessageBox::Warning;
159 break;
160 case CRITICAL:
161 iconType = QMessageBox::Critical;
162 break;
163 default:
164 iconType = QMessageBox::Information;
165 break;
166 }
167
168 QMessageBox dialog;
169 dialog.setWindowTitle(title.c_str());
170 dialog.setIcon(iconType);
171 dialog.setText(text1.c_str());
172 dialog.setInformativeText(text2.c_str());
173 dialog.setStandardButtons(QMessageBox::Close);
174
175 std::string iconPath(PACKAGE".png");
176 if (Resource::getPath(iconPath))
177 {
178 QIcon icon(iconPath.c_str());
179 dialog.setWindowIcon(icon);
180 }
181
182 dialog.exec();
183
184 #endif
185 }
186 };
187
188
189 } // namespace Mf
190
191 #endif // _MOOF_MODALDIALOG_HH_
192
This page took 0.037707 seconds and 4 git commands to generate.