[file-roller] D-Bus service: added GetSupportedTypes method



commit ace4f31c586641fcf7ad1de165cd7f27b5a371c1
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Nov 29 20:41:42 2010 +0100

    D-Bus service: added GetSupportedTypes method

 src/server.c      |   76 +++++++++++++++++++++++++++++++++++----
 src/test-server.c |  103 ++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 163 insertions(+), 16 deletions(-)
---
diff --git a/src/server.c b/src/server.c
index 9e3e2a2..4d8376b 100644
--- a/src/server.c
+++ b/src/server.c
@@ -36,7 +36,6 @@ static const char introspection_xml[] =
 	"<node>"
 	"  <interface name='org.gnome.ArchiveManager'>"
 
-#if 0
 	/**
 	 * GetSuppertedTypes:
 	 *
@@ -45,21 +44,25 @@ static const char introspection_xml[] =
 	 * Input arguments:
 	 *
 	 * @action:
-	 *   Can be one of the following values: create, extract
+	 *   Can be one of the following values:
+	 *   *) create: create an archive that can contain many files.
+	 *   *) create_single_file: create an archive that can contain a single file.
+	 *   *) extract: extract the content of an archive.
 	 *
 	 * Output arguments:
 	 *
 	 * @types:
-	 *   The supported archive types described as an array of tuples, where
-	 *   the tuple is composed by: the mime type, the default extension,
-	 *   a human readable description.
+	 *   The supported archive types described as an array of hash tables,
+	 *   where each hash table has the following keys:
+	 *   *) mime-type: the mime type relative to the archive type.
+	 *   *) default-extension: the extension to use for newly created archives.
+	 *   *) description: a human readable description of the archive type.
 	 */
 
 	"    <method name='GetSuppertedTypes'>"
 	"      <arg name='action' type='s' direction='in'/>"
-	"      <arg name='types' type='a(sss)' direction='out'/>"
+	"      <arg name='types' type='aa{ss}' direction='out'/>"
 	"    </method>"
-#endif
 
 	/**
 	 * AddToArchive:
@@ -73,6 +76,8 @@ static const char introspection_xml[] =
 	 *   The archive URI.
 	 * @files:
 	 *   The files to add to the archive, as an array of URIs.
+	 * @use_progress_dialog:
+	 *   Whether to show the progress dialog.
 	 */
 
 	"    <method name='AddToArchive'>"
@@ -97,6 +102,8 @@ static const char introspection_xml[] =
 	 * @destination:
 	 *   An optional destination, if not specified the folder of the first
 	 *   file in @files is used.
+	 * @use_progress_dialog:
+	 *   Whether to show the progress dialog.
 	 */
 
 	"    <method name='Compress'>"
@@ -116,6 +123,8 @@ static const char introspection_xml[] =
 	 *   The archive to extract.
 	 * @destination:
 	 *   The location where to extract the archive.
+	 * @use_progress_dialog:
+	 *   Whether to show the progress dialog.
 	 */
 
 	"    <method name='Extract'>"
@@ -133,6 +142,8 @@ static const char introspection_xml[] =
 	 *
 	 * @archive:
 	 *   The archive to extract.
+	 * @use_progress_dialog:
+	 *   Whether to show the progress dialog.
 	 */
 
 	"    <method name='ExtractHere'>"
@@ -151,6 +162,7 @@ static const char introspection_xml[] =
 	 * @details:
 	 *   text message that describes the current operation.
 	 */
+
 	"    <signal name='Progress'>"
 	"      <arg name='fraction' type='d'/>"
 	"      <arg name='details' type='s'/>"
@@ -195,6 +207,8 @@ window_progress_cb (FrWindow *window,
 						      fraction,
 						      details),
 				       NULL);
+
+	return TRUE;
 }
 
 
