~ctf/unity-settings-daemon/bug1389099_mic_volume_icons

« back to all changes in this revision

Viewing changes to plugins/common/test-plugin.h

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-02-07 11:44:36 UTC
  • Revision ID: package-import@ubuntu.com-20140207114436-7t5u3yvwc4ul7w3e
Tags: upstream-14.04.0
ImportĀ upstreamĀ versionĀ 14.04.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Create a test app for your plugin quickly.
 
3
 *
 
4
 * #define NEW gsd_media_keys_manager_new
 
5
 * #define START gsd_media_keys_manager_start
 
6
 * #define MANAGER GsdMediaKeysManager
 
7
 * #include "gsd-media-keys-manager.h"
 
8
 *
 
9
 * #include "test-plugin.h"
 
10
 */
 
11
 
 
12
#include "config.h"
 
13
 
 
14
#include <stdlib.h>
 
15
 
 
16
#include <glib/gi18n.h>
 
17
#include <gtk/gtk.h>
 
18
#include <libnotify/notify.h>
 
19
 
 
20
#ifndef SCHEMA_NAME
 
21
#define SCHEMA_NAME PLUGIN_NAME
 
22
#endif
 
23
 
 
24
#ifndef PLUGIN_NAME
 
25
#error Include PLUGIN_CFLAGS in the test application s CFLAGS
 
26
#endif /* !PLUGIN_NAME */
 
27
 
 
28
static MANAGER *manager = NULL;
 
29
 
 
30
static gboolean
 
31
has_settings (void)
 
32
{
 
33
        const gchar * const * list;
 
34
        guint i;
 
35
 
 
36
        list = g_settings_list_schemas ();
 
37
        for (i = 0; list[i] != NULL; i++) {
 
38
                if (g_str_equal (list[i], "org.gnome.settings-daemon.plugins." SCHEMA_NAME))
 
39
                        return TRUE;
 
40
        }
 
41
        return FALSE;
 
42
}
 
43
 
 
44
static void
 
45
print_enable_disable_help (void)
 
46
{
 
47
        fprintf (stderr, "To deactivate:\n");
 
48
        fprintf (stderr, "\tgsettings set org.gnome.settings-daemon.plugins." SCHEMA_NAME " active false\n");
 
49
        fprintf (stderr, "To reactivate:\n");
 
50
        fprintf (stderr, "\tgsettings set org.gnome.settings-daemon.plugins." SCHEMA_NAME " active true\n");
 
51
}
 
52
 
 
53
int
 
54
main (int argc, char **argv)
 
55
{
 
56
        GError  *error;
 
57
        GSettings *settings;
 
58
 
 
59
        bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR);
 
60
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
61
        textdomain (GETTEXT_PACKAGE);
 
62
        notify_init ("gnome-settings-daemon");
 
63
 
 
64
        g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
 
65
 
 
66
        error = NULL;
 
67
        if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) {
 
68
                fprintf (stderr, "%s\n", error->message);
 
69
                g_error_free (error);
 
70
                exit (1);
 
71
        }
 
72
 
 
73
        if (has_settings () == FALSE) {
 
74
                fprintf (stderr, "The schemas for plugin '%s' isn't available, check your installation.\n", SCHEMA_NAME);
 
75
        } else {
 
76
                settings = g_settings_new ("org.gnome.settings-daemon.plugins." SCHEMA_NAME);
 
77
                if (g_settings_get_boolean (settings, "active") != FALSE) {
 
78
                        fprintf (stderr, "Plugin '%s' is not disabled. You need to disable it before launching the test application.\n", SCHEMA_NAME);
 
79
                        print_enable_disable_help ();
 
80
                        exit (1);
 
81
                }
 
82
                print_enable_disable_help();
 
83
        }
 
84
 
 
85
        manager = NEW ();
 
86
 
 
87
        error = NULL;
 
88
        START (manager, &error);
 
89
 
 
90
        gtk_main ();
 
91
 
 
92
        STOP (manager);
 
93
        g_object_unref (manager);
 
94
 
 
95
        return 0;
 
96
}