2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
10 #ifndef _MOOF_MODAL_DIALOG_HH_
11 #define _MOOF_MODAL_DIALOG_HH_
24 #include <QApplication>
26 #include <QMessageBox>
29 #include <moof/log.hh>
30 #include <moof/resource.hh>
34 * \file modal_dialog.hh
35 * A class for creating and running modal dialogs. Several toolkits are
36 * supported, but only one can be used as determined at build time.
43 * Small wrapper over various user interface modal dialog windows.
60 * Construct a dialog box.
61 * \param type The type of dialog, indicating its priority.
62 * \param title The text used as the title of the dialog.
63 * \param text1 The first line of the dialog window.
64 * \param text2 The second line.
66 modal_dialog(enum type type
= information
,
67 const std::string
& title
= "",
68 const std::string
& text1
= "",
69 const std::string
& text2
= "") :
98 icon_type
= MB_ICONWARNING
;
101 icon_type
= MB_ICONERROR
;
104 icon_type
= MB_ICONINFORMATION
;
108 MessageBox(0, (text1
+ "\n" + text2
).c_str(), title
.c_str(),
113 gtk_init(&argc
, &argv
);
115 GtkMessageType icon_type
;
119 icon_type
= GTK_MESSAGE_WARNING
;
122 icon_type
= GTK_MESSAGE_ERROR
;
125 icon_type
= GTK_MESSAGE_INFO
;
129 GtkWidget
* dialog
= gtk_message_dialog_new(NULL
,
130 GTK_DIALOG_DESTROY_WITH_PARENT
, icon_type
,
131 GTK_BUTTONS_CLOSE
, "%s", text1
.c_str());
132 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog
),
133 "%s", text2
.c_str());
134 gtk_window_set_title(GTK_WINDOW(dialog
), title
.c_str());
136 std::string icon_path
= resource::find_file(PACKAGE_TARNAME
".png");
137 if (!icon_path
.empty())
139 GdkPixbuf
* iconPixbuf
= gdk_pixbuf_new_from_file(icon_path
.c_str(),
141 gtk_window_set_icon(GTK_WINDOW(dialog
), iconPixbuf
);
144 gtk_dialog_run(GTK_DIALOG(dialog
));
145 gtk_widget_destroy(dialog
);
146 // FIXME - this doesn't seem to actually remove the window from the
147 // screen when it closes
151 QApplication
qt_app(argc
, argv
);
153 QMessageBox::Icon icon_type
;
157 icon_type
= QMessageBox::Warning
;
160 icon_type
= QMessageBox::Critical
;
163 icon_type
= QMessageBox::Information
;
168 dialog
.setWindowTitle(title
.c_str());
169 dialog
.setIcon(icon_type
);
170 dialog
.setText(text1
.c_str());
171 dialog
.setInformativeText(text2
.c_str());
172 dialog
.setStandardButtons(QMessageBox::Close
);
174 std::string icon_path
= resource::find_file(PACKAGE_TARNAME
".png");
175 if (!icon_path
.empty())
177 QIcon
icon(icon_path
.c_str());
178 dialog
.setWindowIcon(icon
);
189 #endif // _MOOF_MODAL_DIALOG_HH_