3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
35 #include <glib/gi18n.h>
36 #include <glib/gprintf.h>
38 #include <unique/unique.h>
40 #include "base-application.h"
41 #include "base-window.h"
42 #include "egg-sm-client.h"
46 struct _BaseApplicationClassPrivate
{
47 void *empty
; /* so that gcc -pedantic is happy */
50 /* private instance data
52 struct _BaseApplicationPrivate
{
53 gboolean dispose_has_run
;
59 GOptionEntry
*options
;
60 gchar
*application_name
;
62 gchar
*unique_app_name
;
66 EggSMClient
*sm_client
;
68 BaseWindow
*main_window
;
70 gboolean is_gtk_initialized
;
71 UniqueApp
*unique_app_handle
;
77 /* instance properties
85 BASE_PROP_APPLICATION_NAME_ID
,
86 BASE_PROP_ICON_NAME_ID
,
87 BASE_PROP_UNIQUE_APP_NAME_ID
,
88 BASE_APPLICATION_PROP_IS_GTK_INITIALIZED_ID
,
89 BASE_APPLICATION_PROP_UNIQUE_APP_HANDLE_ID
,
90 BASE_APPLICATION_PROP_EXIT_CODE_ID
,
91 BASE_APPLICATION_PROP_EXIT_MESSAGE1_ID
,
92 BASE_APPLICATION_PROP_EXIT_MESSAGE2_ID
,
93 BASE_APPLICATION_PROP_BUILDER_ID
,
94 BASE_APPLICATION_PROP_MAIN_WINDOW_ID
,
96 BASE_PROP_N_PROPERTIES
99 static GObjectClass
*st_parent_class
= NULL
;
101 static GType
register_type( void );
102 static void class_init( BaseApplicationClass
*klass
);
103 static void instance_init( GTypeInstance
*instance
, gpointer klass
);
104 static void instance_get_property( GObject
*object
, guint property_id
, GValue
*value
, GParamSpec
*spec
);
105 static void instance_set_property( GObject
*object
, guint property_id
, const GValue
*value
, GParamSpec
*spec
);
106 static void instance_dispose( GObject
*application
);
107 static void instance_finalize( GObject
*application
);
109 static gboolean
appli_initialize_i18n( BaseApplication
*application
, int *code
);
110 static gboolean
appli_initialize_application_name( BaseApplication
*application
, int *code
);
111 static gboolean
appli_initialize_gtk( BaseApplication
*application
, int *code
);
112 static gboolean
appli_initialize_manage_options( const BaseApplication
*application
, int *code
);
113 static gboolean
appli_initialize_unique_app( BaseApplication
*application
, int *code
);
115 static UniqueResponse
on_unique_message_received( UniqueApp
*app
, UniqueCommand command
, UniqueMessageData
*message
, guint time
, gpointer user_data
);
117 static gboolean
appli_initialize_session_manager( BaseApplication
*application
, int *code
);
118 static void session_manager_client_quit_cb( EggSMClient
*client
, BaseApplication
*application
);
119 static void session_manager_client_quit_requested_cb( EggSMClient
*client
, BaseApplication
*application
);
120 static gboolean
appli_initialize_application_icon( BaseApplication
*application
, int *code
);
121 static gboolean
appli_initialize_builder( BaseApplication
*application
, int *code
);
123 static gint
display_dlg( BaseApplication
*application
, GtkMessageType type_message
, GtkButtonsType type_buttons
, const gchar
*first
, const gchar
*second
);
125 static void display_error_message( BaseApplication
*application
);
126 static void set_initialize_ui_get_fname_error( BaseApplication
*application
);
127 static void set_initialize_ui_add_xml_error( BaseApplication
*application
, const gchar
*filename
, GError
*error
);
131 base_application_get_type( void )
133 static GType application_type
= 0;
135 if( !application_type
){
136 application_type
= register_type();
139 return( application_type
);
143 register_type( void )
145 static const gchar
*thisfn
= "base_application_register_type";
148 static GTypeInfo info
= {
149 sizeof( BaseApplicationClass
),
150 ( GBaseInitFunc
) NULL
,
151 ( GBaseFinalizeFunc
) NULL
,
152 ( GClassInitFunc
) class_init
,
155 sizeof( BaseApplication
),
157 ( GInstanceInitFunc
) instance_init
160 g_debug( "%s", thisfn
);
164 type
= g_type_register_static( G_TYPE_OBJECT
, "BaseApplication", &info
, 0 );
170 class_init( BaseApplicationClass
*klass
)
172 static const gchar
*thisfn
= "base_application_class_init";
173 GObjectClass
*object_class
;
176 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
178 st_parent_class
= g_type_class_peek_parent( klass
);
180 object_class
= G_OBJECT_CLASS( klass
);
181 object_class
->dispose
= instance_dispose
;
182 object_class
->finalize
= instance_finalize
;
183 object_class
->get_property
= instance_get_property
;
184 object_class
->set_property
= instance_set_property
;
186 g_object_class_install_property( object_class
, BASE_PROP_ARGC_ID
,
189 _( "Arguments count" ),
190 _( "The count of command-line arguments" ),
192 G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
));
194 g_object_class_install_property( object_class
, BASE_PROP_ARGV_ID
,
198 _( "The array of command-line arguments" ),
200 G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
));
202 g_object_class_install_property( object_class
, BASE_PROP_OPTIONS_ID
,
203 g_param_spec_pointer(
205 _( "Option entries" ),
206 _( "The array of command-line option definitions" ),
207 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
));
209 g_object_class_install_property( object_class
, BASE_PROP_APPLICATION_NAME_ID
,
211 BASE_PROP_APPLICATION_NAME
,
212 _( "Application name" ),
213 _( "The name of the application" ),
215 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
));
217 g_object_class_install_property( object_class
, BASE_PROP_ICON_NAME_ID
,
221 _( "The name of the icon of the application" ),
223 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
));
225 g_object_class_install_property( object_class
, BASE_PROP_UNIQUE_APP_NAME_ID
,
227 BASE_PROP_UNIQUE_APP_NAME
,
228 _( "UniqueApp name" ),
229 _( "The Unique name of the application" ),
231 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
));
233 spec
= g_param_spec_boolean(
234 BASE_APPLICATION_PROP_IS_GTK_INITIALIZED
,
235 "Gtk+ initialization flag",
236 "Has Gtk+ be initialized ?", FALSE
,
237 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
);
238 g_object_class_install_property( object_class
, BASE_APPLICATION_PROP_IS_GTK_INITIALIZED_ID
, spec
);
240 spec
= g_param_spec_pointer(
241 BASE_APPLICATION_PROP_UNIQUE_APP_HANDLE
,
242 "UniqueApp object pointer",
243 "A reference to the UniqueApp object if any",
244 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
);
245 g_object_class_install_property( object_class
, BASE_APPLICATION_PROP_UNIQUE_APP_HANDLE_ID
, spec
);
247 spec
= g_param_spec_int(
248 BASE_APPLICATION_PROP_EXIT_CODE
,
250 "Exit code of the application", 0, 65535, 0,
251 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
);
252 g_object_class_install_property( object_class
, BASE_APPLICATION_PROP_EXIT_CODE_ID
, spec
);
254 spec
= g_param_spec_string(
255 BASE_APPLICATION_PROP_EXIT_MESSAGE1
,
257 "First line of the error message displayed when exit_code not nul", "",
258 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
);
259 g_object_class_install_property( object_class
, BASE_APPLICATION_PROP_EXIT_MESSAGE1_ID
, spec
);
261 spec
= g_param_spec_string(
262 BASE_APPLICATION_PROP_EXIT_MESSAGE2
,
264 "Second line of the error message displayed when exit_code not nul", "",
265 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
);
266 g_object_class_install_property( object_class
, BASE_APPLICATION_PROP_EXIT_MESSAGE2_ID
, spec
);
268 spec
= g_param_spec_pointer(
269 BASE_APPLICATION_PROP_BUILDER
,
271 "A reference to the UI definition from GtkBuilder",
272 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
);
273 g_object_class_install_property( object_class
, BASE_APPLICATION_PROP_BUILDER_ID
, spec
);
275 spec
= g_param_spec_pointer(
276 BASE_APPLICATION_PROP_MAIN_WINDOW
,
277 "Main BaseWindow object",
278 "A reference to the main BaseWindow object",
279 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
);
280 g_object_class_install_property( object_class
, BASE_APPLICATION_PROP_MAIN_WINDOW_ID
, spec
);
282 klass
->private = g_new0( BaseApplicationClassPrivate
, 1 );
284 klass
->manage_options
= NULL
;
285 klass
->main_window_new
= NULL
;
289 instance_init( GTypeInstance
*application
, gpointer klass
)
291 static const gchar
*thisfn
= "base_application_instance_init";
292 BaseApplication
*self
;
294 g_return_if_fail( BASE_IS_APPLICATION( application
));
296 g_debug( "%s: application=%p (%s), klass=%p",
297 thisfn
, ( void * ) application
, G_OBJECT_TYPE_NAME( application
), ( void * ) klass
);
299 self
= BASE_APPLICATION( application
);
301 self
->private = g_new0( BaseApplicationPrivate
, 1 );
303 self
->private->dispose_has_run
= FALSE
;
307 instance_get_property( GObject
*object
, guint property_id
, GValue
*value
, GParamSpec
*spec
)
309 BaseApplication
*self
;
311 g_return_if_fail( BASE_IS_APPLICATION( object
));
312 self
= BASE_APPLICATION( object
);
314 if( !self
->private->dispose_has_run
){
316 switch( property_id
){
317 case BASE_PROP_ARGC_ID
:
318 g_value_set_int( value
, self
->private->argc
);
321 case BASE_PROP_ARGV_ID
:
322 g_value_set_boxed( value
, self
->private->argv
);
325 case BASE_PROP_OPTIONS_ID
:
326 g_value_set_pointer( value
, self
->private->options
);
329 case BASE_PROP_APPLICATION_NAME_ID
:
330 g_value_set_string( value
, self
->private->application_name
);
333 case BASE_PROP_ICON_NAME_ID
:
334 g_value_set_string( value
, self
->private->icon_name
);
337 case BASE_PROP_UNIQUE_APP_NAME_ID
:
338 g_value_set_string( value
, self
->private->unique_app_name
);
341 case BASE_APPLICATION_PROP_IS_GTK_INITIALIZED_ID
:
342 g_value_set_boolean( value
, self
->private->is_gtk_initialized
);
345 case BASE_APPLICATION_PROP_UNIQUE_APP_HANDLE_ID
:
346 g_value_set_pointer( value
, self
->private->unique_app_handle
);
349 case BASE_APPLICATION_PROP_EXIT_CODE_ID
:
350 g_value_set_int( value
, self
->private->exit_code
);
353 case BASE_APPLICATION_PROP_EXIT_MESSAGE1_ID
:
354 g_value_set_string( value
, self
->private->exit_message1
);
357 case BASE_APPLICATION_PROP_EXIT_MESSAGE2_ID
:
358 g_value_set_string( value
, self
->private->exit_message2
);
361 case BASE_APPLICATION_PROP_BUILDER_ID
:
362 g_value_set_pointer( value
, self
->private->builder
);
365 case BASE_APPLICATION_PROP_MAIN_WINDOW_ID
:
366 g_value_set_pointer( value
, self
->private->main_window
);
370 G_OBJECT_WARN_INVALID_PROPERTY_ID( object
, property_id
, spec
);
377 instance_set_property( GObject
*object
, guint property_id
, const GValue
*value
, GParamSpec
*spec
)
379 BaseApplication
*self
;
381 g_return_if_fail( BASE_IS_APPLICATION( object
));
382 self
= BASE_APPLICATION( object
);
384 if( !self
->private->dispose_has_run
){
386 switch( property_id
){
387 case BASE_PROP_ARGC_ID
:
388 self
->private->argc
= g_value_get_int( value
);
391 case BASE_PROP_ARGV_ID
:
392 if( self
->private->argv
){
393 g_boxed_free( G_TYPE_STRV
, self
->private->argv
);
395 self
->private->argv
= g_value_dup_boxed( value
);
398 case BASE_PROP_OPTIONS_ID
:
399 self
->private->options
= g_value_get_pointer( value
);
402 case BASE_PROP_APPLICATION_NAME_ID
:
403 g_free( self
->private->application_name
);
404 self
->private->application_name
= g_value_dup_string( value
);
407 case BASE_PROP_ICON_NAME_ID
:
408 g_free( self
->private->icon_name
);
409 self
->private->icon_name
= g_value_dup_string( value
);
412 case BASE_PROP_UNIQUE_APP_NAME_ID
:
413 g_free( self
->private->unique_app_name
);
414 self
->private->unique_app_name
= g_value_dup_string( value
);
417 case BASE_APPLICATION_PROP_IS_GTK_INITIALIZED_ID
:
418 self
->private->is_gtk_initialized
= g_value_get_boolean( value
);
421 case BASE_APPLICATION_PROP_UNIQUE_APP_HANDLE_ID
:
422 self
->private->unique_app_handle
= g_value_get_pointer( value
);
425 case BASE_APPLICATION_PROP_EXIT_CODE_ID
:
426 self
->private->exit_code
= g_value_get_int( value
);
429 case BASE_APPLICATION_PROP_EXIT_MESSAGE1_ID
:
430 g_free( self
->private->exit_message1
);
431 self
->private->exit_message1
= g_value_dup_string( value
);
434 case BASE_APPLICATION_PROP_EXIT_MESSAGE2_ID
:
435 g_free( self
->private->exit_message2
);
436 self
->private->exit_message2
= g_value_dup_string( value
);
439 case BASE_APPLICATION_PROP_BUILDER_ID
:
440 self
->private->builder
= g_value_get_pointer( value
);
443 case BASE_APPLICATION_PROP_MAIN_WINDOW_ID
:
444 self
->private->main_window
= g_value_get_pointer( value
);
448 G_OBJECT_WARN_INVALID_PROPERTY_ID( object
, property_id
, spec
);
455 instance_dispose( GObject
*application
)
457 static const gchar
*thisfn
= "base_application_instance_dispose";
458 BaseApplication
*self
;
460 g_return_if_fail( BASE_IS_APPLICATION( application
));
462 self
= BASE_APPLICATION( application
);
464 if( !self
->private->dispose_has_run
){
466 g_debug( "%s: application=%p (%s)", thisfn
, ( void * ) application
, G_OBJECT_TYPE_NAME( application
));
468 self
->private->dispose_has_run
= TRUE
;
470 if( UNIQUE_IS_APP( self
->private->unique_app_handle
)){
471 g_object_unref( self
->private->unique_app_handle
);
474 if( GTK_IS_BUILDER( self
->private->builder
)){
475 g_object_unref( self
->private->builder
);
478 if( self
->private->sm_client
){
479 g_object_unref( self
->private->sm_client
);
482 /* chain up to the parent class */
483 if( G_OBJECT_CLASS( st_parent_class
)->dispose
){
484 G_OBJECT_CLASS( st_parent_class
)->dispose( application
);
490 instance_finalize( GObject
*application
)
492 static const gchar
*thisfn
= "base_application_instance_finalize";
493 BaseApplication
*self
;
495 g_return_if_fail( BASE_IS_APPLICATION( application
));
497 g_debug( "%s: application=%p (%s)", thisfn
, ( void * ) application
, G_OBJECT_TYPE_NAME( application
));
499 self
= BASE_APPLICATION( application
);
501 g_free( self
->private->application_name
);
502 g_free( self
->private->icon_name
);
503 g_free( self
->private->unique_app_name
);
505 g_free( self
->private->exit_message1
);
506 g_free( self
->private->exit_message2
);
508 g_free( self
->private );
510 /* chain call to parent class */
511 if( G_OBJECT_CLASS( st_parent_class
)->finalize
){
512 G_OBJECT_CLASS( st_parent_class
)->finalize( application
);
517 * base_application_run:
518 * @application: this #BaseApplication -derived instance.
520 * Starts and runs the application.
521 * Takes care of creating, initializing, and running the main window.
523 * All steps are implemented as virtual functions which provide some
524 * suitable defaults, and may be overriden by a derived class.
526 * Returns: an %int code suitable as an exit code for the program.
528 * Though it is defined as a virtual function itself, it should be very
529 * seldomly needed to override this in a derived class.
532 base_application_run( BaseApplication
*application
)
534 static const gchar
*thisfn
= "base_application_run";
536 GtkWindow
*gtk_toplevel
;
538 g_return_val_if_fail( BASE_IS_APPLICATION( application
), BASE_EXIT_CODE_START_FAIL
);
540 code
= BASE_EXIT_CODE_START_FAIL
;
542 if( !application
->private->dispose_has_run
){
543 g_debug( "%s: application=%p", thisfn
, ( void * ) application
);
545 code
= BASE_EXIT_CODE_OK
;
546 application
->private->main_window
= NULL
;
548 if( appli_initialize_i18n( application
, &code
) &&
549 appli_initialize_application_name( application
, &code
) &&
550 appli_initialize_gtk( application
, &code
) &&
551 appli_initialize_manage_options( application
, &code
) &&
552 appli_initialize_unique_app( application
, &code
) &&
553 appli_initialize_session_manager( application
, &code
) &&
554 appli_initialize_application_icon( application
, &code
) &&
555 appli_initialize_builder( application
, &code
)){
558 if( BASE_APPLICATION_GET_CLASS( application
)->main_window_new
){
559 application
->private->main_window
= ( BaseWindow
* ) BASE_APPLICATION_GET_CLASS( application
)->main_window_new( application
, &application
->private->exit_code
);
561 code
= BASE_EXIT_CODE_MAIN_WINDOW
;
564 if( application
->private->main_window
){
565 g_return_val_if_fail( BASE_IS_WINDOW( application
->private->main_window
), BASE_EXIT_CODE_START_FAIL
);
567 if( base_window_init( application
->private->main_window
)){
568 gtk_toplevel
= base_window_get_toplevel( application
->private->main_window
);
569 g_return_val_if_fail( gtk_toplevel
, BASE_EXIT_CODE_START_FAIL
);
570 g_return_val_if_fail( GTK_IS_WINDOW( gtk_toplevel
), BASE_EXIT_CODE_START_FAIL
);
572 if( application
->private->unique_app_handle
){
573 unique_app_watch_window( application
->private->unique_app_handle
, gtk_toplevel
);
576 code
= base_window_run( application
->private->main_window
);
586 appli_initialize_i18n( BaseApplication
*application
, int *code
)
588 static const gchar
*thisfn
= "base_application_appli_initialize_i18n";
590 g_debug( "%s: application=%p, code=%p (%d)", thisfn
, ( void * ) application
, ( void * ) code
, *code
);
593 bindtextdomain( GETTEXT_PACKAGE
, GNOMELOCALEDIR
);
594 # ifdef HAVE_BIND_TEXTDOMAIN_CODESET
595 bind_textdomain_codeset( GETTEXT_PACKAGE
, "UTF-8" );
597 textdomain( GETTEXT_PACKAGE
);
606 appli_initialize_application_name( BaseApplication
*application
, int *code
)
608 static const gchar
*thisfn
= "base_application_appli_initialize_application_name";
611 g_debug( "%s: application=%p, code=%p (%d)", thisfn
, ( void * ) application
, ( void * ) code
, *code
);
613 name
= base_application_get_application_name( application
);
614 if( name
&& g_utf8_strlen( name
, -1 )){
615 g_set_application_name( name
);
623 appli_initialize_gtk( BaseApplication
*application
, int *code
)
625 static const gchar
*thisfn
= "base_application_appli_initialize_gtk";
627 char *parameter_string
;
630 g_debug( "%s: application=%p, code=%p (%d)", thisfn
, ( void * ) application
, ( void * ) code
, *code
);
632 if( application
->private->options
){
633 parameter_string
= g_strdup( g_get_application_name());
635 ret
= gtk_init_with_args(
636 &application
->private->argc
, ( char *** ) &application
->private->argv
,
637 parameter_string
, application
->private->options
, GETTEXT_PACKAGE
, &error
);
640 g_warning( "%s: %s", thisfn
, error
->message
);
641 g_error_free( error
);
645 g_free( parameter_string
);
648 ret
= gtk_init_check( &application
->private->argc
, ( char *** ) &application
->private->argv
);
655 appli_initialize_manage_options( const BaseApplication
*application
, int *code
)
657 static const gchar
*thisfn
= "base_application_appli_initialize_manage_options";
660 g_debug( "%s: application=%p, code=%p (%d)", thisfn
, ( void * ) application
, ( void * ) code
, *code
);
664 if( BASE_APPLICATION_GET_CLASS( application
)->manage_options
){
665 ret
= BASE_APPLICATION_GET_CLASS( application
)->manage_options( application
, code
);
672 appli_initialize_unique_app( BaseApplication
*application
, int *code
)
674 static const gchar
*thisfn
= "base_application_appli_initialize_unique_app";
679 g_debug( "%s: application=%p, code=%p (%d)", thisfn
, ( void * ) application
, ( void * ) code
, *code
);
683 if( application
->private->unique_app_name
&&
684 strlen( application
->private->unique_app_name
)){
686 application
->private->unique_app_handle
= unique_app_new( application
->private->unique_app_name
, NULL
);
687 is_first
= unique_app_is_running( application
->private->unique_app_handle
);
690 unique_app_send_message( application
->private->unique_app_handle
, UNIQUE_ACTIVATE
, NULL
);
691 /* i18n: application name */
692 msg
= g_strdup_printf(
693 _( "Another instance of %s is already running.\n"
694 "Please switch back to it." ), application
->private->application_name
);
695 base_window_display_error_dlg( NULL
, _( "The application is not unique" ), msg
);
698 *code
= BASE_EXIT_CODE_UNIQUE_APP
;
700 /* default from libunique is actually to activate the first window
701 * so we rely on the default..
704 g_signal_connect( application
->private->unique_app_handle
,
705 "message-received", G_CALLBACK( on_unique_message_received
), application
);
714 static UniqueResponse
715 on_unique_message_received(
716 UniqueApp
*app
, UniqueCommand command
, UniqueMessageData
*message
, guint time
, gpointer user_data
)
718 static const gchar
*thisfn
= "base_application_check_for_unique_app";
719 UniqueResponse resp
= UNIQUE_RESPONSE_OK
;
722 case UNIQUE_ACTIVATE
:
723 g_debug( "%s: received message UNIQUE_ACTIVATE", thisfn
);
726 resp
= UNIQUE_RESPONSE_PASSTHROUGH
;
735 appli_initialize_session_manager( BaseApplication
*application
, int *code
)
737 static const gchar
*thisfn
= "base_application_do_initialize_session_manager";
739 g_debug( "%s: application=%p, code=%p (%d)", thisfn
, ( void * ) application
, ( void * ) code
, *code
);
741 egg_sm_client_set_mode( EGG_SM_CLIENT_MODE_NO_RESTART
);
742 application
->private->sm_client
= egg_sm_client_get();
743 egg_sm_client_startup();
744 g_debug( "%s: sm_client=%p", thisfn
, ( void * ) application
->private->sm_client
);
746 g_signal_connect( application
->private->sm_client
,
747 "quit-requested", G_CALLBACK( session_manager_client_quit_requested_cb
), application
);
749 g_signal_connect( application
->private->sm_client
,
750 "quit", G_CALLBACK( session_manager_client_quit_cb
), application
);
756 session_manager_client_quit_cb( EggSMClient
*client
, BaseApplication
*application
)
758 static const gchar
*thisfn
= "base_application_session_manager_client_quit_cb";
760 g_return_if_fail( BASE_IS_APPLICATION( application
));
762 g_debug( "%s: client=%p, application=%p", thisfn
, ( void * ) client
, ( void * ) application
);
764 if( application
->private->main_window
&&
765 BASE_IS_WINDOW( application
->private->main_window
)){
767 g_object_unref( application
->private->main_window
);
768 application
->private->main_window
= NULL
;
773 session_manager_client_quit_requested_cb( EggSMClient
*client
, BaseApplication
*application
)
775 static const gchar
*thisfn
= "base_application_session_manager_client_quit_requested_cb";
776 gboolean willing_to
= TRUE
;
778 g_return_if_fail( BASE_IS_APPLICATION( application
));
780 g_debug( "%s: client=%p, application=%p", thisfn
, ( void * ) client
, ( void * ) application
);
782 if( application
->private->main_window
&&
783 BASE_IS_WINDOW( application
->private->main_window
)){
785 willing_to
= base_window_is_willing_to_quit( application
->private->main_window
);
788 egg_sm_client_will_quit( client
, willing_to
);
792 appli_initialize_application_icon( BaseApplication
*application
, int *code
)
794 static const gchar
*thisfn
= "base_application_appli_initialize_application_icon";
796 g_debug( "%s: application=%p, code=%p (%d)", thisfn
, ( void * ) application
, ( void * ) code
, *code
);
798 if( application
->private->icon_name
&&
799 g_utf8_strlen( application
->private->icon_name
, -1 )){
801 gtk_window_set_default_icon_name( application
->private->icon_name
);
808 appli_initialize_builder( BaseApplication
*application
, int *code
)
810 static const gchar
*thisfn
= "base_application_appli_initialize_builder";
812 g_debug( "%s: application=%p, code=%p (%d)", thisfn
, ( void * ) application
, ( void * ) code
, *code
);
814 application
->private->builder
= base_builder_new();
820 * base_application_get_application_name:
821 * @application: this #BaseApplication instance.
823 * Returns: the application name as a newly allocated string which should
824 * be be g_free() by the caller.
827 base_application_get_application_name( const BaseApplication
*application
)
831 g_return_val_if_fail( BASE_IS_APPLICATION( application
), NULL
);
833 if( !application
->private->dispose_has_run
){
835 name
= g_strdup( application
->private->application_name
);
842 * base_application_get_builder:
843 * @application: this #BaseApplication instance.
845 * Returns: the default #BaseBuilder object for the application.
848 base_application_get_builder( BaseApplication
*application
)
850 /*static const gchar *thisfn = "base_application_get_application_name";
851 g_debug( "%s: application=%p", thisfn, application );*/
852 BaseBuilder
*builder
= NULL
;
854 g_return_val_if_fail( BASE_IS_APPLICATION( application
), NULL
);
856 if( !application
->private->dispose_has_run
){
857 builder
= application
->private->builder
;
864 * base_application_get_ui_filename:
865 * @application: this #BaseApplication instance.
867 * Asks the #BaseApplication-derived class for the filename of the file
868 * which contains the XML definition of the user interface.
872 * Returns: a newly allocated string to be g_free() by the caller.
875 base_application_get_ui_filename( BaseApplication
*application
)
877 /*static const gchar *thisfn = "base_application_get_ui_filename";
878 g_debug( "%s: icon=%p", thisfn, application );*/
881 g_return_val_if_fail( BASE_IS_APPLICATION( application
), NULL
);
883 if( !application
->private->dispose_has_run
){
884 if( BASE_APPLICATION_GET_CLASS( application
)->get_ui_filename
){
885 name
= BASE_APPLICATION_GET_CLASS( application
)->get_ui_filename( application
);
888 name
= g_strdup( "" );
896 * base_application_message_dlg:
897 * @application: this #BaseApplication instance.
898 * @message: the message to be displayed.
900 * Displays a dialog with only an OK button.
903 base_application_message_dlg( BaseApplication
*application
, GSList
*msg
)
908 if( !application
->private->dispose_has_run
){
910 string
= g_string_new( "" );
911 for( im
= msg
; im
; im
= im
->next
){
912 if( g_utf8_strlen( string
->str
, -1 )){
913 string
= g_string_append( string
, "\n" );
915 string
= g_string_append( string
, ( gchar
* ) im
->data
);
917 display_dlg( application
, GTK_MESSAGE_INFO
, GTK_BUTTONS_OK
, string
->str
, NULL
);
919 g_string_free( string
, TRUE
);
924 * base_application_error_dlg:
925 * @application: this #BaseApplication instance.
927 * @primary: a first message.
928 * @secondaru: a second message.
930 * Displays an error dialog with only an OK button.
933 base_application_error_dlg( BaseApplication
*application
,
936 const gchar
*second
)
938 if( !application
->private->dispose_has_run
){
939 display_dlg( application
, type
, GTK_BUTTONS_OK
, first
, second
);
944 * base_application_yesno_dlg:
945 * @application: this #BaseApplication instance.
947 * @primary: a first message.
948 * @secondaru: a second message.
950 * Displays a choice dialog, with Yes and No buttons.
951 * No button is the default.
953 * Returns: %TRUE if user has clicked on Yes button, %FALSE else.
956 base_application_yesno_dlg( BaseApplication
*application
, GtkMessageType type
, const gchar
*first
, const gchar
*second
)
958 gboolean ret
= FALSE
;
961 if( !application
->private->dispose_has_run
){
963 result
= display_dlg( application
, type
, GTK_BUTTONS_YES_NO
, first
, second
);
964 ret
= ( result
== GTK_RESPONSE_YES
);
972 application_do_initialize_ui( BaseApplication
*application
)
974 static const gchar
*thisfn
= "base_application_do_initialize_ui";
976 GError
*error
= NULL
;
979 g_debug( "%s: application=%p", thisfn
, ( void * ) application
);
981 name
= base_application_get_ui_filename( application
);
983 if( !name
|| !strlen( name
)){
985 set_initialize_ui_get_fname_error( application
);
988 application
->private->builder
= base_builder_new();
989 if( !base_builder_add_from_file( application
->private->builder
, name
, &error
)){
991 set_initialize_ui_add_xml_error( application
, name
, error
);
993 g_error_free( error
);
1004 display_dlg( BaseApplication
*application
, GtkMessageType type_message
, GtkButtonsType type_buttons
, const gchar
*first
, const gchar
*second
)
1011 g_assert( BASE_IS_APPLICATION( application
));
1014 if( application
->private->main_window
){
1015 parent
= base_window_get_toplevel( application
->private->main_window
);
1018 dialog
= gtk_message_dialog_new( parent
, GTK_DIALOG_MODAL
, type_message
, type_buttons
, "%s", first
);
1020 if( second
&& g_utf8_strlen( second
, -1 )){
1021 gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( dialog
), "%s", second
);
1024 name
= g_get_application_name();
1026 g_object_set( G_OBJECT( dialog
) , "title", name
, NULL
);
1028 result
= gtk_dialog_run( GTK_DIALOG( dialog
));
1030 gtk_widget_destroy( dialog
);
1037 display_error_message( BaseApplication
*application
)
1039 if( application
->private->exit_message1
&& g_utf8_strlen( application
->private->exit_message1
, -1 )){
1041 if( application
->private->is_gtk_initialized
){
1042 base_application_error_dlg(
1045 application
->private->exit_message1
,
1046 application
->private->exit_message2
);
1049 g_printf( "%s\n", application
->private->exit_message1
);
1050 if( application
->private->exit_message2
&& g_utf8_strlen( application
->private->exit_message2
, -1 )){
1051 g_printf( "%s\n", application
->private->exit_message2
);
1058 set_initialize_ui_get_fname_error( BaseApplication
*application
)
1060 application
->private->exit_code
= BASE_APPLICATION_ERROR_UI_FNAME
;
1062 application
->private->exit_message1
=
1063 g_strdup( _( "No filename provided for the UI XML definition." ));
1067 set_initialize_ui_add_xml_error( BaseApplication
*application
, const gchar
*filename
, GError
*error
)
1069 application
->private->exit_code
= BASE_APPLICATION_ERROR_UI_LOAD
;
1071 application
->private->exit_message1
=
1072 /* i18n: Unable to load the XML definition from <filename> */
1073 g_strdup_printf( _( "Unable to load the XML definition from %s." ), filename
);
1075 if( error
&& error
->message
){
1076 application
->private->exit_message2
= g_strdup( error
->message
);