Fix #635: Export in JPG
[geeqie.git] / src / remote.c
index 87d6223..15cb871 100644 (file)
@@ -1,33 +1,47 @@
 /*
- * Geeqie
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-
 #include "main.h"
 #include "remote.h"
 
+#include "cache_maint.h"
 #include "collect.h"
 #include "filedata.h"
+#include "image.h"
 #include "img-view.h"
 #include "layout.h"
 #include "layout_image.h"
+#include "layout_util.h"
 #include "misc.h"
+#include "pixbuf-renderer.h"
 #include "slideshow.h"
 #include "ui_fileops.h"
+#include "rcfile.h"
 
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <signal.h>
 #include <errno.h>
 
+#include "glua.h"
 
 #define SERVER_MAX_CLIENTS 8
 
 
 static RemoteConnection *remote_client_open(const gchar *path);
 static gint remote_client_send(RemoteConnection *rc, const gchar *text);
+static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data);
 
+static LayoutWindow *lw_id = NULL; /* points to the window set by the --id option */
 
 typedef struct _RemoteClient RemoteClient;
 struct _RemoteClient {
        gint fd;
-       gint channel_id;
+       guint channel_id; /* event source id */
        RemoteConnection *rc;
 };
 
@@ -62,12 +78,11 @@ static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition conditi
        RemoteConnection *rc;
        GIOStatus status = G_IO_STATUS_NORMAL;
 
+       lw_id = NULL;
        rc = client->rc;
 
        if (condition & G_IO_IN)
                {
-               GList *queue = NULL;
-               GList *work;
                gchar *buffer = NULL;
                GError *error = NULL;
                gsize termpos;
@@ -80,12 +95,11 @@ static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition conditi
 
                                if (strlen(buffer) > 0)
                                        {
-                                       queue = g_list_append(queue, buffer);
-                                       }
-                               else
-                                       {
-                                       g_free(buffer);
+                                       if (rc->read_func) rc->read_func(rc, buffer, source, rc->read_data);
+                                       g_io_channel_write_chars(source, "\n", -1, NULL, NULL); /* empty line finishes the command */
+                                       g_io_channel_flush(source, NULL);
                                        }
+                               g_free(buffer);
 
                                buffer = NULL;
                                }
@@ -96,18 +110,6 @@ static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition conditi
                        log_printf("error reading socket: %s\n", error->message);
                        g_error_free(error);
                        }
-
-               work = queue;
-               while (work)
-                       {
-                       gchar *command = work->data;
-                       work = work->next;
-
-                       if (rc->read_func) rc->read_func(rc, command, rc->read_data);
-                       g_free(command);
-                       }
-
-               g_list_free(queue);
                }
 
        if (condition & G_IO_HUP || status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR)
@@ -116,7 +118,7 @@ static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition conditi
 
                DEBUG_1("HUP detected, closing client.");
                DEBUG_1("client count %d", g_list_length(rc->clients));
-               
+
                g_source_remove(client->channel_id);
                close(client->fd);
                g_free(client);
@@ -182,7 +184,7 @@ static gboolean remote_server_read_cb(GIOChannel *source, GIOCondition condition
        return TRUE;
 }
 
-static gint remote_server_exists(const gchar *path)
+gboolean remote_server_exists(const gchar *path)
 {
        RemoteConnection *rc;
 
@@ -226,18 +228,14 @@ static RemoteConnection *remote_server_open(const gchar *path)
                }
 
        rc = g_new0(RemoteConnection, 1);
+
        rc->server = TRUE;
        rc->fd = fd;
        rc->path = g_strdup(path);
 
-       rc->read_func = NULL;
-       rc->read_data = NULL;
-
-       rc->clients = NULL;
-
        channel = g_io_channel_unix_new(rc->fd);
-       g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL); 
-       
+       g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
+
        rc->channel_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, G_IO_IN,
                                             remote_server_read_cb, rc, NULL);
        g_io_channel_unref(channel);
@@ -282,28 +280,27 @@ static RemoteConnection *remote_client_open(const gchar *path)
        rc->fd = fd;
        rc->path = g_strdup(path);
 
-       /* this might fix the freezes on freebsd, solaris, etc. - completely untested */
-       remote_client_send(rc, "\n");
-
        return rc;
 }
 
-static sig_atomic_t sigpipe_occured = FALSE;
+static sig_atomic_t sigpipe_occurred = FALSE;
 
 static void sighandler_sigpipe(gint sig)
 {
-       sigpipe_occured = TRUE;
+       sigpipe_occurred = TRUE;
 }
 
-static gint remote_client_send(RemoteConnection *rc, const gchar *text)
+static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
 {
        struct sigaction new_action, old_action;
-       gint ret = FALSE;
+       gboolean ret = FALSE;
+       GError *error = NULL;
+       GIOChannel *channel;
 
        if (!rc || rc->server) return FALSE;
        if (!text) return TRUE;
 
-       sigpipe_occured = FALSE;
+       sigpipe_occurred = FALSE;
 
        new_action.sa_handler = sighandler_sigpipe;
        sigemptyset(&new_action.sa_mask);
@@ -312,17 +309,16 @@ static gint remote_client_send(RemoteConnection *rc, const gchar *text)
        /* setup our signal handler */
        sigaction(SIGPIPE, &new_action, &old_action);
 
-       if (write(rc->fd, text, strlen(text)) == -1 ||
-           write(rc->fd, "\n", 1) == -1)
+       channel = g_io_channel_unix_new(rc->fd);
+
+       g_io_channel_write_chars(channel, text, -1, NULL, &error);
+       g_io_channel_write_chars(channel, "\n", -1, NULL, &error);
+       g_io_channel_flush(channel, &error);
+
+       if (error)
                {
-               if (sigpipe_occured)
-                       {
-                       log_printf("SIGPIPE writing to socket: %s\n", rc->path);
-                       }
-               else
-                       {
-                       log_printf("error writing to socket: %s\n", strerror(errno));
-                       }
+               log_printf("error reading socket: %s\n", error->message);
+               g_error_free(error);
                ret = FALSE;;
                }
        else
@@ -330,9 +326,39 @@ static gint remote_client_send(RemoteConnection *rc, const gchar *text)
                ret = TRUE;
                }
 
+       if (ret)
+               {
+               gchar *buffer = NULL;
+               gsize termpos;
+               while (g_io_channel_read_line(channel, &buffer, NULL, &termpos, &error) == G_IO_STATUS_NORMAL)
+                       {
+                       if (buffer)
+                               {
+                               if (buffer[0] == '\n') /* empty line finishes the command */
+                                       {
+                                       g_free(buffer);
+                                       fflush(stdout);
+                                       break;
+                                       }
+                               buffer[termpos] = '\0';
+                               printf("%s\n", buffer);
+                               g_free(buffer);
+                               buffer = NULL;
+                               }
+                       }
+
+               if (error)
+                       {
+                       log_printf("error reading socket: %s\n", error->message);
+                       g_error_free(error);
+                       ret = FALSE;
+                       }
+               }
+
+
        /* restore the original signal handler */
        sigaction(SIGPIPE, &old_action, NULL);
-
+       g_io_channel_unref(channel);
        return ret;
 }
 
@@ -363,112 +389,220 @@ void remote_close(RemoteConnection *rc)
  *-----------------------------------------------------------------------------
  */
 
-static void gr_image_next(const gchar *text, gpointer data)
+static void gr_image_next(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       layout_image_next(lw_id);
+}
+
+static void gr_new_window(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       LayoutWindow *lw = NULL;
+
+       if (!layout_valid(&lw)) return;
+
+       lw_id = layout_menu_new_window(NULL, lw);
+}
+
+static gboolean gr_close_window_cb()
+{
+       if (!layout_valid(&lw_id)) return FALSE;
+
+       layout_menu_close_cb(NULL, lw_id);
+
+       return FALSE;
+}
+
+static void gr_close_window(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_next(NULL);
+       g_idle_add(gr_close_window_cb, NULL);
 }
 
-static void gr_image_prev(const gchar *text, gpointer data)
+static void gr_image_prev(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_prev(NULL);
+       layout_image_prev(lw_id);
 }
 
-static void gr_image_first(const gchar *text, gpointer data)
+static void gr_image_first(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_first(NULL);
+       layout_image_first(lw_id);
 }
 
-static void gr_image_last(const gchar *text, gpointer data)
+static void gr_image_last(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_last(NULL);
+       layout_image_last(lw_id);
 }
 
-static void gr_fullscreen_toggle(const gchar *text, gpointer data)
+static void gr_fullscreen_toggle(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_full_screen_toggle(NULL);
+       layout_image_full_screen_toggle(lw_id);
 }
 
-static void gr_fullscreen_start(const gchar *text, gpointer data)
+static void gr_fullscreen_start(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_full_screen_start(NULL);
+       layout_image_full_screen_start(lw_id);
 }
 
-static void gr_fullscreen_stop(const gchar *text, gpointer data)
+static void gr_fullscreen_stop(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_full_screen_stop(NULL);
+       layout_image_full_screen_stop(lw_id);
 }
 
-static void gr_slideshow_start_rec(const gchar *text, gpointer data)
+static void gr_lw_id(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       lw_id = layout_find_by_layout_id(text);
+       if (!lw_id)
+               {
+               log_printf("remote sent window ID that does not exist:\"%s\"\n",text);
+               }
+       layout_valid(&lw_id);
+}
+
+static void gr_slideshow_start_rec(const gchar *text, GIOChannel *channel, gpointer data)
 {
        GList *list;
-       FileData *dir_fd = file_data_new_simple(text);
+       FileData *dir_fd = file_data_new_dir(text);
        list = filelist_recursive(dir_fd);
        file_data_unref(dir_fd);
        if (!list) return;
 //printf("length: %d\n", g_list_length(list));
-       layout_image_slideshow_stop(NULL);
-       layout_image_slideshow_start_from_list(NULL, list);
+       layout_image_slideshow_stop(lw_id);
+       layout_image_slideshow_start_from_list(lw_id, list);
+}
+
+static void gr_cache_thumb(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       if (!g_strcmp0(text, "clear"))
+               cache_maintain_home_remote(FALSE, TRUE);
+       else if (!g_strcmp0(text, "clean"))
+               cache_maintain_home_remote(FALSE, FALSE);
+}
+
+static void gr_cache_shared(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       if (!g_strcmp0(text, "clear"))
+               cache_manager_standard_process_remote(TRUE);
+       else if (!g_strcmp0(text, "clean"))
+               cache_manager_standard_process_remote(FALSE);
+}
+
+static void gr_cache_metadata(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       cache_maintain_home_remote(TRUE, FALSE);
+}
+
+static void gr_cache_render(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       cache_manager_render_remote(text, FALSE, FALSE);
+}
+
+static void gr_cache_render_recurse(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       cache_manager_render_remote(text, TRUE, FALSE);
 }
 
-static void gr_slideshow_toggle(const gchar *text, gpointer data)
+static void gr_cache_render_standard(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_slideshow_toggle(NULL);
+       if(options->thumbnails.spec_standard)
+               cache_manager_render_remote(text, FALSE, TRUE);
 }
 
-static void gr_slideshow_start(const gchar *text, gpointer data)
+static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_slideshow_start(NULL);
+       if(options->thumbnails.spec_standard)
+               cache_manager_render_remote(text, TRUE, TRUE);
 }
 
-static void gr_slideshow_stop(const gchar *text, gpointer data)
+static void gr_slideshow_toggle(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       layout_image_slideshow_stop(NULL);
+       layout_image_slideshow_toggle(lw_id);
 }
 
-static void gr_slideshow_delay(const gchar *text, gpointer data)
+static void gr_slideshow_start(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       gdouble n;
+       layout_image_slideshow_start(lw_id);
+}
+
+static void gr_slideshow_stop(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       layout_image_slideshow_stop(lw_id);
+}
 
-       n = strtod(text, NULL);
-       if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
+static void gr_slideshow_delay(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gdouble t1, t2, t3, n;
+       gint res;
+
+       res = sscanf(text, "%lf:%lf:%lf", &t1, &t2, &t3);
+       if (res == 3)
                {
-               printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
-                           SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
-               return;
+               n = (t1 * 3600) + (t2 * 60) + t3;
+               if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS ||
+                               t1 >= 24 || t2 >= 60 || t3 >= 60)
+                       {
+                       printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
+                                                               SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
+                       return;
+                       }
+               }
+       else if (res == 2)
+               {
+               n = t1 * 60 + t2;
+               if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS ||
+                               t1 >= 60 || t2 >= 60)
+                       {
+                       printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
+                                                               SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
+                       return;
+                       }
+               }
+       else if (res == 1)
+               {
+               n = t1;
+               if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
+                       {
+                       printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
+                                                               SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
+                       return;
+                       }
+               }
+       else
+               {
+               n = 0;
                }
+
        options->slideshow.delay = (gint)(n * 10.0 + 0.01);
 }
 
-static void gr_tools_show(const gchar *text, gpointer data)
+static void gr_tools_show(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       gint popped;
-       gint hidden;
+       gboolean popped;
+       gboolean hidden;
 
-       if (layout_tools_float_get(NULL, &popped, &hidden) && hidden)
+       if (layout_tools_float_get(lw_id, &popped, &hidden) && hidden)
                {
-               layout_tools_float_set(NULL, popped, FALSE);
+               layout_tools_float_set(lw_id, popped, FALSE);
                }
 }
 
-static void gr_tools_hide(const gchar *text, gpointer data)
+static void gr_tools_hide(const gchar *text, GIOChannel *channel, gpointer data)
 {
-       gint popped;
-       gint hidden;
+       gboolean popped;
+       gboolean hidden;
 
-       if (layout_tools_float_get(NULL, &popped, &hidden) && !hidden)
+       if (layout_tools_float_get(lw_id, &popped, &hidden) && !hidden)
                {
-               layout_tools_float_set(NULL, popped, TRUE);
+               layout_tools_float_set(lw_id, popped, TRUE);
                }
 }
 
-static gint gr_quit_idle_cb(gpointer data)
+static gboolean gr_quit_idle_cb(gpointer data)
 {
        exit_program();
 
        return FALSE;
 }
 
-static void gr_quit(const gchar *text, gpointer data)
+static void gr_quit(const gchar *text, GIOChannel *channel, gpointer data)
 {
        /* schedule exit when idle, if done from within a
         * remote handler remote_close will crash
@@ -476,7 +610,7 @@ static void gr_quit(const gchar *text, gpointer data)
        g_idle_add(gr_quit_idle_cb, NULL);
 }
 
-static void gr_file_load(const gchar *text, gpointer data)
+static void gr_file_load_no_raise(const gchar *text, GIOChannel *channel, gpointer data)
 {
        gchar *filename = expand_tilde(text);
 
@@ -488,30 +622,204 @@ static void gr_file_load(const gchar *text, gpointer data)
                        }
                else
                        {
-                       layout_set_path(NULL, filename);
+                       layout_set_path(lw_id, filename);
                        }
                }
        else if (isdir(filename))
                {
-               layout_set_path(NULL, filename);
+               layout_set_path(lw_id, filename);
                }
        else
                {
                log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
+               layout_set_path(lw_id, homedir());
                }
 
        g_free(filename);
 }
 
-static void gr_file_view(const gchar *text, gpointer data)
+static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gr_file_load_no_raise(text, channel, data);
+
+       gr_raise(text, channel, data);
+}
+
+static void gr_pixel_info(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *pixel_info;
+       gint x_pixel, y_pixel;
+       gint width, height;
+       gint r_mouse, g_mouse, b_mouse;
+       PixbufRenderer *pr;
+       LayoutWindow *lw = NULL;
+
+       if (!layout_valid(&lw_id)) return;
+
+       pr = (PixbufRenderer*)lw_id->image->pr;
+
+       if (pr)
+               {
+               pixbuf_renderer_get_image_size(pr, &width, &height);
+               if (width < 1 || height < 1) return;
+
+               pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
+
+               if (x_pixel >= 0 && y_pixel >= 0)
+                       {
+                       pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
+                                                        &r_mouse, &g_mouse, &b_mouse);
+
+                       pixel_info = g_strdup_printf(_("[%d,%d]: RGB(%3d,%3d,%3d)"),
+                                                x_pixel, y_pixel,
+                                                r_mouse, g_mouse, b_mouse);
+
+                       g_io_channel_write_chars(channel, pixel_info, -1, NULL, NULL);
+                       g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+                       g_free(pixel_info);
+                       }
+               else
+                       {
+                       return;
+                       }
+               }
+       else
+               {
+               return;
+               }
+}
+
+static void gr_rectangle(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *rectangle_info;
+       PixbufRenderer *pr;
+       LayoutWindow *lw = NULL;
+       gint x1, y1, x2, y2;
+
+       if (!options->draw_rectangle) return;
+       if (!layout_valid(&lw_id)) return;
+
+       pr = (PixbufRenderer*)lw_id->image->pr;
+
+       if (pr)
+               {
+               image_get_rectangle(&x1, &y1, &x2, &y2);
+               rectangle_info = g_strdup_printf(_("%dx%d+%d+%d"),
+                                       (x2 > x1) ? x2 - x1 : x1 - x2,
+                                       (y2 > y1) ? y2 - y1 : y1 - y2,
+                                       (x2 > x1) ? x1 : x2,
+                                       (y2 > y1) ? y1 : y2);
+
+               g_io_channel_write_chars(channel, rectangle_info, -1, NULL, NULL);
+               g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+               g_free(rectangle_info);
+               }
+}
+
+static void gr_render_intent(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *render_intent;
+
+       switch (options->color_profile.render_intent)
+               {
+               case 0:
+                       render_intent = g_strdup("Perceptual");
+                       break;
+               case 1:
+                       render_intent = g_strdup("Relative Colorimetric");
+                       break;
+               case 2:
+                       render_intent = g_strdup("Saturation");
+                       break;
+               case 3:
+                       render_intent = g_strdup("Absolute Colorimetric");
+                       break;
+               default:
+                       render_intent = g_strdup("none");
+                       break;
+               }
+
+       g_io_channel_write_chars(channel, render_intent, -1, NULL, NULL);
+       g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+       g_free(render_intent);
+}
+
+static void gr_file_tell(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       if (!layout_valid(&lw_id)) return;
+
+       if (image_get_path(lw_id->image))
+               {
+               g_io_channel_write_chars(channel, image_get_path(lw_id->image), -1, NULL, NULL);
+               g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+               }
+}
+
+static void gr_config_load(const gchar *text, GIOChannel *channel, gpointer data)
 {
        gchar *filename = expand_tilde(text);
 
-       view_window_new(file_data_new_simple(filename));
+       if (isfile(filename))
+               {
+               load_config_from_file(filename, FALSE);
+               }
+       else
+               {
+               log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
+               layout_set_path(NULL, homedir());
+               }
+
        g_free(filename);
 }
 
-static void gr_list_clear(const gchar *text, gpointer data)
+static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *filename = expand_tilde(text);
+       FileData *fd = file_data_new_group(filename);
+
+       GList *work;
+       if (fd->parent) fd = fd->parent;
+
+       g_io_channel_write_chars(channel, fd->path, -1, NULL, NULL);
+       g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+       work = fd->sidecar_files;
+
+       while (work)
+               {
+               fd = work->data;
+               work = work->next;
+               g_io_channel_write_chars(channel, fd->path, -1, NULL, NULL);
+               g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+               }
+       g_free(filename);
+}
+
+static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *filename = expand_tilde(text);
+       FileData *fd = file_data_new_group(filename);
+
+       if (fd->change && fd->change->dest)
+               {
+               g_io_channel_write_chars(channel, fd->change->dest, -1, NULL, NULL);
+               g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+               }
+       g_free(filename);
+}
+
+static void gr_file_view(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *filename = expand_tilde(text);
+
+       view_window_new(file_data_new_group(filename));
+       g_free(filename);
+}
+
+static void gr_list_clear(const gchar *text, GIOChannel *channel, gpointer data)
 {
        RemoteData *remote_data = data;
 
@@ -522,10 +830,10 @@ static void gr_list_clear(const gchar *text, gpointer data)
                }
 }
 
-static void gr_list_add(const gchar *text, gpointer data)
+static void gr_list_add(const gchar *text, GIOChannel *channel, gpointer data)
 {
        RemoteData *remote_data = data;
-       gint new = TRUE;
+       gboolean new = TRUE;
 
        if (!remote_data->command_collection)
                {
@@ -545,61 +853,116 @@ static void gr_list_add(const gchar *text, gpointer data)
                new = (!collection_get_first(remote_data->command_collection));
                }
 
-       if (collection_add(remote_data->command_collection, file_data_new_simple(text), FALSE) && new)
+       if (collection_add(remote_data->command_collection, file_data_new_group(text), FALSE) && new)
                {
                layout_image_set_collection(NULL, remote_data->command_collection,
                                            collection_get_first(remote_data->command_collection));
                }
 }
 
-static void gr_raise(const gchar *text, gpointer data)
+static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data)
 {
        LayoutWindow *lw = NULL;
 
-       if (layout_valid(&lw))
+       if (layout_valid(&lw_id))
+               {
+               gtk_window_present(GTK_WINDOW(lw_id->window));
+               }
+}
+
+#ifdef HAVE_LUA
+static void gr_lua(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       gchar *result = NULL;
+       gchar **lua_command;
+
+       lua_command = g_strsplit(text, ",", 2);
+
+       if (lua_command[0] && lua_command[1])
+               {
+               FileData *fd = file_data_new_group(lua_command[0]);
+               result = g_strdup(lua_callvalue(fd, lua_command[1], NULL));
+               if (result)
+                       {
+                       g_io_channel_write_chars(channel, result, -1, NULL, NULL);
+                       }
+               else
+                       {
+                       g_io_channel_write_chars(channel, N_("lua error: no data"), -1, NULL, NULL);
+                       }
+               }
+       else
                {
-               gtk_window_present(GTK_WINDOW(lw->window));
+               g_io_channel_write_chars(channel, N_("lua error: no data"), -1, NULL, NULL);
                }
+
+       g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+       g_strfreev(lua_command);
+       g_free(result);
 }
+#endif
 
 typedef struct _RemoteCommandEntry RemoteCommandEntry;
 struct _RemoteCommandEntry {
        gchar *opt_s;
        gchar *opt_l;
-       void (*func)(const gchar *text, gpointer data);
-       gint needs_extra;
-       gint prefer_command_line;
+       void (*func)(const gchar *text, GIOChannel *channel, gpointer data);
+       gboolean needs_extra;
+       gboolean prefer_command_line;
+       gchar *parameter;
        gchar *description;
 };
 
 static RemoteCommandEntry remote_commands[] = {
-       /* short, long                  callback,               extra, prefer,description */
-       { "-n", "--next",               gr_image_next,          FALSE, FALSE, N_("next image") },
-       { "-b", "--back",               gr_image_prev,          FALSE, FALSE, N_("previous image") },
-       { NULL, "--first",              gr_image_first,         FALSE, FALSE, N_("first image") },
-       { NULL, "--last",               gr_image_last,          FALSE, FALSE, N_("last image") },
-       { "-f", "--fullscreen",         gr_fullscreen_toggle,   FALSE, TRUE,  N_("toggle full screen") },
-       { "-fs","--fullscreen-start",   gr_fullscreen_start,    FALSE, FALSE, N_("start full screen") },
-       { "-fS","--fullscreen-stop",    gr_fullscreen_stop,     FALSE, FALSE, N_("stop full screen") },
-       { "-s", "--slideshow",          gr_slideshow_toggle,    FALSE, TRUE,  N_("toggle slide show") },
-       { "-ss","--slideshow-start",    gr_slideshow_start,     FALSE, FALSE, N_("start slide show") },
-       { "-sS","--slideshow-stop",     gr_slideshow_stop,      FALSE, FALSE, N_("stop slide show") },
-       { "-sr","--slideshow-recurse",  gr_slideshow_start_rec, TRUE,  FALSE, N_("start recursive slide show") },
-       { "-d", "--delay=",             gr_slideshow_delay,     TRUE,  FALSE, N_("set slide show delay in seconds") },
-       { "+t", "--tools-show",         gr_tools_show,          FALSE, TRUE,  N_("show tools") },
-       { "-t", "--tools-hide",         gr_tools_hide,          FALSE, TRUE,  N_("hide tools") },
-       { "-q", "--quit",               gr_quit,                FALSE, FALSE, N_("quit") },
-       { NULL, "file:",                gr_file_load,           TRUE,  FALSE, N_("open file") },
-       { NULL, "view:",                gr_file_view,           TRUE,  FALSE, N_("open file in new window") },
-       { NULL, "--list-clear",         gr_list_clear,          FALSE, FALSE, NULL },
-       { NULL, "--list-add:",          gr_list_add,            TRUE,  FALSE, NULL },
-       { NULL, "raise",                gr_raise,               FALSE, FALSE, NULL },
-       { NULL, NULL, NULL, FALSE, FALSE, NULL }
+       /* short, long                  callback,               extra, prefer, parameter, description */
+       { "-n", "--next",               gr_image_next,          FALSE, FALSE, NULL, N_("next image") },
+       { "-b", "--back",               gr_image_prev,          FALSE, FALSE, NULL, N_("previous image") },
+       { NULL, "--first",              gr_image_first,         FALSE, FALSE, NULL, N_("first image") },
+       { NULL, "--last",               gr_image_last,          FALSE, FALSE, NULL, N_("last image") },
+       { "-f", "--fullscreen",         gr_fullscreen_toggle,   FALSE, TRUE,  NULL, N_("toggle full screen") },
+       { "-fs","--fullscreen-start",   gr_fullscreen_start,    FALSE, FALSE, NULL, N_("start full screen") },
+       { "-fS","--fullscreen-stop",    gr_fullscreen_stop,     FALSE, FALSE, NULL, N_("stop full screen") },
+       { "-s", "--slideshow",          gr_slideshow_toggle,    FALSE, TRUE,  NULL, N_("toggle slide show") },
+       { "-ss","--slideshow-start",    gr_slideshow_start,     FALSE, FALSE, NULL, N_("start slide show") },
+       { "-sS","--slideshow-stop",     gr_slideshow_stop,      FALSE, FALSE, NULL, N_("stop slide show") },
+       { NULL, "--slideshow-recurse:", gr_slideshow_start_rec, TRUE,  FALSE, N_("<FOLDER>"), N_("start recursive slide show in FOLDER") },
+       { "-d", "--delay=",             gr_slideshow_delay,     TRUE,  FALSE, N_("<[H:][M:][N][.M]>"), N_("set slide show delay to Hrs Mins N.M seconds") },
+       { "+t", "--tools-show",         gr_tools_show,          FALSE, TRUE,  NULL, N_("show tools") },
+       { "-t", "--tools-hide",         gr_tools_hide,          FALSE, TRUE,  NULL, N_("hide tools") },
+       { "-q", "--quit",               gr_quit,                FALSE, FALSE, NULL, N_("quit") },
+       { NULL, "--config-load:",       gr_config_load,         TRUE,  FALSE, N_("<FILE>"), N_("load configuration from FILE") },
+       { NULL, "--get-sidecars:",      gr_get_sidecars,        TRUE,  FALSE, N_("<FILE>"), N_("get list of sidecars of FILE") },
+       { NULL, "--get-destination:",   gr_get_destination,     TRUE,  FALSE, N_("<FILE>"), N_("get destination path of FILE") },
+       { NULL, "file:",                gr_file_load,           TRUE,  FALSE, N_("<FILE>"), N_("open FILE, bring Geeqie window to the top") },
+       { NULL, "File:",                gr_file_load_no_raise,  TRUE,  FALSE, N_("<FILE>"), N_("open FILE, do not bring Geeqie window to the top") },
+       { NULL, "--tell",               gr_file_tell,           FALSE, FALSE, NULL, N_("print filename of current image") },
+       { NULL, "--pixel-info",         gr_pixel_info,          FALSE, FALSE, NULL, N_("print pixel info of mouse pointer on current image") },
+       { NULL, "--get-rectangle",      gr_rectangle,           FALSE, FALSE, NULL, N_("get rectangle co-ordinates") },
+       { NULL, "--get-render-intent",  gr_render_intent,       FALSE, FALSE, NULL, N_("get render intent") },
+       { NULL, "view:",                gr_file_view,           TRUE,  FALSE, N_("<FILE>"), N_("open FILE in new window") },
+       { NULL, "--list-clear",         gr_list_clear,          FALSE, FALSE, NULL, N_("clear command line collection list") },
+       { NULL, "--list-add:",          gr_list_add,            TRUE,  FALSE, N_("<FILE>"), N_("add FILE to command line collection list") },
+       { NULL, "raise",                gr_raise,               FALSE, FALSE, NULL, N_("bring the Geeqie window to the top") },
+       { NULL, "--id:",                gr_lw_id,               TRUE, FALSE, N_("<ID>"), N_("window id for following commands") },
+       { NULL, "--new-window",         gr_new_window,          FALSE, FALSE, NULL, N_("new window") },
+       { NULL, "--close-window",       gr_close_window,        FALSE, FALSE, NULL, N_("close window") },
+       { "-ct:", "--cache-thumbs:",    gr_cache_thumb,         TRUE, FALSE, N_("clear|clean"), N_("clear or clean thumbnail cache") },
+       { "-cs:", "--cache-shared:",    gr_cache_shared,        TRUE, FALSE, N_("clear|clean"), N_("clear or clean shared thumbnail cache") },
+       { "-cm","--cache-metadata",      gr_cache_metadata,               FALSE, FALSE, NULL, N_("    clean the metadata cache") },
+       { "-cr:", "--cache-render:",    gr_cache_render,        TRUE, FALSE, N_("<folder>  "), N_(" render thumbnails") },
+       { "-crr:", "--cache-render-recurse:", gr_cache_render_recurse, TRUE, FALSE, N_("<folder> "), N_("render thumbnails recursively") },
+       { "-crs:", "--cache-render-shared:", gr_cache_render_standard, TRUE, FALSE, N_("<folder> "), N_(" render thumbnails (see Help)") },
+       { "-crsr:", "--cache-render-shared-recurse:", gr_cache_render_standard_recurse, TRUE, FALSE, N_("<folder>"), N_(" render thumbnails recursively (see Help)") },
+#ifdef HAVE_LUA
+       { NULL, "--lua:",               gr_lua,                 TRUE, FALSE, N_("<FILE>,<lua script>"), N_("run lua script on FILE") },
+#endif
+       { NULL, NULL, NULL, FALSE, FALSE, NULL, NULL }
 };
 
 static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **offset)
 {
-       gint match = FALSE;
+       gboolean match = FALSE;
        gint i;
 
        i = 0;
@@ -636,7 +999,7 @@ static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar **
        return NULL;
 }
 
-static void remote_cb(RemoteConnection *rc, const gchar *text, gpointer data)
+static void remote_cb(RemoteConnection *rc, const gchar *text, GIOChannel *channel, gpointer data)
 {
        RemoteCommandEntry *entry;
        const gchar *offset;
@@ -644,7 +1007,7 @@ static void remote_cb(RemoteConnection *rc, const gchar *text, gpointer data)
        entry = remote_command_find(text, &offset);
        if (entry && entry->func)
                {
-               entry->func(offset, data);
+               entry->func(offset, channel, data);
                }
        else
                {
@@ -655,22 +1018,29 @@ static void remote_cb(RemoteConnection *rc, const gchar *text, gpointer data)
 void remote_help(void)
 {
        gint i;
+       gchar *s_opt_param;
+       gchar *l_opt_param;
 
-       print_term(_("Remote command list:\n"));
+       print_term(FALSE, _("Remote command list:\n"));
 
        i = 0;
        while (remote_commands[i].func != NULL)
                {
                if (remote_commands[i].description)
                        {
-                       printf_term("  %-3s%s %-20s %s\n",
-                                   (remote_commands[i].opt_s) ? remote_commands[i].opt_s : "",
+                       s_opt_param = g_strconcat(remote_commands[i].opt_s, remote_commands[i].parameter, NULL);
+                       l_opt_param = g_strconcat(remote_commands[i].opt_l, remote_commands[i].parameter, NULL);
+                       printf_term(FALSE, "  %-11s%-1s %-30s%-s\n",
+                                   (remote_commands[i].opt_s) ? s_opt_param : "",
                                    (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
-                                   (remote_commands[i].opt_l) ? remote_commands[i].opt_l : "",
+                                   (remote_commands[i].opt_l) ? l_opt_param : "",
                                    _(remote_commands[i].description));
+                       g_free(s_opt_param);
+                       g_free(l_opt_param);
                        }
                i++;
                }
+       printf_term(FALSE, N_("\n  All other command line parameters are used as plain files if they exists.\n"));
 }
 
 GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
@@ -687,7 +1057,7 @@ GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
                        {
                        list = g_list_append(list, argv[i]);
                        }
-               else if (errors)
+               else if (errors && !isfile(argv[i]))
                        {
                        *errors = g_list_append(*errors, argv[i]);
                        }
@@ -697,11 +1067,18 @@ GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
        return list;
 }
 
+/**
+ * \param arg_exec Binary (argv0)
+ * \param remote_list Evaluated and recognized remote commands
+ * \param path The current path
+ * \param cmd_list List of all non collections in Path
+ * \param collection_list List of all collections in argv
+ */
 void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
                    GList *cmd_list, GList *collection_list)
 {
        RemoteConnection *rc;
-       gint started = FALSE;
+       gboolean started = FALSE;
        gchar *buf;
 
        buf = g_build_filename(get_rc_dir(), ".command", NULL);
@@ -711,9 +1088,9 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path
                GString *command;
                GList *work;
                gint retry_count = 12;
-               gint blank = FALSE;
+               gboolean blank = FALSE;
 
-               printf_term(_("Remote %s not running, starting..."), GQ_APPNAME);
+               printf_term(FALSE, _("Remote %s not running, starting..."), GQ_APPNAME);
 
                command = g_string_new(arg_exec);
 
@@ -753,11 +1130,11 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path
                        {
                        usleep((retry_count > 10) ? 500000 : 1000000);
                        rc = remote_client_open(buf);
-                       if (!rc) print_term(".");
+                       if (!rc) print_term(FALSE, ".");
                        retry_count--;
                        }
 
-               print_term("\n");
+               print_term(FALSE, "\n");
 
                started = TRUE;
                }
@@ -767,8 +1144,8 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path
                {
                GList *work;
                const gchar *prefix;
-               gint use_path = TRUE;
-               gint sent = FALSE;
+               gboolean use_path = TRUE;
+               gboolean sent = FALSE;
 
                work = remote_list;
                while (work)
@@ -849,7 +1226,7 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path
                }
        else
                {
-               print_term(_("Remote not available\n"));
+               print_term(TRUE, _("Remote not available\n"));
                }
 
        _exit(0);
@@ -859,7 +1236,7 @@ RemoteConnection *remote_server_init(gchar *path, CollectionData *command_collec
 {
        RemoteConnection *remote_connection = remote_server_open(path);
        RemoteData *remote_data = g_new(RemoteData, 1);
-       
+
        remote_data->command_collection = command_collection;
 
        remote_server_subscribe(remote_connection, remote_cb, remote_data);