[gnac/devel] Added '-l' command-line option



commit dc5f30b450e8b2efe1bcdb785bd70d1062450efb
Author: Benoît Dupasquier <bdupasqu src gnome org>
Date:   Sat Oct 2 10:33:01 2010 +0100

    Added '-l' command-line option

 man/gnac.1                           |    5 +-
 src/gnac-options.c                   |   22 +++++++
 src/profiles/gnac-profiles-manager.c |  106 ++++++++++++++++++++++++++++++++++
 src/profiles/gnac-profiles-manager.h |    3 +
 4 files changed, 135 insertions(+), 1 deletions(-)
---
diff --git a/man/gnac.1 b/man/gnac.1
index 1c6ae36..48798bb 100644
--- a/man/gnac.1
+++ b/man/gnac.1
@@ -15,7 +15,7 @@
 .\" along with GNAC; if not, write to the Free Software
 .\" Foundation, Inc., 51 Franklin St, Fifth Floor, 
 .\" Boston, MA  02110-1301  USA
-.TH gnac 1 "2010\-09\-28" "GNOME"
+.TH gnac 1 "2010\-10\-02" "GNOME"
 
 .SH NAME
 Gnac \- Audio converter for GNOME
@@ -35,6 +35,9 @@ files conversion between all GStreamer supported audio formats.
 .B \-a, \-\-audio-profile=name
 Use audio profile 'name'
 .TP
+.B \-l, \-\-list-profiles
+List available profiles and exit
+.TP
 .B \-\-debug
 Show debugging information
 .TP
diff --git a/src/gnac-options.c b/src/gnac-options.c
index f2f15cb..7386c83 100644
--- a/src/gnac-options.c
+++ b/src/gnac-options.c
@@ -33,6 +33,7 @@
 #include "gnac-main.h"
 #include "gnac-options.h"
 #include "libgnac-debug.h"
+#include "profiles/gnac-profiles-manager.h"
 
 
 static gboolean
@@ -41,6 +42,12 @@ gnac_options_audio_profile_cb(const gchar  *option_name,
                               gpointer      data,
                               GError      **error);
 
