-/*] 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_
-/**
- * \file modal_dialog.hh
- * A class for creating and running modal dialogs. Several toolkits are
- * supported, but only one can be used as determined at build time.
- */
-
-#include "../config.h"
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
#include <string>
-#if defined(_WIN32)
+#if PLATFORM_WIN32
#include <windows.h>
-#elif USE_GTK
+#elif WITH_GUI_GTK
#include <gtk/gtk.h>
-#elif USE_QT4
+#elif WITH_GUI_QT4
#include <QApplication>
#include <QIcon>
#include <QMessageBox>
#include <moof/resource.hh>
+/**
+ * \file modal_dialog.hh
+ * A class for creating and running modal dialogs. Several toolkits are
+ * supported, but only one can be used as determined at build time.
+ */
+
namespace moof {
/**
* Small wrapper over various user interface modal dialog windows.
*/
-
struct modal_dialog
{
enum type
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.
* \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);
}
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;
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
}
};