summaryrefslogtreecommitdiff
path: root/src/trg-main-window.c
diff options
context:
space:
mode:
authorGravatar Alan F <ajf@eth0.org.uk>2014-03-10 09:10:24 +0000
committerGravatar Alan F <ajf@eth0.org.uk>2014-03-10 09:10:24 +0000
commit1a5447c0138fd25e3f6d78f78593f5b70be5614a (patch)
tree9468304a4688a63788363bcf2457b1767aa513a9 /src/trg-main-window.c
parentdd0c7d8317dd199b6dd9d612ebb863c4da6cf242 (diff)
parent118b702bec50d9872699357a379413f69e9b176e (diff)
Merge branch 'rss-viewer'. This is the biggest feature I've attempted to add for quite a long time. Quite a lot of refactoring of the HTTP client and threadpool has been done (to make it not send session tokens etc), uploads (was too much code duplication), and the add dialog was done to implement this. Don't expect this to be some fully automatable RSS client, use something like flexget for that, this is just a simple view on RSS feeds. It uses the rss-glib library, which you will probably need to install yourself to optionally use this feature. There are probably bugs still, so report them.
Diffstat (limited to 'src/trg-main-window.c')
-rw-r--r--src/trg-main-window.c106
1 files changed, 72 insertions, 34 deletions
diff --git a/src/trg-main-window.c b/src/trg-main-window.c
index 906a384..4cf6047 100644
--- a/src/trg-main-window.c
+++ b/src/trg-main-window.c
@@ -17,9 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include <stdlib.h>
#include <string.h>
@@ -73,8 +71,12 @@
#include "trg-menu-bar.h"
#include "trg-status-bar.h"
#include "trg-stats-dialog.h"
+#ifdef HAVE_RSSGLIB
+#include "trg-rss-window.h"
+#endif
#include "trg-remote-prefs-dialog.h"
#include "trg-preferences-dialog.h"
+#include "upload.h"
/* The rather large main window class, which glues everything together. */
@@ -479,7 +481,7 @@ static void pause_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_pause(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void pause_all_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
@@ -488,7 +490,7 @@ static void pause_all_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
if (trg_client_is_connected(priv->client))
dispatch_async(priv->client, torrent_pause(NULL),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
gint trg_add_from_filename(TrgMainWindow * win, gchar ** uris)
@@ -504,10 +506,14 @@ gint trg_add_from_filename(TrgMainWindow * win, gchar ** uris)
return EXIT_SUCCESS;
}
- if (uris)
- for (i = 0; uris[i]; i++)
- if (uris[i])
+ if (uris) {
+ for (i = 0; uris[i]; i++) {
+ if (is_minimised_arg(uris[i]))
+ g_free(uris[i]);
+ else if (uris[i])
filesList = g_slist_append(filesList, uris[i]);
+ }
+ }
g_free(uris);
@@ -517,20 +523,20 @@ gint trg_add_from_filename(TrgMainWindow * win, gchar ** uris)
if (trg_prefs_get_bool(prefs, TRG_PREFS_KEY_ADD_OPTIONS_DIALOG,
TRG_PREFS_GLOBAL)) {
TrgTorrentAddDialog *dialog =
- trg_torrent_add_dialog_new(win, client,
+ trg_torrent_add_dialog_new_from_filenames(win, client,
filesList);
gtk_widget_show_all(GTK_WIDGET(dialog));
} else {
- struct add_torrent_threadfunc_args *args =
- g_new0(struct add_torrent_threadfunc_args, 1);
- args->list = filesList;
- args->cb_data = win;
- args->client = client;
- args->extraArgs = FALSE;
- args->flags = trg_prefs_get_add_flags(prefs);
-
- launch_add_thread(args);
+ trg_upload *upload = g_new0(trg_upload, 1);
+
+ upload->list = filesList;
+ upload->main_window = win;
+ upload->client = client;
+ upload->extra_args = FALSE;
+ upload->flags = trg_prefs_get_add_flags(prefs);
+
+ trg_do_upload(upload);
}
return EXIT_SUCCESS;
@@ -542,7 +548,7 @@ static void resume_all_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
if (trg_client_is_connected(priv->client))
dispatch_async(priv->client, torrent_start(NULL),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void resume_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
@@ -553,7 +559,7 @@ static void resume_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_start(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void disconnect_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data)
@@ -712,7 +718,7 @@ static void reannounce_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_reannounce(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void verify_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
@@ -723,7 +729,7 @@ static void verify_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_verify(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void start_now_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
@@ -734,7 +740,7 @@ static void start_now_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_start_now(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void up_queue_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
@@ -745,7 +751,7 @@ static void up_queue_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_queue_move_up(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void top_queue_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
@@ -756,7 +762,7 @@ static void top_queue_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_queue_move_top(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void
@@ -768,7 +774,7 @@ bottom_queue_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_queue_move_bottom(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static void down_queue_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
@@ -779,7 +785,7 @@ static void down_queue_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
dispatch_async(priv->client,
torrent_queue_move_down(build_json_id_array
(priv->torrentTreeView)),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
}
static gint
@@ -881,7 +887,7 @@ static void remove_cb(GtkWidget * w G_GNUC_UNUSED, TrgMainWindow * win)
_("<big><b>Remove %d torrents?</b></big>"),
GTK_STOCK_REMOVE) == GTK_RESPONSE_ACCEPT)
dispatch_async(priv->client, torrent_remove(ids, FALSE),
- on_generic_interactive_action, win);
+ on_generic_interactive_action_response, win);
else
json_array_unref(ids);
}
@@ -924,6 +930,22 @@ static void view_stats_toggled_cb(GtkWidget * w, gpointer data)
}
}
+#ifdef HAVE_RSSGLIB
+static void view_rss_toggled_cb(GtkWidget * w, gpointer data)
+{
+ TrgMainWindow *win = TRG_MAIN_WINDOW(data);
+ TrgMainWindowPrivate *priv = win->priv;
+
+ if (trg_client_is_connected(priv->client)) {
+ TrgRssWindow *rss =
+ trg_rss_window_get_instance(TRG_MAIN_WINDOW(data), priv->client);
+
+ gtk_widget_show_all(GTK_WIDGET(rss));
+ gtk_window_present(GTK_WINDOW(rss));
+ }
+}
+#endif
+
static void
view_states_toggled_cb(GtkCheckMenuItem * w, TrgMainWindow * win)
{
@@ -1570,13 +1592,10 @@ gboolean on_delete_complete(gpointer data)
trg_client_update_session(priv->client, on_session_get,
response->cb_data);
- return on_generic_interactive_action(data);
+ return on_generic_interactive_action_response(data);
}
-gboolean on_generic_interactive_action(gpointer data)
-{
- trg_response *response = (trg_response *) data;
- TrgMainWindow *win = TRG_MAIN_WINDOW(response->cb_data);
+void on_generic_interactive_action(TrgMainWindow *win, trg_response *response) {
TrgMainWindowPrivate *priv = win->priv;
TrgClient *tc = priv->client;
@@ -1596,6 +1615,15 @@ gboolean on_generic_interactive_action(gpointer data)
}
trg_response_free(response);
+}
+
+gboolean on_generic_interactive_action_response(gpointer data)
+{
+ trg_response *response = (trg_response *) data;
+ TrgMainWindow *win = TRG_MAIN_WINDOW(response->cb_data);
+
+ on_generic_interactive_action(win, response);
+
return FALSE;
}
@@ -1738,6 +1766,9 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win)
#if TRG_WITH_GRAPH
*b_show_graph,
#endif
+#ifdef HAVE_RSSGLIB
+ *b_view_rss,
+#endif
*b_start_now;
TrgMenuBar *menuBar;
@@ -1766,6 +1797,9 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win)
#if TRG_WITH_GRAPH
"show-graph", &b_show_graph,
#endif
+#ifdef HAVE_RSSGLIB
+ "view-rss-button", &b_view_rss,
+#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);
@@ -1810,6 +1844,10 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win)
G_CALLBACK(view_states_toggled_cb), win);
g_signal_connect(b_view_stats, "activate",
G_CALLBACK(view_stats_toggled_cb), win);
+#ifdef HAVE_RSSGLIB
+ g_signal_connect(b_view_rss, "activate",
+ G_CALLBACK(view_rss_toggled_cb), win);
+#endif
#if TRG_WITH_GRAPH
g_signal_connect(b_show_graph, "toggled",
G_CALLBACK(trg_main_window_toggle_graph_cb), win);
@@ -1928,7 +1966,7 @@ static void set_limit_cb(GtkWidget * w, TrgMainWindow * win)
json_object_set_boolean_member(args, enabledKey, speed >= 0);
if (limitIds)
- dispatch_async(priv->client, req, on_generic_interactive_action,
+ dispatch_async(priv->client, req, on_generic_interactive_action_response,
win);
else
dispatch_async(priv->client, req, on_session_set, win);
@@ -1953,7 +1991,7 @@ static void set_priority_cb(GtkWidget * w, TrgMainWindow * win)
json_object_set_int_member(args, FIELD_BANDWIDTH_PRIORITY, priority);
- dispatch_async(priv->client, req, on_generic_interactive_action, win);
+ dispatch_async(priv->client, req, on_generic_interactive_action_response, win);
}
static GtkWidget *limit_item_new(TrgMainWindow * win, GtkWidget * menu,