Merge lp:~jendrikseipp/redshift/suspend into lp:~jonls/redshift/trunk

Proposed by Jendrik Seipp
Status: Merged
Merged at revision: 177
Proposed branch: lp:~jendrikseipp/redshift/suspend
Merge into: lp:~jonls/redshift/trunk
Diff against target: 79 lines (+47/-0)
1 file modified
src/gtk-redshift/statusicon.py (+47/-0)
To merge this branch: bzr merge lp:~jendrikseipp/redshift/suspend
Reviewer Review Type Date Requested Status
Jon Lund Steffensen Pending
Review via email: mp+91381@code.launchpad.net

Description of the change

I added the discussed "suspend for X minutes" option.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/gtk-redshift/statusicon.py'
2--- src/gtk-redshift/statusicon.py 2010-10-18 00:14:49 +0000
3+++ src/gtk-redshift/statusicon.py 2012-02-03 01:15:35 +0000
4@@ -40,6 +40,9 @@
5 import utils
6
7
8+SUSPEND_TIMER = None
9+
10+
11 def run():
12 # Internationalisation
13 gettext.bindtextdomain('redshift', defs.LOCALEDIR)
14@@ -64,7 +67,24 @@
15 status_icon.set_from_icon_name('redshift-status-on')
16 status_icon.set_tooltip('Redshift')
17
18+ def is_enabled():
19+ if appindicator:
20+ return indicator.get_icon() == 'redshift-status-on'
21+ else:
22+ return status_icon.get_icon_name() == 'redshift-status-on'
23+
24+ def remove_suspend_timer():
25+ global SUSPEND_TIMER
26+ if SUSPEND_TIMER is not None:
27+ glib.source_remove(SUSPEND_TIMER)
28+ SUSPEND_TIMER = None
29+
30 def toggle_cb(widget, data=None):
31+ # If the user toggles redshift, we forget about the suspend timer.
32+ # Only then widget is not None.
33+ if widget:
34+ remove_suspend_timer()
35+
36 process.send_signal(signal.SIGUSR1)
37 if appindicator:
38 if indicator.get_icon() == 'redshift-status-on':
39@@ -77,6 +97,23 @@
40 else:
41 status_icon.set_from_icon_name('redshift-status-on')
42
43+ def enable_cb():
44+ if is_enabled():
45+ return
46+ # Enable redshift
47+ toggle_cb(None)
48+
49+ def suspend_cb(widget, minutes):
50+ if is_enabled():
51+ # Disable redshift
52+ toggle_cb(None)
53+ # If "suspend" is clicked while redshift is disabled, we reenable
54+ # it after the last selected timespan is over.
55+ remove_suspend_timer()
56+ # If redshift was already disabled we reenable it nonetheless.
57+ global SUSPEND_TIMER
58+ SUSPEND_TIMER = glib.timeout_add_seconds(minutes * 60, enable_cb)
59+
60 def autostart_cb(widget, data=None):
61 utils.set_autostart(widget.get_active())
62
63@@ -93,6 +130,16 @@
64 toggle_item.connect('activate', toggle_cb)
65 status_menu.append(toggle_item)
66
67+ suspend_menu_item = gtk.MenuItem(_('Suspend for'))
68+ suspend_menu = gtk.Menu()
69+ for minutes, label in [(30, _('30 minutes')), (60, _('1 hour')),
70+ (120, _('2 hours'))]:
71+ suspend_item = gtk.MenuItem(label)
72+ suspend_item.connect('activate', suspend_cb, minutes)
73+ suspend_menu.append(suspend_item)
74+ suspend_menu_item.set_submenu(suspend_menu)
75+ status_menu.append(suspend_menu_item)
76+
77 autostart_item = gtk.CheckMenuItem(_('Autostart'))
78 try:
79 autostart_item.set_active(utils.get_autostart())

Subscribers

People subscribed via source and target branches