From: Jean-Philippe Orsini Date: Fri, 25 Apr 2014 12:56:38 +0000 (+0200) Subject: enable gnome-autostart if the desktop file is in autostart dir but the entry turned off X-Git-Tag: v1.0.1~37 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=psensor.git;a=commitdiff_plain;h=0e4030c08848ffa28cd51b6b4f764bc2e526f810 enable gnome-autostart if the desktop file is in autostart dir but the entry turned off (gnome startup application does not remove the file but turn off the entry) --- diff --git a/po/Makefile.in b/po/Makefile.in index 0ea07b3..37928c5 100644 --- a/po/Makefile.in +++ b/po/Makefile.in @@ -21,7 +21,7 @@ srcdir = . top_srcdir = .. -prefix = /usr/local +prefix = /tmp exec_prefix = ${prefix} datarootdir = ${prefix}/share datadir = ${datarootdir} diff --git a/src/pxdg.c b/src/pxdg.c index 3687c8f..12735d0 100644 --- a/src/pxdg.c +++ b/src/pxdg.c @@ -63,10 +63,45 @@ static int is_file_exists(const char *path) return stat(path, &st) == 0; } -unsigned int pxdg_is_autostarted() +static GKeyFile *get_key_file(const char *path) +{ + GKeyFile *kfile; + int ret; + + kfile = g_key_file_new(); + ret = g_key_file_load_from_file(kfile, + path, + G_KEY_FILE_KEEP_COMMENTS + | G_KEY_FILE_KEEP_TRANSLATIONS, + NULL); + + if (ret) { + return kfile; + } else { + log_err("Failed to parse: %s", path); + + g_key_file_free(kfile); + return NULL; + } +} + +static int is_user_desktop_autostarted(GKeyFile *f) +{ + return (!g_key_file_has_key(f, + G_KEY_FILE_DESKTOP_GROUP, + "X-GNOME-Autostart-enabled", + NULL)) + || g_key_file_get_boolean(f, + G_KEY_FILE_DESKTOP_GROUP, + "X-GNOME-Autostart-enabled", + NULL); +} + +int pxdg_is_autostarted() { char *user_desktop; unsigned int ret; + GKeyFile *kfile; log_fct_enter(); @@ -76,8 +111,19 @@ unsigned int pxdg_is_autostarted() ret = is_file_exists(user_desktop); - if (!ret) + if (!ret) { log_fct("user desktop file does not exist."); + } else { + log_fct("user desktop file exist."); + if (ret) { + kfile = get_key_file(user_desktop); + if (kfile) + ret = is_user_desktop_autostarted(kfile); + else + ret = -1; + } + g_key_file_free(kfile); + } free(user_desktop); @@ -88,7 +134,8 @@ unsigned int pxdg_is_autostarted() void pxdg_set_autostart(unsigned int enable) { - char *user_desktop; + char *user_desktop, *data; + GKeyFile *f; log_fct_enter(); @@ -101,7 +148,29 @@ void pxdg_set_autostart(unsigned int enable) if (enable) { if (!is_file_exists(user_desktop)) file_copy(get_desktop_file(), user_desktop); + + f = get_key_file(user_desktop); + if (f) { + if (g_key_file_has_key(f, + G_KEY_FILE_DESKTOP_GROUP, + "X-GNOME-Autostart-enabled", + NULL)) + g_key_file_set_boolean + (f, + G_KEY_FILE_DESKTOP_GROUP, + "X-GNOME-Autostart-enabled", + TRUE); + data = g_key_file_to_data(f, NULL, NULL); + g_file_set_contents(user_desktop, + data, + -1, + NULL); + + g_key_file_free(f); + } } else { + /* because X-GNOME-Autostart-enabled does not turn off + * autostart on all Desktop Envs. */ remove(user_desktop); } diff --git a/src/pxdg.h b/src/pxdg.h index 82abc44..78aa571 100644 --- a/src/pxdg.h +++ b/src/pxdg.h @@ -19,7 +19,13 @@ #ifndef _PXDG_H_ #define _PXDG_H_ -unsigned int pxdg_is_autostarted(); +/* + * returns: + * - 1 if psensor is currently launch during session startup. + * - 0 if psensor is not currently launch during session startup. + * - -1 if it cannot be determined. + */ +int pxdg_is_autostarted(); void pxdg_set_autostart(unsigned int); #endif