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>
44 #define SERVER_MAX_CLIENTS 8
46 #define REMOTE_SERVER_BACKLOG 4
50 #define UNIX_PATH_MAX 108
54 static RemoteConnection *remote_client_open(const gchar *path);
55 static gint remote_client_send(RemoteConnection *rc, const gchar *text);
56 static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data);
59 typedef struct _RemoteClient RemoteClient;
60 struct _RemoteClient {
62 guint channel_id; /* event source id */
66 typedef struct _RemoteData RemoteData;
68 CollectionData *command_collection;
72 static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition condition, gpointer data)
74 RemoteClient *client = data;
76 GIOStatus status = G_IO_STATUS_NORMAL;
80 if (condition & G_IO_IN)
86 while ((status = g_io_channel_read_line(source, &buffer, NULL, &termpos, &error)) == G_IO_STATUS_NORMAL)
90 buffer[termpos] = '\0';
92 if (strlen(buffer) > 0)
94 if (rc->read_func) rc->read_func(rc, buffer, source, rc->read_data);
95 g_io_channel_write_chars(source, "\n", -1, NULL, NULL); /* empty line finishes the command */
96 g_io_channel_flush(source, NULL);
106 log_printf("error reading socket: %s\n", error->message);
111 if (condition & G_IO_HUP || status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR)
113 rc->clients = g_list_remove(rc->clients, client);
115 DEBUG_1("HUP detected, closing client.");
116 DEBUG_1("client count %d", g_list_length(rc->clients));
118 g_source_remove(client->channel_id);
126 static void remote_server_client_add(RemoteConnection *rc, gint fd)
128 RemoteClient *client;
131 if (g_list_length(rc->clients) > SERVER_MAX_CLIENTS)
133 log_printf("maximum remote clients of %d exceeded, closing connection\n", SERVER_MAX_CLIENTS);
138 client = g_new0(RemoteClient, 1);
142 channel = g_io_channel_unix_new(fd);
143 client->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP,
144 remote_server_client_cb, client, NULL);
145 g_io_channel_unref(channel);
147 rc->clients = g_list_append(rc->clients, client);
148 DEBUG_1("client count %d", g_list_length(rc->clients));
151 static void remote_server_clients_close(RemoteConnection *rc)
155 RemoteClient *client = rc->clients->data;
157 rc->clients = g_list_remove(rc->clients, client);
159 g_source_remove(client->channel_id);
165 static gboolean remote_server_read_cb(GIOChannel *source, GIOCondition condition, gpointer data)
167 RemoteConnection *rc = data;
171 fd = accept(rc->fd, NULL, &alen);
174 log_printf("error accepting socket: %s\n", strerror(errno));
178 remote_server_client_add(rc, fd);
183 static gboolean remote_server_exists(const gchar *path)
185 RemoteConnection *rc;
187 /* verify server up */
188 rc = remote_client_open(path);
193 /* unable to connect, remove socket file to free up address */
198 static RemoteConnection *remote_server_open(const gchar *path)
200 RemoteConnection *rc;
201 struct sockaddr_un addr;
206 if (remote_server_exists(path))
208 log_printf("Address already in use: %s\n", path);
212 fd = socket(PF_UNIX, SOCK_STREAM, 0);
213 if (fd == -1) return NULL;
215 addr.sun_family = AF_UNIX;
216 sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX);
217 strncpy(addr.sun_path, path, sun_path_len);
218 if (bind(fd, &addr, sizeof(addr)) == -1 ||
219 listen(fd, REMOTE_SERVER_BACKLOG) == -1)
221 log_printf("error subscribing to socket: %s\n", strerror(errno));
226 rc = g_new0(RemoteConnection, 1);
230 rc->path = g_strdup(path);
232 channel = g_io_channel_unix_new(rc->fd);
233 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
235 rc->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN,
236 remote_server_read_cb, rc, NULL);
237 g_io_channel_unref(channel);
242 static void remote_server_subscribe(RemoteConnection *rc, RemoteReadFunc *func, gpointer data)
244 if (!rc || !rc->server) return;
246 rc->read_func = func;
247 rc->read_data = data;
251 static RemoteConnection *remote_client_open(const gchar *path)
253 RemoteConnection *rc;
255 struct sockaddr_un addr;
259 if (stat(path, &st) != 0 || !S_ISSOCK(st.st_mode)) return NULL;
261 fd = socket(PF_UNIX, SOCK_STREAM, 0);
262 if (fd == -1) return NULL;
264 addr.sun_family = AF_UNIX;
265 sun_path_len = MIN(strlen(path) + 1, UNIX_PATH_MAX);
266 strncpy(addr.sun_path, path, sun_path_len);
267 if (connect(fd, &addr, sizeof(addr)) == -1)
269 DEBUG_1("error connecting to socket: %s", strerror(errno));
274 rc = g_new0(RemoteConnection, 1);
277 rc->path = g_strdup(path);
282 static sig_atomic_t sigpipe_occured = FALSE;
284 static void sighandler_sigpipe(gint sig)
286 sigpipe_occured = TRUE;
289 static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
291 struct sigaction new_action, old_action;
292 gboolean ret = FALSE;
293 GError *error = NULL;
296 if (!rc || rc->server) return FALSE;
297 if (!text) return TRUE;
299 sigpipe_occured = FALSE;
301 new_action.sa_handler = sighandler_sigpipe;
302 sigemptyset(&new_action.sa_mask);
303 new_action.sa_flags = 0;
305 /* setup our signal handler */
306 sigaction(SIGPIPE, &new_action, &old_action);
308 channel = g_io_channel_unix_new(rc->fd);
310 g_io_channel_write_chars(channel, text, -1, NULL, &error);
311 g_io_channel_write_chars(channel, "\n", -1, NULL, &error);
312 g_io_channel_flush(channel, &error);
316 log_printf("error reading socket: %s\n", error->message);
327 gchar *buffer = NULL;
329 while (g_io_channel_read_line(channel, &buffer, NULL, &termpos, &error) == G_IO_STATUS_NORMAL)
333 if (buffer[0] == '\n') /* empty line finishes the command */
339 buffer[termpos] = '\0';
340 printf("%s\n", buffer);
348 log_printf("error reading socket: %s\n", error->message);
355 /* restore the original signal handler */
356 sigaction(SIGPIPE, &old_action, NULL);
357 g_io_channel_unref(channel);
361 void remote_close(RemoteConnection *rc)
367 remote_server_clients_close(rc);
369 g_source_remove(rc->channel_id);
374 g_free(rc->read_data);
383 *-----------------------------------------------------------------------------
385 *-----------------------------------------------------------------------------
388 static void gr_image_next(const gchar *text, GIOChannel *channel, gpointer data)
390 layout_image_next(NULL);
393 static void gr_image_prev(const gchar *text, GIOChannel *channel, gpointer data)
395 layout_image_prev(NULL);
398 static void gr_image_first(const gchar *text, GIOChannel *channel, gpointer data)
400 layout_image_first(NULL);
403 static void gr_image_last(const gchar *text, GIOChannel *channel, gpointer data)
405 layout_image_last(NULL);
408 static void gr_fullscreen_toggle(const gchar *text, GIOChannel *channel, gpointer data)
410 layout_image_full_screen_toggle(NULL);
413 static void gr_fullscreen_start(const gchar *text, GIOChannel *channel, gpointer data)
415 layout_image_full_screen_start(NULL);
418 static void gr_fullscreen_stop(const gchar *text, GIOChannel *channel, gpointer data)
420 layout_image_full_screen_stop(NULL);
423 static void gr_slideshow_start_rec(const gchar *text, GIOChannel *channel, gpointer data)
426 FileData *dir_fd = file_data_new_dir(text);
427 list = filelist_recursive(dir_fd);
428 file_data_unref(dir_fd);
430 //printf("length: %d\n", g_list_length(list));
431 layout_image_slideshow_stop(NULL);
432 layout_image_slideshow_start_from_list(NULL, list);
435 static void gr_cache_thumb(const gchar *text, GIOChannel *channel, gpointer data)
437 if (!g_strcmp0(text, "clear"))
438 cache_maintain_home_remote(FALSE, TRUE);
439 else if (!g_strcmp0(text, "clean"))
440 cache_maintain_home_remote(FALSE, FALSE);
443 static void gr_cache_shared(const gchar *text, GIOChannel *channel, gpointer data)
445 if (!g_strcmp0(text, "clear"))
446 cache_manager_standard_process_remote(TRUE);
447 else if (!g_strcmp0(text, "clean"))
448 cache_manager_standard_process_remote(FALSE);
451 static void gr_cache_metadata(const gchar *text, GIOChannel *channel, gpointer data)
453 cache_maintain_home_remote(TRUE, FALSE);
456 static void gr_cache_render(const gchar *text, GIOChannel *channel, gpointer data)
458 cache_manager_render_remote(text, FALSE, FALSE);
461 static void gr_cache_render_recurse(const gchar *text, GIOChannel *channel, gpointer data)
463 cache_manager_render_remote(text, TRUE, FALSE);
466 static void gr_cache_render_standard(const gchar *text, GIOChannel *channel, gpointer data)
468 if(options->thumbnails.spec_standard)
469 cache_manager_render_remote(text, FALSE, TRUE);
472 static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *channel, gpointer data)
474 if(options->thumbnails.spec_standard)
475 cache_manager_render_remote(text, TRUE, TRUE);
478 static void gr_slideshow_toggle(const gchar *text, GIOChannel *channel, gpointer data)
480 layout_image_slideshow_toggle(NULL);
483 static void gr_slideshow_start(const gchar *text, GIOChannel *channel, gpointer data)
485 layout_image_slideshow_start(NULL);
488 static void gr_slideshow_stop(const gchar *text, GIOChannel *channel, gpointer data)
490 layout_image_slideshow_stop(NULL);
493 static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer data)
497 n = g_ascii_strtod(text, NULL);
498 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
500 printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
501 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
504 options->slideshow.delay = (gint)(n * 10.0 + 0.01);
507 static void gr_tools_show(const gchar *text, GIOChannel *channel, gpointer data)
512 if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
514 layout_tools_float_set(NULL, popped, FALSE);
518 static void gr_tools_hide(const gchar *text, GIOChannel *channel, gpointer data)
523 if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
525 layout_tools_float_set(NULL, popped, TRUE);
529 static gboolean gr_quit_idle_cb(gpointer data)
536 static void gr_quit(const gchar *text, GIOChannel *channel, gpointer data)
538 /* schedule exit when idle, if done from within a
539 * remote handler remote_close will crash
541 g_idle_add(gr_quit_idle_cb, NULL);
544 static void gr_file_load_no_raise(const gchar *text, GIOChannel *channel, gpointer data)
546 gchar *filename = expand_tilde(text);
548 if (isfile(filename))
550 if (file_extension_match(filename, GQ_COLLECTION_EXT))
552 collection_window_new(filename);
556 layout_set_path(NULL, filename);
559 else if (isdir(filename))
561 layout_set_path(NULL, filename);
565 log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
566 layout_set_path(NULL, homedir());
572 static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data)
574 gr_file_load_no_raise(text, channel, data);
576 gr_raise(text, channel, data);
579 static void gr_file_tell(const gchar *text, GIOChannel *channel, gpointer data)
581 LayoutWindow *lw = NULL; /* NULL to force layout_valid() to do some magic */
582 if (!layout_valid(&lw)) return;
583 if (image_get_path(lw->image))
585 g_io_channel_write_chars(channel, image_get_path(lw->image), -1, NULL, NULL);
586 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
590 static void gr_config_load(const gchar *text, GIOChannel *channel, gpointer data)
592 gchar *filename = expand_tilde(text);
594 if (isfile(filename))
596 load_config_from_file(filename, FALSE);
600 log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
601 layout_set_path(NULL, homedir());
607 static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer data)
609 gchar *filename = expand_tilde(text);
610 FileData *fd = file_data_new_group(filename);
613 if (fd->parent) fd = fd->parent;
615 g_io_channel_write_chars(channel, fd->path, -1, NULL, NULL);
616 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
618 work = fd->sidecar_files;
624 g_io_channel_write_chars(channel, fd->path, -1, NULL, NULL);
625 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
630 static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer data)
632 gchar *filename = expand_tilde(text);
633 FileData *fd = file_data_new_group(filename);
635 if (fd->change && fd->change->dest)
637 g_io_channel_write_chars(channel, fd->change->dest, -1, NULL, NULL);
638 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
643 static void gr_file_view(const gchar *text, GIOChannel *channel, gpointer data)
645 gchar *filename = expand_tilde(text);
647 view_window_new(file_data_new_group(filename));
651 static void gr_list_clear(const gchar *text, GIOChannel *channel, gpointer data)
653 RemoteData *remote_data = data;
655 if (remote_data->command_collection)
657 collection_unref(remote_data->command_collection);
658 remote_data->command_collection = NULL;
662 static void gr_list_add(const gchar *text, GIOChannel *channel, gpointer data)
664 RemoteData *remote_data = data;
667 if (!remote_data->command_collection)
671 cd = collection_new("");
676 cd->name = g_strdup(_("Command line"));
678 remote_data->command_collection = cd;
682 new = (!collection_get_first(remote_data->command_collection));
685 if (collection_add(remote_data->command_collection, file_data_new_group(text), FALSE) && new)
687 layout_image_set_collection(NULL, remote_data->command_collection,
688 collection_get_first(remote_data->command_collection));
692 static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data)
694 LayoutWindow *lw = NULL;
696 if (layout_valid(&lw))
698 gtk_window_present(GTK_WINDOW(lw->window));
703 static void gr_lua(const gchar *text, GIOChannel *channel, gpointer data)
705 gchar *result = NULL;
708 lua_command = g_strsplit(text, ",", 2);
710 if (lua_command[0] && lua_command[1])
712 FileData *fd = file_data_new_group(lua_command[0]);
713 result = g_strdup(lua_callvalue(fd, lua_command[1], NULL));
716 g_io_channel_write_chars(channel, result, -1, NULL, NULL);
720 g_io_channel_write_chars(channel, N_("lua error: no data"), -1, NULL, NULL);
725 g_io_channel_write_chars(channel, N_("lua error: no data"), -1, NULL, NULL);
728 g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
730 g_strfreev(lua_command);
735 typedef struct _RemoteCommandEntry RemoteCommandEntry;
736 struct _RemoteCommandEntry {
739 void (*func)(const gchar *text, GIOChannel *channel, gpointer data);
740 gboolean needs_extra;
741 gboolean prefer_command_line;
746 static RemoteCommandEntry remote_commands[] = {
747 /* short, long callback, extra, prefer, parameter, description */
748 { "-n", "--next", gr_image_next, FALSE, FALSE, NULL, N_("next image") },
749 { "-b", "--back", gr_image_prev, FALSE, FALSE, NULL, N_("previous image") },
750 { NULL, "--first", gr_image_first, FALSE, FALSE, NULL, N_("first image") },
751 { NULL, "--last", gr_image_last, FALSE, FALSE, NULL, N_("last image") },
752 { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, NULL, N_("toggle full screen") },
753 { "-fs","--fullscreen-start", gr_fullscreen_start, FALSE, FALSE, NULL, N_("start full screen") },
754 { "-fS","--fullscreen-stop", gr_fullscreen_stop, FALSE, FALSE, NULL, N_("stop full screen") },
755 { "-s", "--slideshow", gr_slideshow_toggle, FALSE, TRUE, NULL, N_("toggle slide show") },
756 { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, NULL, N_("start slide show") },
757 { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, NULL, N_("stop slide show") },
758 { NULL, "--slideshow-recurse:", gr_slideshow_start_rec, TRUE, FALSE, N_("<FOLDER>"), N_("start recursive slide show in FOLDER") },
759 { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("<[N][.M]>"), N_("set slide show delay to N.M seconds") },
760 { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, NULL, N_("show tools") },
761 { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, NULL, N_("hide tools") },
762 { "-q", "--quit", gr_quit, FALSE, FALSE, NULL, N_("quit") },
763 { NULL, "--config-load:", gr_config_load, TRUE, FALSE, N_("<FILE>"), N_("load configuration from FILE") },
764 { NULL, "--get-sidecars:", gr_get_sidecars, TRUE, FALSE, N_("<FILE>"), N_("get list of sidecars of FILE") },
765 { NULL, "--get-destination:", gr_get_destination, TRUE, FALSE, N_("<FILE>"), N_("get destination path of FILE") },
766 { NULL, "file:", gr_file_load, TRUE, FALSE, N_("<FILE>"), N_("open FILE, bring Geeqie window to the top") },
767 { NULL, "File:", gr_file_load_no_raise, TRUE, FALSE, N_("<FILE>"), N_("open FILE, do not bring Geeqie window to the top") },
768 { NULL, "--tell", gr_file_tell, FALSE, FALSE, NULL, N_("print filename of current image") },
769 { NULL, "view:", gr_file_view, TRUE, FALSE, N_("<FILE>"), N_("open FILE in new window") },
770 { NULL, "--list-clear", gr_list_clear, FALSE, FALSE, NULL, N_("clear command line collection list") },
771 { NULL, "--list-add:", gr_list_add, TRUE, FALSE, N_("<FILE>"), N_("add FILE to command line collection list") },
772 { NULL, "raise", gr_raise, FALSE, FALSE, NULL, N_("bring the Geeqie window to the top") },
773 { "-ct:", "--cache-thumbs:", gr_cache_thumb, TRUE, FALSE, N_("clear|clean"), N_("clear or clean thumbnail cache") },
774 { "-cs:", "--cache-shared:", gr_cache_shared, TRUE, FALSE, N_("clear|clean"), N_("clear or clean shared thumbnail cache") },
775 { "-cm","--cache-metadata", gr_cache_metadata, FALSE, FALSE, NULL, N_(" clean the metadata cache") },
776 { "-cr:", "--cache-render:", gr_cache_render, TRUE, FALSE, N_("<folder> "), N_(" render thumbnails") },
777 { "-crr:", "--cache-render-recurse:", gr_cache_render_recurse, TRUE, FALSE, N_("<folder> "), N_("render thumbnails recursively") },
778 { "-crs:", "--cache-render-shared:", gr_cache_render_standard, TRUE, FALSE, N_("<folder> "), N_(" render thumbnails (see Help)") },
779 { "-crsr:", "--cache-render-shared-recurse:", gr_cache_render_standard_recurse, TRUE, FALSE, N_("<folder>"), N_(" render thumbnails recursively (see Help)") },
781 { NULL, "--lua:", gr_lua, TRUE, FALSE, N_("<FILE>,<lua script>"), N_("run lua script on FILE") },
783 { NULL, NULL, NULL, FALSE, FALSE, NULL, NULL }
786 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset)
788 gboolean match = FALSE;
792 while (!match && remote_commands[i].func != NULL)
794 if (remote_commands[i].needs_extra)
796 if (remote_commands[i].opt_s &&
797 strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0)
799 if (offset) *offset = text + strlen(remote_commands[i].opt_s);
800 return &remote_commands[i];
802 else if (remote_commands[i].opt_l &&
803 strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
805 if (offset) *offset = text + strlen(remote_commands[i].opt_l);
806 return &remote_commands[i];
811 if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) ||
812 (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0))
814 if (offset) *offset = text;
815 return &remote_commands[i];
825 static void remote_cb(RemoteConnection *rc, const gchar *text, GIOChannel *channel, gpointer data)
827 RemoteCommandEntry *entry;
830 entry = remote_command_find(text, &offset);
831 if (entry && entry->func)
833 entry->func(offset, channel, data);
837 log_printf("unknown remote command:%s\n", text);
841 void remote_help(void)
847 print_term(_("Remote command list:\n"));
850 while (remote_commands[i].func != NULL)
852 if (remote_commands[i].description)
854 s_opt_param = g_strconcat(remote_commands[i].opt_s, remote_commands[i].parameter, NULL);
855 l_opt_param = g_strconcat(remote_commands[i].opt_l, remote_commands[i].parameter, NULL);
856 printf_term(" %-11s%-1s %-30s%-s\n",
857 (remote_commands[i].opt_s) ? s_opt_param : "",
858 (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
859 (remote_commands[i].opt_l) ? l_opt_param : "",
860 _(remote_commands[i].description));
866 printf_term(N_("\n All other command line parameters are used as plain files if they exists.\n"));
869 GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
876 RemoteCommandEntry *entry;
878 entry = remote_command_find(argv[i], NULL);
881 list = g_list_append(list, argv[i]);
883 else if (errors && !isfile(argv[i]))
885 *errors = g_list_append(*errors, argv[i]);
894 * \param arg_exec Binary (argv0)
895 * \param remote_list Evaluated and recognized remote commands
896 * \param path The current path
897 * \param cmd_list List of all non collections in Path
898 * \param collection_list List of all collections in argv
900 void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
901 GList *cmd_list, GList *collection_list)
903 RemoteConnection *rc;
904 gboolean started = FALSE;
907 buf = g_build_filename(get_rc_dir(), ".command", NULL);
908 rc = remote_client_open(buf);
913 gint retry_count = 12;
914 gboolean blank = FALSE;
916 printf_term(_("Remote %s not running, starting..."), GQ_APPNAME);
918 command = g_string_new(arg_exec);
924 RemoteCommandEntry *entry;
929 entry = remote_command_find(text, NULL);
932 if (entry->prefer_command_line)
934 remote_list = g_list_remove(remote_list, text);
935 g_string_append(command, " ");
936 g_string_append(command, text);
938 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0)
945 if (blank || cmd_list || path) g_string_append(command, " --blank");
946 if (get_debug_level()) g_string_append(command, " --debug");
948 g_string_append(command, " &");
949 runcmd(command->str);
950 g_string_free(command, TRUE);
952 while (!rc && retry_count > 0)
954 usleep((retry_count > 10) ? 500000 : 1000000);
955 rc = remote_client_open(buf);
956 if (!rc) print_term(".");
970 gboolean use_path = TRUE;
971 gboolean sent = FALSE;
977 RemoteCommandEntry *entry;
982 entry = remote_command_find(text, NULL);
985 strcmp(entry->opt_l, "file:") == 0) use_path = FALSE;
987 remote_client_send(rc, text);
992 if (cmd_list && cmd_list->next)
994 prefix = "--list-add:";
995 remote_client_send(rc, "--list-clear");
1011 text = g_strconcat(prefix, fd->path, NULL);
1012 remote_client_send(rc, text);
1018 if (path && !cmd_list && use_path)
1022 text = g_strdup_printf("file:%s", path);
1023 remote_client_send(rc, text);
1029 work = collection_list;
1038 text = g_strdup_printf("file:%s", name);
1039 remote_client_send(rc, text);
1045 if (!started && !sent)
1047 remote_client_send(rc, "raise");
1052 print_term(_("Remote not available\n"));
1058 RemoteConnection *remote_server_init(gchar *path, CollectionData *command_collection)
1060 RemoteConnection *remote_connection = remote_server_open(path);
1061 RemoteData *remote_data = g_new(RemoteData, 1);
1063 remote_data->command_collection = command_collection;
1065 remote_server_subscribe(remote_connection, remote_cb, remote_data);
1066 return remote_connection;
1068 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */