summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am1
-rw-r--r--src/trg-cell-renderer-numgtzero.c111
-rw-r--r--src/trg-cell-renderer-numgtzero.h51
-rw-r--r--src/trg-torrent-tree-view.c4
-rw-r--r--src/trg-tree-view.c10
-rw-r--r--src/trg-tree-view.h3
6 files changed, 177 insertions, 3 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5756834..8064e42 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-cell-renderer-epoch.c \
+ trg-cell-renderer-numgtzero.c \
trg-torrent-move-dialog.c \
trg-stats-dialog.c \
trg-torrent-graph.c \
diff --git a/src/trg-cell-renderer-numgtzero.c b/src/trg-cell-renderer-numgtzero.c
new file mode 100644
index 0000000..c28b258
--- /dev/null
+++ b/src/trg-cell-renderer-numgtzero.c
@@ -0,0 +1,111 @@
+/*
+ * transmission-remote-gtk - Transmission RPC client for GTK
+ * 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 <stdint.h>
+#include <gtk/gtk.h>
+
+#include "trg-cell-renderer-numgtzero.h"
+#include "util.h"
+
+enum {
+ PROP_0,
+ PROP_VALUE_VALUE
+};
+
+G_DEFINE_TYPE(TrgCellRendererNumgtzero, trg_cell_renderer_numgtzero,
+ GTK_TYPE_CELL_RENDERER_TEXT)
+#define TRG_CELL_RENDERER_NUMGTZERO_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRG_TYPE_CELL_RENDERER_NUMGTZERO, TrgCellRendererNumgtzeroPrivate))
+typedef struct _TrgCellRendererNumgtzeroPrivate TrgCellRendererNumgtzeroPrivate;
+
+struct _TrgCellRendererNumgtzeroPrivate {
+ gint64 value_value;
+};
+
+static void
+trg_cell_renderer_numgtzero_get_property(GObject * object, guint property_id,
+ GValue * value, GParamSpec * pspec)
+{
+ TrgCellRendererNumgtzeroPrivate *priv =
+ TRG_CELL_RENDERER_NUMGTZERO_GET_PRIVATE(object);
+ switch (property_id) {
+ case PROP_VALUE_VALUE:
+ g_value_set_int64(value, priv->value_value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ }
+}
+
+static void
+trg_cell_renderer_numgtzero_set_property(GObject * object, guint property_id,
+ const GValue * value,
+ GParamSpec * pspec)
+{
+ TrgCellRendererNumgtzeroPrivate *priv =
+ TRG_CELL_RENDERER_NUMGTZERO_GET_PRIVATE(object);
+ if (property_id == PROP_VALUE_VALUE) {
+ priv->value_value = g_value_get_int64(value);
+ if (priv->value_value > 0) {
+ g_object_set(object, "text", priv->value_value, NULL);
+ } else {
+ g_object_set(object, "text", "", NULL);
+ }
+ } else {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ }
+}
+
+static void
+trg_cell_renderer_numgtzero_class_init(TrgCellRendererNumgtzeroClass * klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->get_property = trg_cell_renderer_numgtzero_get_property;
+ object_class->set_property = trg_cell_renderer_numgtzero_set_property;
+
+ g_object_class_install_property(object_class,
+ PROP_VALUE_VALUE,
+ g_param_spec_int64("value",
+ "Value",
+ "Value",
+ 0,
+ INT64_MAX,
+ 0,
+ G_PARAM_READWRITE
+ |
+ G_PARAM_STATIC_NAME
+ |
+ G_PARAM_STATIC_NICK
+ |
+ G_PARAM_STATIC_BLURB));
+
+ g_type_class_add_private(klass, sizeof(TrgCellRendererNumgtzeroPrivate));
+}
+
+static void trg_cell_renderer_numgtzero_init(TrgCellRendererNumgtzero * self)
+{
+ g_object_set(self, "xalign", 1.0f, NULL);
+}
+
+GtkCellRenderer *trg_cell_renderer_numgtzero_new(void)
+{
+ return
+ GTK_CELL_RENDERER(g_object_new(TRG_TYPE_CELL_RENDERER_NUMGTZERO, NULL));
+}
diff --git a/src/trg-cell-renderer-numgtzero.h b/src/trg-cell-renderer-numgtzero.h
new file mode 100644
index 0000000..79d86a9
--- /dev/null
+++ b/src/trg-cell-renderer-numgtzero.h
@@ -0,0 +1,51 @@
+/*
+ * transmission-remote-gtk - Transmission RPC client for GTK
+ * 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 TRG_CELL_RENDERER_NUMGTZERO_H_
+#define TRG_CELL_RENDERER_NUMGTZERO_H_
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+#define TRG_TYPE_CELL_RENDERER_NUMGTZERO trg_cell_renderer_numgtzero_get_type()
+#define TRG_CELL_RENDERER_NUMGTZERO(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), TRG_TYPE_CELL_RENDERER_NUMGTZERO, TrgCellRendererNumgtzero))
+#define TRG_CELL_RENDERER_NUMGTZERO_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), TRG_TYPE_CELL_RENDERER_NUMGTZERO, TrgCellRendererNumgtzeroClass))
+#define TRG_IS_CELL_RENDERER_NUMGTZERO(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TRG_TYPE_CELL_RENDERER_NUMGTZERO))
+#define TRG_IS_CELL_RENDERER_NUMGTZERO_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), TRG_TYPE_CELL_RENDERER_NUMGTZERO))
+#define TRG_CELL_RENDERER_NUMGTZERO_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), TRG_TYPE_CELL_RENDERER_NUMGTZERO, TrgCellRendererNumgtzeroClass))
+ typedef struct {
+ GtkCellRendererText parent;
+} TrgCellRendererNumgtzero;
+
+typedef struct {
+ GtkCellRendererTextClass parent_class;
+} TrgCellRendererNumgtzeroClass;
+
+GType trg_cell_renderer_numgtzero_get_type(void);
+
+GtkCellRenderer *trg_cell_renderer_numgtzero_new(void);
+
+G_END_DECLS
+#endif /* TRG_CELL_RENDERER_NUMGTZERO_H_ */
diff --git a/src/trg-torrent-tree-view.c b/src/trg-torrent-tree-view.c
index bd5b860..d05e872 100644
--- a/src/trg-torrent-tree-view.c
+++ b/src/trg-torrent-tree-view.c
@@ -51,9 +51,9 @@ static void trg_torrent_tree_view_init(TrgTorrentTreeView * tttv)
_("Done"), "done", 0);
trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, TORRENT_COLUMN_STATUS,
_("Status"), "status", 0);
- trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT, TORRENT_COLUMN_SEEDS,
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_NUMGTZERO, TORRENT_COLUMN_SEEDS,
_("Seeds"), "seeds", 0);
- trg_tree_view_reg_column(ttv, TRG_COLTYPE_TEXT,
+ trg_tree_view_reg_column(ttv, TRG_COLTYPE_NUMGTZERO,
TORRENT_COLUMN_LEECHERS, _("Leechers"),
"leechers", 0);
trg_tree_view_reg_column(ttv, TRG_COLTYPE_SPEED,
diff --git a/src/trg-tree-view.c b/src/trg-tree-view.c
index cd1f709..a64b403 100644
--- a/src/trg-tree-view.c
+++ b/src/trg-tree-view.c
@@ -30,6 +30,7 @@
#include "trg-cell-renderer-epoch.h"
#include "trg-cell-renderer-wanted.h"
#include "trg-cell-renderer-priority.h"
+#include "trg-cell-renderer-numgtzero.h"
G_DEFINE_TYPE(TrgTreeView, trg_tree_view, GTK_TYPE_TREE_VIEW)
#define TRG_TREE_VIEW_GET_PRIVATE(o) \
@@ -283,6 +284,15 @@ static void trg_tree_view_add_column_after(TrgTreeView * tv,
desc->model_column,
NULL);
break;
+ case TRG_COLTYPE_NUMGTZERO:
+ renderer = trg_cell_renderer_numgtzero_new();
+ column =
+ gtk_tree_view_column_new_with_attributes(desc->header,
+ renderer,
+ "value",
+ desc->model_column,
+ NULL);
+ break;
}
gtk_tree_view_column_set_resizable(column, TRUE);
diff --git a/src/trg-tree-view.h b/src/trg-tree-view.h
index 3b73a2f..027f0fd 100644
--- a/src/trg-tree-view.h
+++ b/src/trg-tree-view.h
@@ -58,7 +58,8 @@ enum {
TRG_COLTYPE_ETA,
TRG_COLTYPE_PROG,
TRG_COLTYPE_WANT,
- TRG_COLTYPE_PRIO
+ TRG_COLTYPE_PRIO,
+ TRG_COLTYPE_NUMGTZERO,
} TrgColumnType;
typedef struct {