[nautilus-actions: 29/30] Allowing user to run multiple NACT instance on demand
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions: 29/30] Allowing user to run multiple NACT instance on demand
- Date: Sat, 21 Nov 2009 18:03:42 +0000 (UTC)
commit 8eab1a7ea4398d0e1e65a5601158dccf8f621ba4
Author: Pierre Wieser <pwieser trychlos org>
Date: Sat Nov 21 19:00:49 2009 +0100
Allowing user to run multiple NACT instance on demand
Define --non-unique and --version command-line options.
ChangeLog | 27 +++++
TODO | 3 -
nautilus-actions/nact/base-application-class.h | 12 +++
nautilus-actions/nact/base-application.c | 110 ++++++++++++++++++---
nautilus-actions/nact/base-application.h | 7 ++
nautilus-actions/nact/nact-application.c | 40 ++++++++
nautilus-actions/runtime/na-utils.c | 28 +++++
nautilus-actions/runtime/na-utils.h | 4 +
nautilus-actions/utils/console-utils.c | 30 +------
nautilus-actions/utils/console-utils.h | 2 -
nautilus-actions/utils/nautilus-actions-new.c | 2 +-
nautilus-actions/utils/nautilus-actions-schemas.c | 2 +-
12 files changed, 215 insertions(+), 52 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 64c6a25..703f4eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,33 @@
* nautilus-actions/private/Makefile.am:
Remove useless -DPKGLIBDIR.
+ Allow the user to run multiple instances of NACT.
+
+ * nautilus-actions/nact/base-application-class.h (manage_options):
+ New virtual function.
+
+ * nautilus-actions/nact/base-application.c:
+ * nautilus-actions/nact/base-application.h: New entries property.
+
+ * nautilus-actions/nact/base-application.c:
+ argc and argv are now 'contruct only' properties.
+ Accept now an GOptionEntry list as a 'contruct only property'.
+ Check args if GOptionEntry list is not null.
+
+ * nautilus-actions/nact/nact-application.c:
+ Define --version option.
+ Define --non-unique command-line option.
+
+ * nautilus-actions/runtime/na-utils.c:
+ * nautilus-actions/runtime/na-utils.h:
+ * nautilus-actions/utils/console-utils.c:
+ * nautilus-actions/utils/console-utils.h:
+ Move console_print_version() function to na_utils_print_version().
+
+ * nautilus-actions/utils/nautilus-actions-new.c:
+ * nautilus-actions/utils/nautilus-actions-schemas.c:
+ Updated accordingly.
+
2009-11-20 Pierre Wieser <pwieser trychlos org>
Define functions with actual type for arguments.
diff --git a/TODO b/TODO
index a2bea43..054688e 100644
--- a/TODO
+++ b/TODO
@@ -50,9 +50,6 @@
- use eggsmclient
-- add -nounique option to not check for unicity (make easier to compare
- two versions)
-
- when a unique app is found, use libwnck (?) to activate it
- have a preference for modified and invalid fonts
diff --git a/nautilus-actions/nact/base-application-class.h b/nautilus-actions/nact/base-application-class.h
index 73069c2..018408d 100644
--- a/nautilus-actions/nact/base-application-class.h
+++ b/nautilus-actions/nact/base-application-class.h
@@ -152,6 +152,18 @@ typedef struct {
gboolean ( *initialize_gtk ) ( BaseApplication *appli );
/**
+ * manage_options:
+ * @appli: this #BaseApplication instance.
+ *
+ * Lets the application an opportunity to manage options entered
+ * in command-line.
+ *
+ * Returns: %TRUE to continue initialization process,
+ * %FALSE to stop it.
+ */
+ gboolean ( *manage_options ) ( BaseApplication *appli );
+
+ /**
* initialize_application_name:
* @appli: this #BaseApplication instance.
*
diff --git a/nautilus-actions/nact/base-application.c b/nautilus-actions/nact/base-application.c
index 4db4243..e324dc2 100644
--- a/nautilus-actions/nact/base-application.c
+++ b/nautilus-actions/nact/base-application.c
@@ -49,16 +49,17 @@ struct BaseApplicationClassPrivate {
/* private instance data
*/
struct BaseApplicationPrivate {
- gboolean dispose_has_run;
- int argc;
- gpointer argv;
- gboolean is_gtk_initialized;
- UniqueApp *unique_app_handle;
- int exit_code;
- gchar *exit_message1;
- gchar *exit_message2;
- BaseBuilder *builder;
- BaseWindow *main_window;
+ gboolean dispose_has_run;
+ int argc;
+ gpointer argv;
+ GOptionEntry *options;
+ gboolean is_gtk_initialized;
+ UniqueApp *unique_app_handle;
+ int exit_code;
+ gchar *exit_message1;
+ gchar *exit_message2;
+ BaseBuilder *builder;
+ BaseWindow *main_window;
};
/* instance properties
@@ -66,6 +67,7 @@ struct BaseApplicationPrivate {
enum {
BASE_APPLICATION_PROP_ARGC_ID = 1,
BASE_APPLICATION_PROP_ARGV_ID,
+ BASE_APPLICATION_PROP_OPTIONS_ID,
BASE_APPLICATION_PROP_IS_GTK_INITIALIZED_ID,
BASE_APPLICATION_PROP_UNIQUE_APP_HANDLE_ID,
BASE_APPLICATION_PROP_EXIT_CODE_ID,
@@ -88,6 +90,7 @@ static void instance_finalize( GObject *application );
static gboolean v_initialize( BaseApplication *application );
static gboolean v_initialize_i18n( BaseApplication *application );
static gboolean v_initialize_gtk( BaseApplication *application );
+static gboolean v_manage_options( BaseApplication *application );
static gboolean v_initialize_application_name( BaseApplication *application );
static gboolean v_initialize_unique_app( BaseApplication *application );
static gboolean v_initialize_ui( BaseApplication *application );
@@ -98,6 +101,7 @@ static int application_do_run( BaseApplication *application );
static gboolean application_do_initialize( BaseApplication *application );
static gboolean application_do_initialize_i18n( BaseApplication *application );
static gboolean application_do_initialize_gtk( BaseApplication *application );
+static gboolean application_do_manage_options( BaseApplication *application );
static gboolean application_do_initialize_application_name( BaseApplication *application );
static gboolean application_do_initialize_unique_app( BaseApplication *application );
static gboolean application_do_initialize_ui( BaseApplication *application );
@@ -109,6 +113,7 @@ static gboolean check_for_unique_app( BaseApplication *application );
static gint display_dlg( BaseApplication *application, GtkMessageType type_message, GtkButtonsType type_buttons, const gchar *first, const gchar *second );
static void display_error_message( BaseApplication *application );
+static gboolean init_with_args( BaseApplication *application, int *argc, char ***argv, GOptionEntry *entries );
static void set_initialize_i18n_error( BaseApplication *application );
static void set_initialize_gtk_error( BaseApplication *application );
static void set_initialize_unique_app_error( BaseApplication *application );
@@ -177,16 +182,23 @@ class_init( BaseApplicationClass *klass )
BASE_APPLICATION_PROP_ARGC,
"Command-line arguments count",
"Command-line arguments count", 0, 65535, 0,
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
g_object_class_install_property( object_class, BASE_APPLICATION_PROP_ARGC_ID, spec );
spec = g_param_spec_pointer(
BASE_APPLICATION_PROP_ARGV,
"Command-line arguments",
"A pointer to command-line arguments",
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
g_object_class_install_property( object_class, BASE_APPLICATION_PROP_ARGV_ID, spec );
+ spec = g_param_spec_pointer(
+ BASE_APPLICATION_PROP_OPTIONS,
+ "Command-line options",
+ "A pointer to command-line options",
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
+ g_object_class_install_property( object_class, BASE_APPLICATION_PROP_OPTIONS_ID, spec );
+
spec = g_param_spec_boolean(
BASE_APPLICATION_PROP_IS_GTK_INITIALIZED,
"Gtk+ initialization flag",
@@ -242,6 +254,7 @@ class_init( BaseApplicationClass *klass )
klass->initialize = application_do_initialize;
klass->initialize_i18n = application_do_initialize_i18n;
klass->initialize_gtk = application_do_initialize_gtk;
+ klass->manage_options = application_do_manage_options;
klass->initialize_application_name = application_do_initialize_application_name;
klass->initialize_unique_app = application_do_initialize_unique_app;
klass->initialize_ui = application_do_initialize_ui;
@@ -290,6 +303,10 @@ instance_get_property( GObject *object, guint property_id, GValue *value, GParam
g_value_set_pointer( value, self->private->argv );
break;
+ case BASE_APPLICATION_PROP_OPTIONS_ID:
+ g_value_set_pointer( value, self->private->options );
+ break;
+
case BASE_APPLICATION_PROP_IS_GTK_INITIALIZED_ID:
g_value_set_boolean( value, self->private->is_gtk_initialized );
break;
@@ -344,6 +361,10 @@ instance_set_property( GObject *object, guint property_id, const GValue *value,
self->private->argv = g_value_get_pointer( value );
break;
+ case BASE_APPLICATION_PROP_OPTIONS_ID:
+ self->private->options = g_value_get_pointer( value );
+ break;
+
case BASE_APPLICATION_PROP_IS_GTK_INITIALIZED_ID:
self->private->is_gtk_initialized = g_value_get_boolean( value );
break;
@@ -766,6 +787,19 @@ v_initialize_gtk( BaseApplication *application )
}
static gboolean
+v_manage_options( BaseApplication *application )
+{
+ static const gchar *thisfn = "base_application_v_manage_options";
+ gboolean ok;
+
+ g_debug( "%s: application=%p", thisfn, ( void * ) application );
+
+ ok = BASE_APPLICATION_GET_CLASS( application )->manage_options( application );
+
+ return( ok );
+}
+
+static gboolean
v_initialize_application_name( BaseApplication *application )
{
static const gchar *thisfn = "base_application_v_initialize_application_name";
@@ -880,8 +914,9 @@ application_do_initialize( BaseApplication *application )
return(
v_initialize_i18n( application ) &&
- v_initialize_gtk( application ) &&
v_initialize_application_name( application ) &&
+ v_initialize_gtk( application ) &&
+ v_manage_options( application ) &&
v_initialize_unique_app( application ) &&
v_initialize_ui( application ) &&
v_initialize_default_icon( application ) &&
@@ -913,21 +948,41 @@ application_do_initialize_gtk( BaseApplication *application )
int argc;
gpointer argv;
gboolean ret;
+ GOptionEntry *options;
g_debug( "%s: application=%p", thisfn, ( void * ) application );
- g_object_get( G_OBJECT( application ), BASE_APPLICATION_PROP_ARGC, &argc, BASE_APPLICATION_PROP_ARGV, &argv, NULL );
+ g_object_get( G_OBJECT( application ),
+ BASE_APPLICATION_PROP_ARGC, &argc,
+ BASE_APPLICATION_PROP_ARGV, &argv,
+ BASE_APPLICATION_PROP_OPTIONS, &options,
+ NULL );
- ret = gtk_init_check( &argc, ( char *** ) &argv );
+ if( options ){
+ ret = init_with_args( application, &argc, ( char *** ) &argv, options );
+ } else {
+ ret = gtk_init_check( &argc, ( char *** ) &argv );
+ }
if( ret ){
- g_object_set( G_OBJECT( application ), BASE_APPLICATION_PROP_ARGC, argc, BASE_APPLICATION_PROP_ARGV, argv, NULL );
+ application->private->argc = argc;
+ application->private->argv = argv;
}
return( ret );
}
static gboolean
+application_do_manage_options( BaseApplication *application )
+{
+ static const gchar *thisfn = "base_application_do_manage_options";
+
+ g_debug( "%s: application=%p", thisfn, ( void * ) application );
+
+ return( TRUE );
+}
+
+static gboolean
application_do_initialize_application_name( BaseApplication *application )
{
static const gchar *thisfn = "base_application_do_initialize_application_name";
@@ -1123,6 +1178,29 @@ display_error_message( BaseApplication *application )
}
}
+static gboolean
+init_with_args( BaseApplication *application, int *argc, char ***argv, GOptionEntry *entries )
+{
+ static const gchar *thisfn = "base_application_init_with_args";
+ gboolean ret;
+ char *parameter_string;
+ GError *error;
+
+ parameter_string = g_strdup( g_get_application_name());
+ error = NULL;
+
+ ret = gtk_init_with_args( argc, argv, parameter_string, entries, GETTEXT_PACKAGE, &error );
+ if( error ){
+ g_warning( "%s: %s", thisfn, error->message );
+ g_error_free( error );
+ ret = FALSE;
+ }
+
+ g_free( parameter_string );
+
+ return( ret );
+}
+
static void
set_initialize_i18n_error( BaseApplication *application )
{
diff --git a/nautilus-actions/nact/base-application.h b/nautilus-actions/nact/base-application.h
index e18521c..a14377f 100644
--- a/nautilus-actions/nact/base-application.h
+++ b/nautilus-actions/nact/base-application.h
@@ -67,6 +67,13 @@ enum {
#define BASE_APPLICATION_PROP_ARGV "base-application-argv"
/**
+ * @BASE_APPLICATION_PROP_OPTIONS: command-line options.
+ *
+ * Can be provided at instanciation time only.
+ */
+#define BASE_APPLICATION_PROP_OPTIONS "base-application-options"
+
+/**
* @BASE_APPLICATION_PROP_IS_GTK_INITIALIZED: set to %TRUE after
* successfully returning from the application_initialize_gtk() virtual
* function.
diff --git a/nautilus-actions/nact/nact-application.c b/nautilus-actions/nact/nact-application.c
index 8c0790f..ac5cb0a 100644
--- a/nautilus-actions/nact/nact-application.c
+++ b/nautilus-actions/nact/nact-application.c
@@ -39,6 +39,7 @@
#include <runtime/na-iabout.h>
#include <runtime/na-ipivot-consumer.h>
+#include <runtime/na-utils.h>
#include "nact-application.h"
#include "nact-main-window.h"
@@ -64,6 +65,17 @@ enum {
#define NACT_APPLICATION_PROP_PIVOT "nact-application-pivot"
+static gboolean st_non_unique_opt = FALSE;
+static gboolean st_version_opt = FALSE;
+
+static GOptionEntry st_entries[] = {
+ { "non-unique", 'n', 0, G_OPTION_ARG_NONE, &st_non_unique_opt,
+ N_( "Set it to run multiple instances of the program [unique]" ), NULL },
+ { "version" , 'v', 0, G_OPTION_ARG_NONE, &st_version_opt,
+ N_( "Output the version number, and exit gracefully [no]" ), NULL },
+ { NULL }
+};
+
static BaseApplicationClass *st_parent_class = NULL;
static GType register_type( void );
@@ -74,6 +86,7 @@ static void instance_set_property( GObject *object, guint property_id, const
static void instance_dispose( GObject *application );
static void instance_finalize( GObject *application );
+static gboolean appli_manage_options( BaseApplication *application );
static gboolean appli_initialize_unique_app( BaseApplication *application );
static gboolean appli_initialize_application( BaseApplication *application );
static gchar *appli_get_application_name( BaseApplication *application );
@@ -147,6 +160,7 @@ class_init( NactApplicationClass *klass )
klass->private = g_new0( NactApplicationClassPrivate, 1 );
appli_class = BASE_APPLICATION_CLASS( klass );
+ appli_class->manage_options = appli_manage_options;
appli_class->initialize_unique_app = appli_initialize_unique_app;
appli_class->initialize_application = appli_initialize_application;
appli_class->get_application_name = appli_get_application_name;
@@ -273,6 +287,7 @@ nact_application_new_with_args( int argc, char **argv )
NACT_APPLICATION_TYPE,
BASE_APPLICATION_PROP_ARGC, argc,
BASE_APPLICATION_PROP_ARGV, argv,
+ BASE_APPLICATION_PROP_OPTIONS, st_entries,
NULL )
);
}
@@ -300,6 +315,27 @@ nact_application_get_pivot( NactApplication *application )
}
/*
+ * overriden to manage command-line options
+ */
+static gboolean
+appli_manage_options( BaseApplication *application )
+{
+ gboolean ok;
+
+ /* call parent class */
+ ok = BASE_APPLICATION_CLASS( st_parent_class )->manage_options( application );
+
+ if( ok ){
+ if( st_version_opt ){
+ na_utils_print_version();
+ ok = FALSE;
+ }
+ }
+
+ return( ok );
+}
+
+/*
* overrided to provide a personalized error message
*/
static gboolean
@@ -394,6 +430,10 @@ appli_get_unique_app_name( BaseApplication *application )
g_debug( "%s: application=%p", thisfn, ( void * ) application );
+ if( st_non_unique_opt ){
+ return( g_strdup( "" ));
+ }
+
return( g_strdup( "org.nautilus-actions.ConfigurationTool" ));
}
diff --git a/nautilus-actions/runtime/na-utils.c b/nautilus-actions/runtime/na-utils.c
index 47f9b0b..34e0d0f 100644
--- a/nautilus-actions/runtime/na-utils.c
+++ b/nautilus-actions/runtime/na-utils.c
@@ -36,6 +36,7 @@
#include <glib-object.h>
#include <string.h>
+#include "na-iabout.h"
#include "na-utils.h"
static GSList *text_to_string_list( const gchar *text, const gchar *separator, const gchar *default_value );
@@ -645,3 +646,30 @@ na_utils_remove_last_level_from_path( const gchar *path )
return( new_path );
}
+
+/**
+ * na_utils_print_version:
+ *
+ * Print a version message on the console
+ *
+ * nautilus-actions-new (Nautilus-Actions) v 2.29.1
+ * Copyright (C) 2005-2007 Frederic Ruaudel
+ * Copyright (C) 2009 Pierre Wieser
+ * Nautilus-Actions is free software, licensed under GPLv2 or later.
+ */
+void
+na_utils_print_version( void )
+{
+ gchar *copyright;
+
+ g_print( "\n" );
+ g_print( "%s (%s) v %s\n", g_get_prgname(), PACKAGE_NAME, PACKAGE_VERSION );
+ copyright = na_iabout_get_copyright( TRUE );
+ g_print( "%s\n", copyright );
+ g_free( copyright );
+
+ g_print( "%s is free software, and is provided without any warranty. You may\n", PACKAGE_NAME );
+ g_print( "redistribute copies of %s under the terms of the GNU General Public\n", PACKAGE_NAME );
+ g_print( "License (see COPYING).\n" );
+ g_print( "\n" );
+}
diff --git a/nautilus-actions/runtime/na-utils.h b/nautilus-actions/runtime/na-utils.h
index 1016e04..66669b2 100644
--- a/nautilus-actions/runtime/na-utils.h
+++ b/nautilus-actions/runtime/na-utils.h
@@ -73,6 +73,10 @@ gboolean na_utils_is_writable_dir( const gchar *uri );
gchar *na_utils_path_extract_last_dir( const gchar *path );
gchar *na_utils_remove_last_level_from_path( const gchar *path );
+/* console utilities
+ */
+void na_utils_print_version( void );
+
G_END_DECLS
#endif /* __NA_RUNTIME_UTILS_H__ */
diff --git a/nautilus-actions/utils/console-utils.c b/nautilus-actions/utils/console-utils.c
index 746bc1d..2484216 100644
--- a/nautilus-actions/utils/console-utils.c
+++ b/nautilus-actions/utils/console-utils.c
@@ -34,7 +34,7 @@
#include <glib.h>
-#include <runtime/na-iabout.h>
+#include <runtime/na-utils.h>
#include "console-utils.h"
@@ -54,34 +54,6 @@ console_init_log_handler( void )
st_default_log_func = g_log_set_default_handler(( GLogFunc ) log_handler, NULL );
}
-/**
- * console_print_version:
- *
- * Prints the current version of the program to stdout.
- */
-/*
- * nautilus-actions-new (Nautilus-Actions) v 2.29.1
- * Copyright (C) 2005-2007 Frederic Ruaudel
- * Copyright (C) 2009 Pierre Wieser
- * Nautilus-Actions is free software, licensed under GPLv2 or later.
- */
-void
-console_print_version( void )
-{
- gchar *copyright;
-
- g_print( "\n" );
- g_print( "%s (%s) v %s\n", g_get_prgname(), PACKAGE_NAME, PACKAGE_VERSION );
- copyright = na_iabout_get_copyright( TRUE );
- g_print( "%s\n", copyright );
- g_free( copyright );
-
- g_print( "%s is free software, and is provided without any warranty. You may\n", PACKAGE_NAME );
- g_print( "redistribute copies of %s under the terms of the GNU General Public\n", PACKAGE_NAME );
- g_print( "License (see COPYING).\n" );
- g_print( "\n" );
-}
-
static void
log_handler( const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data )
{
diff --git a/nautilus-actions/utils/console-utils.h b/nautilus-actions/utils/console-utils.h
index 2350205..a8e11a3 100644
--- a/nautilus-actions/utils/console-utils.h
+++ b/nautilus-actions/utils/console-utils.h
@@ -39,6 +39,4 @@
void console_init_log_handler( void );
-void console_print_version( void );
-
#endif /* __CONSOLE_UTILS_H__ */
diff --git a/nautilus-actions/utils/nautilus-actions-new.c b/nautilus-actions/utils/nautilus-actions-new.c
index 8262c9a..0ff7c19 100644
--- a/nautilus-actions/utils/nautilus-actions-new.c
+++ b/nautilus-actions/utils/nautilus-actions-new.c
@@ -169,7 +169,7 @@ main( int argc, char** argv )
}
if( version ){
- console_print_version();
+ na_utils_print_version();
exit( status );
}
diff --git a/nautilus-actions/utils/nautilus-actions-schemas.c b/nautilus-actions/utils/nautilus-actions-schemas.c
index 7253458..c017637 100644
--- a/nautilus-actions/utils/nautilus-actions-schemas.c
+++ b/nautilus-actions/utils/nautilus-actions-schemas.c
@@ -100,7 +100,7 @@ main( int argc, char** argv )
}
if( version ){
- console_print_version();
+ na_utils_print_version();
exit( status );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]