+G_GNUC_NORETURN static gboolean
+gnac_options_list_profiles_cb(const gchar  *option_name,
+                              const gchar  *value,
+                              gpointer      data,
+                              GError      **error);
+
 static gboolean
 gnac_options_debug_cb(const gchar  *option_name,
                       const gchar  *value,
@@ -66,6 +73,10 @@ const GOptionEntry all_options[] = {
         0, G_OPTION_ARG_CALLBACK,
         gnac_options_audio_profile_cb,
         N_("Use audio profile 'name'"), N_("name") },
+  { "list-profiles", 'l',
+        G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+        gnac_options_list_profiles_cb,
+        N_("List available profiles and exit"), NULL },
   { "debug", '\0', 
         G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
         gnac_options_debug_cb,
@@ -98,6 +109,17 @@ gnac_options_audio_profile_cb(const gchar  *option_name,
 }
 
 
+G_GNUC_NORETURN static gboolean
+gnac_options_list_profiles_cb(const gchar  *option_name,
+                              const gchar  *value,
+                              gpointer      data,
+                              GError      **error)
+{
+  gnac_profiles_mgr_list_profiles();
+  gnac_exit(EXIT_SUCCESS);
+}
+
+
 static gboolean
 gnac_options_debug_cb(const gchar  *option_name,
                       const gchar  *value,
diff --git a/src/profiles/gnac-profiles-manager.c b/src/profiles/gnac-profiles-manager.c
index 6e15bc3..a283d93 100644
--- a/src/profiles/gnac-profiles-manager.c
+++ b/src/profiles/gnac-profiles-manager.c
@@ -32,7 +32,9 @@
 #include <glib/gi18n.h>
 #include <stdlib.h>
 
+#include "gnac-gconf.h"
 #include "gnac-main.h"
+#include "gnac-profiles-default.h"
 #include "gnac-profiles-manager.h"
 #include "libgnac-debug.h"
 
@@ -226,6 +228,110 @@ gnac_profiles_mgr_set_parent(GtkWidget *parent)
 }
 
 
+static GFile *
+gnac_profiles_mgr_get_profiles_dir(void)
+{
+  GFile  *dir;
+  GError *error = NULL;
+
+  saved_profiles_dir = g_build_filename(g_get_home_dir(),
+      ".gnac", "profiles", NULL);
+  dir = g_file_new_for_path(saved_profiles_dir);
+  if (!g_file_query_exists(dir, NULL)) {
+    if (!g_file_make_directory_with_parents(dir, NULL, &error)) {
+      libgnac_warning("%s: %s",
+          _("Unable to create the profiles directory"), error->message);
+      g_error_free(error);
+      return NULL;
+    } else {
+      gnac_profiles_mgr_import_default_profiles();
+    }
+  }
+  return dir;
+}
+
+
+void
+gnac_profiles_mgr_list_profiles(void)
+{
+  AudioProfileGeneric *profile;
+  const gchar         *profile_file_name;
+  gchar               *profile_file_full_path;
+  gchar               *profile_file_path;
+  GError              *error = NULL;
+  GFile               *dir;
+  GFile               *profile_file;
+  GFileEnumerator     *files;
+  GFileInfo           *file_info;
+
+  dir = gnac_profiles_mgr_get_profiles_dir();
+  if (!dir) return;
+
+  files = g_file_enumerate_children(dir,
+      G_FILE_ATTRIBUTE_STANDARD_NAME ","
+      G_FILE_ATTRIBUTE_STANDARD_TYPE,
+      G_FILE_QUERY_INFO_NONE, NULL, &error);
+
+  if (!files) {
+    g_error_free(error);
+    /* no profiles found, try to import the default ones */
+    gnac_profiles_mgr_import_default_profiles();
+    files = g_file_enumerate_children(dir,
+        G_FILE_ATTRIBUTE_STANDARD_NAME ","
+        G_FILE_ATTRIBUTE_STANDARD_TYPE,
+        G_FILE_QUERY_INFO_NONE, NULL, &error);
+    if (!files) {
+      g_printerr(_("No profiles available"));
+      libgnac_warning("%s", error->message);
+      g_error_free(error);
+      return;
+    }
+  }
+
+  g_print(_("Available audio profiles:"));
+  g_print("\n\n");
+
+  guint count = 0;
+  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);
+      profile_file_path = g_file_get_path(profile_file);
+      profile_file_name = g_file_info_get_name(file_info);
+      profile_file_full_path = g_build_filename(profile_file_path,
+          profile_file_name, NULL);
+      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);
+        g_print("\t%2s) %s\n", g_str_equal(name,
+            gnac_gconf_get_string(GNAC_GCONF_LAST_USED_PROFILE)) ?
+                "*" : count_str, name);
+        count++;
+        g_free(count_str);
+      }
+      /* Cleanup */
+      g_free(profile_file_path);
+      g_free(profile_file_full_path);
+    }
+    g_object_unref(G_OBJECT(file_info));
+  }
+
+  if (count == 0) {
+    g_print("\t");
+    g_print(_("No profiles available"));
+    g_print("\n");
+  }
+
+  g_print("\n");
+
+  /* Cleanup */
+  g_object_unref(dir);
+  g_file_enumerator_close(files, NULL, NULL);
+  g_object_unref(files);
+}
+
+
 static void
 gnac_profiles_mgr_populate(void)
 { 
diff --git a/src/profiles/gnac-profiles-manager.h b/src/profiles/gnac-profiles-manager.h
index d33a2fc..7e50863 100644
--- a/src/profiles/gnac-profiles-manager.h
+++ b/src/profiles/gnac-profiles-manager.h
@@ -37,6 +37,9 @@ gnac_profiles_mgr_init(StandardCallBack call_back);
 void
 gnac_profiles_mgr_set_parent(GtkWidget *parent);
 
+void
+gnac_profiles_mgr_list_profiles(void);
+
 GList *
 gnac_profiles_mgr_get_profiles_list(void);
 



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