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_
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.
61 ModalDialog(Type pType
= INFO
,
62 const std::string
& pTitle
= "",
63 const std::string
& pText1
= "",
64 const std::string
& pText2
= "") :
95 iconType
= MB_ICONWARNING
;
98 iconType
= MB_ICONERROR
;
101 iconType
= MB_ICONINFORMATION
;
105 MessageBox(0, (text1
+ "\n" + text2
).c_str(), title
.c_str(),
112 gtk_init(&argc
, &argv
);
114 GtkMessageType iconType
;
118 iconType
= GTK_MESSAGE_WARNING
;
121 iconType
= GTK_MESSAGE_ERROR
;
124 iconType
= GTK_MESSAGE_INFO
;
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());
135 std::string
iconPath(PACKAGE
".png");
136 if (Resource::getPath(iconPath
))
138 GdkPixbuf
* iconPixbuf
= gdk_pixbuf_new_from_file(iconPath
.c_str(),
140 gtk_window_set_icon(GTK_WINDOW(dialog
), iconPixbuf
);
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
152 QApplication
qtApp(argc
, argv
);
154 QMessageBox::Icon iconType
;
158 iconType
= QMessageBox::Warning
;
161 iconType
= QMessageBox::Critical
;
164 iconType
= QMessageBox::Information
;
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
);
175 std::string
iconPath(PACKAGE
".png");
176 if (Resource::getPath(iconPath
))
178 QIcon
icon(iconPath
.c_str());
179 dialog
.setWindowIcon(icon
);
191 #endif // _MOOF_MODALDIALOG_HH_