3 # This file is part of Jamaendo.
4 # Copyright (c) 2010 Kristoffer Gronlund
6 # Jamaendo is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # Jamaendo is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Jamaendo. If not, see <http://www.gnu.org/licenses/>.
19 # Player code heavily based on http://thpinfo.com/2008/panucci/:
20 # A resuming media player for Podcasts and Audiobooks
21 # Copyright (c) 2008-05-26 Thomas Perl <thpinfo.com>
22 # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
27 from postoffice import postoffice
30 log = logging.getLogger(__name__)
32 class Settings(object):
36 'favorites':set([]) # local favorites - until we can sync back
40 self.__savename = "/tmp/jamaendo_uisettings"
41 for k,v in self.defaults.iteritems():
44 def __setattr__(self, key, value):
45 object.__setattr__(self, key, value)
46 if key in self.defaults.keys():
47 postoffice.notify('settings-changed', key, value)
49 def set_filename(self, savename):
50 self.__savename = savename
52 def favorite(self, album):
53 self.favorites.add(('album', album.ID))
57 if not os.path.isfile(self.__savename):
60 f = open(self.__savename)
61 settings = cPickle.load(f)
64 if settings['version'] > VERSION:
65 log.warning("Settings version %s higher than current version (%s)",
66 settings['version'], VERSION)
68 for k in self.defaults.keys():
70 setattr(self, k, settings[k])
72 log.exception('failed to load settings')
79 for k in self.defaults.keys():
80 settings[k] = getattr(self, k)
81 f = open(self.__savename, 'w')
82 cPickle.dump(settings, f)
85 log.exception('failed to save settings')