[gthumb] Crash when dropping files on an empty folder/catalog



commit 4c2301a9a67369cc02dc3d7381bbb3bccf3cedcb
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Mar 20 11:36:16 2022 +0100

    Crash when dropping files on an empty folder/catalog
    
    Fixes #220

 extensions/file_manager/callbacks.c | 60 +++++++++++++++++++------------------
 gthumb/gth-file-list.c              | 17 +++++++++--
 gthumb/gth-file-list.h              |  2 ++
 3 files changed, 48 insertions(+), 31 deletions(-)
---
diff --git a/extensions/file_manager/callbacks.c b/extensions/file_manager/callbacks.c
index d91cf872..eb0a9bb8 100644
--- a/extensions/file_manager/callbacks.c
+++ b/extensions/file_manager/callbacks.c
@@ -179,7 +179,7 @@ browser_data_free (BrowserData *data)
 
 
 static void
-gth_file_list_drag_data_received (GtkWidget        *file_view,
+gth_file_list_drag_data_received (GtkWidget        *widget,
                                  GdkDragContext   *context,
                                  int               x,
                                  int               y,
@@ -189,11 +189,14 @@ gth_file_list_drag_data_received (GtkWidget        *file_view,
                                  gpointer          user_data)
 {
        GthBrowser     *browser = user_data;
+       GtkWidget      *file_view;
        gboolean        success = FALSE;
        char          **uris;
        GList          *selected_files;
        GdkDragAction   action;
 
+       file_view = gth_browser_get_file_list_view (browser);
+
        action = gdk_drag_context_get_suggested_action (context);
        if (action == GDK_ACTION_COPY || action == GDK_ACTION_MOVE) {
                success = TRUE;
@@ -411,6 +414,12 @@ gth_file_list_drag_motion (GtkWidget      *file_view,
        data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
        data->drop_pos = -1;
 
+       if (GTH_IS_EMPTY_LIST (file_view)) {
+               gth_file_list_enable_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)), FALSE);
+               gdk_drag_status (context, 0, time);
+               return FALSE;
+       }
+
        if ((gtk_drag_get_source_widget (context) == file_view) && ! gth_file_source_is_reorderable 
(gth_browser_get_location_source (browser))) {
                gdk_drag_status (context, 0, time);
                return FALSE;
@@ -481,9 +490,10 @@ gth_file_list_drag_leave (GtkWidget      *file_view,
                          guint           time,
                          gpointer        extra_data)
 {
+       GthBrowser *browser = extra_data;
        if (gtk_drag_get_source_widget (context) == file_view)
                gth_file_view_set_drag_dest_pos (GTH_FILE_VIEW (file_view), context, -1, -1, time, NULL);
-
+       gth_file_list_enable_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)), TRUE);
        return TRUE;
 }
 
@@ -738,25 +748,25 @@ fm__gth_browser_construct_cb (GthBrowser *browser)
 
        file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
        g_signal_connect (file_view,
-                          "drag_data_received",
-                          G_CALLBACK (gth_file_list_drag_data_received),
-                          browser);
+                         "drag_data_received",
+                         G_CALLBACK (gth_file_list_drag_data_received),
+                         browser);
        g_signal_connect (file_view,
-                         "drag_drop",
-                         G_CALLBACK (gth_file_list_drag_drop),
-                         browser);
+                         "drag_drop",
+                         G_CALLBACK (gth_file_list_drag_drop),
+                         browser);
        g_signal_connect (file_view,
                          "drag_motion",
                          G_CALLBACK (gth_file_list_drag_motion),
                          browser);
        g_signal_connect (file_view,
-                         "drag_leave",
-                         G_CALLBACK (gth_file_list_drag_leave),
-                         browser);
+                         "drag_leave",
+                         G_CALLBACK (gth_file_list_drag_leave),
+                         browser);
        g_signal_connect (file_view,
-                         "drag_end",
-                         G_CALLBACK (gth_file_list_drag_end),
-                         browser);
+                         "drag_end",
+                         G_CALLBACK (gth_file_list_drag_end),
+                         browser);
        g_signal_connect (file_view,
                          "file-selection-changed",
                          G_CALLBACK (file_selection_changed_cb),
@@ -764,25 +774,17 @@ fm__gth_browser_construct_cb (GthBrowser *browser)
 
        file_view = gth_file_list_get_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
        g_signal_connect (file_view,
-                          "drag_data_received",
-                          G_CALLBACK (gth_file_list_drag_data_received),
-                          browser);
-       g_signal_connect (file_view,
-                         "drag_drop",
-                         G_CALLBACK (gth_file_list_drag_drop),
-                         browser);
-       g_signal_connect (file_view,
-                         "drag_motion",
+                         "drag-motion",
                          G_CALLBACK (gth_file_list_drag_motion),
                          browser);
        g_signal_connect (file_view,
-                         "drag_leave",
-                         G_CALLBACK (gth_file_list_drag_leave),
-                         browser);
+                         "drag_data_received",
+                         G_CALLBACK (gth_file_list_drag_data_received),
+                         browser);
        g_signal_connect (file_view,
-                         "drag_end",
-                         G_CALLBACK (gth_file_list_drag_end),
-                         browser);
+                         "drag_drop",
+                         G_CALLBACK (gth_file_list_drag_drop),
+                         browser);
 
        g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) 
