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"
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
= Resource::getPath(PACKAGE
".png");
136 GdkPixbuf
* iconPixbuf
= gdk_pixbuf_new_from_file(iconPath
.c_str(),
138 gtk_window_set_icon(GTK_WINDOW(dialog
), iconPixbuf
);
140 gtk_dialog_run(GTK_DIALOG(dialog
));
141 gtk_widget_destroy(dialog
);
142 // FIXME - this doesn't seem to actually remove the window from the
143 // screen when it closes
149 QApplication
qtApp(argc
, argv
);
151 QMessageBox::Icon iconType
;
155 iconType
= QMessageBox::Warning
;
158 iconType
= QMessageBox::Critical
;
161 iconType
= QMessageBox::Information
;
166 dialog
.setWindowTitle(title
.c_str());
167 dialog
.setIcon(iconType
);
168 dialog
.setText(text1
.c_str());
169 dialog
.setInformativeText(text2
.c_str());
170 dialog
.setStandardButtons(QMessageBox::Close
);
172 std::string iconPath
= Resource::getPath(PACKAGE
".png");
173 QIcon
icon(iconPath
.c_str());
174 dialog
.setWindowIcon(icon
);
185 #endif // _MOOF_MODALDIALOG_HH_