Trim trailing white spaces on empty lines.
[geeqie.git] / src / remote.c
index 39ae67f..579811a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -102,7 +102,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);
@@ -212,14 +212,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);
 
        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);
@@ -321,6 +321,7 @@ static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
                                if (buffer[0] == '\n') /* empty line finishes the command */
                                        {
                                        g_free(buffer);
+                                       fflush(stdout);
                                        break;
                                        }
                                buffer[termpos] = '\0';
@@ -337,7 +338,7 @@ static gboolean remote_client_send(RemoteConnection *rc, const gchar *text)
                        ret = FALSE;
                        }
                }
-               
+
 
        /* restore the original signal handler */
        sigaction(SIGPIPE, &old_action, NULL);
@@ -410,7 +411,7 @@ static void gr_fullscreen_stop(const gchar *text, GIOChannel *channel, gpointer
 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;
@@ -528,11 +529,47 @@ static void gr_config_load(const gchar *text, GIOChannel *channel, gpointer data
        g_free(filename);
 }
 
+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_simple(filename));
+       view_window_new(file_data_new_group(filename));
        g_free(filename);
 }
 
@@ -570,7 +607,7 @@ static void gr_list_add(const gchar *text, GIOChannel *channel, 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));
@@ -615,6 +652,8 @@ static RemoteCommandEntry remote_commands[] = {
        { "-t", "--tools-hide",         gr_tools_hide,          FALSE, TRUE,  N_("hide tools") },
        { "-q", "--quit",               gr_quit,                FALSE, FALSE, N_("quit") },
        { NULL, "--config-load:",       gr_config_load,         TRUE,  FALSE, N_("load config file") },
+       { NULL, "--get-sidecars:",      gr_get_sidecars,        TRUE,  FALSE, N_("get list of sidecars of the given file") },
+       { NULL, "--get-destination:",   gr_get_destination,     TRUE,  FALSE, N_("get destination path for the given file") },
        { 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 },
@@ -697,6 +736,7 @@ void remote_help(void)
                        }
                i++;
                }
+       printf_term(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)
@@ -713,7 +753,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]);
                        }
@@ -723,6 +763,13 @@ 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)
 {
@@ -885,7 +932,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);