summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar George Kaklamanos <gkaklas1@gmail.com>2017-06-18 04:39:13 +0300
committerGravatar George Kaklamanos <gkaklas1@gmail.com>2017-06-19 16:33:56 +0300
commit810d589610ef851096d5a4c1e711725afe817f92 (patch)
tree0172a9b63f875a0fb317b434d949c12199cf8327
parentc61967fe324d462024cf115648a117ea5a8010df (diff)
Add option in menu to copy magnet link
-rw-r--r--src/protocol-constants.h1
-rw-r--r--src/requests.c1
-rw-r--r--src/torrent.c5
-rw-r--r--src/torrent.h1
-rw-r--r--src/trg-main-window.c23
-rw-r--r--src/trg-menu-bar.c13
6 files changed, 42 insertions, 2 deletions
diff --git a/src/protocol-constants.h b/src/protocol-constants.h
index 8fffb00..18c6d28 100644
--- a/src/protocol-constants.h
+++ b/src/protocol-constants.h
@@ -70,6 +70,7 @@
#define FIELD_LEFTUNTILDONE "leftUntilDone"
#define FIELD_ISFINISHED "isFinished"
#define FIELD_ISPRIVATE "isPrivate"
+#define FIELD_MAGNETLINK "magnetLink"
#define FIELD_ERROR "error"
#define FIELD_ERROR_STRING "errorString"
#define FIELD_BANDWIDTH_PRIORITY "bandwidthPriority"
diff --git a/src/requests.c b/src/requests.c
index 4e044ab..77466f9 100644
--- a/src/requests.c
+++ b/src/requests.c
@@ -212,6 +212,7 @@ JsonNode *torrent_get(gint64 id)
json_array_add_string_element(fields, FIELD_SEED_RATIO_MODE);
json_array_add_string_element(fields, FIELD_PEER_LIMIT);
json_array_add_string_element(fields, FIELD_ACTIVITY_DATE);
+ json_array_add_string_element(fields, FIELD_MAGNETLINK);
json_array_add_string_element(fields, FIELD_ERROR);
json_array_add_string_element(fields, FIELD_ERROR_STRING);
json_array_add_string_element(fields, FIELD_WANTED);
diff --git a/src/torrent.c b/src/torrent.c
index e5577ee..8e5422f 100644
--- a/src/torrent.c
+++ b/src/torrent.c
@@ -108,6 +108,11 @@ gint64 torrent_get_bandwidth_priority(JsonObject * t)
return json_object_get_int_member(t, FIELD_BANDWIDTH_PRIORITY);
}
+const gchar *torrent_get_magnetlink(JsonObject * t)
+{
+ return json_object_get_string_member(t, FIELD_MAGNETLINK);
+}
+
gint64 torrent_get_upload_limit(JsonObject * t)
{
return json_object_get_int_member(t, FIELD_UPLOAD_LIMIT);
diff --git a/src/torrent.h b/src/torrent.h
index c837046..481841d 100644
--- a/src/torrent.h
+++ b/src/torrent.h
@@ -87,6 +87,7 @@ gboolean torrent_get_is_private(JsonObject * t);
gboolean torrent_get_honors_session_limits(JsonObject * t);
gint64 torrent_get_bandwidth_priority(JsonObject * t);
gint64 torrent_get_upload_limit(JsonObject * t);
+const gchar *torrent_get_magnetlink(JsonObject * t);
gint64 torrent_get_added_date(JsonObject * t);
gint64 torrent_get_done_date(JsonObject * t);
gboolean torrent_get_upload_limited(JsonObject * t);
diff --git a/src/trg-main-window.c b/src/trg-main-window.c
index d85a364..5729254 100644
--- a/src/trg-main-window.c
+++ b/src/trg-main-window.c
@@ -449,6 +449,20 @@ static void open_props_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
gtk_widget_show_all(GTK_WIDGET(dialog));
}
+static void copy_magnetlink_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
+{
+ TrgMainWindowPrivate *priv = trg_main_window_get_instance_private(win);
+ JsonObject *json = NULL;
+ GtkClipboard *clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
+
+ if (priv->selectedTorrentId < 0)
+ return;
+
+ if(get_torrent_data(trg_client_get_torrent_table(priv->client),
+ priv->selectedTorrentId, &json, NULL))
+ gtk_clipboard_set_text(clip, torrent_get_magnetlink(json), -1);
+}
+
static void
torrent_tv_onRowActivated(GtkTreeView * treeview,
GtkTreePath * path G_GNUC_UNUSED,
@@ -1785,7 +1799,7 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win)
#ifdef HAVE_RSS
*b_view_rss,
#endif
- *b_start_now;
+ *b_start_now, *b_copy_magnetlink;
TrgMenuBar *menuBar;
GtkAccelGroup *accel_group;
@@ -1818,7 +1832,8 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win)
#endif
"up-queue", &b_up_queue, "down-queue", &b_down_queue,
"top-queue", &b_top_queue, "bottom-queue",
- &b_bottom_queue, "start-now", &b_start_now, NULL);
+ &b_bottom_queue, "start-now", &b_start_now,
+ "copymagnet-button", &b_copy_magnetlink, NULL);
g_signal_connect(b_disconnect, "activate", G_CALLBACK(disconnect_cb),
win);
@@ -1871,6 +1886,7 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win)
G_CALLBACK(trg_main_window_toggle_graph_cb), win);
#endif
g_signal_connect(b_props, "activate", G_CALLBACK(open_props_cb), win);
+ g_signal_connect(b_copy_magnetlink, "activate", G_CALLBACK(copy_magnetlink_cb), win);
g_signal_connect(b_quit, "activate", G_CALLBACK(quit_cb), win);
gtk_window_add_accel_group(GTK_WINDOW(win), accel_group);
@@ -2224,6 +2240,9 @@ trg_torrent_tv_view_menu(GtkWidget * treeview,
trg_imagemenuitem_new(GTK_MENU_SHELL(menu), _("Properties"),
GTK_STOCK_PROPERTIES, TRUE,
G_CALLBACK(open_props_cb), win);
+ trg_imagemenuitem_new(GTK_MENU_SHELL(menu), _("Copy Magnet Link"),
+ GTK_STOCK_COPY, TRUE,
+ G_CALLBACK(copy_magnetlink_cb), win);
trg_imagemenuitem_new(GTK_MENU_SHELL(menu), _("Resume"),
GTK_STOCK_MEDIA_PLAY, TRUE,
G_CALLBACK(resume_cb), win);
diff --git a/src/trg-menu-bar.c b/src/trg-menu-bar.c
index faf3548..d5ae375 100644
--- a/src/trg-menu-bar.c
+++ b/src/trg-menu-bar.c
@@ -48,6 +48,7 @@ enum {
PROP_VERIFY_BUTTON,
PROP_REANNOUNCE_BUTTON,
PROP_PROPS_BUTTON,
+ PROP_COPYMAGNET_BUTTON,
PROP_MOVE_BUTTON,
PROP_REMOTE_PREFS_BUTTON,
PROP_LOCAL_PREFS_BUTTON,
@@ -99,6 +100,7 @@ struct _TrgMenuBarPrivate {
GtkWidget *mb_verify;
GtkWidget *mb_reannounce;
GtkWidget *mb_props;
+ GtkWidget *mb_copy_magnetlink;
GtkWidget *mb_local_prefs;
GtkWidget *mb_remote_prefs;
GtkWidget *mb_view_states;
@@ -165,6 +167,7 @@ trg_menu_bar_torrent_actions_sensitive(TrgMenuBar * mb, gboolean sensitive)
TrgMenuBarPrivate *priv = TRG_MENU_BAR_GET_PRIVATE(mb);
gtk_widget_set_sensitive(priv->mb_props, sensitive);
+ gtk_widget_set_sensitive(priv->mb_copy_magnetlink, sensitive);
gtk_widget_set_sensitive(priv->mb_remove, sensitive);
gtk_widget_set_sensitive(priv->mb_delete, sensitive);
gtk_widget_set_sensitive(priv->mb_resume, sensitive);
@@ -265,6 +268,9 @@ trg_menu_bar_get_property(GObject * object, guint property_id,
case PROP_PROPS_BUTTON:
g_value_set_object(value, priv->mb_props);
break;
+ case PROP_COPYMAGNET_BUTTON:
+ g_value_set_object(value, priv->mb_copy_magnetlink);
+ break;
case PROP_REMOTE_PREFS_BUTTON:
g_value_set_object(value, priv->mb_remote_prefs);
break;
@@ -713,6 +719,11 @@ static GtkWidget *trg_menu_bar_torrent_menu_new(TrgMenuBar * menu)
FALSE);
trg_menu_bar_accel_add(menu, priv->mb_props, GDK_i, GDK_CONTROL_MASK);
+ priv->mb_copy_magnetlink =
+ trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), _("_Copy Magnet Link"),
+ GTK_STOCK_COPY, FALSE);
+ trg_menu_bar_accel_add(menu, priv->mb_copy_magnetlink, GDK_c, GDK_CONTROL_MASK);
+
priv->mb_resume =
trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), _("_Resume"),
GTK_STOCK_MEDIA_PLAY, FALSE);
@@ -904,6 +915,8 @@ static void trg_menu_bar_class_init(TrgMenuBarClass * klass)
"pause-button", "Pause Button");
trg_menu_bar_install_widget_prop(object_class, PROP_PROPS_BUTTON,
"props-button", "Props Button");
+ trg_menu_bar_install_widget_prop(object_class, PROP_COPYMAGNET_BUTTON,
+ "copymagnet-button", "Copy-magnet Button");
trg_menu_bar_install_widget_prop(object_class, PROP_ABOUT_BUTTON,
"about-button", "About Button");
trg_menu_bar_install_widget_prop(object_class, PROP_VIEW_STATS_BUTTON,