[maemo-developers] [maemo-developers] gconf notifications?

From: Manuel Roman mraccount1 at gmail.com
Date: Tue Dec 12 08:38:19 EET 2006
Hi,

I just wrote a very simple application that uses gconf notifications.
Unfortunately, the callback is never called.  I have used gconf from a
graphical hildon app and notifications worked fine, however, when I try from
a console application it does not seem to work. I include the two simple
files I wrote: gconf_test, which registers the callback and gconf_test_set,
which sets a value. If you can pinpoint the problem I would really
appreciate it. Although there is no error checking for gconf_init, I tested
it and always returned TRUE.

GCONF_TEST
#include <gconf/gconf-client.h>
#define GCONF_MAEMO_PREFIX "/apps/maemo"
#define GCONF_KEY_OPERATION GCONF_MAEMO_PREFIX"/mc/operation"

static void callback(GConfClient *gconf_client, guint cnxn_id, GConfEntry
*entry, gpointer user_data)
{
        char *operationName     = gconf_client_get_string(gconf_client,
GCONF_KEY_OPERATION, NULL);
        printf("OpName:%s\n",operationName);
}

void config_init()
{
    GConfValue *value;
    gchar *str;

    GConfClient *gconf_client = gconf_client_get_default();

    if(!gconf_client)
    {
        printf("Failed to initialize GConf.  Quitting.");
        exit(1);
    }

    gconf_client_add_dir(gconf_client, GCONF_KEY_OPERATION,
GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
    gconf_client_notify_add(gconf_client, GCONF_KEY_OPERATION, callback,
NULL, NULL, NULL);

    g_object_unref(gconf_client);
}

int main(int argc, char **argv)
{
        //Initialize GConf
        g_type_init();
        gconf_init(argc, argv, NULL);
        config_init();

        while(1)
             sleep(1);
}


GCONF_TEST
#include <gconf/gconf-client.h>
#define GCONF_MAEMO_PREFIX "/apps/maemo"
#define GCONF_KEY_OPERATION GCONF_MAEMO_PREFIX"/mc/operation"

static void
config_init()
{
    GConfValue *value;
    gchar *str;

    GConfClient *gconf_client = gconf_client_get_default();

    if(!gconf_client)
    {
        printf("Failed to initialize GConf.  Quitting.");
        exit(1);
    }

    printf("Setting:%s\n",GCONF_KEY_OPERATION);
    gconf_client_set_string(gconf_client, GCONF_KEY_OPERATION, "deactivate",
NULL);

    g_object_unref(gconf_client);
}

int main(int argc, char **argv)
{
        //Initialize GConf
        g_type_init();
        gconf_init(argc, argv, NULL);
        config_init();

        return 1;
}

Thanks!
Manuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maemo.org/pipermail/maemo-developers/attachments/20061211/23a3db5a/attachment.htm 
More information about the maemo-developers mailing list