2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
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.
10 **************************************************************************/
12 #ifndef _MOOF_MODALDIALOG_HH_
13 #define _MOOF_MODALDIALOG_HH_
18 #include "../config.h"
21 #if defined(_WIN32) || defined(__WIN32__)
23 #elif defined(__APPLE__) && defined(__MACH__)
24 #include <Carbon/Carbon.h>
28 #include <QApplication>
30 #include <QMessageBox>
33 #include <Moof/Log.hh>
34 #include <Moof/Resource.hh>
41 * Small wrapper over various user interface modal dialog windows.
78 #if defined(_WIN32) || defined(__WIN32__)
84 iconType
= MB_ICONWARNING
;
87 iconType
= MB_ICONERROR
;
90 iconType
= MB_ICONINFORMATION
;
94 MessageBox(0, (text1
+ "\n" + text2
).c_str(), title
.c_str(),
101 gtk_init(&argc
, &argv
);
103 GtkMessageType iconType
;
107 iconType
= GTK_MESSAGE_WARNING
;
110 iconType
= GTK_MESSAGE_ERROR
;
113 iconType
= GTK_MESSAGE_INFO
;
117 GtkWidget
* dialog
= gtk_message_dialog_new(NULL
,
118 GTK_DIALOG_DESTROY_WITH_PARENT
, iconType
,
119 GTK_BUTTONS_CLOSE
, "%s", text1
.c_str());
120 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog
),
121 "%s", text2
.c_str());
122 gtk_window_set_title(GTK_WINDOW(dialog
), title
.c_str());
124 std::string iconPath
= Resource::getPath(PACKAGE
".png");
125 GdkPixbuf
* iconPixbuf
= gdk_pixbuf_new_from_file(iconPath
.c_str(),
127 gtk_window_set_icon(GTK_WINDOW(dialog
), iconPixbuf
);
129 gtk_dialog_run(GTK_DIALOG(dialog
));
130 gtk_widget_destroy(dialog
);
131 // FIXME - this doesn't seem to actually remove the window from the
132 // screen when it closes
138 QApplication
qtApp(argc
, argv
);
140 QMessageBox::Icon iconType
;
144 iconType
= QMessageBox::Warning
;
147 iconType
= QMessageBox::Critical
;
150 iconType
= QMessageBox::Information
;
155 dialog
.setWindowTitle(title
.c_str());
156 dialog
.setIcon(iconType
);
157 dialog
.setText(text1
.c_str());
158 dialog
.setInformativeText(text2
.c_str());
159 dialog
.setStandardButtons(QMessageBox::Close
);
161 std::string iconPath
= Resource::getPath(PACKAGE
".png");
162 QIcon
icon(iconPath
.c_str());
163 dialog
.setWindowIcon(icon
);
174 #endif // _MOOF_MODALDIALOG_HH_