summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2023-04-12 19:49:58 +0200
committerOrangerot <purple@orangerot.dev>2023-04-12 19:49:58 +0200
commit8f32fb80e99c5d9cd2a8afce6e873ee772ffb5ab (patch)
tree6d11190f4fdb20b908294bf8a7412bdf2e534d28
parentb0a8acd23c0a4ac5058dd8ea0c7dcb422929ebf1 (diff)
parentd59da82993efbea45af8ec29f5764c90987c60e6 (diff)
Merge branch 'drag-and-drop'
-rw-r--r--dicons.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/dicons.c b/dicons.c
index dd5b096..5c4e479 100644
--- a/dicons.c
+++ b/dicons.c
@@ -11,6 +11,11 @@ enum
NUM_COLS
};
+static GtkTargetEntry targets[] =
+{
+ { "text/uri-list", 0, 0 }
+};
+
GtkIconTheme *theme;
void remove_row_by_file(GtkListStore *store, GFile *file)
@@ -72,6 +77,49 @@ static void file_changed_cb(GFileMonitor *monitor, GFile *file, GFile *other_fil
}
}
+static void drop_data_cb(GtkWidget* self, GdkDragContext* context, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer user_data)
+{
+ const gchar *desktop_path;
+ gchar **uris;
+ GFile *file, *dir_file;
+ GFileInfo *file_info;
+
+ desktop_path = g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP);
+ dir_file = g_file_new_for_path(desktop_path);
+ printf("test\n");
+
+ uris = gtk_selection_data_get_uris(data);
+ for (gchar **uri = uris; *uri != 0; uri++)
+ {
+ printf("dropped %s\n", *uri);
+ file = g_file_new_for_uri(*uri);
+ file_info = g_file_query_info(file, "standard::*,owner:.user", 0, 0, 0);
+
+ g_file_copy(file, g_file_get_child(dir_file, g_file_info_get_name(file_info)), G_FILE_COPY_NONE, 0, 0, 0, 0);
+ }
+ gtk_drag_finish(context, TRUE, FALSE, time);
+}
+
+static void drag_data_cb(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* data, guint info, guint time, gpointer user_data)
+{
+ GList *selected_items, *iter;
+ GtkTreeModel *model = GTK_TREE_MODEL(user_data);
+ gchar **uris;
+ int index = 0;
+
+ selected_items = gtk_icon_view_get_selected_items(GTK_ICON_VIEW(widget));
+ uris = g_new(gchar*, g_list_length(selected_items) + 1);
+ for (iter = selected_items; iter != NULL; iter = iter->next)
+ {
+ GtkTreeIter tree_iter;
+ GFile *file;
+ gtk_tree_model_get_iter(model, &tree_iter, (GtkTreePath *)iter->data);
+ gtk_tree_model_get(model, &tree_iter, COL_FILE, &file, -1);
+ uris[index++] = g_file_get_uri(file);
+ }
+ gtk_selection_data_set_uris(data, uris);
+}
+
static GtkListStore *create_desktop_list(void)
{
GtkTreeIter iter;
@@ -154,7 +202,18 @@ static void activate (GtkApplication* app, gpointer user_data)
gtk_icon_view_set_text_column(GTK_ICON_VIEW (icon_view), COL_DISPLAY_NAME);
gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW (icon_view), COL_PIXBUF);
+ gtk_drag_dest_set(icon_view, GTK_DEST_DEFAULT_ALL, targets, G_N_ELEMENTS(targets), GDK_ACTION_COPY);
+ gtk_icon_view_enable_model_drag_source (
+ GTK_ICON_VIEW(icon_view),
+ GDK_BUTTON1_MASK,
+ targets,
+ G_N_ELEMENTS(targets),
+ GDK_ACTION_COPY
+ );
+
g_signal_connect(icon_view, "item-activated", G_CALLBACK(activate_cb), model);
+ g_signal_connect(icon_view, "drag-data-received", G_CALLBACK(drop_data_cb), model);
+ g_signal_connect(icon_view, "drag-data-get", G_CALLBACK(drag_data_cb), model);
gtk_container_add(GTK_CONTAINER(window), icon_view);
gtk_widget_grab_focus (icon_view);