From f3ba17bac4e7a43e934ec56f8c0a28cc3b8df803 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Sat, 3 Dec 2011 22:50:10 +0100 Subject: gtk-redshift: Also set "Hidden" property in autostart file (as specified in XDG autostart standard). --- src/gtk-redshift/utils.py | 56 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/gtk-redshift/utils.py b/src/gtk-redshift/utils.py index 93e0195..2fd3b71 100644 --- a/src/gtk-redshift/utils.py +++ b/src/gtk-redshift/utils.py @@ -15,6 +15,7 @@ # along with Redshift. If not, see . # Copyright (c) 2010 Francesco Marella +# Copyright (c) 2011 Jon Lund Steffensen import os from xdg import BaseDirectory as base @@ -22,45 +23,42 @@ from xdg import DesktopEntry as desktop REDSHIFT_DESKTOP = 'gtk-redshift.desktop' +# Keys to set when enabling/disabling autostart. +# Only first one is checked on "get". +AUTOSTART_KEYS = (('Hidden', ('true', 'false')), + ('X-GNOME-Autostart-enabled', ('false', 'true'))) -def get_autostart(): - AUTOSTART_KEY = "X-GNOME-Autostart-enabled" + +def open_autostart_file(): autostart_dir = base.save_config_path("autostart") autostart_file = os.path.join(autostart_dir, REDSHIFT_DESKTOP) + if not os.path.exists(autostart_file): - desktop_files = list(base.load_data_paths("applications", - REDSHIFT_DESKTOP)) + desktop_files = list(base.load_data_paths("applications", + REDSHIFT_DESKTOP)) + if not desktop_files: raise IOError("Installed redshift desktop file not found!") + desktop_file_path = desktop_files[0] - # Read installed file and modify it + + # Read installed file dfile = desktop.DesktopEntry(desktop_file_path) - dfile.set(AUTOSTART_KEY, "false") + for key, values in AUTOSTART_KEYS: + dfile.set(key, values[False]) dfile.write(filename=autostart_file) - return False else: dfile = desktop.DesktopEntry(autostart_file) - if dfile.get(AUTOSTART_KEY) == 'false': - return False - else: - return True + + return dfile, autostart_file + +def get_autostart(): + dfile, path = open_autostart_file() + check_key, check_values = AUTOSTART_KEYS[0] + return dfile.get(check_key) == check_values[True] def set_autostart(active): - AUTOSTART_KEY = "X-GNOME-Autostart-enabled" - autostart_dir = base.save_config_path("autostart") - autostart_file = os.path.join(autostart_dir, REDSHIFT_DESKTOP) - if not os.path.exists(autostart_file): - desktop_files = list(base.load_data_paths("applications", - REDSHIFT_DESKTOP)) - if not desktop_files: - raise IOError("Installed redshift desktop file not found!") - return - desktop_file_path = desktop_files[0] - # Read installed file and modify it - dfile = desktop.DesktopEntry(desktop_file_path) - else: - dfile = desktop.DesktopEntry(autostart_file) - activestr = str(bool(active)).lower() - # print "Setting autostart to %s" % activestr - dfile.set(AUTOSTART_KEY, activestr) - dfile.write(filename=autostart_file) + dfile, path = open_autostart_file() + for key, values in AUTOSTART_KEYS: + dfile.set(key, values[active]) + dfile.write(filename=path) -- cgit v1.2.3-70-g09d2