summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmdock/mdock-widget.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/libmdock/mdock-widget.c b/libmdock/mdock-widget.c
index 3ba14fa..512f006 100644
--- a/libmdock/mdock-widget.c
+++ b/libmdock/mdock-widget.c
@@ -78,6 +78,8 @@ static const GtkTargetEntry drag_types[] = {
"text/uri-list", 0, DRAG_TYPE_URILIST
};
+static void connect_item(MDockWidget *self, MDockItem *item, GSequenceIter *position);
+
static inline MDockItemWindowSelector * selector_from_item(MDockItem *item)
{
return g_object_get_qdata((GObject*)item,
@@ -86,7 +88,8 @@ static inline MDockItemWindowSelector * selector_from_item(MDockItem *item)
static void save_items_to_settings(MDockWidget *self)
{
- GSettings *settings = self->priv->settings;
+ g_return_if_fail(self->priv->settings);
+
GSequenceIter *seq_iter = g_sequence_get_begin_iter(self->priv->items);
GVariantBuilder builder;
@@ -106,7 +109,7 @@ static void save_items_to_settings(MDockWidget *self)
}
self->priv->loading_settings = TRUE;
- g_settings_set(settings, "items", "as", &builder);
+ g_settings_set(self->priv->settings, "items", "as", &builder);
self->priv->loading_settings = FALSE;
}
@@ -345,11 +348,46 @@ static void mdock_widget_drag_data_received(GtkWidget *widget, GdkDragContext *c
case DRAG_TYPE_URILIST:
uris = gtk_selection_data_get_uris(selection_data);
if (uris) {
+ GSequenceIter *pos_iter = find_drop_position_at_coordinates(self, x, y, TRUE);
+ gint position = g_sequence_iter_get_position(pos_iter);
for (int i = 0; uris[i]; i++) {
- gchar *uri = uris[i];
- g_message("TODO: handle uri %s", uri);
+ const gchar *uri = uris[i];
+ gchar *filename = g_filename_from_uri(uri, NULL, NULL);
+ if (!filename) {
+ g_message("dropped uri is not a local filename: %s", uri);
+ continue;
+ }
+
+ GDesktopAppInfo *appinfo = g_desktop_app_info_new_from_filename(filename);
+ if (appinfo) {
+ const gchar *desktopid = g_app_info_get_id(G_APP_INFO(appinfo));
+ GSequenceIter *iter = g_hash_table_lookup(self->priv->desktopid_to_item,
+ desktopid);
+ if (!iter) {
+ // This desktopid is not yet already on the dock.
+ g_debug("creating launcher for dropped item");
+ MDockItem *item = mdock_item_new();
+ mdock_item_set_desktop_app_info(item, appinfo);
+ mdock_item_set_pinned(item, TRUE);
+
+ iter = g_sequence_insert_before(pos_iter, item);
+ g_hash_table_insert(self->priv->desktopid_to_item, g_strdup(desktopid), iter);
+
+ connect_item(self, item, iter);
+
+ gtk_widget_show(GTK_WIDGET(item));
+ gtk_box_pack_start(GTK_BOX(self), GTK_WIDGET(item), TRUE, TRUE, 0);
+ gtk_box_reorder_child(GTK_BOX(self), GTK_WIDGET(item), position);
+ }
+
+ g_object_unref(appinfo);
+ } else {
+ g_message("dropped uri is not a desktop file: %s", filename);
+ }
+ g_free(filename);
}
g_strfreev(uris);
+ save_items_to_settings(self);
}
gtk_drag_finish(context, TRUE, FALSE, timestamp);