Result of call to g_settings_set_value() not persistent (2)



Hello,

I'm trying to change a setting in `gsettings' using <gio.h>'s
g_settings_set_value() in a C program, and it successfully changes the
value, but it is not persistent, as you can see from the output that the
program (a.out, see source below) produces:
 
$ gsettings get org.gnome.desktop.background picture-uri
'file:///usr/share/backgrounds/Winter_Fog_by_Daniel_Vesterskov.jpg'
 
$ ./a.out
Before: /usr/share/backgrounds/Winter_Fog_by_Daniel_Vesterskov.jpg
Setting wallpaper to
/usr/share/backgrounds/La_Gomera_by_Alfonso_Aguirre_Arbex.jpg ... Done
After: /usr/share/backgrounds/La_Gomera_by_Alfonso_Aguirre_Arbex.jpg

$ ./a.out
Before: /usr/share/backgrounds/Winter_Fog_by_Daniel_Vesterskov.jpg
Setting wallpaper to
/usr/share/backgrounds/La_Gomera_by_Alfonso_Aguirre_Arbex.jpg ... Done
After: /usr/share/backgrounds/La_Gomera_by_Alfonso_Aguirre_Arbex.jpg
 
$ gsettings get org.gnome.desktop.background picture-uri
'file:///usr/share/backgrounds/Winter_Fog_by_Daniel_Vesterskov.jpg'
 
As you can see from the output, the result from calling
g_settings_set_value() is not persistent. What am I doing wrong?

Regards,
Serrano

The (partial) source:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <gio/gio.h>
...
 
int main(void) {
    char current_wallpaper[PATH_MAX];
    char new_wallpaper[] =
"/usr/share/backgrounds/La_Gomera_by_Alfonso_Aguirre_Arbex.jpg";
    ...
 
    /* Get the path of the current wallpaper */
    get_background_uri(current_wallpaper);
    fprintf(stderr, "Before: %s\n", current_wallpaper);
 
    /* Set the new wallpaper */
    fprintf(stderr, "Setting wallpaper to %s ... ", new_wallpaper);
    if (set_background_uri(new_wallpaper)) {
        fprintf(stderr, "Done\n");
        get_background_uri(current_wallpaper);
        fprintf(stderr, "After: %s\n", current_wallpaper);
    }
    else {
        fprintf(stderr, "Failed\n");
    }
 
    return 0;
}
 
int get_background_uri(char *dest) {
    GSettings *gso;
    const char *uri;
 
    gso = g_settings_new("org.gnome.desktop.background");
    uri = g_variant_get_string(g_settings_get_value(gso, "picture-uri"),
NULL);
    strcpy(dest, uri+7);
    return 0;
}
 
int set_background_uri(const char *path) {
    char pathc[PATH_MAX];
    GSettings *gso;
 
    if (!strstr(path, "file://"))
        sprintf(pathc, "file://%s", path);
    else
        strcpy(pathc, path);
 
    gso = g_settings_new("org.gnome.desktop.background");
    return g_settings_set_string(gso, "picture-uri", pathc);
}


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