diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-09-20 06:58:27 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-09-20 06:58:27 +0000 |
commit | 748f906b8a5f9b98e4a44e7c75043285b7dbebbe (patch) | |
tree | e992bf85f02755d8e6e3d922b7ae4a2ee4702627 | |
parent | 762cbfb2daba6a8ad62c70ebefd3420850e7ff81 (diff) |
issue 78 - contributed patch for drag'n'drop support
-rw-r--r-- | src/requests.c | 2 | ||||
-rw-r--r-- | src/trg-client.c | 4 | ||||
-rw-r--r-- | src/trg-main-window.c | 50 |
3 files changed, 52 insertions, 4 deletions
diff --git a/src/requests.c b/src/requests.c index cc1f7ac..c77217d 100644 --- a/src/requests.c +++ b/src/requests.c @@ -143,7 +143,7 @@ JsonNode *torrent_get(gint64 id) JsonObject *args = node_get_arguments(root); JsonArray *fields = json_array_new(); - if (id == -2) { + if (id == TORRENT_GET_TAG_MODE_UPDATE) { json_object_set_string_member(args, PARAM_IDS, FIELD_RECENTLY_ACTIVE); } else if (id >= 0) { diff --git a/src/trg-client.c b/src/trg-client.c index 7fcb40b..4ee3998 100644 --- a/src/trg-client.c +++ b/src/trg-client.c @@ -241,8 +241,8 @@ int trg_client_populate_with_settings(TrgClient * tc) priv->min_interval = trg_prefs_get_int(prefs, TRG_PREFS_KEY_MINUPDATE_INTERVAL, TRG_PREFS_PROFILE); - if (priv->interval < 1) - priv->interval = TRG_INTERVAL_DEFAULT; + if (priv->min_interval < 1) + priv->min_interval = TRG_INTERVAL_DEFAULT; priv->username = trg_prefs_get_string(prefs, TRG_PREFS_KEY_USERNAME, TRG_PREFS_PROFILE); diff --git a/src/trg-main-window.c b/src/trg-main-window.c index 6c73b03..433412e 100644 --- a/src/trg-main-window.c +++ b/src/trg-main-window.c @@ -409,7 +409,7 @@ gboolean trg_add_from_filename(TrgMainWindow * win, gchar ** uris) { launch_add_thread(args); } - g_free(uris); + g_free(uris); // launch_add_thread() or trg_torrent_add_dialog() will free the filenames and fileList; return TRUE; } @@ -1724,6 +1724,41 @@ static void trg_client_session_updated_cb(TrgClient *tc, JsonObject *session, priv->queuesEnabled = queuesEnabled; } +/* Drag & Drop support */ +static GtkTargetEntry target_list[] = { + /* datatype (string), restrictions on DnD (GtkTargetFlags), datatype (int) */ + { "text/uri-list", GTK_TARGET_OTHER_APP | GTK_TARGET_OTHER_WIDGET, 0 } +}; +static guint n_targets = G_N_ELEMENTS (target_list); + +static void on_dropped_file( + GtkWidget *widget, GdkDragContext *context, gint x, gint y, + GtkSelectionData *data, guint info, guint time, gpointer user_data) { + TrgMainWindow *win = user_data; + + if ((data->length >= 0) && (data->format == 8)) + { + if (context->action == GDK_ACTION_MOVE) { + g_debug ("GDK_ACTION_MOVE"); + gchar **uri_list = gtk_selection_data_get_uris(data); + guint num_files = g_strv_length(uri_list); + gchar **file_list = g_new0(gchar *,num_files+1); + int i; + for (i = 0; i < num_files; i++) { + file_list[i] = g_filename_from_uri( uri_list[i], NULL, NULL ); + g_debug ("to be added: %s",file_list[i]); + } + g_strfreev(uri_list); + gtk_drag_finish (context, TRUE, FALSE, time); + trg_add_from_filename(win,file_list); + return; + } + } + gtk_drag_finish (context, FALSE, FALSE, time); + return; +} + + static GObject *trg_main_window_constructor(GType type, guint n_construct_properties, GObjectConstructParam * construct_params) { TrgMainWindow *self; @@ -1902,6 +1937,19 @@ static GObject *trg_main_window_constructor(GType type, if (tray && priv->min_on_start) gtk_widget_hide(GTK_WIDGET(self)); + /* Drag and Drop */ + gtk_drag_dest_set + ( + GTK_WIDGET (self), // widget that will accept a drop + GTK_DEST_DEFAULT_ALL, // default actions for dest on DnD + target_list, // lists of target to support + n_targets, // size of list + GDK_ACTION_MOVE // what to do with data after dropped + // | GDK_ACTION_COPY ... seems that file managers only need ACTION_MOVE, not ACTION_COPY + ); + //g_signal_connect (priv->torrentTreeView, "drag-motion",G_CALLBACK (drag_motion_handl), NULL); + g_signal_connect (self, "drag-data-received",G_CALLBACK (on_dropped_file), self); + return G_OBJECT(self); } |