summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-09-18 16:21:04 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-09-18 16:21:04 +0000
commit79cd86dbfd5b2ea0963c84b48088ec189acfc795 (patch)
tree535769200823fdaa1fec9795fe986668cb33bdee
parent63763bb00502e3c235e478ec50e097904c774696 (diff)
Big changeset, may break stuff. Unfortunately you can't magically jump into the UI thread using gdk_threads_enter/leave() on Windows, the only way is to schedule a callback using g_idle_add. This required a lot of reworking. Good news, Windows support actually works now \o/
-rw-r--r--src/Makefile.am12
-rw-r--r--src/dispatch.c113
-rw-r--r--src/dispatch.h42
-rw-r--r--src/json.c7
-rw-r--r--src/json.h3
-rw-r--r--src/main.c3
-rw-r--r--src/trg-about-window.c1
-rw-r--r--src/trg-client.c136
-rw-r--r--src/trg-client.h30
-rw-r--r--src/trg-files-tree-view.c13
-rw-r--r--src/trg-main-window.c180
-rw-r--r--src/trg-main-window.h5
-rw-r--r--src/trg-prefs.c4
-rw-r--r--src/trg-prefs.h2
-rw-r--r--src/trg-remote-prefs-dialog.c44
-rw-r--r--src/trg-state-selector.c2
-rw-r--r--src/trg-stats-dialog.c30
-rw-r--r--src/trg-torrent-add-dialog.c9
-rw-r--r--src/trg-torrent-add-url-dialog.c1
-rw-r--r--src/trg-torrent-graph.c4
-rw-r--r--src/trg-torrent-move-dialog.c1
-rw-r--r--src/trg-torrent-props-dialog.c1
-rw-r--r--src/trg-trackers-tree-view.c13
-rw-r--r--src/util.c14
-rw-r--r--src/util.h4
25 files changed, 291 insertions, 383 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5d18c97..660a59e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,7 +25,11 @@ desktopdir = $(datadir)/applications
desktop_DATA = transmission-remote-gtk.desktop
bin_PROGRAMS = transmission-remote-gtk
-INCLUDES = --pedantic -Wall -I.. -DTRGLICENSE=\""$(trglicense)"\" -DTRGLOCALEDIR=\""$(trglocaledir)"\" $(jsonglib_CFLAGS) $(gthread_CFLAGS) $(gtk_CFLAGS) $(gio_CFLAGS) $(unique_CFLAGS) $(notify_CFLAGS) $(libproxy_CFLAGS) -std=gnu99
+INCLUDES = --pedantic -Wall -I.. -DTRGLICENSE=\""$(trglicense)"\" $(libcurl_CFLAGS) $(jsonglib_CFLAGS) $(gthread_CFLAGS) $(gtk_CFLAGS) $(gio_CFLAGS) $(unique_CFLAGS) $(notify_CFLAGS) $(libproxy_CFLAGS) -std=gnu99
+
+if WIN32
+INCLUDES += -mms-bitfields -mwin32
+endif
transmission_remote_gtk_SOURCES = main.c \
requests.c \
@@ -37,7 +41,6 @@ transmission_remote_gtk_SOURCES = main.c \
torrent.c \
tpeer.c \
tfile.c \
- dispatch.c \
session-get.c \
trg-client.c \
trg-preferences-dialog.c \
@@ -79,7 +82,10 @@ transmission_remote_gtk_SOURCES = main.c \
trg-destination-combo.c \
$(NULL)
-transmission_remote_gtk_LDFLAGS = -lm -lcurl $(jsonglib_LIBS) $(gtk_LIBS) $(gthread_LIBS) $(GEOIP_LIBS) $(gio_LIBS) $(unique_LIBS) $(notify_LIBS) $(libproxy_LIBS)
+transmission_remote_gtk_LDFLAGS = -lm -lcurl $(jsonglib_LIBS) $(gtk_LIBS) $(gthread_LIBS) $(GEOIP_LIBS) $(gio_LIBS) $(unique_LIBS) $(notify_LIBS) $(libproxy_LIBS) $(libcurl_LIBS)
+if WIN32
+transmission_remote_gtk_LDFLAGS += -mwindows
+endif
install-data-local: install-icons update-icon-cache
diff --git a/src/dispatch.c b/src/dispatch.c
deleted file mode 100644
index 03a1755..0000000
--- a/src/dispatch.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * transmission-remote-gtk - A GTK RPC client to Transmission
- * Copyright (C) 2011 Alan Fitton
-
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <glib.h>
-#include <glib/gprintf.h>
-#include <json-glib/json-glib.h>
-#include <curl/curl.h>
-
-#include "config.h"
-#include "dispatch.h"
-#include "json.h"
-#include "protocol-constants.h"
-
-static void dispatch_async_threadfunc(struct DispatchAsyncData *task,
- TrgClient * client);
-
-JsonObject *dispatch(TrgClient * client, JsonNode * req, int *status)
-{
- gchar *serialized;
- trg_http_response *response;
- JsonObject *deserialized;
- JsonNode *result;
- GError *decode_error = NULL;
-
- serialized = trg_serialize(req);
- json_node_free(req);
-#ifdef DEBUG
- if (g_getenv("TRG_SHOW_OUTGOING"))
- g_debug("=>(OUTgoing)=>: %s", serialized);
-#endif
- response = trg_http_perform(client, serialized);
- g_free(serialized);
-
- if (status)
- *status = response->status;
-
- if (response->status != CURLE_OK) {
- http_response_free(response);
- return NULL;
- }
-
- deserialized = trg_deserialize(response, &decode_error);
- http_response_free(response);
-
- if (decode_error) {
- g_error("JSON decoding error: %s", decode_error->message);
- g_error_free(decode_error);
- if (status)
- *status = FAIL_JSON_DECODE;
- return NULL;
- }
-
- result = json_object_get_member(deserialized, FIELD_RESULT);
- if (status
- && (!result || g_strcmp0(json_node_get_string(result), FIELD_SUCCESS)))
- *status = FAIL_RESPONSE_UNSUCCESSFUL;
-
- return deserialized;
-}
-
-static void dispatch_async_threadfunc(struct DispatchAsyncData *task,
- TrgClient * client)
-{
- int status;
- JsonObject *result = dispatch(client, task->req, &status);
- if (task->callback)
- task->callback(result, status, task->data);
- g_free(task);
-}
-
-GThreadPool *dispatch_init_pool(TrgClient * client)
-{
- return g_thread_pool_new((GFunc) dispatch_async_threadfunc, client,
- DISPATCH_POOL_SIZE, TRUE, NULL);
-}
-
-gboolean dispatch_async(TrgClient * client, JsonNode * req,
- void (*callback) (JsonObject *, int, gpointer),
- gpointer data)
-{
- GError *error = NULL;
- struct DispatchAsyncData *args = g_new(struct DispatchAsyncData, 1);
-
- args->callback = callback;
- args->data = data;
- args->req = req;
-
- trg_client_thread_pool_push(client, args, &error);
- if (error) {
- g_error("thread creation error: %s\n", error->message);
- g_error_free(error);
- g_free(args);
- return FALSE;
- } else {
- return TRUE;
- }
-}
diff --git a/src/dispatch.h b/src/dispatch.h
deleted file mode 100644
index 0e7225f..0000000
--- a/src/dispatch.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * transmission-remote-gtk - A GTK RPC client to Transmission
- * Copyright (C) 2011 Alan Fitton
-
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef DISPATCH_H_
-#define DISPATCH_H_
-
-#include "trg-client.h"
-
-#define FAIL_JSON_DECODE -2
-#define FAIL_RESPONSE_UNSUCCESSFUL -3
-
-#define DISPATCH_POOL_SIZE 3
-
-struct DispatchAsyncData {
- gpointer *data;
- JsonNode *req;
- void (*callback) (JsonObject *, int, gpointer);
-};
-
-JsonObject *dispatch(TrgClient * client, JsonNode * req, int *status);
-gboolean dispatch_async(TrgClient * client, JsonNode * req,
- void (*callback) (JsonObject *, int, gpointer),
- gpointer data);
-GThreadPool *dispatch_init_pool(TrgClient * client);
-
-#endif /* DISPATCH_H_ */
diff --git a/src/json.c b/src/json.c
index fce3954..ce166f2 100644
--- a/src/json.c
+++ b/src/json.c
@@ -25,7 +25,6 @@
#include "config.h"
#include "protocol-constants.h"
#include "requests.h"
-#include "dispatch.h"
#include "json.h"
gchar *trg_serialize(JsonNode * req)
@@ -43,7 +42,7 @@ gchar *trg_serialize(JsonNode * req)
return response;
}
-JsonObject *trg_deserialize(trg_http_response * response,
+JsonObject *trg_deserialize(trg_response * reqrsp,
GError ** error)
{
JsonParser *parser;
@@ -51,13 +50,13 @@ JsonObject *trg_deserialize(trg_http_response * response,
JsonObject *ret = NULL;
parser = json_parser_new();
- json_parser_load_from_data(parser, response->data, response->size,
+ json_parser_load_from_data(parser, reqrsp->raw, reqrsp->size,
error);
if (*error == NULL) {
root = json_parser_get_root(parser);
#ifdef DEBUG
if (g_getenv("TRG_SHOW_INCOMING") != NULL) {
- g_debug("<=(INcoming)<=: %s", response->data);
+ g_debug("<=(INcoming)<=: %s", reqrsp->raw);
} else if (g_getenv("TRG_SHOW_INCOMING_PRETTY") != NULL) {
JsonGenerator *pg;
gsize len;
diff --git a/src/json.h b/src/json.h
index a71e130..62237f8 100644
--- a/src/json.h
+++ b/src/json.h
@@ -26,8 +26,7 @@
#include "trg-client.h"
gchar *trg_serialize(JsonNode * req);
-JsonObject *trg_deserialize(trg_http_response *response,
- GError ** error);
+JsonObject *trg_deserialize(trg_response *response, GError ** error);
JsonObject *get_arguments(JsonObject * req);
JsonObject *node_get_arguments(JsonNode * req);
diff --git a/src/main.c b/src/main.c
index adbb416..e64f35c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -100,11 +100,10 @@ int main(int argc, char *argv[])
g_type_init();
g_thread_init(NULL);
- gdk_threads_init();
gtk_init(&argc, &argv);
g_set_application_name (PACKAGE_NAME);
- bindtextdomain(GETTEXT_PACKAGE, TRGLOCALEDIR);
+ bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
diff --git a/src/trg-about-window.c b/src/trg-about-window.c
index 654aeab..d173251 100644
--- a/src/trg-about-window.c
+++ b/src/trg-about-window.c
@@ -25,7 +25,6 @@
#include <gtk/gtk.h>
#include <json-glib/json-glib.h>
-#include "dispatch.h"
#include "trg-about-window.h"
#include "util.h"
diff --git a/src/trg-client.c b/src/trg-client.c
index 3dbcea1..6ddca81 100644
--- a/src/trg-client.c
+++ b/src/trg-client.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>
@@ -33,9 +31,10 @@
#include <curl/curl.h>
#include <curl/easy.h>
+#include "json.h"
#include "trg-prefs.h"
+#include "protocol-constants.h"
#include "util.h"
-#include "dispatch.h"
#include "trg-client.h"
G_DEFINE_TYPE (TrgClient, trg_client, G_TYPE_OBJECT)
@@ -75,6 +74,9 @@ struct _TrgClientPrivate {
GMutex *configMutex;
};
+static void dispatch_async_threadfunc(trg_request *reqrsp,
+ TrgClient * client);
+
static void
trg_client_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
@@ -82,6 +84,7 @@ trg_client_get_property (GObject *object, guint property_id,
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
@@ -92,6 +95,7 @@ trg_client_set_property (GObject *object, guint property_id,
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
@@ -138,9 +142,11 @@ trg_client_new (void)
priv->updateMutex = g_mutex_new();
priv->configMutex = g_mutex_new();
- priv->pool = dispatch_init_pool(tc);
priv->tlsKey = g_private_new(NULL);
+ priv->pool = g_thread_pool_new((GFunc) dispatch_async_threadfunc, tc,
+ DISPATCH_POOL_SIZE, TRUE, NULL);
+
return tc;
}
@@ -441,24 +447,25 @@ void trg_client_set_minimised_interval(TrgClient *tc, guint interval)
/* formerly http.c */
-void http_response_free(trg_http_response *response)
+void trg_response_free(trg_response *response)
{
- g_free(response->data);
- response->data = NULL;
+ json_object_unref(response->obj);
+ g_free(response);
}
static size_t
http_receive_callback(void *ptr, size_t size, size_t nmemb, void *data)
{
size_t realsize = size * nmemb;
- trg_http_response *mem = (trg_http_response *) data;
+ trg_response *mem = (trg_response *) data;
- mem->data = realloc(mem->data, mem->size + realsize + 1);
- if (mem->data) {
- memcpy(&(mem->data[mem->size]), ptr, realsize);
+ mem->raw = realloc(mem->raw, mem->size + realsize + 1);
+ if (mem->raw) {
+ memcpy(&(mem->raw[mem->size]), ptr, realsize);
mem->size += realsize;
- mem->data[mem->size] = 0;
+ mem->raw[mem->size] = 0;
}
+
return realsize;
}
@@ -509,14 +516,11 @@ trg_tls *trg_tls_new(TrgClient *tc)
{
trg_tls *tls = g_new0(trg_tls, 1);
- tls->response = g_new0(trg_http_response, 1);
-
tls->curl = curl_easy_init();
curl_easy_setopt(tls->curl, CURLOPT_USERAGENT, PACKAGE_NAME);
curl_easy_setopt(tls->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(tls->curl, CURLOPT_WRITEFUNCTION,
&http_receive_callback);
- curl_easy_setopt(tls->curl, CURLOPT_WRITEDATA, (void *)tls->response);
curl_easy_setopt(tls->curl, CURLOPT_HEADERFUNCTION, &header_callback);
curl_easy_setopt(tls->curl, CURLOPT_WRITEHEADER, (void *) tc);
@@ -525,8 +529,9 @@ trg_tls *trg_tls_new(TrgClient *tc)
return tls;
}
-static trg_http_response *trg_http_perform_inner(TrgClient * tc,
- gchar * req,
+static int trg_http_perform_inner(TrgClient * tc,
+ gchar * reqstr,
+ trg_response *response,
gboolean recurse)
{
TrgClientPrivate *priv = TRG_CLIENT_GET_PRIVATE(tc);
@@ -556,16 +561,12 @@ static trg_http_response *trg_http_perform_inner(TrgClient * tc,
g_mutex_unlock(priv->configMutex);
- tls->response->size = 0;
- tls->response->status = -1;
-
- if (tls->response->data) {
- g_free(tls->response->data);
- tls->response->data = NULL;
- }
+ response->size = 0;
+ response->raw = NULL;
- curl_easy_setopt(tls->curl, CURLOPT_POSTFIELDS, req);
- tls->response->status = curl_easy_perform(tls->curl);
+ curl_easy_setopt(tls->curl, CURLOPT_POSTFIELDS, reqstr);
+ curl_easy_setopt(tls->curl, CURLOPT_WRITEDATA, (void *)response);
+ response->status = curl_easy_perform(tls->curl);
if (session_id) {
g_free(session_id);
@@ -574,17 +575,88 @@ static trg_http_response *trg_http_perform_inner(TrgClient * tc,
curl_easy_getinfo(tls->curl, CURLINFO_RESPONSE_CODE, &httpCode);
- if (tls->response->status == CURLE_OK) {
+ if (response->status == CURLE_OK) {
if (httpCode == HTTP_CONFLICT && recurse == TRUE)
- return trg_http_perform_inner(tc, req, FALSE);
+ return trg_http_perform_inner(tc, reqstr, response, FALSE);
else if (httpCode != HTTP_OK)
- tls->response->status = (-httpCode) - 100;
+ response->status = (-httpCode) - 100;
}
- return tls->response;
+ return response->status;
}
-trg_http_response *trg_http_perform(TrgClient * tc, gchar * req)
+int trg_http_perform(TrgClient * tc, gchar * reqstr, trg_response *reqrsp)
{
- return trg_http_perform_inner(tc, req, TRUE);
+ return trg_http_perform_inner(tc, reqstr, reqrsp, TRUE);
+}
+
+/* formerly dispatch.c */
+
+trg_response *dispatch(TrgClient * client, JsonNode * req)
+{
+ trg_response *response = g_new0(trg_response, 1);
+ GError *decode_error = NULL;
+ gchar *serialized;
+ JsonNode *result;
+
+ serialized = trg_serialize(req);
+ json_node_free(req);
+#ifdef DEBUG
+ if (g_getenv("TRG_SHOW_OUTGOING"))
+ g_debug("=>(OUTgoing)=>: %s", serialized);
+#endif
+ trg_http_perform(client, serialized, response);
+ g_free(serialized);
+
+ if (response->status != CURLE_OK)
+ return response;
+
+ response->obj = trg_deserialize(response, &decode_error);
+ g_free(response->raw);
+ response->raw = NULL;
+
+ if (decode_error) {
+ g_error("JSON decoding error: %s", decode_error->message);
+ g_error_free(decode_error);
+ response->status = FAIL_JSON_DECODE;
+ return response;
+ }
+
+ result = json_object_get_member(response->obj, FIELD_RESULT);
+ if (!result || g_strcmp0(json_node_get_string(result), FIELD_SUCCESS))
+ response->status = FAIL_RESPONSE_UNSUCCESSFUL;
+
+ return response;
+}
+
+static void dispatch_async_threadfunc(trg_request *req,
+ TrgClient * client)
+{
+ trg_response *rsp = dispatch(client, req->node);
+ rsp->cb_data = req->cb_data;
+ if (req->callback)
+ g_idle_add(req->callback, rsp);
+ g_free(req);
+}
+
+gboolean dispatch_async(TrgClient * client, JsonNode * req,
+ GSourceFunc callback,
+ gpointer data)
+{
+ GError *error = NULL;
+ trg_request *trg_req = g_new(trg_request, 1);
+
+ trg_req->callback = callback;
+ trg_req->cb_data = data;
+ trg_req->node = req;
+
+ trg_client_thread_pool_push(client, trg_req, &error);
+ if (error) {
+ g_error("thread creation error: %s\n", error->message);
+ g_error_free(error);
+ g_free(req);
+ return FALSE;
+ } else {
+ return TRUE;
+ }
}
diff --git a/src/trg-client.h b/src/trg-client.h
index a35b9cb..d6aa679 100644
--- a/src/trg-client.h
+++ b/src/trg-client.h
@@ -52,11 +52,25 @@
#define HTTP_OK 200
#define HTTP_CONFLICT 409
+#define FAIL_JSON_DECODE -2
+#define FAIL_RESPONSE_UNSUCCESSFUL -3
+#define DISPATCH_POOL_SIZE 3
+
+
typedef struct {
int status;
- char *data;
+ char *raw;
int size;
-} trg_http_response;
+ JsonObject *obj;
+ gpointer cb_data;
+} trg_response;
+
+typedef struct
+{
+ JsonNode *node;
+ GSourceFunc callback;
+ gpointer cb_data;
+} trg_request;
G_BEGIN_DECLS
@@ -98,14 +112,20 @@ typedef struct {
*/
int serial;
CURL *curl;
- trg_http_response *response;
} trg_tls;
/* stuff that used to be in http.h */
-void http_response_free(trg_http_response *response);
-trg_http_response *trg_http_perform(TrgClient * client, gchar * req);
+void trg_response_free(trg_response *response);
+int trg_http_perform(TrgClient * client, gchar * reqstr, trg_response *reqrsp);
/* end http.h*/
+/* stuff that used to be in dispatch.c */
+trg_response *dispatch(TrgClient * client, JsonNode * req);
+gboolean dispatch_async(TrgClient * client, JsonNode * req,
+ GSourceFunc callback,
+ gpointer data);
+/* end dispatch.c*/
+
GType trg_client_get_type (void);
TrgClient* trg_client_new (void);
diff --git a/src/trg-files-tree-view.c b/src/trg-files-tree-view.c
index f0975fa..d9661b0 100644
--- a/src/trg-files-tree-view.c
+++ b/src/trg-files-tree-view.c
@@ -30,7 +30,6 @@
#include "requests.h"
#include "util.h"
#include "json.h"
-#include "dispatch.h"
#include "protocol-constants.h"
G_DEFINE_TYPE(TrgFilesTreeView, trg_files_tree_view, TRG_TYPE_TREE_VIEW)
@@ -104,15 +103,17 @@ static void send_updated_file_prefs_foreachfunc(GtkTreeModel * model,
add_file_id_to_array(args, FIELD_FILES_PRIORITY_NORMAL, id);
}
-static void
-on_files_update(JsonObject * response, int status, gpointer data)
+static gboolean
+on_files_update(gpointer data)
{
- TrgFilesTreeViewPrivate *priv = TRG_FILES_TREE_VIEW_GET_PRIVATE(data);
- GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(data));
+ trg_response *response = (trg_response*)data;
+ TrgFilesTreeViewPrivate *priv = TRG_FILES_TREE_VIEW_GET_PRIVATE(response->cb_data);
+ GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(response->cb_data));
trg_files_model_set_accept(TRG_FILES_MODEL(model), TRUE);
- on_generic_interactive_action(response, status, priv->win);
+ response->cb_data = priv->win;
+ return on_generic_interactive_action(data);
}
static void send_updated_file_prefs(TrgFilesTreeView * tv)
diff --git a/src/trg-main-window.c b/src/trg-main-window.c
index 08bdc18..7a1998c 100644
--- a/src/trg-main-window.c
+++ b/src/trg-main-window.c
@@ -36,7 +36,6 @@
#include <libnotify/notify.h>
#endif
-#include "dispatch.h"
#include "trg-client.h"
#include "json.h"
#include "util.h"
@@ -110,17 +109,12 @@ static void view_stats_toggled_cb(GtkWidget * w, gpointer data);
static void view_states_toggled_cb(GtkCheckMenuItem * w, gpointer data);
static void view_notebook_toggled_cb(GtkCheckMenuItem * w, gpointer data);
static GtkWidget *trg_main_window_notebook_new(TrgMainWindow * win);
-static void on_session_get(JsonObject * response, int status, gpointer data);
-static void on_torrent_get(JsonObject * response, int mode, int status,
- gpointer data);
-static void on_torrent_get_first(JsonObject * response, int status,
- gpointer data);
-static void on_torrent_get_active(JsonObject * response, int status,
- gpointer data);
-static void on_torrent_get_update(JsonObject * response, int status,
- gpointer data);
-static void on_torrent_get_interactive(JsonObject * response, int status,
- gpointer data);
+static gboolean on_session_get(gpointer data);
+static gboolean on_torrent_get(gpointer data, int mode);
+static gboolean on_torrent_get_first(gpointer data);
+static gboolean on_torrent_get_active(gpointer data);
+static gboolean on_torrent_get_update(gpointer data);
+static gboolean on_torrent_get_interactive(gpointer data);
static gboolean trg_update_torrents_timerfunc(gpointer data);
static void open_about_cb(GtkWidget * w, GtkWindow * parent);
static gboolean trg_torrent_tree_view_visible_func(GtkTreeModel * model,
@@ -129,7 +123,7 @@ static TrgTorrentTreeView
* trg_main_window_torrent_tree_view_new(TrgMainWindow * win,
GtkTreeModel * model);
static gboolean trg_dialog_error_handler(TrgMainWindow * win,
- JsonObject * response, int status);
+ trg_response *response);
static gboolean torrent_selection_changed(GtkTreeSelection * selection,
gpointer data);
static void trg_main_window_torrent_scrub(TrgMainWindow * win);
@@ -332,6 +326,11 @@ static void destroy_window(GtkWidget * w, gpointer data G_GNUC_UNUSED) {
TRG_PREFS_GLOBAL);
trg_prefs_set_int(prefs, TRG_PREFS_KEY_WINDOW_WIDTH, priv->width,
TRG_PREFS_GLOBAL);
+ trg_prefs_set_int(prefs, TRG_PREFS_KEY_NOTEBOOK_PANED_POS, gtk_paned_get_position(GTK_PANED(priv->vpaned)),
+ TRG_PREFS_GLOBAL);
+ trg_prefs_set_int(prefs, TRG_PREFS_KEY_STATES_PANED_POS, gtk_paned_get_position(GTK_PANED(priv->hpaned)),
+ TRG_PREFS_GLOBAL);
+
trg_tree_view_persist(TRG_TREE_VIEW(priv->peersTreeView));
trg_tree_view_persist(TRG_TREE_VIEW(priv->filesTreeView));
trg_tree_view_persist(TRG_TREE_VIEW(priv->torrentTreeView));
@@ -396,12 +395,10 @@ gboolean trg_add_from_filename(TrgMainWindow * win, gchar ** uris) {
if (trg_prefs_get_bool(prefs, TRG_PREFS_KEY_ADD_OPTIONS_DIALOG,
TRG_PREFS_GLOBAL)) {
- gdk_threads_enter();
TrgTorrentAddDialog *dialog = trg_torrent_add_dialog_new(win, client,
filesList);
gtk_widget_show_all(GTK_WIDGET(dialog));
- gdk_threads_leave();
} else {
struct add_torrent_threadfunc_args *args =
g_new0(struct add_torrent_threadfunc_args, 1);
@@ -743,8 +740,6 @@ static GtkWidget *trg_main_window_notebook_new(TrgMainWindow * win) {
GtkWidget *notebook = priv->notebook = gtk_notebook_new();
- gtk_widget_set_size_request(notebook, -1, 185);
-
priv->genDetails = trg_general_panel_new(
GTK_TREE_MODEL(priv->torrentModel), priv->client);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
@@ -778,35 +773,33 @@ static GtkWidget *trg_main_window_notebook_new(TrgMainWindow * win) {
return notebook;
}
-void on_session_set(JsonObject * response, int status, gpointer data) {
- TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data);
+gboolean on_session_set(gpointer data) {
+ trg_response *response = (trg_response*)data;
+ TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(response->cb_data);
- if (status == CURLE_OK || status == FAIL_RESPONSE_UNSUCCESSFUL)
- dispatch_async(priv->client, session_get(), on_session_get, data);
+ if (response->status == CURLE_OK || response->status == FAIL_RESPONSE_UNSUCCESSFUL)
+ dispatch_async(priv->client, session_get(), on_session_get, response->cb_data);
- gdk_threads_enter();
- trg_dialog_error_handler(TRG_MAIN_WINDOW(data), response, status);
- gdk_threads_leave();
+ trg_dialog_error_handler(TRG_MAIN_WINDOW(data), response);
+ trg_response_free(response);
- response_unref(response);
+ return FALSE;
}
-static void on_session_get(JsonObject * response, int status, gpointer data) {
- TrgMainWindow *win = TRG_MAIN_WINDOW(data);
- TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data);
+static gboolean on_session_get(gpointer data) {
+ trg_response *response = (trg_response*)data;
+ TrgMainWindow *win = TRG_MAIN_WINDOW(response->cb_data);
+ TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(response->cb_data);
TrgClient *client = priv->client;
- JsonObject *newSession;
gboolean isConnected = trg_client_is_connected(client);
+ JsonObject *newSession;
- gdk_threads_enter();
-
- if (trg_dialog_error_handler(win, response, status) == TRUE) {
- response_unref(response);
- gdk_threads_leave();
- return;
+ if (trg_dialog_error_handler(win, response) == TRUE) {
+ trg_response_free(response);
+ return FALSE;
}
- newSession = get_arguments(response);
+ newSession = get_arguments(response->obj);
if (!isConnected) {
float version;
@@ -825,9 +818,8 @@ static void on_session_get(JsonObject * response, int status, gpointer data) {
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
g_free(msg);
- gdk_threads_leave();
- response_unref(response);
- return;
+ trg_response_free(response);
+ return FALSE;
}
}
@@ -840,26 +832,24 @@ static void on_session_get(JsonObject * response, int status, gpointer data) {
if (!isConnected)
trg_trackers_tree_view_new_connection(priv->trackersTreeView, client);
- gdk_threads_leave();
-
json_object_ref(newSession);
- response_unref(response);
- if (!isConnected) {
- int firstStatus;
- JsonObject *firstResponse = dispatch(client, torrent_get(-1),
- &firstStatus);
- on_torrent_get_first(firstResponse, firstStatus, data);
- }
+ if (!isConnected)
+ dispatch_async(client, torrent_get(-1), on_torrent_get_first, win);
+
+ trg_response_free(response);
+
+ return FALSE;
}
/*
* The callback for a torrent-get response.
*/
-static void on_torrent_get(JsonObject * response, int mode, int status,
- gpointer data) {
- TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data);
+static gboolean on_torrent_get(gpointer data, int mode) {
+ trg_response *response = (trg_response*)data;
+ TrgMainWindow *win = TRG_MAIN_WINDOW(response->cb_data);
+ TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(response->cb_data);
TrgClient *client = priv->client;
trg_torrent_model_update_stats stats;
@@ -867,35 +857,33 @@ static void on_torrent_get(JsonObject * response, int mode, int status,
/* Disconnected between request and response callback */
if (!trg_client_is_connected(client)) {
- response_unref(response);
- return;
+ trg_response_free(response);
+ return FALSE;
}
trg_client_updatelock(client);
- gdk_threads_enter();
interval
- = gtk_widget_get_visible(GTK_WIDGET(data)) ? trg_client_get_interval(
+ = gtk_widget_get_visible(GTK_WIDGET(win)) ? trg_client_get_interval(
client)
: trg_client_get_minimised_interval(client);
- if (status != CURLE_OK) {
+ if (response->status != CURLE_OK) {
if (trg_client_inc_failcount(client) >= TRG_MAX_RETRIES) {
- trg_main_window_conn_changed(TRG_MAIN_WINDOW(data), FALSE);
- trg_dialog_error_handler(TRG_MAIN_WINDOW(data), response, status);
+ trg_main_window_conn_changed(win, FALSE);
+ trg_dialog_error_handler(win, response);
} else {
- gchar *msg = make_error_message(response, status);
+ gchar *msg = make_error_message(response->obj, response->status);
gchar *statusBarMsg = g_strdup_printf(_("Request %d/%d failed: %s"),
trg_client_get_failcount(client), TRG_MAX_RETRIES, msg);
trg_status_bar_push_connection_msg(priv->statusBar, statusBarMsg);
g_free(msg);
g_free(statusBarMsg);
- priv->timerId = g_timeout_add_seconds(interval, trg_update_torrents_timerfunc, data);
+ priv->timerId = g_timeout_add_seconds(interval, trg_update_torrents_timerfunc, win);
}
- gdk_threads_leave();
trg_client_updateunlock(client);
- response_unref(response);
- return;
+ trg_response_free(response);
+ return FALSE;
}
trg_client_reset_failcount(client);
@@ -903,9 +891,9 @@ static void on_torrent_get(JsonObject * response, int mode, int status,
trg_client_inc_serial(client);
- trg_torrent_model_update(priv->torrentModel, client, response, &stats, mode);
+ trg_torrent_model_update(priv->torrentModel, client, response->obj, &stats, mode);
- update_selected_torrent_notebook(TRG_MAIN_WINDOW(data), mode,
+ update_selected_torrent_notebook(win, mode,
priv->selectedTorrentId);
trg_status_bar_update(priv->statusBar, &stats, client);
@@ -914,31 +902,27 @@ static void on_torrent_get(JsonObject * response, int mode, int status,
trg_torrent_graph_set_speed(priv->graph, &stats);
if (mode != TORRENT_GET_MODE_INTERACTION)
- priv->timerId = g_timeout_add_seconds(interval, trg_update_torrents_timerfunc, data);
+ priv->timerId = g_timeout_add_seconds(interval, trg_update_torrents_timerfunc, win);
- gdk_threads_leave();
trg_client_updateunlock(client);
- response_unref(response);
+ trg_response_free(response);
+ return FALSE;
}
-static void on_torrent_get_active(JsonObject * response, int status,
- gpointer data) {
- on_torrent_get(response, TORRENT_GET_MODE_ACTIVE, status, data);
+static gboolean on_torrent_get_active(gpointer data) {
+ return on_torrent_get(data, TORRENT_GET_MODE_ACTIVE);
}
-static void on_torrent_get_first(JsonObject * response, int status,
- gpointer data) {
- on_torrent_get(response, TORRENT_GET_MODE_FIRST, status, data);
+static gboolean on_torrent_get_first(gpointer data) {
+ return on_torrent_get(data, TORRENT_GET_MODE_FIRST);
}
-static void on_torrent_get_interactive(JsonObject * response, int status,
- gpointer data) {
- on_torrent_get(response, TORRENT_GET_MODE_INTERACTION, status, data);
+static gboolean on_torrent_get_interactive(gpointer data) {
+ return on_torrent_get(data, TORRENT_GET_MODE_INTERACTION);
}
-static void on_torrent_get_update(JsonObject * response, int status,
- gpointer data) {
- on_torrent_get(response, TORRENT_GET_MODE_UPDATE, status, data);
+static gboolean on_torrent_get_update(gpointer data) {
+ return on_torrent_get(data, TORRENT_GET_MODE_UPDATE);
}
static gboolean trg_update_torrents_timerfunc(gpointer data) {
@@ -1049,14 +1033,14 @@ static TrgTorrentTreeView *trg_main_window_torrent_tree_view_new(
}
static gboolean trg_dialog_error_handler(TrgMainWindow * win,
- JsonObject * response, int status) {
+ trg_response *response) {
TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win);
- if (status != CURLE_OK) {
+ if (response->status != CURLE_OK) {
GtkWidget *dialog;
const gchar *msg;
- msg = make_error_message(response, status);
+ msg = make_error_message(response->obj, response->status);
trg_status_bar_clear_indicators(priv->statusBar);
trg_status_bar_push_connection_msg(priv->statusBar, msg);
dialog = gtk_message_dialog_new(GTK_WINDOW(win), GTK_DIALOG_MODAL,
@@ -1105,33 +1089,30 @@ static gboolean torrent_selection_changed(GtkTreeSelection * selection,
return TRUE;
}
-void on_generic_interactive_action(JsonObject * response, int status,
- gpointer data) {
- TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data);
+gboolean on_generic_interactive_action(gpointer data) {
+ trg_response *response = (trg_response*)data;
+ TrgMainWindow *win = TRG_MAIN_WINDOW(response->cb_data);
+ TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(response->cb_data);
TrgClient *tc = priv->client;
if (trg_client_is_connected(tc)) {
- gdk_threads_enter();
- trg_dialog_error_handler(TRG_MAIN_WINDOW(data), response, status);
- gdk_threads_leave();
+ trg_dialog_error_handler(win, response);
- if (status == CURLE_OK) {
+ if (response->status == CURLE_OK) {
gint64 id;
- gint updateStatus;
- JsonObject *updateResponse;
- if (json_object_has_member(response, PARAM_TAG))
- id = json_object_get_int_member(response, PARAM_TAG);
+ if (json_object_has_member(response->obj, PARAM_TAG))
+ id = json_object_get_int_member(response->obj, PARAM_TAG);
else if (trg_client_get_activeonlyupdate(tc))
id = -2;
else
id = -1;
- updateResponse = dispatch(tc, torrent_get(id), &updateStatus);
- on_torrent_get_interactive(updateResponse, updateStatus, data);
+ dispatch_async(tc, torrent_get(id), on_torrent_get_interactive, win);
}
}
- response_unref(response);
+ trg_response_free(response);
+ return FALSE;
}
static
@@ -1208,6 +1189,7 @@ static void trg_main_window_get_property(GObject * object, guint property_id,
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
@@ -1223,6 +1205,7 @@ static void trg_main_window_set_property(GObject * object, guint property_id,
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
@@ -1912,6 +1895,9 @@ static GObject *trg_main_window_constructor(GType type,
trg_prefs_get_bool(prefs, TRG_PREFS_KEY_SHOW_NOTEBOOK,
TRG_PREFS_GLOBAL));
+ gtk_paned_set_position(GTK_PANED(priv->vpaned), trg_prefs_get_int(prefs, TRG_PREFS_KEY_NOTEBOOK_PANED_POS, TRG_PREFS_GLOBAL));
+ gtk_paned_set_position(GTK_PANED(priv->hpaned), trg_prefs_get_int(prefs, TRG_PREFS_KEY_STATES_PANED_POS, TRG_PREFS_GLOBAL));
+
if (tray && priv->min_on_start)
gtk_widget_hide(GTK_WIDGET(self));
diff --git a/src/trg-main-window.h b/src/trg-main-window.h
index da04254..ac19fba 100644
--- a/src/trg-main-window.h
+++ b/src/trg-main-window.h
@@ -58,9 +58,8 @@ typedef struct {
GType trg_main_window_get_type(void);
gboolean trg_add_from_filename(TrgMainWindow * win, gchar ** uris);
-void on_session_set(JsonObject * response, int status, gpointer data);
-void on_generic_interactive_action(JsonObject * response, int status,
- gpointer data);
+gboolean on_session_set(gpointer data);
+gboolean on_generic_interactive_action(gpointer data);
void auto_connect_if_required(TrgMainWindow * win, TrgClient * tc);
TrgMainWindow *trg_main_window_new(TrgClient * tc, gboolean minonstart);
void trg_main_window_add_status_icon(TrgMainWindow * win);
diff --git a/src/trg-prefs.c b/src/trg-prefs.c
index be9d4e5..69e1557 100644
--- a/src/trg-prefs.c
+++ b/src/trg-prefs.c
@@ -60,6 +60,7 @@ static void trg_prefs_get_property(GObject *object, guint property_id,
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
@@ -68,6 +69,7 @@ static void trg_prefs_set_property(GObject *object, guint property_id,
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
@@ -85,6 +87,8 @@ static void trg_prefs_create_defaults(TrgPrefs *p) {
trg_prefs_add_default_int(p, TRG_PREFS_KEY_UPDATE_INTERVAL, TRG_INTERVAL_DEFAULT);
trg_prefs_add_default_int(p, TRG_PREFS_KEY_MINUPDATE_INTERVAL, TRG_MININTERVAL_DEFAULT);
trg_prefs_add_default_int(p, TRG_PREFS_ACTIVEONLY_FULLSYNC_EVERY, 2);
+ trg_prefs_add_default_int(p, TRG_PREFS_KEY_NOTEBOOK_PANED_POS, 185);
+ trg_prefs_add_default_int(p, TRG_PREFS_KEY_STATES_PANED_POS, 120);
trg_prefs_add_default_bool_true(p, TRG_PREFS_KEY_FILTER_DIRS);
trg_prefs_add_default_bool_true(p, TRG_PREFS_KEY_FILTER_TRACKERS);
diff --git a/src/trg-prefs.h b/src/trg-prefs.h
index bc3f475..7fcfb87 100644
--- a/src/trg-prefs.h
+++ b/src/trg-prefs.h
@@ -66,6 +66,8 @@
#define TRG_PREFS_KEY_TV_SORT_COL "sort-col"
#define TRG_PREFS_KEY_TV_COLUMNS "columns"
#define TRG_PREFS_KEY_TV_WIDTHS "widths"
+#define TRG_PREFS_KEY_NOTEBOOK_PANED_POS "notebook-paned-pos"
+#define TRG_PREFS_KEY_STATES_PANED_POS "states-paned-pos"
#define TRG_PREFS_NOFLAGS (1 << 0) /* 0x00 */
#define TRG_PREFS_GLOBAL (1 << 1) /* 0x01 */
diff --git a/src/trg-remote-prefs-dialog.c b/src/trg-remote-prefs-dialog.c
index 4d28f2e..3926ff8 100644
--- a/src/trg-remote-prefs-dialog.c
+++ b/src/trg-remote-prefs-dialog.c
@@ -26,7 +26,6 @@
#include "trg-remote-prefs-dialog.h"
#include "hig.h"
#include "util.h"
-#include "dispatch.h"
#include "requests.h"
#include "json.h"
#include "trg-json-widgets.h"
@@ -186,19 +185,18 @@ static GtkWidget *trg_rprefs_limitsPage(TrgRemotePrefsDialog * win,
return t;
}
-static void on_port_tested(JsonObject * response, int status, gpointer data) {
- gdk_threads_enter();
-
- if (TRG_IS_REMOTE_PREFS_DIALOG(data)) {
+static gboolean on_port_tested(gpointer data) {
+ trg_response *response = (trg_response*)data;
+ if (TRG_IS_REMOTE_PREFS_DIALOG(response->cb_data)) {
TrgRemotePrefsDialogPrivate *priv =
- TRG_REMOTE_PREFS_DIALOG_GET_PRIVATE(data);
+ TRG_REMOTE_PREFS_DIALOG_GET_PRIVATE(response->cb_data);
gtk_button_set_label(GTK_BUTTON(priv->port_test_button), _("Retest"));
gtk_widget_set_sensitive(priv->port_test_button, TRUE);
- if (status == CURLE_OK) {
+ if (response->status == CURLE_OK) {
gboolean isOpen = json_object_get_boolean_member(
- get_arguments(response), "port-is-open");
+ get_arguments(response->obj), "port-is-open");
if (isOpen)
gtk_label_set_markup(
GTK_LABEL(priv->port_test_label),
@@ -210,12 +208,12 @@ static void on_port_tested(JsonObject * response, int status, gpointer data) {
_
("Port is <span font_weight=\"bold\" fgcolor=\"red\">closed</span>"));
} else {
- trg_error_dialog(GTK_WINDOW(data), status, response);
+ trg_error_dialog(GTK_WINDOW(data), response);
}
}
- gdk_threads_leave();
- response_unref(response);
+ trg_response_free(response);
+ return FALSE;
}
static void port_test_cb(GtkButton * b, gpointer data) {
@@ -230,35 +228,33 @@ static void port_test_cb(GtkButton * b, gpointer data) {
dispatch_async(priv->client, req, on_port_tested, data);
}
-static void on_blocklist_updated(JsonObject * response, int status,
- gpointer data) {
- gdk_threads_enter();
-
- if (TRG_IS_REMOTE_PREFS_DIALOG(data)) {
+static gboolean on_blocklist_updated(gpointer data) {
+ trg_response *response = (trg_response*)data;
+ if (TRG_IS_REMOTE_PREFS_DIALOG(response->cb_data)) {
TrgRemotePrefsDialogPrivate *priv =
- TRG_REMOTE_PREFS_DIALOG_GET_PRIVATE(data);
+ TRG_REMOTE_PREFS_DIALOG_GET_PRIVATE(response->cb_data);
gtk_widget_set_sensitive(priv->blocklist_update_button, TRUE);
gtk_button_set_label(GTK_BUTTON(priv->blocklist_update_button),
"Update");
- if (status == CURLE_OK) {
- JsonObject *args = get_arguments(response);
+ if (response->status == CURLE_OK) {
+ JsonObject *args = get_arguments(response->obj);
gchar *labelText = g_strdup_printf(_("Blocklist (%ld entries)"),
json_object_get_int_member(args, SGET_BLOCKLIST_SIZE));
gtk_button_set_label(GTK_BUTTON(priv->blocklist_check), labelText);
g_free(labelText);
} else {
- trg_error_dialog(GTK_WINDOW(data), status, response);
+ trg_error_dialog(GTK_WINDOW(response->cb_data), response);
}
}
- gdk_threads_leave();
+ trg_response_free(response);
- response_unref(response);
+ return FALSE;
}
-static void update_blocklist_cb(GtkButton * b, gpointer data) {
+static gboolean update_blocklist_cb(GtkButton * b, gpointer data) {
TrgRemotePrefsDialogPrivate *priv =
TRG_REMOTE_PREFS_DIALOG_GET_PRIVATE(data);
JsonNode *req = blocklist_update();
@@ -267,6 +263,8 @@ static void update_blocklist_cb(GtkButton * b, gpointer data) {
gtk_button_set_label(b, _("Updating..."));
dispatch_async(priv->client, req, on_blocklist_updated, data);
+
+ return FALSE;
}
static GtkWidget *trg_rprefs_connPage(TrgRemotePrefsDialog * win,
diff --git a/src/trg-state-selector.c b/src/trg-state-selector.c
index 4b7f035..beef747 100644
--- a/src/trg-state-selector.c
+++ b/src/trg-state-selector.c
@@ -497,8 +497,6 @@ static GObject *trg_state_selector_constructor(GType type,
gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(object), TRUE);
- gtk_widget_set_size_request(GTK_WIDGET(object), 120, -1);
-
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(object));
g_signal_connect(G_OBJECT(selection), "changed",
diff --git a/src/trg-stats-dialog.c b/src/trg-stats-dialog.c
index 9ecbc28..5688083 100644
--- a/src/trg-stats-dialog.c
+++ b/src/trg-stats-dialog.c
@@ -23,7 +23,6 @@
#include <curl/curl.h>
#include "hig.h"
-#include "dispatch.h"
#include "requests.h"
#include "json.h"
#include "util.h"
@@ -63,8 +62,7 @@ struct _TrgStatsDialogPrivate {
static GObject *instance = NULL;
static gboolean trg_update_stats_timerfunc(gpointer data);
-static void on_stats_reply(JsonObject * response, int status,
- gpointer data);
+static gboolean on_stats_reply(gpointer data);
static void
trg_stats_dialog_get_property(GObject * object, guint property_id,
@@ -87,6 +85,7 @@ trg_stats_dialog_set_property(GObject * object, guint property_id,
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
@@ -188,23 +187,21 @@ static void update_time_stat(JsonObject * args, GtkTreeRowReference * rr,
update_statistic(rr, session_val, cumulat_val);
}
-static void on_stats_reply(JsonObject * response, int status,
- gpointer data)
+static gboolean on_stats_reply(gpointer data)
{
+ trg_response *response = (trg_response*)data;
TrgStatsDialogPrivate *priv;
JsonObject *args;
- if (!TRG_IS_STATS_DIALOG(data)) {
- response_unref(response);
- return;
+ if (!TRG_IS_STATS_DIALOG(response->cb_data)) {
+ trg_response_free(response);
+ return FALSE;
}
- gdk_threads_enter();
-
- priv = TRG_STATS_DIALOG_GET_PRIVATE(data);
+ priv = TRG_STATS_DIALOG_GET_PRIVATE(response->cb_data);
- if (status == CURLE_OK) {
- args = get_arguments(response);
+ if (response->status == CURLE_OK) {
+ args = get_arguments(response->obj);
update_size_stat(args, priv->rr_up, "uploadedBytes");
update_size_stat(args, priv->rr_down, "downloadedBytes");
@@ -215,12 +212,11 @@ static void on_stats_reply(JsonObject * response, int status,
if (trg_client_is_connected(priv->client))
g_timeout_add_seconds(STATS_UPDATE_INTERVAL, trg_update_stats_timerfunc, data);
} else {
- trg_error_dialog(GTK_WINDOW(data), status, response);
+ trg_error_dialog(GTK_WINDOW(data), response);
}
- gdk_threads_leave();
-
- response_unref(response);
+ trg_response_free(response);
+ return FALSE;
}
static gboolean trg_update_stats_timerfunc(gpointer data)
diff --git a/src/trg-torrent-add-dialog.c b/src/trg-torrent-add-dialog.c
index d02b4e6..9dc69b7 100644
--- a/src/trg-torrent-add-dialog.c
+++ b/src/trg-torrent-add-dialog.c
@@ -39,7 +39,6 @@
#include "requests.h"
#include "torrent.h"
#include "json.h"
-#include "dispatch.h"
#include "protocol-constants.h"
enum {
@@ -146,16 +145,14 @@ static gpointer add_files_threadfunc(gpointer data)
JsonNode *request =
torrent_add(fileName, files_thread_data->flags);
JsonObject *args = node_get_arguments(request);
- JsonObject *response;
- gint status;
+ trg_response *response;
if (files_thread_data->extraArgs)
add_set_common_args(args, files_thread_data->priority,
files_thread_data->dir);
- response = dispatch(files_thread_data->client, request, &status);
- on_generic_interactive_action(response, status,
- files_thread_data->cb_data);
+ response = dispatch(files_thread_data->client, request);
+ on_generic_interactive_action(response);
}
g_str_slist_free(files_thread_data->list);
diff --git a/src/trg-torrent-add-url-dialog.c b/src/trg-torrent-add-url-dialog.c
index 0a2908c..ebf211c 100644
--- a/src/trg-torrent-add-url-dialog.c
+++ b/src/trg-torrent-add-url-dialog.c
@@ -26,7 +26,6 @@
#include "trg-torrent-add-url-dialog.h"
#include "hig.h"
#include "requests.h"
-#include "dispatch.h"
G_DEFINE_TYPE(TrgTorrentAddUrlDialog, trg_torrent_add_url_dialog,
GTK_TYPE_DIALOG)
diff --git a/src/trg-torrent-graph.c b/src/trg-torrent-graph.c
index 3f599ae..b5fd187 100644
--- a/src/trg-torrent-graph.c
+++ b/src/trg-torrent-graph.c
@@ -91,6 +91,7 @@ trg_torrent_graph_get_property(GObject * object, guint property_id,
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
@@ -101,6 +102,7 @@ trg_torrent_graph_set_property(GObject * object, guint property_id,
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
@@ -518,8 +520,6 @@ static GObject *trg_torrent_graph_constructor(GType type,
gtk_box_set_homogeneous(GTK_BOX(object), FALSE);
- gtk_widget_set_size_request(GTK_WIDGET(object), -1, GRAPH_MIN_HEIGHT);
-
priv->disp = gtk_drawing_area_new();
g_signal_connect(G_OBJECT(priv->disp), "expose_event",
G_CALLBACK(trg_torrent_graph_expose), object);
diff --git a/src/trg-torrent-move-dialog.c b/src/trg-torrent-move-dialog.c
index b270b4a..d7627b7 100644
--- a/src/trg-torrent-move-dialog.c
+++ b/src/trg-torrent-move-dialog.c
@@ -29,7 +29,6 @@
#include "hig.h"
#include "torrent.h"
#include "requests.h"
-#include "dispatch.h"
G_DEFINE_TYPE(TrgTorrentMoveDialog, trg_torrent_move_dialog,
GTK_TYPE_DIALOG)
diff --git a/src/trg-torrent-props-dialog.c b/src/trg-torrent-props-dialog.c
index 35afb6d..2ce81ec 100644
--- a/src/trg-torrent-props-dialog.c
+++ b/src/trg-torrent-props-dialog.c
@@ -23,7 +23,6 @@
#include "torrent.h"
#include "json.h"
-#include "dispatch.h"
#include "trg-client.h"
#include "trg-json-widgets.h"
#include "requests.h"
diff --git a/src/trg-trackers-tree-view.c b/src/trg-trackers-tree-view.c
index 7f385ba..f4c1e87 100644
--- a/src/trg-trackers-tree-view.c
+++ b/src/trg-trackers-tree-view.c
@@ -27,7 +27,6 @@
#include "trg-client.h"
#include "trg-menu-bar.h"
#include "requests.h"
-#include "dispatch.h"
#include "json.h"
#include "trg-trackers-model.h"
#include "trg-main-window.h"
@@ -56,16 +55,18 @@ static gboolean is_tracker_edit_supported(TrgClient *tc)
return trg_client_get_rpc_version(tc) >= 10;
}
-static void
-on_trackers_update(JsonObject * response, int status, gpointer data)
+static gboolean
+on_trackers_update(gpointer data)
{
+ trg_response *response = (trg_response*)data;
TrgTrackersTreeViewPrivate *priv =
- TRG_TRACKERS_TREE_VIEW_GET_PRIVATE(data);
- GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(data));
+ TRG_TRACKERS_TREE_VIEW_GET_PRIVATE(response->cb_data);
+ GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(response->cb_data));
trg_trackers_model_set_accept(TRG_TRACKERS_MODEL(model), TRUE);
- on_generic_interactive_action(response, status, priv->win);
+ response->cb_data = priv->win;
+ return on_generic_interactive_action(data);
}
void trg_trackers_tree_view_new_connection(TrgTrackersTreeView * tv,
diff --git a/src/util.c b/src/util.c
index 85b3ee5..e37e728 100644
--- a/src/util.c
+++ b/src/util.c
@@ -32,7 +32,6 @@
#include <gtk/gtk.h>
#include "util.h"
-#include "dispatch.h"
void add_file_id_to_array(JsonObject * args, gchar * key, gint index)
{
@@ -70,10 +69,9 @@ gchar *trg_gregex_get_first(GRegex * rx, const gchar * src)
return dst;
}
-void trg_error_dialog(GtkWindow * parent, int status,
- JsonObject * response)
+void trg_error_dialog(GtkWindow * parent, trg_response *response)
{
- const gchar *msg = make_error_message(response, status);
+ gchar *msg = make_error_message(response->obj, response->status);
GtkWidget *dialog = gtk_message_dialog_new(parent,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
@@ -82,7 +80,7 @@ void trg_error_dialog(GtkWindow * parent, int status,
gtk_window_set_title(GTK_WINDOW(dialog), _("Error"));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
- g_free((gpointer) msg);
+ g_free(msg);
}
gchar *make_error_message(JsonObject * response, int status)
@@ -104,12 +102,6 @@ gchar *make_error_message(JsonObject * response, int status)
}
}
-void response_unref(JsonObject * response)
-{
- if (response != NULL)
- json_object_unref(response);
-}
-
char *tr_strlpercent(char *buf, double x, size_t buflen)
{
return tr_strpercent(buf, x, buflen);
diff --git a/src/util.h b/src/util.h
index a859bd0..03d8165 100644
--- a/src/util.h
+++ b/src/util.h
@@ -43,10 +43,8 @@ void add_file_id_to_array(JsonObject * args, gchar * key, gint index);
void g_str_slist_free(GSList * list);
GRegex *trg_uri_host_regex_new(void);
gchar *trg_gregex_get_first(GRegex * rx, const gchar * uri);
-void response_unref(JsonObject * response);
gchar *make_error_message(JsonObject * response, int status);
-void trg_error_dialog(GtkWindow * parent, int status,
- JsonObject * response);
+void trg_error_dialog(GtkWindow * parent, trg_response * response);
char *tr_strltime_long(char *buf, long seconds, size_t buflen);
char *tr_strltime_short(char *buf, long seconds, size_t buflen);