diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-12-11 15:08:03 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-12-11 15:08:03 +0000 |
commit | 763abd8c8fc32b29c5f989cd0d4cab1b6e472997 (patch) | |
tree | 4ff54223e8526dbb20e9fe87e9c21d9a3b80975c /src/trg-destination-combo.c | |
parent | 0d08a471f9ebfdfadded6c92abc700c706475644 (diff) |
oops, no tabs. (indent -kr -nut)
Diffstat (limited to 'src/trg-destination-combo.c')
-rw-r--r-- | src/trg-destination-combo.c | 366 |
1 files changed, 183 insertions, 183 deletions
diff --git a/src/trg-destination-combo.c b/src/trg-destination-combo.c index c19a750..3ebc14d 100644 --- a/src/trg-destination-combo.c +++ b/src/trg-destination-combo.c @@ -27,7 +27,7 @@ #include "util.h" G_DEFINE_TYPE(TrgDestinationCombo, trg_destination_combo, - GTK_TYPE_COMBO_BOX) + GTK_TYPE_COMBO_BOX) #define TRG_DESTINATION_COMBO_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRG_TYPE_DESTINATION_COMBO, TrgDestinationComboPrivate)) typedef struct _TrgDestinationComboPrivate TrgDestinationComboPrivate; @@ -54,47 +54,47 @@ enum { static void trg_destination_combo_finalize(GObject * object) { TrgDestinationComboPrivate *priv = - TRG_DESTINATION_COMBO_GET_PRIVATE(object); + TRG_DESTINATION_COMBO_GET_PRIVATE(object); g_free((gpointer) priv->last_selection); } static void trg_destination_combo_get_property(GObject * object, - guint property_id, - GValue * value, - GParamSpec * pspec) + guint property_id, + GValue * value, + GParamSpec * pspec) { TrgDestinationComboPrivate *priv = - TRG_DESTINATION_COMBO_GET_PRIVATE(object); + TRG_DESTINATION_COMBO_GET_PRIVATE(object); switch (property_id) { case PROP_CLIENT: - g_value_set_pointer(value, priv->client); - break; + g_value_set_pointer(value, priv->client); + break; case PROP_LAST_SELECTION: - g_value_set_string(value, priv->last_selection); - break; + g_value_set_string(value, priv->last_selection); + break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); + break; } } static void trg_destination_combo_set_property(GObject * object, - guint property_id, - const GValue * value, - GParamSpec * pspec) + guint property_id, + const GValue * value, + GParamSpec * pspec) { TrgDestinationComboPrivate *priv = - TRG_DESTINATION_COMBO_GET_PRIVATE(object); + TRG_DESTINATION_COMBO_GET_PRIVATE(object); switch (property_id) { case PROP_CLIENT: - priv->client = g_value_get_pointer(value); - break; + priv->client = g_value_get_pointer(value); + break; case PROP_LAST_SELECTION: - priv->last_selection = g_strdup(g_value_get_string(value)); - break; + priv->last_selection = g_strdup(g_value_get_string(value)); + break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); + break; } } @@ -102,11 +102,11 @@ static gboolean g_slist_str_set_add(GSList ** list, const gchar * string) { GSList *li; for (li = *list; li; li = g_slist_next(li)) - if (!g_strcmp0((gchar *) li->data, string)) - return FALSE; + if (!g_strcmp0((gchar *) li->data, string)) + return FALSE; *list = g_slist_insert_sorted(*list, (gpointer) string, - (GCompareFunc) g_strcmp0); + (GCompareFunc) g_strcmp0); return TRUE; } @@ -114,92 +114,92 @@ static gboolean g_slist_str_set_add(GSList ** list, const gchar * string) void trg_destination_combo_save_selection(TrgDestinationCombo * combo_box) { TrgDestinationComboPrivate *priv = - TRG_DESTINATION_COMBO_GET_PRIVATE(combo_box); + TRG_DESTINATION_COMBO_GET_PRIVATE(combo_box); GtkTreeIter iter; if (priv->last_selection - && gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo_box), - &iter)) { - GtkTreeModel *model = - gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box)); - TrgPrefs *prefs = trg_client_get_prefs(priv->client); - gchar *text; - - gtk_tree_model_get(model, &iter, DEST_COLUMN_LABEL, &text, -1); - trg_prefs_set_string(prefs, priv->last_selection, text, - TRG_PREFS_CONNECTION); - g_free(text); + && gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo_box), + &iter)) { + GtkTreeModel *model = + gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box)); + TrgPrefs *prefs = trg_client_get_prefs(priv->client); + gchar *text; + + gtk_tree_model_get(model, &iter, DEST_COLUMN_LABEL, &text, -1); + trg_prefs_set_string(prefs, priv->last_selection, text, + TRG_PREFS_CONNECTION); + g_free(text); } } static void gtk_combo_box_entry_active_changed(GtkComboBox * combo_box, - gpointer user_data) + gpointer user_data) { GtkTreeModel *model; GtkTreeIter iter; gboolean editableEntry = TRUE; if (gtk_combo_box_get_active_iter(combo_box, &iter)) { - GtkEntry *entry = - trg_destination_combo_get_entry(TRG_DESTINATION_COMBO - (combo_box)); + GtkEntry *entry = + trg_destination_combo_get_entry(TRG_DESTINATION_COMBO + (combo_box)); - if (entry) { - GValue value = { 0, }; - guint type; + if (entry) { + GValue value = { 0, }; + guint type; - model = gtk_combo_box_get_model(combo_box); + model = gtk_combo_box_get_model(combo_box); - gtk_tree_model_get_value(model, &iter, DEST_COLUMN_LABEL, - &value); - gtk_tree_model_get(model, &iter, DEST_COLUMN_TYPE, &type, -1); + gtk_tree_model_get_value(model, &iter, DEST_COLUMN_LABEL, + &value); + gtk_tree_model_get(model, &iter, DEST_COLUMN_TYPE, &type, -1); - g_object_set_property(G_OBJECT(entry), "text", &value); - g_value_unset(&value); + g_object_set_property(G_OBJECT(entry), "text", &value); + g_value_unset(&value); - if (type == DEST_LABEL) - editableEntry = FALSE; - } + if (type == DEST_LABEL) + editableEntry = FALSE; + } } #if GTK_CHECK_VERSION( 3, 0, 0 ) gtk_editable_set_editable(GTK_EDITABLE - (trg_destination_combo_get_entry - (TRG_DESTINATION_COMBO(combo_box))), - editableEntry); + (trg_destination_combo_get_entry + (TRG_DESTINATION_COMBO(combo_box))), + editableEntry); #else gtk_entry_set_editable(trg_destination_combo_get_entry - (TRG_DESTINATION_COMBO(combo_box)), - editableEntry); + (TRG_DESTINATION_COMBO(combo_box)), + editableEntry); #endif } gboolean trg_destination_combo_has_text(TrgDestinationCombo * combo) { const gchar *text = - gtk_entry_get_text(trg_destination_combo_get_entry - (TRG_DESTINATION_COMBO(combo))); + gtk_entry_get_text(trg_destination_combo_get_entry + (TRG_DESTINATION_COMBO(combo))); return strlen(text) > 0; } GtkEntry *trg_destination_combo_get_entry(TrgDestinationCombo * combo) { TrgDestinationComboPrivate *priv = - TRG_DESTINATION_COMBO_GET_PRIVATE(combo); + TRG_DESTINATION_COMBO_GET_PRIVATE(combo); return GTK_ENTRY(priv->entry); } static void add_entry_cb(GtkEntry * entry, - GtkEntryIconPosition icon_pos, - GdkEvent * event, gpointer user_data) + GtkEntryIconPosition icon_pos, + GdkEvent * event, gpointer user_data) { GtkComboBox *combo = GTK_COMBO_BOX(user_data); GtkTreeModel *model = gtk_combo_box_get_model(combo); GtkTreeIter iter; gtk_list_store_insert_with_values(GTK_LIST_STORE(model), &iter, - INT_MAX, DEST_COLUMN_LABEL, "", - DEST_COLUMN_DIR, "", - DEST_COLUMN_TYPE, DEST_USERADD, -1); + INT_MAX, DEST_COLUMN_LABEL, "", + DEST_COLUMN_DIR, "", + DEST_COLUMN_TYPE, DEST_USERADD, -1); gtk_combo_box_set_active_iter(combo, &iter); } @@ -210,10 +210,10 @@ struct findDupeArg { gboolean trg_destination_combo_insert_check_dupe_foreach(GtkTreeModel * model, - GtkTreePath * - path G_GNUC_UNUSED, - GtkTreeIter * iter, - struct findDupeArg *args) + GtkTreePath * + path G_GNUC_UNUSED, + GtkTreeIter * iter, + struct findDupeArg *args) { gchar *existing; gtk_tree_model_get(model, iter, DEST_COLUMN_DIR, &existing, -1); @@ -223,52 +223,52 @@ trg_destination_combo_insert_check_dupe_foreach(GtkTreeModel * model, } static void trg_destination_combo_insert(GtkComboBox * box, - const gchar * label, - const gchar * dir, guint type, - const gchar * lastDestination) + const gchar * label, + const gchar * dir, guint type, + const gchar * lastDestination) { GtkTreeModel *model = gtk_combo_box_get_model(box); gchar *comboLabel; GtkTreeIter iter; if (type == DEST_EXISTING) { - struct findDupeArg args; - args.isDupe = FALSE; - args.dir = dir; - gtk_tree_model_foreach(GTK_TREE_MODEL(model), - (GtkTreeModelForeachFunc) - trg_destination_combo_insert_check_dupe_foreach, - &args); - if (args.isDupe) - return; + struct findDupeArg args; + args.isDupe = FALSE; + args.dir = dir; + gtk_tree_model_foreach(GTK_TREE_MODEL(model), + (GtkTreeModelForeachFunc) + trg_destination_combo_insert_check_dupe_foreach, + &args); + if (args.isDupe) + return; } comboLabel = - label ? g_strdup_printf("%s (%s)", label, dir) : g_strdup(dir); + label ? g_strdup_printf("%s (%s)", label, dir) : g_strdup(dir); gtk_list_store_insert_with_values(GTK_LIST_STORE(model), &iter, - INT_MAX, DEST_COLUMN_LABEL, - comboLabel, DEST_COLUMN_DIR, dir, - DEST_COLUMN_TYPE, type, -1); + INT_MAX, DEST_COLUMN_LABEL, + comboLabel, DEST_COLUMN_DIR, dir, + DEST_COLUMN_TYPE, type, -1); if (lastDestination && !g_strcmp0(lastDestination, comboLabel)) - gtk_combo_box_set_active_iter(box, &iter); + gtk_combo_box_set_active_iter(box, &iter); g_free(comboLabel); } static GObject *trg_destination_combo_constructor(GType type, - guint - n_construct_properties, - GObjectConstructParam * - construct_params) + guint + n_construct_properties, + GObjectConstructParam * + construct_params) { GObject *object = G_OBJECT_CLASS - (trg_destination_combo_parent_class)->constructor(type, - n_construct_properties, - construct_params); + (trg_destination_combo_parent_class)->constructor(type, + n_construct_properties, + construct_params); TrgDestinationComboPrivate *priv = - TRG_DESTINATION_COMBO_GET_PRIVATE(object); + TRG_DESTINATION_COMBO_GET_PRIVATE(object); TrgClient *client = priv->client; TrgPrefs *prefs = trg_client_get_prefs(client); @@ -284,102 +284,102 @@ static GObject *trg_destination_combo_constructor(GType type, const gchar *lastDestination = NULL; comboModel = gtk_list_store_new(N_DEST_COLUMNS, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_UINT); + G_TYPE_STRING, G_TYPE_UINT); gtk_combo_box_set_model(GTK_COMBO_BOX(object), - GTK_TREE_MODEL(comboModel)); + GTK_TREE_MODEL(comboModel)); g_object_unref(comboModel); g_signal_connect(object, "changed", - G_CALLBACK(gtk_combo_box_entry_active_changed), NULL); + G_CALLBACK(gtk_combo_box_entry_active_changed), NULL); priv->entry = gtk_entry_new(); gtk_container_add(GTK_CONTAINER(object), priv->entry); priv->text_renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(object), - priv->text_renderer, TRUE); + priv->text_renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(object), - priv->text_renderer, "text", 0, NULL); + priv->text_renderer, "text", 0, NULL); g_slist_foreach(dirs, (GFunc) g_free, NULL); g_slist_free(dirs); gtk_entry_set_icon_from_stock(GTK_ENTRY(priv->entry), - GTK_ENTRY_ICON_SECONDARY, - GTK_STOCK_CLEAR); + GTK_ENTRY_ICON_SECONDARY, + GTK_STOCK_CLEAR); g_signal_connect(priv->entry, "icon-release", - G_CALLBACK(add_entry_cb), object); + G_CALLBACK(add_entry_cb), object); defaultDir = - g_strdup(session_get_download_dir(trg_client_get_session(client))); + g_strdup(session_get_download_dir(trg_client_get_session(client))); rm_trailing_slashes(defaultDir); savedDestinations = - trg_prefs_get_array(prefs, TRG_PREFS_KEY_DESTINATIONS, - TRG_PREFS_CONNECTION); + trg_prefs_get_array(prefs, TRG_PREFS_KEY_DESTINATIONS, + TRG_PREFS_CONNECTION); if (priv->last_selection) - lastDestination = trg_prefs_get_string(prefs, priv->last_selection, - TRG_PREFS_CONNECTION); + lastDestination = trg_prefs_get_string(prefs, priv->last_selection, + TRG_PREFS_CONNECTION); trg_destination_combo_insert(GTK_COMBO_BOX(object), - NULL, - defaultDir, - DEST_DEFAULT, lastDestination); + NULL, + defaultDir, + DEST_DEFAULT, lastDestination); if (savedDestinations) { - list = json_array_get_elements(savedDestinations); - if (list) { - for (li = list; li; li = g_list_next(li)) { - JsonObject *obj = - json_node_get_object((JsonNode *) li->data); - trg_destination_combo_insert(GTK_COMBO_BOX(object), - json_object_get_string_member - (obj, TRG_PREFS_SUBKEY_LABEL), - json_object_get_string_member - (obj, - TRG_PREFS_KEY_DESTINATIONS_SUBKEY_DIR), - DEST_LABEL, lastDestination); - } - g_list_free(list); - } + list = json_array_get_elements(savedDestinations); + if (list) { + for (li = list; li; li = g_list_next(li)) { + JsonObject *obj = + json_node_get_object((JsonNode *) li->data); + trg_destination_combo_insert(GTK_COMBO_BOX(object), + json_object_get_string_member + (obj, TRG_PREFS_SUBKEY_LABEL), + json_object_get_string_member + (obj, + TRG_PREFS_KEY_DESTINATIONS_SUBKEY_DIR), + DEST_LABEL, lastDestination); + } + g_list_free(list); + } } trg_client_updatelock(client); list = g_hash_table_get_values(trg_client_get_torrent_table(client)); for (li = list; li; li = g_list_next(li)) { - rr = (GtkTreeRowReference *) li->data; - model = gtk_tree_row_reference_get_model(rr); - path = gtk_tree_row_reference_get_path(rr); + rr = (GtkTreeRowReference *) li->data; + model = gtk_tree_row_reference_get_model(rr); + path = gtk_tree_row_reference_get_path(rr); - if (path) { - GtkTreeIter iter; + if (path) { + GtkTreeIter iter; - if (gtk_tree_model_get_iter(model, &iter, path)) { - gchar *dd; + if (gtk_tree_model_get_iter(model, &iter, path)) { + gchar *dd; - gtk_tree_model_get(model, &iter, - TORRENT_COLUMN_DOWNLOADDIR, &dd, -1); + gtk_tree_model_get(model, &iter, + TORRENT_COLUMN_DOWNLOADDIR, &dd, -1); - if (dd && g_strcmp0(dd, defaultDir)) - g_slist_str_set_add(&dirs, dd); - else - g_free(dd); - } + if (dd && g_strcmp0(dd, defaultDir)) + g_slist_str_set_add(&dirs, dd); + else + g_free(dd); + } - gtk_tree_path_free(path); - } + gtk_tree_path_free(path); + } } trg_client_updateunlock(client); for (sli = dirs; sli; sli = g_slist_next(sli)) - trg_destination_combo_insert(GTK_COMBO_BOX(object), - NULL, - (gchar *) sli->data, - DEST_EXISTING, lastDestination); + trg_destination_combo_insert(GTK_COMBO_BOX(object), + NULL, + (gchar *) sli->data, + DEST_EXISTING, lastDestination); g_list_free(list); g_free(defaultDir); @@ -393,24 +393,24 @@ gchar *trg_destination_combo_get_dir(TrgDestinationCombo * combo) GtkTreeIter iter; if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) { - gchar *value; - guint type; + gchar *value; + guint type; - gtk_tree_model_get(model, &iter, DEST_COLUMN_TYPE, &type, -1); + gtk_tree_model_get(model, &iter, DEST_COLUMN_TYPE, &type, -1); - if (type == DEST_LABEL) { - gtk_tree_model_get(model, &iter, DEST_COLUMN_DIR, &value, -1); - return value; - } + if (type == DEST_LABEL) { + gtk_tree_model_get(model, &iter, DEST_COLUMN_DIR, &value, -1); + return value; + } } return - g_strdup(gtk_entry_get_text - (trg_destination_combo_get_entry(combo))); + g_strdup(gtk_entry_get_text + (trg_destination_combo_get_entry(combo))); } static void trg_destination_combo_class_init(TrgDestinationComboClass * - klass) + klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); @@ -422,31 +422,31 @@ static void trg_destination_combo_class_init(TrgDestinationComboClass * object_class->constructor = trg_destination_combo_constructor; 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)); + 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)); g_object_class_install_property(object_class, - PROP_LAST_SELECTION, - g_param_spec_string - ("last-selection-key", - "LastSelectionKey", - "LastSelectionKey", NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); + PROP_LAST_SELECTION, + g_param_spec_string + ("last-selection-key", + "LastSelectionKey", + "LastSelectionKey", NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_NAME | + G_PARAM_STATIC_NICK | + G_PARAM_STATIC_BLURB)); } static void trg_destination_combo_init(TrgDestinationCombo * self) @@ -454,10 +454,10 @@ static void trg_destination_combo_init(TrgDestinationCombo * self) } GtkWidget *trg_destination_combo_new(TrgClient * client, - const gchar * lastSelectionKey) + const gchar * lastSelectionKey) { return GTK_WIDGET(g_object_new(TRG_TYPE_DESTINATION_COMBO, - "trg-client", client, - "last-selection-key", lastSelectionKey, - NULL)); + "trg-client", client, + "last-selection-key", lastSelectionKey, + NULL)); } |