=== added file 'caffeine/config.py'
--- caffeine/config.py 1970-01-01 00:00:00 +0000
+++ caffeine/config.py 2014-05-08 19:05:20 +0000
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright © 2009-2014 The Caffeine Developers
+#
+# This program 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.
+#
+# This program 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 this program. If not, see .
+#
+
+import os
+import ConfigParser
+
+class Config(object):
+ configHome = os.path.expanduser("~/.config/caffeine")
+ configFile = os.path.join(configHome, "config")
+
+ def __init__(self):
+ # create config if it doesn't exists
+ if not os.path.exists(Config.configHome):
+ os.mkdir(Config.configHome)
+
+ if not os.path.exists(Config.configFile):
+ self.writeConfig(self.getDefaultConfig())
+
+
+ # to avoid keeping config in memory
+ # create instance when needed
+ def getConfig(self):
+ config = ConfigParser.RawConfigParser()
+ config.readfp(open(Config.configFile))
+ return config
+
+
+ # FIXME: use skeleton config file
+ def getDefaultConfig(self):
+ config = ConfigParser.ConfigParser()
+ config.add_section('preferences')
+ config.set('preferences', 'persistent', 'false')
+ return config
+
+
+ def getPreference(self, option):
+ return self.getConfig().getboolean("preferences", option)
+
+
+ def setPreference(self, option, boolean):
+ config = self.getConfig()
+ config.set("preferences", option, boolean)
+ self.writeConfig(config)
+
+
+ def writeConfig(self, config):
+ with open(Config.configFile, 'wb') as configFile:
+ config.write(configFile)
=== modified file 'caffeine/core.py'
--- caffeine/core.py 2014-02-25 19:25:28 +0000
+++ caffeine/core.py 2014-05-08 19:07:39 +0000
@@ -24,6 +24,7 @@
import subprocess
import dbus
import logging
+from config import Config
import applicationinstance
@@ -36,6 +37,8 @@
def __init__(self):
GObject.GObject.__init__(self)
+ self.config = Config()
+
## Status string.
self.status_string = ""
@@ -50,10 +53,15 @@
self.preventedForFullScreen = False
self.screenSaverCookie = None
+ self.persistent = self.config.getPreference("persistent")
+
+ if self.persistent:
+ self.setActivated(True)
+
# Add hook for full-screen check (same interval as mplayer's heartbeat command)
# FIXME: add capability to xdg-screensaver to report timeout
GObject.timeout_add(30000, self._check_for_fullscreen)
-
+
print self.status_string
@@ -105,6 +113,9 @@
def getActivated(self):
return self.sleepIsPrevented
+ def getPersistent(self):
+ return self.persistent
+
def _deactivate(self):
self.toggleActivated()
@@ -130,7 +141,15 @@
self.emit("activation-toggled", self.getActivated(),
self.status_string)
self.status_string = ""
+
+ def togglePersistent(self):
+ self.persistent = not self.persistent
+ self.config.setPreference("persistent", self.persistent)
+ if self.persistent:
+ self.setActivated(True)
+
+ self.emit("persistent-toggled", self.persistent)
def _performTogglingActions(self):
"""This method performs the actions that affect desktop idleness."""
@@ -157,3 +176,5 @@
## register a signal
GObject.signal_new("activation-toggled", Caffeine,
GObject.SignalFlags.RUN_FIRST, None, [bool, str])
+GObject.signal_new("persistent-toggled", Caffeine,
+ GObject.SignalFlags.RUN_FIRST, None, [bool])
=== modified file 'caffeine/main.py'
--- caffeine/main.py 2014-02-01 00:41:57 +0000
+++ caffeine/main.py 2014-05-08 18:35:35 +0000
@@ -37,6 +37,7 @@
self.Core = core.Caffeine()
self.Core.connect("activation-toggled", self.on_activation_toggled)
+ self.Core.connect("persistent-toggled", self.on_persistent_toggled)
builder = Gtk.Builder()
builder.add_from_file(os.path.join(caffeine.GLADE_PATH,
@@ -54,6 +55,9 @@
self.activate_menuitem = get("activate_menuitem")
self.set_icon_is_activated(self.Core.getActivated())
+ self.persistent_menuitem = get("persistent_menuitem")
+ self.set_persistent_activated(self.Core.getPersistent())
+
## popup menu
self.menu = get("popup_menu")
self.menu.show()
@@ -76,6 +80,9 @@
def on_activation_toggled(self, source, active, tooltip):
self.set_icon_is_activated(active)
+ def on_persistent_toggled(self, source, active):
+ self.set_persistent_activated(active)
+
def set_icon_is_activated(self, activated):
## toggle the icon, indexing with a bool.
icon_name = ["caffeine-cup-empty", "caffeine-cup-full"][activated]
@@ -85,6 +92,10 @@
label = [_("Disable Screensaver"), _("Enable Screensaver")]
self.activate_menuitem.set_label (label[self.Core.getActivated()])
+ def set_persistent_activated(self, activated):
+ label = [_("Enable Persistent"), _("Disable Persistent")]
+ self.persistent_menuitem.set_label(label[self.Core.getPersistent()])
+
### Callbacks
def on_R_click(self, status_icon, mbutton, time, data=None):
## popdown menu
@@ -100,6 +111,9 @@
label = [_("Disable Screensaver"), _("Enable Screensaver")]
menuitem.set_label (label[self.Core.getActivated()])
+ def on_activate_menuitem_persistent(self, menuitem, data=None):
+ self.Core.togglePersistent()
+
def on_prefs_menuitem_activate(self, menuitem, data=None):
self.window.show_all()
=== modified file 'share/caffeine/glade/GUI.glade'
--- share/caffeine/glade/GUI.glade 2014-02-25 21:00:57 +0000
+++ share/caffeine/glade/GUI.glade 2014-05-08 17:04:59 +0000
@@ -1,5 +1,7 @@
+
+
-
+
@@ -74,13 +76,13 @@
-
+
-
-
\ No newline at end of file
+
+