browser_data_free);
 }
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index 0d407038..91c681ab 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -142,6 +142,7 @@ struct _GthFileListPrivate {
        ThumbnailerState  thumbnailer_state;
        int               max_loaders;
        int               started_loaders;
+       gboolean          allow_empty_view;
 };
 
 
@@ -389,6 +390,7 @@ gth_file_list_init (GthFileList *file_list)
        file_list->priv->thumbnailer_state.phase = THUMBNAILER_PHASE_INITIALIZE;
        file_list->priv->started_loaders = 0;
        file_list->priv->max_loaders = _get_max_loaders ();
+       file_list->priv->allow_empty_view = TRUE;
 }
 
 
@@ -647,7 +649,7 @@ _gth_file_list_update_pane (GthFileList *file_list)
 
        file_store = gth_file_list_get_model (file_list);
 
-       if (gth_file_store_n_visibles (file_store) > 0) {
+       if ((gth_file_store_n_visibles (file_store) > 0) || ! file_list->priv->allow_empty_view) {
                gtk_stack_set_visible_child_name (GTK_STACK (file_list->priv->notebook), _FILE_VIEW);
        }
        else {
@@ -823,7 +825,7 @@ gfl_clear_list (GthFileList *file_list,
        gth_file_store_clear (file_store);
 
        gth_empty_list_set_text (GTH_EMPTY_LIST (file_list->priv->message), message);
-       gtk_stack_set_visible_child_name (GTK_STACK (file_list->priv->notebook), _EMPTY_VIEW);
+       gtk_stack_set_visible_child_name (GTK_STACK (file_list->priv->notebook), 
file_list->priv->allow_empty_view ? _EMPTY_VIEW : _FILE_VIEW);
 }
 
 
@@ -2122,3 +2124,14 @@ gth_file_list_focus (GthFileList *file_list)
                child = gtk_bin_get_child (GTK_BIN (child));
        gtk_widget_grab_focus ((child != NULL) ? child : GTK_WIDGET (file_list));
 }
+
+
+void
+gth_file_list_enable_empty_view (GthFileList *file_list,
+                                gboolean     allow)
+{
+       if (file_list->priv->allow_empty_view == allow)
+               return;
+       file_list->priv->allow_empty_view = allow;
+       _gth_file_list_update_pane (file_list);
+}
diff --git a/gthumb/gth-file-list.h b/gthumb/gth-file-list.h
index 2b961e8d..022f89b4 100644
--- a/gthumb/gth-file-list.h
+++ b/gthumb/gth-file-list.h
@@ -135,6 +135,8 @@ void              gth_file_list_enable_drag_source (GthFileList         *file_li
                                                    GdkDragAction        actions);
 void              gth_file_list_unset_drag_source  (GthFileList         *file_list);
 void              gth_file_list_focus              (GthFileList         *file_list);
+void              gth_file_list_enable_empty_view  (GthFileList         *file_list,
+                                                   gboolean             enable);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]