2 /*******************************************************************************
4 Copyright (c) 2009, Charles McGarvey
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *******************************************************************************/
29 #ifndef _MOOF_MODALDIALOG_HH_
30 #define _MOOF_MODALDIALOG_HH_
35 #include "../config.h"
38 #if defined(_WIN32) || defined(__WIN32__)
40 #elif defined(__APPLE__) && defined(__MACH__)
41 #include <Carbon/Carbon.h>
45 #include <QApplication>
47 #include <QMessageBox>
50 #include <Moof/Log.hh>
51 #include <Moof/Resource.hh>
58 * Small wrapper over various user interface modal dialog windows.
82 logWarning("%s", text1
.c_str());
83 logWarning("%s", text2
.c_str());
86 logError("%s", text1
.c_str());
87 logError("%s", text2
.c_str());
90 logInfo("%s", text1
.c_str());
91 logInfo("%s", text2
.c_str());
99 gtk_init(&argc
, &argv
);
101 GtkMessageType iconType
;
105 iconType
= GTK_MESSAGE_WARNING
;
108 iconType
= GTK_MESSAGE_ERROR
;
111 iconType
= GTK_MESSAGE_INFO
;
115 GtkWidget
* dialog
= gtk_message_dialog_new(NULL
,
116 GTK_DIALOG_DESTROY_WITH_PARENT
, iconType
,
117 GTK_BUTTONS_CLOSE
, "%s", text1
.c_str());
118 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog
),
119 "%s", text2
.c_str());
120 gtk_window_set_title(GTK_WINDOW(dialog
), title
.c_str());
122 std::string iconPath
= Resource::getPath(PACKAGE
".png");
123 GdkPixbuf
* iconPixbuf
= gdk_pixbuf_new_from_file(iconPath
.c_str(), NULL
);
124 gtk_window_set_icon(GTK_WINDOW(dialog
), iconPixbuf
);
126 gtk_dialog_run(GTK_DIALOG(dialog
));
127 gtk_widget_destroy(dialog
);
128 // FIXME - this doesn't seem to actually remove the window from the
129 // screen when it closes, not sure why...
135 QApplication
qtApp(argc
, argv
);
137 QMessageBox::Icon iconType
;
141 iconType
= QMessageBox::Warning
;
144 iconType
= QMessageBox::Critical
;
147 iconType
= QMessageBox::Information
;
152 dialog
.setWindowTitle(title
.c_str());
153 dialog
.setIcon(iconType
);
154 dialog
.setText(text1
.c_str());
155 dialog
.setInformativeText(text2
.c_str());
156 dialog
.setStandardButtons(QMessageBox::Close
);
158 std::string iconPath
= Resource::getPath(PACKAGE
".png");
159 QIcon
icon(iconPath
.c_str());
160 dialog
.setWindowIcon(icon
);
171 #endif // _MOOF_MODALDIALOG_HH_
173 /** vim: set ts=4 sw=4 tw=80: *************************************************/