summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac2
-rw-r--r--debian/changelog6
-rw-r--r--freebsd/Makefile2
-rw-r--r--redhat/transmission-remote-gtk.spec7
-rw-r--r--src/main.c4
-rw-r--r--src/trg-files-tree-view.c64
-rw-r--r--src/trg-main-window.c13
-rw-r--r--src/trg-peers-tree-view.c42
-rw-r--r--src/trg-torrent-add-dialog.c4
-rw-r--r--src/trg-torrent-move-dialog.c11
-rw-r--r--src/trg-torrent-props-dialog.c6
-rw-r--r--src/trg-torrent-tree-view.c74
-rw-r--r--src/trg-trackers-tree-view.c38
-rw-r--r--src/trg-tree-view.c398
-rw-r--r--src/trg-tree-view.h58
-rw-r--r--src/util.c12
16 files changed, 434 insertions, 307 deletions
diff --git a/configure.ac b/configure.ac
index d0b749e..e001cd2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
AC_PREREQ(2.63)
-AC_INIT(transmission-remote-gtk, 0.4, alan@eth0.org.uk)
+AC_INIT(transmission-remote-gtk, 0.4.1, alan@eth0.org.uk)
AC_CONFIG_SRCDIR(src)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AM_INIT_AUTOMAKE([foreign])
diff --git a/debian/changelog b/debian/changelog
index ffd59ec..ead35bf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+transmission-remote-gtk (0.4.1-1) unstable; urgency=low
+
+ * Fixes.
+
+ -- Alan Fitton <alan@eth0.org.uk> Fri, 22 Apr 2011 23:45:30 +0100
+
transmission-remote-gtk (0.4-1) unstable; urgency=low
* Initial release
diff --git a/freebsd/Makefile b/freebsd/Makefile
index ea9e40a..63d39f6 100644
--- a/freebsd/Makefile
+++ b/freebsd/Makefile
@@ -6,7 +6,7 @@
#
PORTNAME= transmission-remote-gtk
-PORTVERSION= 0.3
+PORTVERSION= 0.4.1
CATEGORIES= net-p2p
MASTER_SITES= ${MASTER_SITE_GOOGLE_CODE}
diff --git a/redhat/transmission-remote-gtk.spec b/redhat/transmission-remote-gtk.spec
index d24f2de..3a3ab31 100644
--- a/redhat/transmission-remote-gtk.spec
+++ b/redhat/transmission-remote-gtk.spec
@@ -1,5 +1,5 @@
Name: transmission-remote-gtk
-Version: 0.4
+Version: 0.4.1
Release: 1%{?dist:%{dist}}
Summary: Remote control client for Transmission BitTorrent
@@ -95,6 +95,11 @@ fi
%{_datadir}/locale/ru/LC_MESSAGES/%{name}.mo
%changelog
+* Fri Apr 22 2011 Alan Fitton <alan@eth0.org.uk> - 0.4.1
+- Fix a few of small memory leaks.
+- Sync single torrent when file/trackers are changed.
+- Update efficiency improvement.
+
* Tue Apr 12 2011 Alan Fitton <alan@eth0.org.uk> - 0.4
- Torrent add dialog.
- Support for active only updates.
diff --git a/src/main.c b/src/main.c
index 2183b94..0065db7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -107,12 +107,12 @@ int main(int argc, char *argv[])
gchar **files = g_new0(gchar *, argc);
int i;
for (i = 1; i < argc; i++)
- files[i - 1] = g_strdup(argv[i]);
+ files[i - 1] = argv[i];
command = COMMAND_ADD;
message = unique_message_data_new();
unique_message_data_set_uris(message, files);
- g_strfreev(files);
+ g_free(files);
} else {
command = UNIQUE_ACTIVATE;
message = NULL;
diff --git a/src/trg-files-tree-view.c b/src/trg-files-tree-view.c
index fdc6a1c..0c61f10 100644
--- a/src/trg-files-tree-view.c
+++ b/src/trg-files-tree-view.c
@@ -280,58 +280,34 @@ static gboolean view_onPopupMenu(GtkWidget * treeview, gpointer userdata)
return TRUE;
}
-static void trg_files_tree_view_add_priority_column(TrgTreeView * tv,
- char *title, int index,
- int width)
-{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
-
- renderer = trg_cell_renderer_priority_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "priority-value",
- index, NULL);
-
- trg_tree_view_std_column_setup(column, index, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
-}
-
-static void trg_files_tree_view_add_wanted_column(TrgTreeView * tv,
- char *title, int index,
- int width)
-{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
-
- renderer = trg_cell_renderer_wanted_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "wanted-value",
- index, NULL);
-
- trg_tree_view_std_column_setup(column, index, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
-}
-
static void trg_files_tree_view_init(TrgFilesTreeView * self)
{
- trg_tree_view_add_pixbuf_text_column(TRG_TREE_VIEW(self),
- FILESCOL_ICON, FILESCOL_NAME,
- _("Name"), -1);
- trg_tree_view_add_size_column(TRG_TREE_VIEW(self), _("Size"),
- FILESCOL_SIZE, -1);
- trg_tree_view_add_prog_column(TRG_TREE_VIEW(self), _("Progress"),
- FILESCOL_PROGRESS, -1);
- trg_files_tree_view_add_wanted_column(TRG_TREE_VIEW(self), _("Wanted"),
- FILESCOL_WANTED, -1);
- trg_files_tree_view_add_priority_column(TRG_TREE_VIEW(self),
- _("Priority"),
- FILESCOL_PRIORITY, -1);
+ TrgTreeView *ttv = TRG_TREE_VIEW(self);
+ trg_column_description *desc;
+
+ desc =
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_ICONTEXT, FILESCOL_NAME,
+ _("Name"), "name", 1);
+ desc->model_column_icon = FILESCOL_ICON;
+ desc->defaultWidth = 300;
+
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_SIZE, FILESCOL_SIZE,
+ _("Size"), "size", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_PROG, FILESCOL_PROGRESS,
+ _("Progress"), "progress", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_WANT, FILESCOL_WANTED,
+ _("Wanted"), "wanted", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_PRIO, FILESCOL_PRIORITY,
+ _("Priority"), "priority", 1);
+
gtk_tree_view_set_search_column(GTK_TREE_VIEW(self), FILESCOL_NAME);
g_signal_connect(self, "button-press-event",
G_CALLBACK(view_onButtonPressed), NULL);
g_signal_connect(self, "popup-menu", G_CALLBACK(view_onPopupMenu),
NULL);
+
+ trg_tree_view_setup_columns(ttv);
}
TrgFilesTreeView *trg_files_tree_view_new(TrgFilesModel * model,
diff --git a/src/trg-main-window.c b/src/trg-main-window.c
index accc00d..3bacab5 100644
--- a/src/trg-main-window.c
+++ b/src/trg-main-window.c
@@ -33,6 +33,7 @@
#include <gdk/gdkkeysyms.h>
#include <curl/curl.h>
#include <libnotify/notify.h>
+#include <gconf/gconf-client.h>
#include "dispatch.h"
#include "trg-client.h"
@@ -354,6 +355,10 @@ static gboolean delete_event(GtkWidget * w,
height, NULL);
gconf_client_set_int(priv->client->gconf, TRG_GCONF_KEY_WINDOW_WIDTH,
width, NULL);
+ 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));
+ trg_tree_view_persist(TRG_TREE_VIEW(priv->trackersTreeView));
return FALSE;
}
@@ -998,10 +1003,10 @@ static gboolean trg_update_torrents_timerfunc(gpointer data)
if (priv->client->session)
dispatch_async(priv->client,
- torrent_get(priv->client->
- activeOnlyUpdate ? -2 : -1),
- priv->
- client->activeOnlyUpdate ? on_torrent_get_active :
+ torrent_get(priv->
+ client->activeOnlyUpdate ? -2 : -1),
+ priv->client->
+ activeOnlyUpdate ? on_torrent_get_active :
on_torrent_get_update, data);
return FALSE;
diff --git a/src/trg-peers-tree-view.c b/src/trg-peers-tree-view.c
index bf0b541..f2da8dd 100644
--- a/src/trg-peers-tree-view.c
+++ b/src/trg-peers-tree-view.c
@@ -42,28 +42,34 @@ trg_peers_tree_view_class_init(TrgPeersTreeViewClass * klass G_GNUC_UNUSED)
static void trg_peers_tree_view_init(TrgPeersTreeView * self)
{
- trg_tree_view_add_pixbuf_text_column(TRG_TREE_VIEW
- (self),
- PEERSCOL_ICON,
- PEERSCOL_IP, _("IP"), 160);
- trg_tree_view_add_column_fixed_width(TRG_TREE_VIEW(self), _("Host"),
- PEERSCOL_HOST, 250);
+ TrgTreeView *ttv = TRG_TREE_VIEW(self);
+ trg_column_description *desc;
+
+ desc =
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_ICONTEXT, PEERSCOL_ICON,
+ _("IP"), "ip", 1);
+ desc->model_column_icon = PEERSCOL_ICON;
+
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, PEERSCOL_HOST,
+ _("Host"), "host", 1);
+
#ifdef HAVE_GEOIP
- trg_tree_view_add_column(TRG_TREE_VIEW(self), _("Country"),
- PEERSCOL_COUNTRY);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, PEERSCOL_COUNTRY,
+ _("Country"), "country", 1);
#endif
- trg_tree_view_add_speed_column(TRG_TREE_VIEW(self), _("Down Speed"),
- PEERSCOL_DOWNSPEED, -1);
- trg_tree_view_add_speed_column(TRG_TREE_VIEW(self), _("Up Speed"),
- PEERSCOL_UPSPEED, -1);
- trg_tree_view_add_prog_column(TRG_TREE_VIEW(self), _("Progress"),
- PEERSCOL_PROGRESS, -1);
- trg_tree_view_add_column(TRG_TREE_VIEW(self), _("Flags"),
- PEERSCOL_FLAGS);
- trg_tree_view_add_column(TRG_TREE_VIEW(self), _("Client"),
- PEERSCOL_CLIENT);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_SPEED, PEERSCOL_DOWNSPEED,
+ _("Down Speed"), "down-speed", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_SPEED, PEERSCOL_UPSPEED,
+ _("Up Speed"), "up-speed", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_PROG, PEERSCOL_PROGRESS,
+ _("Progress"), "progress", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, PEERSCOL_FLAGS,
+ _("Flags"), "flags", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, PEERSCOL_CLIENT,
+ _("Client"), "client", 1);
gtk_tree_view_set_search_column(GTK_TREE_VIEW(self), PEERSCOL_HOST);
+ trg_tree_view_setup_columns(ttv);
}
TrgPeersTreeView *trg_peers_tree_view_new(TrgPeersModel * model)
diff --git a/src/trg-torrent-add-dialog.c b/src/trg-torrent-add-dialog.c
index cd6308f..148aca8 100644
--- a/src/trg-torrent-add-dialog.c
+++ b/src/trg-torrent-add-dialog.c
@@ -890,8 +890,8 @@ static GObject *trg_torrent_add_dialog_constructor(GType type,
priv->paused_check =
gtk_check_button_new_with_mnemonic(_("Start _paused"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->paused_check),
- pref_get_start_paused(priv->
- client->gconf));
+ pref_get_start_paused(priv->client->
+ gconf));
priv->priority_combo = gtr_priority_combo_new();
gtk_combo_box_set_active(GTK_COMBO_BOX(priv->priority_combo), 1);
diff --git a/src/trg-torrent-move-dialog.c b/src/trg-torrent-move-dialog.c
index bd0bd1c..f9bfb62 100644
--- a/src/trg-torrent-move-dialog.c
+++ b/src/trg-torrent-move-dialog.c
@@ -55,6 +55,7 @@ trg_torrent_move_response_cb(GtkDialog * dlg, gint res_id, gpointer data)
{
TrgTorrentMoveDialogPrivate *priv =
TRG_TORRENT_MOVE_DIALOG_GET_PRIVATE(dlg);
+
if (res_id == GTK_RESPONSE_ACCEPT) {
gchar *location =
gtk_combo_box_get_active_text(GTK_COMBO_BOX
@@ -140,22 +141,18 @@ TrgTorrentMoveDialog *trg_torrent_move_dialog_new(TrgMainWindow * win,
(GTK_TREE_VIEW(ttv)));
if (count == 1) {
- GtkTreeIter iter;
JsonObject *json;
- gchar *name;
+ const gchar *name;
const gchar *current_location;
get_torrent_data(client->torrentTable,
- trg_mw_get_selected_torrent_id(win), &json,
- &iter);
- gtk_tree_model_get(trg_main_window_get_torrent_model(priv->win),
- &iter, TORRENT_COLUMN_NAME, &name, -1);
+ trg_mw_get_selected_torrent_id(win), &json, NULL);
+ name = torrent_get_name(json);
current_location = torrent_get_download_dir(json);
gtk_combo_box_append_text(GTK_COMBO_BOX(priv->location_combo),
current_location);
gtk_combo_box_set_active(GTK_COMBO_BOX(priv->location_combo), 0);
msg = g_strdup_printf(_("Move %s"), name);
- g_free(name);
} else {
msg = g_strdup_printf(_("Move %d torrents"), count);
}
diff --git a/src/trg-torrent-props-dialog.c b/src/trg-torrent-props-dialog.c
index 5d11a99..8f83ffd 100644
--- a/src/trg-torrent-props-dialog.c
+++ b/src/trg-torrent-props-dialog.c
@@ -138,12 +138,10 @@ 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 1aa3e56..76f4c83 100644
--- a/src/trg-torrent-tree-view.c
+++ b/src/trg-torrent-tree-view.c
@@ -33,38 +33,52 @@ trg_torrent_tree_view_class_init(TrgTorrentTreeViewClass *
{
}
-static void trg_torrent_tree_view_init(TrgTorrentTreeView * tv)
+static void trg_torrent_tree_view_init(TrgTorrentTreeView * tttv)
{
- trg_tree_view_add_pixbuf_text_column(TRG_TREE_VIEW(tv),
- TORRENT_COLUMN_ICON,
- TORRENT_COLUMN_NAME, _("Name"),
- -1);
- 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"),
- TORRENT_COLUMN_DONE, 70);
- trg_tree_view_add_column(TRG_TREE_VIEW(tv), _("Status"),
- TORRENT_COLUMN_STATUS);
- trg_tree_view_add_column(TRG_TREE_VIEW(tv), _("Seeds"),
- TORRENT_COLUMN_SEEDS);
- trg_tree_view_add_column(TRG_TREE_VIEW(tv), _("Leechers"),
- TORRENT_COLUMN_LEECHERS);
- trg_tree_view_add_speed_column(TRG_TREE_VIEW(tv), _("Down Speed"),
- TORRENT_COLUMN_DOWNSPEED, -1);
- trg_tree_view_add_speed_column(TRG_TREE_VIEW(tv), _("Up Speed"),
- TORRENT_COLUMN_UPSPEED, -1);
- trg_tree_view_add_eta_column(TRG_TREE_VIEW(tv), _("ETA"),
- TORRENT_COLUMN_ETA, -1);
- trg_tree_view_add_size_column(TRG_TREE_VIEW(tv), _("Uploaded"),
- TORRENT_COLUMN_UPLOADED, -1);
- trg_tree_view_add_size_column(TRG_TREE_VIEW(tv), _("Downloaded"),
- TORRENT_COLUMN_DOWNLOADED, -1);
- trg_tree_view_add_ratio_column(TRG_TREE_VIEW(tv), _("Ratio"),
- TORRENT_COLUMN_RATIO, -1);
- trg_tree_view_add_epoch_column(TRG_TREE_VIEW(tv), _("Added"),
- TORRENT_COLUMN_ADDED, -1);
- gtk_tree_view_set_search_column(GTK_TREE_VIEW(tv),
+ TrgTreeView *ttv = TRG_TREE_VIEW(tttv);
+ trg_column_description *desc;
+
+ desc =
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_ICONTEXT,
+ TORRENT_COLUMN_NAME, _("Name"), "name",
+ 1);
+ desc->model_column_icon = TORRENT_COLUMN_ICON;
+ desc->defaultWidth = 250;
+
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_SIZE, TORRENT_COLUMN_SIZE,
+ _("Size"), "size", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_PROG, TORRENT_COLUMN_DONE,
+ _("Done"), "done", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, TORRENT_COLUMN_STATUS,
+ _("Status"), "status", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, TORRENT_COLUMN_SEEDS,
+ _("Seeds"), "seeds", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT,
+ TORRENT_COLUMN_LEECHERS, _("Leechers"),
+ "leechers", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_SPEED,
+ TORRENT_COLUMN_DOWNSPEED, _("Down Speed"),
+ "down-speed", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_SPEED,
+ TORRENT_COLUMN_UPSPEED, _("Up Speed"),
+ "up-speed", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_ETA, TORRENT_COLUMN_ETA,
+ _("ETA"), "eta", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_SIZE,
+ TORRENT_COLUMN_UPLOADED, _("Uploaded"),
+ "uploaded", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_SIZE,
+ TORRENT_COLUMN_DOWNLOADED, _("Downloaded"),
+ "downloaded", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_RATIO, TORRENT_COLUMN_RATIO,
+ _("Ratio"), "ratio", 1);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_EPOCH, TORRENT_COLUMN_ADDED,
+ _("Added"), "added", 1);
+
+ gtk_tree_view_set_search_column(GTK_TREE_VIEW(tttv),
TORRENT_COLUMN_NAME);
+
+ trg_tree_view_setup_columns(ttv);
}
static void
diff --git a/src/trg-trackers-tree-view.c b/src/trg-trackers-tree-view.c
index c650b28..8b07818 100644
--- a/src/trg-trackers-tree-view.c
+++ b/src/trg-trackers-tree-view.c
@@ -147,12 +147,20 @@ static void trg_trackers_tree_view_init(TrgTrackersTreeView * self)
{
TrgTrackersTreeViewPrivate *priv =
TRG_TRACKERS_TREE_VIEW_GET_PRIVATE(self);
-
- trg_tree_view_add_pixbuf_text_column(TRG_TREE_VIEW(self),
- TRACKERCOL_ICON,
- TRACKERCOL_TIER, _("Tier"), -1);
-
- priv->announceRenderer = gtk_cell_renderer_text_new();
+ TrgTreeView *ttv = TRG_TREE_VIEW(self);
+ trg_column_description *desc;
+
+ desc =
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_ICONTEXT,
+ TRACKERCOL_TIER, _("Tier"), "tier", -1);
+ desc->model_column_icon = TRACKERCOL_ICON;
+
+ desc =
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT,
+ TRACKERCOL_ANNOUNCE, _("Announce URL"),
+ "announce-url", -1);
+ priv->announceRenderer = desc->customRenderer =
+ gtk_cell_renderer_text_new();
g_signal_connect(priv->announceRenderer, "edited",
G_CALLBACK(trg_tracker_announce_edited), self);
g_signal_connect(priv->announceRenderer, "editing-canceled",
@@ -161,20 +169,12 @@ static void trg_trackers_tree_view_init(TrgTrackersTreeView * self)
g_signal_connect(priv->announceRenderer, "editing-started",
G_CALLBACK(trg_tracker_announce_editing_started),
self);
+ desc->out = &priv->announceColumn;
- priv->announceColumn =
- gtk_tree_view_column_new_with_attributes(_("Announce URL"),
- priv->announceRenderer,
- "text",
- TRACKERCOL_ANNOUNCE,
- NULL);
-
- trg_tree_view_std_column_setup(priv->announceColumn,
- TRACKERCOL_ANNOUNCE, -1);
- gtk_tree_view_append_column(GTK_TREE_VIEW(self), priv->announceColumn);
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, TRACKERCOL_SCRAPE,
+ _("Scrape URL"), "scrape-url", 1);
- trg_tree_view_add_column(TRG_TREE_VIEW(self), _("Scrape URL"),
- TRACKERCOL_SCRAPE);
+ trg_tree_view_setup_columns(ttv);
}
static void add_tracker(GtkWidget * w, gpointer data)
@@ -214,7 +214,7 @@ static void delete_tracker(GtkWidget * w, gpointer data)
for (li = selectionRefs; li; li = g_list_next(li)) {
GtkTreeRowReference *rr = (GtkTreeRowReference *) li->data;
GtkTreePath *path = gtk_tree_row_reference_get_path(rr);
- if (path != NULL) {
+ if (path) {
gint64 trackerId;
GtkTreeIter trackerIter;
gtk_tree_model_get_iter(model, &trackerIter, path);
diff --git a/src/trg-tree-view.c b/src/trg-tree-view.c
index d828d0e..42e7343 100644
--- a/src/trg-tree-view.c
+++ b/src/trg-tree-view.c
@@ -17,7 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <stdlib.h>
#include <gtk/gtk.h>
+#include <gconf/gconf-client.h>
#include "trg-tree-view.h"
#include "trg-cell-renderer-speed.h"
@@ -25,190 +27,306 @@
#include "trg-cell-renderer-ratio.h"
#include "trg-cell-renderer-eta.h"
#include "trg-cell-renderer-epoch.h"
+#include "trg-cell-renderer-wanted.h"
+#include "trg-cell-renderer-priority.h"
G_DEFINE_TYPE(TrgTreeView, trg_tree_view, GTK_TYPE_TREE_VIEW)
-
-GList *trg_tree_view_get_selected_refs_list(GtkTreeView * tv)
+#define TRG_TREE_VIEW_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRG_TYPE_TREE_VIEW, TrgTreeViewPrivate))
+typedef struct _TrgTreeViewPrivate TrgTreeViewPrivate;
+
+struct _TrgTreeViewPrivate {
+ GList *columns;
+};
+
+trg_column_description *trg_tree_view_reg_column(TrgTreeView * tv,
+ gint type,
+ gint model_column,
+ gchar * header,
+ gchar * id, gint show)
{
- GtkTreeModel *model = gtk_tree_view_get_model(tv);
- GtkTreeSelection *selection = gtk_tree_view_get_selection(tv);
- GList *li, *selectionList;
- GList *refList = NULL;
+ TrgTreeViewPrivate *priv = TRG_TREE_VIEW_GET_PRIVATE(tv);
+ trg_column_description *desc = g_new0(trg_column_description, 1);
- selectionList = gtk_tree_selection_get_selected_rows(selection, NULL);
- for (li = selectionList; li != NULL; li = g_list_next(li)) {
- GtkTreePath *path = (GtkTreePath *) li->data;
- GtkTreeRowReference *ref = gtk_tree_row_reference_new(model, path);
- gtk_tree_path_free(path);
- refList = g_list_append(refList, ref);
- }
- g_list_free(selectionList);
-
- return refList;
-}
-
-void trg_tree_view_std_column_setup(GtkTreeViewColumn * column, int index,
- int width)
-{
- gtk_tree_view_column_set_resizable(column, TRUE);
- gtk_tree_view_column_set_reorderable(column, TRUE);
- gtk_tree_view_column_set_sort_column_id(column, index);
+ desc->type = type;
+ desc->model_column = model_column;
+ desc->header = g_strdup(header);
+ desc->id = g_strdup(id);
+ desc->show = show;
- if (width > 0) {
- gtk_tree_view_column_set_sizing(column,
- GTK_TREE_VIEW_COLUMN_FIXED);
- gtk_tree_view_column_set_fixed_width(column, width);
- }
-}
+ priv->columns = g_list_append(priv->columns, desc);
-static void
-trg_tree_view_class_init(TrgTreeViewClass * klass G_GNUC_UNUSED)
-{
+ return desc;
}
-static void trg_tree_view_init(TrgTreeView * tv)
+static trg_column_description *trg_tree_view_find_column(TrgTreeView * tv,
+ gchar * id)
{
- gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(tv), TRUE);
- gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(tv), TRUE);
- gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tv), TRUE);
- gtk_tree_selection_set_mode(gtk_tree_view_get_selection
- (GTK_TREE_VIEW(tv)),
- GTK_SELECTION_MULTIPLE);
+ TrgTreeViewPrivate *priv = TRG_TREE_VIEW_GET_PRIVATE(tv);
+ GList *li;
+ trg_column_description *desc;
+
+ for (li = priv->columns; li; li = g_list_next(li)) {
+ desc = (trg_column_description *) li->data;
+ if (!g_strcmp0(desc->id, id))
+ return desc;
+ }
- gtk_widget_set_sensitive(GTK_WIDGET(tv), FALSE);
+ return NULL;
}
-void trg_tree_view_add_size_column(TrgTreeView * tv, char *title,
- int index, int width)
+static gchar **trg_gconf_get_csv(TrgTreeView * tv, gchar * key)
{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
+ gchar **ret = NULL;
+ GConfClient *gcc = gconf_client_get_default();
+ gchar *gconf_key =
+ g_strdup_printf("/apps/transmission-remote-gtk/%s-%s",
+ G_OBJECT_TYPE_NAME(tv), key);
+ gchar *gconf_value = gconf_client_get_string(gcc, gconf_key, NULL);
+
+ if (gconf_value) {
+ ret = g_strsplit(gconf_value, ",", -1);
+ g_free(gconf_value);
+ }
- renderer = trg_cell_renderer_size_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "size-value",
- index, NULL);
+ g_free(gconf_key);
+ g_object_unref(gcc);
- trg_tree_view_std_column_setup(column, index, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
+ return ret;
}
-void trg_tree_view_add_eta_column(TrgTreeView * tv, char *title, int index,
- int width)
+static void trg_tree_view_add_column(TrgTreeView * tv,
+ trg_column_description * desc,
+ gchar ** widths, gint i)
{
GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
-
- renderer = trg_cell_renderer_eta_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "eta-value",
- index, NULL);
+ GtkTreeViewColumn *column = NULL;
+
+ switch (desc->type) {
+ case TRG_COLTYPE_TEXT:
+ renderer =
+ desc->customRenderer ? desc->
+ customRenderer : gtk_cell_renderer_text_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer, "text",
+ desc->model_column,
+ NULL);
+
+ break;
+ case TRG_COLTYPE_SPEED:
+ renderer = trg_cell_renderer_speed_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer,
+ "speed-value",
+ desc->model_column,
+ NULL);
+ break;
+ case TRG_COLTYPE_EPOCH:
+ renderer = trg_cell_renderer_epoch_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer,
+ "epoch-value",
+ desc->model_column,
+ NULL);
+ break;
+ case TRG_COLTYPE_ETA:
+ renderer = trg_cell_renderer_eta_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer, "eta-value",
+ desc->model_column,
+ NULL);
+ break;
+ case TRG_COLTYPE_SIZE:
+ renderer = trg_cell_renderer_size_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer,
+ "size-value",
+ desc->model_column,
+ NULL);
+ break;
+ case TRG_COLTYPE_PROG:
+ renderer = gtk_cell_renderer_progress_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer, "value",
+ desc->model_column,
+ NULL);
+ break;
+ case TRG_COLTYPE_RATIO:
+ renderer = trg_cell_renderer_ratio_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer,
+ "ratio-value",
+ desc->model_column,
+ NULL);
+ break;
+ case TRG_COLTYPE_ICONTEXT:
+ column = gtk_tree_view_column_new();
+
+ renderer = gtk_cell_renderer_pixbuf_new();
+ gtk_tree_view_column_set_title(column, desc->header);
+ gtk_tree_view_column_pack_start(column, renderer, FALSE);
+ gtk_tree_view_column_set_attributes(column, renderer, "stock-id",
+ desc->model_column_icon, NULL);
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_column_pack_start(column, renderer, TRUE);
+ gtk_tree_view_column_set_attributes(column, renderer, "text",
+ desc->model_column, NULL);
+ break;
+ case TRG_COLTYPE_WANT:
+ renderer = trg_cell_renderer_wanted_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer,
+ "wanted-value",
+ desc->model_column,
+ NULL);
+ break;
+ case TRG_COLTYPE_PRIO:
+ renderer = trg_cell_renderer_priority_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer,
+ "priority-value",
+ desc->model_column,
+ NULL);
+ break;
+ }
- trg_tree_view_std_column_setup(column, index, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
-}
+ gtk_tree_view_column_set_resizable(column, TRUE);
+ gtk_tree_view_column_set_reorderable(column, TRUE);
+ gtk_tree_view_column_set_sort_column_id(column, desc->model_column);
-void trg_tree_view_add_prog_column(TrgTreeView * tv,
- gchar * title, gint index, gint width)
-{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
+ if (i < 0 && desc->defaultWidth > 0) {
+ gtk_tree_view_column_set_sizing(column,
+ GTK_TREE_VIEW_COLUMN_FIXED);
+ gtk_tree_view_column_set_fixed_width(column, desc->defaultWidth);
+ } else if (widths && i >= 0) {
+ gchar *ws = widths[i];
+ int w = atoi(ws);
+ gtk_tree_view_column_set_sizing(column,
+ GTK_TREE_VIEW_COLUMN_FIXED);
+ gtk_tree_view_column_set_fixed_width(column, w);
+ }
- renderer = gtk_cell_renderer_progress_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "value", index,
- NULL);
+ g_object_set_data(G_OBJECT(column), "column-desc", desc);
- trg_tree_view_std_column_setup(column, index, width);
gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
+
+ if (desc->out)
+ *(desc->out) = column;
}
-void trg_tree_view_add_speed_column(TrgTreeView * tv, char *title,
- int index, int width)
+void trg_tree_view_persist(TrgTreeView * tv)
{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
+ GConfClient *gcc = gconf_client_get_default();
+ GList *cols = gtk_tree_view_get_columns(GTK_TREE_VIEW(tv));
+ gint n_cols = g_list_length(cols);
+ gchar *cols_key =
+ g_strdup_printf("/apps/transmission-remote-gtk/%s-columns",
+ G_OBJECT_TYPE_NAME(tv));
+ gchar *widths_key =
+ g_strdup_printf("/apps/transmission-remote-gtk/%s-widths",
+ G_OBJECT_TYPE_NAME(tv));
+ gchar **cols_v = g_new0(gchar *, n_cols + 1);
+ gchar **widths_v = g_new0(gchar *, n_cols + 1);
+ gchar *widths_js, *cols_js;
+ GList *li;
+ int i = 0;
+
+ for (li = cols; li; li = g_list_next(li)) {
+ GtkTreeViewColumn *col = (GtkTreeViewColumn *) li->data;
+ trg_column_description *desc =
+ g_object_get_data(G_OBJECT(li->data), "column-desc");
+ cols_v[i] = desc->id;
+ widths_v[i] =
+ g_strdup_printf("%d", gtk_tree_view_column_get_width(col));
+ i++;
+ }
- renderer = trg_cell_renderer_speed_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "speed-value",
- index, NULL);
+ widths_js = g_strjoinv(",", widths_v);
+ cols_js = g_strjoinv(",", cols_v);
- trg_tree_view_std_column_setup(column, index, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
+ gconf_client_set_string(gcc, cols_key, cols_js, NULL);
+ gconf_client_set_string(gcc, widths_key, widths_js, NULL);
+
+ g_free(cols_key);
+ g_free(widths_key);
+ g_free(widths_js);
+ g_free(cols_js);
+ g_free(cols_v);
+ g_strfreev(widths_v);
+ g_list_free(cols);
+ g_object_unref(gcc);
}
-void trg_tree_view_add_epoch_column(TrgTreeView * tv, char *title,
- int index, int width)
+void trg_tree_view_setup_columns(TrgTreeView * tv)
{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
-
- renderer = trg_cell_renderer_epoch_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "epoch-value",
- index, NULL);
-
- trg_tree_view_std_column_setup(column, index, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
+ TrgTreeViewPrivate *priv = TRG_TREE_VIEW_GET_PRIVATE(tv);
+ gchar **columns = trg_gconf_get_csv(tv, "columns");
+ gchar **widths = trg_gconf_get_csv(tv, "widths");
+ GList *li;
+ int i;
+ trg_column_description *desc;
+
+ if (columns) {
+ for (i = 0; columns[i]; i++) {
+ trg_column_description *desc =
+ trg_tree_view_find_column(tv, columns[i]);
+ if (desc)
+ trg_tree_view_add_column(tv, desc, widths, i);
+ }
+ } else {
+ for (li = priv->columns; li; li = g_list_next(li)) {
+ desc = (trg_column_description *) li->data;
+ if (desc && desc->show != 0)
+ trg_tree_view_add_column(tv, desc, widths, -1);
+ }
+ }
}
-void trg_tree_view_add_ratio_column(TrgTreeView * tv, char *title,
- int index, int width)
+GList *trg_tree_view_get_selected_refs_list(GtkTreeView * tv)
{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
+ GtkTreeModel *model = gtk_tree_view_get_model(tv);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(tv);
+ GList *li, *selectionList;
+ GList *refList = NULL;
- renderer = trg_cell_renderer_ratio_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "ratio-value",
- index, NULL);
+ selectionList = gtk_tree_selection_get_selected_rows(selection, NULL);
+ for (li = selectionList; li != NULL; li = g_list_next(li)) {
+ GtkTreePath *path = (GtkTreePath *) li->data;
+ GtkTreeRowReference *ref = gtk_tree_row_reference_new(model, path);
+ gtk_tree_path_free(path);
+ refList = g_list_append(refList, ref);
+ }
+ g_list_free(selectionList);
- trg_tree_view_std_column_setup(column, index, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
+ return refList;
}
-GtkCellRenderer *trg_tree_view_add_column_fixed_width(TrgTreeView * tv,
- char *title,
- int index, int width)
+static void
+trg_tree_view_class_init(TrgTreeViewClass * klass G_GNUC_UNUSED)
{
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
-
- renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes(title, renderer,
- "text", index, NULL);
-
- trg_tree_view_std_column_setup(column, index, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
-
- return renderer;
+ g_type_class_add_private(klass, sizeof(TrgTreeViewPrivate));
}
-void
-trg_tree_view_add_pixbuf_text_column(TrgTreeView * tv,
- int iconIndex,
- int nameIndex,
- gchar * text, int width)
+static void trg_tree_view_init(TrgTreeView * tv)
{
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
-
- column = gtk_tree_view_column_new();
-
- renderer = gtk_cell_renderer_pixbuf_new();
- gtk_tree_view_column_set_title(GTK_TREE_VIEW_COLUMN(column), text);
- gtk_tree_view_column_pack_start(column, renderer, FALSE);
- gtk_tree_view_column_set_attributes(column, renderer, "stock-id",
- iconIndex, NULL);
-
- renderer = gtk_cell_renderer_text_new();
- gtk_tree_view_column_pack_start(column, renderer, TRUE);
- gtk_tree_view_column_set_attributes(column, renderer, "text",
- nameIndex, NULL);
+ gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(tv), TRUE);
+ gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(tv), TRUE);
+ gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tv), TRUE);
+ gtk_tree_selection_set_mode(gtk_tree_view_get_selection
+ (GTK_TREE_VIEW(tv)),
+ GTK_SELECTION_MULTIPLE);
- trg_tree_view_std_column_setup(column, nameIndex, width);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tv), column);
+ gtk_widget_set_sensitive(GTK_WIDGET(tv), FALSE);
}
GtkWidget *trg_tree_view_new(void)
diff --git a/src/trg-tree-view.h b/src/trg-tree-view.h
index 9cb8748..9723ec3 100644
--- a/src/trg-tree-view.h
+++ b/src/trg-tree-view.h
@@ -46,35 +46,39 @@ GType trg_tree_view_get_type(void);
GtkWidget *trg_tree_view_new(void);
-G_END_DECLS
-#define trg_tree_view_add_column(tv, title, index) trg_tree_view_add_column_fixed_width(tv, title, index, -1)
- GList * trg_tree_view_get_selected_refs_list(GtkTreeView * tv);
+G_END_DECLS GList * trg_tree_view_get_selected_refs_list(GtkTreeView * tv);
-GtkCellRenderer *trg_tree_view_add_column_fixed_width(TrgTreeView *
- treeview,
- char *title,
- int index,
- int width);
+enum {
+ TRG_COLTYPE_ICONTEXT,
+ TRG_COLTYPE_TEXT,
+ TRG_COLTYPE_SIZE,
+ TRG_COLTYPE_RATIO,
+ TRG_COLTYPE_EPOCH,
+ TRG_COLTYPE_SPEED,
+ TRG_COLTYPE_ETA,
+ TRG_COLTYPE_PROG,
+ TRG_COLTYPE_WANT,
+ TRG_COLTYPE_PRIO
+} TrgColumnType;
-void trg_tree_view_add_pixbuf_text_column(TrgTreeView *
- treeview,
- int iconIndex,
- int nameIndex,
- gchar * text, int width);
+typedef struct {
+ gint model_column;
+ gint model_column_icon;
+ gchar *header;
+ gchar *id;
+ gint show;
+ gint defaultWidth;
+ gint type;
+ GtkCellRenderer *customRenderer;
+ GtkTreeViewColumn **out;
+} trg_column_description;
-void trg_tree_view_add_speed_column(TrgTreeView * tv, char *title,
- int index, int width);
-void trg_tree_view_add_size_column(TrgTreeView * tv, char *title,
- int index, int width);
-void trg_tree_view_add_prog_column(TrgTreeView * tv, gchar * title,
- gint index, gint width);
-void trg_tree_view_add_ratio_column(TrgTreeView * tv, char *title,
- int index, int width);
-void trg_tree_view_add_eta_column(TrgTreeView * tv, char *title, int index,
- int width);
-void trg_tree_view_std_column_setup(GtkTreeViewColumn * column, int index,
- int width);
-void trg_tree_view_add_epoch_column(TrgTreeView * tv, char *title,
- int index, int width);
+trg_column_description *trg_tree_view_reg_column(TrgTreeView * tv,
+ gint type,
+ gint model_column,
+ gchar * header,
+ gchar * id, gint show);
+void trg_tree_view_setup_columns(TrgTreeView * tv);
+void trg_tree_view_persist(TrgTreeView * tv);
#endif /* _TRG_TREE_VIEW_H_ */
diff --git a/src/util.c b/src/util.c
index 077568d..0ae0aa3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -105,7 +105,7 @@ gint gconf_client_get_int_or_default(GConfClient * gconf,
gboolean g_slist_str_set_add(GSList ** list, const gchar * string)
{
GSList *li;
- for (li = *list; li != NULL; li = g_slist_next(li))
+ for (li = *list; li; li = g_slist_next(li))
if (!g_strcmp0((gchar *) li->data, string))
return FALSE;
@@ -115,16 +115,14 @@ gboolean g_slist_str_set_add(GSList ** list, const gchar * string)
gboolean gconf_client_get_bool_or_true(GConfClient * gconf, gchar * key)
{
- GError *error = NULL;
- GConfValue *value =
- gconf_client_get_without_default(gconf, key, &error);
+ GConfValue *value = gconf_client_get_without_default(gconf, key, NULL);
gboolean ret = TRUE;
- if (error) {
- g_error_free(error);
- } else if (value) {
+
+ if (value) {
ret = gconf_value_get_bool(value);
gconf_value_free(value);
}
+
return ret;
}