@@ -211,7 +225,53 @@ handle_method_call (GDBusConnection       *connection,
 	update_registered_commands_capabilities ();
 
 	if (g_strcmp0 (method_name, "GetSuppertedTypes") == 0) {
-		/* TODO */
+		char *action;
+		int  *supported_types = NULL;
+
+		g_variant_get (parameters, "(s)", &action);
+
+		if (g_strcmp0 (action, "create") == 0) {
+			supported_types = save_type;
+		}
+		else if (g_strcmp0 (action, "create_single_file") == 0) {
+			supported_types = single_file_save_type;
+		}
+		else if (g_strcmp0 (action, "extract") == 0) {
+			supported_types = open_type;
+		}
+
+		if (supported_types == NULL) {
+			g_dbus_method_invocation_return_error (invocation,
+							       G_IO_ERROR,
+							       G_IO_ERROR_INVALID_ARGUMENT,
+							       "Action not valid %s, valid values are: create, create_single_file, extract",
+							       action);
+		}
+		else {
+			GVariantBuilder builder;
+			int             i;
+
+			g_variant_builder_init (&builder, G_VARIANT_TYPE ("(aa{ss})"));
+			g_variant_builder_open (&builder, G_VARIANT_TYPE ("aa{ss}"));
+			for (i = 0; supported_types[i] != -1; i++) {
+				g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{ss}"));
+				g_variant_builder_add (&builder, "{ss}",
+						       "mime-type",
+						       mime_type_desc[supported_types[i]].mime_type);
+				g_variant_builder_add (&builder, "{ss}",
+						       "default-extension",
+						       mime_type_desc[supported_types[i]].default_ext);
+				g_variant_builder_add (&builder, "{ss}",
+						       "description",
+						       _(mime_type_desc[supported_types[i]].name));
+				g_variant_builder_close (&builder);
+			}
+			g_variant_builder_close (&builder);
+
+			g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
+		}
+
+		g_free (action);
 	}
 	else if (g_strcmp0 (method_name, "AddToArchive") == 0) {
 		char       *archive;
diff --git a/src/test-server.c b/src/test-server.c
index 4d499df..813705f 100644
--- a/src/test-server.c
+++ b/src/test-server.c
@@ -27,6 +27,70 @@ GMainLoop *loop;
 
 
 static void
+fileroller_getsupportedtypes_ready_cb (GObject      *source_object,
+		  	  	       GAsyncResult *res,
+		  	  	       gpointer      user_data)
+{
+	GDBusProxy *proxy;
+	GVariant   *values;
+	GError     *error = NULL;
+
+	proxy = G_DBUS_PROXY (source_object);
+	values = g_dbus_proxy_call_finish (proxy, res, &error);
+	if (values == NULL) {
+		g_error ("%s\n", error->message);
+		g_clear_error (&error);
+	}
+	else {
+		GVariantIter  argument_iter;
+		GVariant     *array_of_types;
+		GVariantIter  type_iter;
+		GVariant     *supported_type;
+		int           n = 0;
+
+		g_variant_iter_init (&argument_iter, values);
+		array_of_types = g_variant_iter_next_value (&argument_iter);
+
+		g_variant_iter_init (&type_iter, array_of_types);
+		while ((supported_type = g_variant_iter_next_value (&type_iter))) {
+			char         *mime_type = NULL;
+			char         *default_ext = NULL;
+			char         *description = NULL;
+			char         *key;
+			char         *value;
+			GVariantIter  value_iter;
+
+			g_variant_iter_init (&value_iter, supported_type);
+			while (g_variant_iter_next (&value_iter, "{ss}", &key, &value)) {
+				if (g_strcmp0 (key, "mime-type") == 0)
+					mime_type = g_strdup (value);
+				else if (g_strcmp0 (key, "default-extension") == 0)
+					default_ext = g_strdup (value);
+				else if (g_strcmp0 (key, "description") == 0)
+					description = g_strdup (value);
+
+				g_free (key);
+				g_free (value);
+			}
+
+			n++;
+			g_print ("%d)\tmime-type: %s\n\tdefault-extension: %s\n\tdescription: %s\n", n, mime_type, default_ext, description);
+
+			g_free (description);
+			g_free (default_ext);
+			g_free (mime_type);
+			g_variant_unref (supported_type);
+		}
+
+		g_variant_unref (array_of_types);
+	}
+
+	g_object_unref (proxy);
+	g_main_loop_quit (loop);
+}
+
+
+static void
 fileroller_addtoarchive_ready_cb (GObject      *source_object,
 				  GAsyncResult *res,
 				  gpointer      user_data)
@@ -97,6 +161,19 @@ main (int argc, char *argv[])
 			                  G_CALLBACK (on_signal),
 			                  NULL);
 
+#if 0
+			/* -- GetSuppertedTypes -- */
+
+			g_dbus_proxy_call (proxy,
+					   "GetSuppertedTypes",
+					   g_variant_new ("(s)", "create"),
+					   G_DBUS_CALL_FLAGS_NONE,
+					   G_MAXINT,
+					   NULL,
+					   fileroller_getsupportedtypes_ready_cb,
+					   NULL);
+#endif
+
 			/* -- AddToArchive -- */
 
 			char  *archive;
@@ -109,7 +186,10 @@ main (int argc, char *argv[])
 
 			g_dbus_proxy_call (proxy,
 					   "AddToArchive",
-					   g_variant_new ("(s^asb)", archive, files, FALSE),
+					   g_variant_new ("(s^asb)",
+							  archive,
+							  files,
+							  FALSE),
 					   G_DBUS_CALL_FLAGS_NONE,
 					   G_MAXINT,
 					   NULL,
@@ -119,7 +199,9 @@ main (int argc, char *argv[])
 			g_free (archive);
 			g_strfreev (files);
 
-			/* -- Compress --
+#if 0
+
+			/* -- Compress -- */
 
 			char **files;
 			char  *destination;
@@ -131,7 +213,10 @@ main (int argc, char *argv[])
 
 			g_dbus_proxy_call (proxy,
 					   "Compress",
-					   g_variant_new ("(^assb)", files, destination, TRUE),
+					   g_variant_new ("(^assb)",
+							  files,
+							  destination,
+							  TRUE),
 					   G_DBUS_CALL_FLAGS_NONE,
 					   G_MAXINT,
 					   NULL,
@@ -140,9 +225,8 @@ main (int argc, char *argv[])
 
 			g_strfreev (files);
 			g_free (destination);
-			*/
 
-			/* -- Extract --
+			/* -- Extract -- */
 
 			g_dbus_proxy_call (proxy,
 					   "Extract",
@@ -155,9 +239,8 @@ main (int argc, char *argv[])
 					   NULL,
 					   fileroller_addtoarchive_ready_cb,
 					   NULL);
-			*/
 
-			/* -- ExtractHere --
+			/* -- ExtractHere -- */
 
 			g_dbus_proxy_call (proxy,
 					   "ExtractHere",
@@ -169,10 +252,14 @@ main (int argc, char *argv[])
 					   NULL,
 					   fileroller_addtoarchive_ready_cb,
 					   NULL);
-			*/
+
+#endif
+
 		}
 	}
 
 	loop = g_main_loop_new (NULL, FALSE);
 	g_main_loop_run (loop);
+
+	return 0;
 }



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