diff options
author | 2011-02-14 19:34:56 +0000 | |
---|---|---|
committer | 2011-02-14 19:34:56 +0000 | |
commit | 3f7785e670e09cfd75a77ccca8031fabc0d432ab (patch) | |
tree | 41ff9eadd2b1eb537568f87a0bfcc3941a4df36a /src | |
parent | 009ef4d4a37ca136c6bd1071fc980c4f164badd9 (diff) |
statistics!
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/http.c | 2 | ||||
-rw-r--r-- | src/protocol-constants.h | 3 | ||||
-rw-r--r-- | src/requests.c | 28 | ||||
-rw-r--r-- | src/requests.h | 6 | ||||
-rw-r--r-- | src/torrent.c | 2 | ||||
-rw-r--r-- | src/trg-client.c | 9 | ||||
-rw-r--r-- | src/trg-client.h | 2 | ||||
-rw-r--r-- | src/trg-files-tree-view.c | 10 | ||||
-rw-r--r-- | src/trg-main-window.c | 557 | ||||
-rw-r--r-- | src/trg-main-window.h | 14 | ||||
-rw-r--r-- | src/trg-menu-bar.c | 15 | ||||
-rw-r--r-- | src/trg-preferences-dialog.c | 34 | ||||
-rw-r--r-- | src/trg-preferences-dialog.h | 2 | ||||
-rw-r--r-- | src/trg-remote-prefs-dialog.c | 2 | ||||
-rw-r--r-- | src/trg-torrent-model.c | 9 | ||||
-rw-r--r-- | src/trg-torrent-model.h | 4 | ||||
-rw-r--r-- | src/trg-torrent-props-dialog.c | 6 | ||||
-rw-r--r-- | src/trg-torrent-tree-view.c | 2 | ||||
-rw-r--r-- | src/util.c | 28 | ||||
-rw-r--r-- | src/util.h | 3 |
21 files changed, 442 insertions, 297 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 260bf2d..ac97ef1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,6 +67,7 @@ transmission_remote_gtk_SOURCES = main.c \ trg-cell-renderer-wanted.c \ trg-cell-renderer-priority.c \ trg-torrent-move-dialog.c \ + trg-stats-dialog.c \ $(NULL) transmission_remote_gtk_LDFLAGS = -lcurl $(jsonglib_LIBS) $(gtk_LIBS) $(gthread_LIBS) $(GEOIP_LIBS) $(gconf_LIBS) $(gio_LIBS) $(unique_LIBS) $(notify_LIBS) @@ -77,7 +77,7 @@ static struct http_response *trg_http_perform_inner(trg_client * tc, curl_easy_setopt(handle, CURLOPT_WRITEHEADER, (void *) tc); curl_easy_setopt(handle, CURLOPT_POSTFIELDS, req); if (tc->ssl) - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); if (tc->session_id != NULL) { headers = curl_slist_append(headers, tc->session_id); diff --git a/src/protocol-constants.h b/src/protocol-constants.h index ea1e917..4d48751 100644 --- a/src/protocol-constants.h +++ b/src/protocol-constants.h @@ -95,6 +95,9 @@ #define METHOD_TORRENT_VERIFY "torrent-verify" #define METHOD_TORRENT_REMOVE "torrent-remove" #define METHOD_TORRENT_ADD "torrent-add" +#define METHOD_PORT_TEST "port-test" +#define METHOD_BLOCKLIST_UPDATE "blocklist-update" +#define METHOD_SESSION_STATS "session-stats" #define PARAM_IDS "ids" #define PARAM_DELETE_LOCAL_DATA "delete-local-data" diff --git a/src/requests.c b/src/requests.c index 3858dd7..221ab5f 100644 --- a/src/requests.c +++ b/src/requests.c @@ -40,18 +40,34 @@ JsonNode *generic_request(gchar * method, JsonArray * ids) return root; } +JsonNode *session_stats() +{ + return generic_request(METHOD_SESSION_STATS, NULL); +} + +JsonNode *blocklist_update() +{ + return generic_request(METHOD_BLOCKLIST_UPDATE, NULL); +} + +JsonNode *port_test() +{ + return generic_request(METHOD_PORT_TEST, NULL); +} + JsonNode *session_get() { return generic_request(METHOD_SESSION_GET, NULL); } -JsonNode *torrent_set_location(JsonArray *array, gchar *location, gboolean move) +JsonNode *torrent_set_location(JsonArray * array, gchar * location, + gboolean move) { - JsonNode *req = generic_request(METHOD_TORRENT_SET_LOCATION, array); - JsonObject *args = node_get_arguments(req); - json_object_set_boolean_member(args, FIELD_MOVE, move); - json_object_set_string_member(args, FIELD_LOCATION, location); - return req; + JsonNode *req = generic_request(METHOD_TORRENT_SET_LOCATION, array); + JsonObject *args = node_get_arguments(req); + json_object_set_boolean_member(args, FIELD_MOVE, move); + json_object_set_string_member(args, FIELD_LOCATION, location); + return req; } JsonNode *torrent_start(JsonArray * array) diff --git a/src/requests.h b/src/requests.h index a490004..b5d8c75 100644 --- a/src/requests.h +++ b/src/requests.h @@ -35,6 +35,10 @@ JsonNode *torrent_verify(JsonArray * array); JsonNode *torrent_remove(JsonArray * array, int removeData); JsonNode *torrent_add(gchar * filename, gboolean paused); JsonNode *torrent_add_url(const gchar * url, gboolean paused); -JsonNode *torrent_set_location(JsonArray *array, gchar *location, gboolean move); +JsonNode *torrent_set_location(JsonArray * array, gchar * location, + gboolean move); +JsonNode *blocklist_update(); +JsonNode *port_test(); +JsonNode *session_stats(); #endif /* REQUESTS_H_ */ diff --git a/src/torrent.c b/src/torrent.c index 29f9e30..9ecb354 100644 --- a/src/torrent.c +++ b/src/torrent.c @@ -51,7 +51,7 @@ gint64 torrent_get_id(JsonObject * t) const gchar *torrent_get_download_dir(JsonObject * t) { - return json_object_get_string_member(t, FIELD_DOWNLOAD_DIR); + return json_object_get_string_member(t, FIELD_DOWNLOAD_DIR); } const gchar *torrent_get_name(JsonObject * t) diff --git a/src/trg-client.c b/src/trg-client.c index b7ac4fd..97462bb 100644 --- a/src/trg-client.c +++ b/src/trg-client.c @@ -37,8 +37,7 @@ trg_client *trg_init_client() #define check_for_error(error) if (error) { g_error_free(error); return TRG_GCONF_SCHEMA_ERROR; } -int trg_client_populate_with_settings(trg_client * tc, - GConfClient * gconf) +int trg_client_populate_with_settings(trg_client * tc, GConfClient * gconf) { gint port; gchar *host; @@ -59,12 +58,14 @@ int trg_client_populate_with_settings(trg_client * tc, host = gconf_client_get_string(gconf, TRG_GCONF_KEY_HOSTNAME, &error); check_for_error(error); if (!host || strlen(host) < 1) - return TRG_NO_HOSTNAME_SET; + return TRG_NO_HOSTNAME_SET; tc->ssl = gconf_client_get_bool(gconf, TRG_GCONF_KEY_SSL, &error); check_for_error(error); - tc->url = g_strdup_printf("%s://%s:%d/transmission/rpc", tc->ssl ? "https" : "http", host, port); + tc->url = + g_strdup_printf("%s://%s:%d/transmission/rpc", + tc->ssl ? "https" : "http", host, port); g_free(host); tc->username = diff --git a/src/trg-client.h b/src/trg-client.h index 4d98420..2fbcad9 100644 --- a/src/trg-client.h +++ b/src/trg-client.h @@ -44,6 +44,6 @@ typedef struct { trg_client *trg_init_client(); int trg_client_populate_with_settings(trg_client * tc, - GConfClient * gconf); + GConfClient * gconf); #endif /* TRG_CLIENT_H_ */ diff --git a/src/trg-files-tree-view.c b/src/trg-files-tree-view.c index c70e990..01d8a7a 100644 --- a/src/trg-files-tree-view.c +++ b/src/trg-files-tree-view.c @@ -69,12 +69,12 @@ static void set_low_foreachfunc(GtkTreeModel * model, GtkTreeIter * iter, gpointer data G_GNUC_UNUSED) { - GValue value = { 0 }; - g_value_init (&value, G_TYPE_INT64); - g_value_set_int64 (&value, T_PRIORITY_LOW); + GValue value = { 0 }; + g_value_init(&value, G_TYPE_INT64); + g_value_set_int64(&value, T_PRIORITY_LOW); - gtk_list_store_set_value(GTK_LIST_STORE(model), iter, FILESCOL_PRIORITY, - &value); + gtk_list_store_set_value(GTK_LIST_STORE(model), iter, + FILESCOL_PRIORITY, &value); } static void set_normal_foreachfunc(GtkTreeModel * model, diff --git a/src/trg-main-window.c b/src/trg-main-window.c index fee7444..0a2f95d 100644 --- a/src/trg-main-window.c +++ b/src/trg-main-window.c @@ -60,72 +60,130 @@ #include "trg-toolbar.h" #include "trg-menu-bar.h" #include "trg-status-bar.h" +#include "trg-stats-dialog.h" #include "trg-remote-prefs-dialog.h" #include "trg-preferences-dialog.h" -static gboolean update_selected_torrent_notebook(TrgMainWindow *win, gboolean first); -static void response_unref(JsonObject *response); -static void torrent_event_notification(TrgTorrentModel *model, gchar *icon, gchar *desc, gint tmout, gchar *prefKey, GtkTreeIter *iter, gpointer *data); -static void on_torrent_completed(TrgTorrentModel *model, GtkTreeIter *iter, gpointer *data); -static void on_torrent_added(TrgTorrentModel *model, GtkTreeIter *iter, gpointer *data); -static gboolean delete_event(GtkWidget *w, GdkEvent *event, gpointer *data); -static void destroy_window(GtkWidget *w, gpointer data); -static const gchar *make_error_message(JsonObject *response, int status); -static void torrent_tv_onRowActivated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *col, gpointer userdata); +static gboolean update_selected_torrent_notebook(TrgMainWindow * win, + gboolean first); +static void torrent_event_notification(TrgTorrentModel * model, + gchar * icon, gchar * desc, + gint tmout, gchar * prefKey, + GtkTreeIter * iter, + gpointer * data); +static void on_torrent_completed(TrgTorrentModel * model, + GtkTreeIter * iter, gpointer * data); +static void on_torrent_added(TrgTorrentModel * model, GtkTreeIter * iter, + gpointer * data); +static gboolean delete_event(GtkWidget * w, GdkEvent * event, + gpointer * data); +static void destroy_window(GtkWidget * w, gpointer data); +static void torrent_tv_onRowActivated(GtkTreeView * treeview, + GtkTreePath * path, + GtkTreeViewColumn * col, + gpointer userdata); static gpointer add_files_threadfunc(gpointer data); -static void add_url_cb(GtkWidget *w, gpointer data); -static void add_cb(GtkWidget *w, gpointer data); -static void disconnect_cb(GtkWidget *w, gpointer data); -static void connect_cb(GtkWidget *w, gpointer data); -static void open_local_prefs_cb(GtkWidget *w, gpointer data); -static void open_remote_prefs_cb(GtkWidget *w, gpointer data); -static TrgToolbar *trg_main_window_toolbar_new(TrgMainWindow *win); -static void verify_cb(GtkWidget *w, gpointer data); -static void pause_cb(GtkWidget *w, gpointer data); -static void resume_cb(GtkWidget *w, gpointer data); -static void remove_cb(GtkWidget *w, gpointer data); -static void move_cb(GtkWidget *w, gpointer data); -static void delete_cb(GtkWidget *w, gpointer data); -static void open_props_cb(GtkWidget *w, gpointer data); -static gint confirm_action_dialog(GtkWindow *win, GtkTreeSelection *selection, gchar *question_single, gchar *question_multi, gchar *action_stock); -static GtkWidget *my_scrolledwin_new(GtkWidget *child); -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_first(JsonObject *response, int status, gpointer data); -static void on_torrent_get(JsonObject *response, int status, gpointer data); +static void add_url_cb(GtkWidget * w, gpointer data); +static void add_cb(GtkWidget * w, gpointer data); +static void disconnect_cb(GtkWidget * w, gpointer data); +static void connect_cb(GtkWidget * w, gpointer data); +static void open_local_prefs_cb(GtkWidget * w, gpointer data); +static void open_remote_prefs_cb(GtkWidget * w, gpointer data); +static TrgToolbar *trg_main_window_toolbar_new(TrgMainWindow * win); +static void verify_cb(GtkWidget * w, gpointer data); +static void pause_cb(GtkWidget * w, gpointer data); +static void resume_cb(GtkWidget * w, gpointer data); +static void remove_cb(GtkWidget * w, gpointer data); +static void move_cb(GtkWidget * w, gpointer data); +static void delete_cb(GtkWidget * w, gpointer data); +static void open_props_cb(GtkWidget * w, gpointer data); +static gint confirm_action_dialog(GtkWindow * win, + GtkTreeSelection * selection, + gchar * question_single, + gchar * question_multi, + gchar * action_stock); +static GtkWidget *my_scrolledwin_new(GtkWidget * child); +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_first(JsonObject * response, int status, + gpointer data); +static void on_torrent_get(JsonObject * response, int status, + gpointer data); static gboolean trg_update_torrents_timerfunc(gpointer data); -static void trg_main_window_update_notebook_displays(TrgMainWindow *win, JsonObject *t, GtkTreeIter *iter, gboolean first); -static void open_about_cb(GtkWidget *w, GtkWindow *parent); -static gboolean trg_torrent_tree_view_visible_func(GtkTreeModel *model, GtkTreeIter *iter, gpointer data); -static TrgTorrentTreeView *trg_main_window_torrent_tree_view_new(TrgMainWindow *win, GtkTreeModel *model, TrgStateSelector *selector); -static gboolean trg_dialog_error_handler(TrgMainWindow *win, JsonObject *response, int status); -static gboolean torrent_selection_changed(GtkWidget *w, gpointer data); -static void trg_main_window_torrent_scrub(TrgMainWindow *win); -static void on_torrent_get_multipurpose(JsonObject *response, gboolean first, int status, gpointer data); -static void entry_filter_changed_cb(GtkWidget *w, gpointer data); -static void torrent_state_selection_changed(TrgStateSelector *selector, guint flag, gpointer data); -static void trg_main_window_conn_changed(TrgMainWindow *win, gboolean connected); -static void trg_main_window_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void trg_main_window_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); -static void quit_cb(GtkWidget *w, gpointer data); -static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow *win); -static void status_icon_activated(GtkStatusIcon *icon, gpointer data); -static void clear_filter_entry_cb(GtkWidget *w, gpointer data); -static gboolean torrent_tv_key_press_event(GtkWidget *w, GdkEventKey *key, gpointer data); -static GtkWidget *trg_imagemenuitem_new(GtkMenuShell *shell, char *text, char *stock_id, gboolean sensitive, GCallback cb, gpointer cbdata); -static void set_limit_cb(GtkWidget *w, gpointer data); -static GtkWidget *limit_item_new(TrgMainWindow *win, GtkWidget *menu, gint64 currentLimit, gint limit); -static GtkWidget *limit_menu_new(TrgMainWindow *win, gchar *title, gchar *enabledKey, gchar *speedKey, JsonArray *ids); -static void trg_torrent_tv_view_menu(GtkWidget *treeview, GdkEventButton *event, gpointer data); -static void trg_status_icon_view_menu(GtkStatusIcon *icon, GdkEventButton *event, gpointer data); -static gboolean trg_status_icon_popup_menu_cb(GtkStatusIcon *icon, gpointer userdata); -static gboolean status_icon_button_press_event(GtkStatusIcon *icon, GdkEventButton *event, gpointer data); -static gboolean torrent_tv_button_pressed_cb(GtkWidget *treeview, GdkEventButton *event, gpointer userdata); -static gboolean torrent_tv_popup_menu_cb(GtkWidget *treeview, gpointer userdata); -static void status_bar_text_pushed(GtkStatusbar *statusbar, guint context_id, gchar *text, gpointer user_data); -static gboolean window_state_event(GtkWidget *widget, GdkEventWindowState *event, gpointer trayIcon); +static void trg_main_window_update_notebook_displays(TrgMainWindow * win, + JsonObject * t, + GtkTreeIter * iter, + gboolean first); +static void open_about_cb(GtkWidget * w, GtkWindow * parent); +static gboolean trg_torrent_tree_view_visible_func(GtkTreeModel * model, + GtkTreeIter * iter, + gpointer data); +static TrgTorrentTreeView + *trg_main_window_torrent_tree_view_new(TrgMainWindow * win, + GtkTreeModel * model, + TrgStateSelector * selector); +static gboolean trg_dialog_error_handler(TrgMainWindow * win, + JsonObject * response, + int status); +static gboolean torrent_selection_changed(GtkWidget * w, gpointer data); +static void trg_main_window_torrent_scrub(TrgMainWindow * win); +static void on_torrent_get_multipurpose(JsonObject * response, + gboolean first, int status, + gpointer data); +static void entry_filter_changed_cb(GtkWidget * w, gpointer data); +static void torrent_state_selection_changed(TrgStateSelector * selector, + guint flag, gpointer data); +static void trg_main_window_conn_changed(TrgMainWindow * win, + gboolean connected); +static void trg_main_window_get_property(GObject * object, + guint property_id, GValue * value, + GParamSpec * pspec); +static void trg_main_window_set_property(GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec); +static void quit_cb(GtkWidget * w, gpointer data); +static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win); +static void status_icon_activated(GtkStatusIcon * icon, gpointer data); +static void clear_filter_entry_cb(GtkWidget * w, gpointer data); +static gboolean torrent_tv_key_press_event(GtkWidget * w, + GdkEventKey * key, + gpointer data); +static GtkWidget *trg_imagemenuitem_new(GtkMenuShell * shell, char *text, + char *stock_id, gboolean sensitive, + GCallback cb, gpointer cbdata); +static void set_limit_cb(GtkWidget * w, gpointer data); +static GtkWidget *limit_item_new(TrgMainWindow * win, GtkWidget * menu, + gint64 currentLimit, gint limit); +static GtkWidget *limit_menu_new(TrgMainWindow * win, gchar * title, + gchar * enabledKey, gchar * speedKey, + JsonArray * ids); +static void trg_torrent_tv_view_menu(GtkWidget * treeview, + GdkEventButton * event, + gpointer data); +static void trg_status_icon_view_menu(GtkStatusIcon * icon, + GdkEventButton * event, + gpointer data); +static gboolean trg_status_icon_popup_menu_cb(GtkStatusIcon * icon, + gpointer userdata); +static gboolean status_icon_button_press_event(GtkStatusIcon * icon, + GdkEventButton * event, + gpointer data); +static gboolean torrent_tv_button_pressed_cb(GtkWidget * treeview, + GdkEventButton * event, + gpointer userdata); +static gboolean torrent_tv_popup_menu_cb(GtkWidget * treeview, + gpointer userdata); +static void status_bar_text_pushed(GtkStatusbar * statusbar, + guint context_id, gchar * text, + gpointer user_data); +static gboolean window_state_event(GtkWidget * widget, + GdkEventWindowState * event, + gpointer trayIcon); G_DEFINE_TYPE(TrgMainWindow, trg_main_window, GTK_TYPE_WINDOW) #define TRG_MAIN_WINDOW_GET_PRIVATE(o) \ @@ -199,15 +257,10 @@ static gboolean update_selected_torrent_notebook(TrgMainWindow * win, return FALSE; } -static void response_unref(JsonObject * response) -{ - if (response != NULL) - json_object_unref(response); -} - static void torrent_event_notification(TrgTorrentModel * model, - gchar *icon, gchar *desc, gint tmout, - gchar *prefKey, GtkTreeIter * iter, gpointer * data) + gchar * icon, gchar * desc, + gint tmout, gchar * prefKey, + GtkTreeIter * iter, gpointer * data) { TrgMainWindowPrivate *priv; gchar *name; @@ -220,17 +273,14 @@ static void torrent_event_notification(TrgTorrentModel * model, return; if (!gconf_client_get_bool(priv->client->gconf, prefKey, NULL)) - return; + return; gtk_tree_model_get(GTK_TREE_MODEL(model), iter, TORRENT_COLUMN_NAME, &name, -1); - notify = - notify_notification_new(name, - desc, - icon + notify = notify_notification_new(name, desc, icon #if !defined(NOTIFY_VERSION_MINOR) || (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7) - , NULL + , NULL #endif ); @@ -249,15 +299,17 @@ static void torrent_event_notification(TrgTorrentModel * model, static void on_torrent_completed(TrgTorrentModel * model, GtkTreeIter * iter, gpointer * data) { - torrent_event_notification(model, GTK_STOCK_APPLY, "This torrent has completed.", - 8000, TRG_GCONF_KEY_COMPLETE_NOTIFY, iter, data); + torrent_event_notification(model, GTK_STOCK_APPLY, + "This torrent has completed.", 8000, + TRG_GCONF_KEY_COMPLETE_NOTIFY, iter, data); } static void on_torrent_added(TrgTorrentModel * model, - GtkTreeIter * iter, gpointer * data) + GtkTreeIter * iter, gpointer * data) { - torrent_event_notification(model, GTK_STOCK_ADD, "This torrent has been added.", - 3000, TRG_GCONF_KEY_ADD_NOTIFY, iter, data); + torrent_event_notification(model, GTK_STOCK_ADD, + "This torrent has been added.", 3000, + TRG_GCONF_KEY_ADD_NOTIFY, iter, data); } static gboolean delete_event(GtkWidget * w, @@ -281,25 +333,6 @@ destroy_window(GtkWidget * w G_GNUC_UNUSED, gpointer data G_GNUC_UNUSED) gtk_main_quit(); } -static const gchar *make_error_message(JsonObject * response, int status) -{ - if (status == FAIL_JSON_DECODE) { - return g_strdup("JSON decoding error."); - } else if (status == FAIL_RESPONSE_UNSUCCESSFUL) { - const gchar *resultStr = - json_object_get_string_member(response, "result"); - if (resultStr == NULL) - return g_strdup("Server responded, but with no result."); - else - return g_strdup(resultStr); - } else if (status <= -100) { - return g_strdup_printf("Request failed with HTTP code %d", - -(status + 100)); - } else { - return g_strdup(curl_easy_strerror(status)); - } -} - static void open_props_cb(GtkWidget * w, gpointer data) { TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); @@ -312,12 +345,12 @@ static void open_props_cb(GtkWidget * w, gpointer data) } static void -torrent_tv_onRowActivated (GtkTreeView *treeview, - GtkTreePath *path G_GNUC_UNUSED, - GtkTreeViewColumn *col G_GNUC_UNUSED, - gpointer userdata) +torrent_tv_onRowActivated(GtkTreeView * treeview, + GtkTreePath * path G_GNUC_UNUSED, + GtkTreeViewColumn * col G_GNUC_UNUSED, + gpointer userdata) { - open_props_cb(GTK_WIDGET(treeview), userdata); + open_props_cb(GTK_WIDGET(treeview), userdata); } /* Use synchronous dispatch() in our dedicated thread function. @@ -458,23 +491,25 @@ static void connect_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) int populate_result; priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); - populate_result = trg_client_populate_with_settings(priv->client, priv->client->gconf); + populate_result = + trg_client_populate_with_settings(priv->client, + priv->client->gconf); if (populate_result < 0) { - gchar *msg; - - switch(populate_result) - { - case TRG_GCONF_SCHEMA_ERROR: - msg = "Unable to retrieve connection settings from GConf. Schema not installed?"; - break; - case TRG_NO_HOSTNAME_SET: - msg = "No hostname set"; - break; - default: - msg = "Unknown error getting settings"; - break; - } + gchar *msg; + + switch (populate_result) { + case TRG_GCONF_SCHEMA_ERROR: + msg = + "Unable to retrieve connection settings from GConf. Schema not installed?"; + break; + case TRG_NO_HOSTNAME_SET: + msg = "No hostname set"; + break; + default: + msg = "Unknown error getting settings"; + break; + } @@ -482,8 +517,7 @@ static void connect_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) gtk_message_dialog_new(GTK_WINDOW(data), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "%s", msg); + GTK_BUTTONS_OK, "%s", msg); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); @@ -498,9 +532,9 @@ static void open_local_prefs_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) { TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); - GtkWidget *dlg = trg_preferences_dialog_get_instance(TRG_MAIN_WINDOW(data), - priv-> - client->gconf); + GtkWidget *dlg = + trg_preferences_dialog_get_instance(TRG_MAIN_WINDOW(data), + priv->client->gconf); gtk_widget_show_all(dlg); } @@ -631,7 +665,9 @@ static gint confirm_action_dialog(GtkWindow * win, static void move_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) { TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); - TrgTorrentMoveDialog *dlg = trg_torrent_move_dialog_new(TRG_MAIN_WINDOW(data), priv->client, priv->torrentTreeView); + TrgTorrentMoveDialog *dlg = + trg_torrent_move_dialog_new(TRG_MAIN_WINDOW(data), priv->client, + priv->torrentTreeView); gtk_widget_show_all(GTK_WIDGET(dlg)); } @@ -656,7 +692,7 @@ static void remove_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) FALSE), on_generic_interactive_action, data); else - json_array_unref(ids); + json_array_unref(ids); } static void delete_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) @@ -681,7 +717,7 @@ static void delete_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) TRUE), on_generic_interactive_action, data); else - json_array_unref(ids); + json_array_unref(ids); } static @@ -695,6 +731,16 @@ GtkWidget *my_scrolledwin_new(GtkWidget * child) return scrolled_win; } +static void view_stats_toggled_cb(GtkWidget * w, gpointer data) +{ + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); + + TrgStatsDialog *dlg = + trg_stats_dialog_get_instance(TRG_MAIN_WINDOW(data), priv->client); + + gtk_widget_show_all(GTK_WIDGET(dlg)); +} + static void view_states_toggled_cb(GtkCheckMenuItem * w, gpointer data) { TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); @@ -1128,7 +1174,7 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win) GObject *b_connect, *b_disconnect, *b_add, *b_resume, *b_pause, *b_verify, *b_remove, *b_delete, *b_props, *b_local_prefs, *b_remote_prefs, *b_about, *b_view_states, *b_view_notebook, - *b_add_url, *b_quit, *b_move; + *b_view_stats, *b_add_url, *b_quit, *b_move; TrgMenuBar *menuBar; menuBar = trg_menu_bar_new(win); @@ -1148,6 +1194,7 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win) "local-prefs-button", &b_local_prefs, "view-notebook-button", &b_view_notebook, "view-states-button", &b_view_states, + "view-stats-button", &b_view_stats, "about-button", &b_about, "quit-button", &b_quit, NULL); g_signal_connect(b_connect, "activate", G_CALLBACK(connect_cb), win); @@ -1170,6 +1217,8 @@ static TrgMenuBar *trg_main_window_menu_bar_new(TrgMainWindow * win) G_CALLBACK(view_notebook_toggled_cb), win); g_signal_connect(b_view_states, "toggled", G_CALLBACK(view_states_toggled_cb), win); + g_signal_connect(b_view_stats, "activate", + G_CALLBACK(view_stats_toggled_cb), win); g_signal_connect(b_props, "activate", G_CALLBACK(open_props_cb), win); g_signal_connect(b_quit, "activate", G_CALLBACK(quit_cb), win); @@ -1220,111 +1269,116 @@ GtkWidget *trg_imagemenuitem_new(GtkMenuShell * shell, char *text, return item; } -static void set_limit_cb(GtkWidget *w, gpointer data) +static void set_limit_cb(GtkWidget * w, gpointer data) { - TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); - GtkWidget *parent = gtk_widget_get_parent(w); + GtkWidget *parent = gtk_widget_get_parent(w); - gint speed = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), "limit")); - gchar *speedKey = g_object_get_data(G_OBJECT(parent), "speedKey"); - gchar *enabledKey = g_object_get_data(G_OBJECT(parent), "enabledKey"); - gpointer limitIds = g_object_get_data(G_OBJECT(parent), "limit-ids"); + gint speed = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), "limit")); + gchar *speedKey = g_object_get_data(G_OBJECT(parent), "speedKey"); + gchar *enabledKey = g_object_get_data(G_OBJECT(parent), "enabledKey"); + gpointer limitIds = g_object_get_data(G_OBJECT(parent), "limit-ids"); - JsonNode *req = NULL; - JsonObject *args; - if (limitIds == NULL) { - req = session_set(); - } else { - req = torrent_set((JsonArray*)limitIds); - } + JsonNode *req = NULL; + JsonObject *args; + if (limitIds == NULL) { + req = session_set(); + } else { + req = torrent_set((JsonArray *) limitIds); + } - args = node_get_arguments(req); + args = node_get_arguments(req); - if (speed >= 0) - json_object_set_int_member(args, speedKey, speed); + if (speed >= 0) + json_object_set_int_member(args, speedKey, speed); - json_object_set_boolean_member(args, enabledKey, speed >= 0); + json_object_set_boolean_member(args, enabledKey, speed >= 0); - if (limitIds == NULL) - dispatch_async(priv->client, req, on_session_set, data); - else - dispatch_async(priv->client, req, on_generic_interactive_action, data); + if (limitIds == NULL) + dispatch_async(priv->client, req, on_session_set, data); + else + dispatch_async(priv->client, req, on_generic_interactive_action, + data); } -static GtkWidget *limit_item_new(TrgMainWindow *win, GtkWidget *menu, - gint64 currentLimit, gint limit) +static GtkWidget *limit_item_new(TrgMainWindow * win, GtkWidget * menu, + gint64 currentLimit, gint limit) { - char speed[32]; - GtkWidget *item; - gboolean active = limit < 0 ? FALSE : (currentLimit == (gint64)limit); + char speed[32]; + GtkWidget *item; + gboolean active = limit < 0 ? FALSE : (currentLimit == (gint64) limit); - g_snprintf(speed, sizeof(speed), "%d KB/s", limit); - item = gtk_check_menu_item_new_with_label (speed); + g_snprintf(speed, sizeof(speed), "%d KB/s", limit); + item = gtk_check_menu_item_new_with_label(speed); - g_object_set_data(G_OBJECT(item), "limit", GINT_TO_POINTER(limit)); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), active); - g_signal_connect(item, "activate", G_CALLBACK(set_limit_cb), win); + g_object_set_data(G_OBJECT(item), "limit", GINT_TO_POINTER(limit)); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), active); + g_signal_connect(item, "activate", G_CALLBACK(set_limit_cb), win); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - return item; + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + return item; } -static GtkWidget *limit_menu_new(TrgMainWindow *win, gchar *title, gchar *enabledKey, gchar *speedKey, JsonArray *ids) +static GtkWidget *limit_menu_new(TrgMainWindow * win, gchar * title, + gchar * enabledKey, gchar * speedKey, + JsonArray * ids) { - TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); - JsonObject *current = NULL; - GtkTreeIter iter; - GtkWidget *toplevel, *menu, *item; - gint64 limit; + JsonObject *current = NULL; + GtkTreeIter iter; + GtkWidget *toplevel, *menu, *item; + gint64 limit; - if (ids == NULL) - current = priv->client->session; - else - get_first_selected(priv->client, priv->torrentTreeView, &iter, - ¤t); + if (ids == NULL) + current = priv->client->session; + else + get_first_selected(priv->client, priv->torrentTreeView, &iter, + ¤t); - limit = json_object_get_boolean_member(current, enabledKey) ? - json_object_get_int_member(current, speedKey) : -1; - toplevel = gtk_image_menu_item_new_with_label(GTK_STOCK_NETWORK); + limit = json_object_get_boolean_member(current, enabledKey) ? + json_object_get_int_member(current, speedKey) : -1; + toplevel = gtk_image_menu_item_new_with_label(GTK_STOCK_NETWORK); gtk_image_menu_item_set_use_stock(GTK_IMAGE_MENU_ITEM(toplevel), TRUE); gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM (toplevel), TRUE); gtk_menu_item_set_label(GTK_MENU_ITEM(toplevel), title); - menu = gtk_menu_new(); + menu = gtk_menu_new(); g_object_set_data_full(G_OBJECT(menu), "speedKey", - g_strdup(speedKey), g_free); + g_strdup(speedKey), g_free); g_object_set_data_full(G_OBJECT(menu), "enabledKey", - g_strdup(enabledKey), g_free); - g_object_set_data_full(G_OBJECT(menu), "limit-ids", ids, (GDestroyNotify)json_array_unref); + g_strdup(enabledKey), g_free); + g_object_set_data_full(G_OBJECT(menu), "limit-ids", ids, + (GDestroyNotify) json_array_unref); - item = gtk_check_menu_item_new_with_label("No Limit"); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), limit < 0); - g_object_set_data(G_OBJECT(item), "limit", GINT_TO_POINTER(-1)); - g_signal_connect(item, "activate", G_CALLBACK(set_limit_cb), win); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + item = gtk_check_menu_item_new_with_label("No Limit"); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), limit < 0); + g_object_set_data(G_OBJECT(item), "limit", GINT_TO_POINTER(-1)); + g_signal_connect(item, "activate", G_CALLBACK(set_limit_cb), win); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), + gtk_separator_menu_item_new()); - limit_item_new(win, menu, limit, 0); - limit_item_new(win, menu, limit, 5); - limit_item_new(win, menu, limit, 10); - limit_item_new(win, menu, limit, 25); - limit_item_new(win, menu, limit, 50); - limit_item_new(win, menu, limit, 75); - limit_item_new(win, menu, limit, 100); - limit_item_new(win, menu, limit, 150); - limit_item_new(win, menu, limit, 200); - limit_item_new(win, menu, limit, 300); - limit_item_new(win, menu, limit, 400); - limit_item_new(win, menu, limit, 500); + limit_item_new(win, menu, limit, 0); + limit_item_new(win, menu, limit, 5); + limit_item_new(win, menu, limit, 10); + limit_item_new(win, menu, limit, 25); + limit_item_new(win, menu, limit, 50); + limit_item_new(win, menu, limit, 75); + limit_item_new(win, menu, limit, 100); + limit_item_new(win, menu, limit, 150); + limit_item_new(win, menu, limit, 200); + limit_item_new(win, menu, limit, 300); + limit_item_new(win, menu, limit, 400); + limit_item_new(win, menu, limit, 500); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(toplevel), menu); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(toplevel), menu); - return toplevel; + return toplevel; } static void @@ -1358,8 +1412,15 @@ trg_torrent_tv_view_menu(GtkWidget * treeview, GTK_STOCK_DELETE, TRUE, G_CALLBACK(delete_cb), data); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), limit_menu_new(TRG_MAIN_WINDOW(data), "Down Limit", FIELD_DOWNLOAD_LIMITED, FIELD_DOWNLOAD_LIMIT, ids)); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), limit_menu_new(TRG_MAIN_WINDOW(data), "Up Limit", FIELD_UPLOAD_LIMITED, FIELD_UPLOAD_LIMIT, ids)); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), + limit_menu_new(TRG_MAIN_WINDOW(data), + "Down Limit", + FIELD_DOWNLOAD_LIMITED, + FIELD_DOWNLOAD_LIMIT, ids)); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), + limit_menu_new(TRG_MAIN_WINDOW(data), "Up Limit", + FIELD_UPLOAD_LIMITED, + FIELD_UPLOAD_LIMIT, ids)); gtk_widget_show_all(menu); @@ -1379,25 +1440,34 @@ trg_status_icon_view_menu(GtkStatusIcon * icon G_GNUC_UNUSED, menu = gtk_menu_new(); if (!connected) { - trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Connect", - GTK_STOCK_CONNECT, !connected, - G_CALLBACK(connect_cb), data); + trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Connect", + GTK_STOCK_CONNECT, !connected, + G_CALLBACK(connect_cb), data); } else { - trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Disconnect", - GTK_STOCK_DISCONNECT, connected, - G_CALLBACK(disconnect_cb), data); - - trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Add", GTK_STOCK_ADD, - connected, G_CALLBACK(add_cb), data); - trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Add from URL", - GTK_STOCK_ADD, connected, G_CALLBACK(add_url_cb), - data); - - gtk_menu_shell_append(GTK_MENU_SHELL(menu), limit_menu_new(TRG_MAIN_WINDOW(data), "Down Limit", SGET_SPEED_LIMIT_DOWN_ENABLED, SGET_SPEED_LIMIT_DOWN, NULL)); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), limit_menu_new(TRG_MAIN_WINDOW(data), "Up Limit", SGET_SPEED_LIMIT_UP_ENABLED, SGET_SPEED_LIMIT_UP, NULL)); + trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Disconnect", + GTK_STOCK_DISCONNECT, connected, + G_CALLBACK(disconnect_cb), data); + + trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Add", GTK_STOCK_ADD, + connected, G_CALLBACK(add_cb), data); + trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Add from URL", + GTK_STOCK_ADD, connected, + G_CALLBACK(add_url_cb), data); + + gtk_menu_shell_append(GTK_MENU_SHELL(menu), + limit_menu_new(TRG_MAIN_WINDOW(data), + "Down Limit", + SGET_SPEED_LIMIT_DOWN_ENABLED, + SGET_SPEED_LIMIT_DOWN, NULL)); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), + limit_menu_new(TRG_MAIN_WINDOW(data), + "Up Limit", + SGET_SPEED_LIMIT_UP_ENABLED, + SGET_SPEED_LIMIT_UP, NULL)); } - gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), + gtk_separator_menu_item_new()); trg_imagemenuitem_new(GTK_MENU_SHELL(menu), "Quit", GTK_STOCK_QUIT, TRUE, G_CALLBACK(quit_cb), data); @@ -1485,10 +1555,9 @@ static gboolean window_state_event(GtkWidget * widget, || event->new_window_state == (GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED))) { GError *error = NULL; - gboolean tray_min = - gconf_client_get_bool(priv->client->gconf, - TRG_GCONF_KEY_SYSTEM_TRAY_MINIMISE, - &error); + gboolean tray_min = gconf_client_get_bool(priv->client->gconf, + TRG_GCONF_KEY_SYSTEM_TRAY_MINIMISE, + &error); if (error) { g_error_free(error); @@ -1502,33 +1571,32 @@ static gboolean window_state_event(GtkWidget * widget, return TRUE; } -void trg_main_window_remove_status_icon(TrgMainWindow *win) +void trg_main_window_remove_status_icon(TrgMainWindow * win) { - TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); - if (priv->statusIcon != NULL) - g_object_unref(G_OBJECT(priv->statusIcon)); + if (priv->statusIcon != NULL) + g_object_unref(G_OBJECT(priv->statusIcon)); - priv->statusIcon = NULL; + priv->statusIcon = NULL; } -void trg_main_window_add_status_icon(TrgMainWindow *win) +void trg_main_window_add_status_icon(TrgMainWindow * win) { - TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); - if (priv->icon == NULL) - return; + if (priv->icon == NULL) + return; - priv->statusIcon = gtk_status_icon_new_from_pixbuf(priv->icon); - gtk_status_icon_set_screen(priv->statusIcon, - gtk_window_get_screen(GTK_WINDOW - (win))); - g_signal_connect(priv->statusIcon, "activate", - G_CALLBACK(status_icon_activated), win); - g_signal_connect(priv->statusIcon, "button-press-event", - G_CALLBACK(status_icon_button_press_event), win); - g_signal_connect(priv->statusIcon, "popup-menu", - G_CALLBACK(trg_status_icon_popup_menu_cb), win); + priv->statusIcon = gtk_status_icon_new_from_pixbuf(priv->icon); + gtk_status_icon_set_screen(priv->statusIcon, + gtk_window_get_screen(GTK_WINDOW(win))); + g_signal_connect(priv->statusIcon, "activate", + G_CALLBACK(status_icon_activated), win); + g_signal_connect(priv->statusIcon, "button-press-event", + G_CALLBACK(status_icon_button_press_event), win); + g_signal_connect(priv->statusIcon, "popup-menu", + G_CALLBACK(trg_status_icon_popup_menu_cb), win); } static GObject *trg_main_window_constructor(GType type, @@ -1598,7 +1666,8 @@ static GObject *trg_main_window_constructor(GType type, G_CALLBACK(torrent_tv_popup_menu_cb), self); g_signal_connect(priv->torrentTreeView, "button-press-event", G_CALLBACK(torrent_tv_button_pressed_cb), self); - g_signal_connect(priv->torrentTreeView, "row-activated", G_CALLBACK(torrent_tv_onRowActivated), self); + g_signal_connect(priv->torrentTreeView, "row-activated", + G_CALLBACK(torrent_tv_onRowActivated), self); outerVbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(self), outerVbox); @@ -1675,9 +1744,9 @@ static GObject *trg_main_window_constructor(GType type, } if (tray) { - trg_main_window_add_status_icon(self); + trg_main_window_add_status_icon(self); } else { - priv->statusIcon = NULL; + priv->statusIcon = NULL; } priv->statusBar = trg_status_bar_new(); diff --git a/src/trg-main-window.h b/src/trg-main-window.h index bf8df6e..e563088 100644 --- a/src/trg-main-window.h +++ b/src/trg-main-window.h @@ -54,14 +54,14 @@ typedef struct { } TrgMainWindowClass; GType trg_main_window_get_type(void); -gboolean trg_add_from_filename(TrgMainWindow *win, gchar *fileName); -void on_session_set(JsonObject *response, int status, gpointer data); -void on_generic_interactive_action(JsonObject *response, int status, gpointer data); -void auto_connect_if_required(TrgMainWindow *win, trg_client *tc); +gboolean trg_add_from_filename(TrgMainWindow * win, gchar * fileName); +void on_session_set(JsonObject * response, int status, gpointer data); +void on_generic_interactive_action(JsonObject * response, int status, + gpointer data); +void auto_connect_if_required(TrgMainWindow * win, trg_client * tc); TrgMainWindow *trg_main_window_new(trg_client * tc); -void trg_main_window_add_status_icon(TrgMainWindow *win); -void trg_main_window_remove_status_icon(TrgMainWindow *win); +void trg_main_window_add_status_icon(TrgMainWindow * win); +void trg_main_window_remove_status_icon(TrgMainWindow * win); G_END_DECLS - #endif /* MAIN_WINDOW_H_ */ diff --git a/src/trg-menu-bar.c b/src/trg-menu-bar.c index 61f5be3..ddd2626 100644 --- a/src/trg-menu-bar.c +++ b/src/trg-menu-bar.c @@ -37,6 +37,7 @@ enum { PROP_REMOTE_PREFS_BUTTON, PROP_LOCAL_PREFS_BUTTON, PROP_ABOUT_BUTTON, + PROP_VIEW_STATS_BUTTON, PROP_VIEW_STATES_BUTTON, PROP_VIEW_NOTEBOOK_BUTTON, PROP_QUIT @@ -63,6 +64,7 @@ struct _TrgMenuBarPrivate { GtkWidget *mb_remote_prefs; GtkWidget *mb_view_states; GtkWidget *mb_view_notebook; + GtkWidget *mb_view_stats; GtkWidget *mb_about; GtkWidget *mb_quit; }; @@ -76,6 +78,7 @@ void trg_menu_bar_connected_change(TrgMenuBar * mb, gboolean connected) gtk_widget_set_sensitive(priv->mb_connect, !connected); gtk_widget_set_sensitive(priv->mb_disconnect, connected); gtk_widget_set_sensitive(priv->mb_remote_prefs, connected); + gtk_widget_set_sensitive(priv->mb_view_stats, connected); } void trg_menu_bar_torrent_actions_sensitive(TrgMenuBar * mb, @@ -146,6 +149,9 @@ trg_menu_bar_get_property(GObject * object, guint property_id, case PROP_VIEW_NOTEBOOK_BUTTON: g_value_set_object(value, priv->mb_view_notebook); break; + case PROP_VIEW_STATS_BUTTON: + g_value_set_object(value, priv->mb_view_stats); + break; case PROP_QUIT: g_value_set_object(value, priv->mb_quit); break; @@ -206,9 +212,12 @@ static GtkWidget *trg_menu_bar_view_menu_new(TrgMenuBarPrivate * priv) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM (priv->mb_view_notebook), TRUE); + priv->mb_view_stats = gtk_menu_item_new_with_label("Statistics"); + gtk_menu_shell_append(GTK_MENU_SHELL(viewMenu), priv->mb_view_states); gtk_menu_shell_append(GTK_MENU_SHELL(viewMenu), priv->mb_view_notebook); + gtk_menu_shell_append(GTK_MENU_SHELL(viewMenu), priv->mb_view_stats); return view; } @@ -280,7 +289,7 @@ GtkWidget *trg_menu_bar_torrent_menu_new(TrgMenuBarPrivate * priv) GTK_STOCK_REFRESH, FALSE); priv->mb_move = trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), "Move", - GTK_STOCK_HARDDISK, FALSE); + GTK_STOCK_HARDDISK, FALSE); priv->mb_remove = trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), "Remove", GTK_STOCK_REMOVE, FALSE); @@ -343,6 +352,10 @@ static void trg_menu_bar_class_init(TrgMenuBarClass * klass) 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, + "view-stats-button", + "View stats button"); + trg_menu_bar_install_widget_prop(object_class, PROP_VIEW_STATES_BUTTON, "view-states-button", "View states Button"); diff --git a/src/trg-preferences-dialog.c b/src/trg-preferences-dialog.c index 9964353..15616af 100644 --- a/src/trg-preferences-dialog.c +++ b/src/trg-preferences-dialog.c @@ -59,7 +59,8 @@ trg_preferences_dialog_set_property(GObject * object, const GValue * value, GParamSpec * pspec G_GNUC_UNUSED) { - TrgPreferencesDialogPrivate *priv = TRG_PREFERENCES_DIALOG_GET_PRIVATE(object); + TrgPreferencesDialogPrivate *priv = + TRG_PREFERENCES_DIALOG_GET_PRIVATE(object); switch (prop_id) { case PROP_GCONF_CLIENT: @@ -88,7 +89,8 @@ trg_preferences_dialog_get_property(GObject * object, GValue * value, GParamSpec * pspec G_GNUC_UNUSED) { - TrgPreferencesDialogPrivate *priv = TRG_PREFERENCES_DIALOG_GET_PRIVATE(object); + TrgPreferencesDialogPrivate *priv = + TRG_PREFERENCES_DIALOG_GET_PRIVATE(object); switch (prop_id) { case PROP_GCONF_CLIENT: @@ -197,13 +199,14 @@ static GtkWidget *new_entry(GConfClient * gconf, const char *key) static void toggle_tray_icon(GtkToggleButton * w, gpointer win) { - if (gtk_toggle_button_get_active(w)) - trg_main_window_add_status_icon(TRG_MAIN_WINDOW(win)); - else - trg_main_window_remove_status_icon(TRG_MAIN_WINDOW(win)); + if (gtk_toggle_button_get_active(w)) + trg_main_window_add_status_icon(TRG_MAIN_WINDOW(win)); + else + trg_main_window_remove_status_icon(TRG_MAIN_WINDOW(win)); } -static GtkWidget *trg_prefs_desktopPage(GConfClient * gconf, TrgMainWindow *win) +static GtkWidget *trg_prefs_desktopPage(GConfClient * gconf, + TrgMainWindow * win) { GtkWidget *tray, *w, *t; gint row = 0; @@ -214,11 +217,12 @@ static GtkWidget *trg_prefs_desktopPage(GConfClient * gconf, TrgMainWindow *win) tray = new_check_button(gconf, "Show in system tray", TRG_GCONF_KEY_SYSTEM_TRAY); - g_signal_connect(G_OBJECT(tray), "toggled", G_CALLBACK(toggle_tray_icon), win); + g_signal_connect(G_OBJECT(tray), "toggled", + G_CALLBACK(toggle_tray_icon), win); hig_workarea_add_wide_control(t, &row, tray); w = new_check_button(gconf, "Minimise to system tray", - TRG_GCONF_KEY_SYSTEM_TRAY_MINIMISE); + TRG_GCONF_KEY_SYSTEM_TRAY_MINIMISE); gtk_widget_set_sensitive(w, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (tray))); @@ -227,7 +231,7 @@ static GtkWidget *trg_prefs_desktopPage(GConfClient * gconf, TrgMainWindow *win) hig_workarea_add_wide_control(t, &row, w); w = new_check_button(gconf, "Torrent added notifications", - TRG_GCONF_KEY_ADD_NOTIFY); + TRG_GCONF_KEY_ADD_NOTIFY); gtk_widget_set_sensitive(w, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (tray))); @@ -236,7 +240,7 @@ static GtkWidget *trg_prefs_desktopPage(GConfClient * gconf, TrgMainWindow *win) hig_workarea_add_wide_control(t, &row, w); w = new_check_button(gconf, "Torrent complete notifications", - TRG_GCONF_KEY_COMPLETE_NOTIFY); + TRG_GCONF_KEY_COMPLETE_NOTIFY); gtk_widget_set_sensitive(w, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (tray))); @@ -266,8 +270,7 @@ static GtkWidget *trg_prefs_serverPage(GConfClient * gconf) TRG_GCONF_KEY_AUTO_CONNECT); hig_workarea_add_wide_control(t, &row, w); - w = new_check_button(gconf, "SSL", - TRG_GCONF_KEY_SSL); + w = new_check_button(gconf, "SSL", TRG_GCONF_KEY_SSL); hig_workarea_add_wide_control(t, &row, w); hig_workarea_add_section_divider(t, &row); @@ -300,7 +303,8 @@ static GObject *trg_preferences_dialog_constructor(GType type, construct_params); priv = TRG_PREFERENCES_DIALOG_GET_PRIVATE(object); - gtk_window_set_transient_for(GTK_WINDOW(object), GTK_WINDOW(priv->win)); + gtk_window_set_transient_for(GTK_WINDOW(object), + GTK_WINDOW(priv->win)); gtk_window_set_destroy_with_parent(GTK_WINDOW(object), TRUE); gtk_dialog_add_button(GTK_DIALOG(object), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); @@ -375,7 +379,7 @@ static void trg_preferences_dialog_init(TrgPreferencesDialog * pref_dlg) { } -GtkWidget *trg_preferences_dialog_get_instance(TrgMainWindow *win, +GtkWidget *trg_preferences_dialog_get_instance(TrgMainWindow * win, GConfClient * client) { if (instance == NULL) { diff --git a/src/trg-preferences-dialog.h b/src/trg-preferences-dialog.h index 49791a5..04c8c3c 100644 --- a/src/trg-preferences-dialog.h +++ b/src/trg-preferences-dialog.h @@ -49,7 +49,7 @@ struct _TrgPreferencesDialogClass { GType trg_preferences_dialog_get_type(void); -GtkWidget *trg_preferences_dialog_get_instance(TrgMainWindow *win, +GtkWidget *trg_preferences_dialog_get_instance(TrgMainWindow * win, GConfClient * client); G_END_DECLS #endif /* TRG_PREFERENCES_WINDOW_H_ */ diff --git a/src/trg-remote-prefs-dialog.c b/src/trg-remote-prefs-dialog.c index 7f90709..c27fc35 100644 --- a/src/trg-remote-prefs-dialog.c +++ b/src/trg-remote-prefs-dialog.c @@ -32,7 +32,7 @@ G_DEFINE_TYPE(TrgRemotePrefsDialog, trg_remote_prefs_dialog, GTK_TYPE_DIALOG) #define TRG_REMOTE_PREFS_DIALOG_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRG_TYPE_REMOTE_PREFS_DIALOG, TrgRemotePrefsDialogPrivate)) +(G_TYPE_INSTANCE_GET_PRIVATE ((o), TRG_TYPE_REMOTE_PREFS_DIALOG, TrgRemotePrefsDialogPrivate)) enum { PROP_0, PROP_PARENT, diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c index a3c9398..3d7d85f 100644 --- a/src/trg-torrent-model.c +++ b/src/trg-torrent-model.c @@ -329,10 +329,11 @@ void trg_torrent_model_update(TrgTorrentModel * model, trg_client * tc, gtk_list_store_append(GTK_LIST_STORE(model), &iter); update_torrent_iter(tc->updateSerial, model, &iter, t, stats); if (!first) - g_signal_emit(model, signals[TMODEL_TORRENT_ADDED], 0, &iter); - } else { - update_torrent_iter(tc->updateSerial, model, &iter, t, stats); - } + g_signal_emit(model, signals[TMODEL_TORRENT_ADDED], 0, + &iter); + } else { + update_torrent_iter(tc->updateSerial, model, &iter, t, stats); + } } json_array_ref(newTorrents); diff --git a/src/trg-torrent-model.h b/src/trg-torrent-model.h index 962a2f0..2c11dd0 100644 --- a/src/trg-torrent-model.h +++ b/src/trg-torrent-model.h @@ -48,8 +48,8 @@ typedef struct { GtkTreeIter * iter, JsonObject * t, gpointer data); void (*torrent_added) (TrgTorrentModel * model, - GtkTreeIter * iter, JsonObject * t, - gpointer data); + GtkTreeIter * iter, JsonObject * t, + gpointer data); } TrgTorrentModelClass; typedef struct { diff --git a/src/trg-torrent-props-dialog.c b/src/trg-torrent-props-dialog.c index 827e643..477b15f 100644 --- a/src/trg-torrent-props-dialog.c +++ b/src/trg-torrent-props-dialog.c @@ -137,10 +137,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-torrent-tree-view.c b/src/trg-torrent-tree-view.c index e33e718..b68bead 100644 --- a/src/trg-torrent-tree-view.c +++ b/src/trg-torrent-tree-view.c @@ -36,7 +36,7 @@ static void trg_torrent_tree_view_init(TrgTorrentTreeView * tv) { trg_tree_view_add_pixbuf_text_column(TRG_TREE_VIEW(tv), TORRENT_COLUMN_ICON, - TORRENT_COLUMN_NAME, "Name", -1); + TORRENT_COLUMN_NAME, "Name", 300); trg_tree_view_add_size_column(TRG_TREE_VIEW(tv), "Size", TORRENT_COLUMN_SIZE, -1); trg_tree_view_add_prog_column(TRG_TREE_VIEW(tv), "Done", @@ -24,11 +24,39 @@ #include <string.h> #include <glib-object.h> +#include <curl/curl.h> +#include <json-glib/json-glib.h> #include <glib.h> #include <glib/gprintf.h> #include <gtk/gtk.h> #include "util.h" +#include "dispatch.h" + +const gchar *make_error_message(JsonObject * response, int status) +{ + if (status == FAIL_JSON_DECODE) { + return g_strdup("JSON decoding error."); + } else if (status == FAIL_RESPONSE_UNSUCCESSFUL) { + const gchar *resultStr = + json_object_get_string_member(response, "result"); + if (resultStr == NULL) + return g_strdup("Server responded, but with no result."); + else + return g_strdup(resultStr); + } else if (status <= -100) { + return g_strdup_printf("Request failed with HTTP code %d", + -(status + 100)); + } else { + return g_strdup(curl_easy_strerror(status)); + } +} + +void response_unref(JsonObject * response) +{ + if (response != NULL) + json_object_unref(response); +} char *tr_strlpercent(char *buf, double x, size_t buflen) { @@ -23,6 +23,7 @@ #define UTIL_H_ #include <glib-object.h> +#include <json-glib/json-glib.h> #define trg_strlspeed(a, b) tr_strlspeed(a, b, sizeof(a)) #define trg_strlpercent(a, b) tr_strlpercent(a, b, sizeof(a)) @@ -52,5 +53,7 @@ size_t tr_strlcpy(char *dst, const void *src, size_t siz); double tr_truncd(double x, int decimal_places); int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap); +void response_unref(JsonObject * response); +const gchar *make_error_message(JsonObject * response, int status); #endif /* UTIL_H_ */ |