X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fmodal_dialog.hh;h=4afeb39b1d998a78d066470b66916c25cd364b3e;hp=4498692c9a3a79bade1539f6f778bd71fde20fc8;hb=574af38ed616d1adfa5e6ce35f67cda1f707f89d;hpb=6c9943707d4f33035830eba0587a61a34eaecbc2 diff --git a/src/moof/modal_dialog.hh b/src/moof/modal_dialog.hh index 4498692..4afeb39 100644 --- a/src/moof/modal_dialog.hh +++ b/src/moof/modal_dialog.hh @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _MOOF_MODAL_DIALOG_HH_ #define _MOOF_MODAL_DIALOG_HH_ @@ -18,7 +16,9 @@ * supported, but only one can be used as determined at build time. */ +#if HAVE_CONFIG_H #include "config.h" +#endif #include @@ -42,7 +42,6 @@ namespace moof { /** * Small wrapper over various user interface modal dialog windows. */ - struct modal_dialog { enum type @@ -52,12 +51,10 @@ struct modal_dialog error = 3 }; - - std::string title; + std::string title; type type; - std::string text1; - std::string text2; - + std::string text1; + std::string text2; /** * Construct a dialog box. @@ -67,84 +64,80 @@ struct modal_dialog * \param text2 The second line. */ modal_dialog(enum type type = information, - const std::string& title = "", - const std::string& text1 = "", - const std::string& text2 = "") : + const std::string& title = "", + const std::string& text1 = "", + const std::string& text2 = "") : title(title), type(type), text1(text1), text2(text2) {} - void run() const { switch (type) { - case warning: - log_warning(text1); - log_warning(text2); - break; - case error: - log_error(text1); - log_error(text2); - break; - default: - log_info(text1); - log_info(text2); - break; + case warning: + log_warning(text1); + log_warning(text2); + break; + case error: + log_error(text1); + log_error(text2); + break; + default: + log_info(text1); + log_info(text2); + break; } #if PLATFORM_WIN32 - int icon_type; switch (type) { - case warning: - icon_type = MB_ICONWARNING; - break; - case error: - icon_type = MB_ICONERROR; - break; - default: - icon_type = MB_ICONINFORMATION; - break; + case warning: + icon_type = MB_ICONWARNING; + break; + case error: + icon_type = MB_ICONERROR; + break; + default: + icon_type = MB_ICONINFORMATION; + break; } MessageBox(0, (text1 + "\n" + text2).c_str(), title.c_str(), MB_OK | icon_type); - #elif WITH_GUI_GTK - - int argc = 0; + int argc = 0; char** argv; gtk_init(&argc, &argv); GtkMessageType icon_type; switch (type) { - case warning: - icon_type = GTK_MESSAGE_WARNING; - break; - case error: - icon_type = GTK_MESSAGE_ERROR; - break; - default: - icon_type = GTK_MESSAGE_INFO; - break; + case warning: + icon_type = GTK_MESSAGE_WARNING; + break; + case error: + icon_type = GTK_MESSAGE_ERROR; + break; + default: + icon_type = GTK_MESSAGE_INFO; + break; } GtkWidget* dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, icon_type, GTK_BUTTONS_CLOSE, "%s", text1.c_str()); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), - "%s", text2.c_str()); + "%s", text2.c_str()); gtk_window_set_title(GTK_WINDOW(dialog), title.c_str()); - std::string icon_path = resource::find_file(PACKAGE".png"); + std::string icon_path = resource::find_file(PACKAGE_TARNAME".png"); if (!icon_path.empty()) { GdkPixbuf* iconPixbuf = gdk_pixbuf_new_from_file(icon_path.c_str(), - NULL); + NULL); gtk_window_set_icon(GTK_WINDOW(dialog), iconPixbuf); } @@ -152,25 +145,23 @@ struct modal_dialog gtk_widget_destroy(dialog); // FIXME - this doesn't seem to actually remove the window from the // screen when it closes - #elif WITH_GUI_QT4 - - int argc = 0; + int argc = 0; char** argv; QApplication qt_app(argc, argv); QMessageBox::Icon icon_type; switch (type) { - case warning: - icon_type = QMessageBox::Warning; - break; - case error: - icon_type = QMessageBox::Critical; - break; - default: - icon_type = QMessageBox::Information; - break; + case warning: + icon_type = QMessageBox::Warning; + break; + case error: + icon_type = QMessageBox::Critical; + break; + default: + icon_type = QMessageBox::Information; + break; } QMessageBox dialog; @@ -180,7 +171,7 @@ struct modal_dialog dialog.setInformativeText(text2.c_str()); dialog.setStandardButtons(QMessageBox::Close); - std::string icon_path = resource::find_file(PACKAGE".png"); + std::string icon_path = resource::find_file(PACKAGE_TARNAME".png"); if (!icon_path.empty()) { QIcon icon(icon_path.c_str()); @@ -188,7 +179,6 @@ struct modal_dialog } dialog.exec(); - #endif } };