Fix #822: The image rotation keys ([ and ]) affect the wrong image
authorColin Clark <colin.clark@cclark.uk>
Fri, 15 Jan 2021 12:43:54 +0000 (12:43 +0000)
committerColin Clark <colin.clark@cclark.uk>
Fri, 15 Jan 2021 12:43:54 +0000 (12:43 +0000)
https://github.com/BestImageViewer/geeqie/issues/822

If a call is of the format:
geeqie /<folder1>/*jpg
Geeqie opens folder1 with the listed files selected.

If a call is of the format:
geeqie /<folder1>/*jpg /<folder2>/*jpg
Geeqie opens folder1 and the listed files are displayed in an unnamed
collection.

The hidden command line collection feature of previous versions is
deleted.

src/layout.c
src/layout.h
src/main.c
src/remote.c
src/view_file.h
src/view_file/view_file.c
src/view_file/view_file_icon.c
src/view_file/view_file_icon.h
src/view_file/view_file_list.c
src/view_file/view_file_list.h

index 7a0e1b8..0040057 100644 (file)
@@ -1086,6 +1086,16 @@ void layout_select_invert(LayoutWindow *lw)
        if (lw->vf) vf_select_invert(lw->vf);
 }
 
+void layout_select_list(LayoutWindow *lw, GList *list)
+{
+       if (!layout_valid(&lw)) return;
+
+       if (lw->vf)
+               {
+               vf_select_list(lw->vf, list);
+               }
+}
+
 void layout_mark_to_selection(LayoutWindow *lw, gint mark, MarkToSelectionMode mode)
 {
        if (!layout_valid(&lw)) return;
index 78bbfaf..ddb0d89 100644 (file)
@@ -75,6 +75,7 @@ guint layout_selection_count(LayoutWindow *lw, gint64 *bytes);
 void layout_select_all(LayoutWindow *lw);
 void layout_select_none(LayoutWindow *lw);
 void layout_select_invert(LayoutWindow *lw);
+void layout_select_list(LayoutWindow *lw, GList *list);
 
 void layout_mark_to_selection(LayoutWindow *lw, gint mark, MarkToSelectionMode mode);
 void layout_selection_to_mark(LayoutWindow *lw, gint mark, SelectionToMarkMode mode);
index 4af654f..1356f9a 100644 (file)
@@ -138,7 +138,7 @@ static void parse_command_line_add_file(const gchar *file_path, gchar **path, gc
                {
                if (!*path) *path = remove_level_from_path(path_parsed);
                if (!*file) *file = g_strdup(path_parsed);
-               *list = g_list_prepend(*list, file_data_new_no_grouping(path_parsed));
+               *list = g_list_prepend(*list, path_parsed);
                }
 }
 
@@ -452,7 +452,13 @@ static void parse_command_line(gint argc, gchar *argv[])
                                remote_list = g_list_prepend(remote_list, geometry);
                                }
                        remote_list = g_list_prepend(remote_list, "--new-window");
-               }
+                       }
+               else if (!remote_server_exists(app_lock))
+                       {
+                       /* Geeqie started for first time but with --remote option
+                        */
+                       remote_do = FALSE;
+                       }
                g_free(app_lock);
                }
 
@@ -482,6 +488,8 @@ static void parse_command_line(gint argc, gchar *argv[])
                remote_list = g_list_prepend(remote_list, pwd);
 
                remote_control(argv[0], remote_list, command_line->path, list, command_line->collection_list);
+               /* There is no return to this point
+                */
                g_free(pwd);
                g_free(current_dir);
                }
@@ -494,7 +502,7 @@ static void parse_command_line(gint argc, gchar *argv[])
                }
        else
                {
-               filelist_free(list);
+               string_list_free(list);
                command_line->cmd_list = NULL;
                }
 
@@ -900,6 +908,8 @@ gint main(gint argc, gchar *argv[])
        gchar *buf;
        CollectionData *cd = NULL;
        gboolean disable_clutter = FALSE;
+       gboolean single_dir = TRUE;
+       LayoutWindow *lw;
 
 #ifdef HAVE_GTHREAD
 #if !GLIB_CHECK_VERSION(2,32,0)
@@ -1037,6 +1047,9 @@ gint main(gint argc, gchar *argv[])
 
        layout_editors_reload_start();
 
+       /* If no --list option, open a separate collection window for each
+        * .gqv file on the command line
+        */
        if (command_line->collection_list && !command_line->startup_command_line_collection)
                {
                GList *work;
@@ -1064,34 +1077,59 @@ gint main(gint argc, gchar *argv[])
                command_line->ssi = secure_open(pathl);
                }
 
-       if (command_line->cmd_list ||
-           (command_line->startup_command_line_collection && command_line->collection_list))
+       /* If there is a files list on the command line and no --list option,
+        * check if they are all in the same folder
+        */
+       if (command_line->cmd_list && !(command_line->startup_command_line_collection))
                {
                GList *work;
+               gchar *path = NULL;
 
-               if (command_line->startup_command_line_collection)
-                       {
-                       CollectWindow *cw;
+               work = command_line->cmd_list;
 
-                       cw = collection_window_new("");
-                       cd = cw->cd;
-                       }
-               else
+               while (work && single_dir)
                        {
-                       cd = collection_new("");        /* if we pass NULL, untitled counter is falsely increm. */
+                       gchar *dirname;
+
+                       dirname = g_path_get_dirname(work->data);
+                       if (!path)
+                               {
+                               path = g_strdup(dirname);
+                               }
+                       else
+                               {
+                               if (g_strcmp0(path, dirname) != 0)
+                                       {
+                                       single_dir = FALSE;
+                                       }
+                               }
+                       g_free(dirname);
+                       work = work->next;
                        }
+               g_free(path);
+               }
 
-               g_free(cd->path);
-               cd->path = NULL;
-               g_free(cd->name);
-               cd->name = g_strdup(_("Command line"));
+       /* Files from multiple folders, or --list option given
+        * then open an unnamed collection and insert all files
+        */
+       if ((command_line->cmd_list && !single_dir) || (command_line->startup_command_line_collection))
+               {
+               GList *work;
+               CollectWindow *cw;
+
+               cw = collection_window_new(NULL);
+               cd = cw->cd;
 
                collection_path_changed(cd);
 
                work = command_line->cmd_list;
                while (work)
                        {
-                       collection_add(cd, (FileData *)work->data, FALSE);
+                       FileData *fd;
+
+                       fd = file_data_new_simple(work->data);
+                       collection_add(cd, fd, FALSE);
+                       file_data_unref(fd);
                        work = work->next;
                        }
 
@@ -1119,6 +1157,29 @@ gint main(gint argc, gchar *argv[])
                                            collection_get_first(first_collection));
                }
 
+       /* If the files on the command line are from one folder, select those files
+        */
+       lw = NULL;
+       layout_valid(&lw);
+
+       if (single_dir && command_line->cmd_list)
+               {
+               GList *work;
+               GList *selected;
+               FileData *fd;
+
+               selected = NULL;
+               work = command_line->cmd_list;
+               while (work)
+                       {
+                       fd = file_data_new_simple((gchar *)work->data);
+                       selected = g_list_append(selected, fd);
+                       file_data_unref(fd);
+                       work = work->next;
+                       }
+               layout_select_list(lw, selected);
+               }
+
        buf = g_build_filename(get_rc_dir(), ".command", NULL);
        remote_connection = remote_server_init(buf, cd);
        g_free(buf);
index 78634cf..6f44424 100644 (file)
@@ -38,6 +38,7 @@
 #include "slideshow.h"
 #include "ui_fileops.h"
 #include "rcfile.h"
+#include "view_file.h"
 
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -72,6 +73,8 @@ struct _RemoteClient {
 typedef struct _RemoteData RemoteData;
 struct _RemoteData {
        CollectionData *command_collection;
+       GList *file_list;
+       gboolean single_dir;
 };
 
 /* To enable file names containing newlines to be processed correctly,
@@ -1221,39 +1224,87 @@ static void gr_list_clear(const gchar *text, GIOChannel *channel, gpointer data)
 {
        RemoteData *remote_data = data;
 
-       if (remote_data->command_collection)
-               {
-               collection_unref(remote_data->command_collection);
-               remote_data->command_collection = NULL;
-               }
+       remote_data->command_collection = NULL;
+       remote_data->file_list = NULL;
+       remote_data->single_dir = TRUE;
 }
 
 static void gr_list_add(const gchar *text, GIOChannel *channel, gpointer data)
 {
        RemoteData *remote_data = data;
        gboolean new = TRUE;
+       gchar *path = NULL;
+       FileData *fd;
+       FileData *first;
 
-       if (!remote_data->command_collection)
+       /* If there is a files list on the command line
+        * check if they are all in the same folder
+        */
+       if (remote_data->single_dir)
                {
+               GList *work;
+               work = remote_data->file_list;
+               while (work && remote_data->single_dir)
+                       {
+                       gchar *dirname;
+                       dirname = g_path_get_dirname(((FileData *)work->data)->path);
+                       if (!path)
+                               {
+                               path = g_strdup(dirname);
+                               }
+                       else
+                               {
+                               if (g_strcmp0(path, dirname) != 0)
+                                       {
+                                       remote_data->single_dir = FALSE;
+                                       }
+                               }
+                       g_free(dirname);
+                       work = work->next;
+                       }
+               g_free(path);
+               }
+
+       gchar *pathname = g_path_get_dirname(text);
+       layout_set_path(lw_id, pathname);
+       g_free(pathname);
+
+       fd = file_data_new_simple(text);
+       remote_data->file_list = g_list_append(remote_data->file_list, fd);
+       file_data_unref(fd);
+
+       vf_select_none(lw_id->vf);
+       remote_data->file_list = g_list_reverse(remote_data->file_list);
+
+       layout_select_list(lw_id, remote_data->file_list);
+       layout_refresh(lw_id);
+       first = (FileData *)(g_list_first(vf_selection_get_list(lw_id->vf))->data);
+       layout_set_fd(lw_id, first);
+
                CollectionData *cd;
+               CollectWindow *cw;
 
-               cd = collection_new("");
+       if (!remote_data->command_collection && !remote_data->single_dir)
+               {
+               cw = collection_window_new(NULL);
+               cd = cw->cd;
 
-               g_free(cd->path);
-               cd->path = NULL;
-               g_free(cd->name);
-               cd->name = g_strdup(_("Command line"));
+               collection_path_changed(cd);
 
                remote_data->command_collection = cd;
                }
-       else
+       else if (!remote_data->single_dir)
                {
                new = (!collection_get_first(remote_data->command_collection));
                }
 
-       if (collection_add(remote_data->command_collection, file_data_new_group(text), FALSE) && new)
+       if (!remote_data->single_dir)
                {
                layout_image_set_collection(lw_id, remote_data->command_collection, collection_get_first(remote_data->command_collection));
+               if (collection_add(remote_data->command_collection, file_data_new_group(text), FALSE) && new)
+                       {
+                       layout_image_set_collection(lw_id, remote_data->command_collection, collection_get_first(remote_data->command_collection));
+                       }
                }
 }
 
@@ -1495,7 +1546,7 @@ GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
  * \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 cmd_list List of all non collections in Path (gchar *path)
  * \param collection_list List of all collections in argv
  */
 void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path,
@@ -1608,15 +1659,12 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path
                work = cmd_list;
                while (work)
                        {
-                       FileData *fd;
                        gchar *text;
 
-                       fd = work->data;
-                       work = work->next;
-
-                       text = g_strconcat(prefix, fd->path, NULL);
+                       text = g_strconcat(prefix, work->data, NULL);
                        remote_client_send(rc, text);
                        g_free(text);
+                       work = work->next;
 
                        sent = TRUE;
                        }
index 6ec34f7..16297da 100644 (file)
@@ -64,6 +64,7 @@ void vf_select_all(ViewFile *vf);
 void vf_select_none(ViewFile *vf);
 void vf_select_invert(ViewFile *vf);
 void vf_select_by_fd(ViewFile *vf, FileData *fd);
+void vf_select_list(ViewFile *vf, GList *list);
 
 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode);
 void vf_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode);
index e07670a..5e6674a 100644 (file)
@@ -234,6 +234,15 @@ void vf_select_by_fd(ViewFile *vf, FileData *fd)
        }
 }
 
+void vf_select_list(ViewFile *vf, GList *list)
+{
+       switch (vf->type)
+       {
+       case FILEVIEW_LIST: vflist_select_list(vf, list); break;
+       case FILEVIEW_ICON: vficon_select_list(vf, list); break;
+       }
+}
+
 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
 {
        switch (vf->type)
index 611f987..e1493c8 100644 (file)
@@ -922,6 +922,26 @@ void vficon_select_by_fd(ViewFile *vf, FileData *fd)
        vficon_set_focus(vf, fd);
 }
 
+void vficon_select_list(ViewFile *vf, GList *list)
+{
+       GList *work;
+       FileData *fd;
+
+       if (!list) return;
+
+       work = list;
+       while (work)
+               {
+               fd = work->data;
+               if (g_list_find(vf->list, fd))
+                       {
+                       VFICON(vf)->selection = g_list_append(VFICON(vf)->selection, fd);
+                       vficon_selection_add(vf, fd, SELECTION_SELECTED, NULL);
+                       }
+               work = work->next;
+               }
+}
+
 void vficon_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
 {
        GList *work;
index 4f2d6c3..35e5855 100644 (file)
@@ -64,6 +64,7 @@ void vficon_select_all(ViewFile *vf);
 void vficon_select_none(ViewFile *vf);
 void vficon_select_invert(ViewFile *vf);
 void vficon_select_by_fd(ViewFile *vf, FileData *fd);
+void vficon_select_list(ViewFile *vf, GList *list);
 
 void vficon_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode);
 void vficon_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode);
index 2e2a092..6418b41 100644 (file)
@@ -1673,6 +1673,31 @@ void vflist_select_by_fd(ViewFile *vf, FileData *fd)
                }
 }
 
+void vflist_select_list(ViewFile *vf, GList *list)
+{
+       GtkTreeIter iter;
+       GList *work;
+
+       work = list;
+
+       while (work)
+               {
+               FileData *fd;
+
+               fd = work->data;
+
+               if (vflist_find_row(vf, fd, &iter) < 0) return;
+               if (!vflist_row_is_selected(vf, fd))
+                       {
+                       GtkTreeSelection *selection;
+
+                       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
+                       gtk_tree_selection_select_iter(selection, &iter);
+                       }
+               work = work->next;
+               }
+}
+
 static void vflist_select_closest(ViewFile *vf, FileData *sel_fd)
 {
        GList *work;
index a1df381..3bbf480 100644 (file)
@@ -63,6 +63,7 @@ void vflist_select_all(ViewFile *vf);
 void vflist_select_none(ViewFile *vf);
 void vflist_select_invert(ViewFile *vf);
 void vflist_select_by_fd(ViewFile *vf, FileData *fd);
+void vflist_select_list(ViewFile *vf, GList *list);
 
 void vflist_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode);
 void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode);