summaryrefslogtreecommitdiff
path: root/src/test-server.c
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-11-20 15:57:29 +0100
committerinfirit <[email protected]>2014-11-22 21:32:47 +0100
commit0c3107bbc42745c2e45530a8d43ea7fccd881e6f (patch)
treee581355d77464632e50e2de673a62a795810b90b /src/test-server.c
parent02cd7f18c806194eabd1dee69d28b5e2f2b51344 (diff)
downloadengrampa-0c3107bbc42745c2e45530a8d43ea7fccd881e6f.tar.bz2
engrampa-0c3107bbc42745c2e45530a8d43ea7fccd881e6f.tar.xz
Added a D-BUS service to create and extract archives.
Initial commits from FR: f998fd8e33a08d686a1071db87d21f4a83963d99 4078d1a9e5ddae3357302791432fc61d82ff37e4 58c55b06f30014326f27bdf94c406ceee0897731 Improvements and fixes from FR: D-Bus service: added GetSupportedTypes method ace4f31c586641fcf7ad1de165cd7f27b5a371c1 1399b9a84b0d4f4a5015066b0d7cec7e048d59dc From: Paolo Bacchilega <[email protected]>
Diffstat (limited to 'src/test-server.c')
-rw-r--r--src/test-server.c263
1 files changed, 263 insertions, 0 deletions
diff --git a/src/test-server.c b/src/test-server.c
new file mode 100644
index 0000000..a9dcb5f
--- /dev/null
+++ b/src/test-server.c
@@ -0,0 +1,263 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * Engrampa
+ *
+ * Copyright (C) 2010 The Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <gio/gio.h>
+
+
+GMainLoop *loop;
+
+
+static void
+engrampa_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
+engrampa_addtoarchive_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);
+ }
+
+ if (values != NULL)
+ g_variant_unref (values);
+ g_object_unref (proxy);
+
+ g_main_loop_quit (loop);
+}
+
+
+static void
+on_signal (GDBusProxy *proxy,
+ char *sender_name,
+ char *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ if (g_strcmp0 (signal_name, "Progress") == 0) {
+ double fraction;
+ char *details;
+
+ g_variant_get (parameters, "(ds)", &fraction, &details);
+ g_print ("Progress: %f (%s)\n", fraction, details);
+
+ g_free (details);
+ }
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection != NULL) {
+ GDBusProxy *proxy;
+
+ proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.mate.Engrampa",
+ "/org/mate/Engrampa",
+ "org.mate.ArchiveManager",
+ NULL,
+ &error);
+
+ if (proxy != NULL) {
+
+ g_signal_connect (proxy,
+ "g-signal",
+ G_CALLBACK (on_signal),
+ NULL);
+
+#if 0
+ /* -- GetSupportedTypes -- */
+
+ g_dbus_proxy_call (proxy,
+ "GetSupportedTypes",
+ g_variant_new ("(s)", "create"),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ engrampa_getsupportedtypes_ready_cb,
+ NULL);
+#endif
+
+ /* -- AddToArchive -- */
+
+ char *archive;
+ char **files;
+
+ archive = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre.tar.gz");
+ files = g_new0 (char *, 2);
+ files[0] = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre");
+ files[1] = NULL;
+
+ g_dbus_proxy_call (proxy,
+ "AddToArchive",
+ g_variant_new ("(s^asb)",
+ archive,
+ files,
+ FALSE),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ engrampa_addtoarchive_ready_cb,
+ NULL);
+
+ g_free (archive);
+ g_strfreev (files);
+
+#if 0
+
+ /* -- Compress -- */
+
+ char **files;
+ char *destination;
+
+ files = g_new0 (char *, 2);
+ files[0] = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre");
+ files[1] = NULL;
+ destination = g_strdup ("file:///home/paolo/Scrivania");
+
+ g_dbus_proxy_call (proxy,
+ "Compress",
+ g_variant_new ("(^assb)",
+ files,
+ destination,
+ TRUE),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ engrampa_addtoarchive_ready_cb,
+ NULL);
+
+ g_strfreev (files);
+ g_free (destination);
+
+ /* -- Extract -- */
+
+ g_dbus_proxy_call (proxy,
+ "Extract",
+ g_variant_new ("(ssb)",
+ "file:///home/paolo/Scrivania/test.tar.gz",
+ "file:///home/paolo/Scrivania",
+ TRUE),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ engrampa_addtoarchive_ready_cb,
+ NULL);
+
+ /* -- ExtractHere -- */
+
+ g_dbus_proxy_call (proxy,
+ "ExtractHere",
+ g_variant_new ("(sb)",
+ "file:///home/paolo/Scrivania/test.tar.gz",
+ TRUE),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ engrampa_addtoarchive_ready_cb,
+ NULL);
+
+#endif
+
+ }
+ }
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+
+ return 0;
+}