summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dispatch.c17
-rw-r--r--src/dispatch.h2
-rw-r--r--src/requests.c14
-rw-r--r--src/requests.h3
-rw-r--r--src/trg-files-model.c3
-rw-r--r--src/trg-files-tree-view.c1
-rw-r--r--src/trg-main-window.c29
-rw-r--r--src/trg-peers-model.c9
-rw-r--r--src/trg-state-selector.c7
-rw-r--r--src/trg-status-bar.c54
-rw-r--r--src/trg-status-bar.h3
-rw-r--r--src/trg-torrent-add-dialog.c12
-rw-r--r--src/trg-torrent-props-dialog.c6
-rw-r--r--src/trg-trackers-tree-view.c10
14 files changed, 104 insertions, 66 deletions
diff --git a/src/dispatch.c b/src/dispatch.c
index b5fc216..d58517c 100644
--- a/src/dispatch.c
+++ b/src/dispatch.c
@@ -27,7 +27,8 @@
#include "http.h"
#include "json.h"
-static void dispatch_async_threadfunc(struct DispatchAsyncData *task, trg_client *client);
+static void dispatch_async_threadfunc(struct DispatchAsyncData *task,
+ trg_client * client);
JsonObject *dispatch(trg_client * client, JsonNode * req, int *status)
{
@@ -67,14 +68,14 @@ JsonObject *dispatch(trg_client * client, JsonNode * req, int *status)
result = json_object_get_member(deserialized, "result");
if (status
- && (!result
- || g_strcmp0(json_node_get_string(result), "success")))
+ && (!result || g_strcmp0(json_node_get_string(result), "success")))
*status = FAIL_RESPONSE_UNSUCCESSFUL;
return deserialized;
}
-static void dispatch_async_threadfunc(struct DispatchAsyncData *task, trg_client *client)
+static void dispatch_async_threadfunc(struct DispatchAsyncData *task,
+ trg_client * client)
{
int status;
JsonObject *result = dispatch(client, task->req, &status);
@@ -83,9 +84,10 @@ static void dispatch_async_threadfunc(struct DispatchAsyncData *task, trg_client
g_free(task);
}
-GThreadPool *dispatch_init_pool(trg_client *client)
+GThreadPool *dispatch_init_pool(trg_client * client)
{
- return g_thread_pool_new((GFunc)dispatch_async_threadfunc, client, DISPATCH_POOL_SIZE, FALSE, NULL);
+ return g_thread_pool_new((GFunc) dispatch_async_threadfunc, client,
+ DISPATCH_POOL_SIZE, FALSE, NULL);
}
gboolean dispatch_async(trg_client * client, JsonNode * req,
@@ -93,8 +95,7 @@ gboolean dispatch_async(trg_client * client, JsonNode * req,
gpointer data)
{
GError *error = NULL;
- struct DispatchAsyncData *args =
- g_new(struct DispatchAsyncData, 1);
+ struct DispatchAsyncData *args = g_new(struct DispatchAsyncData, 1);
args->callback = callback;
args->data = data;
diff --git a/src/dispatch.h b/src/dispatch.h
index e5a35e9..2520e10 100644
--- a/src/dispatch.h
+++ b/src/dispatch.h
@@ -37,6 +37,6 @@ JsonObject *dispatch(trg_client * client, JsonNode * req, int *status);
gboolean dispatch_async(trg_client * client, JsonNode * req,
void (*callback) (JsonObject *, int, gpointer),
gpointer data);
-GThreadPool *dispatch_init_pool(trg_client *client);
+GThreadPool *dispatch_init_pool(trg_client * client);
#endif /* DISPATCH_H_ */
diff --git a/src/requests.c b/src/requests.c
index a891364..ba761f9 100644
--- a/src/requests.c
+++ b/src/requests.c
@@ -110,15 +110,20 @@ JsonNode *torrent_remove(JsonArray * array, gboolean removeData)
return root;
}
-JsonNode *torrent_get(gboolean recent)
+JsonNode *torrent_get(gint64 id)
{
JsonNode *root = base_request(METHOD_TORRENT_GET);
JsonObject *args = node_get_arguments(root);
JsonArray *fields = json_array_new();
- if (recent)
+ if (id == -2) {
json_object_set_string_member(args, PARAM_IDS,
FIELD_RECENTLY_ACTIVE);
+ } else if (id >= 0) {
+ JsonArray *ids = json_array_new();
+ json_array_add_int_element(ids, id);
+ json_object_set_array_member(args, PARAM_IDS, ids);
+ }
json_array_add_string_element(fields, FIELD_ETA);
json_array_add_string_element(fields, FIELD_PEERS);
@@ -192,3 +197,8 @@ static JsonNode *base_request(gchar * method)
json_node_take_object(root, object);
return root;
}
+
+void request_set_tag(JsonNode * req, gint64 tag)
+{
+ json_object_set_int_member(json_node_get_object(req), PARAM_TAG, tag);
+}
diff --git a/src/requests.h b/src/requests.h
index b87cf3f..8c1bc00 100644
--- a/src/requests.h
+++ b/src/requests.h
@@ -27,7 +27,7 @@ JsonNode *generic_request(gchar * method, JsonArray * array);
JsonNode *session_set(void);
JsonNode *session_get(void);
-JsonNode *torrent_get(gboolean recent);
+JsonNode *torrent_get(gint64 id);
JsonNode *torrent_set(JsonArray * array);
JsonNode *torrent_pause(JsonArray * array);
JsonNode *torrent_start(JsonArray * array);
@@ -41,5 +41,6 @@ JsonNode *torrent_set_location(JsonArray * array, gchar * location,
JsonNode *blocklist_update(void);
JsonNode *port_test(void);
JsonNode *session_stats(void);
+void request_set_tag(JsonNode * req, gint64 tag);
#endif /* REQUESTS_H_ */
diff --git a/src/trg-files-model.c b/src/trg-files-model.c
index 0327962..7da053f 100644
--- a/src/trg-files-model.c
+++ b/src/trg-files-model.c
@@ -111,8 +111,7 @@ static void trg_files_model_init(TrgFilesModel * self)
gboolean
trg_files_model_update_foreach(GtkListStore * model,
GtkTreePath * path G_GNUC_UNUSED,
- GtkTreeIter * iter,
- GList *files)
+ GtkTreeIter * iter, GList * files)
{
TrgFilesModelPrivate *priv = TRG_FILES_MODEL_GET_PRIVATE(model);
JsonObject *file;
diff --git a/src/trg-files-tree-view.c b/src/trg-files-tree-view.c
index 19af10b..fdc6a1c 100644
--- a/src/trg-files-tree-view.c
+++ b/src/trg-files-tree-view.c
@@ -133,6 +133,7 @@ static void send_updated_file_prefs(TrgFilesTreeView * tv)
req = torrent_set(targetIdArray);
args = node_get_arguments(req);
+ request_set_tag(req, targetId);
gtk_tree_selection_selected_foreach(selection,
send_updated_file_prefs_foreachfunc,
diff --git a/src/trg-main-window.c b/src/trg-main-window.c
index 17af3e3..b5769af 100644
--- a/src/trg-main-window.c
+++ b/src/trg-main-window.c
@@ -860,7 +860,7 @@ TRANSMISSION_MIN_SUPPORTED, version);
trg_status_bar_connect(priv->statusBar, newSession);
trg_main_window_conn_changed(win, TRUE);
- dispatch_async(client, torrent_get(FALSE), on_torrent_get_first,
+ dispatch_async(client, torrent_get(-1), on_torrent_get_first,
data);
}
@@ -979,9 +979,10 @@ static gboolean trg_update_torrents_timerfunc(gpointer data)
if (priv->client->session)
dispatch_async(priv->client,
- torrent_get(priv->client->activeOnlyUpdate),
- priv->client->
- activeOnlyUpdate ? on_torrent_get_active :
+ torrent_get(priv->client->
+ activeOnlyUpdate ? -2 : -1),
+ priv->
+ client->activeOnlyUpdate ? on_torrent_get_active :
on_torrent_get_update, data);
return FALSE;
@@ -1149,13 +1150,21 @@ on_generic_interactive_action(JsonObject * response, int status,
trg_dialog_error_handler(TRG_MAIN_WINDOW(data), response, status);
gdk_threads_leave();
- if (status == CURLE_OK || status == FAIL_RESPONSE_UNSUCCESSFUL) {
- struct timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 350000000;
- nanosleep(&ts, NULL);
+ if (status == CURLE_OK) {
+ gint64 id;
+ if (json_object_has_member(response, PARAM_TAG)) {
+ id = json_object_get_int_member(response, PARAM_TAG);
+ } else if (priv->client->activeOnlyUpdate) {
+ id = -2;
+ } else {
+ id = -1;
+ }
+ /*struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 350000000;
+ nanosleep(&ts, NULL); */
- dispatch_async(priv->client, torrent_get(TRUE),
+ dispatch_async(priv->client, torrent_get(id),
on_torrent_get_interactive, data);
}
}
diff --git a/src/trg-peers-model.c b/src/trg-peers-model.c
index b80b05a..c9a64e1 100644
--- a/src/trg-peers-model.c
+++ b/src/trg-peers-model.c
@@ -61,7 +61,7 @@ find_existing_peer_item_foreachfunc(GtkTreeModel * model,
GtkTreePath * path G_GNUC_UNUSED,
GtkTreeIter * iter, gpointer data)
{
- struct peerAndIter *pi = (struct peerAndIter *)data;
+ struct peerAndIter *pi = (struct peerAndIter *) data;
gchar *ip;
gtk_tree_model_get(model, iter, PEERSCOL_IP, &ip, -1);
@@ -159,8 +159,7 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial,
PEERSCOL_ICON, GTK_STOCK_NETWORK,
PEERSCOL_IP, address,
#ifdef HAVE_GEOIP
- PEERSCOL_COUNTRY,
- country ? country : "",
+ PEERSCOL_COUNTRY, country ? country : "",
#endif
PEERSCOL_CLIENT, peer_get_client_name(peer),
-1);
@@ -183,9 +182,9 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial,
if (isNew == TRUE) {
GtkTreePath *path =
- gtk_tree_model_get_path(GTK_TREE_MODEL(model), &peerIter);
+ gtk_tree_model_get_path(GTK_TREE_MODEL(model), &peerIter);
GtkTreeRowReference *treeRef =
- gtk_tree_row_reference_new(GTK_TREE_MODEL(model), path);
+ gtk_tree_row_reference_new(GTK_TREE_MODEL(model), path);
GInetAddress *inetAddr;
GResolver *resolver;
diff --git a/src/trg-state-selector.c b/src/trg-state-selector.c
index 816d7a1..20345e5 100644
--- a/src/trg-state-selector.c
+++ b/src/trg-state-selector.c
@@ -247,9 +247,10 @@ void trg_state_selector_update(TrgStateSelector * s)
continue;
if (priv->showTrackers) {
- trackersList = json_array_get_elements(torrent_get_trackers(t));
- for (trackerItem = trackersList;
- trackerItem; trackerItem = g_list_next(trackerItem)) {
+ trackersList =
+ json_array_get_elements(torrent_get_trackers(t));
+ for (trackerItem = trackersList; trackerItem;
+ trackerItem = g_list_next(trackerItem)) {
JsonObject *tracker =
json_node_get_object((JsonNode *) trackerItem->data);
const gchar *announceUrl = tracker_get_announce(tracker);
diff --git a/src/trg-status-bar.c b/src/trg-status-bar.c
index 34b53ed..3e45b72 100644
--- a/src/trg-status-bar.c
+++ b/src/trg-status-bar.c
@@ -78,49 +78,57 @@ void trg_status_bar_connect(TrgStatusBar * sb, JsonObject * session)
}
void trg_status_bar_update(TrgStatusBar * sb,
- trg_torrent_model_update_stats * stats, trg_client * client)
+ trg_torrent_model_update_stats * stats,
+ trg_client * client)
{
TrgStatusBarPrivate *priv;
gchar *statusBarUpdate;
- gint64 uplimitraw, downlimitraw;
+ gint64 uplimitraw, downlimitraw;
gchar downRateTotalString[32], upRateTotalString[32];
- gchar uplimit[64], downlimit[64];
+ gchar uplimit[64], downlimit[64];
priv = TRG_STATUS_BAR_GET_PRIVATE(sb);
- /* The session should always exist otherwise this function wouldn't be called */
- downlimitraw = json_object_get_boolean_member(client->session, SGET_SPEED_LIMIT_DOWN_ENABLED) ?
- json_object_get_int_member(client->session, SGET_SPEED_LIMIT_DOWN) : -1;
+ /* The session should always exist otherwise this function wouldn't be called */
+ downlimitraw =
+ json_object_get_boolean_member(client->session,
+ SGET_SPEED_LIMIT_DOWN_ENABLED) ?
+ json_object_get_int_member(client->session,
+ SGET_SPEED_LIMIT_DOWN) : -1;
- uplimitraw = json_object_get_boolean_member(client->session, SGET_SPEED_LIMIT_UP_ENABLED) ?
- json_object_get_int_member(client->session, SGET_SPEED_LIMIT_UP) : -1;
+ uplimitraw =
+ json_object_get_boolean_member(client->session,
+ SGET_SPEED_LIMIT_UP_ENABLED) ?
+ json_object_get_int_member(client->session,
+ SGET_SPEED_LIMIT_UP) : -1;
trg_strlspeed(downRateTotalString,
stats->downRateTotal / KILOBYTE_FACTOR);
trg_strlspeed(upRateTotalString, stats->upRateTotal / KILOBYTE_FACTOR);
- if (uplimitraw >= 0)
- {
- gchar uplimitstring[32];
- trg_strlspeed(uplimitstring, uplimitraw);
- g_snprintf(uplimit, sizeof(uplimit), _( " (Limit: %s)" ), uplimitstring);
- }
+ if (uplimitraw >= 0) {
+ gchar uplimitstring[32];
+ trg_strlspeed(uplimitstring, uplimitraw);
+ g_snprintf(uplimit, sizeof(uplimit), _(" (Limit: %s)"),
+ uplimitstring);
+ }
- if (downlimitraw >= 0)
- {
- gchar downlimitstring[32];
- trg_strlspeed(downlimitstring, downlimitraw);
- g_snprintf(downlimit, sizeof(downlimit), _( " (Limit: %s)" ), downlimitstring);
- }
+ if (downlimitraw >= 0) {
+ gchar downlimitstring[32];
+ trg_strlspeed(downlimitstring, downlimitraw);
+ g_snprintf(downlimit, sizeof(downlimit), _(" (Limit: %s)"),
+ downlimitstring);
+ }
statusBarUpdate =
g_strdup_printf
(ngettext
("%d torrent .. Down %s%s, Up %s%s .. %d seeding, %d downloading, %d paused",
"%d torrents .. Down %s%s, Up %s%s .. %d seeding, %d downloading, %d paused",
- stats->count), stats->count, downRateTotalString, downlimitraw >= 0 ? downlimit : "",
- upRateTotalString, uplimitraw >= 0 ? uplimit : "",
- stats->seeding, stats->down, stats->paused);
+ stats->count), stats->count, downRateTotalString,
+ downlimitraw >= 0 ? downlimit : "", upRateTotalString,
+ uplimitraw >= 0 ? uplimit : "", stats->seeding, stats->down,
+ stats->paused);
gtk_statusbar_pop(GTK_STATUSBAR(sb), priv->countSpeedsCtx);
gtk_statusbar_push(GTK_STATUSBAR(sb),
priv->countSpeedsCtx, statusBarUpdate);
diff --git a/src/trg-status-bar.h b/src/trg-status-bar.h
index 27f2c44..88b4ed1 100644
--- a/src/trg-status-bar.h
+++ b/src/trg-status-bar.h
@@ -52,7 +52,8 @@ TrgStatusBar *trg_status_bar_new();
G_END_DECLS
void trg_status_bar_update(TrgStatusBar * sb,
- trg_torrent_model_update_stats * stats, trg_client * client);
+ trg_torrent_model_update_stats * stats,
+ trg_client * client);
void trg_status_bar_connect(TrgStatusBar * sb, JsonObject * session);
void trg_status_bar_push_connection_msg(TrgStatusBar * sb,
const gchar * msg);
diff --git a/src/trg-torrent-add-dialog.c b/src/trg-torrent-add-dialog.c
index 0dae71e..b9c5af8 100644
--- a/src/trg-torrent-add-dialog.c
+++ b/src/trg-torrent-add-dialog.c
@@ -747,9 +747,13 @@ static void store_add_node(GtkTreeStore * store, GtkTreeIter * parent,
(trg_torrent_file_node *) li->data);
}
-static void torrent_not_parsed_warning(GtkWindow *parent)
+static void torrent_not_parsed_warning(GtkWindow * parent)
{
- GtkWidget *dialog = gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Unable to parse torrent file. File preferences unavailable, but you can still try uploading it."));
+ GtkWidget *dialog =
+ gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
+ _
+ ("Unable to parse torrent file. File preferences unavailable, but you can still try uploading it."));
gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
@@ -897,8 +901,8 @@ static GObject *trg_torrent_add_dialog_constructor(GType type,
priv->paused_check =
gtk_check_button_new_with_mnemonic(_("Start _paused"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->paused_check),
- pref_get_start_paused(priv->client->
- gconf));
+ pref_get_start_paused(priv->
+ client->gconf));
priv->priority_combo = gtr_priority_combo_new();
gtk_combo_box_set_active(GTK_COMBO_BOX(priv->priority_combo), 1);
diff --git a/src/trg-torrent-props-dialog.c b/src/trg-torrent-props-dialog.c
index bf9f096..2851b7c 100644
--- a/src/trg-torrent-props-dialog.c
+++ b/src/trg-torrent-props-dialog.c
@@ -138,10 +138,12 @@ trg_torrent_props_response_cb(GtkDialog * dlg, gint res_id,
(priv->seedRatioLimit), args);
json_object_set_int_member(args, FIELD_SEED_RATIO_MODE,
gtk_combo_box_get_active(GTK_COMBO_BOX
- (priv->seedRatioMode)));
+ (priv->
+ seedRatioMode)));
json_object_set_int_member(args, FIELD_BANDWIDTH_PRIORITY,
gtk_combo_box_get_active(GTK_COMBO_BOX
- (priv->bandwidthPriorityCombo))
+ (priv->
+ bandwidthPriorityCombo))
- 1);
gtk_spin_button_json_int_out(GTK_SPIN_BUTTON
diff --git a/src/trg-trackers-tree-view.c b/src/trg-trackers-tree-view.c
index acc20eb..c650b28 100644
--- a/src/trg-trackers-tree-view.c
+++ b/src/trg-trackers-tree-view.c
@@ -103,6 +103,7 @@ static void trg_tracker_announce_edited(GtkCellRendererText * renderer,
json_array_add_int_element(torrentIds, torrentId);
req = torrent_set(torrentIds);
+ request_set_tag(req, torrentId);
args = node_get_arguments(req);
if (!g_strcmp0(icon, GTK_STOCK_ADD)) {
@@ -202,13 +203,15 @@ static void delete_tracker(GtkWidget * w, gpointer data)
GList *selectionRefs = trg_tree_view_get_selected_refs_list(tv);
GtkTreeModel *model = gtk_tree_view_get_model(tv);
JsonArray *trackerIds = json_array_new();
+ gint64 torrentId =
+ trg_trackers_model_get_torrent_id(TRG_TRACKERS_MODEL(model));
JsonArray *torrentIds = json_array_new();
JsonNode *req;
JsonObject *args;
GList *li;
- for (li = selectionRefs; li != NULL; li = g_list_next(li)) {
+ for (li = selectionRefs; li; li = g_list_next(li)) {
GtkTreeRowReference *rr = (GtkTreeRowReference *) li->data;
GtkTreePath *path = gtk_tree_row_reference_get_path(rr);
if (path != NULL) {
@@ -225,11 +228,10 @@ static void delete_tracker(GtkWidget * w, gpointer data)
}
g_list_free(selectionRefs);
- json_array_add_int_element(torrentIds,
- trg_trackers_model_get_torrent_id
- (TRG_TRACKERS_MODEL(model)));
+ json_array_add_int_element(torrentIds, torrentId);
req = torrent_set(torrentIds);
+ request_set_tag(req, torrentId);
args = node_get_arguments(req);
json_object_set_array_member(args, "trackerRemove", trackerIds);