2 * Copyright (C) 2010-2014 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <sys/types.h>
31 static char *get_user_autostart_dir()
33 const char *xdg_cfg_dir;
35 xdg_cfg_dir = g_get_user_config_dir();
37 log_fct("g_user_config_dir(): %s", xdg_cfg_dir);
39 return path_append(xdg_cfg_dir, "autostart");
42 static char *get_user_desktop_file()
46 dir = get_user_autostart_dir();
47 path = path_append(dir, "psensor.desktop");
54 static const char *get_desktop_file()
56 return DATADIR"/applications/psensor.desktop";
59 static int is_file_exists(const char *path)
63 return stat(path, &st) == 0;
66 unsigned int pxdg_is_autostarted()
73 user_desktop = get_user_desktop_file();
75 log_fct("user desktop file: %s", user_desktop);
77 ret = is_file_exists(user_desktop);
80 log_fct("user desktop file does not exist.");
89 void pxdg_set_autostart(unsigned int enable)
95 user_desktop = get_user_desktop_file();
97 log_fct("user desktop file: %s", user_desktop);
99 log_fct("desktop file: %s", get_desktop_file());
102 if (!is_file_exists(user_desktop))
103 file_copy(get_desktop_file(), user_desktop);
105 remove(user_desktop);