X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fmodal_dialog.hh;h=4afeb39b1d998a78d066470b66916c25cd364b3e;hp=c5139f27e06bb7dd95ae9c9a2915adcd5a897180;hb=574af38ed616d1adfa5e6ce35f67cda1f707f89d;hpb=449366f5f32d24f2a2a6589da6e16b2bf0d61773 diff --git a/src/moof/modal_dialog.hh b/src/moof/modal_dialog.hh index c5139f2..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,15 +16,17 @@ * supported, but only one can be used as determined at build time. */ -#include "../config.h" +#if HAVE_CONFIG_H +#include "config.h" +#endif #include -#if defined(_WIN32) +#if PLATFORM_WIN32 #include -#elif USE_GTK +#elif WITH_GUI_GTK #include -#elif USE_QT4 +#elif WITH_GUI_QT4 #include #include #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 defined(_WIN32) - +#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 USE_GTK - - int argc = 0; +#elif WITH_GUI_GTK + 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(PACKAGE".png"); - if (resource::find(icon_path)) + 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 USE_QT4 - - int argc = 0; +#elif WITH_GUI_QT4 + 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,15 +171,14 @@ struct modal_dialog dialog.setInformativeText(text2.c_str()); dialog.setStandardButtons(QMessageBox::Close); - std::string icon_path(PACKAGE".png"); - if (resource::find(icon_path)) + std::string icon_path = resource::find_file(PACKAGE_TARNAME".png"); + if (!icon_path.empty()) { QIcon icon(icon_path.c_str()); dialog.setWindowIcon(icon); } dialog.exec(); - #endif } };