2 * Copyright (C) 2004 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "cache_maint.h"
31 #include "layout_image.h"
33 #include "slideshow.h"
34 #include "ui_fileops.h"
37 #include <sys/socket.h>
43 #define SERVER_MAX_CLIENTS 8
45 #define REMOTE_SERVER_BACKLOG 4
49 #define UNIX_PATH_MAX 108
53 static RemoteConnection *remote_client_open(const gchar *path);
54 static gint remote_client_send(RemoteConnection *rc, const gchar *text);
55 static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data);
58 typedef struct _RemoteClient RemoteClient;
59 struct _RemoteClient {
61 guint channel_id; /* event source id */
65 typedef struct _RemoteData RemoteData;
67 CollectionData *command_collection;
71 static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition condition, gpointer data)
73 RemoteClient *client = data;
75 GIOStatus status = G_IO_STATUS_NORMAL;
79 if (condition & G_IO_IN)
85 while ((status = g_io_channel_read_line(source, &buffer, NULL, &termpos, &error)) == G_IO_STATUS_NORMAL)
89 buffer[termpos] = '\0';
91 if (strlen(buffer) > 0)
93 if (rc->read_func) rc->read_func(rc, buffer, source, rc->read_data);
94 g_io_channel_write_chars(source, "\n", -1, NULL, NULL); /* empty line finishes the command */
95 g_io_channel_flush(source, NULL);
105 log_printf("error reading socket: %s\n", error->message);
110 if (condition & G_IO_HUP || status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR)
112 rc->clients = g_list_remove(rc->clients, client);
114 DEBUG_1("HUP detected, closing client.");
115 DEBUG_1("client count %d", g_list_length(rc->clients));
117 g_source_remove(client->channel_id);
125 static void remote_server_client_add(RemoteConnection *rc, gint fd)
127 RemoteClient *client;
130 if (g_list_length(rc->clients) > SERVER_MAX_CLIENTS)
132 log_printf("maximum remote clients of %d exceeded, closing connection\n", SERVER_MAX_CLIENTS);
137 client = g_new0(RemoteClient, 1);
141 channel = g_io_channel_unix_new(fd);
142 client->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP,
143 remote_server_client_cb, client, NULL);
144 g_io_channel_unref(channel);
146 rc->clients = g_list_append(rc->clients, client);
147 DEBUG_1("client count %d", g_list_length(rc->clients));
150 static void remote_server_clients_close(RemoteConnection *rc)
154 RemoteClient *client = rc->clients->data;
156 rc->clients = g_list_remove(rc->clients, client);
158 g_source_remove(client->channel_id);
164 static gboolean remote_server_read_cb(GIOChannel *source, GIOCondition condition, gpointer data)
166 RemoteConnection *rc = data;
170 fd = accept(rc->fd, NULL, &alen);
173 log_printf("error accepting socket: %s\n", strerror(errno));
177 remote_server_client_add(rc, fd);
182 static gboolean remote_server_exists(const gchar *path)
184 RemoteConnection *rc;
186 /* verify server up */
187 rc = remote_client_open(path);
192 /* unable to connect, remove socket file to free up address */
197 static RemoteConnection *remote_server_open(const gchar *path)
199 RemoteConnection *rc;
200 struct sockaddr_un addr;
205 if (remote_server_exists(path))
207 log_printf("Address already in use: %s\n", path);
211 fd = socket(PF_UNIX, SOCK_STREAM, 0);
212 if (fd == -1) return NULL;
214 addr.sun_family = AF_UNIX;
215 sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX);
216 strncpy(addr.sun_path, path, sun_path_len);
217 if (bind(fd, &addr, sizeof(addr)) == -1 ||
218 listen(fd, REMOTE_SERVER_BACKLOG) == -1)
220 log_printf("error subscribing to socket: %s\n", strerror(errno));
225 rc = g_new0(RemoteConnection, 1);
229 rc->path = g_strdup(path);
231 channel = g_io_channel_unix_new(rc->fd);
232 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
234 rc->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN,
235 remote_server_read_cb, rc, NULL);
236 g_io_channel_unref(channel);
241 static void remote_server_subscribe(RemoteConnection *rc, RemoteReadFunc *func, gpointer data)
243 if (!rc || !rc->server) return;
245 rc->read_func = func;
246 rc->read_data = data;
250 static RemoteConnection *remote_client_open(const gchar *path)
252 RemoteConnection *rc;
254 struct sockaddr_un addr;
258 if (stat(path, &st) != 0 || !S_ISSOCK(st.st_mode)) return NULL;
260 fd = socket(PF_UNIX, SOCK_STREAM, 0);
261 if (fd == -1) return NULL;
263 addr.sun_family = AF_UNIX;
264 sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX);
265 strncpy(addr.sun_path, path, sun_path_len);
266 if (connect(fd, &addr, sizeof(addr)) == -1)
268 DEBUG_1("error connecting to socket: %s", strerror(errno));
273 rc = g_new0(RemoteConnection, 1);
276 rc->path = g_strdup(path);
281 static sig_atomic_t sigpipe_occured = FALSE;
283 static void sighandler_sigpipe(gint sig)
285 sigpipe_occured = TRUE;
288 static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
290 struct sigaction new_action, old_action;
291 gboolean ret = FALSE;
292 GError *error = NULL;
295 if (!rc || rc->server) return FALSE;
296 if (!text) return TRUE;
298 sigpipe_occured = FALSE;
300 new_action.sa_handler = sighandler_sigpipe;
301 sigemptyset(&new_action.sa_mask);
302 new_action.sa_flags = 0;
304 /* setup our signal handler */
305 sigaction(SIGPIPE, &new_action, &old_action);
307 channel = g_io_channel_unix_new(rc->fd);
309 g_io_channel_write_chars(channel, text, -1, NULL, &error);
310 g_io_channel_write_chars(channel, "\n", -1, NULL, &error);
311 g_io_channel_flush(channel, &error);
315 log_printf("error reading socket: %s\n", error->message);
326 gchar *buffer = NULL;
328 while (g_io_channel_read_line(channel, &buffer, NULL, &termpos, &error) == G_IO_STATUS_NORMAL)
332 if (buffer[0] == '\n') /* empty line finishes the command */
338 buffer[termpos] = '\0';
339 printf("%s\n", buffer);
347 log_printf("error reading socket: %s\n", error->message);
354 /* restore the original signal handler */
355 sigaction(SIGPIPE, &old_action, NULL);
356 g_io_channel_unref(channel);
360 void remote_close(RemoteConnection *rc)
366 remote_server_clients_close(rc);
368 g_source_remove(rc->channel_id);
373 g_free(rc->read_data);
382 *-----------------------------------------------------------------------------
384 *-----------------------------------------------------------------------------
387 static void gr_image_next(const gchar *text, GIOChannel *channel, gpointer data)
389 layout_image_next(NULL);
392 static void gr_image_prev(const gchar *text, GIOChannel *channel, gpointer data)
394 layout_image_prev(NULL);
397 static void gr_image_first(const gchar *text, GIOChannel *channel, gpointer data)
399 layout_image_first(NULL);
402 static void gr_image_last(const gchar *text, GIOChannel *channel, gpointer data)
404 layout_image_last(NULL);
407 static void gr_fullscreen_toggle(const gchar *text, GIOChannel *channel, gpointer data)
409 layout_image_full_screen_toggle(NULL);
412 static void gr_fullscreen_start(const gchar *text, GIOChannel *channel, gpointer data)
414 layout_image_full_screen_start(NULL);
417 static void gr_fullscreen_stop(const gchar *text, GIOChannel *channel, gpointer data)
419 layout_image_full_screen_stop(NULL);
422 static void gr_slideshow_start_rec(const gchar *text, GIOChannel *channel, gpointer data)
425 FileData *dir_fd = file_data_new_dir(text);
426 list = filelist_recursive(dir_fd);
427 file_data_unref(dir_fd);
429 //printf("length: %d\n", g_list_length(list));
430 layout_image_slideshow_stop(NULL);
431 layout_image_slideshow_start_from_list(NULL, list);
434 static void gr_cache_thumb(const gchar *text, GIOChannel *channel, gpointer data)
436 if (!g_strcmp0(text, "clear"))
437 cache_maintain_home_remote(FALSE, TRUE);
438 else if (!g_strcmp0(text, "clean"))
439 cache_maintain_home_remote(FALSE, FALSE);
442 static void gr_cache_shared(const gchar *text, GIOChannel *channel, gpointer data)
444 if (!g_strcmp0(text, "clear"))
445 cache_manager_standard_process_remote(TRUE);
446 else if (!g_strcmp0(text, "clean"))
447 cache_manager_standard_process_remote(FALSE);
450 static void gr_cache_metadata(const gchar *text, GIOChannel *channel, gpointer data)
452 cache_maintain_home_remote(TRUE, FALSE);
455 static void gr_cache_clear(const gchar *text, GIOChannel *channel, gpointer data)
457 cache_maintain_home_remote(FALSE, TRUE);
460 static void gr_cache_render(const gchar *text, GIOChannel *channel, gpointer data)
462 cache_manager_render_remote(text, FALSE, FALSE);
465 static void gr_cache_render_recurse(const gchar *text, GIOChannel *channel, gpointer data)
467 cache_manager_render_remote(text, TRUE, FALSE);
470 static void gr_cache_render_standard(const gchar *text, GIOChannel *channel, gpointer data)
472 if(options->thumbnails.spec_standard)
473 cache_manager_render_remote(text, FALSE, TRUE);
476 static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *channel, gpointer data)
478 if(options->thumbnails.spec_standard)
479 cache_manager_render_remote(text, TRUE, TRUE);
482 static void gr_slideshow_toggle(const gchar *text, GIOChannel *channel, gpointer data)
484 layout_image_slideshow_toggle(NULL);
487 static void gr_slideshow_start(const gchar *text, GIOChannel *channel, gpointer data)
489 layout_image_slideshow_start(NULL);
492 static void gr_slideshow_stop(const gchar *text, GIOChannel *channel, gpointer data)
494 layout_image_slideshow_stop(NULL);
497 static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer data)
501 n = g_ascii_strtod(text, NULL);
502 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
504 printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
505 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
508 options->slideshow.delay = (gint)(n * 10.0 + 0.01);
511 static void gr_tools_show(const gchar *text, GIOChannel *channel, gpointer data)
516 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
518 layout_tools_float_set(NULL, popped, FALSE);
522 static void gr_tools_hide(const gchar *text, GIOChannel *channel, gpointer data)
527 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
529 layout_tools_float_set(NULL, popped, TRUE);
533 static gboolean gr_quit_idle_cb(gpointer data)
540 static void gr_quit(const gchar *text, GIOChannel *channel, gpointer data)
542 /* schedule exit when idle, if done from within a
543 * remote handler remote_close will crash
545 g_idle_add(gr_quit_idle_cb, NULL);
548 static void gr_file_load_no_raise(const gchar *text, GIOChannel *channel, gpointer data)
550 gchar *filename = expand_tilde(text);
552 if (isfile(filename))
554 if (file_extension_match(filename, GQ_COLLECTION_EXT))
556 collection_window_new(filename);
560 layout_set_path(NULL, filename);
563 else if (isdir(filename))
565 layout_set_path(NULL, filename);
569 log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
570 layout_set_path(NULL, homedir());
576 static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data)
578 gr_file_load_no_raise(text, channel, data);
580 gr_raise(text, channel, data);
583 static void gr_file_tell(const gchar *text, GIOChannel *channel, gpointer data)
585 LayoutWindow *lw = NULL; /* NULL to force layout_valid() to do some magic */
586 if (!layout_valid(&lw)) return;
587 if (image_get_path(lw->image))
589 g_io_channel_write_chars(channel, image_get_path(lw->image), -1, NULL, NULL);
590 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
594 static void gr_config_load(const gchar *text, GIOChannel *channel, gpointer data)
596 gchar *filename = expand_tilde(text);
598 if (isfile(filename))
600 load_config_from_file(filename, FALSE);
604 log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
605 layout_set_path(NULL, homedir());
611 static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer data)
613 gchar *filename = expand_tilde(text);
614 FileData *fd = file_data_new_group(filename);
617 if (fd->parent) fd = fd->parent;
619 g_io_channel_write_chars(channel, fd->path, -1, NULL, NULL);
620 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
622 work = fd->sidecar_files;
628 g_io_channel_write_chars(channel, fd->path, -1, NULL, NULL);
629 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
634 static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer data)
636 gchar *filename = expand_tilde(text);
637 FileData *fd = file_data_new_group(filename);
639 if (fd->change && fd->change->dest)
641 g_io_channel_write_chars(channel, fd->change->dest, -1, NULL, NULL);
642 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
647 static void gr_file_view(const gchar *text, GIOChannel *channel, gpointer data)
649 gchar *filename = expand_tilde(text);
651 view_window_new(file_data_new_group(filename));
655 static void gr_list_clear(const gchar *text, GIOChannel *channel, gpointer data)
657 RemoteData *remote_data = data;
659 if (remote_data->command_collection)
661 collection_unref(remote_data->command_collection);
662 remote_data->command_collection = NULL;
666 static void gr_list_add(const gchar *text, GIOChannel *channel, gpointer data)
668 RemoteData *remote_data = data;
671 if (!remote_data->command_collection)
675 cd = collection_new("");
680 cd->name = g_strdup(_("Command line"));
682 remote_data->command_collection = cd;
686 new = (!collection_get_first(remote_data->command_collection));
689 if (collection_add(remote_data->command_collection, file_data_new_group(text), FALSE) && new)
691 layout_image_set_collection(NULL, remote_data->command_collection,
692 collection_get_first(remote_data->command_collection));
696 static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data)
698 LayoutWindow *lw = NULL;
700 if (layout_valid(&lw))
702 gtk_window_present(GTK_WINDOW(lw->window));
706 typedef struct _RemoteCommandEntry RemoteCommandEntry;
707 struct _RemoteCommandEntry {
710 void (*func)(const gchar *text, GIOChannel *channel, gpointer data);
711 gboolean needs_extra;
712 gboolean prefer_command_line;
717 static RemoteCommandEntry remote_commands[] = {
718 /* short, long callback, extra, prefer, parameter, description */
719 { "-n", "--next", gr_image_next, FALSE, FALSE, NULL, N_("next image") },
720 { "-b", "--back", gr_image_prev, FALSE, FALSE, NULL, N_("previous image") },
721 { NULL, "--first", gr_image_first, FALSE, FALSE, NULL, N_("first image") },
722 { NULL, "--last", gr_image_last, FALSE, FALSE, NULL, N_("last image") },
723 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, NULL, N_("toggle full screen") },
724 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, NULL, N_("start full screen") },
725 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, NULL, N_("stop full screen") },
726 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, NULL, N_("toggle slide show") },
727 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, NULL, N_("start slide show") },
728 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, NULL, N_("stop slide show") },
729 { NULL, "--slideshow-recurse:", gr_slideshow_start_rec, TRUE, FALSE, N_("<FOLDER>"), N_("start recursive slide show in FOLDER") },
730 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("<[N][.M]>"), N_("set slide show delay to N.M seconds") },
731 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, NULL, N_("show tools") },
732 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, NULL, N_("hide tools") },
733 { "-q", "--quit", gr_quit, FALSE, FALSE, NULL, N_("quit") },
734 { NULL, "--config-load:", gr_config_load, TRUE, FALSE, N_("<FILE>"), N_("load configuration from FILE") },
735 { NULL, "--get-sidecars:", gr_get_sidecars, TRUE, FALSE, N_("<FILE>"), N_("get list of sidecars of FILE") },
736 { NULL, "--get-destination:", gr_get_destination, TRUE, FALSE, N_("<FILE>"), N_("get destination path of FILE") },
737 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("<FILE>"), N_("open FILE, bring Geeqie window to the top") },
738 { NULL, "File:", gr_file_load_no_raise, TRUE, FALSE, N_("<FILE>"), N_("open FILE, do not bring Geeqie window to the top") },
739 { NULL, "--tell", gr_file_tell, FALSE, FALSE, NULL, N_("print filename of current image") },
740 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("<FILE>"), N_("open FILE in new window") },
741 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL, N_("clear command line collection list") },
742 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, N_("<FILE>"), N_("add FILE to command line collection list") },
743 { NULL, "raise", gr_raise, FALSE, FALSE, NULL, N_("bring the Geeqie window to the top") },
744 { "-ct:", "--cache-thumbs:", gr_cache_thumb, TRUE, FALSE, N_("clear|clean"), N_("clear or clean thumbnail cache") },
745 { "-cs:", "--cache-shared:", gr_cache_shared, TRUE, FALSE, N_("clear|clean"), N_("clear or clean shared thumbnail cache") },
746 { "-cm","--cache-metadata", gr_cache_metadata, FALSE, FALSE, NULL, N_(" clean the metadata cache") },
747 { "-cr:", "--cache-render:", gr_cache_render, TRUE, FALSE, N_("<folder> "), N_(" render thumbnails") },
748 { "-crr:", "--cache-render-recurse:", gr_cache_render_recurse, TRUE, FALSE, N_("<folder> "), N_("render thumbnails recursively") },
749 { "-crs:", "--cache-render-shared:", gr_cache_render_standard, TRUE, FALSE, N_("<folder> "), N_(" render thumbnails (see Help)") },
750 { "-crsr:", "--cache-render-shared-recurse:", gr_cache_render_standard_recurse, TRUE, FALSE, N_("<folder>"), N_(" render thumbnails recursively (see Help)") },
751 { NULL, NULL, NULL, FALSE, FALSE, NULL }
754 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset)
756 gboolean match = FALSE;
760 while (!match && remote_commands[i].func != NULL)
762 if (remote_commands[i].needs_extra)
764 if (remote_commands[i].opt_s &&
765 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0)
767 if (offset) *offset = text + strlen(remote_commands[i].opt_s);
768 return &remote_commands[i];
770 else if (remote_commands[i].opt_l &&
771 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
773 if (offset) *offset = text + strlen(remote_commands[i].opt_l);
774 return &remote_commands[i];
779 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) ||
780 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0))
782 if (offset) *offset = text;
783 return &remote_commands[i];
793 static void remote_cb(RemoteConnection *rc, const gchar *text, GIOChannel *channel, gpointer data)
795 RemoteCommandEntry *entry;
798 entry = remote_command_find(text, &offset);
799 if (entry && entry->func)
801 entry->func(offset, channel, data);
805 log_printf("unknown remote command:%s\n", text);
809 void remote_help(void)
815 print_term(_("Remote command list:\n"));
818 while (remote_commands[i].func != NULL)
820 if (remote_commands[i].description)
822 s_opt_param = g_strconcat(remote_commands[i].opt_s, remote_commands[i].parameter, NULL);
823 l_opt_param = g_strconcat(remote_commands[i].opt_l, remote_commands[i].parameter, NULL);
824 printf_term(" %-11s%-1s %-30s%-s\n",
825 (remote_commands[i].opt_s) ? s_opt_param : "",
826 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
827 (remote_commands[i].opt_l) ? l_opt_param : "",
828 _(remote_commands[i].description));
834 printf_term(N_("\n All other command line parameters are used as plain files if they exists.\n"));
837 GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
844 RemoteCommandEntry *entry;
846 entry = remote_command_find(argv[i], NULL);
849 list = g_list_append(list, argv[i]);
851 else if (errors && !isfile(argv[i]))
853 *errors = g_list_append(*errors, argv[i]);
862 * \param arg_exec Binary (argv0)
863 * \param remote_list Evaluated and recognized remote commands
864 * \param path The current path
865 * \param cmd_list List of all non collections in Path
866 * \param collection_list List of all collections in argv
868 void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
869 GList *cmd_list, GList *collection_list)
871 RemoteConnection *rc;
872 gboolean started = FALSE;
875 buf = g_build_filename(get_rc_dir(), ".command", NULL);
876 rc = remote_client_open(buf);
881 gint retry_count = 12;
882 gboolean blank = FALSE;
884 printf_term(_("Remote %s not running, starting..."), GQ_APPNAME);
886 command = g_string_new(arg_exec);
892 RemoteCommandEntry *entry;
897 entry = remote_command_find(text, NULL);
900 if (entry->prefer_command_line)
902 remote_list = g_list_remove(remote_list, text);
903 g_string_append(command, " ");
904 g_string_append(command, text);
906 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0)
913 if (blank || cmd_list || path) g_string_append(command, " --blank");
914 if (get_debug_level()) g_string_append(command, " --debug");
916 g_string_append(command, " &");
917 runcmd(command->str);
918 g_string_free(command, TRUE);
920 while (!rc && retry_count > 0)
922 usleep((retry_count > 10) ? 500000 : 1000000);
923 rc = remote_client_open(buf);
924 if (!rc) print_term(".");
938 gboolean use_path = TRUE;
939 gboolean sent = FALSE;
945 RemoteCommandEntry *entry;
950 entry = remote_command_find(text, NULL);
953 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE;
955 remote_client_send(rc, text);
960 if (cmd_list && cmd_list->next)
962 prefix = "--list-add:";
963 remote_client_send(rc, "--list-clear");
979 text = g_strconcat(prefix, fd->path, NULL);
980 remote_client_send(rc, text);
986 if (path && !cmd_list && use_path)
990 text = g_strdup_printf("file:%s", path);
991 remote_client_send(rc, text);
997 work = collection_list;
1006 text = g_strdup_printf("file:%s", name);
1007 remote_client_send(rc, text);
1013 if (!started && !sent)
1015 remote_client_send(rc, "raise");
1020 print_term(_("Remote not available\n"));
1026 RemoteConnection *remote_server_init(gchar *path, CollectionData *command_collection)
1028 RemoteConnection *remote_connection = remote_server_open(path);
1029 RemoteData *remote_data = g_new(RemoteData, 1);
1031 remote_data->command_collection = command_collection;
1033 remote_server_subscribe(remote_connection, remote_cb, remote_data);
1034 return remote_connection;
1036 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */