[gnome-settings-daemon] common: Check whether plugin is disable in test apps



commit b278cb323dab6c6fb9fdfba573d6506a3b4b2fcf
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Jul 2 13:39:34 2012 +0100

    common: Check whether plugin is disable in test apps
    
    Instead of having 2 copies of the same code clashing with each other,
    make sure that the test applications bail out if the schemas aren't
    installed properly, or the plugin is marked as active.

 plugins/common/test-plugin.h |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/plugins/common/test-plugin.h b/plugins/common/test-plugin.h
index 036d6f1..6120cc0 100644
--- a/plugins/common/test-plugin.h
+++ b/plugins/common/test-plugin.h
@@ -16,12 +16,35 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+#ifndef SCHEMA_NAME
+#define SCHEMA_NAME PLUGIN_NAME
+#endif
+
+#ifndef PLUGIN_NAME
+#error Include PLUGIN_CFLAGS in the test application s CFLAGS
+#endif /* !PLUGIN_NAME */
+
 static MANAGER *manager = NULL;
 
+static gboolean
+has_settings (void)
+{
+	const gchar * const * list;
+	guint i;
+
+	list = g_settings_list_schemas ();
+	for (i = 0; list[i] != NULL; i++) {
+		if (g_str_equal (list[i], "org.gnome.settings-daemon.plugins." SCHEMA_NAME))
+			return TRUE;
+	}
+	return FALSE;
+}
+
 int
 main (int argc, char **argv)
 {
         GError  *error;
+        GSettings *settings;
 
         bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR);
         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -31,11 +54,26 @@ main (int argc, char **argv)
 
         error = NULL;
         if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) {
-                fprintf (stderr, "%s", error->message);
+                fprintf (stderr, "%s\n", error->message);
                 g_error_free (error);
                 exit (1);
         }
 
+	if (has_settings () == FALSE) {
+		fprintf (stderr, "The schemas for plugin '%s' aren't available, check your installation.\n", SCHEMA_NAME);
+		exit (1);
+	}
+
+        settings = g_settings_new ("org.gnome.settings-daemon.plugins." SCHEMA_NAME);
+        if (g_settings_get_boolean (settings, "active") != FALSE) {
+		fprintf (stderr, "Plugin '%s' is not disabled. You need to disable it before launching the test application.\n", SCHEMA_NAME);
+		fprintf (stderr, "To deactivate:\n");
+		fprintf (stderr, "\tgsettings set org.gnome.settings-daemon.plugins." SCHEMA_NAME " active false\n");
+		fprintf (stderr, "To reactivate:\n");
+		fprintf (stderr, "\tgsettings set org.gnome.settings-daemon.plugins." SCHEMA_NAME " active true\n");
+		exit (1);
+	}
+
         manager = NEW ();
 
         error = NULL;



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