diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-10-03 09:36:52 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-10-03 09:36:52 +0000 |
commit | 5ce226277955a7d1aa6f5d0e00acb2ee98041003 (patch) | |
tree | abe471016e38d7ea8d9559eee35afe0ef6687261 | |
parent | a9780439e066ea76d7b5aa6af66a8a539c59b0cf (diff) |
use an icon for file wanted/unwanted
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/requests.c | 2 | ||||
-rw-r--r-- | src/trg-cell-renderer-wanted.c | 107 | ||||
-rw-r--r-- | src/trg-cell-renderer-wanted.h | 51 | ||||
-rw-r--r-- | src/trg-file-parser.c | 7 | ||||
-rw-r--r-- | src/trg-files-model.c | 8 | ||||
-rw-r--r-- | src/trg-files-tree-view.c | 19 | ||||
-rw-r--r-- | src/trg-torrent-add-dialog.c | 2 | ||||
-rw-r--r-- | src/trg-tree-view.c | 21 | ||||
-rw-r--r-- | src/trg-tree-view.h | 4 | ||||
-rw-r--r-- | src/util.c | 7 | ||||
-rw-r--r-- | src/util.h | 1 |
12 files changed, 39 insertions, 191 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 03b5e2e..6b3f3c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -58,7 +58,6 @@ transmission_remote_gtk_SOURCES = main.c \ trg-cell-renderer-ratio.c \ trg-cell-renderer-eta.c \ trg-remote-prefs-dialog.c \ - trg-cell-renderer-wanted.c \ trg-cell-renderer-priority.c \ trg-cell-renderer-epoch.c \ trg-cell-renderer-numgteqthan.c \ diff --git a/src/requests.c b/src/requests.c index c1c58b0..cd270d8 100644 --- a/src/requests.c +++ b/src/requests.c @@ -213,7 +213,7 @@ JsonNode *torrent_add(gchar * target, gint flags) { JsonNode *root; JsonObject *args; - gboolean isMagnet = g_str_has_prefix(target, "magnet:"); + gboolean isMagnet = is_magnet(target); gboolean isUri = isMagnet || is_url(target); gchar *encodedFile; diff --git a/src/trg-cell-renderer-wanted.c b/src/trg-cell-renderer-wanted.c deleted file mode 100644 index 57daaa6..0000000 --- a/src/trg-cell-renderer-wanted.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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 <glib/gi18n.h> -#include <gtk/gtk.h> - -#include "trg-cell-renderer-wanted.h" -#include "util.h" - -enum { - PROP_0, - PROP_WANTED_VALUE -}; - -G_DEFINE_TYPE(TrgCellRendererWanted, trg_cell_renderer_wanted, - GTK_TYPE_CELL_RENDERER_TEXT) -#define TRG_CELL_RENDERER_WANTED_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRG_TYPE_CELL_RENDERER_WANTED, TrgCellRendererWantedPrivate)) -typedef struct _TrgCellRendererWantedPrivate TrgCellRendererWantedPrivate; - -struct _TrgCellRendererWantedPrivate { - gboolean wanted_value; -}; - -static void -trg_cell_renderer_wanted_get_property(GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - TrgCellRendererWantedPrivate *priv = - TRG_CELL_RENDERER_WANTED_GET_PRIVATE(object); - switch (property_id) { - case PROP_WANTED_VALUE: - g_value_set_boolean(value, priv->wanted_value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - } -} - -static void -trg_cell_renderer_wanted_set_property(GObject * object, guint property_id, - const GValue * value, - GParamSpec * pspec) -{ - TrgCellRendererWantedPrivate *priv = - TRG_CELL_RENDERER_WANTED_GET_PRIVATE(object); - if (property_id == PROP_WANTED_VALUE) { - priv->wanted_value = g_value_get_boolean(value); - if (priv->wanted_value) { - g_object_set(object, "text", _("Yes"), NULL); - } else { - g_object_set(object, "text", _("No"), NULL); - } - } else { - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - } -} - -static void -trg_cell_renderer_wanted_class_init(TrgCellRendererWantedClass * klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS(klass); - - object_class->get_property = trg_cell_renderer_wanted_get_property; - object_class->set_property = trg_cell_renderer_wanted_set_property; - - g_object_class_install_property(object_class, - PROP_WANTED_VALUE, - g_param_spec_boolean - ("wanted-value", "Wanted Value", - "Wanted Value", TRUE, - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); - - g_type_class_add_private(klass, sizeof(TrgCellRendererWantedPrivate)); -} - -static void -trg_cell_renderer_wanted_init(TrgCellRendererWanted * self G_GNUC_UNUSED) -{ -} - -GtkCellRenderer *trg_cell_renderer_wanted_new(void) -{ - return - GTK_CELL_RENDERER(g_object_new - (TRG_TYPE_CELL_RENDERER_WANTED, NULL)); -} diff --git a/src/trg-cell-renderer-wanted.h b/src/trg-cell-renderer-wanted.h deleted file mode 100644 index 9f73206..0000000 --- a/src/trg-cell-renderer-wanted.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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_WANTED_H_ -#define TRG_CELL_RENDERER_WANTED_H_ - -#include <glib-object.h> -#include <gtk/gtk.h> - -G_BEGIN_DECLS -#define TRG_TYPE_CELL_RENDERER_WANTED trg_cell_renderer_wanted_get_type() -#define TRG_CELL_RENDERER_WANTED(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TRG_TYPE_CELL_RENDERER_WANTED, TrgCellRendererWanted)) -#define TRG_CELL_RENDERER_WANTED_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TRG_TYPE_CELL_RENDERER_WANTED, TrgCellRendererWantedClass)) -#define TRG_IS_CELL_RENDERER_WANTED(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TRG_TYPE_CELL_RENDERER_WANTED)) -#define TRG_IS_CELL_RENDERER_WANTED_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TRG_TYPE_CELL_RENDERER_WANTED)) -#define TRG_CELL_RENDERER_WANTED_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TRG_TYPE_CELL_RENDERER_WANTED, TrgCellRendererWantedClass)) - typedef struct { - GtkCellRendererText parent; -} TrgCellRendererWanted; - -typedef struct { - GtkCellRendererTextClass parent_class; -} TrgCellRendererWantedClass; - -GType trg_cell_renderer_wanted_get_type(void); - -GtkCellRenderer *trg_cell_renderer_wanted_new(void); - -G_END_DECLS -#endif /* TRG_CELL_RENDERER_WANTED_H_ */ diff --git a/src/trg-file-parser.c b/src/trg-file-parser.c index 0a4a8c0..582ee82 100644 --- a/src/trg-file-parser.c +++ b/src/trg-file-parser.c @@ -113,10 +113,15 @@ trg_torrent_file *trg_parse_torrent_file(const gchar *filename) be_node *top_node, *info_node, *name_node; trg_torrent_file *ret = NULL; + if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { + g_error("%s does not exist", filename); + return NULL; + } + mf = g_mapped_file_new(filename, FALSE, &error); if (error) { - g_message("%s",error->message); + g_error("%s",error->message); g_error_free(error); g_mapped_file_unref(mf); return NULL; diff --git a/src/trg-files-model.c b/src/trg-files-model.c index e816924..0c8d348 100644 --- a/src/trg-files-model.c +++ b/src/trg-files-model.c @@ -90,9 +90,8 @@ trg_files_model_iter_update(TrgFilesModel * model, if (priv->accept) { gtk_list_store_set(GTK_LIST_STORE(model), filesIter, - /* set wanted icon: FILESCOL_WANTED_ICON, - wanted ? GTK_STOCK_APPLY : GTK_STOCK_CANCEL, */ - FILESCOL_WANTED, wanted, + FILESCOL_WANTED, + wanted ? GTK_STOCK_APPLY : GTK_STOCK_CANCEL, FILESCOL_PRIORITY, priority, -1); } } @@ -114,8 +113,7 @@ static void trg_files_model_init(TrgFilesModel * self) column_types[FILESCOL_SIZE] = G_TYPE_INT64; column_types[FILESCOL_PROGRESS] = G_TYPE_DOUBLE; column_types[FILESCOL_ID] = G_TYPE_INT; - column_types[FILESCOL_WANTED] = G_TYPE_BOOLEAN; - //column_types[FILESCOL_WANTED_ICON] = G_TYPE_STRING; + column_types[FILESCOL_WANTED] = G_TYPE_STRING; column_types[FILESCOL_PRIORITY] = G_TYPE_INT64; gtk_list_store_set_column_types(GTK_LIST_STORE(self), diff --git a/src/trg-files-tree-view.c b/src/trg-files-tree-view.c index e6f0f88..9d63920 100644 --- a/src/trg-files-tree-view.c +++ b/src/trg-files-tree-view.c @@ -24,8 +24,6 @@ #include "trg-tree-view.h" #include "trg-files-tree-view.h" #include "trg-files-model.h" -#include "trg-cell-renderer-wanted.h" -#include "trg-cell-renderer-priority.h" #include "trg-main-window.h" #include "requests.h" #include "util.h" @@ -52,8 +50,7 @@ static void set_unwanted_foreachfunc(GtkTreeModel * model, GtkTreeIter * iter, gpointer data G_GNUC_UNUSED) { - gtk_list_store_set(GTK_LIST_STORE(model), iter, FILESCOL_WANTED, FALSE, - /* set wanted icon: FILESCOL_WANTED_ICON, GTK_STOCK_CANCEL,*/ -1); + gtk_list_store_set(GTK_LIST_STORE(model), iter, FILESCOL_WANTED, GTK_STOCK_CANCEL, -1); } static void set_wanted_foreachfunc(GtkTreeModel * model, @@ -61,8 +58,8 @@ static void set_wanted_foreachfunc(GtkTreeModel * model, GtkTreeIter * iter, gpointer data G_GNUC_UNUSED) { - gtk_list_store_set(GTK_LIST_STORE(model), iter, FILESCOL_WANTED, TRUE, - /* set wanted icon: FILESCOL_WANTED_ICON, GTK_STOCK_APPLY,*/ -1); + gtk_list_store_set(GTK_LIST_STORE(model), iter, + FILESCOL_WANTED, GTK_STOCK_APPLY, -1); } static void set_priority_foreachfunc(GtkTreeModel * model, @@ -85,16 +82,18 @@ static void send_updated_file_prefs_foreachfunc(GtkTreeModel * model, { JsonObject *args = (JsonObject *) data; gint64 priority, id; - gboolean wanted; + gchar *wanted; gtk_tree_model_get(model, iter, FILESCOL_WANTED, &wanted, FILESCOL_PRIORITY, &priority, FILESCOL_ID, &id, -1); - if (wanted == FALSE) + if (!g_strcmp0(wanted, GTK_STOCK_CANCEL)) add_file_id_to_array(args, FIELD_FILES_UNWANTED, id); else add_file_id_to_array(args, FIELD_FILES_WANTED, id); + g_free(wanted); + if (priority == TR_PRI_LOW) add_file_id_to_array(args, FIELD_FILES_PRIORITY_LOW, id); else if (priority == TR_PRI_HIGH) @@ -287,7 +286,7 @@ static void trg_files_tree_view_init(TrgFilesTreeView * self) trg_column_description *desc; desc = - trg_tree_view_reg_column(ttv, TRG_COLTYPE_PIXBUFICONTEXT, FILESCOL_NAME, + trg_tree_view_reg_column(ttv, TRG_COLTYPE_GICONTEXT, FILESCOL_NAME, _("Name"), "name", 0); desc->model_column_icon = FILESCOL_ICON; desc->defaultWidth = 500; @@ -296,7 +295,7 @@ static void trg_files_tree_view_init(TrgFilesTreeView * self) _("Size"), "size", 0); trg_tree_view_reg_column(ttv, TRG_COLTYPE_PROG, FILESCOL_PROGRESS, _("Progress"), "progress", 0); - trg_tree_view_reg_column(ttv, TRG_COLTYPE_WANT, FILESCOL_WANTED, + trg_tree_view_reg_column(ttv, TRG_COLTYPE_ICON, FILESCOL_WANTED, _("Wanted"), "wanted", 0); trg_tree_view_reg_column(ttv, TRG_COLTYPE_PRIO, FILESCOL_PRIORITY, _("Priority"), "priority", 0); diff --git a/src/trg-torrent-add-dialog.c b/src/trg-torrent-add-dialog.c index 2d034f8..8c40486 100644 --- a/src/trg-torrent-add-dialog.c +++ b/src/trg-torrent-add-dialog.c @@ -712,7 +712,7 @@ static void trg_torrent_add_dialog_set_filenames(TrgTorrentAddDialog * d, if (nfiles == 1) { gchar *file_name = (gchar *) filenames->data; - if (is_url(file_name)) { + if (is_url(file_name) || is_magnet(file_name)) { gtk_button_set_label(chooser, file_name); gtk_widget_set_sensitive(priv->file_list, FALSE); gtk_widget_set_sensitive(priv->delete_check, FALSE); diff --git a/src/trg-tree-view.c b/src/trg-tree-view.c index ede3989..7ee83a5 100644 --- a/src/trg-tree-view.c +++ b/src/trg-tree-view.c @@ -29,7 +29,6 @@ #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" #include "trg-cell-renderer-numgteqthan.h" @@ -338,21 +337,21 @@ static void trg_tree_view_add_column_after(TrgTreeView * tv, desc->model_column, NULL); break; + case TRG_COLTYPE_ICON: + column = gtk_tree_view_column_new(); + renderer = gtk_cell_renderer_pixbuf_new(); + gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), 0.5f, 0.0); + gtk_tree_view_column_set_title(column, desc->header); + gtk_tree_view_column_pack_start(column, renderer, TRUE); + gtk_tree_view_column_set_attributes(column, renderer, "stock-id", + desc->model_column, NULL); + break; case TRG_COLTYPE_STOCKICONTEXT: column = trg_tree_view_icontext_column_new(desc, "stock-id"); break; - case TRG_COLTYPE_PIXBUFICONTEXT: + case TRG_COLTYPE_GICONTEXT: column = trg_tree_view_icontext_column_new(desc, "gicon"); 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 = diff --git a/src/trg-tree-view.h b/src/trg-tree-view.h index 086fd5b..8040262 100644 --- a/src/trg-tree-view.h +++ b/src/trg-tree-view.h @@ -52,7 +52,8 @@ G_END_DECLS GList *trg_tree_view_get_selected_refs_list(GtkTreeView * tv); enum { TRG_COLTYPE_STOCKICONTEXT, - TRG_COLTYPE_PIXBUFICONTEXT, + TRG_COLTYPE_GICONTEXT, + TRG_COLTYPE_ICON, TRG_COLTYPE_TEXT, TRG_COLTYPE_SIZE, TRG_COLTYPE_RATIO, @@ -60,7 +61,6 @@ enum { TRG_COLTYPE_SPEED, TRG_COLTYPE_ETA, TRG_COLTYPE_PROG, - TRG_COLTYPE_WANT, TRG_COLTYPE_PRIO, TRG_COLTYPE_NUMGTZERO, TRG_COLTYPE_NUMGTEQZERO @@ -33,6 +33,11 @@ #include "util.h" +gboolean is_magnet(gchar *string) +{ + return g_str_has_prefix(string, "magnet:"); +} + gboolean is_url(gchar *string) { //return g_regex_match_simple ("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?", string, 0, 0); @@ -59,7 +64,7 @@ void g_str_slist_free(GSList * list) GRegex *trg_uri_host_regex_new(void) { - return g_regex_new("^[^:/?#]+:?//(?:www\\.|tracker\\.|\\d+\\.)?([^/?#:]*)", + return g_regex_new("^[^:/?#]+:?//(?:www\\.|torrent\\.|torrents\\.|tracker\\.|\\d+\\.)?([^/?#:]*)", G_REGEX_OPTIMIZE, 0, NULL); } @@ -69,5 +69,6 @@ gdouble json_double_to_progress(JsonNode *n); gchar *trg_base64encode(const gchar *filename); GtkWidget *my_scrolledwin_new(GtkWidget * child); gboolean is_url(gchar *string); +gboolean is_magnet(gchar *string); #endif /* UTIL_H_ */ |