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_MODAL_DIALOG_HH_
13 #define _MOOF_MODAL_DIALOG_HH_
16 * \file modal_dialog.hh
17 * A class for creating and running modal dialogs. Several toolkits are
18 * supported, but only one can be used as determined at build time.
32 #include <QApplication>
34 #include <QMessageBox>
37 #include <moof/log.hh>
38 #include <moof/resource.hh>
45 * Small wrapper over various user interface modal dialog windows.
65 * Construct a dialog box.
66 * \param type The type of dialog, indicating its priority.
67 * \param title The text used as the title of the dialog.
68 * \param text1 The first line of the dialog window.
69 * \param text2 The second line.
71 modal_dialog(enum type type
= information
,
72 const std::string
& title
= "",
73 const std::string
& text1
= "",
74 const std::string
& text2
= "") :
105 icon_type
= MB_ICONWARNING
;
108 icon_type
= MB_ICONERROR
;
111 icon_type
= MB_ICONINFORMATION
;
115 MessageBox(0, (text1
+ "\n" + text2
).c_str(), title
.c_str(),
122 gtk_init(&argc
, &argv
);
124 GtkMessageType icon_type
;
128 icon_type
= GTK_MESSAGE_WARNING
;
131 icon_type
= GTK_MESSAGE_ERROR
;
134 icon_type
= GTK_MESSAGE_INFO
;
138 GtkWidget
* dialog
= gtk_message_dialog_new(NULL
,
139 GTK_DIALOG_DESTROY_WITH_PARENT
, icon_type
,
140 GTK_BUTTONS_CLOSE
, "%s", text1
.c_str());
141 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog
),
142 "%s", text2
.c_str());
143 gtk_window_set_title(GTK_WINDOW(dialog
), title
.c_str());
145 std::string
icon_path(PACKAGE
".png");
146 if (resource::find(icon_path
))
148 GdkPixbuf
* iconPixbuf
= gdk_pixbuf_new_from_file(icon_path
.c_str(),
150 gtk_window_set_icon(GTK_WINDOW(dialog
), iconPixbuf
);
153 gtk_dialog_run(GTK_DIALOG(dialog
));
154 gtk_widget_destroy(dialog
);
155 // FIXME - this doesn't seem to actually remove the window from the
156 // screen when it closes
162 QApplication
qt_app(argc
, argv
);
164 QMessageBox::Icon icon_type
;
168 icon_type
= QMessageBox::Warning
;
171 icon_type
= QMessageBox::Critical
;
174 icon_type
= QMessageBox::Information
;
179 dialog
.setWindowTitle(title
.c_str());
180 dialog
.setIcon(icon_type
);
181 dialog
.setText(text1
.c_str());
182 dialog
.setInformativeText(text2
.c_str());
183 dialog
.setStandardButtons(QMessageBox::Close
);
185 std::string
icon_path(PACKAGE
".png");
186 if (resource::find(icon_path
))
188 QIcon
icon(icon_path
.c_str());
189 dialog
.setWindowIcon(icon
);
201 #endif // _MOOF_MODAL_DIALOG_HH_