1
# -.- coding: utf-8 -.-
3
# GNOME Activity Journal
5
# Copyright © 2009-2010 Seif Lotfy <seif@lotfy.com>
6
# Copyright © 2010 Siegfried Gevatter <siegfried@gevatter.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Lesser General Public License for more details.
18
# You should have received a copy of the GNU Lesser General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
from __future__ import with_statement
27
from config import DATA_PATH
29
def event_exists(uri):
30
# TODO: Move this into Zeitgeist's datamodel.py
31
return not uri.startswith("file://") or os.path.exists(
32
urllib.unquote(str(uri[7:])))
34
class Bookmarker(gobject.GObject):
37
"reload" : (gobject.SIGNAL_RUN_FIRST,
39
(gobject.TYPE_PYOBJECT,))
46
gobject.GObject.__init__(self)
47
self.bookmarks_file = os.path.join(DATA_PATH, "bookmarks.pickled")
51
if os.path.isfile(self.bookmarks_file):
53
with open(self.bookmarks_file) as f:
54
self.bookmarks = cPickle.load(f)
56
for bookmark in self.bookmarks:
57
if not event_exists(bookmark):
58
removable.append(bookmark)
60
self.bookmarks.remove(uri)
62
print "Pin database is corrupt."
65
with open(self.bookmarks_file, "w") as f:
66
cPickle.dump(self.bookmarks, f)
68
def bookmark(self, uri):
69
if not uri in self.bookmarks and event_exists(uri):
70
self.bookmarks.append(uri)
72
self.emit("reload", self.bookmarks)
74
def unbookmark(self, uri):
75
if uri in self.bookmarks:
76
self.bookmarks.remove(uri)
78
self.emit("reload", self.bookmarks)
80
def is_bookmarked(self, uri):
81
return uri in self.bookmarks
83
bookmarker = Bookmarker()