diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2010-06-30 19:55:36 +0200 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2010-06-30 19:55:36 +0200 |
commit | 0d533f457c4053e3f8fb3a5c86d2c43689dd2b15 (patch) | |
tree | d6edf22c8b64f5336e233e411a20d57cd08bf0ef /src/gtk-redshift | |
parent | Change comment in colorramp.c. (diff) | |
parent | utils.py: copy the desktop file in autostart folder (diff) | |
download | redshift-ng-0d533f457c4053e3f8fb3a5c86d2c43689dd2b15.tar.gz redshift-ng-0d533f457c4053e3f8fb3a5c86d2c43689dd2b15.tar.bz2 redshift-ng-0d533f457c4053e3f8fb3a5c86d2c43689dd2b15.tar.xz |
Merge GUI autostart feature from Francesco Marella.
Diffstat (limited to 'src/gtk-redshift')
-rw-r--r-- | src/gtk-redshift/Makefile.am | 10 | ||||
-rwxr-xr-x | src/gtk-redshift/gtk-redshift.desktop | 11 | ||||
-rw-r--r-- | src/gtk-redshift/rsappindicator.py | 15 | ||||
-rw-r--r-- | src/gtk-redshift/statusicon.py | 15 | ||||
-rw-r--r-- | src/gtk-redshift/utils.py | 66 |
5 files changed, 117 insertions, 0 deletions
diff --git a/src/gtk-redshift/Makefile.am b/src/gtk-redshift/Makefile.am index ddeafd6..42647f7 100644 --- a/src/gtk-redshift/Makefile.am +++ b/src/gtk-redshift/Makefile.am @@ -3,24 +3,34 @@ if ENABLE_STATUSICON gui_module=statusicon gtk_redshift_PYTHON = \ __init__.py \ + utils.py \ statusicon.py nodist_gtk_redshift_PYTHON = \ defs.py gtk_redshiftdir = $(pythondir)/gtk_redshift bin_SCRIPTS = gtk-redshift + +# Desktop file +desktopdir = ${datadir}/applications +desktop_DATA = gtk-redshift.desktop endif if ENABLE_APPINDICATOR gui_module=rsappindicator gtk_redshift_PYTHON = \ __init__.py \ + utils.py \ rsappindicator.py nodist_gtk_redshift_PYTHON = \ defs.py gtk_redshiftdir = $(pythondir)/gtk_redshift bin_SCRIPTS = gtk-redshift + +# Desktop file +desktopdir = ${datadir}/applications +desktop_DATA = gtk-redshift.desktop endif EXTRA_DIST = gtk-redshift.in \ diff --git a/src/gtk-redshift/gtk-redshift.desktop b/src/gtk-redshift/gtk-redshift.desktop new file mode 100755 index 0000000..850255c --- /dev/null +++ b/src/gtk-redshift/gtk-redshift.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Version=1.0 +Name=Redshift +GenericName=Color temperature adjustment +Comment=Color temperature adjustment tool +Exec=gtk-redshift +Icon=redshift +Terminal=false +Type=Application +Categories=Utility; +StartupNotify=true diff --git a/src/gtk-redshift/rsappindicator.py b/src/gtk-redshift/rsappindicator.py index 59fa725..23f1ac8 100644 --- a/src/gtk-redshift/rsappindicator.py +++ b/src/gtk-redshift/rsappindicator.py @@ -33,6 +33,7 @@ except ImportError as ie: sys.exit(str(ie)) import defs +import utils def run(): @@ -60,6 +61,9 @@ def run(): indicator.set_icon('redshift') process.send_signal(signal.SIGUSR1) + def autostart_cb(widget, data=None): + utils.set_autostart(widget.get_active()) + def destroy_cb(widget, data=None): gtk.main_quit() return False @@ -71,6 +75,17 @@ def run(): toggle_item.connect('activate', toggle_cb) status_menu.append(toggle_item) + autostart_item = gtk.CheckMenuItem(_('Autostart')) + try: + autostart_item.set_active(utils.get_autostart()) + except IOError as strerror: + print strerror + autostart_item.set_property('sensitive', False) + else: + autostart_item.connect('activate', autostart_cb) + finally: + status_menu.append(autostart_item) + quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) quit_item.connect('activate', destroy_cb) status_menu.append(quit_item) diff --git a/src/gtk-redshift/statusicon.py b/src/gtk-redshift/statusicon.py index 9b544ab..82b5cd6 100644 --- a/src/gtk-redshift/statusicon.py +++ b/src/gtk-redshift/statusicon.py @@ -28,6 +28,7 @@ pygtk.require("2.0") import gtk, glib import defs +import utils def run(): @@ -54,6 +55,9 @@ def run(): else: status_icon.set_from_icon_name('redshift') + def autostart_cb(widget, data=None): + utils.set_autostart(widget.get_active()) + def destroy_cb(widget, data=None): status_icon.set_visible(False) gtk.main_quit() @@ -66,6 +70,17 @@ def run(): toggle_item.connect('activate', toggle_cb) status_menu.append(toggle_item) + autostart_item = gtk.CheckMenuItem(_('Autostart')) + try: + autostart_item.set_active(utils.get_autostart()) + except IOError as strerror: + print strerror + autostart_item.set_property('sensitive', False) + else: + autostart_item.connect('activate', autostart_cb) + finally: + status_menu.append(autostart_item) + quit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT) quit_item.connect('activate', destroy_cb) status_menu.append(quit_item) diff --git a/src/gtk-redshift/utils.py b/src/gtk-redshift/utils.py new file mode 100644 index 0000000..93e0195 --- /dev/null +++ b/src/gtk-redshift/utils.py @@ -0,0 +1,66 @@ +# utils.py -- utility functions source +# This file is part of Redshift. + +# Redshift 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 3 of the License, or +# (at your option) any later version. + +# Redshift 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 Redshift. If not, see <http://www.gnu.org/licenses/>. + +# Copyright (c) 2010 Francesco Marella <francesco.marella@gmail.com> + +import os +from xdg import BaseDirectory as base +from xdg import DesktopEntry as desktop + +REDSHIFT_DESKTOP = 'gtk-redshift.desktop' + + +def get_autostart(): + 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!") + desktop_file_path = desktop_files[0] + # Read installed file and modify it + dfile = desktop.DesktopEntry(desktop_file_path) + dfile.set(AUTOSTART_KEY, "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 + +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) |