[sound-juicer/gnome-3-18] genres: Simplify GtkListStore usage
- From: Phillip Wood <pwood src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sound-juicer/gnome-3-18] genres: Simplify GtkListStore usage
- Date: Tue, 22 Mar 2016 10:18:30 +0000 (UTC)
commit 13acc043f87687432c94e20a079a2f3e852d0482
Author: Bastien Nocera <hadess hadess net>
Date: Sat Nov 21 16:21:24 2015 +0100
genres: Simplify GtkListStore usage
Pointer arithmetic looks pretty gross, and GtkListStore has functions to
avoid needing to append an iter before inserting the values.
https://bugzilla.gnome.org/show_bug.cgi?id=758457
src/sj-genres.c | 35 +++++++++++++++++++++--------------
1 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/src/sj-genres.c b/src/sj-genres.c
index 5a4f477..fb63055 100644
--- a/src/sj-genres.c
+++ b/src/sj-genres.c
@@ -45,10 +45,19 @@ static const char* const known_genres[] = {
N_("Reggae"),
N_("Rock"),
N_("Soul"),
- N_("Spoken Word"),
- NULL
+ N_("Spoken Word")
};
+static gboolean is_known_genre (const char *str) {
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS(known_genres); i++) {
+ if (strcasecmp (str, known_genres[i]) == 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
static gboolean in_array (const char *str, const char** array) {
const char **list = array;
gboolean found = FALSE;
@@ -99,25 +108,23 @@ static char** saved_genres (void) {
static GtkTreeModel* create_genre_list (void) {
GtkListStore *store;
- const char * const *g = known_genres;
+ guint i;
char **genres;
store = gtk_list_store_new (1, G_TYPE_STRING);
- while (*g != NULL) {
- GtkTreeIter iter;
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, _(*g++), -1);
+ for (i = 0; i < G_N_ELEMENTS(known_genres); i++) {
+ gtk_list_store_insert_with_values (store, NULL, -1,
+ 0, _(known_genres[i]),
+ -1);
}
genres = saved_genres ();
if (genres) {
- char **list = genres;
-
- while (*list != NULL) {
- GtkTreeIter iter;
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, *list++, -1);
+ for (i = 0; genres[i] != NULL; i++) {
+ gtk_list_store_insert_with_values (store, NULL, -1,
+ 0, genres[i],
+ -1);
}
g_strfreev (genres);
@@ -153,7 +160,7 @@ void save_genre (GtkWidget *entry) {
genre = gtk_entry_get_text (GTK_ENTRY (entry));
- if (in_array ((const char *)genre, (const char **) known_genres))
+ if (is_known_genre (genre))
return;
len = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]