File: | test-server.c |
Warning: | line 106, column 3 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
2 | |
3 | /* |
4 | * Grapa |
5 | * |
6 | * Copyright (C) 2010 The Free Software Foundation, Inc. |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | #include <config.h> |
23 | #include <gio/gio.h> |
24 | |
25 | |
26 | GMainLoop *loop; |
27 | |
28 | |
29 | static void |
30 | grapa_getsupportedtypes_ready_cb (GObject *source_object, |
31 | GAsyncResult *res, |
32 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
33 | { |
34 | GDBusProxy *proxy; |
35 | GVariant *values; |
36 | GError *error = NULL((void*)0); |
37 | |
38 | proxy = G_DBUS_PROXY (source_object)((((GDBusProxy*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((source_object)), ((g_dbus_proxy_get_type ())))))); |
39 | values = g_dbus_proxy_call_finish (proxy, res, &error); |
40 | if (values == NULL((void*)0)) { |
41 | g_error ("%s\n", error->message); |
42 | g_clear_error (&error); |
43 | } |
44 | else { |
45 | GVariantIter argument_iter; |
46 | GVariant *array_of_types; |
47 | GVariantIter type_iter; |
48 | GVariant *supported_type; |
49 | int n = 0; |
50 | |
51 | g_variant_iter_init (&argument_iter, values); |
52 | array_of_types = g_variant_iter_next_value (&argument_iter); |
53 | |
54 | g_variant_iter_init (&type_iter, array_of_types); |
55 | while ((supported_type = g_variant_iter_next_value (&type_iter))) { |
56 | char *mime_type = NULL((void*)0); |
57 | char *default_ext = NULL((void*)0); |
58 | char *description = NULL((void*)0); |
59 | char *key; |
60 | char *value; |
61 | GVariantIter value_iter; |
62 | |
63 | g_variant_iter_init (&value_iter, supported_type); |
64 | while (g_variant_iter_next (&value_iter, "{ss}", &key, &value)) { |
65 | if (g_strcmp0 (key, "mime-type") == 0) |
66 | mime_type = g_strdup (value)g_strdup_inline (value); |
67 | else if (g_strcmp0 (key, "default-extension") == 0) |
68 | default_ext = g_strdup (value)g_strdup_inline (value); |
69 | else if (g_strcmp0 (key, "description") == 0) |
70 | description = g_strdup (value)g_strdup_inline (value); |
71 | |
72 | g_free (key); |
73 | g_free (value); |
74 | } |
75 | |
76 | n++; |
77 | g_print ("%d)\tmime-type: %s\n\tdefault-extension: %s\n\tdescription: %s\n", n, mime_type, default_ext, description); |
78 | |
79 | g_free (description); |
80 | g_free (default_ext); |
81 | g_free (mime_type); |
82 | g_variant_unref (supported_type); |
83 | } |
84 | |
85 | g_variant_unref (array_of_types); |
86 | } |
87 | |
88 | g_object_unref (proxy); |
89 | g_main_loop_quit (loop); |
90 | } |
91 | |
92 | |
93 | static void |
94 | grapa_addtoarchive_ready_cb (GObject *source_object, |
95 | GAsyncResult *res, |
96 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
97 | { |
98 | GDBusProxy *proxy; |
99 | GVariant *values; |
100 | GError *error = NULL((void*)0); |
101 | |
102 | proxy = G_DBUS_PROXY (source_object)((((GDBusProxy*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((source_object)), ((g_dbus_proxy_get_type ())))))); |
103 | values = g_dbus_proxy_call_finish (proxy, res, &error); |
104 | if (values == NULL((void*)0)) { |
105 | g_error ("%s\n", error->message); |
106 | g_clear_error (&error); |
This statement is never executed | |
107 | } |
108 | |
109 | if (values != NULL((void*)0)) |
110 | g_variant_unref (values); |
111 | g_object_unref (proxy); |
112 | |
113 | g_main_loop_quit (loop); |
114 | } |
115 | |
116 | |
117 | static void |
118 | on_signal (GDBusProxy *proxy G_GNUC_UNUSED__attribute__ ((__unused__)), |
119 | char *sender_name G_GNUC_UNUSED__attribute__ ((__unused__)), |
120 | char *signal_name, |
121 | GVariant *parameters, |
122 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
123 | { |
124 | if (g_strcmp0 (signal_name, "Progress") == 0) { |
125 | double fraction; |
126 | char *details; |
127 | |
128 | g_variant_get (parameters, "(ds)", &fraction, &details); |
129 | g_print ("Progress: %f (%s)\n", fraction, details); |
130 | |
131 | g_free (details); |
132 | } |
133 | } |
134 | |
135 | |
136 | int |
137 | main (int argc G_GNUC_UNUSED__attribute__ ((__unused__)), |
138 | char *argv[] G_GNUC_UNUSED__attribute__ ((__unused__))) |
139 | { |
140 | GDBusConnection *connection; |
141 | GError *error = NULL((void*)0); |
142 | |
143 | connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL((void*)0), &error); |
144 | if (connection != NULL((void*)0)) { |
145 | GDBusProxy *proxy; |
146 | |
147 | proxy = g_dbus_proxy_new_sync (connection, |
148 | G_DBUS_PROXY_FLAGS_NONE, |
149 | NULL((void*)0), |
150 | "org.cafe.Grapa", |
151 | "/org/cafe/Grapa", |
152 | "org.cafe.ArchiveManager", |
153 | NULL((void*)0), |
154 | &error); |
155 | |
156 | if (proxy != NULL((void*)0)) { |
157 | |
158 | g_signal_connect (proxy,g_signal_connect_data ((proxy), ("g-signal"), (((GCallback) ( on_signal))), (((void*)0)), ((void*)0), (GConnectFlags) 0) |
159 | "g-signal",g_signal_connect_data ((proxy), ("g-signal"), (((GCallback) ( on_signal))), (((void*)0)), ((void*)0), (GConnectFlags) 0) |
160 | G_CALLBACK (on_signal),g_signal_connect_data ((proxy), ("g-signal"), (((GCallback) ( on_signal))), (((void*)0)), ((void*)0), (GConnectFlags) 0) |
161 | NULL)g_signal_connect_data ((proxy), ("g-signal"), (((GCallback) ( on_signal))), (((void*)0)), ((void*)0), (GConnectFlags) 0); |
162 | |
163 | /* -- GetSupportedTypes -- */ |
164 | |
165 | g_dbus_proxy_call (proxy, |
166 | "GetSupportedTypes", |
167 | g_variant_new ("(s)", "create"), |
168 | G_DBUS_CALL_FLAGS_NONE, |
169 | G_MAXINT2147483647, |
170 | NULL((void*)0), |
171 | grapa_getsupportedtypes_ready_cb, |
172 | NULL((void*)0)); |
173 | |
174 | /* -- AddToArchive -- */ |
175 | |
176 | char *archive; |
177 | char **files; |
178 | |
179 | archive = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre.tar.gz")g_strdup_inline ("file:///home/paolo/Scrivania/firefox-4.0b8pre.tar.gz" ); |
180 | files = g_new0 (char *, 2)((char * *) g_malloc0_n ((2), sizeof (char *))); |
181 | files[0] = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre")g_strdup_inline ("file:///home/paolo/Scrivania/firefox-4.0b8pre" ); |
182 | files[1] = NULL((void*)0); |
183 | |
184 | g_dbus_proxy_call (proxy, |
185 | "AddToArchive", |
186 | g_variant_new ("(s^asb)", |
187 | archive, |
188 | files, |
189 | FALSE(0)), |
190 | G_DBUS_CALL_FLAGS_NONE, |
191 | G_MAXINT2147483647, |
192 | NULL((void*)0), |
193 | grapa_addtoarchive_ready_cb, |
194 | NULL((void*)0)); |
195 | |
196 | g_free (archive); |
197 | g_strfreev (files); |
198 | |
199 | /* -- Compress -- */ |
200 | |
201 | char *destination; |
202 | |
203 | files = g_new0 (char *, 2)((char * *) g_malloc0_n ((2), sizeof (char *))); |
204 | files[0] = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre")g_strdup_inline ("file:///home/paolo/Scrivania/firefox-4.0b8pre" ); |
205 | files[1] = NULL((void*)0); |
206 | destination = g_strdup ("file:///home/paolo/Scrivania")g_strdup_inline ("file:///home/paolo/Scrivania"); |
207 | |
208 | g_dbus_proxy_call (proxy, |
209 | "Compress", |
210 | g_variant_new ("(^assb)", |
211 | files, |
212 | destination, |
213 | TRUE(!(0))), |
214 | G_DBUS_CALL_FLAGS_NONE, |
215 | G_MAXINT2147483647, |
216 | NULL((void*)0), |
217 | grapa_addtoarchive_ready_cb, |
218 | NULL((void*)0)); |
219 | |
220 | g_strfreev (files); |
221 | g_free (destination); |
222 | |
223 | /* -- Extract -- */ |
224 | |
225 | g_dbus_proxy_call (proxy, |
226 | "Extract", |
227 | g_variant_new ("(ssb)", |
228 | "file:///home/paolo/Scrivania/test.tar.gz", |
229 | "file:///home/paolo/Scrivania", |
230 | TRUE(!(0))), |
231 | G_DBUS_CALL_FLAGS_NONE, |
232 | G_MAXINT2147483647, |
233 | NULL((void*)0), |
234 | grapa_addtoarchive_ready_cb, |
235 | NULL((void*)0)); |
236 | |
237 | /* -- ExtractHere -- */ |
238 | |
239 | g_dbus_proxy_call (proxy, |
240 | "ExtractHere", |
241 | g_variant_new ("(sb)", |
242 | "file:///home/paolo/Scrivania/test.tar.gz", |
243 | TRUE(!(0))), |
244 | G_DBUS_CALL_FLAGS_NONE, |
245 | G_MAXINT2147483647, |
246 | NULL((void*)0), |
247 | grapa_addtoarchive_ready_cb, |
248 | NULL((void*)0)); |
249 | } |
250 | } |
251 | |
252 | loop = g_main_loop_new (NULL((void*)0), FALSE(0)); |
253 | g_main_loop_run (loop); |
254 | |
255 | return 0; |
256 | } |