[gnac/devel] Improved 'gnac -l' output



commit ee04f8ce8501e6a3ed16d41536a052bef26bf0de
Author: Benoît Dupasquier <bdupasqu src gnome org>
Date:   Fri Mar 4 14:37:52 2011 +0000

    Improved 'gnac -l' output

 src/profiles/gnac-profiles-manager.c |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index 428e584..83f2334 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -293,7 +293,7 @@ gnac_profiles_mgr_list_profiles(void)
   gchar *last_used_profile = g_settings_get_string(settings,
       GNAC_KEY_LAST_USED_PROFILE);
 
-  guint count = 0;
+  GSList *profiles = NULL;
   while ((file_info = g_file_enumerator_next_file(files, NULL, NULL))) {
     if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) {
       profile_file = g_file_enumerator_get_container(files);
@@ -304,15 +304,8 @@ gnac_profiles_mgr_list_profiles(void)
       gnac_profiles_default_load_generic_audio_profile(profile_file_full_path,
           &profile);
       if (profile) {
-        const gchar *name = (profile->generic)->name;
-        gchar *count_str = g_strdup_printf("%u", count);
-        /* if last_used_profile is not set, assume the
-         * first profile was last used */
-        g_print("\t%2s) %s\n",
-            ((count == 0 && !last_used_profile) ||
-            g_str_equal(name, last_used_profile)) ? "*" : count_str, name);
-        count++;
-        g_free(count_str);
+        gpointer name = (profile->generic)->name;
+        profiles = g_slist_append(profiles, name);
       }
       /* Cleanup */
       g_free(profile_file_path);
@@ -321,15 +314,36 @@ gnac_profiles_mgr_list_profiles(void)
     g_object_unref(G_OBJECT(file_info));
   }
 
+  guint count = g_slist_length(profiles);
   if (count == 0) {
     g_print("\t");
     g_print(_("No profiles available"));
     g_print("\n");
+  } else {
+    /* check if last_used_profile exists */
+    if (!g_slist_find_custom(profiles, last_used_profile,
+        (GCompareFunc)g_strcmp0))
+    {
+      last_used_profile = NULL;
+    }
+    GSList *tmp;
+    for (tmp = profiles; tmp; tmp = g_slist_next(tmp)) {
+      gint pos = g_slist_position(profiles, tmp);
+      gchar *count_str = g_strdup_printf("%u", pos+1);
+      /* if last_used_profile is not set, assume the
+       * first profile was last used */
+      gchar *name = tmp->data;
+      gboolean found = ((pos == 0 && !last_used_profile)
+          || (last_used_profile && g_str_equal(name, last_used_profile)));
+      g_print("\t%2s) %s\n", found ? "*" : count_str, name);
+      g_free(count_str);
+    }
   }
 
   g_print("\n");
 
   /* Cleanup */
+  g_slist_free(profiles);
   g_free(last_used_profile);
   g_object_unref(dir);
   g_file_enumerator_close(files, NULL, NULL);



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