Silence GTK deprecation warning in unused function
[geeqie.git] / src / remote.cc
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include "remote.h"
23
24 #include <sys/socket.h>
25 #include <sys/stat.h>
26 #include <sys/un.h>
27 #include <unistd.h>
28
29 #include <cerrno>
30 #include <csignal>
31 #include <cstdio>
32 #include <cstdlib>
33 #include <cstring>
34
35 #include <config.h>
36
37 #include <gtk/gtk.h>
38
39 #include "cache-maint.h"
40 #include "collect-io.h"
41 #include "collect.h"
42 #include "compat.h"
43 #include "debug.h"
44 #include "exif.h"
45 #include "filedata.h"
46 #include "filefilter.h"
47 #include "glua.h"
48 #include "image.h"
49 #include "img-view.h"
50 #include "intl.h"
51 #include "layout-image.h"
52 #include "layout-util.h"
53 #include "layout.h"
54 #include "main-defines.h"
55 #include "main.h"
56 #include "misc.h"
57 #include "options.h"
58 #include "pixbuf-renderer.h"
59 #include "rcfile.h"
60 #include "slideshow.h"
61 #include "typedefs.h"
62 #include "ui-fileops.h"
63 #include "ui-misc.h"
64 #include "utilops.h"
65 #include "view-file.h"
66
67 #ifndef UNIX_PATH_MAX
68 #define UNIX_PATH_MAX 108
69 #endif
70
71 namespace
72 {
73
74 constexpr guint SERVER_MAX_CLIENTS = 8;
75 constexpr int REMOTE_SERVER_BACKLOG = 4;
76
77 } // namespace
78
79 static RemoteConnection *remote_client_open(const gchar *path);
80 static gint remote_client_send(RemoteConnection *rc, const gchar *text);
81 static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data);
82
83 static LayoutWindow *lw_id = nullptr; /* points to the window set by the --id option */
84
85 struct RemoteClient {
86         gint fd;
87         guint channel_id; /* event source id */
88         RemoteConnection *rc;
89 };
90
91 struct RemoteData {
92         CollectionData *command_collection;
93         GList *file_list;
94         gboolean single_dir;
95 };
96
97 /* To enable file names containing newlines to be processed correctly,
98  * the --print0 remote option sets returned data to be terminated with a null
99  * character rather a newline
100  */
101 static gboolean print0 = FALSE;
102
103 /* Remote commands from main.cc are prepended with the current dir the remote
104  * command was made from. Some remote commands require this. The
105  * value is stored here
106  */
107 static gchar *pwd = nullptr;
108
109 /**
110  * @brief Ensures file path is absolute.
111  * @param[in] filename Filepath, absolute or relative to calling directory
112  * @returns absolute path
113  *
114  * If first character of input filepath is not the directory
115  * separator, assume it as a relative path and prepend
116  * the directory the remote command was initiated from
117  *
118  * Return value must be freed with g_free()
119  */
120 static gchar *set_pwd(gchar *filename)
121 {
122         gchar *temp;
123
124         if (strncmp(filename, G_DIR_SEPARATOR_S, 1) != 0)
125                 {
126                 temp = g_build_filename(pwd, filename, NULL);
127                 }
128         else
129                 {
130                 temp = g_strdup(filename);
131                 }
132
133         return temp;
134 }
135
136 static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition condition, gpointer data)
137 {
138         auto client = static_cast<RemoteClient *>(data);
139         RemoteConnection *rc;
140         GIOStatus status = G_IO_STATUS_NORMAL;
141
142         lw_id = nullptr;
143         rc = client->rc;
144
145         if (condition & G_IO_IN)
146                 {
147                 gchar *buffer = nullptr;
148                 GError *error = nullptr;
149                 gsize termpos;
150                 /** @FIXME it should be possible to terminate the command with a null character */
151                 g_io_channel_set_line_term(source, "<gq_end_of_command>", -1);
152                 while ((status = g_io_channel_read_line(source, &buffer, nullptr, &termpos, &error)) == G_IO_STATUS_NORMAL)
153                         {
154                         if (buffer)
155                                 {
156                                 buffer[termpos] = '\0';
157
158                                 if (strlen(buffer) > 0)
159                                         {
160                                         if (rc->read_func) rc->read_func(rc, buffer, source, rc->read_data);
161                                         g_io_channel_write_chars(source, "<gq_end_of_command>", -1, nullptr, nullptr); /* empty line finishes the command */
162                                         g_io_channel_flush(source, nullptr);
163                                         }
164                                 g_free(buffer);
165
166                                 buffer = nullptr;
167                                 }
168                         }
169
170                 if (error)
171                         {
172                         log_printf("error reading socket: %s\n", error->message);
173                         g_error_free(error);
174                         }
175                 }
176
177         if (condition & G_IO_HUP || status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR)
178                 {
179                 rc->clients = g_list_remove(rc->clients, client);
180
181                 DEBUG_1("HUP detected, closing client.");
182                 DEBUG_1("client count %d", g_list_length(rc->clients));
183
184                 g_source_remove(client->channel_id);
185                 close(client->fd);
186                 g_free(client);
187                 }
188
189         return TRUE;
190 }
191
192 static void remote_server_client_add(RemoteConnection *rc, gint fd)
193 {
194         RemoteClient *client;
195         GIOChannel *channel;
196
197         if (g_list_length(rc->clients) > SERVER_MAX_CLIENTS)
198                 {
199                 log_printf("maximum remote clients of %d exceeded, closing connection\n", SERVER_MAX_CLIENTS);
200                 close(fd);
201                 return;
202                 }
203
204         client = g_new0(RemoteClient, 1);
205         client->rc = rc;
206         client->fd = fd;
207
208         channel = g_io_channel_unix_new(fd);
209         client->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, static_cast<GIOCondition>(G_IO_IN | G_IO_HUP),
210                                                  remote_server_client_cb, client, nullptr);
211         g_io_channel_unref(channel);
212
213         rc->clients = g_list_append(rc->clients, client);
214         DEBUG_1("client count %d", g_list_length(rc->clients));
215 }
216
217 static void remote_server_clients_close(RemoteConnection *rc)
218 {
219         while (rc->clients)
220                 {
221                 auto client = static_cast<RemoteClient *>(rc->clients->data);
222
223                 rc->clients = g_list_remove(rc->clients, client);
224
225                 g_source_remove(client->channel_id);
226                 close(client->fd);
227                 g_free(client);
228                 }
229 }
230
231 static gboolean remote_server_read_cb(GIOChannel *, GIOCondition, gpointer data)
232 {
233         auto rc = static_cast<RemoteConnection *>(data);
234         gint fd;
235         guint alen;
236
237         fd = accept(rc->fd, nullptr, &alen);
238         if (fd == -1)
239                 {
240                 log_printf("error accepting socket: %s\n", strerror(errno));
241                 return TRUE;
242                 }
243
244         remote_server_client_add(rc, fd);
245
246         return TRUE;
247 }
248
249 gboolean remote_server_exists(const gchar *path)
250 {
251         RemoteConnection *rc;
252
253         /* verify server up */
254         rc = remote_client_open(path);
255         remote_close(rc);
256
257         if (rc) return TRUE;
258
259         /* unable to connect, remove socket file to free up address */
260         unlink(path);
261         return FALSE;
262 }
263
264 static RemoteConnection *remote_server_open(const gchar *path)
265 {
266         RemoteConnection *rc;
267         struct sockaddr_un addr;
268         gint fd;
269         GIOChannel *channel;
270
271         if (strlen(path) >= sizeof(addr.sun_path))
272                 {
273                 log_printf("Address is too long: %s\n", path);
274                 return nullptr;
275                 }
276
277         if (remote_server_exists(path))
278                 {
279                 log_printf("Address already in use: %s\n", path);
280                 return nullptr;
281                 }
282
283         fd = socket(PF_UNIX, SOCK_STREAM, 0);
284         if (fd == -1) return nullptr;
285
286         addr.sun_family = AF_UNIX;
287 #pragma GCC diagnostic push
288 #pragma GCC diagnostic ignored "-Wstringop-truncation"
289         strncpy(addr.sun_path, path, sizeof(addr.sun_path));
290 #pragma GCC diagnostic pop
291         if (bind(fd, reinterpret_cast<const struct sockaddr*>(&addr), sizeof(addr)) == -1 ||
292             listen(fd, REMOTE_SERVER_BACKLOG) == -1)
293                 {
294                 log_printf("error subscribing to socket: %s\n", strerror(errno));
295                 close(fd);
296                 return nullptr;
297                 }
298
299         rc = g_new0(RemoteConnection, 1);
300
301         rc->server = TRUE;
302         rc->fd = fd;
303         rc->path = g_strdup(path);
304
305         channel = g_io_channel_unix_new(rc->fd);
306         g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, nullptr);
307
308         rc->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN,
309                                              remote_server_read_cb, rc, nullptr);
310         g_io_channel_unref(channel);
311
312         return rc;
313 }
314
315 static void remote_server_subscribe(RemoteConnection *rc, RemoteConnection::ReadFunc *func, gpointer data)
316 {
317         if (!rc || !rc->server) return;
318
319         rc->read_func = func;
320         rc->read_data = data;
321 }
322
323
324 static RemoteConnection *remote_client_open(const gchar *path)
325 {
326         RemoteConnection *rc;
327         struct stat st;
328         struct sockaddr_un addr;
329         gint fd;
330
331         if (strlen(path) >= sizeof(addr.sun_path)) return nullptr;
332
333         if (stat(path, &st) != 0 || !S_ISSOCK(st.st_mode)) return nullptr;
334
335         fd = socket(PF_UNIX, SOCK_STREAM, 0);
336         if (fd == -1) return nullptr;
337
338         addr.sun_family = AF_UNIX;
339 #pragma GCC diagnostic push
340 #pragma GCC diagnostic ignored "-Wstringop-truncation"
341         strncpy(addr.sun_path, path, sizeof(addr.sun_path));
342 #pragma GCC diagnostic pop
343         if (connect(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) == -1)
344                 {
345                 DEBUG_1("error connecting to socket: %s", strerror(errno));
346                 close(fd);
347                 return nullptr;
348                 }
349
350         rc = g_new0(RemoteConnection, 1);
351         rc->server = FALSE;
352         rc->fd = fd;
353         rc->path = g_strdup(path);
354
355         return rc;
356 }
357
358 static sig_atomic_t sigpipe_occurred = FALSE;
359
360 static void sighandler_sigpipe(gint)
361 {
362         sigpipe_occurred = TRUE;
363 }
364
365 static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
366 {
367         struct sigaction new_action;
368         struct sigaction old_action;
369         gboolean ret = FALSE;
370         GError *error = nullptr;
371         GIOChannel *channel;
372
373         if (!rc || rc->server) return FALSE;
374         if (!text) return TRUE;
375
376         sigpipe_occurred = FALSE;
377
378         new_action.sa_handler = sighandler_sigpipe;
379         sigemptyset(&new_action.sa_mask);
380         new_action.sa_flags = 0;
381
382         /* setup our signal handler */
383         sigaction(SIGPIPE, &new_action, &old_action);
384
385         channel = g_io_channel_unix_new(rc->fd);
386
387         g_io_channel_write_chars(channel, text, -1, nullptr, &error);
388         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, &error);
389         g_io_channel_flush(channel, &error);
390
391         if (error)
392                 {
393                 log_printf("error reading socket: %s\n", error->message);
394                 g_error_free(error);
395                 ret = FALSE;;
396                 }
397         else
398                 {
399                 ret = TRUE;
400                 }
401
402         if (ret)
403                 {
404                 gchar *buffer = nullptr;
405                 gsize termpos;
406                 g_io_channel_set_line_term(channel, "<gq_end_of_command>", -1);
407                 while (g_io_channel_read_line(channel, &buffer, nullptr, &termpos, &error) == G_IO_STATUS_NORMAL)
408                         {
409                         if (buffer)
410                                 {
411                                 if (g_strstr_len(buffer, -1, "<gq_end_of_command>") == buffer) /* empty line finishes the command */
412                                         {
413                                         g_free(buffer);
414                                         fflush(stdout);
415                                         break;
416                                         }
417                                 buffer[termpos] = '\0';
418                                 if (g_strstr_len(buffer, -1, "print0") != nullptr)
419                                         {
420                                         print0 = TRUE;
421                                         }
422                                 else
423                                         {
424                                         if (print0)
425                                                 {
426                                                 printf("%s%c", buffer, 0);
427                                                 }
428                                         else
429                                                 {
430                                                 printf("%s\n", buffer);
431                                                 }
432                                         }
433                                 g_free(buffer);
434                                 buffer = nullptr;
435                                 }
436                         }
437
438                 if (error)
439                         {
440                         log_printf("error reading socket: %s\n", error->message);
441                         g_error_free(error);
442                         ret = FALSE;
443                         }
444                 }
445
446
447         /* restore the original signal handler */
448         sigaction(SIGPIPE, &old_action, nullptr);
449         g_io_channel_unref(channel);
450         return ret;
451 }
452
453 void remote_close(RemoteConnection *rc)
454 {
455         if (!rc) return;
456
457         if (rc->server)
458                 {
459                 remote_server_clients_close(rc);
460
461                 g_source_remove(rc->channel_id);
462                 unlink(rc->path);
463                 }
464
465         if (rc->read_data)
466                 g_free(rc->read_data);
467
468         close(rc->fd);
469
470         g_free(rc->path);
471         g_free(rc);
472 }
473
474 /*
475  *-----------------------------------------------------------------------------
476  * remote functions
477  *-----------------------------------------------------------------------------
478  */
479
480 static void gr_image_next(const gchar *, GIOChannel *, gpointer)
481 {
482         layout_image_next(lw_id);
483 }
484
485 static void gr_new_window(const gchar *, GIOChannel *, gpointer)
486 {
487         LayoutWindow *lw = nullptr;
488
489         if (!layout_valid(&lw)) return;
490
491         lw_id = layout_new_from_default();
492
493         layout_set_path(lw_id, pwd);
494 }
495
496 static gboolean gr_close_window_cb(gpointer)
497 {
498         if (!layout_valid(&lw_id)) return FALSE;
499
500         layout_menu_close_cb(nullptr, lw_id);
501
502         return G_SOURCE_REMOVE;
503 }
504
505 static void gr_close_window(const gchar *, GIOChannel *, gpointer)
506 {
507         g_idle_add((gr_close_window_cb), nullptr);
508 }
509
510 static void gr_image_prev(const gchar *, GIOChannel *, gpointer)
511 {
512         layout_image_prev(lw_id);
513 }
514
515 static void gr_image_first(const gchar *, GIOChannel *, gpointer)
516 {
517         layout_image_first(lw_id);
518 }
519
520 static void gr_image_last(const gchar *, GIOChannel *, gpointer)
521 {
522         layout_image_last(lw_id);
523 }
524
525 static void gr_fullscreen_toggle(const gchar *, GIOChannel *, gpointer)
526 {
527         layout_image_full_screen_toggle(lw_id);
528 }
529
530 static void gr_fullscreen_start(const gchar *, GIOChannel *, gpointer)
531 {
532         layout_image_full_screen_start(lw_id);
533 }
534
535 static void gr_fullscreen_stop(const gchar *, GIOChannel *, gpointer)
536 {
537         layout_image_full_screen_stop(lw_id);
538 }
539
540 static void gr_lw_id(const gchar *text, GIOChannel *, gpointer)
541 {
542         lw_id = layout_find_by_layout_id(text);
543         if (!lw_id)
544                 {
545                 log_printf("remote sent window ID that does not exist:\"%s\"\n",text);
546                 }
547         layout_valid(&lw_id);
548 }
549
550 static void gr_slideshow_start_rec(const gchar *text, GIOChannel *, gpointer)
551 {
552         GList *list;
553         gchar *tilde_filename;
554
555         tilde_filename = expand_tilde(text);
556
557         FileData *dir_fd = file_data_new_dir(tilde_filename);
558         g_free(tilde_filename);
559
560         layout_valid(&lw_id);
561         list = filelist_recursive_full(dir_fd, lw_id->options.file_view_list_sort.method, lw_id->options.file_view_list_sort.ascend, lw_id->options.file_view_list_sort.case_sensitive);
562         file_data_unref(dir_fd);
563         if (!list) return;
564
565         layout_image_slideshow_stop(lw_id);
566         layout_image_slideshow_start_from_list(lw_id, list);
567 }
568
569 static void gr_cache_thumb(const gchar *text, GIOChannel *, gpointer)
570 {
571         if (!g_strcmp0(text, "clear"))
572                 {
573                 cache_maintain_home_remote(FALSE, TRUE, nullptr);
574                 }
575         else if (!g_strcmp0(text, "clean"))
576                 {
577                 cache_maintain_home_remote(FALSE, FALSE, nullptr);
578                 }
579 }
580
581 static void gr_cache_shared(const gchar *text, GIOChannel *, gpointer)
582 {
583         if (!g_strcmp0(text, "clear"))
584                 cache_manager_standard_process_remote(TRUE);
585         else if (!g_strcmp0(text, "clean"))
586                 cache_manager_standard_process_remote(FALSE);
587 }
588
589 static void gr_cache_metadata(const gchar *, GIOChannel *, gpointer)
590 {
591         cache_maintain_home_remote(TRUE, FALSE, nullptr);
592 }
593
594 static void gr_cache_render(const gchar *text, GIOChannel *, gpointer)
595 {
596         cache_manager_render_remote(text, FALSE, FALSE, nullptr);
597 }
598
599 static void gr_cache_render_recurse(const gchar *text, GIOChannel *, gpointer)
600 {
601         cache_manager_render_remote(text, TRUE, FALSE, nullptr);
602 }
603
604 static void gr_cache_render_standard(const gchar *text, GIOChannel *, gpointer)
605 {
606         if(options->thumbnails.spec_standard)
607                 {
608                 cache_manager_render_remote(text, FALSE, TRUE, nullptr);
609                 }
610 }
611
612 static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *, gpointer)
613 {
614         if(options->thumbnails.spec_standard)
615                 {
616                 cache_manager_render_remote(text, TRUE, TRUE, nullptr);
617                 }
618 }
619
620 static void gr_slideshow_toggle(const gchar *, GIOChannel *, gpointer)
621 {
622         layout_image_slideshow_toggle(lw_id);
623 }
624
625 static void gr_slideshow_start(const gchar *, GIOChannel *, gpointer)
626 {
627         layout_image_slideshow_start(lw_id);
628 }
629
630 static void gr_slideshow_stop(const gchar *, GIOChannel *, gpointer)
631 {
632         layout_image_slideshow_stop(lw_id);
633 }
634
635 static void gr_slideshow_delay(const gchar *text, GIOChannel *, gpointer)
636 {
637         gdouble t1;
638         gdouble t2;
639         gdouble t3;
640         gdouble n;
641         gint res;
642
643         res = sscanf(text, "%lf:%lf:%lf", &t1, &t2, &t3);
644         if (res == 3)
645                 {
646                 n = (t1 * 3600) + (t2 * 60) + t3;
647                 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS ||
648                                 t1 >= 24 || t2 >= 60 || t3 >= 60)
649                         {
650                         printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
651                                                                 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
652                         return;
653                         }
654                 }
655         else if (res == 2)
656                 {
657                 n = t1 * 60 + t2;
658                 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS ||
659                                 t1 >= 60 || t2 >= 60)
660                         {
661                         printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
662                                                                 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
663                         return;
664                         }
665                 }
666         else if (res == 1)
667                 {
668                 n = t1;
669                 if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
670                         {
671                         printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
672                                                                 SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
673                         return;
674                         }
675                 }
676         else
677                 {
678                 n = 0;
679                 }
680
681         options->slideshow.delay = static_cast<gint>(n * 10.0 + 0.01);
682 }
683
684 static void gr_tools_show(const gchar *, GIOChannel *, gpointer)
685 {
686         gboolean popped;
687         gboolean hidden;
688
689         if (layout_tools_float_get(lw_id, &popped, &hidden) && hidden)
690                 {
691                 layout_tools_float_set(lw_id, popped, FALSE);
692                 }
693 }
694
695 static void gr_tools_hide(const gchar *, GIOChannel *, gpointer)
696 {
697         gboolean popped;
698         gboolean hidden;
699
700         if (layout_tools_float_get(lw_id, &popped, &hidden) && !hidden)
701                 {
702                 layout_tools_float_set(lw_id, popped, TRUE);
703                 }
704 }
705
706 static gboolean gr_quit_idle_cb(gpointer)
707 {
708         exit_program();
709
710         return G_SOURCE_REMOVE;
711 }
712
713 static void gr_quit(const gchar *, GIOChannel *, gpointer)
714 {
715         /* schedule exit when idle, if done from within a
716          * remote handler remote_close will crash
717          */
718         g_idle_add(gr_quit_idle_cb, nullptr);
719 }
720
721 static void gr_file_load_no_raise(const gchar *text, GIOChannel *, gpointer)
722 {
723         gchar *filename;
724         gchar *tilde_filename;
725
726         if (!download_web_file(text, TRUE, nullptr))
727                 {
728                 tilde_filename = expand_tilde(text);
729                 filename = set_pwd(tilde_filename);
730
731                 if (isfile(filename))
732                         {
733                         if (file_extension_match(filename, GQ_COLLECTION_EXT))
734                                 {
735                                 collection_window_new(filename);
736                                 }
737                         else
738                                 {
739                                 layout_set_path(lw_id, filename);
740                                 }
741                         }
742                 else if (isdir(filename))
743                         {
744                         layout_set_path(lw_id, filename);
745                         }
746                 else
747                         {
748                         log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
749                         layout_set_path(lw_id, homedir());
750                         }
751
752                 g_free(filename);
753                 g_free(tilde_filename);
754                 }
755 }
756
757 static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data)
758 {
759         gr_file_load_no_raise(text, channel, data);
760
761         gr_raise(text, channel, data);
762 }
763
764 static void gr_pixel_info(const gchar *, GIOChannel *channel, gpointer)
765 {
766         gchar *pixel_info;
767         gint x_pixel;
768         gint y_pixel;
769         gint width;
770         gint height;
771         gint r_mouse;
772         gint g_mouse;
773         gint b_mouse;
774         PixbufRenderer *pr;
775
776         if (!layout_valid(&lw_id)) return;
777
778         pr = reinterpret_cast<PixbufRenderer*>(lw_id->image->pr);
779
780         if (pr)
781                 {
782                 pixbuf_renderer_get_image_size(pr, &width, &height);
783                 if (width < 1 || height < 1) return;
784
785                 pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
786
787                 if (x_pixel >= 0 && y_pixel >= 0)
788                         {
789                         pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
790                                                          &r_mouse, &g_mouse, &b_mouse);
791
792                         pixel_info = g_strdup_printf(_("[%d,%d]: RGB(%3d,%3d,%3d)"),
793                                                  x_pixel, y_pixel,
794                                                  r_mouse, g_mouse, b_mouse);
795
796                         g_io_channel_write_chars(channel, pixel_info, -1, nullptr, nullptr);
797                         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
798
799                         g_free(pixel_info);
800                         }
801                 else
802                         {
803                         return;
804                         }
805                 }
806         else
807                 {
808                 return;
809                 }
810 }
811
812 static void gr_rectangle(const gchar *, GIOChannel *channel, gpointer)
813 {
814         gchar *rectangle_info;
815         PixbufRenderer *pr;
816         gint x1;
817         gint y1;
818         gint x2;
819         gint y2;
820
821         if (!options->draw_rectangle) return;
822         if (!layout_valid(&lw_id)) return;
823
824         pr = reinterpret_cast<PixbufRenderer*>(lw_id->image->pr);
825
826         if (pr)
827                 {
828                 image_get_rectangle(&x1, &y1, &x2, &y2);
829                 rectangle_info = g_strdup_printf(_("%dx%d+%d+%d"),
830                                         (x2 > x1) ? x2 - x1 : x1 - x2,
831                                         (y2 > y1) ? y2 - y1 : y1 - y2,
832                                         (x2 > x1) ? x1 : x2,
833                                         (y2 > y1) ? y1 : y2);
834
835                 g_io_channel_write_chars(channel, rectangle_info, -1, nullptr, nullptr);
836                 g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
837
838                 g_free(rectangle_info);
839                 }
840 }
841
842 static void gr_render_intent(const gchar *, GIOChannel *channel, gpointer)
843 {
844         gchar *render_intent;
845
846         switch (options->color_profile.render_intent)
847                 {
848                 case 0:
849                         render_intent = g_strdup("Perceptual");
850                         break;
851                 case 1:
852                         render_intent = g_strdup("Relative Colorimetric");
853                         break;
854                 case 2:
855                         render_intent = g_strdup("Saturation");
856                         break;
857                 case 3:
858                         render_intent = g_strdup("Absolute Colorimetric");
859                         break;
860                 default:
861                         render_intent = g_strdup("none");
862                         break;
863                 }
864
865         g_io_channel_write_chars(channel, render_intent, -1, nullptr, nullptr);
866         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
867
868         g_free(render_intent);
869 }
870
871 static void get_filelist(const gchar *text, GIOChannel *channel, gboolean recurse)
872 {
873         GList *list = nullptr;
874         FileFormatClass format_class;
875         FileData *dir_fd;
876         FileData *fd;
877         GList *work;
878         gchar *tilde_filename;
879
880         if (strcmp(text, "") == 0)
881                 {
882                 if (layout_valid(&lw_id))
883                         {
884                         dir_fd = file_data_new_dir(lw_id->dir_fd->path);
885                         }
886                 else
887                         {
888                         return;
889                         }
890                 }
891         else
892                 {
893                 tilde_filename = expand_tilde(text);
894                 if (isdir(tilde_filename))
895                         {
896                         dir_fd = file_data_new_dir(tilde_filename);
897                         }
898                 else
899                         {
900                         g_free(tilde_filename);
901                         return;
902                         }
903                 g_free(tilde_filename);
904                 }
905
906         if (recurse)
907                 {
908                 list = filelist_recursive(dir_fd);
909                 }
910         else
911                 {
912                 filelist_read(dir_fd, &list, nullptr);
913                 }
914
915         GString *out_string = g_string_new(nullptr);
916         work = list;
917         while (work)
918                 {
919                 fd = static_cast<FileData *>(work->data);
920                 g_string_append(out_string, fd->path);
921                 format_class = filter_file_get_class(fd->path);
922
923                 switch (format_class)
924                         {
925                         case FORMAT_CLASS_IMAGE:
926                                 out_string = g_string_append(out_string, "    Class: Image");
927                                 break;
928                         case FORMAT_CLASS_RAWIMAGE:
929                                 out_string = g_string_append(out_string, "    Class: RAW image");
930                                 break;
931                         case FORMAT_CLASS_META:
932                                 out_string = g_string_append(out_string, "    Class: Metadata");
933                                 break;
934                         case FORMAT_CLASS_VIDEO:
935                                 out_string = g_string_append(out_string, "    Class: Video");
936                                 break;
937                         case FORMAT_CLASS_COLLECTION:
938                                 out_string = g_string_append(out_string, "    Class: Collection");
939                                 break;
940                         case FORMAT_CLASS_DOCUMENT:
941                                 out_string = g_string_append(out_string, "    Class: Document");
942                                 break;
943                         case FORMAT_CLASS_ARCHIVE:
944                                 out_string = g_string_append(out_string, "    Class: Archive");
945                                 break;
946                         case FORMAT_CLASS_UNKNOWN:
947                                 out_string = g_string_append(out_string, "    Class: Unknown");
948                                 break;
949                         default:
950                                 out_string = g_string_append(out_string, "    Class: Unknown");
951                                 break;
952                         }
953                 out_string = g_string_append(out_string, "\n");
954                 work = work->next;
955                 }
956
957         g_io_channel_write_chars(channel, out_string->str, -1, nullptr, nullptr);
958         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
959
960         g_string_free(out_string, TRUE);
961         filelist_free(list);
962         file_data_unref(dir_fd);
963 }
964
965 static void gr_get_selection(const gchar *, GIOChannel *channel, gpointer)
966 {
967         if (!layout_valid(&lw_id)) return;
968
969         GList *selected = layout_selection_list(lw_id);  // Keep copy to free.
970         GString *out_string = g_string_new(nullptr);
971
972         GList *work = selected;
973         while (work)
974                 {
975                 auto fd = static_cast<FileData *>(work->data);
976                 g_assert(fd->magick == FD_MAGICK);
977
978                 g_string_append_printf(out_string, "%s    %s\n",
979                                        fd->path,
980                                        format_class_list[filter_file_get_class(fd->path)]);
981
982                 work = work->next;
983                 }
984
985         g_io_channel_write_chars(channel, out_string->str, -1, nullptr, nullptr);
986         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
987
988         filelist_free(selected);
989         g_string_free(out_string, TRUE);
990 }
991
992 static void gr_selection_add(const gchar *text, GIOChannel *, gpointer)
993 {
994         if (!layout_valid(&lw_id)) return;
995
996         FileData *fd_to_select = nullptr;
997         if (strcmp(text, "") == 0)
998                 {
999                 // No file specified, use current fd.
1000                 fd_to_select = layout_image_get_fd(lw_id);
1001                 }
1002         else
1003                 {
1004                 // Search through the current file list for a file matching the specified path.
1005                 // "Match" is either a basename match or a file path match.
1006                 gchar *path = expand_tilde(text);
1007                 gchar *filename = g_path_get_basename(path);
1008                 gchar *slash_plus_filename = g_strdup_printf("%s%s", G_DIR_SEPARATOR_S, filename);
1009
1010                 GList *file_list = layout_list(lw_id);
1011                 for (GList *work = file_list; work && !fd_to_select; work = work->next)
1012                         {
1013                         auto fd = static_cast<FileData *>(work->data);
1014                         if (!strcmp(path, fd->path) || g_str_has_suffix(fd->path, slash_plus_filename))
1015                                 {
1016                                 fd_to_select = file_data_ref(fd);
1017                                 continue;  // will exit loop.
1018                                 }
1019
1020                         for (GList *sidecar = fd->sidecar_files; sidecar && !fd_to_select; sidecar = sidecar->next)
1021                                 {
1022                                 auto side_fd = static_cast<FileData *>(sidecar->data);
1023                                 if (!strcmp(path, side_fd->path)
1024                                     || g_str_has_suffix(side_fd->path, slash_plus_filename))
1025                                         {
1026                                         fd_to_select = file_data_ref(side_fd);
1027                                         continue;  // will exit both nested loops.
1028                                         }
1029                                 }
1030                         }
1031
1032                 if (!fd_to_select)
1033                         {
1034                         log_printf("remote sent --selection-add filename that could not be found: \"%s\"\n",
1035                                    filename);
1036                         }
1037
1038                 filelist_free(file_list);
1039                 g_free(slash_plus_filename);
1040                 g_free(filename);
1041                 g_free(path);
1042                 }
1043
1044         if (fd_to_select)
1045                 {
1046                 GList *to_select = g_list_append(nullptr, fd_to_select);
1047                 // Using the "_list" variant doesn't clear the existing selection.
1048                 layout_select_list(lw_id, to_select);
1049                 filelist_free(to_select);
1050                 }
1051 }
1052
1053 static void gr_selection_clear(const gchar *, GIOChannel *, gpointer)
1054 {
1055         layout_select_none(lw_id);  // Checks lw_id validity internally.
1056 }
1057
1058 static void gr_selection_remove(const gchar *text, GIOChannel *, gpointer)
1059 {
1060         if (!layout_valid(&lw_id)) return;
1061
1062         GList *selected = layout_selection_list(lw_id);  // Keep copy to free.
1063         if (!selected)
1064                 {
1065                 log_printf("remote sent --selection-remove with empty selection.");
1066                 return;
1067                 }
1068
1069         FileData *fd_to_deselect = nullptr;
1070         gchar *path = nullptr;
1071         gchar *filename = nullptr;
1072         gchar *slash_plus_filename = nullptr;
1073         if (strcmp(text, "") == 0)
1074                 {
1075                 // No file specified, use current fd.
1076                 fd_to_deselect = layout_image_get_fd(lw_id);
1077                 if (!fd_to_deselect)
1078                         {
1079                         log_printf("remote sent \"--selection-remove:\" with no current image");
1080                         filelist_free(selected);
1081                         return;
1082                         }
1083                 }
1084         else
1085                 {
1086                 // Search through the selection list for a file matching the specified path.
1087                 // "Match" is either a basename match or a file path match.
1088                 path = expand_tilde(text);
1089                 filename = g_path_get_basename(path);
1090                 slash_plus_filename = g_strdup_printf("%s%s", G_DIR_SEPARATOR_S, filename);
1091                 }
1092
1093         GList *prior_link = nullptr;  // Stash base for link removal to avoid a second traversal.
1094         GList *link_to_remove = nullptr;
1095         for (GList *work = selected; work; prior_link = work, work = work->next)
1096                 {
1097                 auto fd = static_cast<FileData *>(work->data);
1098                 if (fd_to_deselect)
1099                         {
1100                         if (fd == fd_to_deselect)
1101                                 {
1102                                 link_to_remove = work;
1103                                 break;
1104                                 }
1105                         }
1106                 else
1107                         {
1108                         // path, filename, and slash_plus_filename should be defined.
1109
1110                         if (!strcmp(path, fd->path) || g_str_has_suffix(fd->path, slash_plus_filename))
1111                                 {
1112                                 link_to_remove = work;
1113                                 break;
1114                                 }
1115                         }
1116                 }
1117
1118         if (!link_to_remove)
1119                 {
1120                 if (fd_to_deselect)
1121                         {
1122                         log_printf("remote sent \"--selection-remove:\" but current image is not selected");
1123                         }
1124                 else
1125                         {
1126                         log_printf("remote sent \"--selection-remove:%s\" but that filename is not selected",
1127                                    filename);
1128                         }
1129                 }
1130         else
1131                 {
1132                 if (link_to_remove == selected)
1133                         {
1134                         // Remove first link.
1135                         selected = g_list_remove_link(selected, link_to_remove);
1136                         filelist_free(link_to_remove);
1137                         link_to_remove = nullptr;
1138                         }
1139                 else
1140                         {
1141                         // Remove a subsequent link.
1142                         prior_link = g_list_remove_link(prior_link, link_to_remove);
1143                         filelist_free(link_to_remove);
1144                         link_to_remove = nullptr;
1145                         }
1146
1147                 // Re-select all but the deselected item.
1148                 layout_select_none(lw_id);
1149                 layout_select_list(lw_id, selected);
1150                 }
1151
1152         filelist_free(selected);
1153         file_data_unref(fd_to_deselect);
1154         g_free(slash_plus_filename);
1155         g_free(filename);
1156         g_free(path);
1157 }
1158
1159 static void gr_collection(const gchar *text, GIOChannel *channel, gpointer)
1160 {
1161         GString *contents = g_string_new(nullptr);
1162
1163         if (is_collection(text))
1164                 {
1165                 collection_contents(text, &contents);
1166                 }
1167         else
1168                 {
1169                 return;
1170                 }
1171
1172         g_io_channel_write_chars(channel, contents->str, -1, nullptr, nullptr);
1173         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1174
1175         g_string_free(contents, TRUE);
1176 }
1177
1178 static void gr_collection_list(const gchar *, GIOChannel *channel, gpointer)
1179 {
1180
1181         GList *collection_list = nullptr;
1182         GList *work;
1183         GString *out_string = g_string_new(nullptr);
1184
1185         collect_manager_list(&collection_list, nullptr, nullptr);
1186
1187         work = collection_list;
1188         while (work)
1189                 {
1190                 auto collection_name = static_cast<const gchar *>(work->data);
1191                 out_string = g_string_append(out_string, collection_name);
1192                 out_string = g_string_append(out_string, "\n");
1193
1194                 work = work->next;
1195                 }
1196
1197         g_io_channel_write_chars(channel, out_string->str, -1, nullptr, nullptr);
1198         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1199
1200         g_list_free_full(collection_list, g_free);
1201         g_string_free(out_string, TRUE);
1202 }
1203
1204 static gboolean wait_cb(gpointer data)
1205 {
1206         gint position = GPOINTER_TO_INT(data);
1207         gint x = position >> 16;
1208         gint y = position - (x << 16);
1209
1210         gq_gtk_window_move(GTK_WINDOW(lw_id->window), x, y);
1211
1212         return G_SOURCE_REMOVE;
1213 }
1214
1215 static void gr_geometry(const gchar *text, GIOChannel *, gpointer)
1216 {
1217         gchar **geometry;
1218
1219         if (!layout_valid(&lw_id) || !text)
1220                 {
1221                 return;
1222                 }
1223
1224         if (text[0] == '+')
1225                 {
1226                 geometry = g_strsplit_set(text, "+", 3);
1227                 if (geometry[1] != nullptr && geometry[2] != nullptr )
1228                         {
1229                         gq_gtk_window_move(GTK_WINDOW(lw_id->window), atoi(geometry[1]), atoi(geometry[2]));
1230                         }
1231                 }
1232         else
1233                 {
1234                 geometry = g_strsplit_set(text, "+x", 4);
1235                 if (geometry[0] != nullptr && geometry[1] != nullptr)
1236                         {
1237                         gtk_window_resize(GTK_WINDOW(lw_id->window), atoi(geometry[0]), atoi(geometry[1]));
1238                         }
1239                 if (geometry[2] != nullptr && geometry[3] != nullptr)
1240                         {
1241                         /* There is an occasional problem with a window_move immediately after a window_resize */
1242                         g_idle_add(wait_cb, GINT_TO_POINTER((atoi(geometry[2]) << 16) + atoi(geometry[3])));
1243                         }
1244                 }
1245         g_strfreev(geometry);
1246 }
1247
1248 static void gr_filelist(const gchar *text, GIOChannel *channel, gpointer)
1249 {
1250         get_filelist(text, channel, FALSE);
1251 }
1252
1253 static void gr_filelist_recurse(const gchar *text, GIOChannel *channel, gpointer)
1254 {
1255         get_filelist(text, channel, TRUE);
1256 }
1257
1258 static void gr_file_tell(const gchar *, GIOChannel *channel, gpointer)
1259 {
1260         gchar *out_string;
1261         gchar *collection_name = nullptr;
1262
1263         if (!layout_valid(&lw_id)) return;
1264
1265         if (image_get_path(lw_id->image))
1266                 {
1267                 if (lw_id->image->collection && lw_id->image->collection->name)
1268                         {
1269                         collection_name = remove_extension_from_path(lw_id->image->collection->name);
1270                         out_string = g_strconcat(image_get_path(lw_id->image), "    Collection: ", collection_name, NULL);
1271                         }
1272                 else
1273                         {
1274                         out_string = g_strconcat(image_get_path(lw_id->image), NULL);
1275                         }
1276                 }
1277         else
1278                 {
1279                 out_string = g_strconcat(lw_id->dir_fd->path, G_DIR_SEPARATOR_S, NULL);
1280                 }
1281
1282         g_io_channel_write_chars(channel, out_string, -1, nullptr, nullptr);
1283         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1284
1285         g_free(collection_name);
1286         g_free(out_string);
1287 }
1288
1289 static void gr_file_info(const gchar *, GIOChannel *channel, gpointer)
1290 {
1291         gchar *filename;
1292         FileData *fd;
1293         gchar *country_name;
1294         gchar *country_code;
1295         gchar *timezone;
1296         gchar *local_time;
1297         GString *out_string;
1298         FileFormatClass format_class;
1299
1300         if (!layout_valid(&lw_id)) return;
1301
1302         if (image_get_path(lw_id->image))
1303                 {
1304                 filename = g_strdup(image_get_path(lw_id->image));
1305                 fd = file_data_new_group(filename);
1306                 out_string = g_string_new(nullptr);
1307
1308                 if (fd->pixbuf)
1309                         {
1310                         format_class = filter_file_get_class(image_get_path(lw_id->image));
1311                         }
1312                 else
1313                         {
1314                         format_class = FORMAT_CLASS_UNKNOWN;
1315                         }
1316
1317                 g_string_append_printf(out_string, _("Class: %s\n"), format_class_list[format_class]);
1318
1319                 if (fd->page_total > 1)
1320                         {
1321                         g_string_append_printf(out_string, _("Page no: %d/%d\n"), fd->page_num + 1, fd->page_total);
1322                         }
1323
1324                 if (fd->exif)
1325                         {
1326                         country_name = exif_get_data_as_text(fd->exif, "formatted.countryname");
1327                         if (country_name)
1328                                 {
1329                                 g_string_append_printf(out_string, _("Country name: %s\n"), country_name);
1330                                 g_free(country_name);
1331                                 }
1332
1333                         country_code = exif_get_data_as_text(fd->exif, "formatted.countrycode");
1334                         if (country_name)
1335                                 {
1336                                 g_string_append_printf(out_string, _("Country code: %s\n"), country_code);
1337                                 g_free(country_code);
1338                                 }
1339
1340                         timezone = exif_get_data_as_text(fd->exif, "formatted.timezone");
1341                         if (timezone)
1342                                 {
1343                                 g_string_append_printf(out_string, _("Timezone: %s\n"), timezone);
1344                                 g_free(timezone);
1345                                 }
1346
1347                         local_time = exif_get_data_as_text(fd->exif, "formatted.localtime");
1348                         if (local_time)
1349                                 {
1350                                 g_string_append_printf(out_string, ("Local time: %s\n"), local_time);
1351                                 g_free(local_time);
1352                                 }
1353                         }
1354
1355                 g_io_channel_write_chars(channel, out_string->str, -1, nullptr, nullptr);
1356                 g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1357
1358                 g_string_free(out_string, TRUE);
1359                 file_data_unref(fd);
1360                 g_free(filename);
1361                 }
1362 }
1363
1364 static gchar *config_file_path(const gchar *param)
1365 {
1366         gchar *path = nullptr;
1367         gchar *full_name = nullptr;
1368
1369         if (file_extension_match(param, ".xml"))
1370                 {
1371                 path = g_build_filename(get_window_layouts_dir(), param, NULL);
1372                 }
1373         else if (file_extension_match(param, nullptr))
1374                 {
1375                 full_name = g_strconcat(param, ".xml", NULL);
1376                 path = g_build_filename(get_window_layouts_dir(), full_name, NULL);
1377                 }
1378
1379         if (!isfile(path))
1380                 {
1381                 g_free(path);
1382                 path = nullptr;
1383                 }
1384
1385         g_free(full_name);
1386         return path;
1387 }
1388
1389 static gboolean is_config_file(const gchar *param)
1390 {
1391         gchar *name = nullptr;
1392
1393         name = config_file_path(param);
1394         if (name)
1395                 {
1396                 g_free(name);
1397                 return TRUE;
1398                 }
1399         return FALSE;
1400 }
1401
1402 static void gr_config_load(const gchar *text, GIOChannel *, gpointer)
1403 {
1404         gchar *filename = expand_tilde(text);
1405
1406         if (!g_strstr_len(filename, -1, G_DIR_SEPARATOR_S))
1407                 {
1408                 if (is_config_file(filename))
1409                         {
1410                         gchar *tmp = config_file_path(filename);
1411                         g_free(filename);
1412                         filename = tmp;
1413                         }
1414                 }
1415
1416         if (isfile(filename))
1417                 {
1418                 load_config_from_file(filename, FALSE);
1419                 }
1420         else
1421                 {
1422                 log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
1423                 layout_set_path(nullptr, homedir());
1424                 }
1425
1426         g_free(filename);
1427 }
1428
1429 static void gr_window_list(const gchar *, GIOChannel *channel, gpointer)
1430 {
1431         GString *window_list;
1432
1433         window_list = layout_get_window_list();
1434
1435         g_io_channel_write_chars(channel, window_list->str, -1, nullptr, nullptr);
1436         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1437
1438         g_string_free(window_list, TRUE);
1439 }
1440
1441 static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer)
1442 {
1443         gchar *filename = expand_tilde(text);
1444         FileData *fd = file_data_new_group(filename);
1445
1446         GList *work;
1447         if (fd->parent) fd = fd->parent;
1448
1449         g_io_channel_write_chars(channel, fd->path, -1, nullptr, nullptr);
1450         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1451
1452         work = fd->sidecar_files;
1453
1454         while (work)
1455                 {
1456                 fd = static_cast<FileData *>(work->data);
1457                 work = work->next;
1458                 g_io_channel_write_chars(channel, fd->path, -1, nullptr, nullptr);
1459                 g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1460                 }
1461         g_free(filename);
1462 }
1463
1464 static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer)
1465 {
1466         gchar *filename = expand_tilde(text);
1467         FileData *fd = file_data_new_group(filename);
1468
1469         if (fd->change && fd->change->dest)
1470                 {
1471                 g_io_channel_write_chars(channel, fd->change->dest, -1, nullptr, nullptr);
1472                 g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1473                 }
1474         g_free(filename);
1475 }
1476
1477 static void gr_file_view(const gchar *text, GIOChannel *, gpointer)
1478 {
1479         gchar *filename;
1480         gchar *tilde_filename = expand_tilde(text);
1481
1482         filename = set_pwd(tilde_filename);
1483
1484         view_window_new(file_data_new_group(filename));
1485         g_free(filename);
1486         g_free(tilde_filename);
1487 }
1488
1489 static void gr_list_clear(const gchar *, GIOChannel *, gpointer data)
1490 {
1491         auto remote_data = static_cast<RemoteData *>(data);
1492
1493         remote_data->command_collection = nullptr;
1494         remote_data->file_list = nullptr;
1495         remote_data->single_dir = TRUE;
1496 }
1497
1498 static void gr_list_add(const gchar *text, GIOChannel *, gpointer data)
1499 {
1500         auto remote_data = static_cast<RemoteData *>(data);
1501         gboolean is_new = TRUE;
1502         gchar *path = nullptr;
1503         FileData *fd;
1504         FileData *first;
1505
1506         /** @FIXME Should check if file is in current dir, has tilde or is relative */
1507         if (!isfile(text))
1508                 {
1509                 log_printf("Warning: File does not exist --remote --list-add:%s", text);
1510
1511                 return;
1512                 }
1513
1514         /* If there is a files list on the command line
1515          * check if they are all in the same folder
1516          */
1517         if (remote_data->single_dir)
1518                 {
1519                 GList *work;
1520                 work = remote_data->file_list;
1521                 while (work && remote_data->single_dir)
1522                         {
1523                         gchar *dirname;
1524                         dirname = g_path_get_dirname((static_cast<FileData *>(work->data))->path);
1525                         if (!path)
1526                                 {
1527                                 path = g_strdup(dirname);
1528                                 }
1529                         else
1530                                 {
1531                                 if (g_strcmp0(path, dirname) != 0)
1532                                         {
1533                                         remote_data->single_dir = FALSE;
1534                                         }
1535                                 }
1536                         g_free(dirname);
1537                         work = work->next;
1538                         }
1539                 g_free(path);
1540                 }
1541
1542         gchar *pathname = g_path_get_dirname(text);
1543         layout_set_path(lw_id, pathname);
1544         g_free(pathname);
1545
1546         fd = file_data_new_simple(text);
1547         remote_data->file_list = g_list_append(remote_data->file_list, fd);
1548         file_data_unref(fd);
1549
1550         vf_select_none(lw_id->vf);
1551         remote_data->file_list = g_list_reverse(remote_data->file_list);
1552
1553         layout_select_list(lw_id, remote_data->file_list);
1554         layout_refresh(lw_id);
1555         first = static_cast<FileData *>(g_list_first(vf_selection_get_list(lw_id->vf))->data);
1556         layout_set_fd(lw_id, first);
1557
1558                 CollectionData *cd;
1559                 CollectWindow *cw;
1560
1561         if (!remote_data->command_collection && !remote_data->single_dir)
1562                 {
1563                 cw = collection_window_new(nullptr);
1564                 cd = cw->cd;
1565
1566                 collection_path_changed(cd);
1567
1568                 remote_data->command_collection = cd;
1569                 }
1570         else if (!remote_data->single_dir)
1571                 {
1572                 is_new = (!collection_get_first(remote_data->command_collection));
1573                 }
1574
1575         if (!remote_data->single_dir)
1576                 {
1577                 layout_image_set_collection(lw_id, remote_data->command_collection, collection_get_first(remote_data->command_collection));
1578                 if (collection_add(remote_data->command_collection, file_data_new_group(text), FALSE) && is_new)
1579                         {
1580                         layout_image_set_collection(lw_id, remote_data->command_collection, collection_get_first(remote_data->command_collection));
1581                         }
1582                 }
1583 }
1584
1585 static void gr_action(const gchar *text, GIOChannel *, gpointer)
1586 {
1587         GtkAction *action;
1588
1589         if (!layout_valid(&lw_id))
1590                 {
1591                 return;
1592                 }
1593
1594         if (g_strstr_len(text, -1, ".desktop") != nullptr)
1595                 {
1596                 file_util_start_editor_from_filelist(text, layout_selection_list(lw_id), layout_get_path(lw_id), lw_id->window);
1597                 }
1598         else
1599                 {
1600                 action = gtk_action_group_get_action(lw_id->action_group, text);
1601                 if (action)
1602                         {
1603                         gtk_action_activate(action);
1604                         }
1605                 else
1606                         {
1607                         log_printf("Action %s unknown", text);
1608                         }
1609                 }
1610 }
1611
1612 static void gr_action_list(const gchar *, GIOChannel *channel, gpointer)
1613 {
1614         ActionItem *action_item;
1615         gint max_length = 0;
1616         GList *list = nullptr;
1617         GString *out_string = g_string_new(nullptr);
1618
1619         if (!layout_valid(&lw_id))
1620                 {
1621                 return;
1622                 }
1623
1624         list = get_action_items();
1625
1626         /* Get the length required for padding */
1627         for (GList *work = list; work; work = work->next)
1628                 {
1629                 action_item = static_cast<ActionItem *>(work->data);
1630                 const auto length = g_utf8_strlen(action_item->name, -1);
1631                 max_length = MAX(length, max_length);
1632                 }
1633
1634         /* Pad the action names to the same column for readable output */
1635         for (GList *work = list; work; work = work->next)
1636                 {
1637                 action_item = static_cast<ActionItem *>(work->data);
1638
1639                 g_string_append_printf(out_string, "%-*s", max_length + 4, action_item->name);
1640                 out_string = g_string_append(out_string, action_item->label);
1641                 out_string = g_string_append(out_string, "\n");
1642                 }
1643
1644         action_items_free(list);
1645
1646         g_io_channel_write_chars(channel, out_string->str, -1, nullptr, nullptr);
1647         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1648
1649         g_string_free(out_string, TRUE);
1650 }
1651
1652 static void gr_raise(const gchar *, GIOChannel *, gpointer)
1653 {
1654         if (layout_valid(&lw_id))
1655                 {
1656                 gtk_window_present(GTK_WINDOW(lw_id->window));
1657                 }
1658 }
1659
1660 static void gr_pwd(const gchar *text, GIOChannel *, gpointer)
1661 {
1662         LayoutWindow *lw = nullptr;
1663
1664         layout_valid(&lw);
1665
1666         g_free(pwd);
1667         pwd = g_strdup(text);
1668         lw_id = lw;
1669 }
1670
1671 static void gr_print0(const gchar *, GIOChannel *channel, gpointer)
1672 {
1673         g_io_channel_write_chars(channel, "print0", -1, nullptr, nullptr);
1674         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1675 }
1676
1677 #if HAVE_LUA
1678 static void gr_lua(const gchar *text, GIOChannel *channel, gpointer)
1679 {
1680         gchar *result = nullptr;
1681         gchar **lua_command;
1682
1683         lua_command = g_strsplit(text, ",", 2);
1684
1685         if (lua_command[0] && lua_command[1])
1686                 {
1687                 FileData *fd = file_data_new_group(lua_command[0]);
1688                 result = g_strdup(lua_callvalue(fd, lua_command[1], nullptr));
1689                 if (result)
1690                         {
1691                         g_io_channel_write_chars(channel, result, -1, nullptr, nullptr);
1692                         }
1693                 else
1694                         {
1695                         g_io_channel_write_chars(channel, N_("lua error: no data"), -1, nullptr, nullptr);
1696                         }
1697                 }
1698         else
1699                 {
1700                 g_io_channel_write_chars(channel, N_("lua error: no data"), -1, nullptr, nullptr);
1701                 }
1702
1703         g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
1704
1705         g_strfreev(lua_command);
1706         g_free(result);
1707 }
1708 #endif
1709
1710 struct RemoteCommandEntry {
1711         const gchar *opt_s;
1712         const gchar *opt_l;
1713         void (*func)(const gchar *text, GIOChannel *channel, gpointer data);
1714         gboolean needs_extra;
1715         gboolean prefer_command_line;
1716         const gchar *parameter;
1717         const gchar *description;
1718 };
1719
1720 static RemoteCommandEntry remote_commands[] = {
1721         /* short, long                  callback,               extra, prefer, parameter, description */
1722         { nullptr, "--action:",          gr_action,            TRUE,  FALSE, N_("<ACTION>"), N_("execute keyboard action (See Help/Reference/Remote Keyboard Actions)") },
1723         { nullptr, "--action-list",          gr_action_list,    FALSE,  FALSE, nullptr, N_("list available keyboard actions (some are redundant)") },
1724         { "-b", "--back",               gr_image_prev,          FALSE, FALSE, nullptr, N_("previous image") },
1725         { nullptr, "--close-window",       gr_close_window,        FALSE, FALSE, nullptr, N_("close window") },
1726         { nullptr, "--config-load:",       gr_config_load,         TRUE,  FALSE, N_("<FILE>|layout ID"), N_("load configuration from FILE") },
1727         { "-cm","--cache-metadata",      gr_cache_metadata,               FALSE, FALSE, nullptr, N_("clean the metadata cache") },
1728         { "-cr:", "--cache-render:",    gr_cache_render,        TRUE, FALSE, N_("<folder>  "), N_(" render thumbnails") },
1729         { "-crr:", "--cache-render-recurse:", gr_cache_render_recurse, TRUE, FALSE, N_("<folder> "), N_("render thumbnails recursively") },
1730         { "-crs:", "--cache-render-shared:", gr_cache_render_standard, TRUE, FALSE, N_("<folder> "), N_(" render thumbnails (see Help)") },
1731         { "-crsr:", "--cache-render-shared-recurse:", gr_cache_render_standard_recurse, TRUE, FALSE, N_("<folder>"), N_(" render thumbnails recursively (see Help)") },
1732         { "-cs:", "--cache-shared:",    gr_cache_shared,        TRUE, FALSE, N_("clear|clean"), N_("clear or clean shared thumbnail cache") },
1733         { "-ct:", "--cache-thumbs:",    gr_cache_thumb,         TRUE, FALSE, N_("clear|clean"), N_("clear or clean thumbnail cache") },
1734         { "-d", "--delay=",             gr_slideshow_delay,     TRUE,  FALSE, N_("<[H:][M:][N][.M]>"), N_("set slide show delay to Hrs Mins N.M seconds") },
1735         { nullptr, "--first",              gr_image_first,         FALSE, FALSE, nullptr, N_("first image") },
1736         { "-f", "--fullscreen",         gr_fullscreen_toggle,   FALSE, TRUE,  nullptr, N_("toggle full screen") },
1737         { nullptr, "--file:",              gr_file_load,           TRUE,  FALSE, N_("<FILE>|<URL>"), N_("open FILE or URL, bring Geeqie window to the top") },
1738         { nullptr, "file:",                gr_file_load,           TRUE,  FALSE, N_("<FILE>|<URL>"), N_("open FILE or URL, bring Geeqie window to the top") },
1739         { nullptr, "--File:",              gr_file_load_no_raise,  TRUE,  FALSE, N_("<FILE>|<URL>"), N_("open FILE or URL, do not bring Geeqie window to the top") },
1740         { nullptr, "File:",                gr_file_load_no_raise,  TRUE,  FALSE, N_("<FILE>|<URL>"), N_("open FILE or URL, do not bring Geeqie window to the top") },
1741         { "-fs","--fullscreen-start",   gr_fullscreen_start,    FALSE, FALSE, nullptr, N_("start full screen") },
1742         { "-fS","--fullscreen-stop",    gr_fullscreen_stop,     FALSE, FALSE, nullptr, N_("stop full screen") },
1743         { nullptr, "--geometry=",          gr_geometry,            TRUE, FALSE, N_("<GEOMETRY>"), N_("set window geometry") },
1744         { nullptr, "--get-collection:",    gr_collection,          TRUE,  FALSE, N_("<COLLECTION>"), N_("get collection content") },
1745         { nullptr, "--get-collection-list", gr_collection_list,    FALSE, FALSE, nullptr, N_("get collection list") },
1746         { nullptr, "--get-destination:",        gr_get_destination,     TRUE,  FALSE, N_("<FILE>"), N_("get destination path of FILE (See Plugins Configuration)") },
1747         { nullptr, "--get-file-info",      gr_file_info,           FALSE, FALSE, nullptr, N_("get file info") },
1748         { nullptr, "--get-filelist:",      gr_filelist,            TRUE,  FALSE, N_("[<FOLDER>]"), N_("get list of files and class") },
1749         { nullptr, "--get-filelist-recurse:", gr_filelist_recurse, TRUE,  FALSE, N_("[<FOLDER>]"), N_("get list of files and class recursive") },
1750         { nullptr, "--get-rectangle",      gr_rectangle,           FALSE, FALSE, nullptr, N_("get rectangle co-ordinates") },
1751         { nullptr, "--get-render-intent",  gr_render_intent,       FALSE, FALSE, nullptr, N_("get render intent") },
1752         { nullptr, "--get-selection",      gr_get_selection,       FALSE, FALSE, nullptr, N_("get list of selected files") },
1753         { nullptr, "--get-sidecars:",      gr_get_sidecars,        TRUE,  FALSE, N_("<FILE>"), N_("get list of sidecars of FILE") },
1754         { nullptr, "--get-window-list",    gr_window_list,         FALSE, FALSE, nullptr, N_("get window list") },
1755         { nullptr, "--id:",                gr_lw_id,               TRUE, FALSE, N_("<ID>"), N_("window id for following commands") },
1756         { nullptr, "--last",               gr_image_last,          FALSE, FALSE, nullptr, N_("last image") },
1757         { nullptr, "--list-add:",          gr_list_add,            TRUE,  FALSE, N_("<FILE>"), N_("add FILE to command line collection list") },
1758         { nullptr, "--list-clear",         gr_list_clear,          FALSE, FALSE, nullptr, N_("clear command line collection list") },
1759 #if HAVE_LUA
1760         { nullptr, "--lua:",               gr_lua,                 TRUE, FALSE, N_("<FILE>,<lua script>"), N_("run lua script on FILE") },
1761 #endif
1762         { nullptr, "--new-window",         gr_new_window,          FALSE, FALSE, nullptr, N_("new window") },
1763         { "-n", "--next",               gr_image_next,          FALSE, FALSE, nullptr, N_("next image") },
1764         { nullptr, "--pixel-info",         gr_pixel_info,          FALSE, FALSE, nullptr, N_("print pixel info of mouse pointer on current image") },
1765         { nullptr, "--print0",             gr_print0,              TRUE, FALSE, nullptr, N_("terminate returned data with null character instead of newline") },
1766         { nullptr, "--PWD:",               gr_pwd,                 TRUE, FALSE, N_("<PWD>"), N_("use PWD as working directory for following commands") },
1767         { "-q", "--quit",               gr_quit,                FALSE, FALSE, nullptr, N_("quit") },
1768         { nullptr, "--raise",              gr_raise,               FALSE, FALSE, nullptr, N_("bring the Geeqie window to the top") },
1769         { nullptr, "raise",                gr_raise,               FALSE, FALSE, nullptr, N_("bring the Geeqie window to the top") },
1770         { nullptr, "--selection-add:",     gr_selection_add,       TRUE,  FALSE, N_("[<FILE>]"), N_("adds the current file (or the specified file) to the current selection") },
1771         { nullptr, "--selection-clear",    gr_selection_clear,     FALSE, FALSE, nullptr, N_("clears the current selection") },
1772         { nullptr, "--selection-remove:",  gr_selection_remove,    TRUE,  FALSE, N_("[<FILE>]"), N_("removes the current file (or the specified file) from the current selection") },
1773         { "-s", "--slideshow",          gr_slideshow_toggle,    FALSE, TRUE,  nullptr, N_("toggle slide show") },
1774         { nullptr, "--slideshow-recurse:", gr_slideshow_start_rec, TRUE,  FALSE, N_("<FOLDER>"), N_("start recursive slide show in FOLDER") },
1775         { "-ss","--slideshow-start",    gr_slideshow_start,     FALSE, FALSE, nullptr, N_("start slide show") },
1776         { "-sS","--slideshow-stop",     gr_slideshow_stop,      FALSE, FALSE, nullptr, N_("stop slide show") },
1777         { nullptr, "--tell",               gr_file_tell,           FALSE, FALSE, nullptr, N_("print filename [and Collection] of current image") },
1778         { "+t", "--tools-show",         gr_tools_show,          FALSE, TRUE,  nullptr, N_("show tools") },
1779         { "-t", "--tools-hide",         gr_tools_hide,          FALSE, TRUE,  nullptr, N_("hide tools") },
1780         { nullptr, "--view:",              gr_file_view,           TRUE,  FALSE, N_("<FILE>"), N_("open FILE in new window") },
1781         { nullptr, "view:",                gr_file_view,           TRUE,  FALSE, N_("<FILE>"), N_("open FILE in new window") },
1782         { nullptr, nullptr, nullptr, FALSE, FALSE, nullptr, nullptr }
1783 };
1784
1785 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset)
1786 {
1787         gboolean match = FALSE;
1788         gint i;
1789
1790         i = 0;
1791         while (!match && remote_commands[i].func != nullptr)
1792                 {
1793                 if (remote_commands[i].needs_extra)
1794                         {
1795                         if (remote_commands[i].opt_s &&
1796                             strncmp(remote_commands[i].opt_s, text, strlen(remote_commands[i].opt_s)) == 0)
1797                                 {
1798                                 if (offset) *offset = text + strlen(remote_commands[i].opt_s);
1799                                 return &remote_commands[i];
1800                                 }
1801
1802                         if (remote_commands[i].opt_l &&
1803                                  strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0)
1804                                 {
1805                                 if (offset) *offset = text + strlen(remote_commands[i].opt_l);
1806                                 return &remote_commands[i];
1807                                 }
1808                         }
1809                 else
1810                         {
1811                         if ((remote_commands[i].opt_s && strcmp(remote_commands[i].opt_s, text) == 0) ||
1812                             (remote_commands[i].opt_l && strcmp(remote_commands[i].opt_l, text) == 0))
1813                                 {
1814                                 if (offset) *offset = text;
1815                                 return &remote_commands[i];
1816                                 }
1817                         }
1818
1819                 i++;
1820                 }
1821
1822         return nullptr;
1823 }
1824
1825 static void remote_cb(RemoteConnection *, const gchar *text, GIOChannel *channel, gpointer data)
1826 {
1827         RemoteCommandEntry *entry;
1828         const gchar *offset;
1829
1830         entry = remote_command_find(text, &offset);
1831         if (entry && entry->func)
1832                 {
1833                 entry->func(offset, channel, data);
1834                 }
1835         else
1836                 {
1837                 log_printf("unknown remote command:%s\n", text);
1838                 }
1839 }
1840
1841 void remote_help()
1842 {
1843         gint i;
1844         gchar *s_opt_param;
1845         gchar *l_opt_param;
1846
1847         print_term(FALSE, _("Remote command list:\n"));
1848
1849         i = 0;
1850         while (remote_commands[i].func != nullptr)
1851                 {
1852                 if (remote_commands[i].description)
1853                         {
1854                         s_opt_param = g_strdup(remote_commands[i].opt_s  ? remote_commands[i].opt_s : "" );
1855                         l_opt_param = g_strconcat(remote_commands[i].opt_l, remote_commands[i].parameter, NULL);
1856
1857                         if (g_str_has_prefix(l_opt_param, "--"))
1858                                 {
1859                                 printf_term(FALSE, "  %-4s %-40s%-s\n", s_opt_param, l_opt_param, _(remote_commands[i].description));
1860                                 }
1861                         g_free(s_opt_param);
1862                         g_free(l_opt_param);
1863                         }
1864                 i++;
1865                 }
1866         printf_term(FALSE, _("\n\n  All other command line parameters are used as plain files if they exist.\n\n  The name of a collection, with or without either path or extension (.gqv) may be used.\n"));
1867 }
1868
1869 GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
1870 {
1871         gint i;
1872
1873         i = 1;
1874         while (i < argc)
1875                 {
1876                 RemoteCommandEntry *entry;
1877
1878                 entry = remote_command_find(argv[i], nullptr);
1879                 if (entry)
1880                         {
1881                         list = g_list_append(list, argv[i]);
1882                         }
1883                 else if (errors && !isname(argv[i]))
1884                         {
1885                         *errors = g_list_append(*errors, argv[i]);
1886                         }
1887                 i++;
1888                 }
1889
1890         return list;
1891 }
1892
1893 /**
1894  * @param arg_exec Binary (argv0)
1895  * @param remote_list Evaluated and recognized remote commands
1896  * @param path The current path
1897  * @param cmd_list List of all non collections in Path (gchar *path)
1898  * @param collection_list List of all collections in argv
1899  */
1900 void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
1901                     GList *cmd_list, GList *collection_list)
1902 {
1903         RemoteConnection *rc;
1904         gboolean started = FALSE;
1905         gchar *buf;
1906
1907         buf = g_build_filename(get_rc_dir(), ".command", NULL);
1908         rc = remote_client_open(buf);
1909         if (!rc)
1910                 {
1911                 GString *command;
1912                 GList *work;
1913                 gint retry_count = 12;
1914                 gboolean blank = FALSE;
1915
1916                 printf_term(FALSE, _("Remote %s not running, starting..."), GQ_APPNAME);
1917
1918                 command = g_string_new(arg_exec);
1919
1920                 work = remote_list;
1921                 while (work)
1922                         {
1923                         gchar *text;
1924                         RemoteCommandEntry *entry;
1925
1926                         text = static_cast<gchar *>(work->data);
1927                         work = work->next;
1928
1929                         entry = remote_command_find(text, nullptr);
1930                         if (entry)
1931                                 {
1932                                 /* If Geeqie is not running, stop the --new-window command opening a second window */
1933                                 if (g_strcmp0(text, "--new-window") == 0)
1934                                         {
1935                                         remote_list = g_list_remove(remote_list, text);
1936                                         }
1937                                 if (entry->prefer_command_line)
1938                                         {
1939                                         remote_list = g_list_remove(remote_list, text);
1940                                         g_string_append(command, " ");
1941                                         g_string_append(command, text);
1942                                         }
1943                                 if (entry->opt_l && strcmp(entry->opt_l, "file:") == 0)
1944                                         {
1945                                         blank = TRUE;
1946                                         }
1947                                 }
1948                         }
1949
1950                 if (blank || cmd_list || path) g_string_append(command, " --blank");
1951                 if (get_debug_level()) g_string_append(command, " --debug");
1952
1953                 g_string_append(command, " &");
1954                 runcmd(command->str);
1955                 g_string_free(command, TRUE);
1956
1957                 while (!rc && retry_count > 0)
1958                         {
1959                         usleep((retry_count > 10) ? 500000 : 1000000);
1960                         rc = remote_client_open(buf);
1961                         if (!rc) print_term(FALSE, ".");
1962                         retry_count--;
1963                         }
1964
1965                 print_term(FALSE, "\n");
1966
1967                 started = TRUE;
1968                 }
1969         g_free(buf);
1970
1971         if (rc)
1972                 {
1973                 GList *work;
1974                 const gchar *prefix;
1975                 gboolean use_path = TRUE;
1976                 gboolean sent = FALSE;
1977
1978                 work = remote_list;
1979                 while (work)
1980                         {
1981                         gchar *text;
1982                         RemoteCommandEntry *entry;
1983
1984                         text = static_cast<gchar *>(work->data);
1985                         work = work->next;
1986
1987                         entry = remote_command_find(text, nullptr);
1988                         if (entry &&
1989                             entry->opt_l &&
1990                             strcmp(entry->opt_l, "file:") == 0) use_path = FALSE;
1991
1992                         remote_client_send(rc, text);
1993
1994                         sent = TRUE;
1995                         }
1996
1997                 if (cmd_list && cmd_list->next)
1998                         {
1999                         prefix = "--list-add:";
2000                         remote_client_send(rc, "--list-clear");
2001                         }
2002                 else
2003                         {
2004                         prefix = "file:";
2005                         }
2006
2007                 work = cmd_list;
2008                 while (work)
2009                         {
2010                         gchar *text;
2011
2012                         text = g_strconcat(prefix, work->data, NULL);
2013                         remote_client_send(rc, text);
2014                         g_free(text);
2015                         work = work->next;
2016
2017                         sent = TRUE;
2018                         }
2019
2020                 if (path && !cmd_list && use_path)
2021                         {
2022                         gchar *text;
2023
2024                         text = g_strdup_printf("file:%s", path);
2025                         remote_client_send(rc, text);
2026                         g_free(text);
2027
2028                         sent = TRUE;
2029                         }
2030
2031                 work = collection_list;
2032                 while (work)
2033                         {
2034                         const gchar *name;
2035                         gchar *text;
2036
2037                         name = static_cast<const gchar *>(work->data);
2038                         work = work->next;
2039
2040                         text = g_strdup_printf("file:%s", name);
2041                         remote_client_send(rc, text);
2042                         g_free(text);
2043
2044                         sent = TRUE;
2045                         }
2046
2047                 if (!started && !sent)
2048                         {
2049                         remote_client_send(rc, "raise");
2050                         }
2051                 }
2052         else
2053                 {
2054                 print_term(TRUE, _("Remote not available\n"));
2055                 }
2056
2057         _exit(0);
2058 }
2059
2060 RemoteConnection *remote_server_init(gchar *path, CollectionData *command_collection)
2061 {
2062         RemoteConnection *remote_connection = remote_server_open(path);
2063         auto remote_data = g_new(RemoteData, 1);
2064
2065         remote_data->command_collection = command_collection;
2066
2067         remote_server_subscribe(remote_connection, remote_cb, remote_data);
2068         return remote_connection;
2069 }
2070 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */