[nautilus-actions] Add %p (port number) and %R (list of URIs) new parameters



commit 7b6464574ec0c890d2afb8706aecc5f6b4447cd7
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Jul 30 00:35:37 2009 +0200

    Add %p (port number) and %R (list of URIs) new parameters

 ChangeLog                                |    8 ++++
 TODO                                     |    5 ++
 src/common/na-action-profile.c           |   52 ++++++++++++++++++++------
 src/common/na-xml-names.h                |    2 +-
 src/nact/nact-icommand-tab.c             |   44 ++++++++++++++++-----
 src/nact/nautilus-actions-config-tool.ui |   60 ++++++++++++++++++++---------
 6 files changed, 128 insertions(+), 43 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0d3d187..99324c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-07-30 Pierre Wieser <pwieser trychlos org>
+
+	* src/common/na-action-profile.c:
+	* src/common/na-xml-names.h:
+	* src/nact/nact-icommand-tab.c:
+	* src/nact/nautilus-actions-config-tool.ui:
+	Add %p (port number) and %R (list of URIs) parameters.
+
 2009-07-29 Pierre Wieser <pwieser trychlos org>
 
 	* exports/nautilus-actions.schema.in:
diff --git a/TODO b/TODO
index 08acacd..1056b2b 100644
--- a/TODO
+++ b/TODO
@@ -24,3 +24,8 @@
 
 - NAUTILUS_ACTIONS_CONFIG_GCONF_BASEDIR has nothing to do in configure.ac
   (not a configuration variable)
+
+- changing conditions in IConditionsTab should trigger an update of the
+  example label
+
+- use GtkUIManager
diff --git a/src/common/na-action-profile.c b/src/common/na-action-profile.c
index 911c682..ae0d785 100644
--- a/src/common/na-action-profile.c
+++ b/src/common/na-action-profile.c
@@ -1267,10 +1267,18 @@ na_action_profile_is_candidate( const NAActionProfile *profile, GList* files )
  * %h : hostname of the (first) URI
  * %m : list of the basename of the selected files/directories separated by space.
  * %M : list of the selected files/directories with their complete path separated by space.
+ * %p : port number from the (first) URI
+ * %R : space-separated list of URIs
  * %s : scheme of the (first) URI
- * %u : (first)  URI
+ * %u : (first) URI
  * %U : username of the (first) URI
  * %% : a percent sign
+ *
+ * Adding a parameter requires updating of :
+ * - src/common/na/na-action-profile.c:na_action_profile_parse_parameters()
+ * - src/common/na/na-xml-names.h
+ * - src/nact/nact-icommand-tab.c:parse_parameters()
+ * - src/nact/nautilus-actions-config-tool.ui:LegendDialog
  */
 gchar *
 na_action_profile_parse_parameters( const NAActionProfile *profile, GList* files )
@@ -1287,7 +1295,8 @@ na_action_profile_parse_parameters( const NAActionProfile *profile, GList* files
 	gchar *filename = NULL;
 	gchar *hostname = NULL;
 	gchar *username = NULL;
-	GString *basename_list, *pathname_list;
+	gint port_number = 0;
+	GString *basename_list, *pathname_list, *uris_list;
 	gchar *tmp;
 	NAGnomeVFSURI *vfs;
 
@@ -1296,6 +1305,7 @@ na_action_profile_parse_parameters( const NAActionProfile *profile, GList* files
 	string = g_string_new( "" );
 	basename_list = g_string_new( "" );
 	pathname_list = g_string_new( "" );
+	uris_list = g_string_new( "" );
 	first = TRUE;
 
 	for( ifi = files ; ifi ; ifi = ifi->next ){
@@ -1305,24 +1315,24 @@ na_action_profile_parse_parameters( const NAActionProfile *profile, GList* files
 		ipath = g_file_get_path( iloc );
 		ibname = g_file_get_basename( iloc );
 
-		vfs = g_new0( NAGnomeVFSURI, 1 );
-		na_gnome_vfs_uri_parse( vfs, iuri );
-
 		if( first ){
 
+			vfs = g_new0( NAGnomeVFSURI, 1 );
+			na_gnome_vfs_uri_parse( vfs, iuri );
+
 			uri = g_strdup( iuri );
 			dirname = g_path_get_dirname( ipath );
 			scheme = nautilus_file_info_get_uri_scheme(( NautilusFileInfo * ) ifi->data );
 			filename = g_strdup( ibname );
-
 			hostname = g_strdup( vfs->host_name );
 			username = g_strdup( vfs->user_name );
+			port_number = vfs->host_port;
 
 			first = FALSE;
+			na_gnome_vfs_uri_free( vfs );
 		}
 
 		tmp = g_shell_quote( ibname );
-
 		g_string_append_printf( basename_list, " %s", tmp );
 		g_free( tmp );
 
@@ -1330,7 +1340,10 @@ na_action_profile_parse_parameters( const NAActionProfile *profile, GList* files
 		g_string_append_printf( pathname_list, " %s", tmp );
 		g_free( tmp );
 
-		na_gnome_vfs_uri_free( vfs );
+		tmp = g_shell_quote( iuri );
+		g_string_append_printf( uris_list, " %s", tmp );
+		g_free( tmp );
+
 		g_free( ibname );
 		g_free( ipath );
 		g_object_unref( iloc );
@@ -1361,7 +1374,7 @@ na_action_profile_parse_parameters( const NAActionProfile *profile, GList* files
 				g_free( tmp );
 				break;
 
-			/* hostname of the (first) GVfs URI
+			/* hostname of the (first) URI
 			 */
 			case 'h':
 				string = g_string_append( string, hostname );
@@ -1379,19 +1392,33 @@ na_action_profile_parse_parameters( const NAActionProfile *profile, GList* files
 				string = g_string_append( string, pathname_list->str );
 				break;
 
-			/* scheme of the (first) GVfs URI
+			/* port number of the (first) URI
+			 */
+			case 'p':
+				if( port_number > 0 ){
+					g_string_append_printf( string, "%d", port_number );
+				}
+				break;
+
+			/* list of URIs
+			 */
+			case 'R':
+				string = g_string_append( string, uris_list->str );
+				break;
+
+			/* scheme of the (first) URI
 			 */
 			case 's':
 				string = g_string_append( string, scheme );
 				break;
 
-			/* GVfs URI of the first item
+			/* URI of the first item
 			 */
 			case 'u':
 				string = g_string_append( string, uri );
 				break;
 
-			/* username of the (first) GVfs URI
+			/* username of the (first) URI
 			 */
 			case 'U':
 				string = g_string_append( string, username );
@@ -1416,6 +1443,7 @@ na_action_profile_parse_parameters( const NAActionProfile *profile, GList* files
 	g_free( hostname );
 	g_free( username );
 	g_free( iter );
+	g_string_free( uris_list, TRUE );
 	g_string_free( basename_list, TRUE );
 	g_string_free( pathname_list, TRUE );
 
diff --git a/src/common/na-xml-names.h b/src/common/na-xml-names.h
index e1abc94..edd1513 100644
--- a/src/common/na-xml-names.h
+++ b/src/common/na-xml-names.h
@@ -109,7 +109,7 @@ enum {
 #define ACTION_PATH_DESC_SHORT		_("The path of the command")
 #define ACTION_PATH_DESC_LONG		_("The path of the command to start when the user select the menu item in the Nautilus popup menu")
 #define ACTION_PARAMETERS_DESC_SHORT _("The parameters of the command")
-#define ACTION_PARAMETERS_DESC_LONG	_("The parameters of the command to start when the user selects the menu item in the Nautilus popup menu.\n\nThe parameters can contain some special tokens which are replaced by Nautilus information before starting the command:\n\n%d: base folder of the selected file(s)\n%f: the name of the selected file or the first one if many are selected\n%h: hostname of the URI\n%m: space-separated list of the basenames of the selected file(s)/folder(s)\n%M: space-separated list of the selected file(s)/folder(s), with their full paths\n%s: scheme of the URI\n%u: URI\n%U: username of the URI\n%%: a percent sign")
+#define ACTION_PARAMETERS_DESC_LONG	_("The parameters of the command to start when the user selects the menu item in the Nautilus popup menu.\n\nThe parameters can contain some special tokens which are replaced by Nautilus information before starting the command:\n\n%d: base folder of the selected file(s)\n%f: the name of the selected file or the first one if many are selected\n%h: hostname of the URI\n%m: space-separated list of the basenames of the selected file(s)/folder(s)\n%M: space-separated list of the selected file(s)/folder(s), with their full paths\n%p: port number of the first URI\n%R: space-separated list of selected URIs\n%s: scheme of the URI\n%u: URI\n%U: username of the URI\n%%: a percent sign")
 #define ACTION_BASENAMES_DESC_SHORT	_("The list of pattern to match the selected file(s)/folder(s)")
 #define ACTION_BASENAMES_DESC_LONG	_("A list of strings with joker '*' or '?' to match the name of the selected file(s)/folder(s). Each selected items must match at least one of the filename patterns for the action to appear")
 #define ACTION_MATCHCASE_DESC_SHORT _("'true' if the filename patterns have to be case sensitive, 'false' otherwise")
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index 2f83736..8b4c97a 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -504,14 +504,16 @@ update_example_label( NactWindow *window )
 /*
  * Valid parameters :
  *
- * %d : base dir of the selected file(s)/folder(s)
- * %f : the name of the selected file/folder or the 1st one if many are selected
- * %h : hostname of the GVfs URI
+ * %d : base dir of the (first) selected file(s)/folder(s)
+ * %f : the name of the (firstà selected file/folder
+ * %h : hostname of the (first) URI
  * %m : list of the basename of the selected files/directories separated by space.
  * %M : list of the selected files/directories with their complete path separated by space.
- * %s : scheme of the GVfs URI
- * %u : GVfs URI
- * %U : username of the GVfs URI
+ * %p : port number of the (first) URI
+ * %R : space-separated list of selected URIs
+ * %s : scheme of the (first) URI
+ * %u : (first) URI
+ * %U : username of the (first) URI
  * %% : a percent sign
  */
 static gchar *
@@ -528,9 +530,15 @@ parse_parameters( NactWindow *window )
 	gchar* ex_host_default = _( "test.example.net" );
 	gchar* ex_one_file = _( "file.txt" );
 	gchar* ex_one_dir = _( "folder" );
+	gchar* ex_port_default = _( "8080" );
 	gchar* ex_one = NULL;
 	gchar* ex_list = NULL;
 	gchar* ex_path_list = NULL;
+	gchar* ex_uri_file1 = _( "file:///path/to/file1.text" );
+	gchar* ex_uri_file2 = _( "file:///path/to/file2.text" );
+	gchar* ex_uri_folder1 = _( "file:///path/to/a/dir" );
+	gchar* ex_uri_folder2 = _( "file:///path/to/another/dir" );
+	gchar* ex_uri_list = NULL;
 	gchar* ex_scheme;
 	gchar* ex_host;
 
@@ -559,23 +567,28 @@ parse_parameters( NactWindow *window )
 			ex_one = ex_files[0];
 			ex_list = na_utils_gstring_joinv( NULL, " ", ex_mixed );
 			ex_path_list = na_utils_gstring_joinv( start, separator, ex_mixed );
+			ex_uri_list = g_strjoin( " ", ex_uri_file1, ex_uri_folder1, NULL );
 
 		} else if( is_dir ){
 			ex_one = ex_dirs[0];
 			ex_list = na_utils_gstring_joinv( NULL, " ", ex_dirs );
 			ex_path_list = na_utils_gstring_joinv( start, separator, ex_dirs );
+			ex_uri_list = g_strjoin( " ", ex_uri_folder1, ex_uri_folder2, NULL );
 
 		} else if( is_file ){
 			ex_one = ex_files[0];
 			ex_list = na_utils_gstring_joinv( NULL, " ", ex_files );
 			ex_path_list = na_utils_gstring_joinv( start, separator, ex_files );
+			ex_uri_list = g_strjoin( " ", ex_uri_file1, ex_uri_file2, NULL );
 		}
 	} else {
 		if( is_dir && !is_file ){
 			ex_one = ex_one_dir;
+			ex_uri_list = g_strdup( ex_uri_folder1 );
 
 		} else {
 			ex_one = ex_one_file;
+			ex_uri_list = g_strdup( ex_uri_file1 );
 		}
 		ex_list = g_strdup( ex_one );
 		ex_path_list = g_strjoin( "/", ex_path, ex_one, NULL );
@@ -605,15 +618,15 @@ parse_parameters( NactWindow *window )
 		tmp_string = g_string_append_len( tmp_string, old_iter, strlen( old_iter ) - strlen( iter ));
 		switch( iter[1] ){
 
-			case 'd': /* base dir of the selected file(s)/folder(s) */
+			case 'd': /* base dir of the (first) selected file(s)/folder(s) */
 				tmp_string = g_string_append( tmp_string, ex_path );
 				break;
 
-			case 'f': /* the basename of the selected file/folder or the 1st one if many are selected */
+			case 'f': /* the basename of the (first) selected file/folder */
 				tmp_string = g_string_append( tmp_string, ex_one );
 				break;
 
-			case 'h': /* hostname of the GVfs URI */
+			case 'h': /* hostname of the (first) URI */
 				tmp_string = g_string_append( tmp_string, ex_host );
 				break;
 
@@ -625,11 +638,19 @@ parse_parameters( NactWindow *window )
 				tmp_string = g_string_append( tmp_string, ex_path_list );
 				break;
 
-			case 's': /* scheme of the GVfs URI */
+			case 'p': /* port number of the (first) URI */
+				tmp_string = g_string_append( tmp_string, ex_port_default );
+				break;
+
+			case 'R': /* space-separated list of selected URIs */
+				tmp_string = g_string_append( tmp_string, ex_uri_list );
+				break;
+
+			case 's': /* scheme of the (first) URI */
 				tmp_string = g_string_append( tmp_string, ex_scheme );
 				break;
 
-			case 'u': /* GVfs URI */
+			case 'u': /* (first) URI */
 				tmp = g_strjoin( NULL, ex_scheme, "://", ex_path, "/", ex_one, NULL );
 				tmp_string = g_string_append( tmp_string, tmp );
 				g_free( tmp );
@@ -652,6 +673,7 @@ parse_parameters( NactWindow *window )
 
 	g_free( ex_list );
 	g_free( ex_path_list );
+	g_free( ex_uri_list );
 	g_free( iter );
 
 	return( g_string_free( tmp_string, FALSE ));
diff --git a/src/nact/nautilus-actions-config-tool.ui b/src/nact/nautilus-actions-config-tool.ui
index 6155dd8..47a56f4 100644
--- a/src/nact/nautilus-actions-config-tool.ui
+++ b/src/nact/nautilus-actions-config-tool.ui
@@ -884,10 +884,10 @@
       <object class="GtkFileChooserWidget" id="filechooserwidget1">
         <property name="visible">True</property>
         <property name="orientation">vertical</property>
-        <property name="local_only">False</property>
         <property name="select_multiple">True</property>
-        <property name="use_preview_label">False</property>
         <property name="preview_widget_active">False</property>
+        <property name="use_preview_label">False</property>
+        <property name="local_only">False</property>
       </object>
     </child>
     <child>
@@ -970,10 +970,10 @@ to extend a selection.</property>
           <object class="GtkFileChooserWidget" id="ExportFolderChooser">
             <property name="visible">True</property>
             <property name="orientation">vertical</property>
-            <property name="local_only">False</property>
-            <property name="use_preview_label">False</property>
             <property name="preview_widget_active">False</property>
             <property name="action">select-folder</property>
+            <property name="use_preview_label">False</property>
+            <property name="local_only">False</property>
           </object>
           <packing>
             <property name="position">0</property>
@@ -1259,7 +1259,7 @@ The exported file may later be imported via :
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
-                <property name="label" translatable="yes">&lt;b&gt;%d&lt;/b&gt;: base folder of the selected file(s)</property>
+                <property name="label" translatable="yes">&lt;b&gt;%d&lt;/b&gt;: base directory of the (first) selected file or folder</property>
                 <property name="use_markup">True</property>
                 <property name="wrap">True</property>
               </object>
@@ -1274,7 +1274,7 @@ The exported file may later be imported via :
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
-                <property name="label" translatable="yes">&lt;b&gt;%f&lt;/b&gt;: the name of the selected file or the 1st one if many are selected</property>
+                <property name="label" translatable="yes">&lt;b&gt;%f&lt;/b&gt;: the name of the (first) selected file or folder</property>
                 <property name="use_markup">True</property>
                 <property name="wrap">True</property>
               </object>
@@ -1289,7 +1289,7 @@ The exported file may later be imported via :
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
-                <property name="label" translatable="yes">&lt;b&gt;%h&lt;/b&gt;: hostname of the URI</property>
+                <property name="label" translatable="yes">&lt;b&gt;%h&lt;/b&gt;: hostname of the (first) URI</property>
                 <property name="use_markup">True</property>
                 <property name="wrap">True</property>
               </object>
@@ -1320,7 +1320,7 @@ file(s)/folder(s)</property>
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
-                <property name="label" translatable="yes">&lt;b&gt;%M&lt;/b&gt;: space-separated list of the selected file(s)/folder(s) with their full paths</property>
+                <property name="label" translatable="yes">&lt;b&gt;%M&lt;/b&gt;: space-separated list of the full pathanmes of the selected file(s) or folder(s)</property>
                 <property name="use_markup">True</property>
                 <property name="wrap">True</property>
               </object>
@@ -1331,18 +1331,40 @@ file(s)/folder(s)</property>
               </packing>
             </child>
             <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">&lt;b&gt;%p&lt;/b&gt;: port number of the (first) selected URI</property>
+                <property name="use_markup">True</property>
+              </object>
+              <packing>
+                <property name="position">5</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">&lt;b&gt;%R&lt;/b&gt;: space-separated list of selected URIs</property>
+                <property name="use_markup">True</property>
+              </object>
+              <packing>
+                <property name="position">6</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkLabel" id="label16">
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
-                <property name="label" translatable="yes">&lt;b&gt;%s&lt;/b&gt;: scheme of the URI</property>
+                <property name="label" translatable="yes">&lt;b&gt;%s&lt;/b&gt;: scheme of the (first) URI</property>
                 <property name="use_markup">True</property>
                 <property name="wrap">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">5</property>
+                <property name="position">7</property>
               </packing>
             </child>
             <child>
@@ -1350,14 +1372,14 @@ file(s)/folder(s)</property>
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
-                <property name="label" translatable="yes">&lt;b&gt;%u&lt;/b&gt;: URI</property>
+                <property name="label" translatable="yes">&lt;b&gt;%u&lt;/b&gt;: (first) URI</property>
                 <property name="use_markup">True</property>
                 <property name="wrap">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">6</property>
+                <property name="position">8</property>
               </packing>
             </child>
             <child>
@@ -1365,14 +1387,14 @@ file(s)/folder(s)</property>
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="yalign">0</property>
-                <property name="label" translatable="yes">&lt;b&gt;%U&lt;/b&gt;: username of the URI</property>
+                <property name="label" translatable="yes">&lt;b&gt;%U&lt;/b&gt;: username of the (first) URI</property>
                 <property name="use_markup">True</property>
                 <property name="wrap">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">7</property>
+                <property name="position">9</property>
               </packing>
             </child>
             <child>
@@ -1387,7 +1409,7 @@ file(s)/folder(s)</property>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">8</property>
+                <property name="position">10</property>
               </packing>
             </child>
           </object>
@@ -1400,16 +1422,16 @@ file(s)/folder(s)</property>
   </object>
   <object class="GtkSizeGroup" id="CommandLabelSizeGroup">
     <widgets>
-      <widget name="ProfileLabelLabel"/>
-      <widget name="CommandPathLabel"/>
-      <widget name="CommandParametersLabel"/>
       <widget name="CommandExamplePreLabel"/>
+      <widget name="CommandParametersLabel"/>
+      <widget name="CommandPathLabel"/>
+      <widget name="ProfileLabelLabel"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup" id="CommandButtonSizeGroup">
     <widgets>
-      <widget name="CommandPathButton"/>
       <widget name="CommandLegendButton"/>
+      <widget name="CommandPathButton"/>
     </widgets>
   </object>
 </interface>



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