]> uap-core.de Git - mizunara.git/commitdiff
prepare dnd support for MzFilesView master
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 30 Jan 2025 21:10:10 +0000 (22:10 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 30 Jan 2025 21:10:10 +0000 (22:10 +0100)
mizunara/application.h
mizunara/filebrowser.c
mizunara/gtk-filesview.c

index af25e8bc67d5307ad72de857d308acbb512d9469..d5465f2963f8fab713a7815a417bc70980f94ffd 100644 (file)
@@ -128,12 +128,14 @@ struct FileBrowser {
  */
 struct FilesSection {
     CxList *files;
+    char *parent_url;
     size_t num_bytes;
     time_t mtime_from;
     time_t mtime_to;
 };
 
 struct FileInfo {
+    char *parent;
     char *name;
     size_t size;
     time_t mtime;
index 278717248714c9d031b4ecfa892b71c0ca1ed4b2..3cf3bd3cd3cf1e10631b32fceca3acf8cb270ae4 100644 (file)
@@ -112,6 +112,7 @@ int jobthr_filebrowser_op_load(void *data) {
         }
         
         FileInfo f;
+        f.parent = op->url;
         f.name = strdup(ent->d_name);
         
         if(!fstatat(fd, ent->d_name, &s, 0)) {
@@ -143,7 +144,9 @@ void filebrowser_op_finished(UiEvent *event, void *data) {
             FilesSection *section = malloc(sizeof(FilesSection));
             memset(section, 0, sizeof(FilesSection));
             section->files = op->result;
+            section->parent_url = op->url;
             op->result = NULL;
+            op->url = NULL;
             
             // update_grid takes ownership of section
             op->browser->update_grid(op->browser, section, 1, op->browser->update_grid_data);
@@ -155,7 +158,6 @@ void filebrowser_op_finished(UiEvent *event, void *data) {
     }
     
     cxListFree(op->result);
-    
     free(op->url);
     free(op);
 }
index ff98435fe941914b677bd9c48a27866d0048b857..361a8570926970c370e04308d3a552364377dbd6 100644 (file)
@@ -31,6 +31,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include <libidav/utils.h>
+
 
 G_DEFINE_TYPE(MzFilesView, mz_files_view, GTK_TYPE_WIDGET)
 
@@ -51,6 +53,17 @@ static void drag_update_cb(
         gdouble y,
         gpointer user_data);
 
+static GdkContentProvider* dnd_prepare(
+        GtkDragSource* self,
+        gdouble x,
+        gdouble y,
+        gpointer user_data);
+
+static void dnd_begin(
+        GtkDragSource* self,
+        GdkDrag* drag,
+        gpointer user_data);
+
 static void motion_cb(
         GtkEventControllerMotion* self,
         gdouble x,
@@ -79,6 +92,11 @@ static void mz_files_view_init(MzFilesView *self) {
     self->highlight_row = -1;
       
     // event handler
+    GtkDragSource *dnd_source = gtk_drag_source_new();
+    g_signal_connect(dnd_source, "prepare", G_CALLBACK(dnd_prepare), self);
+    g_signal_connect(dnd_source, "drag-begin", G_CALLBACK(dnd_begin), self);
+    gtk_widget_add_controller(GTK_WIDGET(self), GTK_EVENT_CONTROLLER(dnd_source));
+    
     GtkGesture *drag = gtk_gesture_drag_new();
     g_signal_connect(drag, "drag-begin", G_CALLBACK(drag_begin_cb), self);
     g_signal_connect(drag, "drag-end", G_CALLBACK(drag_end_cb), self);
@@ -426,6 +444,32 @@ static void mz_files_view_size_allocate(
 
 /* -------------------------- event handler -------------------------- */
 
+static GdkContentProvider* dnd_prepare(
+        GtkDragSource *self,
+        gdouble x,
+        gdouble y,
+        gpointer user_data)
+{
+    MzFilesView *view = user_data;
+    if(view->drag_item) {
+        char *path = util_concat_path(view->drag_file->parent, view->drag_file->name);
+        printf("dnd file: %s\n", path);
+        GFile *file = g_file_new_for_path(path);
+        free(path);
+        GdkContentProvider *provider = gdk_content_provider_new_typed(G_TYPE_FILE, file);
+        return provider;
+    }
+    return NULL;
+}
+
+static void dnd_begin(
+        GtkDragSource* self,
+        GdkDrag* drag,
+        gpointer user_data)
+{
+    printf("dnd_begin\n");
+}
+
 static void drag_begin_cb(
         GtkGestureDrag* self,
         gdouble start_x,