Fix #314: Remote commands for thumbnail maintenance
[geeqie.git] / src / remote.c
index df2b691..e32f272 100644 (file)
@@ -1,21 +1,31 @@
 /*
- * Geeqie
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2012 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"
@@ -42,6 +52,7 @@
 
 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);
 
 
 typedef struct _RemoteClient RemoteClient;
@@ -420,6 +431,54 @@ static void gr_slideshow_start_rec(const gchar *text, GIOChannel *channel, gpoin
        layout_image_slideshow_start_from_list(NULL, 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_clear(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       cache_maintain_home_remote(FALSE, TRUE);
+}
+
+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_cache_render_standard(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       if(options->thumbnails.spec_standard)
+               cache_manager_render_remote(text, FALSE, TRUE);
+}
+
+static void gr_cache_render_standard_recurse(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       if(options->thumbnails.spec_standard)
+               cache_manager_render_remote(text, TRUE, TRUE);
+}
+
 static void gr_slideshow_toggle(const gchar *text, GIOChannel *channel, gpointer data)
 {
        layout_image_slideshow_toggle(NULL);
@@ -486,7 +545,7 @@ static void gr_quit(const gchar *text, GIOChannel *channel, gpointer data)
        g_idle_add(gr_quit_idle_cb, NULL);
 }
 
-static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data)
+static void gr_file_load_no_raise(const gchar *text, GIOChannel *channel, gpointer data)
 {
        gchar *filename = expand_tilde(text);
 
@@ -508,11 +567,30 @@ static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data)
        else
                {
                log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
+               layout_set_path(NULL, homedir());
                }
 
        g_free(filename);
 }
 
+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_file_tell(const gchar *text, GIOChannel *channel, gpointer data)
+{
+       LayoutWindow *lw = NULL; /* NULL to force layout_valid() to do some magic */
+       if (!layout_valid(&lw)) return;
+       if (image_get_path(lw->image))
+               {
+               g_io_channel_write_chars(channel, image_get_path(lw->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);
@@ -524,6 +602,7 @@ static void gr_config_load(const gchar *text, GIOChannel *channel, gpointer data
        else
                {
                log_printf("remote sent filename that does not exist:\"%s\"\n", filename);
+               layout_set_path(NULL, homedir());
                }
 
        g_free(filename);
@@ -655,11 +734,20 @@ static RemoteCommandEntry remote_commands[] = {
        { 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") },
+       { 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, "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") },
+       { "-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)") },
        { NULL, NULL, NULL, FALSE, FALSE, NULL }
 };