1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2008 Toms Bauģis <toms.baugis at gmail.com>
5
# This file is part of Project Hamster.
7
# Project Hamster is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# Project Hamster is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
24
from db import Storage
25
from dispatcher import Dispatcher
27
class Singleton(object):
28
def __new__(cls, *args, **kwargs):
29
if '__instance' not in vars(cls):
30
cls.__instance = object.__new__(cls, *args, **kwargs)
33
class RuntimeStore(Singleton):
35
Handles one-shot configuration that is not stored between sessions
44
gettext.install("hamster-applet", unicode = True)
46
# Typically shared data dir is /usr/share/hamster-applet
47
if os.path.realpath(__file__).startswith(defs.PYTHONDIR):
48
data_dir = os.path.join(defs.DATA_DIR, "hamster-applet")
50
data_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data'))
51
self.data_dir = data_dir
52
self.dispatcher = Dispatcher()
53
self.storage = Storage(self.dispatcher)
55
def get_art_dir(self):
56
return os.path.join(self.data_dir, "art")
58
art_dir = property(get_art_dir, None)
60
runtime = RuntimeStore()
61
runtime.database_file = os.path.expanduser("~/.gnome2/hamster-applet/hamster.db")
63
class GconfStore(Singleton):
65
Handles storing to and retrieving values from GConf
68
# GConf directory for deskbar in window mode and shared settings
69
GCONF_DIR = "/apps/hamster-applet/general"
71
# GConf key for global keybinding
72
GCONF_KEYBINDING = GCONF_DIR + "/keybinding"
73
GCONF_ENABLE_TIMEOUT = GCONF_DIR + "/enable_timeout"
74
GCONF_STOP_ON_SHUTDOWN = GCONF_DIR + "/stop_on_shutdown"
75
GCONF_NOTIFY_INTERVAL = GCONF_DIR + "/notify_interval"
76
GCONF_NOTIFY_ON_IDLE = GCONF_DIR + "/notify_on_idle"
81
super(GconfStore, self).__init__()
82
self._client = gconf.client_get_default()
83
self.__connect_notifications()
85
def __connect_notifications(self):
86
self._client.add_dir(self.GCONF_DIR, gconf.CLIENT_PRELOAD_RECURSIVE)
87
self._client.notify_add(self.GCONF_KEYBINDING, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_keybinding_changed", z.value.get_string()))
88
self._client.notify_add(self.GCONF_ENABLE_TIMEOUT, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_timeout_enabled_changed", z.value.get_bool()))
89
self._client.notify_add(self.GCONF_STOP_ON_SHUTDOWN, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_stop_on_shutdown_changed", z.value.get_bool()))
90
self._client.notify_add(self.GCONF_NOTIFY_INTERVAL, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_notify_interval_changed", z.value.get_int()))
91
self._client.notify_add(self.GCONF_NOTIFY_ON_IDLE, lambda x, y, z, a: runtime.dispatcher.dispatch("gconf_notify_on_idle_changed", z.value.get_bool()))
94
def get_keybinding(self):
95
return self._client.get_string(self.GCONF_KEYBINDING) or ""
97
def get_timeout_enabled(self):
98
return self._client.get_bool(self.GCONF_ENABLE_TIMEOUT) or False
100
def get_stop_on_shutdown(self):
101
return self._client.get_bool(self.GCONF_STOP_ON_SHUTDOWN) or False
103
def get_notify_interval(self):
104
return self._client.get_int(self.GCONF_NOTIFY_INTERVAL) or 27
106
def get_notify_on_idle(self):
107
return self._client.get_bool(self.GCONF_NOTIFY_ON_IDLE) or False
109
#------------------------
110
def set_keybinding(self, binding):
111
self._client.set_string(self.GCONF_KEYBINDING, binding)
113
def set_timeout_enabled(self, enabled):
114
self._client.set_bool(self.GCONF_ENABLE_TIMEOUT, enabled)
116
def set_stop_on_shutdown(self, enabled):
117
self._client.set_bool(self.GCONF_STOP_ON_SHUTDOWN, enabled)
119
def set_notify_interval(self, interval):
120
return self._client.set_int(self.GCONF_NOTIFY_INTERVAL, interval)
122
def set_notify_on_idle(self, enabled):
123
self._client.set_bool(self.GCONF_NOTIFY_ON_IDLE, enabled)