[recipes] Populate cuisine combobox with all the cuisines



commit ac868b2479683919ffea4eea73f0004cf1e629c8
Author: Ekta Nandwani <mailnandwaniekta gmail com>
Date:   Mon Mar 20 14:51:05 2017 +0530

    Populate cuisine combobox with all the cuisines
    
    Uses gr_recipe_store_get_all_cuisines api to get the cuisines from a hashtable
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779618

 src/gr-edit-page.c |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 3b583bd..f1ae294 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -366,17 +366,26 @@ edit_page_finalize (GObject *object)
 static void
 populate_cuisine_combo (GrEditPage *page)
 {
-        const char **names;
+        GArray *cuisine_names = g_array_new (FALSE, TRUE, sizeof (char *));
+        g_autofree char **names = NULL;
+        guint length;
         const char *title;
-        int length;
         int i;
+        GrRecipeStore *store;
 
-        names = gr_cuisine_get_names (&length);
-        for (i = 0; i < length; i++) {
-                gr_cuisine_get_data (names[i], &title, NULL, NULL);
-                gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (page->cuisine_combo),
-                                           names[i],
-                                           title);
+        store = gr_recipe_store_get ();
+        names = gr_recipe_store_get_all_cuisines (store, &length);
+        gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (page->cuisine_combo));
+
+        for (i = 0; i < length; ++i) {
+                char *temp_cuisine_name;
+                cuisine_names = g_array_append_val (cuisine_names, names[i]);
+                temp_cuisine_name = g_strstrip (g_array_index (cuisine_names, char *, i));
+                if (strcmp (temp_cuisine_name, "") != 0) {
+                        gr_cuisine_get_data (temp_cuisine_name, &title, NULL, NULL);
+                        gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (page->cuisine_combo),
+                                                                       temp_cuisine_name, title);
+                }
         }
 }
 
@@ -2305,7 +2314,7 @@ gr_edit_page_save (GrEditPage *page)
                 if (ret)
                         g_set_object (&page->recipe, recipe);
         }
-
+        populate_cuisine_combo (page);
         if (ret) {
                 gr_image_viewer_persist_changes (GR_IMAGE_VIEWER (page->images));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]