Mercurial > geeqie
annotate src/remote.c @ 1710:fce6debc934e
updated czech translation
author | nadvornik |
---|---|
date | Wed, 29 Jul 2009 21:03:38 +0000 |
parents | 3840882253fe |
children | 956aab097ea7 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "remote.h" |
16 | |
649 | 17 #include "collect.h" |
18 #include "filedata.h" | |
19 #include "img-view.h" | |
20 #include "layout.h" | |
21 #include "layout_image.h" | |
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
1000
diff
changeset
|
22 #include "misc.h" |
649 | 23 #include "slideshow.h" |
24 #include "ui_fileops.h" | |
1467 | 25 #include "rcfile.h" |
9 | 26 |
27 #include <sys/socket.h> | |
28 #include <sys/un.h> | |
29 #include <signal.h> | |
30 #include <errno.h> | |
31 | |
32 | |
33 #define SERVER_MAX_CLIENTS 8 | |
34 | |
35 #define REMOTE_SERVER_BACKLOG 4 | |
36 | |
37 | |
38 #ifndef UNIX_PATH_MAX | |
39 #define UNIX_PATH_MAX 108 | |
40 #endif | |
41 | |
42 | |
649 | 43 static RemoteConnection *remote_client_open(const gchar *path); |
44 static gint remote_client_send(RemoteConnection *rc, const gchar *text); | |
45 | |
46 | |
9 | 47 typedef struct _RemoteClient RemoteClient; |
48 struct _RemoteClient { | |
49 gint fd; | |
1523 | 50 guint channel_id; /* event source id */ |
9 | 51 RemoteConnection *rc; |
52 }; | |
53 | |
649 | 54 typedef struct _RemoteData RemoteData; |
55 struct _RemoteData { | |
56 CollectionData *command_collection; | |
57 }; | |
58 | |
9 | 59 |
60 static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition condition, gpointer data) | |
61 { | |
62 RemoteClient *client = data; | |
63 RemoteConnection *rc; | |
1299 | 64 GIOStatus status = G_IO_STATUS_NORMAL; |
9 | 65 |
66 rc = client->rc; | |
67 | |
68 if (condition & G_IO_IN) | |
69 { | |
70 gchar *buffer = NULL; | |
71 GError *error = NULL; | |
1300 | 72 gsize termpos; |
9 | 73 |
1299 | 74 while ((status = g_io_channel_read_line(source, &buffer, NULL, &termpos, &error)) == G_IO_STATUS_NORMAL) |
9 | 75 { |
76 if (buffer) | |
77 { | |
78 buffer[termpos] = '\0'; | |
79 | |
80 if (strlen(buffer) > 0) | |
81 { | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
82 if (rc->read_func) rc->read_func(rc, buffer, source, rc->read_data); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
83 g_io_channel_write_chars(source, "\n", -1, NULL, NULL); /* empty line finishes the command */ |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
84 g_io_channel_flush(source, NULL); |
9 | 85 } |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
86 g_free(buffer); |
9 | 87 |
88 buffer = NULL; | |
89 } | |
90 } | |
91 | |
92 if (error) | |
93 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
94 log_printf("error reading socket: %s\n", error->message); |
9 | 95 g_error_free(error); |
96 } | |
97 } | |
98 | |
1299 | 99 if (condition & G_IO_HUP || status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR) |
9 | 100 { |
101 rc->clients = g_list_remove(rc->clients, client); | |
102 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
103 DEBUG_1("HUP detected, closing client."); |
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
104 DEBUG_1("client count %d", g_list_length(rc->clients)); |
495 | 105 |
9 | 106 g_source_remove(client->channel_id); |
107 close(client->fd); | |
108 g_free(client); | |
109 } | |
110 | |
111 return TRUE; | |
112 } | |
113 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
114 static void remote_server_client_add(RemoteConnection *rc, gint fd) |
9 | 115 { |
116 RemoteClient *client; | |
117 GIOChannel *channel; | |
118 | |
119 if (g_list_length(rc->clients) > SERVER_MAX_CLIENTS) | |
120 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
121 log_printf("maximum remote clients of %d exceeded, closing connection\n", SERVER_MAX_CLIENTS); |
9 | 122 close(fd); |
123 return; | |
124 } | |
125 | |
126 client = g_new0(RemoteClient, 1); | |
127 client->rc = rc; | |
128 client->fd = fd; | |
129 | |
130 channel = g_io_channel_unix_new(fd); | |
131 client->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP, | |
132 remote_server_client_cb, client, NULL); | |
133 g_io_channel_unref(channel); | |
134 | |
135 rc->clients = g_list_append(rc->clients, client); | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
136 DEBUG_1("client count %d", g_list_length(rc->clients)); |
9 | 137 } |
138 | |
139 static void remote_server_clients_close(RemoteConnection *rc) | |
140 { | |
141 while (rc->clients) | |
142 { | |
143 RemoteClient *client = rc->clients->data; | |
144 | |
145 rc->clients = g_list_remove(rc->clients, client); | |
146 | |
147 g_source_remove(client->channel_id); | |
148 close(client->fd); | |
149 g_free(client); | |
150 } | |
151 } | |
152 | |
153 static gboolean remote_server_read_cb(GIOChannel *source, GIOCondition condition, gpointer data) | |
154 { | |
155 RemoteConnection *rc = data; | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
156 gint fd; |
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
157 guint alen; |
9 | 158 |
159 fd = accept(rc->fd, NULL, &alen); | |
160 if (fd == -1) | |
161 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
162 log_printf("error accepting socket: %s\n", strerror(errno)); |
9 | 163 return TRUE; |
164 } | |
165 | |
166 remote_server_client_add(rc, fd); | |
167 | |
168 return TRUE; | |
169 } | |
170 | |
1444 | 171 static gboolean remote_server_exists(const gchar *path) |
9 | 172 { |
173 RemoteConnection *rc; | |
174 | |
175 /* verify server up */ | |
176 rc = remote_client_open(path); | |
177 remote_close(rc); | |
178 | |
179 if (rc) return TRUE; | |
180 | |
181 /* unable to connect, remove socket file to free up address */ | |
182 unlink(path); | |
183 return FALSE; | |
184 } | |
185 | |
649 | 186 static RemoteConnection *remote_server_open(const gchar *path) |
9 | 187 { |
188 RemoteConnection *rc; | |
189 struct sockaddr_un addr; | |
190 gint sun_path_len; | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
191 gint fd; |
9 | 192 GIOChannel *channel; |
193 | |
194 if (remote_server_exists(path)) | |
195 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
196 log_printf("Address already in use: %s\n", path); |
9 | 197 return NULL; |
198 } | |
199 | |
200 fd = socket(PF_UNIX, SOCK_STREAM, 0); | |
201 if (fd == -1) return NULL; | |
202 | |
203 addr.sun_family = AF_UNIX; | |
204 sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX); | |
205 strncpy(addr.sun_path, path, sun_path_len); | |
206 if (bind(fd, &addr, sizeof(addr)) == -1 || | |
207 listen(fd, REMOTE_SERVER_BACKLOG) == -1) | |
208 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
209 log_printf("error subscribing to socket: %s\n", strerror(errno)); |
9 | 210 close(fd); |
211 return NULL; | |
212 } | |
213 | |
214 rc = g_new0(RemoteConnection, 1); | |
1367
fe4da037be21
When g_new0() is used, drop redundant initializations to NULL, FALSE or 0, second pass.
zas_
parents:
1307
diff
changeset
|
215 |
9 | 216 rc->server = TRUE; |
217 rc->fd = fd; | |
218 rc->path = g_strdup(path); | |
219 | |
220 channel = g_io_channel_unix_new(rc->fd); | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
1284
diff
changeset
|
221 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
1284
diff
changeset
|
222 |
9 | 223 rc->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN, |
224 remote_server_read_cb, rc, NULL); | |
225 g_io_channel_unref(channel); | |
226 | |
227 return rc; | |
228 } | |
229 | |
649 | 230 static void remote_server_subscribe(RemoteConnection *rc, RemoteReadFunc *func, gpointer data) |
9 | 231 { |
232 if (!rc || !rc->server) return; | |
233 | |
234 rc->read_func = func; | |
235 rc->read_data = data; | |
236 } | |
237 | |
238 | |
649 | 239 static RemoteConnection *remote_client_open(const gchar *path) |
9 | 240 { |
241 RemoteConnection *rc; | |
242 struct stat st; | |
243 struct sockaddr_un addr; | |
244 gint sun_path_len; | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
245 gint fd; |
9 | 246 |
247 if (stat(path, &st) != 0 || !S_ISSOCK(st.st_mode)) return NULL; | |
248 | |
249 fd = socket(PF_UNIX, SOCK_STREAM, 0); | |
250 if (fd == -1) return NULL; | |
251 | |
252 addr.sun_family = AF_UNIX; | |
253 sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX); | |
254 strncpy(addr.sun_path, path, sun_path_len); | |
255 if (connect(fd, &addr, sizeof(addr)) == -1) | |
442 | 256 { |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
257 DEBUG_1("error connecting to socket: %s", strerror(errno)); |
442 | 258 close(fd); |
259 return NULL; | |
260 } | |
9 | 261 |
262 rc = g_new0(RemoteConnection, 1); | |
263 rc->server = FALSE; | |
264 rc->fd = fd; | |
265 rc->path = g_strdup(path); | |
266 | |
267 return rc; | |
268 } | |
269 | |
270 static sig_atomic_t sigpipe_occured = FALSE; | |
271 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
272 static void sighandler_sigpipe(gint sig) |
9 | 273 { |
274 sigpipe_occured = TRUE; | |
275 } | |
276 | |
1444 | 277 static gboolean remote_client_send(RemoteConnection *rc, const gchar *text) |
9 | 278 { |
279 struct sigaction new_action, old_action; | |
1437 | 280 gboolean ret = FALSE; |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
281 GError *error = NULL; |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
282 GIOChannel *channel; |
9 | 283 |
284 if (!rc || rc->server) return FALSE; | |
285 if (!text) return TRUE; | |
286 | |
287 sigpipe_occured = FALSE; | |
288 | |
289 new_action.sa_handler = sighandler_sigpipe; | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
507
diff
changeset
|
290 sigemptyset(&new_action.sa_mask); |
9 | 291 new_action.sa_flags = 0; |
292 | |
293 /* setup our signal handler */ | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
507
diff
changeset
|
294 sigaction(SIGPIPE, &new_action, &old_action); |
9 | 295 |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
296 channel = g_io_channel_unix_new(rc->fd); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
297 |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
298 g_io_channel_write_chars(channel, text, -1, NULL, &error); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
299 g_io_channel_write_chars(channel, "\n", -1, NULL, &error); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
300 g_io_channel_flush(channel, &error); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
301 |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
302 if (error) |
9 | 303 { |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
304 log_printf("error reading socket: %s\n", error->message); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
305 g_error_free(error); |
9 | 306 ret = FALSE;; |
307 } | |
308 else | |
309 { | |
310 ret = TRUE; | |
311 } | |
312 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
313 if (ret) |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
314 { |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
315 gchar *buffer = NULL; |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
316 gsize termpos; |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
317 while (g_io_channel_read_line(channel, &buffer, NULL, &termpos, &error) == G_IO_STATUS_NORMAL) |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
318 { |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
319 if (buffer) |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
320 { |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
321 if (buffer[0] == '\n') /* empty line finishes the command */ |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
322 { |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
323 g_free(buffer); |
1556
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
324 fflush(stdout); |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
325 break; |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
326 } |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
327 buffer[termpos] = '\0'; |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
328 printf("%s\n", buffer); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
329 g_free(buffer); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
330 buffer = NULL; |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
331 } |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
332 } |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
333 |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
334 if (error) |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
335 { |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
336 log_printf("error reading socket: %s\n", error->message); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
337 g_error_free(error); |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
338 ret = FALSE; |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
339 } |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
340 } |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
341 |
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
342 |
9 | 343 /* restore the original signal handler */ |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
507
diff
changeset
|
344 sigaction(SIGPIPE, &old_action, NULL); |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
345 g_io_channel_unref(channel); |
9 | 346 return ret; |
347 } | |
348 | |
349 void remote_close(RemoteConnection *rc) | |
350 { | |
351 if (!rc) return; | |
352 | |
353 if (rc->server) | |
354 { | |
355 remote_server_clients_close(rc); | |
356 | |
357 g_source_remove(rc->channel_id); | |
358 unlink(rc->path); | |
359 } | |
360 | |
649 | 361 if (rc->read_data) |
362 g_free(rc->read_data); | |
363 | |
9 | 364 close(rc->fd); |
365 | |
366 g_free(rc->path); | |
367 g_free(rc); | |
368 } | |
649 | 369 |
370 /* | |
371 *----------------------------------------------------------------------------- | |
372 * remote functions | |
373 *----------------------------------------------------------------------------- | |
374 */ | |
375 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
376 static void gr_image_next(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 377 { |
378 layout_image_next(NULL); | |
379 } | |
380 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
381 static void gr_image_prev(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 382 { |
383 layout_image_prev(NULL); | |
384 } | |
385 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
386 static void gr_image_first(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 387 { |
388 layout_image_first(NULL); | |
389 } | |
390 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
391 static void gr_image_last(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 392 { |
393 layout_image_last(NULL); | |
394 } | |
395 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
396 static void gr_fullscreen_toggle(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 397 { |
398 layout_image_full_screen_toggle(NULL); | |
399 } | |
400 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
401 static void gr_fullscreen_start(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 402 { |
403 layout_image_full_screen_start(NULL); | |
404 } | |
405 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
406 static void gr_fullscreen_stop(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 407 { |
408 layout_image_full_screen_stop(NULL); | |
409 } | |
410 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
411 static void gr_slideshow_start_rec(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 412 { |
413 GList *list; | |
783 | 414 FileData *dir_fd = file_data_new_simple(text); |
415 list = filelist_recursive(dir_fd); | |
416 file_data_unref(dir_fd); | |
649 | 417 if (!list) return; |
418 //printf("length: %d\n", g_list_length(list)); | |
419 layout_image_slideshow_stop(NULL); | |
420 layout_image_slideshow_start_from_list(NULL, list); | |
421 } | |
422 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
423 static void gr_slideshow_toggle(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 424 { |
425 layout_image_slideshow_toggle(NULL); | |
426 } | |
427 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
428 static void gr_slideshow_start(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 429 { |
430 layout_image_slideshow_start(NULL); | |
431 } | |
432 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
433 static void gr_slideshow_stop(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 434 { |
435 layout_image_slideshow_stop(NULL); | |
436 } | |
437 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
438 static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 439 { |
440 gdouble n; | |
441 | |
1307 | 442 n = g_ascii_strtod(text, NULL); |
649 | 443 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS) |
444 { | |
445 printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n", | |
446 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS); | |
447 return; | |
448 } | |
449 options->slideshow.delay = (gint)(n * 10.0 + 0.01); | |
450 } | |
451 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
452 static void gr_tools_show(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 453 { |
1416 | 454 gboolean popped; |
455 gboolean hidden; | |
649 | 456 |
457 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden) | |
458 { | |
459 layout_tools_float_set(NULL, popped, FALSE); | |
460 } | |
461 } | |
462 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
463 static void gr_tools_hide(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 464 { |
1416 | 465 gboolean popped; |
466 gboolean hidden; | |
649 | 467 |
468 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden) | |
469 { | |
470 layout_tools_float_set(NULL, popped, TRUE); | |
471 } | |
472 } | |
473 | |
1444 | 474 static gboolean gr_quit_idle_cb(gpointer data) |
649 | 475 { |
476 exit_program(); | |
477 | |
478 return FALSE; | |
479 } | |
480 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
481 static void gr_quit(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 482 { |
483 /* schedule exit when idle, if done from within a | |
484 * remote handler remote_close will crash | |
485 */ | |
486 g_idle_add(gr_quit_idle_cb, NULL); | |
487 } | |
488 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
489 static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 490 { |
653 | 491 gchar *filename = expand_tilde(text); |
492 | |
493 if (isfile(filename)) | |
649 | 494 { |
781
2d2cca2bceb0
Replace hardcoded collection filename extension by a macro (GQ_COLLECTION_EXT).
zas_
parents:
713
diff
changeset
|
495 if (file_extension_match(filename, GQ_COLLECTION_EXT)) |
649 | 496 { |
653 | 497 collection_window_new(filename); |
649 | 498 } |
499 else | |
500 { | |
653 | 501 layout_set_path(NULL, filename); |
649 | 502 } |
503 } | |
653 | 504 else if (isdir(filename)) |
649 | 505 { |
653 | 506 layout_set_path(NULL, filename); |
649 | 507 } |
508 else | |
509 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
510 log_printf("remote sent filename that does not exist:\"%s\"\n", filename); |
649 | 511 } |
653 | 512 |
513 g_free(filename); | |
649 | 514 } |
515 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
516 static void gr_config_load(const gchar *text, GIOChannel *channel, gpointer data) |
1467 | 517 { |
518 gchar *filename = expand_tilde(text); | |
519 | |
520 if (isfile(filename)) | |
521 { | |
1484 | 522 load_config_from_file(filename, FALSE); |
1467 | 523 } |
524 else | |
525 { | |
526 log_printf("remote sent filename that does not exist:\"%s\"\n", filename); | |
527 } | |
528 | |
529 g_free(filename); | |
530 } | |
531 | |
1556
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
532 static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer data) |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
533 { |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
534 gchar *filename = expand_tilde(text); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
535 FileData *fd = file_data_new_simple(filename); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
536 |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
537 GList *work; |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
538 if (fd->parent) fd = fd->parent; |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
539 |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
540 g_io_channel_write_chars(channel, fd->path, -1, NULL, NULL); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
541 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
542 |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
543 work = fd->sidecar_files; |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
544 |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
545 while (work) |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
546 { |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
547 fd = work->data; |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
548 work = work->next; |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
549 g_io_channel_write_chars(channel, fd->path, -1, NULL, NULL); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
550 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
551 } |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
552 g_free(filename); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
553 } |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
554 |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
555 static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer data) |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
556 { |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
557 gchar *filename = expand_tilde(text); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
558 FileData *fd = file_data_new_simple(filename); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
559 |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
560 if (fd->change && fd->change->dest) |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
561 { |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
562 g_io_channel_write_chars(channel, fd->change->dest, -1, NULL, NULL); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
563 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
564 } |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
565 g_free(filename); |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
566 } |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
567 |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
568 static void gr_file_view(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 569 { |
653 | 570 gchar *filename = expand_tilde(text); |
571 | |
572 view_window_new(file_data_new_simple(filename)); | |
573 g_free(filename); | |
649 | 574 } |
575 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
576 static void gr_list_clear(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 577 { |
578 RemoteData *remote_data = data; | |
579 | |
580 if (remote_data->command_collection) | |
581 { | |
582 collection_unref(remote_data->command_collection); | |
583 remote_data->command_collection = NULL; | |
584 } | |
995 | 585 } |
649 | 586 |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
587 static void gr_list_add(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 588 { |
589 RemoteData *remote_data = data; | |
1437 | 590 gboolean new = TRUE; |
649 | 591 |
592 if (!remote_data->command_collection) | |
593 { | |
594 CollectionData *cd; | |
595 | |
596 cd = collection_new(""); | |
597 | |
598 g_free(cd->path); | |
599 cd->path = NULL; | |
600 g_free(cd->name); | |
601 cd->name = g_strdup(_("Command line")); | |
602 | |
603 remote_data->command_collection = cd; | |
604 } | |
605 else | |
606 { | |
607 new = (!collection_get_first(remote_data->command_collection)); | |
608 } | |
609 | |
610 if (collection_add(remote_data->command_collection, file_data_new_simple(text), FALSE) && new) | |
611 { | |
612 layout_image_set_collection(NULL, remote_data->command_collection, | |
613 collection_get_first(remote_data->command_collection)); | |
614 } | |
615 } | |
616 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
617 static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data) |
649 | 618 { |
619 LayoutWindow *lw = NULL; | |
620 | |
621 if (layout_valid(&lw)) | |
622 { | |
623 gtk_window_present(GTK_WINDOW(lw->window)); | |
624 } | |
625 } | |
626 | |
627 typedef struct _RemoteCommandEntry RemoteCommandEntry; | |
628 struct _RemoteCommandEntry { | |
629 gchar *opt_s; | |
630 gchar *opt_l; | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
631 void (*func)(const gchar *text, GIOChannel *channel, gpointer data); |
1444 | 632 gboolean needs_extra; |
633 gboolean prefer_command_line; | |
649 | 634 gchar *description; |
635 }; | |
636 | |
637 static RemoteCommandEntry remote_commands[] = { | |
638 /* short, long callback, extra, prefer,description */ | |
639 { "-n", "--next", gr_image_next, FALSE, FALSE, N_("next image") }, | |
640 { "-b", "--back", gr_image_prev, FALSE, FALSE, N_("previous image") }, | |
641 { NULL, "--first", gr_image_first, FALSE, FALSE, N_("first image") }, | |
642 { NULL, "--last", gr_image_last, FALSE, FALSE, N_("last image") }, | |
643 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, N_("toggle full screen") }, | |
644 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, N_("start full screen") }, | |
645 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, N_("stop full screen") }, | |
646 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, N_("toggle slide show") }, | |
647 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, N_("start slide show") }, | |
648 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, N_("stop slide show") }, | |
1475 | 649 { NULL, "--slideshow-recurse:", gr_slideshow_start_rec, TRUE, FALSE, N_("start recursive slide show") }, |
649 | 650 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("set slide show delay in seconds") }, |
651 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, N_("show tools") }, | |
652 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, N_("hide tools") }, | |
653 { "-q", "--quit", gr_quit, FALSE, FALSE, N_("quit") }, | |
1475 | 654 { NULL, "--config-load:", gr_config_load, TRUE, FALSE, N_("load config file") }, |
1556
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
655 { NULL, "--get-sidecars:", gr_get_sidecars, TRUE, FALSE, N_("get list of sidecars of the given file") }, |
3840882253fe
added remote interface for exporting additional info (sidecars,
nadvornik
parents:
1554
diff
changeset
|
656 { NULL, "--get-destination:", gr_get_destination, TRUE, FALSE, N_("get destination path for the given file") }, |
649 | 657 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("open file") }, |
658 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("open file in new window") }, | |
659 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL }, | |
660 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, NULL }, | |
661 { NULL, "raise", gr_raise, FALSE, FALSE, NULL }, | |
662 { NULL, NULL, NULL, FALSE, FALSE, NULL } | |
663 }; | |
664 | |
665 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset) | |
666 { | |
1437 | 667 gboolean match = FALSE; |
649 | 668 gint i; |
669 | |
670 i = 0; | |
671 while (!match && remote_commands[i].func != NULL) | |
672 { | |
673 if (remote_commands[i].needs_extra) | |
674 { | |
675 if (remote_commands[i].opt_s && | |
676 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0) | |
677 { | |
678 if (offset) *offset = text + strlen(remote_commands[i].opt_s); | |
679 return &remote_commands[i]; | |
680 } | |
681 else if (remote_commands[i].opt_l && | |
682 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0) | |
683 { | |
684 if (offset) *offset = text + strlen(remote_commands[i].opt_l); | |
685 return &remote_commands[i]; | |
686 } | |
687 } | |
688 else | |
689 { | |
690 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) || | |
691 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0)) | |
692 { | |
693 if (offset) *offset = text; | |
694 return &remote_commands[i]; | |
695 } | |
696 } | |
697 | |
698 i++; | |
699 } | |
700 | |
701 return NULL; | |
702 } | |
703 | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
704 static void remote_cb(RemoteConnection *rc, const gchar *text, GIOChannel *channel, gpointer data) |
649 | 705 { |
706 RemoteCommandEntry *entry; | |
707 const gchar *offset; | |
708 | |
709 entry = remote_command_find(text, &offset); | |
710 if (entry && entry->func) | |
711 { | |
1554
a96a20c7feb1
improved remote protocol to allow bidirectional communication
nadvornik
parents:
1523
diff
changeset
|
712 entry->func(offset, channel, data); |
649 | 713 } |
714 else | |
715 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
716 log_printf("unknown remote command:%s\n", text); |
649 | 717 } |
718 } | |
719 | |
720 void remote_help(void) | |
721 { | |
722 gint i; | |
723 | |
724 print_term(_("Remote command list:\n")); | |
725 | |
726 i = 0; | |
727 while (remote_commands[i].func != NULL) | |
728 { | |
729 if (remote_commands[i].description) | |
730 { | |
731 printf_term(" %-3s%s %-20s %s\n", | |
732 (remote_commands[i].opt_s) ? remote_commands[i].opt_s : "", | |
733 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ", | |
734 (remote_commands[i].opt_l) ? remote_commands[i].opt_l : "", | |
735 _(remote_commands[i].description)); | |
736 } | |
737 i++; | |
738 } | |
739 } | |
740 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
741 GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors) |
649 | 742 { |
743 gint i; | |
744 | |
745 i = 1; | |
746 while (i < argc) | |
747 { | |
748 RemoteCommandEntry *entry; | |
749 | |
750 entry = remote_command_find(argv[i], NULL); | |
751 if (entry) | |
752 { | |
753 list = g_list_append(list, argv[i]); | |
754 } | |
652
9bcfd6d7a902
Display a message when invalid remote options are used.
zas_
parents:
649
diff
changeset
|
755 else if (errors) |
9bcfd6d7a902
Display a message when invalid remote options are used.
zas_
parents:
649
diff
changeset
|
756 { |
9bcfd6d7a902
Display a message when invalid remote options are used.
zas_
parents:
649
diff
changeset
|
757 *errors = g_list_append(*errors, argv[i]); |
9bcfd6d7a902
Display a message when invalid remote options are used.
zas_
parents:
649
diff
changeset
|
758 } |
649 | 759 i++; |
760 } | |
761 | |
762 return list; | |
763 } | |
764 | |
765 void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path, | |
766 GList *cmd_list, GList *collection_list) | |
767 { | |
768 RemoteConnection *rc; | |
1437 | 769 gboolean started = FALSE; |
649 | 770 gchar *buf; |
771 | |
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1144
diff
changeset
|
772 buf = g_build_filename(get_rc_dir(), ".command", NULL); |
649 | 773 rc = remote_client_open(buf); |
774 if (!rc) | |
775 { | |
776 GString *command; | |
777 GList *work; | |
778 gint retry_count = 12; | |
1437 | 779 gboolean blank = FALSE; |
649 | 780 |
781 printf_term(_("Remote %s not running, starting..."), GQ_APPNAME); | |
782 | |
783 command = g_string_new(arg_exec); | |
784 | |
785 work = remote_list; | |
786 while (work) | |
787 { | |
788 gchar *text; | |
789 RemoteCommandEntry *entry; | |
790 | |
791 text = work->data; | |
792 work = work->next; | |
793 | |
794 entry = remote_command_find(text, NULL); | |
795 if (entry) | |
796 { | |
797 if (entry->prefer_command_line) | |
798 { | |
799 remote_list = g_list_remove(remote_list, text); | |
800 g_string_append(command, " "); | |
801 g_string_append(command, text); | |
802 } | |
803 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0) | |
804 { | |
805 blank = TRUE; | |
806 } | |
807 } | |
808 } | |
809 | |
810 if (blank || cmd_list || path) g_string_append(command, " --blank"); | |
811 if (get_debug_level()) g_string_append(command, " --debug"); | |
812 | |
813 g_string_append(command, " &"); | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
814 runcmd(command->str); |
649 | 815 g_string_free(command, TRUE); |
816 | |
817 while (!rc && retry_count > 0) | |
818 { | |
819 usleep((retry_count > 10) ? 500000 : 1000000); | |
820 rc = remote_client_open(buf); | |
821 if (!rc) print_term("."); | |
822 retry_count--; | |
823 } | |
824 | |
825 print_term("\n"); | |
826 | |
827 started = TRUE; | |
828 } | |
829 g_free(buf); | |
830 | |
831 if (rc) | |
832 { | |
833 GList *work; | |
834 const gchar *prefix; | |
1437 | 835 gboolean use_path = TRUE; |
836 gboolean sent = FALSE; | |
649 | 837 |
838 work = remote_list; | |
839 while (work) | |
840 { | |
841 gchar *text; | |
842 RemoteCommandEntry *entry; | |
843 | |
844 text = work->data; | |
845 work = work->next; | |
846 | |
847 entry = remote_command_find(text, NULL); | |
848 if (entry && | |
849 entry->opt_l && | |
850 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE; | |
851 | |
852 remote_client_send(rc, text); | |
853 | |
854 sent = TRUE; | |
855 } | |
856 | |
857 if (cmd_list && cmd_list->next) | |
858 { | |
859 prefix = "--list-add:"; | |
860 remote_client_send(rc, "--list-clear"); | |
861 } | |
862 else | |
863 { | |
864 prefix = "file:"; | |
865 } | |
866 | |
867 work = cmd_list; | |
868 while (work) | |
869 { | |
870 FileData *fd; | |
871 gchar *text; | |
872 | |
873 fd = work->data; | |
874 work = work->next; | |
875 | |
876 text = g_strconcat(prefix, fd->path, NULL); | |
877 remote_client_send(rc, text); | |
878 g_free(text); | |
879 | |
880 sent = TRUE; | |
881 } | |
882 | |
883 if (path && !cmd_list && use_path) | |
884 { | |
885 gchar *text; | |
886 | |
887 text = g_strdup_printf("file:%s", path); | |
888 remote_client_send(rc, text); | |
889 g_free(text); | |
890 | |
891 sent = TRUE; | |
892 } | |
893 | |
894 work = collection_list; | |
895 while (work) | |
896 { | |
897 const gchar *name; | |
898 gchar *text; | |
899 | |
900 name = work->data; | |
901 work = work->next; | |
902 | |
903 text = g_strdup_printf("file:%s", name); | |
904 remote_client_send(rc, text); | |
905 g_free(text); | |
906 | |
907 sent = TRUE; | |
908 } | |
909 | |
910 if (!started && !sent) | |
911 { | |
912 remote_client_send(rc, "raise"); | |
913 } | |
914 } | |
915 else | |
916 { | |
917 print_term(_("Remote not available\n")); | |
918 } | |
919 | |
920 _exit(0); | |
921 } | |
922 | |
923 RemoteConnection *remote_server_init(gchar *path, CollectionData *command_collection) | |
924 { | |
925 RemoteConnection *remote_connection = remote_server_open(path); | |
926 RemoteData *remote_data = g_new(RemoteData, 1); | |
927 | |
928 remote_data->command_collection = command_collection; | |
929 | |
930 remote_server_subscribe(remote_connection, remote_cb, remote_data); | |
931 return remote_connection; | |
932 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1022
diff
changeset
|
933 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |