[gnome-packagekit] Update to a better version of the egg-debug code



commit 3d2e47c9164e2713bd8bed150d790a734e2b75b1
Author: Richard Hughes <richard hughsie com>
Date:   Mon Nov 23 12:17:14 2009 +0000

    Update to a better version of the egg-debug code

 src/Makefile.am                |    4 -
 src/egg-debug.c                |  321 ++++++++++++++++++++++++++++++----------
 src/egg-debug.h                |   26 ++--
 src/gpk-application-main.c     |   10 +-
 src/gpk-backend-status.c       |    9 +-
 src/gpk-install-catalog.c      |    9 +-
 src/gpk-install-local-file.c   |    9 +-
 src/gpk-install-mime-type.c    |    9 +-
 src/gpk-install-package-name.c |    9 +-
 src/gpk-install-provide-file.c |    9 +-
 src/gpk-log.c                  |    9 +-
 src/gpk-prefs.c                |    9 +-
 src/gpk-repo.c                 |    9 +-
 src/gpk-self-test.c            |    2 +-
 src/gpk-service-pack.c         |   14 +-
 src/gpk-update-icon.c          |    9 +-
 src/gpk-update-viewer-main.c   |   15 +--
 17 files changed, 303 insertions(+), 179 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a9b6424..7956fbf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,10 +27,6 @@ INCLUDES =						\
 	-DLOCALEDIR=\""$(localedir)"\"			\
 	-DVERSION="\"$(VERSION)\"" 			\
 	-DGPK_DATA=\"$(pkgdatadir)\"			\
-	-DEGG_LOG_FILE=\"\"				\
-	-DEGG_VERBOSE="\"GPK_VERBOSE\""			\
-	-DEGG_LOGGING="\"GPK_LOGGING\""			\
-	-DEGG_CONSOLE="\"GPK_CONSOLE\""			\
 	$(NULL)
 
 bin_PROGRAMS =						\
diff --git a/src/egg-debug.c b/src/egg-debug.c
index dff185e..77bfa20 100644
--- a/src/egg-debug.c
+++ b/src/egg-debug.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2007-2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2007-2009 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -58,18 +58,79 @@
 #define CONSOLE_CYAN		36
 #define CONSOLE_WHITE		37
 
-static gint fd = -1;
+static gint _fd = -1;
+static gboolean _verbose = FALSE;
+static gboolean _console = FALSE;
+static gchar *_log_filename = NULL;
+static gboolean _initialized = FALSE;
+static GPtrArray *_modules_array = NULL;
+static GPtrArray *_functions_array = NULL;
+static gchar **_modules = NULL;
+static gchar **_functions = NULL;
 
 /**
- * pk_set_console_mode:
+ * egg_debug_filter_module:
+ **/
+static gboolean
+egg_debug_filter_module (const gchar *filename)
+{
+	gchar *module;
+	const gchar *module_tmp;
+	guint i;
+	gboolean ret = FALSE;
+
+	/* nothing filtering */
+	if (_modules_array == NULL)
+		return FALSE;
+
+	/* are we in the filter list */
+	module = g_strdup (filename);
+	g_strdelimit (module, ".", '\0');
+	for (i=0; i<_modules_array->len; i++) {
+		module_tmp = g_ptr_array_index (_modules_array, i);
+		if (g_strcmp0 (module_tmp, module) == 0) {
+			ret = TRUE;
+			break;
+		}
+	}
+	return ret;
+}
+
+/**
+ * egg_debug_filter_function:
+ **/
+static gboolean
+egg_debug_filter_function (const gchar *function)
+{
+	guint i;
+	const gchar *function_tmp;
+	gboolean ret = FALSE;
+
+	/* nothing filtering */
+	if (_functions_array == NULL)
+		return FALSE;
+
+	/* are we in the filter list */
+	for (i=0; i<_functions_array->len; i++) {
+		function_tmp = g_ptr_array_index (_functions_array, i);
+		if (g_str_has_prefix (function, function_tmp)) {
+			ret = TRUE;
+			break;
+		}
+	}
+	return ret;
+}
+
+/**
+ * egg_debug_set_console_mode:
  **/
 static void
-pk_set_console_mode (guint console_code)
+egg_debug_set_console_mode (guint console_code)
 {
 	gchar command[13];
 
 	/* don't put extra commands into logs */
-	if (!egg_debug_is_console ())
+	if (!_console)
 		return;
 
 	/* Command is the control command to the terminal */
@@ -92,48 +153,50 @@ egg_debug_backtrace (void)
 	call_stack_size = backtrace (call_stack, G_N_ELEMENTS (call_stack));
 	symbols = backtrace_symbols (call_stack, call_stack_size);
 	if (symbols != NULL) {
-		pk_set_console_mode (CONSOLE_RED);
+		egg_debug_set_console_mode (CONSOLE_RED);
 		g_print ("Traceback:\n");
 		while (i < call_stack_size) {
 			g_print ("\t%s\n", symbols[i]);
 			i++;
 		}
-		pk_set_console_mode (CONSOLE_RESET);
+		egg_debug_set_console_mode (CONSOLE_RESET);
 		free (symbols);
 	}
 #endif
 }
 
 /**
- * pk_log_line:
+ * egg_debug_log_line:
  **/
 static void
-pk_log_line (const gchar *buffer)
+egg_debug_log_line (const gchar *buffer)
 {
 	ssize_t count;
+
 	/* open a file */
-	if (fd == -1) {
+	if (_fd == -1) {
 		/* ITS4: ignore, /var/log/foo is owned by root, and this is just debug text */
-		fd = open (EGG_LOG_FILE, O_WRONLY|O_APPEND|O_CREAT, 0777);
-		if (fd == -1)
-			g_error ("could not open log: '%s'", EGG_LOG_FILE);
+		_fd = open (_log_filename, O_WRONLY|O_APPEND|O_CREAT, 0777);
+		if (_fd == -1)
+			g_error ("could not open log: '%s'", _log_filename);
 	}
 
 	/* ITS4: ignore, debug text always NULL terminated */
-	count = write (fd, buffer, strlen (buffer));
+	count = write (_fd, buffer, strlen (buffer));
 	if (count == -1)
 		g_warning ("could not write %s", buffer);
+
 	/* newline */
-	count = write (fd, "\n", 1);
+	count = write (_fd, "\n", 1);
 	if (count == -1)
 		g_warning ("could not write newline");
 }
 
 /**
- * pk_print_line:
+ * egg_debug_print_line:
  **/
 static void
-pk_print_line (const gchar *func, const gchar *file, const int line, const gchar *buffer, guint color)
+egg_debug_print_line (const gchar *func, const gchar *file, const int line, const gchar *buffer, guint color)
 {
 	gchar *str_time;
 	gchar *header;
@@ -148,18 +211,18 @@ pk_print_line (const gchar *func, const gchar *file, const int line, const gchar
 	g_free (str_time);
 
 	/* always in light green */
-	pk_set_console_mode (CONSOLE_GREEN);
+	egg_debug_set_console_mode (CONSOLE_GREEN);
 	printf ("%s\n", header);
 
 	/* different colors according to the severity */
-	pk_set_console_mode (color);
+	egg_debug_set_console_mode (color);
 	printf (" - %s\n", buffer);
-	pk_set_console_mode (CONSOLE_RESET);
+	egg_debug_set_console_mode (CONSOLE_RESET);
 
 	/* log to a file */
-	if (egg_debug_is_logging ()) {
-		pk_log_line (header);
-		pk_log_line (buffer);
+	if (_log_filename != NULL) {
+		egg_debug_log_line (header);
+		egg_debug_log_line (buffer);
 	}
 
 	/* flush this output, as we need to debug */
@@ -177,16 +240,16 @@ egg_debug_real (const gchar *func, const gchar *file, const int line, const gcha
 	va_list args;
 	gchar *buffer = NULL;
 
-	if (!egg_debug_enabled ())
+	if (!_verbose && !egg_debug_filter_module (file) && !egg_debug_filter_function (func))
 		return;
 
 	va_start (args, format);
 	g_vasprintf (&buffer, format, args);
 	va_end (args);
 
-	pk_print_line (func, file, line, buffer, CONSOLE_BLUE);
+	egg_debug_print_line (func, file, line, buffer, CONSOLE_BLUE);
 
-	g_free(buffer);
+	g_free (buffer);
 }
 
 /**
@@ -198,7 +261,7 @@ egg_warning_real (const gchar *func, const gchar *file, const int line, const gc
 	va_list args;
 	gchar *buffer = NULL;
 
-	if (!egg_debug_enabled ())
+	if (!_verbose && !egg_debug_filter_module (file) && !egg_debug_filter_function (func))
 		return;
 
 	va_start (args, format);
@@ -206,11 +269,11 @@ egg_warning_real (const gchar *func, const gchar *file, const int line, const gc
 	va_end (args);
 
 	/* do extra stuff for a warning */
-	if (!egg_debug_is_console ())
+	if (!_console)
 		printf ("*** WARNING ***\n");
-	pk_print_line (func, file, line, buffer, CONSOLE_RED);
+	egg_debug_print_line (func, file, line, buffer, CONSOLE_RED);
 
-	g_free(buffer);
+	g_free (buffer);
 }
 
 /**
@@ -227,10 +290,10 @@ egg_error_real (const gchar *func, const gchar *file, const int line, const gcha
 	va_end (args);
 
 	/* do extra stuff for a warning */
-	if (!egg_debug_is_console ())
+	if (!_console)
 		printf ("*** ERROR ***\n");
-	pk_print_line (func, file, line, buffer, CONSOLE_RED);
-	g_free(buffer);
+	egg_debug_print_line (func, file, line, buffer, CONSOLE_RED);
+	g_free (buffer);
 
 	/* we want to fix this! */
 	egg_debug_backtrace ();
@@ -239,75 +302,181 @@ egg_error_real (const gchar *func, const gchar *file, const int line, const gcha
 }
 
 /**
- * egg_debug_enabled:
+ * egg_debug_is_verbose:
  *
  * Returns: TRUE if we have debugging enabled
  **/
 gboolean
-egg_debug_enabled (void)
+egg_debug_is_verbose (void)
 {
-	const gchar *env;
-	env = g_getenv (EGG_VERBOSE);
-	return (g_strcmp0 (env, "1") == 0);
+	return _verbose;
 }
 
 /**
- * egg_debug_is_logging:
- *
- * Returns: TRUE if we have logging enabled
+ * egg_debug_set_log_filename:
  **/
-gboolean
-egg_debug_is_logging (void)
+void
+egg_debug_set_log_filename (const gchar *filename)
 {
-	const gchar *env;
-	env = g_getenv (EGG_LOGGING);
-	return (g_strcmp0 (env, "1") == 0);
+	g_free (_log_filename);
+	_log_filename = g_strdup (filename);
 }
 
 /**
- * egg_debug_is_console:
- *
- * Returns: TRUE if we have debugging enabled
+ * egg_debug_strv_split_to_ptr_array:
  **/
-gboolean
-egg_debug_is_console (void)
+static GPtrArray *
+egg_debug_strv_split_to_ptr_array (gchar **modules)
+{
+	GPtrArray *array = NULL;
+	guint i, j;
+	gchar **split;
+
+	/* nothing */
+	if (modules == NULL)
+		goto out;
+
+	/* create array of strings */
+	array = g_ptr_array_new_with_free_func (g_free);
+
+	/* parse each --debug-foo option */
+	for (i=0; modules[i] != NULL; i++) {
+		/* use a comma to delimit multiple entries */
+		split = g_strsplit (modules[i], ",", -1);
+		for (j=0; split[j] != NULL; j++)
+			g_ptr_array_add (array, g_strdup (split[j]));
+		g_strfreev (split);
+	}
+out:
+	return array;
+}
+
+/**
+ * egg_debug_pre_parse_hook:
+ */
+static gboolean
+egg_debug_pre_parse_hook (GOptionContext *context, GOptionGroup *group, gpointer data, GError **error)
 {
-	const gchar *env;
-	env = g_getenv (EGG_CONSOLE);
-	return (g_strcmp0 (env, "1") == 0);
+	const gchar *env_string;
+	const GOptionEntry main_entries[] = {
+		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &_verbose,
+		  /* TRANSLATORS: turn on all debugging */
+		  N_("Show debugging information for all files"), NULL },
+		{ NULL}
+	};
+
+	/* global variable */
+	env_string = g_getenv ("VERBOSE");
+	if (env_string != NULL)
+		_verbose = TRUE;
+
+	/* add main entry */
+	g_option_context_add_main_entries (context, main_entries, NULL);
+
+	return TRUE;
 }
 
 /**
- * egg_debug_set_logging:
+ * egg_debug_free:
  **/
-void
-egg_debug_set_logging (gboolean enabled)
+static void
+egg_debug_free (void)
 {
-	if (enabled)
-		g_setenv (EGG_LOGGING, "1", TRUE);
-	else
-		g_setenv (EGG_LOGGING, "0", TRUE);
+	if (!_initialized)
+		return;
+
+	/* close file */
+	if (_fd != -1)
+		close (_fd);
+
+	/* free memory */
+	g_free (_log_filename);
+	if (_modules_array != NULL)
+		g_ptr_array_unref (_modules_array);
+	if (_functions_array != NULL)
+		g_ptr_array_unref (_functions_array);
+	g_strfreev (_modules);
+	g_strfreev (_functions);
+
+	/* can not re-init */
+	_initialized = FALSE;
+}
+
+/**
+ * egg_debug_post_parse_hook:
+ */
+static gboolean
+egg_debug_post_parse_hook (GOptionContext *context, GOptionGroup *group, gpointer data, GError **error)
+{
+	_initialized = TRUE;
+	_modules_array = egg_debug_strv_split_to_ptr_array (_modules);
+	_functions_array = egg_debug_strv_split_to_ptr_array (_functions);
+	_console = (isatty (fileno (stdout)) == 1);
+	egg_debug ("Verbose debugging %i (on console %i)", _verbose, _console);
+
+	/* run this function on cleanup */
+	atexit (egg_debug_free);
+
+	return TRUE;
+}
 
-	if (egg_debug_is_logging ())
-		egg_debug ("logging to %s", EGG_LOG_FILE);
+/**
+ * egg_debug_get_option_group:
+ *
+ * Returns a #GOptionGroup for the commandline arguments recognized
+ * by debugging. You should add this group to your #GOptionContext
+ * with g_option_context_add_group(), if you are using
+ * g_option_context_parse() to parse your commandline arguments.
+ *
+ * Returns: a #GOptionGroup for the commandline arguments
+ */
+GOptionGroup *
+egg_debug_get_option_group (void)
+{
+	GOptionGroup *group;
+	const GOptionEntry debug_entries[] = {
+		{ "debug-modules", '\0', 0, G_OPTION_ARG_STRING_ARRAY, &_modules,
+		  /* TRANSLATORS: a list of modules to debug */
+		  N_("Debug these specific modules"), NULL },
+		{ "debug-functions", '\0', 0, G_OPTION_ARG_STRING_ARRAY, &_functions,
+		  /* TRANSLATORS: a list of functions to debug */
+		  N_("Debug these specific functions"), NULL },
+		{ "debug-log-filename", '\0', 0, G_OPTION_ARG_STRING, &_log_filename,
+		  /* TRANSLATORS: save to a log */
+		  N_("Log debugging data to a file"), NULL },
+		{ NULL}
+	};
+
+	group = g_option_group_new ("debug", _("Debugging Options"), _("Show debugging options"), NULL, NULL);
+	g_option_group_set_parse_hooks (group, egg_debug_pre_parse_hook, egg_debug_post_parse_hook);
+	g_option_group_add_entries (group, debug_entries);
+	return group;
 }
 
 /**
  * egg_debug_init:
- * @debug: If we should print out verbose logging
+ * @argc: a pointer to the number of command line arguments.
+ * @argv: a pointer to the array of command line arguments.
+ *
+ * Parses command line arguments.
+ *
+ * Return value: %TRUE if initialization succeeded, otherwise %FALSE.
  **/
-void
-egg_debug_init (gboolean debug)
+gboolean
+egg_debug_init (gint *argc, gchar ***argv)
 {
-	/* check if we are on console */
-	if (isatty (fileno (stdout)) == 1)
-		g_setenv (EGG_CONSOLE, "1", FALSE);
-	else
-		g_setenv (EGG_CONSOLE, "0", FALSE);
-	if (debug)
-		g_setenv (EGG_VERBOSE, "1", FALSE);
-	else
-		g_setenv (EGG_VERBOSE, "0", FALSE);
-	egg_debug ("Verbose debugging %i (on console %i)%s", egg_debug_enabled (), egg_debug_is_console (), EGG_VERBOSE);
+	GOptionContext *context;
+
+	/* already initialized */
+	if (_initialized)
+		return TRUE;
+
+	context = g_option_context_new (NULL);
+	g_option_context_set_ignore_unknown_options (context, TRUE);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_parse (context, argc, argv, NULL);
+	g_option_context_free (context);
+
+	return TRUE;
 }
 
diff --git a/src/egg-debug.h b/src/egg-debug.h
index c935dcb..ac6728b 100644
--- a/src/egg-debug.h
+++ b/src/egg-debug.h
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2007-2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2007-2009 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -59,23 +59,23 @@ G_BEGIN_DECLS
 #define egg_error(...)
 #endif
 
-void		egg_debug_init			(gboolean	 debug);
-void		egg_debug_set_logging		(gboolean	 enabled);
-gboolean	egg_debug_enabled		(void);
-gboolean	egg_debug_is_logging		(void);
-gboolean	egg_debug_is_console		(void);
-void		egg_debug_backtrace		(void);
-void		egg_debug_real			(const gchar	*func,
+gboolean	 egg_debug_init			(gint		*argc,
+						 gchar		***argv);
+GOptionGroup	*egg_debug_get_option_group	(void);
+gboolean	 egg_debug_is_verbose		(void);
+void		 egg_debug_backtrace		(void);
+void		 egg_debug_set_log_filename	(const gchar	*filename);
+void		 egg_debug_real			(const gchar	*func,
 						 const gchar	*file,
-						 int		 line,
+						 gint		 line,
 						 const gchar	*format, ...) __attribute__((format (printf,4,5)));
-void		egg_warning_real		(const gchar	*func,
+void		 egg_warning_real		(const gchar	*func,
 						 const gchar	*file,
-						 int		 line,
+						 gint		 line,
 						 const gchar	*format, ...) __attribute__((format (printf,4,5)));
-void		egg_error_real			(const gchar	*func,
+void		 egg_error_real			(const gchar	*func,
 						 const gchar	*file,
-						 int		 line,
+						 gint		 line,
 						 const gchar	*format, ...) G_GNUC_NORETURN __attribute__((format (printf,4,5)));
 
 G_END_DECLS
diff --git a/src/gpk-application-main.c b/src/gpk-application-main.c
index 50cce1d..0150290 100644
--- a/src/gpk-application-main.c
+++ b/src/gpk-application-main.c
@@ -65,7 +65,6 @@ gpk_application_message_received_cb (UniqueApp *app, UniqueCommand command, Uniq
 int
 main (int argc, char *argv[])
 {
-	gboolean verbose = FALSE;
 	gboolean program_version = FALSE;
 	GpkApplication *application = NULL;
 	GOptionContext *context;
@@ -73,9 +72,6 @@ main (int argc, char *argv[])
 	gboolean ret;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  /* TRANSLATORS: show the debug data on the console */
-		  _("Show extra debugging information"), NULL },
 		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
 		  /* TRANSLATORS: show the program version */
 		  _("Show the program version and exit"), NULL },
@@ -92,10 +88,13 @@ main (int argc, char *argv[])
 		g_thread_init (NULL);
 	dbus_g_thread_init ();
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	context = g_option_context_new (NULL);
 	g_option_context_set_summary (context, _("Add/Remove Software"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
@@ -104,9 +103,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* are we running privileged */
 	ret = gpk_check_privileged_user (_("Package installer"), TRUE);
 	if (!ret)
diff --git a/src/gpk-backend-status.c b/src/gpk-backend-status.c
index 3ccb885..3dbefda 100644
--- a/src/gpk-backend-status.c
+++ b/src/gpk-backend-status.c
@@ -230,7 +230,6 @@ int
 main (int argc, char *argv[])
 {
 	GMainLoop *loop;
-	gboolean verbose = FALSE;
 	gboolean program_version = FALSE;
 	GOptionContext *context;
 	GtkWidget *widget;
@@ -239,8 +238,6 @@ main (int argc, char *argv[])
 	GError *error = NULL;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
 		  _("Show the program version and exit"), NULL },
 		{ NULL}
@@ -255,10 +252,13 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	context = g_option_context_new (NULL);
 	g_option_context_set_summary (context, _("PackageKit Backend Details Viewer"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
@@ -267,9 +267,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	loop = g_main_loop_new (NULL, FALSE);
 	control = pk_control_new ();
 
diff --git a/src/gpk-install-catalog.c b/src/gpk-install-catalog.c
index d4bdf9b..5777d61 100644
--- a/src/gpk-install-catalog.c
+++ b/src/gpk-install-catalog.c
@@ -45,12 +45,9 @@ main (int argc, char *argv[])
 	DBusGProxy *proxy = NULL;
 	GError *error = NULL;
 	gboolean ret;
-	gboolean verbose = FALSE;
 	gchar **files = NULL;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
 		/* TRANSLATORS: command line option: a list of catalogs to install */
 		  _("Catalogs files to install"), NULL },
@@ -66,18 +63,18 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	/* TRANSLATORS: program name: application to install a catalog of software */
 	g_set_application_name (_("Catalog Installer"));
 	context = g_option_context_new ("gpk-install-catalog");
 	g_option_context_set_summary (context, _("Catalog Installer"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* are we running privileged */
 	ret = gpk_check_privileged_user (_("Catalog installer"), TRUE);
 	if (!ret)
diff --git a/src/gpk-install-local-file.c b/src/gpk-install-local-file.c
index 6f3fcef..e06a718 100644
--- a/src/gpk-install-local-file.c
+++ b/src/gpk-install-local-file.c
@@ -41,15 +41,12 @@ main (int argc, char *argv[])
 {
 	GOptionContext *context;
 	gboolean ret;
-	gboolean verbose = FALSE;
 	GError *error = NULL;
 	gchar **files = NULL;
 	DBusGConnection *connection;
 	DBusGProxy *proxy = NULL;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
 		  /* TRANSLATORS: command line option: a list of files to install */
 		  _("Files to install"), NULL },
@@ -65,18 +62,18 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	/* TRANSLATORS: program name: application to install a package to provide a file */
 	g_set_application_name (_("PackageKit File Installer"));
 	context = g_option_context_new ("gpk-install-file");
 	g_option_context_set_summary (context, _("PackageKit File Installer"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* TRANSLATORS: title to pass to to the user if there are not enough privs */
 	ret = gpk_check_privileged_user (_("Local file installer"), TRUE);
 	if (!ret)
diff --git a/src/gpk-install-mime-type.c b/src/gpk-install-mime-type.c
index 50a85dc..263ad4f 100644
--- a/src/gpk-install-mime-type.c
+++ b/src/gpk-install-mime-type.c
@@ -41,15 +41,12 @@ main (int argc, char *argv[])
 {
 	GOptionContext *context;
 	gboolean ret;
-	gboolean verbose = FALSE;
 	GError *error = NULL;
 	DBusGConnection *connection;
 	DBusGProxy *proxy = NULL;
 	gchar **types = NULL;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &types,
 		/* TRANSLATORS: command line option: a list of catalogs to install */
 		  _("Mime types to install"), NULL },
@@ -65,18 +62,18 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	/* TRANSLATORS: program name: application to install a package to provide a mime type */
 	g_set_application_name (_("Mime Type Installer"));
 	context = g_option_context_new ("gpk-install-mime-type");
 	g_option_context_set_summary (context, _("Mime Type Installer"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* TRANSLATORS: title to pass to to the user if there are not enough privs */
 	ret = gpk_check_privileged_user (_("Mime type installer"), TRUE);
 	if (!ret)
diff --git a/src/gpk-install-package-name.c b/src/gpk-install-package-name.c
index a651a07..26acce0 100644
--- a/src/gpk-install-package-name.c
+++ b/src/gpk-install-package-name.c
@@ -41,15 +41,12 @@ main (int argc, char *argv[])
 {
 	GOptionContext *context;
 	gboolean ret;
-	gboolean verbose = FALSE;
 	GError *error = NULL;
 	gchar **packages = NULL;
 	DBusGConnection *connection;
 	DBusGProxy *proxy = NULL;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &packages,
 		  _("Packages to install"), NULL },
 		{ NULL}
@@ -64,18 +61,18 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	/* TRANSLATORS: program name: installs a package (or packages) by name */
 	g_set_application_name (_("Package Name Installer"));
 	context = g_option_context_new ("gpk-install-package");
 	g_option_context_set_summary (context, _("Package Name Installer"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* TRANSLATORS: application name to pass to to the user if there are not enough privs */
 	ret = gpk_check_privileged_user (_("Package Name Installer"), TRUE);
 	if (!ret)
diff --git a/src/gpk-install-provide-file.c b/src/gpk-install-provide-file.c
index 5060311..93281ce 100644
--- a/src/gpk-install-provide-file.c
+++ b/src/gpk-install-provide-file.c
@@ -41,15 +41,12 @@ main (int argc, char *argv[])
 {
 	GOptionContext *context;
 	gboolean ret;
-	gboolean verbose = FALSE;
 	GError *error = NULL;
 	DBusGConnection *connection;
 	DBusGProxy *proxy = NULL;
 	gchar **files = NULL;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
 		/* TRANSLATORS: command line option: a list of files to install */
 		  _("Local files to install"), NULL },
@@ -65,18 +62,18 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	/* TRANSLATORS: program name, an application to install a file that is needed by an application and is provided by packages */
 	g_set_application_name (_("Single File Installer"));
 	context = g_option_context_new ("gpk-install-provide-file");
 	g_option_context_set_summary (context, _("Single File Installer"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* TRANSLATORS: application name to pass to to the user if there are not enough privs */
 	ret = gpk_check_privileged_user (_("Single File Installer"), TRUE);
 	if (!ret)
diff --git a/src/gpk-log.c b/src/gpk-log.c
index 9a3711e..618ab76 100644
--- a/src/gpk-log.c
+++ b/src/gpk-log.c
@@ -672,7 +672,6 @@ gpk_log_entry_filter_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_da
 int
 main (int argc, char *argv[])
 {
-	gboolean verbose = FALSE;
 	GOptionContext *context;
 	GConfClient *gconf_client;
 	GtkWidget *widget;
@@ -685,8 +684,6 @@ main (int argc, char *argv[])
 	GError *error = NULL;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  N_("Show extra debugging information"), NULL },
 		{ "filter", 'f', 0, G_OPTION_ARG_STRING, &filter,
 		  /* TRANSLATORS: preset the GtktextBox with this filter text */
 		  N_("Set the filter to this value"), NULL },
@@ -705,16 +702,16 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	context = g_option_context_new (NULL);
 	g_option_context_set_summary (context, _("Software Log Viewer"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* are we running privileged */
 	ret = gpk_check_privileged_user (_("Log viewer"), TRUE);
 	if (!ret)
diff --git a/src/gpk-prefs.c b/src/gpk-prefs.c
index 392958e..9145b5c 100644
--- a/src/gpk-prefs.c
+++ b/src/gpk-prefs.c
@@ -470,7 +470,6 @@ gpk_prefs_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
 int
 main (int argc, char *argv[])
 {
-	gboolean verbose = FALSE;
 	gboolean program_version = FALSE;
 	GOptionContext *context;
 	GtkWidget *main_window;
@@ -483,8 +482,6 @@ main (int argc, char *argv[])
 	GMainLoop *loop;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
 		  _("Show the program version and exit"), NULL },
 		{ "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
@@ -503,11 +500,14 @@ main (int argc, char *argv[])
 		g_thread_init (NULL);
 	dbus_g_thread_init ();
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	context = g_option_context_new (NULL);
 	/* TRANSLATORS: program name, an application to set per-user policy for updates */
 	g_option_context_set_summary(context, _("Software Update Preferences"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
@@ -516,9 +516,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* are we already activated? */
 	unique_app = unique_app_new ("org.freedesktop.PackageKit.Prefs", NULL);
 	if (unique_app_is_running (unique_app)) {
diff --git a/src/gpk-repo.c b/src/gpk-repo.c
index c5c97f7..b6a55c7 100644
--- a/src/gpk-repo.c
+++ b/src/gpk-repo.c
@@ -564,7 +564,6 @@ gpk_repo_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
 int
 main (int argc, char *argv[])
 {
-	gboolean verbose = FALSE;
 	GOptionContext *context;
 	GtkWidget *main_window;
 	GtkWidget *widget;
@@ -579,8 +578,6 @@ main (int argc, char *argv[])
 	GMainLoop *loop;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
 		  /* TRANSLATORS: we can make this modal (stay on top of) another window */
 		  _("Set the parent window to make this modal"), NULL },
@@ -596,16 +593,16 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	context = g_option_context_new (NULL);
 	g_option_context_set_summary (context, _("Software Source Viewer"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* TRANSLATORS: title to pass to to the user if there are not enough privs */
 	ret = gpk_check_privileged_user (_("Software source viewer"), TRUE);
 	if (!ret)
diff --git a/src/gpk-self-test.c b/src/gpk-self-test.c
index 1d8d936..24eda6c 100644
--- a/src/gpk-self-test.c
+++ b/src/gpk-self-test.c
@@ -45,7 +45,7 @@ main (int argc, char **argv)
 	g_type_init ();
 	gtk_init (&argc, &argv);
 	test = egg_test_init ();
-	egg_debug_init (TRUE);
+	egg_debug_init (&argc, &argv);
 
 	/* tests go here */
 	egg_markdown_test (test);
diff --git a/src/gpk-service-pack.c b/src/gpk-service-pack.c
index 6c8aef0..624d235 100644
--- a/src/gpk-service-pack.c
+++ b/src/gpk-service-pack.c
@@ -676,7 +676,6 @@ gpk_pack_radio_copy_cb (GtkWidget *widget2, gpointer data)
 int
 main (int argc, char *argv[])
 {
-	gboolean verbose = FALSE;
 	GOptionContext *context;
 	GtkWidget *main_window;
 	GtkWidget *widget;
@@ -693,8 +692,6 @@ main (int argc, char *argv[])
 	GError *error = NULL;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ "option", 'o', 0, G_OPTION_ARG_STRING, &option,
 		  /* TRANSLATORS: the constants should not be translated */
 		  _("Set the option, allowable values are 'array', 'updates' and 'package'"), NULL },
@@ -722,12 +719,17 @@ main (int argc, char *argv[])
 
 	context = g_option_context_new (NULL);
 	/* TRANSLATORS: program description, an application to create service packs */
-	g_option_context_set_summary(context, _("Service Pack Creator"));
+	g_option_context_set_summary (context, _("Service Pack Creator"));
 	g_option_context_add_main_entries (context, options, NULL);
-	g_option_context_parse (context, &argc, &argv, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
+	ret = g_option_context_parse (context, &argc, &argv, &error);
+	if (!ret) {
+		g_error ("failed to parse %s", error->message);
+		g_error_free (error);
+	}
 	g_option_context_free (context);
 
-	egg_debug_init (verbose);
 	gtk_init (&argc, &argv);
 
 	/* are we already activated? */
diff --git a/src/gpk-update-icon.c b/src/gpk-update-icon.c
index 2bde05f..65af229 100644
--- a/src/gpk-update-icon.c
+++ b/src/gpk-update-icon.c
@@ -109,7 +109,6 @@ pk_dbus_connection_replaced_cb (EggDbusMonitor *monitor, gpointer data)
 int
 main (int argc, char *argv[])
 {
-	gboolean verbose = FALSE;
 	gboolean program_version = FALSE;
 	gboolean timed_exit = FALSE;
 	GpkCheckUpdate *cupdate = NULL;
@@ -124,8 +123,6 @@ main (int argc, char *argv[])
 	EggDbusMonitor *monitor;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  _("Show extra debugging information"), NULL },
 		{ "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit,
 		  _("Exit after a small delay"), NULL },
 		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
@@ -142,6 +139,7 @@ main (int argc, char *argv[])
 	if (! g_thread_supported ())
 		g_thread_init (NULL);
 	g_type_init ();
+	gtk_init (&argc, &argv);
 	dbus_g_thread_init ();
 	notify_init ("gpk-update-icon");
 
@@ -150,6 +148,8 @@ main (int argc, char *argv[])
 	context = g_option_context_new (NULL);
 	g_option_context_set_summary (context, _("Update Applet"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
@@ -158,9 +158,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* TRANSLATORS: title to pass to to the user if there are not enough privs */
 	ret = gpk_check_privileged_user (_("Update applet"), FALSE);
 	if (!ret) {
diff --git a/src/gpk-update-viewer-main.c b/src/gpk-update-viewer-main.c
index 3ae6e2a..ab3a74b 100644
--- a/src/gpk-update-viewer-main.c
+++ b/src/gpk-update-viewer-main.c
@@ -21,11 +21,6 @@
 
 #include "config.h"
 
-//#include <errno.h>
-//#include <string.h>
-//#include <unistd.h>
-//#include <stdlib.h>
-//#include <glib.h>
 #include <glib/gi18n.h>
 #include <dbus/dbus-glib.h>
 #include <gtk/gtk.h>
@@ -62,7 +57,6 @@ gpk_update_viewer_message_received_cb (UniqueApp *app, UniqueCommand command, Un
 int
 main (int argc, char *argv[])
 {
-	gboolean verbose = FALSE;
 	gboolean program_version = FALSE;
 	GpkUpdateViewer *update_viewer = NULL;
 	GOptionContext *context;
@@ -70,9 +64,6 @@ main (int argc, char *argv[])
 	gboolean ret;
 
 	const GOptionEntry options[] = {
-		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
-		  /* TRANSLATORS: show the debug data on the console */
-		  _("Show extra debugging information"), NULL },
 		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
 		  /* TRANSLATORS: show the program version */
 		  _("Show the program version and exit"), NULL },
@@ -89,10 +80,13 @@ main (int argc, char *argv[])
 		g_thread_init (NULL);
 	dbus_g_thread_init ();
 	g_type_init ();
+	gtk_init (&argc, &argv);
 
 	context = g_option_context_new (NULL);
 	g_option_context_set_summary (context, _("Add/Remove Software"));
 	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
@@ -101,9 +95,6 @@ main (int argc, char *argv[])
 		return 0;
 	}
 
-	egg_debug_init (verbose);
-	gtk_init (&argc, &argv);
-
 	/* add application specific icons to search path */
 	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
 					   GPK_DATA G_DIR_SEPARATOR_S "icons");



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