[gnac/devel] Added debug and verbose options.



commit 75dc08133d913cf4b34a1a23d20e8f2a59bcd8ba
Author: Benoît Dupasquier <bdupasqu src gnome org>
Date:   Sun Nov 29 16:47:32 2009 +0000

    Added debug and verbose options.

 configure.ac            |    2 +-
 libgnac/libgnac-debug.c |   35 ++++++----
 libgnac/libgnac-debug.h |    3 +
 man/gnac.1              |   10 ++-
 po/POTFILES.in          |    1 +
 src/Makefile.am         |    2 +
 src/gnac-main.c         |   49 ++------------
 src/gnac-main.h         |    3 +
 src/gnac-options.c      |  168 +++++++++++++++++++++++++++++++++++++++++++++++
 src/gnac-options.h      |   52 +++++++++++++++
 10 files changed, 264 insertions(+), 61 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 95183d8..60e4c63 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
 AC_PREREQ(2.60)
 
-AC_INIT([gnac], [0.3], [http://bugzilla.gnome.org/enter_bug.cgi?product=gnac])
+AC_INIT([gnac], [0.2.2], [http://bugzilla.gnome.org/enter_bug.cgi?product=gnac])
 
 AM_INIT_AUTOMAKE([dist-bzip2])
 AC_CONFIG_MACRO_DIR([m4])
diff --git a/libgnac/libgnac-debug.c b/libgnac/libgnac-debug.c
index e4e8a3d..a26d5e5 100644
--- a/libgnac/libgnac-debug.c
+++ b/libgnac/libgnac-debug.c
@@ -32,6 +32,9 @@
 
 #include "libgnac-debug.h"
 
+gboolean LIBGNAC_DEBUG;
+gboolean LIBGNAC_VERBOSE;
+
 void
 libgnac_debug_real(const gchar *func,
                    const gchar *file,
@@ -39,16 +42,17 @@ libgnac_debug_real(const gchar *func,
                    const gchar *format, 
                    ...)
 {
-#ifdef GNOME_ENABLE_DEBUG
-	va_list args;
-	char buffer[1025];
+  if (LIBGNAC_DEBUG)
+  {
+	  va_list args;
+	  char buffer[1025];
 
-	va_start(args, format);
-	g_vsnprintf(buffer, 1024, format, args);
-	va_end(args);
+	  va_start(args, format);
+	  g_vsnprintf(buffer, 1024, format, args);
+	  va_end(args);
 
-  g_printerr("[DEBUG] %s:%d: %s\n", file, line, buffer);
-#endif
+    g_printerr("[DEBUG] %s:%d: %s\n", file, line, buffer);
+  }
 }
 
 
@@ -91,12 +95,15 @@ libgnac_warning_real(const gchar *func,
 void
 libgnac_info(const gchar *format, ...)
 {
-	va_list args;
-	char buffer[1025];
+  if (LIBGNAC_VERBOSE)
+  {
+	  va_list args;
+	  char buffer[1025];
 
-	va_start(args, format);
-	g_vsnprintf(buffer, 1024, format, args);
-	va_end(args);
+	  va_start(args, format);
+	  g_vsnprintf(buffer, 1024, format, args);
+	  va_end(args);
 
-  g_print("[INFO] %s\n", buffer);
+    g_print("[INFO] %s\n", buffer);
+  }
 }
diff --git a/libgnac/libgnac-debug.h b/libgnac/libgnac-debug.h
index 255aea5..9cbdc84 100644
--- a/libgnac/libgnac-debug.h
+++ b/libgnac/libgnac-debug.h
@@ -64,6 +64,9 @@
 
 G_BEGIN_DECLS
 
+extern gboolean LIBGNAC_DEBUG;
+extern gboolean LIBGNAC_VERBOSE;
+
 void 
 libgnac_debug_real(const gchar *func,
 				           const gchar *file,
diff --git a/man/gnac.1 b/man/gnac.1
index 376aa03..28ccfeb 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 "2009\-11\-06" "GNOME"
+.TH gnac 1 "2009\-11\-29" "GNOME"
 
 .SH NAME
 Gnac \- GNOME desktop audio converter based on GStreamer 
@@ -32,13 +32,19 @@ files conversion between all GStreamer supported audio formats.
 
 .SH OPTIONS
 .TP
+.B \-\-debug
+Show debugging information
+.TP
+.B \-\-verbose
+Enable verbose output
+.TP
 .B \-\-version
 Show the version of the program and exit
 .TP
 .B \-\-display=DISPLAY
 X display to use
 .TP
-.B \-? ", "\-\-help
+.B \-? "," \-h "," \-\-help
 Show help options
 .TP
 .B \-\-help-all
diff --git a/po/POTFILES.in b/po/POTFILES.in
index de5b70f..1b05146 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -42,6 +42,7 @@ src/profiles/formats/gnac-profiles-unknown.c
 src/gnac-bars.c
 src/gnac-gconf.c
 src/gnac-main.c
+src/gnac-options.c
 src/gnac-playlist.c
 src/gnac-prefs.c
 src/gnac-properties.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 7955b35..3227b53 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,8 @@ gnac_SOURCES = \
 	gnac-file-list.c \
 	gnac-gconf.c \
 	gnac-gconf.h \
+	gnac-options.c \
+	gnac-options.h \
 	gnac-playlist.c \
 	gnac-playlist.h \
 	gnac-prefs.h \
diff --git a/src/gnac-main.c b/src/gnac-main.c
index c6a90f2..a53b111 100644
--- a/src/gnac-main.c
+++ b/src/gnac-main.c
@@ -44,6 +44,7 @@
 #include "gnac-gconf.h"
 #include "gnac-ui.h"
 #include "gnac-main.h"
+#include "gnac-options.h"
 #include "gnac-playlist.h"
 #include "gnac-prefs.h"
 #include "gnac-properties.h"
@@ -94,7 +95,7 @@ LibgnacMetadata         *metadata;
 static void
 gnac_change_state(GnacState new_state)
 {
-  
+
 #ifdef GNOME_ENABLE_DEBUG
   libgnac_info("State changed to %s", states[new_state]);
 #endif
@@ -294,7 +295,7 @@ gnac_add_files_thread_entry(gpointer data)
 
 
 //The GList is freed by the thread itself.
-static void
+void
 gnac_add_files(GSList *files)
 {
   GError *error = NULL;
@@ -1245,19 +1246,6 @@ gint
 main(gint    argc,
      gchar **argv)
 {
-  GOptionContext  *context;
-  gchar **args_filenames = NULL;
-  
-  const GOptionEntry entries[] = {
-    { "version", '\0',
-            G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
-            gnac_option_version_cb,
-            N_("Show the version of the program and exit"), NULL },
-    { G_OPTION_REMAINING, '\0',
-            0, G_OPTION_ARG_FILENAME_ARRAY, &args_filenames, NULL, NULL },
-    { NULL }
-  };
-
   if (!g_thread_supported()) g_thread_init(NULL);
 
   #ifdef ENABLE_NLS
@@ -1268,20 +1256,7 @@ main(gint    argc,
   #endif /* ENABLE_NLS */
 
   /* Parse command line arguments */
-  context = g_option_context_new(_("[URIs...] - Convert your audio files"));
-  g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
-  g_option_context_add_group(context, gst_init_get_option_group());
-  g_option_context_add_group(context, gtk_get_option_group(TRUE));
-
-  if (!g_option_context_parse(context, &argc, &argv, NULL))
-  {
-    gchar *help;
-    help = g_option_context_get_help(context, TRUE, NULL);
-    g_print("%s", help);
-    g_free(help);
-    exit(EXIT_FAILURE);
-  }
-  g_option_context_free(context);
+  gnac_options_init(argc, argv);
 
   /* make sure every window has its name and icon */
   g_set_application_name(APPNAME);
@@ -1336,21 +1311,7 @@ main(gint    argc,
   gnac_ui_show();
 
   /* Check if arguments have been passed through the command line */
-  GFile *arg_uri = NULL;
-  GSList *list_files = NULL;
-  if (args_filenames != NULL) 
-  {
-    gint i;
-    gint len = g_strv_length(args_filenames);
-    for (i = 0; i < len; i++) 
-    {
-      arg_uri = g_file_new_for_commandline_arg(args_filenames[i]);
-      list_files = g_slist_append(list_files, arg_uri);
-    }
-    if (list_files != NULL) gnac_add_files(list_files);
-    g_strfreev(args_filenames);
-    args_filenames = NULL;
-  }
+  gnac_options_process_late();
 
   gdk_threads_enter();
   gtk_main();
diff --git a/src/gnac-main.h b/src/gnac-main.h
index 21f3198..bae59f5 100644
--- a/src/gnac-main.h
+++ b/src/gnac-main.h
@@ -43,6 +43,9 @@ typedef enum {
 void
 gnac_add_file(GFile *file);
 
+void
+gnac_add_files(GSList *files);
+
 /* UI Callbacks */
 
 void
diff --git a/src/gnac-options.c b/src/gnac-options.c
new file mode 100644
index 0000000..49101a9
--- /dev/null
+++ b/src/gnac-options.c
@@ -0,0 +1,168 @@
+/*
+ * This file is part of GNAC - Gnome Audio Converter
+ *
+ * Copyright (C) 2007 - 2009 Gnac
+ *    
+ *    - DUPASQUIER  Benoit    <bdupasqu src gnome org>
+ *    - JOAQUIM     David     <djoaquim src gnome org>
+ *    - ROUX        Alexandre <alexroux src gnome org>
+ *
+ * GNAC is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNAC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNAC; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <glib/gi18n.h>
+
+#include "gnac.h"
+#include "gnac-main.h"
+#include "gnac-options.h"
+#include "libgnac-debug.h"
+
+
+static gboolean
+gnac_options_debug_cb(const gchar  *option_name,
+                      const gchar  *value,
+                      gpointer      data,
+                      GError      **error);
+
+static gboolean
+gnac_options_verbose_cb(const gchar  *option_name,
+                        const gchar  *value,
+                        gpointer      data,
+                        GError      **error);
+
+G_GNUC_NORETURN static gboolean
+gnac_options_version_cb(const gchar  *option_name,
+                        const gchar  *value,
+                        gpointer      data,
+                        GError      **error);
+
+static void
+gnac_options_process_filenames(void);
+
+
+GnacCmdLineOptions options;
+
+const GOptionEntry all_options[] = {
+  { "debug", '\0', 
+        G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+        gnac_options_debug_cb,
+        N_("Show debugging information"), NULL },
+  { "verbose", '\0', 
+        G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+        gnac_options_verbose_cb,
+        N_("Enable verbose output"), NULL },
+  { "version", '\0', 
+        G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, 
+        gnac_options_version_cb,
+        N_("Show the version of the program and exit"), NULL },
+  { G_OPTION_REMAINING, '\0', 
+        0, G_OPTION_ARG_FILENAME_ARRAY, 
+        &options.filenames, 
+        NULL, NULL },
+  { NULL }
+};
+
+
+static gboolean
+gnac_options_debug_cb(const gchar  *option_name,
+                      const gchar  *value,
+                      gpointer      data,
+                      GError      **error)
+{
+  LIBGNAC_DEBUG = TRUE;
+  return gnac_options_verbose_cb(option_name, value, data, error);
+}
+
+
+static gboolean
+gnac_options_verbose_cb(const gchar  *option_name,
+                        const gchar  *value,
+                        gpointer      data,
+                        GError      **error)
+{
+  LIBGNAC_VERBOSE = TRUE;
+  return TRUE;
+}
+
+
+G_GNUC_NORETURN static gboolean
+gnac_options_version_cb(const gchar  *option_name,
+                        const gchar  *value,
+                        gpointer      data,
+                        GError      **error)
+{
+  g_print("%s %s\n", APPNAME, VERSION);
+  exit(EXIT_SUCCESS);
+}
+
+
+static void
+gnac_options_process_filenames(void)
+{
+  GSList *list_files = NULL; 
+  if (options.filenames)
+  {
+    gint i, len;
+    GFile  *uri;
+    len = g_strv_length(options.filenames);
+    for (i = 0; i < len; i++)
+    {
+      uri = g_file_new_for_commandline_arg(options.filenames[i]);
+      list_files = g_slist_append(list_files, uri);
+    }
+    gnac_add_files(list_files);
+    g_strfreev(options.filenames);
+  }
+}
+
+
+void
+gnac_options_init(gint    argc, 
+                  gchar **argv)
+{
+  GError *error = NULL;
+  GOptionContext *context;
+
+  context = g_option_context_new(_("[URI...] - Convert your audio files"));
+  g_option_context_add_main_entries(context, all_options, GETTEXT_PACKAGE);
+  g_option_context_add_group(context, gst_init_get_option_group());
+  g_option_context_add_group(context, gtk_get_option_group(TRUE));
+
+  if (!g_option_context_parse(context, &argc, &argv, &error))
+  {
+    if (error) {
+      g_print("%s\n", error->message);
+      g_clear_error(&error);
+    }
+    g_print(_("Run '%s --help' to see a full list "
+              "of available command line options.\n"), 
+              argv[0]);
+    exit(EXIT_FAILURE);
+  }
+
+  g_option_context_free(context);
+}
+
+
+void
+gnac_options_process_late(void)
+{
+  gnac_options_process_filenames();
+}
diff --git a/src/gnac-options.h b/src/gnac-options.h
new file mode 100644
index 0000000..93be034
--- /dev/null
+++ b/src/gnac-options.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of GNAC - Gnome Audio Converter
+ *
+ * Copyright (C) 2007 - 2009 Gnac
+ *    
+ *    - DUPASQUIER  Benoit    <bdupasqu src gnome org>
+ *    - JOAQUIM     David     <djoaquim src gnome org>
+ *    - ROUX        Alexandre <alexroux src gnome org>
+ *
+ * GNAC is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNAC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNAC; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef GNAC_OPTIONS_H
+#define GNAC_OPTIONS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct {
+  gboolean   debug;
+  gboolean   verbose;
+  gchar    **filenames;
+} GnacCmdLineOptions;
+
+extern GnacCmdLineOptions options;
+
+void
+gnac_options_init(gint argc, gchar **argv);
+
+//void 
+//gnac_options_process_early(void);
+
+void 
+gnac_options_process_late(void);
+
+G_END_DECLS
+
+#endif /* GNAC_OPTIONS_H */



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