diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2011-12-03 22:50:10 +0100 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2011-12-03 22:50:10 +0100 |
commit | f3ba17bac4e7a43e934ec56f8c0a28cc3b8df803 (patch) | |
tree | 2e788a123382f08497a1633334169dfd64ea4d83 /src | |
parent | Add print mode (prints parameters and exits) by Vincent Breitmoser. (diff) | |
download | redshift-ng-f3ba17bac4e7a43e934ec56f8c0a28cc3b8df803.tar.gz redshift-ng-f3ba17bac4e7a43e934ec56f8c0a28cc3b8df803.tar.bz2 redshift-ng-f3ba17bac4e7a43e934ec56f8c0a28cc3b8df803.tar.xz |
gtk-redshift: Also set "Hidden" property in autostart file (as specified in XDG autostart standard).
Diffstat (limited to 'src')
-rw-r--r-- | src/gtk-redshift/utils.py | 56 |
1 files changed, 27 insertions, 29 deletions
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 <http://www.gnu.org/licenses/>. # Copyright (c) 2010 Francesco Marella <francesco.marella@gmail.com> +# Copyright (c) 2011 Jon Lund Steffensen <jonlst@gmail.com> 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) |