00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025 #include <gtk/gtk.h>
00026 #include <string.h>
00027 #include <stdarg.h>
00028 #include "kino_common.h"
00029 #include "message.h"
00030
00031 extern "C"
00032 {
00033 extern GtkWidget *main_window;
00034
00035 void modal_message ( const char * message, ... )
00036 {
00037 gchar* msg;
00038 va_list args;
00039
00040 va_start( args, message );
00041 msg = g_strdup_vprintf( message, args );
00042 va_end( args );
00043
00044 modal_message_with_parent( common->getWidget(), msg, NULL );
00045
00046 g_free( msg );
00047 }
00048
00049 char *modal_prompt( const char * message, ... )
00050 {
00051 gchar* msg;
00052 va_list args;
00053 char *rv;
00054
00055 va_start( args, message );
00056 msg = g_strdup_vprintf( message, args );
00057 va_end( args );
00058
00059 rv = modal_prompt_with_parent( common->getWidget(), msg, NULL );
00060
00061 g_free( msg );
00062 return rv;
00063 }
00064
00065 int modal_confirm( const char * affirm_label, const char *close_label, const char *message, ... )
00066 {
00067 gchar* msg;
00068 va_list args;
00069 int rv = 0;
00070
00071 va_start( args, message );
00072 msg = g_strdup_vprintf( message, args );
00073 va_end( args );
00074
00075 rv = modal_confirm_with_parent( affirm_label, close_label, common->getWidget(), msg, NULL );
00076
00077 g_free( msg );
00078 return rv;
00079 }
00080
00081 void modal_message_with_parent( GtkWidget *parent, const char * message, ... )
00082 {
00083 gchar* msg;
00084 va_list args;
00085
00086 va_start( args, message );
00087 msg = g_strdup_vprintf( message, args );
00088 va_end( args );
00089
00090 GtkWidget * dialog = gtk_message_dialog_new(
00091 GTK_WINDOW( main_window ),
00092 GTK_DIALOG_DESTROY_WITH_PARENT,
00093 GTK_MESSAGE_WARNING,
00094 GTK_BUTTONS_OK,
00095 msg );
00096 gtk_window_set_resizable( GTK_WINDOW( dialog ), FALSE );
00097
00098 if(parent)
00099 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(KinoCommon::getWidgetWindow(parent)));
00100
00101 gtk_dialog_run( GTK_DIALOG( dialog ) );
00102 gtk_widget_destroy( dialog );
00103
00104 g_free( msg );
00105 }
00106
00107 char *modal_prompt_with_parent( GtkWidget *parent, const char * message, ... )
00108 {
00109 GtkWidget *dialog, *hbox1, *hbox2, *label, *entry, *icon;
00110 char *response = NULL;
00111 gchar* msg;
00112 va_list args;
00113
00114 va_start( args, message );
00115 msg = g_strdup_vprintf( message, args );
00116 va_end( args );
00117
00118
00119
00120 dialog = gtk_dialog_new_with_buttons( "",
00121 GTK_WINDOW( main_window ),
00122 GTK_DIALOG_DESTROY_WITH_PARENT,
00123 GTK_STOCK_CANCEL,
00124 GTK_RESPONSE_REJECT,
00125 GTK_STOCK_OK,
00126 GTK_RESPONSE_ACCEPT,
00127 NULL);
00128 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_REJECT, -1);
00129 gtk_dialog_set_default_response( GTK_DIALOG( dialog ), GTK_RESPONSE_ACCEPT );
00130 gtk_dialog_set_has_separator( GTK_DIALOG( dialog ), FALSE );
00131 gtk_window_set_resizable( GTK_WINDOW( dialog ), FALSE );
00132 g_signal_connect( G_OBJECT( dialog ), "response",
00133 G_CALLBACK( gtk_widget_hide ),
00134 G_OBJECT( dialog ) );
00135
00136
00137 hbox1 = gtk_hbox_new( FALSE, 12 );
00138 gtk_container_set_border_width( GTK_CONTAINER( hbox1 ), 6 );
00139 hbox2 = gtk_hbox_new( FALSE, 12 );
00140 gtk_container_set_border_width( GTK_CONTAINER( hbox2 ), 6 );
00141 icon = gtk_image_new_from_stock( GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG );
00142 label = gtk_label_new( msg );
00143 entry = gtk_entry_new();
00144 gtk_entry_set_activates_default( GTK_ENTRY( entry ), TRUE );
00145 gtk_container_add( GTK_CONTAINER( hbox1 ), icon );
00146 gtk_container_add( GTK_CONTAINER( hbox1 ), label );
00147 gtk_container_add( GTK_CONTAINER( hbox2 ), entry );
00148 gtk_container_add( GTK_CONTAINER( GTK_DIALOG( dialog )->vbox ), hbox1 );
00149 gtk_container_add( GTK_CONTAINER( GTK_DIALOG( dialog )->vbox ), hbox2 );
00150
00151 if(parent)
00152 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(KinoCommon::getWidgetWindow(parent)));
00153
00154 gtk_widget_show_all( dialog );
00155
00156 if ( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_ACCEPT )
00157 response = strdup( gtk_entry_get_text( GTK_ENTRY( entry ) ) );
00158 gtk_widget_destroy( dialog );
00159
00160 g_free( msg );
00161 return response;
00162 }
00163
00164 int modal_confirm_with_parent( const char *affirm_label, const char *close_label, GtkWidget *parent, const char *message, ... )
00165 {
00166 int result = GTK_RESPONSE_NONE;
00167 va_list args;
00168 GtkWidget* dialog;
00169 gchar* msg;
00170
00171 va_start( args, message );
00172 msg = g_strdup_vprintf( message, args );
00173 va_end( args );
00174
00175 dialog = gtk_message_dialog_new(
00176 GTK_WINDOW( main_window ),
00177 GTK_DIALOG_DESTROY_WITH_PARENT,
00178 GTK_MESSAGE_WARNING,
00179 GTK_BUTTONS_NONE,
00180 msg );
00181
00182 if ( close_label != NULL )
00183 gtk_dialog_add_button( GTK_DIALOG( dialog ), close_label, GTK_RESPONSE_CLOSE );
00184 gtk_dialog_add_button( GTK_DIALOG( dialog ), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT );
00185 gtk_dialog_add_button( GTK_DIALOG( dialog ), affirm_label, GTK_RESPONSE_ACCEPT );
00186 if ( close_label != NULL )
00187 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CLOSE, GTK_RESPONSE_REJECT, -1);
00188 else
00189 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_REJECT, -1);
00190 gtk_dialog_set_default_response( GTK_DIALOG( dialog ), GTK_RESPONSE_ACCEPT );
00191 gtk_window_set_title( GTK_WINDOW( dialog ), _("Question") );
00192 gtk_window_set_resizable( GTK_WINDOW( dialog ), FALSE );
00193
00194 if(parent)
00195 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(KinoCommon::getWidgetWindow(parent)));
00196
00197 result = gtk_dialog_run( GTK_DIALOG( dialog ) );
00198 gtk_widget_destroy( dialog );
00199
00200 g_free( msg );
00201 return result;
00202 }
00203
00204 }