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)
31 #ifndef __BASE_APPLICATION_H__
32 #define __BASE_APPLICATION_H__
35 * SECTION: base-application
36 * @title: BaseApplication
37 * @short_description: The Base Application application base class definition
38 * @include: base-application.h
40 * #BaseApplication is the base class for the application part of Gtk programs.
41 * It aims at providing all common services. It interacts with #BaseBuilder
42 * and #BaseWindow classes.
44 * #BaseApplication is a pure virtual class. A Gtk program should derive
45 * its own class from #BaseApplication, and instantiate it in its main()
46 * program entry point.
50 * #include "my-application.h"
53 * main( int argc, char **argv )
55 * MyApplication *appli;
58 * appli = my_application_new_with_args( argc, argv );
59 * code = base_appliction_run( BASE_APPLICATION( appli ));
60 * g_object_unref( appli );
68 #include "base-builder.h"
72 #define BASE_APPLICATION_TYPE ( base_application_get_type())
73 #define BASE_APPLICATION( object ) ( G_TYPE_CHECK_INSTANCE_CAST( object, BASE_APPLICATION_TYPE, BaseApplication ))
74 #define BASE_APPLICATION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( klass, BASE_APPLICATION_TYPE, BaseApplicationClass ))
75 #define BASE_IS_APPLICATION( object ) ( G_TYPE_CHECK_INSTANCE_TYPE( object, BASE_APPLICATION_TYPE ))
76 #define BASE_IS_APPLICATION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE(( klass ), BASE_APPLICATION_TYPE ))
77 #define BASE_APPLICATION_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), BASE_APPLICATION_TYPE, BaseApplicationClass ))
79 typedef struct _BaseApplicationPrivate BaseApplicationPrivate
;
84 BaseApplicationPrivate
*private;
88 typedef struct _BaseApplicationClassPrivate BaseApplicationClassPrivate
;
91 * BaseApplicationClass:
92 * @manage_options: manage the command-line arguments.
93 * @main_window_new: open and run the first (main) window of the application.
95 * This defines the virtual method a derived class may, should or must implement.
100 BaseApplicationClassPrivate
*private;
105 * @appli: this #BaseApplication -derived instance.
106 * @code: a pointer to an integer that the derived application may
107 * set as the exit code of the program if it chooses to stop
108 * the execution; the code set here will be ignored if execution
109 * is allowed to continue.
111 * This is invoked by the BaseApplication base class, after arguments
112 * in the command-line have been processed by gtk_init_with_args()
115 * This let the derived class an opportunity to manage command-line
118 * If it does not dected an error, the derived class should call the
119 * parent method, to give it a chance to manage its own options.
121 * Returns: %TRUE to continue execution, %FALSE to stop it.
122 * In this later case only, the exit code set in @code will be considered.
124 gboolean ( *manage_options
) ( const BaseApplication
*appli
, int *code
);
128 * @appli: this #BaseApplication -derived instance.
130 * This is invoked by the BaseApplication base class to let the derived
131 * class do its own initializations and create its main window.
133 * This is a pure virtual method.
135 * Returns: the main window of the application, as a #BaseWindow
136 * -derived object. It may or may not having already been initialized.
138 GObject
* ( *main_window_new
)( const BaseApplication
*appli
, int *code
);
142 * @appli: this #BaseApplication instance.
144 * Starts and runs the application.
146 * Returns: an %int code suitable as an exit code for the program.
148 * Overriding this function should be very seldomly needed.
150 * Base class implementation takes care of creating, initializing,
151 * and running the main window. It blocks until the end of the
154 int ( *run
) ( BaseApplication
*appli
);
158 * @appli: this #BaseApplication instance.
160 * Initializes the program.
162 * If this function successfully returns, the program is supposed
163 * to be able to successfully run the main window.
165 * Returns: %TRUE if all initialization is complete and the program
168 * Returning %FALSE means that something has gone wrong in the
169 * initialization process, thus preventing the application to
170 * actually be ran. Aside of returning %FALSE, the responsible
171 * code may also have setup #exit_code and #exit_message.
173 * When overriding this function, and unless you want have a whole
174 * new initialization process, you should call the base class
177 * From the base class implementation point of view, this function
178 * leads the global initialization process of the program. It
179 * actually calls a suite of elementary initialization virtual
180 * functions which may themselves be individually overriden by the
183 * Each individual function should return %TRUE in order to
184 * continue with the initialization process, or %FALSE to stop it.
186 * In other words, the base class implementation considers that the
187 * application is correctly initialized if and only if all
188 * individual initialization virtual functions have returned %TRUE.
190 gboolean ( *initialize
) ( BaseApplication
*appli
);
194 * @appli: this #BaseApplication instance.
196 * Initializes the i18n context.
198 * Returns: %TRUE if OK, %FALSE else.
200 * The base class implementation always returns %TRUE.
202 gboolean ( *initialize_i18n
) ( BaseApplication
*appli
);
206 * @appli: this #BaseApplication instance.
208 * Initializes the Gtk+ GUI interface.
210 * This function must have been successfully called to be able to
211 * display error message in a graphical dialog box rather than as
212 * a character-style stdout message.
214 * Returns: %TRUE if OK, %FALSE if Gtk+ has been unable to
215 * initialize the GUI interface.
217 * The base class implementation defaults to gtk_init_check(). The
218 * derived class may want override it, for example if it wants
219 * parse some command-line parameters.
221 * If failed, the base class implementation sets #exit_code to
222 * %APPLICATION_ERROR_GTK, and prepares a short #exit_message to be
225 gboolean ( *initialize_gtk
) ( BaseApplication
*appli
);
228 * initialize_application_name:
229 * @appli: this #BaseApplication instance.
231 * Initializes the name of the application.
233 gboolean ( *initialize_application_name
)( BaseApplication
*appli
);
236 * initialize_unique_app:
237 * @appli: this #BaseApplication instance.
239 * If relevant, checks if an instance of the application is already
242 * Returns: %TRUE if the initialization process can continue,
243 * %FALSE if the application asked for to be unique and another
244 * instance is already running.
246 * If failed, this function sets #exit_code to
247 * %APPLICATION_ERROR_UNIQUE_APP, and prepares a short #exit_message
248 * to be displayed in a dialog box.
250 * The base class implementation asks the #BaseApplication-derived
251 * class for a DBus unique name. If not empty, it then allocates a
252 * UniqueApp object, delegating it the actual check for the unicity
253 * of the application instance.
255 * If another instance is already running, the base class
256 * implementation sets #exit_code to APPLICATION_ERROR_UNIQUE_APP,
257 * and prepares a short #exit_message to be displayed in a dialog
260 gboolean ( *initialize_unique_app
) ( BaseApplication
*appli
);
263 * initialize_session_manager:
264 * @appli: this #BaseApplication instance.
266 * Initializes the Egg session manager.
270 gboolean ( *initialize_session_manager
) ( BaseApplication
*appli
);
274 * @appli: this #BaseApplication instance.
276 * Loads and initializes the XML file which contains the description
277 * of the user interface of the application.
279 * Returns: %TRUE if the UI description has been successfully
280 * loaded, %FALSE else.
282 * If failed, this function sets #exit_code to %APPLICATION_ERROR_UI,
283 * and prepares a short #exit_message to be displayed in a dialog
286 * The base class implementation asks the #BaseApplication-derived
287 * class for the XML filename. If not empty, it then loads it, and
288 * initializes a corresponding GtkBuilder object.
290 gboolean ( *initialize_ui
) ( BaseApplication
*appli
);
293 * initialize_default_icon:
294 * @appli: this #BaseApplication instance.
296 * Initializes the default icon for the application.
298 * Returns: %TRUE if the default icon has been successfully set for
299 * the application, %FALSE else.
301 * The base class implementation always returns %TRUE.
303 gboolean ( *initialize_default_icon
) ( BaseApplication
*appli
);
306 * initialize_application:
307 * @appli: this #BaseApplication instance.
309 * Initializes the derived-class application.
311 * When this function successfully returns, the #BaseApplication
312 * instance must have a valid pointer to the #BaseWindow-derived
313 * object which will be used as a main window for the application.
315 * Returns: %TRUE if at least all mandatory informations have been
316 * collected, %FALSE else.
318 * The base class implementation asks the derived class to
319 * allocates and provides the BaseWindow-derived object which will
320 * be the main window of the application
321 * (cf. get_main_window()). This step is mandatory.
323 * If failed, this function sets #exit_code to the value which is
324 * pertinent depending of the missing information, and prepares a
325 * short #exit_message to be displayed in a dialog box.
327 gboolean ( *initialize_application
) ( BaseApplication
*appli
);
330 * get_application_name:
331 * @appli: this #BaseApplication instance.
333 * Asks the derived class for the application name.
335 * It is typically used as the primary title of the main window.
337 * If not provided by the derived class, application name defaults
340 * Returns: the application name, to be g_free() by the caller.
342 gchar
* ( *get_application_name
) ( BaseApplication
*appli
);
346 * @appli: this #BaseApplication instance.
348 * Asks the derived class for the name of the default icon.
350 * It is typically used as the icon of the main window.
352 * No default is provided by the base class.
354 * Returns: the default icon name for the application, to be
355 * g_free() by the caller.
357 gchar
* ( *get_icon_name
) ( BaseApplication
*appli
);
360 * get_unique_app_name:
361 * @appli: this #BaseApplication instance.
363 * Asks the derived class for the UniqueApp name of this application.
365 * A UniqueApp name is typically of the form
366 * "com.mydomain.MyApplication.MyName". It is registered in DBus
367 * system by each running instance of the application, and is then
368 * used to check if another instance of the application is already
371 * No default is provided by the base class, which means that the
372 * base class defaults to not check for another instance.
374 * Returns: the UniqueApp name of the application, to be g_free()
377 gchar
* ( *get_unique_app_name
) ( BaseApplication
*appli
);
381 * @appli: this #BaseApplication instance.
383 * Asks the derived class for the filename of the XML definition of
384 * the user interface. This XML definition must be suitable in order
385 * to be loaded via GtkBuilder.
387 * No default is provided by the base class. If the base class does
388 * not provide one, then the program stops and exits with the code
389 * %APPLICATION_ERROR_UI_FNAME.
391 * Returns: the filename of the XML definition, to be g_free() by
394 gchar
* ( *get_ui_filename
) ( BaseApplication
*appli
);
398 * @appli: this #BaseApplication instance.
400 * Returns: a pointer to the #BaseWindow-derived main window of the
401 * application. This pointer is owned by the @appli, and should not
402 * be g_free() not g_object_unref() by the caller.
404 GObject
* ( *get_main_window
) ( BaseApplication
*appli
);
406 BaseApplicationClass
;
409 * Properties defined by the BaseApplication class.
410 * They should be provided at object instantiation time.
412 * @BASE_PROP_ARGC: count of arguments in command-line.
413 * @BASE_PROP_ARGV: array of command-line arguments.
414 * @BASE_PROP_OPTIONS: array of command-line options descriptions.
415 * @BASE_PROP_APPLICATION_NAME: application name.
416 * @BASE_PROP_ICON_NAME: icon name.
417 * @BASE_PROP_UNIQUE_APP_NAME: unique name of the application (if apply)
419 #define BASE_PROP_ARGC "base-application-argc"
420 #define BASE_PROP_ARGV "base-application-argv"
421 #define BASE_PROP_OPTIONS "base-application-options"
422 #define BASE_PROP_APPLICATION_NAME "base-application-name"
423 #define BASE_PROP_ICON_NAME "base-application-icon-name"
424 #define BASE_PROP_UNIQUE_APP_NAME "base-application-unique-app-name"
427 BASE_APPLICATION_ERROR_I18N
= 1, /* i18n initialization error */
428 BASE_APPLICATION_ERROR_GTK
, /* gtk+ initialization error */
429 BASE_APPLICATION_ERROR_MAIN_WINDOW
, /* unable to obtain the main window */
430 BASE_APPLICATION_ERROR_UNIQUE_APP
, /* another instance is running */
431 BASE_APPLICATION_ERROR_UI_FNAME
, /* empty XML filename */
432 BASE_APPLICATION_ERROR_UI_LOAD
, /* unable to load the XML definition of the UI */
433 BASE_APPLICATION_ERROR_DEFAULT_ICON
/* unable to set default icon */
437 * @BASE_APPLICATION_PROP_IS_GTK_INITIALIZED: set to %TRUE after
438 * successfully returning from the application_initialize_gtk() virtual
441 * While this flag is not %TRUE, error messages are printed to
442 * stdout. When %TRUE, error messages are displayed with a dialog
445 #define BASE_APPLICATION_PROP_IS_GTK_INITIALIZED "base-application-is-gtk-initialized"
448 * @BASE_APPLICATION_PROP_UNIQUE_APP_HANDLE: the UniqueApp object allocated
449 * if the derived-class has provided a UniqueApp name (see
450 * #application_get_unique_app_name). Rather for internal use.
452 #define BASE_APPLICATION_PROP_UNIQUE_APP_HANDLE "base-application-unique-app-handle"
455 * @BASE_APPLICATION_PROP_EXIT_CODE: the code which will be returned by the
456 * program to the operating system.
457 * @BASE_APPLICATION_PROP_EXIT_MESSAGE1:
458 * @BASE_APPLICATION_PROP_EXIT_MESSAGE2: the message which will be displayed
459 * at program terminaison if @BASE_APPLICATION_PROP_EXIT_CODE is not zero.
460 * When in graphical mode, the first line is displayed as bold.
462 * See @BASE_APPLICATION_PROP_IS_GTK_INITIALIZED for how the
463 * @BASE_APPLICATION_PROP_EXIT_MESSAGE is actually displayed.
465 #define BASE_APPLICATION_PROP_EXIT_CODE "base-application-exit-code"
466 #define BASE_APPLICATION_PROP_EXIT_MESSAGE1 "base-application-exit-message1"
467 #define BASE_APPLICATION_PROP_EXIT_MESSAGE2 "base-application-exit-message2"
470 * @BASE_APPLICATION_PROP_BUILDER: the #BaseBuilder object allocated to
471 * handle the user interface XML definition. Rather for internal use.
473 #define BASE_APPLICATION_PROP_BUILDER "base-application-builder"
476 * @BASE_APPLICATION_PROP_MAIN_WINDOW: as its name says: a pointer to the
477 * #BaseWindow-derived main window of the application.
479 #define BASE_APPLICATION_PROP_MAIN_WINDOW "base-application-main-window"
481 GType
base_application_get_type( void );
483 int base_application_run( BaseApplication
*application
);
485 gchar
*base_application_get_application_name( BaseApplication
*application
);
486 gchar
*base_application_get_icon_name( BaseApplication
*application
);
487 gchar
*base_application_get_unique_app_name( BaseApplication
*application
);
488 gchar
*base_application_get_ui_filename( BaseApplication
*application
);
489 BaseBuilder
*base_application_get_builder( BaseApplication
*application
);
491 void base_application_message_dlg( BaseApplication
*application
, GSList
*message
);
492 void base_application_error_dlg( BaseApplication
*application
, GtkMessageType type
, const gchar
*first
, const gchar
*second
);
493 gboolean
base_application_yesno_dlg( BaseApplication
*application
, GtkMessageType type
, const gchar
*first
, const gchar
*second
);
497 #endif /* __BASE_APPLICATION_H__ */