[nautilus-actions] Add --version command-line argument to nautilus-actions-new



commit 9ba7b0c2a9f0e1c9c24aca7d8e79627b70b209be
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Oct 27 21:48:22 2009 +0100

    Add --version command-line argument to nautilus-actions-new

 ChangeLog                        |    7 +++
 src/runtime/na-iabout.c          |   34 ++++++++++++--
 src/runtime/na-iabout.h          |    1 +
 src/utils/nautilus-actions-new.c |   91 +++++++++++++++++++++++++++++++-------
 4 files changed, 112 insertions(+), 21 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 64eca38..3fd0cfc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-10-27 Pierre Wieser <pwieser trychlos org>
 
+	* src/runtime/na-iabout.c:
+	* src/runtime/na-iabout.h (na_iabout_get_copyright):
+	New function.
+
+	* src/utils/nautilus-actions-new.c:
+	Add --version command-line argument.
+
 	* src/nact/nact-ibackground-tab.c (insert_new_row):
 	Optimizes because the list is sorted on uris.
 
diff --git a/src/runtime/na-iabout.c b/src/runtime/na-iabout.c
index 5927c52..e767815 100644
--- a/src/runtime/na-iabout.c
+++ b/src/runtime/na-iabout.c
@@ -154,7 +154,7 @@ na_iabout_display( NAIAbout *instance )
 {
 	static const gchar *thisfn = "na_iabout_display";
 	gchar *application_name;
-	gchar *icon_name, *license_i18n;
+	gchar *icon_name, *license_i18n, *copyright;
 	GtkWindow *toplevel;
 
 	static const gchar *artists[] = {
@@ -198,14 +198,14 @@ na_iabout_display( NAIAbout *instance )
 		toplevel = v_get_toplevel( instance );
 
 		icon_name = na_iabout_get_icon_name();
-
+		copyright = na_iabout_get_copyright( FALSE );
 		license_i18n = g_strjoinv( "\n\n", license );
 
 		gtk_show_about_dialog( toplevel,
 				"artists", artists,
 				"authors", authors,
 				"comments", _( "A graphical interface to create and edit your Nautilus actions." ),
-				"copyright", _( "Copyright \xc2\xa9 2005-2007 Frederic Ruaudel <grumz grumz net>\nCopyright \xc2\xa9 2009 Pierre Wieser <pwieser trychlos org>" ),
+				"copyright", copyright,
 				"documenters", documenters,
 				"license", license_i18n,
 				"logo-icon-name", icon_name,
@@ -218,6 +218,7 @@ na_iabout_display( NAIAbout *instance )
 
 		g_free( application_name );
 		g_free( license_i18n );
+		g_free( copyright );
 		g_free( icon_name );
 	}
 }
@@ -225,10 +226,35 @@ na_iabout_display( NAIAbout *instance )
 /**
  * na_iabout_get_icon_name:
  *
- * Returns the name of the default icon for the application.
+ * Returns: the name of the default icon for the application, as a newly
+ * allocated string which should be g_free() by the caller.
  */
 gchar *
 na_iabout_get_icon_name( void )
 {
 	return( g_strdup( PACKAGE ));
 }
+
+/**
+ * na_iabout_get_copyright:
+ * @console: whether the string is to be printed on a console.
+ *
+ * Returns: the copyright string, as a newly allocated string which
+ * should be g_free() by the caller.
+ */
+gchar *
+na_iabout_get_copyright( gboolean console )
+{
+	gchar *copyright;
+	gchar *symbol;
+
+	symbol = g_strdup( console ? "(C)" : "\xc2\xa9");
+
+	copyright = g_strdup_printf(
+			_( "Copyright %s 2005-2007 Frederic Ruaudel <grumz grumz net>\n"
+				"Copyright %s 2009 Pierre Wieser <pwieser trychlos org>" ), symbol, symbol );
+
+	g_free( symbol );
+
+	return( copyright );
+}
diff --git a/src/runtime/na-iabout.h b/src/runtime/na-iabout.h
index 67c3ce9..9d552e0 100644
--- a/src/runtime/na-iabout.h
+++ b/src/runtime/na-iabout.h
@@ -83,6 +83,7 @@ GType  na_iabout_get_type( void );
 void   na_iabout_display( NAIAbout *instance );
 
 gchar *na_iabout_get_icon_name( void );
+gchar *na_iabout_get_copyright( gboolean console );
 
 G_END_DECLS
 
diff --git a/src/utils/nautilus-actions-new.c b/src/utils/nautilus-actions-new.c
index baf9675..edd4e8b 100644
--- a/src/utils/nautilus-actions-new.c
+++ b/src/utils/nautilus-actions-new.c
@@ -36,6 +36,7 @@
 #include <glib/gi18n.h>
 #include <stdlib.h>
 
+#include <runtime/na-iabout.h>
 #include <runtime/na-gconf-provider.h>
 #include <runtime/na-iio-provider.h>
 
@@ -60,34 +61,58 @@ static gboolean   accept_multiple = FALSE;
 static gchar    **schemes_array   = NULL;
 static gchar     *output_dir      = NULL;
 static gboolean   output_gconf    = FALSE;
+static gboolean   version         = FALSE;
 
 static GOptionEntry entries[] = {
 
-	{ "label"                , 'l', 0, G_OPTION_ARG_STRING      , &label          ,	N_("The label of the menu item (mandatory)"), N_("LABEL") },
-	{ "tooltip"              , 't', 0, G_OPTION_ARG_STRING      , &tooltip        , N_("The tooltip of the menu item"), N_("TOOLTIP") },
-	{ "icon"                 , 'i', 0, G_OPTION_ARG_STRING      , &icon           , N_("The icon of the menu item (filename or GTK stock ID)"), N_("ICON") },
-	{ "enabled"              , 'e', 0, G_OPTION_ARG_NONE        , &enabled        , N_("Whether the action is enabled"), NULL },
-	{ "command"              , 'c', 0, G_OPTION_ARG_FILENAME    , &command        , N_("The path of the command"), N_("PATH") },
-	{ "parameters"           , 'p', 0, G_OPTION_ARG_STRING      , &parameters     , N_("The parameters of the command"), N_("PARAMS") },
-	{ "match"                , 'm', 0, G_OPTION_ARG_STRING_ARRAY, &basenames_array, N_("A pattern to match selected files against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
-	{ "match-case"           , 'C', 0, G_OPTION_ARG_NONE        , &matchcase      , N_("The path of the command"), N_("PATH") },
-	{ "mimetypes"            , 'T', 0, G_OPTION_ARG_STRING_ARRAY, &mimetypes_array, N_("A pattern to match selected files' mimetype against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
-	{ "accept-files"         , 'f', 0, G_OPTION_ARG_NONE        , &isfile         , N_("Set it if the selection must only contain files"), NULL },
-	{ "accept-dirs"          , 'd', 0, G_OPTION_ARG_NONE        , &isdir          , N_("Set it if the selection must only contain folders. Specify both '--isfile' and '--isdir' options is selection can contain both types of items"), NULL },
-	{ "accept-multiple-files", 'M', 0, G_OPTION_ARG_NONE        , &accept_multiple, N_("Set it if the selection can have several items"), NULL },
-	{ "scheme"               , 's', 0, G_OPTION_ARG_STRING_ARRAY, &schemes_array  , N_("A valid GVFS scheme where the selected files should be located (you must set one option for each scheme you need)"), N_("SCHEME") },
+	{ "label"                , 'l', 0, G_OPTION_ARG_STRING      , &label,
+			N_("The label of the menu item (mandatory)"), N_("<STRING>") },
+	{ "tooltip"              , 't', 0, G_OPTION_ARG_STRING      , &tooltip,
+			N_("The tooltip of the menu item"), N_("<STRING>") },
+	{ "icon"                 , 'i', 0, G_OPTION_ARG_STRING      , &icon,
+			N_("The icon of the menu item (filename or GTK stock ID)"), N_("<PATH|NAME>") },
+	{ "enabled"              , 'e', 0, G_OPTION_ARG_NONE        , &enabled,
+			N_("Whether the action is enabled"), NULL },
+	{ "command"              , 'c', 0, G_OPTION_ARG_FILENAME    , &command,
+			N_("The path of the command"), N_("<PATH>") },
+	{ "parameters"           , 'p', 0, G_OPTION_ARG_STRING      , &parameters,
+			N_("The parameters of the command"), N_("<PARAMETERS>") },
+	{ "match"                , 'm', 0, G_OPTION_ARG_STRING_ARRAY, &basenames_array,
+			N_("A pattern to match selected files against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
+	{ "match-case"           , 'C', 0, G_OPTION_ARG_NONE        , &matchcase,
+			N_("Set it if the previous patterns are case sensitive"), NULL },
+	{ "mimetypes"            , 'T', 0, G_OPTION_ARG_STRING_ARRAY, &mimetypes_array,
+			N_("A pattern to match selected files' mimetype against. May include wildcards (* or ?) (you must set one option for each pattern you need)"), N_("EXPR") },
+	{ "accept-files"         , 'f', 0, G_OPTION_ARG_NONE        , &isfile,
+			N_("Set it if the selection must only contain files"), NULL },
+	{ "accept-dirs"          , 'd', 0, G_OPTION_ARG_NONE        , &isdir,
+			N_("Set it if the selection must only contain folders. Specify both '--isfile' and '--isdir' options is selection can contain both types of items"), NULL },
+	{ "accept-multiple-files", 'M', 0, G_OPTION_ARG_NONE        , &accept_multiple,
+			N_("Set it if the selection can have several items"), NULL },
+	{ "scheme"               , 's', 0, G_OPTION_ARG_STRING_ARRAY, &schemes_array,
+			N_("A valid GIO scheme where the selected files should be located (you must set one option for each scheme you need)"), N_("SCHEME") },
 	{ NULL }
 };
 
 static GOptionEntry output_entries[] = {
 
-	{ "output-gconf"         , 'g', 0, G_OPTION_ARG_NONE        , &output_gconf   , N_("Directly import the newly created action in GConf configuration"), NULL },
-	{ "output-dir"           , 'o', 0, G_OPTION_ARG_FILENAME    , &output_dir     , N_("The folder where to write the new action as a GConf dump output [default: stdout]"), N_("DIR") },
+	{ "output-gconf"         , 'g', 0, G_OPTION_ARG_NONE        , &output_gconf,
+			N_("Directly import the newly created action in GConf configuration"), NULL },
+	{ "output-dir"           , 'o', 0, G_OPTION_ARG_FILENAME    , &output_dir,
+			N_("The folder where to write the new action as a GConf dump output [default: stdout]"), N_("DIR") },
+	{ NULL }
+};
+
+static GOptionEntry misc_entries[] = {
+
+	{ "version"              , 'v', 0, G_OPTION_ARG_NONE        , &version,
+			N_("Output the version number"), NULL },
 	{ NULL }
 };
 
 static GOptionContext *init_options( void );
 static NAObjectAction *get_action_from_cmdline( void );
+static void            print_version( void );
 static gboolean        write_to_gconf( NAObjectAction *action, GSList **msg );
 static void            exit_with_usage( void );
 
@@ -120,6 +145,11 @@ main( int argc, char** argv )
 		exit_with_usage();
 	}
 
+	if( version ){
+		print_version();
+		exit( status );
+	}
+
 	if( !label || !g_utf8_strlen( label, -1 )){
 		g_printerr( _( "Error: an action label is mandatory.\n" ));
 		exit_with_usage();
@@ -170,6 +200,7 @@ init_options( void )
 	GOptionContext *context;
 	gchar* description;
 	GOptionGroup *output_group;
+	GOptionGroup *misc_group;
 
 	context = g_option_context_new( _( "Define a new action.\n\n"
 			"  The created action defaults to be written to stdout.\n"
@@ -197,11 +228,14 @@ init_options( void )
 
 	output_group = g_option_group_new(
 			"output", _( "Output of the program" ), _( "Choose where the program creates the action" ), NULL, NULL );
-
 	g_option_group_add_entries( output_group, output_entries );
-
 	g_option_context_add_group( context, output_group );
 
+	misc_group = g_option_group_new(
+			"misc", _( "Miscellaneous options" ), _( "Miscellaneous options" ), NULL, NULL );
+	g_option_group_add_entries( misc_group, misc_entries );
+	g_option_context_add_group( context, misc_group );
+
 	return( context );
 }
 
@@ -269,6 +303,29 @@ get_action_from_cmdline( void )
 }
 
 /*
+ * 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.
+ */
+static void
+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" );
+}
+
+/*
  * initialize GConf as an I/O provider
  * then writes the action
  */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]