From: Jean-Philippe Orsini Date: Thu, 24 Apr 2014 21:41:48 +0000 (+0200) Subject: added fcts to handle autostart of psensor X-Git-Tag: v1.0.1~46 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=psensor.git;a=commitdiff_plain;h=5c98024b1c9130dc351172f0be6e0ad15f208526 added fcts to handle autostart of psensor --- diff --git a/src/Makefile.am b/src/Makefile.am index f484916..0f64275 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,9 @@ endif endif # -no-deprecated-declarations to avoid some glib deprecation warnings -AM_CPPFLAGS = -Wno-deprecated-declarations -Wall -Werror -DDEFAULT_WWW_DIR=\""$(pkgdatadir)/www"\"\ +AM_CPPFLAGS = -Wno-deprecated-declarations -Wall -Werror \ + -DDEFAULT_WWW_DIR=\""$(pkgdatadir)/www"\"\ + -DDATADIR=\""$(datadir)"\"\ -I$(top_srcdir)/src/lib \ -I$(top_srcdir)/src/unity \ $(GTK_CFLAGS)\ @@ -49,7 +51,8 @@ psensor_SOURCES = \ ui_pref.h ui_pref.c \ ui_sensorlist.h ui_sensorlist.c \ ui_sensorpref.h ui_sensorpref.c \ - ui_status.h ui_status.c + ui_status.h ui_status.c \ + pxdg.h pxdg.c if GTOP AM_CPPFLAGS += $(GTOP_CFLAGS) diff --git a/src/pxdg.c b/src/pxdg.c new file mode 100644 index 0000000..3687c8f --- /dev/null +++ b/src/pxdg.c @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2010-2014 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include + +static char *get_user_autostart_dir() +{ + const char *xdg_cfg_dir; + + xdg_cfg_dir = g_get_user_config_dir(); + + log_fct("g_user_config_dir(): %s", xdg_cfg_dir); + + return path_append(xdg_cfg_dir, "autostart"); +} + +static char *get_user_desktop_file() +{ + char *dir, *path; + + dir = get_user_autostart_dir(); + path = path_append(dir, "psensor.desktop"); + + free(dir); + + return path; +} + +static const char *get_desktop_file() +{ + return DATADIR"/applications/psensor.desktop"; +} + +static int is_file_exists(const char *path) +{ + struct stat st; + + return stat(path, &st) == 0; +} + +unsigned int pxdg_is_autostarted() +{ + char *user_desktop; + unsigned int ret; + + log_fct_enter(); + + user_desktop = get_user_desktop_file(); + + log_fct("user desktop file: %s", user_desktop); + + ret = is_file_exists(user_desktop); + + if (!ret) + log_fct("user desktop file does not exist."); + + free(user_desktop); + + log_fct_exit(); + + return ret; +} + +void pxdg_set_autostart(unsigned int enable) +{ + char *user_desktop; + + log_fct_enter(); + + user_desktop = get_user_desktop_file(); + + log_fct("user desktop file: %s", user_desktop); + + log_fct("desktop file: %s", get_desktop_file()); + + if (enable) { + if (!is_file_exists(user_desktop)) + file_copy(get_desktop_file(), user_desktop); + } else { + remove(user_desktop); + } + + log_fct_exit(); + + free(user_desktop); +} diff --git a/src/pxdg.h b/src/pxdg.h new file mode 100644 index 0000000..82abc44 --- /dev/null +++ b/src/pxdg.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2010-2014 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef _PXDG_H_ +#define _PXDG_H_ + +unsigned int pxdg_is_autostarted(); +void pxdg_set_autostart(unsigned int); + +#endif