summaryrefslogtreecommitdiff
path: root/src/trg-torrent-move-dialog.c
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-05-11 09:21:11 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-05-11 09:21:11 +0000
commit665e231ceb850f86ceedf80cdb6d13cca52671bf (patch)
tree0e199da108f72aac5a5b5ce4090b1a86db0d3389 /src/trg-torrent-move-dialog.c
parentb0ede16ee68023844bd7633e5ebdc7a134225b07 (diff)
put the destination combo into its own class, changing from the deprecated combo_box_entry_new_text or whatever it is and using it in torrent move dialog also.
Diffstat (limited to 'src/trg-torrent-move-dialog.c')
-rw-r--r--src/trg-torrent-move-dialog.c194
1 files changed, 149 insertions, 45 deletions
diff --git a/src/trg-torrent-move-dialog.c b/src/trg-torrent-move-dialog.c
index b10a471..d683663 100644
--- a/src/trg-torrent-move-dialog.c
+++ b/src/trg-torrent-move-dialog.c
@@ -25,6 +25,7 @@
#include "trg-client.h"
#include "trg-main-window.h"
#include "trg-torrent-move-dialog.h"
+#include "trg-destination-combo.h"
#include "hig.h"
#include "torrent.h"
#include "requests.h"
@@ -40,15 +41,17 @@ typedef struct _TrgTorrentMoveDialogPrivate
struct _TrgTorrentMoveDialogPrivate {
trg_client *client;
TrgMainWindow *win;
+ TrgTorrentTreeView *treeview;
JsonArray *ids;
GtkWidget *location_combo, *move_check, *move_button;
};
-static void
-trg_torrent_move_dialog_class_init(TrgTorrentMoveDialogClass * klass)
-{
- g_type_class_add_private(klass, sizeof(TrgTorrentMoveDialogPrivate));
-}
+enum {
+ PROP_0,
+ PROP_CLIENT,
+ PROP_PARENT_WINDOW,
+ PROP_TREEVIEW
+};
static void
trg_torrent_move_response_cb(GtkDialog * dlg, gint res_id, gpointer data)
@@ -84,86 +87,187 @@ static void location_changed(GtkWidget * w, gpointer data)
g_free(location);
}
-static void trg_torrent_move_dialog_init(TrgTorrentMoveDialog * self)
+static GObject *trg_torrent_move_dialog_constructor(GType type,
+ guint
+ n_construct_properties,
+ GObjectConstructParam
+ * construct_params)
{
+ GObject *object = G_OBJECT_CLASS
+ (trg_torrent_move_dialog_parent_class)->constructor(type,
+ n_construct_properties,
+ construct_params);
TrgTorrentMoveDialogPrivate *priv =
- TRG_TORRENT_MOVE_DIALOG_GET_PRIVATE(self);
+ TRG_TORRENT_MOVE_DIALOG_GET_PRIVATE(object);
+
+ gint count;
+ gchar *msg;
+
GtkWidget *w, *t;
gint row = 0;
t = hig_workarea_create();
- w = priv->location_combo = gtk_combo_box_entry_new_text();
- g_signal_connect(w, "changed", G_CALLBACK(location_changed), self);
+ w = priv->location_combo = trg_destination_combo_new(priv->client);
+ g_signal_connect(w, "changed", G_CALLBACK(location_changed), object);
hig_workarea_add_row(t, &row, _("Location:"), w, NULL);
priv->move_check =
hig_workarea_add_wide_checkbutton(t, &row, _("Move"), TRUE);
- gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
+ gtk_window_set_destroy_with_parent(GTK_WINDOW(object), TRUE);
- gtk_dialog_add_button(GTK_DIALOG(self), GTK_STOCK_CLOSE,
+ gtk_dialog_add_button(GTK_DIALOG(object), GTK_STOCK_CLOSE,
GTK_RESPONSE_CANCEL);
priv->move_button =
- gtk_dialog_add_button(GTK_DIALOG(self), _("Move"),
+ gtk_dialog_add_button(GTK_DIALOG(object), _("Move"),
GTK_RESPONSE_ACCEPT);
gtk_widget_set_sensitive(priv->move_button, FALSE);
- gtk_container_set_border_width(GTK_CONTAINER(self), GUI_PAD);
+ gtk_container_set_border_width(GTK_CONTAINER(object), GUI_PAD);
- gtk_dialog_set_default_response(GTK_DIALOG(self), GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_default_response(GTK_DIALOG(object),
+ GTK_RESPONSE_ACCEPT);
- gtk_dialog_set_alternative_button_order(GTK_DIALOG(self),
+ gtk_dialog_set_alternative_button_order(GTK_DIALOG(object),
GTK_RESPONSE_ACCEPT,
GTK_RESPONSE_CANCEL, -1);
gtk_container_set_border_width(GTK_CONTAINER(t), GUI_PAD);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(self)->vbox), t, TRUE, TRUE, 0);
-}
-
-TrgTorrentMoveDialog *trg_torrent_move_dialog_new(TrgMainWindow * win,
- trg_client * client,
- TrgTorrentTreeView * ttv)
-{
- GObject *obj = g_object_new(TRG_TYPE_TORRENT_MOVE_DIALOG, NULL);
- TrgTorrentMoveDialogPrivate *priv =
- TRG_TORRENT_MOVE_DIALOG_GET_PRIVATE(obj);
-
- gint count;
- gchar *msg;
-
- priv->client = client;
- priv->win = win;
- priv->ids = build_json_id_array(ttv);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(object)->vbox), t, TRUE, TRUE,
+ 0);
count =
gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection
- (GTK_TREE_VIEW(ttv)));
+ (GTK_TREE_VIEW
+ (priv->treeview)));
+ priv->ids = build_json_id_array(priv->treeview);
if (count == 1) {
JsonObject *json;
const gchar *name;
- const gchar *current_location;
- get_torrent_data(client->torrentTable,
- trg_mw_get_selected_torrent_id(win), &json, NULL);
+ get_torrent_data(priv->client->torrentTable,
+ trg_mw_get_selected_torrent_id(priv->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);
} else {
msg = g_strdup_printf(_("Move %d torrents"), count);
}
- gtk_window_set_transient_for(GTK_WINDOW(obj), GTK_WINDOW(win));
- gtk_window_set_title(GTK_WINDOW(obj), msg);
+ gtk_window_set_transient_for(GTK_WINDOW(object),
+ GTK_WINDOW(priv->win));
+ gtk_window_set_title(GTK_WINDOW(object), msg);
- g_signal_connect(G_OBJECT(obj),
+ g_signal_connect(G_OBJECT(object),
"response",
- G_CALLBACK(trg_torrent_move_response_cb), win);
+ G_CALLBACK(trg_torrent_move_response_cb), priv->win);
+
+ return object;
+}
- return TRG_TORRENT_MOVE_DIALOG(obj);
+static void
+trg_torrent_move_dialog_get_property(GObject * object, guint property_id,
+ GValue * value, GParamSpec * pspec)
+{
+ TrgTorrentMoveDialogPrivate *priv =
+ TRG_TORRENT_MOVE_DIALOG_GET_PRIVATE(object);
+ switch (property_id) {
+ case PROP_CLIENT:
+ g_value_set_pointer(value, priv->client);
+ break;
+ case PROP_PARENT_WINDOW:
+ g_value_set_object(value, priv->win);
+ break;
+ case PROP_TREEVIEW:
+ g_value_set_object(value, priv->treeview);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ }
+}
+
+static void
+trg_torrent_move_dialog_set_property(GObject * object, guint property_id,
+ const GValue * value,
+ GParamSpec * pspec)
+{
+ TrgTorrentMoveDialogPrivate *priv =
+ TRG_TORRENT_MOVE_DIALOG_GET_PRIVATE(object);
+ switch (property_id) {
+ case PROP_CLIENT:
+ priv->client = g_value_get_pointer(value);
+ break;
+ case PROP_PARENT_WINDOW:
+ priv->win = g_value_get_object(value);
+ break;
+ case PROP_TREEVIEW:
+ priv->treeview = g_value_get_object(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ }
+}
+
+static void
+trg_torrent_move_dialog_class_init(TrgTorrentMoveDialogClass * klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ g_type_class_add_private(klass, sizeof(TrgTorrentMoveDialogPrivate));
+
+ object_class->get_property = trg_torrent_move_dialog_get_property;
+ object_class->set_property = trg_torrent_move_dialog_set_property;
+ object_class->constructor = trg_torrent_move_dialog_constructor;
+
+ g_object_class_install_property(object_class,
+ PROP_TREEVIEW,
+ g_param_spec_object
+ ("torrent-tree-view",
+ "TrgTorrentTreeView",
+ "TrgTorrentTreeView",
+ TRG_TYPE_TORRENT_TREE_VIEW,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property(object_class,
+ PROP_PARENT_WINDOW,
+ g_param_spec_object
+ ("parent-window", "Parent window",
+ "Parent window", TRG_TYPE_MAIN_WINDOW,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property(object_class,
+ PROP_CLIENT,
+ g_param_spec_pointer
+ ("trg-client", "TClient",
+ "Client",
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+}
+
+static void trg_torrent_move_dialog_init(TrgTorrentMoveDialog * self)
+{
+}
+
+TrgTorrentMoveDialog *trg_torrent_move_dialog_new(TrgMainWindow * win,
+ trg_client * client,
+ TrgTorrentTreeView * ttv)
+{
+ return g_object_new(TRG_TYPE_TORRENT_MOVE_DIALOG,
+ "trg-client", client,
+ "torrent-tree-view", ttv,
+ "parent-window", win, NULL);
}