commit 2f13631811baeda7762d1aac8d5f36884588fa2d
Author: phantomjinx <[email protected]>
Date: Sat May 7 00:56:52 2011 +0100
Migrate combo boxes to remove deprecated code
* configure dictates that compile should fail upon use of deprecated
functions
so migrate deprecated combo box code to make it compatible.
plugins/core_preferences/core_prefs.c | 12 +++++-
plugins/details_editor/details.c | 10 +++-
plugins/playlist_display/playlist_display_spl.c | 42 +++++++++++++------
plugins/repository_editor/repository.c | 7 +++
plugins/repository_editor/repository_init.c | 11 ++++-
plugins/sorttab_display/display_sorttabs.c | 45 ++++++++++++++++-----
plugins/sorttab_display/sorttab_display_actions.c | 8 ++--
plugins/track_display/display_tracks.c | 1 -
plugins/track_display/track_display_preferences.c | 9 +++-
9 files changed, 107 insertions(+), 38 deletions(-)
---
diff --git a/plugins/core_preferences/core_prefs.c
b/plugins/core_preferences/core_prefs.c
index f7ec7a9..e1a0303 100644
--- a/plugins/core_preferences/core_prefs.c
+++ b/plugins/core_preferences/core_prefs.c
@@ -267,7 +267,17 @@ G_MODULE_EXPORT void open_encoding_dialog(GtkButton
*sender, gpointer e) {
glade callback
*/
G_MODULE_EXPORT void on_encoding_combo_changed(GtkComboBox *sender, gpointer
e) {
- gchar *description = gtk_combo_box_get_active_text(sender);
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ if (!gtk_combo_box_get_active_iter(sender, &iter))
+ return;
+
+ model = gtk_combo_box_get_model(sender);
+
+ gchar *description;
+ gtk_tree_model_get(model, &iter, 0, &description, -1);
+
gchar *charset = charset_from_description(description);
prefs_set_string("charset", charset);
diff --git a/plugins/details_editor/details.c b/plugins/details_editor/details.c
index 07ace3e..364582d 100644
--- a/plugins/details_editor/details.c
+++ b/plugins/details_editor/details.c
@@ -528,10 +528,11 @@ static gint comboentry_index_from_id(const ComboEntry
centries[], guint32 id) {
}
/* initialize a combobox with the corresponding entry strings */
-static void details_setup_combobox(GtkWidget *cb, const ComboEntry centries[])
{
+static void details_setup_combo_box(GtkWidget *cb, const ComboEntry
centries[]) {
const ComboEntry *ce = centries;
GtkCellRenderer *cell;
GtkListStore *store;
+ GtkTreeIter iter;
g_return_if_fail (cb);
g_return_if_fail (centries);
@@ -548,7 +549,10 @@ static void details_setup_combobox(GtkWidget *cb, const
ComboEntry centries[]) {
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT (cb), cell, "text", 0,
NULL);
while (ce->str != NULL) {
- gtk_combo_box_append_text(GTK_COMBO_BOX (cb), _(ce->str));
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, _(ce->str),
+ -1);
++ce;
}
}
@@ -669,7 +673,7 @@ static void details_setup_widget(T_item item) {
case T_MEDIA_TYPE:
buf = g_strdup_printf("details_combobox_%d", item);
w = gtkpod_builder_xml_get_widget(details_view->xml, buf);
- details_setup_combobox(w, mediatype_comboentries);
+ details_setup_combo_box(w, mediatype_comboentries);
g_signal_connect (w, "changed",
G_CALLBACK (details_combobox_changed),
details_view);
diff --git a/plugins/playlist_display/playlist_display_spl.c
b/plugins/playlist_display/playlist_display_spl.c
index 69df9e9..11f1064 100644
--- a/plugins/playlist_display/playlist_display_spl.c
+++ b/plugins/playlist_display/playlist_display_spl.c
@@ -290,22 +290,27 @@ static void spl_setup_combobox(GtkComboBox *cb, const
ComboEntry centries[], gin
const ComboEntry *ce = centries;
GtkCellRenderer *cell;
GtkListStore *store;
+ GtkTreeIter iter;
/* Set the model -- that is you cannot do a
gtk_combo_box_new_text()! This gives us the flexibility to
expand this function to set some graphic next to the text. */
store = gtk_list_store_new(1, G_TYPE_STRING);
gtk_combo_box_set_model(cb, GTK_TREE_MODEL (store));
- g_object_unref(store);
cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (cb), cell, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT (cb), cell, "text", 0,
NULL);
while (ce->str != NULL) {
- gtk_combo_box_append_text(cb, _(ce->str));
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, _(ce->str),
+ -1);
++ce;
}
+
+ g_object_unref(store);
g_object_set_data(G_OBJECT (cb), "spl_centries", (gpointer) centries);
g_object_set_data(G_OBJECT (cb), "combo_set", "set");
if (cb_func)
@@ -954,12 +959,14 @@ static void spl_pl_ids_destroy(GArray *array) {
static GtkWidget *spl_create_hbox(GtkWidget *spl_window, Itdb_SPLRule *splr) {
GtkWidget *hbox = NULL;
ItdbSPLActionType at;
- GtkWidget *entry, *label, *combobox;
+ GtkWidget *label, *combobox;
gint index;
GArray *pl_ids = NULL;
Playlist *spl_orig;
iTunesDB *itdb;
GList *gl;
+ GtkListStore *store;
+ GtkTreeIter iter;
g_return_val_if_fail (spl_window, NULL);
g_return_val_if_fail (splr, NULL);
@@ -980,10 +987,10 @@ static GtkWidget *spl_create_hbox(GtkWidget *spl_window,
Itdb_SPLRule *splr) {
switch (at) {
case ITDB_SPLAT_STRING:
- entry = hbox_add_entry(hbox, splr, spl_ET_STRING);
+ hbox_add_entry(hbox, splr, spl_ET_STRING);
break;
case ITDB_SPLAT_INT:
- entry = hbox_add_entry(hbox, splr, spl_ET_FROMVALUE);
+ hbox_add_entry(hbox, splr, spl_ET_FROMVALUE);
/* check for unit */
index = comboentry_index_from_id(splfield_units, splr->field);
if (index != -1) {
@@ -993,14 +1000,14 @@ static GtkWidget *spl_create_hbox(GtkWidget *spl_window,
Itdb_SPLRule *splr) {
}
break;
case ITDB_SPLAT_DATE:
- entry = hbox_add_entry(hbox, splr, spl_ET_FROMVALUE_DATE);
+ hbox_add_entry(hbox, splr, spl_ET_FROMVALUE_DATE);
break;
case ITDB_SPLAT_RANGE_INT:
- entry = hbox_add_entry(hbox, splr, spl_ET_FROMVALUE);
+ hbox_add_entry(hbox, splr, spl_ET_FROMVALUE);
label = gtk_label_new(_("to"));
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX (hbox), label, FALSE, FALSE, 0);
- entry = hbox_add_entry(hbox, splr, spl_ET_TOVALUE),
+ hbox_add_entry(hbox, splr, spl_ET_TOVALUE),
/* check for unit */
index = comboentry_index_from_id(splfield_units, splr->field);
if (index != -1) {
@@ -1010,11 +1017,11 @@ static GtkWidget *spl_create_hbox(GtkWidget
*spl_window, Itdb_SPLRule *splr) {
}
break;
case ITDB_SPLAT_RANGE_DATE:
- entry = hbox_add_entry(hbox, splr, spl_ET_FROMVALUE_DATE);
+ hbox_add_entry(hbox, splr, spl_ET_FROMVALUE_DATE);
label = gtk_label_new(_("to"));
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX (hbox), label, FALSE, FALSE, 0);
- entry = hbox_add_entry(hbox, splr, spl_ET_TOVALUE_DATE);
+ hbox_add_entry(hbox, splr, spl_ET_TOVALUE_DATE);
/* check for unit */
index = comboentry_index_from_id(splfield_units, splr->field);
if (index != -1) {
@@ -1030,7 +1037,7 @@ static GtkWidget *spl_create_hbox(GtkWidget *spl_window,
Itdb_SPLRule *splr) {
splr->fromunits = splat_inthelast_units_comboentries[0].id;
splr->fromvalue *= ((double) units) / splr->fromunits;
}
- entry = hbox_add_entry(hbox, splr, spl_ET_INTHELAST);
+ hbox_add_entry(hbox, splr, spl_ET_INTHELAST);
combobox = gtk_combo_box_new();
gtk_widget_show(combobox);
gtk_box_pack_start(GTK_BOX (hbox), combobox, TRUE, TRUE, 0);
@@ -1038,7 +1045,10 @@ static GtkWidget *spl_create_hbox(GtkWidget *spl_window,
Itdb_SPLRule *splr) {
spl_set_combobox(GTK_COMBO_BOX (combobox),
splat_inthelast_units_comboentries, splr->fromunits, G_CALLBACK
(spl_fromunits_changed), spl_window);
break;
case ITDB_SPLAT_PLAYLIST:
- combobox = gtk_combo_box_new_text();
+ combobox = gtk_combo_box_new();
+ store = gtk_list_store_new(1, G_TYPE_STRING);
+ gtk_combo_box_set_model(GTK_COMBO_BOX(combobox),
GTK_TREE_MODEL(store));
+
gtk_widget_show(combobox);
gtk_box_pack_start(GTK_BOX (hbox), combobox, TRUE, TRUE, 0);
pl_ids = g_array_sized_new(TRUE, TRUE, sizeof(guint64),
itdb_playlists_number(itdb));
@@ -1047,11 +1057,15 @@ static GtkWidget *spl_create_hbox(GtkWidget
*spl_window, Itdb_SPLRule *splr) {
Playlist *pl = gl->next->data;
g_return_val_if_fail (pl, NULL);
if (pl != spl_orig) {
- gtk_combo_box_append_text(GTK_COMBO_BOX (combobox), pl->name);
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ 0, pl->name,
+ -1);
g_array_append_val (pl_ids, pl->id);
}
gl = gl->next;
}
+ g_object_unref(store);
g_object_set_data(G_OBJECT (combobox), "spl_rule", splr);
g_object_set_data_full(G_OBJECT (combobox), "spl_pl_ids", pl_ids,
(GDestroyNotify) spl_pl_ids_destroy);
if (splr->fromvalue == ITDB_SPL_DATE_IDENTIFIER)
@@ -1078,7 +1092,7 @@ static GtkWidget *spl_create_hbox(GtkWidget *spl_window,
Itdb_SPLRule *splr) {
spl_set_combobox(GTK_COMBO_BOX (combobox), use_centries,
splr->fromvalue, G_CALLBACK (spl_videokind_comboentry_changed), spl_window);
}
else { /* not supported: display as standard INT */
- entry = hbox_add_entry(hbox, splr, spl_ET_FROMVALUE);
+ hbox_add_entry(hbox, splr, spl_ET_FROMVALUE);
}
break;
case ITDB_SPLAT_NONE:
diff --git a/plugins/repository_editor/repository.c
b/plugins/repository_editor/repository.c
index 12b2c98..d3e2c69 100644
--- a/plugins/repository_editor/repository.c
+++ b/plugins/repository_editor/repository.c
@@ -180,7 +180,14 @@ void repository_init_model_number_combo(GtkComboBox *cb) {
messes up the entire layout) */
gtk_combo_box_set_model(cb, GTK_TREE_MODEL (store));
g_object_unref(store);
+
+ /* Avoid deprecated function */
+#if GTK_CHECK_VERSION(2,24,0)
+ gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (cb), COL_STRING);
+#else
gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY (cb), COL_STRING);
+#endif
+
gtk_cell_layout_clear(GTK_CELL_LAYOUT (cb));
renderer = gtk_cell_renderer_text_new();
diff --git a/plugins/repository_editor/repository_init.c
b/plugins/repository_editor/repository_init.c
index ed69c89..2c639ab 100644
--- a/plugins/repository_editor/repository_init.c
+++ b/plugins/repository_editor/repository_init.c
@@ -104,6 +104,7 @@ gboolean repository_ipod_init(iTunesDB *itdb) {
gchar buf[PATH_MAX];
GtkComboBox *cb;
const IpodInfo *info;
+ GtkTreeIter iter;
g_return_val_if_fail (itdb, FALSE);
@@ -174,7 +175,11 @@ gboolean repository_ipod_init(iTunesDB *itdb) {
g_free(new_mount);
new_mount = NULL;
}
- model = gtk_combo_box_get_active_text(GTK_COMBO_BOX (GET_WIDGET
(ii->builder, IID_MODEL_COMBO)));
+
+ g_return_val_if_fail(gtk_combo_box_get_active_iter(cb, &iter), FALSE);
+ gtk_tree_model_get(gtk_combo_box_get_model(cb), &iter, COL_STRING,
&model, -1);
+ g_return_val_if_fail(model, FALSE);
+
if ((strcmp(model, gettext(SELECT_OR_ENTER_YOUR_MODEL)) == 0) ||
(strlen(model) == 0)) { /* User didn't choose a model */
g_free(model);
model = NULL;
@@ -230,6 +235,7 @@ void repository_ipod_init_set_model(iTunesDB *itdb, const
gchar *old_model) {
gchar buf[PATH_MAX];
GtkComboBox *cb;
const IpodInfo *info;
+ GtkTreeIter iter;
g_return_if_fail (itdb);
@@ -275,7 +281,8 @@ void repository_ipod_init_set_model(iTunesDB *itdb, const
gchar *old_model) {
switch (response) {
case GTK_RESPONSE_OK:
- model = gtk_combo_box_get_active_text(GTK_COMBO_BOX (GET_WIDGET
(builder, SIMD_MODEL_COMBO)));
+ g_return_if_fail(gtk_combo_box_get_active_iter(cb, &iter));
+ gtk_tree_model_get(gtk_combo_box_get_model(cb), &iter, COL_STRING,
&model, -1);
if (!model) {
gtkpod_warning(_("Could not determine the model you selected --
this could be a bug or incompatibilty in the GTK+ or glade library.\n\n"));
}
diff --git a/plugins/sorttab_display/display_sorttabs.c
b/plugins/sorttab_display/display_sorttabs.c
index 2b7397f..66374a9 100644
--- a/plugins/sorttab_display/display_sorttabs.c
+++ b/plugins/sorttab_display/display_sorttabs.c
@@ -3227,26 +3227,44 @@ gint st_get_sort_tab_number(gchar *text) {
GtkWidget *mdialog;
GtkDialog *dialog;
GtkWidget *combo;
+ GtkCellRenderer *cell;
gint result;
gint i, nr, stn;
- gchar buf[20], *bufp;
+ gchar *bufp;
+ GtkListStore *store;
+ GtkTreeIter iter;
mdialog = gtk_message_dialog_new(GTK_WINDOW (gtkpod_app),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_OK_CANCEL, "%s", text);
dialog = GTK_DIALOG (mdialog);
- combo = gtk_combo_box_new_text();
- gtk_widget_show(combo);
- gtk_container_add(GTK_CONTAINER
(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), combo);
-
+ store = gtk_list_store_new(1, G_TYPE_STRING);
stn = prefs_get_int("sort_tab_num");
/* Create list */
for (i = 1; i <= stn; ++i) {
- sprintf(buf, "%d", i);
- gtk_combo_box_append_text(GTK_COMBO_BOX (combo), buf);
+ bufp = g_strdup_printf("%d", i);
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter, 0, bufp, -1);
+ g_free(bufp);
}
+ combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
+
+ /* Create cell renderer. */
+ cell = gtk_cell_renderer_text_new();
+
+ /* Pack it to the combo box. */
+ gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(combo), cell, TRUE );
+
+ /* Connect renderer to data source */
+ gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(combo), cell, "text", 0,
NULL );
+
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+
+ gtk_widget_show_all(combo);
+ gtk_container_add(GTK_CONTAINER
(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), combo);
+
result = gtk_dialog_run(GTK_DIALOG (mdialog));
/* free the list */
@@ -3254,12 +3272,19 @@ gint st_get_sort_tab_number(gchar *text) {
nr = -1; /* no selection */
}
else {
- bufp = gtk_combo_box_get_active_text(GTK_COMBO_BOX (combo));
- nr = atoi(bufp) - 1;
- last_nr = nr + 1;
+ gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter);
+ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 0, &bufp, -1);
+ if (bufp) {
+ nr = atoi(bufp) - 1;
+ last_nr = nr + 1;
+ g_free(bufp);
+ } else {
+ nr = -1; /* selection failed */
+ }
}
gtk_widget_destroy(mdialog);
+ g_object_unref(store);
return nr;
}
diff --git a/plugins/sorttab_display/sorttab_display_actions.c
b/plugins/sorttab_display/sorttab_display_actions.c
index c28dfa5..51f8ec0 100644
--- a/plugins/sorttab_display/sorttab_display_actions.c
+++ b/plugins/sorttab_display/sorttab_display_actions.c
@@ -65,14 +65,14 @@ static void delete_selected_entry(DeleteAction
deleteaction, gchar *text) {
entry = st_get_selected_entry(inst);
if (!entry) {
- gtkpod_statusbar_message(_("No entry selected in Sort Tab %d"), inst +
1);
+ gtkpod_statusbar_message(_("No entry selected in Filter Tab %d"), inst
+ 1);
return;
}
st_delete_entry_head(inst, deleteaction);
}
void on_delete_selected_entry_from_database(GtkAction *action,
SorttabDisplayPlugin* plugin) {
- delete_selected_entry(DELETE_ACTION_DATABASE, _("Remove entry of which
sort tab from database?"));
+ delete_selected_entry(DELETE_ACTION_DATABASE, _("Remove entry of which
filter tab from database?"));
}
void on_delete_selected_entry_from_ipod(GtkAction *action,
SorttabDisplayPlugin* plugin) {
@@ -104,13 +104,13 @@ void on_update_selected_tab_entry (GtkAction *action,
SorttabDisplayPlugin* plug
TabEntry *entry;
gint inst;
- inst = st_get_sort_tab_number(_("Update selected entry of which sort
tab?"));
+ inst = st_get_sort_tab_number(_("Update selected entry of which filter
tab?"));
if (inst == -1)
return;
entry = st_get_selected_entry(inst);
if (!entry) {
- gtkpod_statusbar_message(_("No entry selected in Sort Tab %d"), inst +
1);
+ gtkpod_statusbar_message(_("No entry selected in Filter Tab %d"), inst
+ 1);
return;
}
diff --git a/plugins/track_display/display_tracks.c
b/plugins/track_display/display_tracks.c
index 233de7c..2a881ba 100644
--- a/plugins/track_display/display_tracks.c
+++ b/plugins/track_display/display_tracks.c
@@ -621,7 +621,6 @@ void tm_add_track_to_track_model(Track *track, GtkTreeIter
*into_iter) {
}
gtk_list_store_set(get_model_as_store(model), &iter, READOUT_COL, track,
-1);
- /* update_model_view (model); -- not needed */
}
/* Used by remove_track() to remove track from model by calling
diff --git a/plugins/track_display/track_display_preferences.c
b/plugins/track_display/track_display_preferences.c
index 52a88e1..63abaae 100644
--- a/plugins/track_display/track_display_preferences.c
+++ b/plugins/track_display/track_display_preferences.c
@@ -378,6 +378,7 @@ static void trkcmd_combobox_changed(GtkComboBox *combo) {
static void populate_track_cmd_combo(GtkComboBox *combo) {
GtkListStore *store;
+ GtkTreeIter iter;
GtkCellRenderer *cell;
GList *trkcmds = gtkpod_get_registered_track_commands();
gint i = 0, activeindex = -1;
@@ -386,7 +387,6 @@ static void populate_track_cmd_combo(GtkComboBox *combo) {
store = gtk_list_store_new(1, G_TYPE_STRING);
gtk_combo_box_set_model(combo, GTK_TREE_MODEL (store));
- g_object_unref(store);
cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combo), cell, TRUE);
@@ -397,13 +397,16 @@ static void populate_track_cmd_combo(GtkComboBox *combo) {
for (i = 0; i < g_list_length(trkcmds); ++i) {
TrackCommand *cmd = g_list_nth_data(trkcmds, i);
- gtk_combo_box_append_text(combo, _(track_command_get_text(cmd)));
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, _(track_command_get_text(cmd)),
+ -1);
if (cmdpref && g_str_equal(cmdpref, track_command_get_id(cmd)))
activeindex = i;
}
if (activeindex > -1)
- gtk_combo_box_set_active(combo, activeindex);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo), activeindex);
g_signal_connect (combo, "changed",
G_CALLBACK (trkcmd_combobox_changed),
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2