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) |
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) |
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, |
119 | char *sender_name, |
120 | char *signal_name, |
121 | GVariant *parameters, |
122 | gpointer user_data) |
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, char *argv[]) |
138 | { |
139 | GDBusConnection *connection; |
140 | GError *error = NULL((void*)0); |
141 | |
142 | connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL((void*)0), &error); |
143 | if (connection != NULL((void*)0)) { |
144 | GDBusProxy *proxy; |
145 | |
146 | proxy = g_dbus_proxy_new_sync (connection, |
147 | G_DBUS_PROXY_FLAGS_NONE, |
148 | NULL((void*)0), |
149 | "org.cafe.Grapa", |
150 | "/org/cafe/Grapa", |
151 | "org.cafe.ArchiveManager", |
152 | NULL((void*)0), |
153 | &error); |
154 | |
155 | if (proxy != NULL((void*)0)) { |
156 | |
157 | g_signal_connect (proxy,g_signal_connect_data ((proxy), ("g-signal"), (((GCallback) ( on_signal))), (((void*)0)), ((void*)0), (GConnectFlags) 0) |
158 | "g-signal",g_signal_connect_data ((proxy), ("g-signal"), (((GCallback) ( on_signal))), (((void*)0)), ((void*)0), (GConnectFlags) 0) |
159 | G_CALLBACK (on_signal),g_signal_connect_data ((proxy), ("g-signal"), (((GCallback) ( on_signal))), (((void*)0)), ((void*)0), (GConnectFlags) 0) |
160 | NULL)g_signal_connect_data ((proxy), ("g-signal"), (((GCallback) ( on_signal))), (((void*)0)), ((void*)0), (GConnectFlags) 0); |
161 | |
162 | /* -- GetSupportedTypes -- */ |
163 | |
164 | g_dbus_proxy_call (proxy, |
165 | "GetSupportedTypes", |
166 | g_variant_new ("(s)", "create"), |
167 | G_DBUS_CALL_FLAGS_NONE, |
168 | G_MAXINT2147483647, |
169 | NULL((void*)0), |
170 | grapa_getsupportedtypes_ready_cb, |
171 | NULL((void*)0)); |
172 | |
173 | /* -- AddToArchive -- */ |
174 | |
175 | char *archive; |
176 | char **files; |
177 | |
178 | archive = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre.tar.gz")g_strdup_inline ("file:///home/paolo/Scrivania/firefox-4.0b8pre.tar.gz" ); |
179 | files = g_new0 (char *, 2)((char * *) g_malloc0_n ((2), sizeof (char *))); |
180 | files[0] = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre")g_strdup_inline ("file:///home/paolo/Scrivania/firefox-4.0b8pre" ); |
181 | files[1] = NULL((void*)0); |
182 | |
183 | g_dbus_proxy_call (proxy, |
184 | "AddToArchive", |
185 | g_variant_new ("(s^asb)", |
186 | archive, |
187 | files, |
188 | FALSE(0)), |
189 | G_DBUS_CALL_FLAGS_NONE, |
190 | G_MAXINT2147483647, |
191 | NULL((void*)0), |
192 | grapa_addtoarchive_ready_cb, |
193 | NULL((void*)0)); |
194 | |
195 | g_free (archive); |
196 | g_strfreev (files); |
197 | |
198 | /* -- Compress -- */ |
199 | |
200 | char *destination; |
201 | |
202 | files = g_new0 (char *, 2)((char * *) g_malloc0_n ((2), sizeof (char *))); |
203 | files[0] = g_strdup ("file:///home/paolo/Scrivania/firefox-4.0b8pre")g_strdup_inline ("file:///home/paolo/Scrivania/firefox-4.0b8pre" ); |
204 | files[1] = NULL((void*)0); |
205 | destination = g_strdup ("file:///home/paolo/Scrivania")g_strdup_inline ("file:///home/paolo/Scrivania"); |
206 | |
207 | g_dbus_proxy_call (proxy, |
208 | "Compress", |
209 | g_variant_new ("(^assb)", |
210 | files, |
211 | destination, |
212 | TRUE(!(0))), |
213 | G_DBUS_CALL_FLAGS_NONE, |
214 | G_MAXINT2147483647, |
215 | NULL((void*)0), |
216 | grapa_addtoarchive_ready_cb, |
217 | NULL((void*)0)); |
218 | |
219 | g_strfreev (files); |
220 | g_free (destination); |
221 | |
222 | /* -- Extract -- */ |
223 | |
224 | g_dbus_proxy_call (proxy, |
225 | "Extract", |
226 | g_variant_new ("(ssb)", |
227 | "file:///home/paolo/Scrivania/test.tar.gz", |
228 | "file:///home/paolo/Scrivania", |
229 | TRUE(!(0))), |
230 | G_DBUS_CALL_FLAGS_NONE, |
231 | G_MAXINT2147483647, |
232 | NULL((void*)0), |
233 | grapa_addtoarchive_ready_cb, |
234 | NULL((void*)0)); |
235 | |
236 | /* -- ExtractHere -- */ |
237 | |
238 | g_dbus_proxy_call (proxy, |
239 | "ExtractHere", |
240 | g_variant_new ("(sb)", |
241 | "file:///home/paolo/Scrivania/test.tar.gz", |
242 | TRUE(!(0))), |
243 | G_DBUS_CALL_FLAGS_NONE, |
244 | G_MAXINT2147483647, |
245 | NULL((void*)0), |
246 | grapa_addtoarchive_ready_cb, |
247 | NULL((void*)0)); |
248 | } |
249 | } |
250 | |
251 | loop = g_main_loop_new (NULL((void*)0), FALSE(0)); |
252 | g_main_loop_run (loop); |
253 | |
254 | return 0; |
255 | } |