~ssh-rdp/deskbar-applet/history-count

« back to all changes in this revision

Viewing changes to src/handler_gtk_bookmarks.py

  • Committer: rslinckx
  • Date: 2005-09-13 16:36:46 UTC
  • Revision ID: vcs-imports@canonical.com-20050913163646-gx8uamx1ea5564up
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import gnomevfs
 
2
import os.path
 
3
import deskbar
 
4
import deskbar.indexer
 
5
 
 
6
 
 
7
bookmarks_index = deskbar.indexer.Index()
 
8
 
 
9
 
 
10
def load_gtk_bookmarks():
 
11
        bookmarks_index.clear()
 
12
        try:
 
13
                sorted_lines = []
 
14
                for line in file(deskbar.HOME_DIR + "/.gtk-bookmarks"):
 
15
                        line = line.replace("%20", " ").strip()
 
16
                        if gnomevfs.exists(line):
 
17
                                if line.startswith("file://"):
 
18
                                        line = line[7:]
 
19
                                if line.startswith(deskbar.HOME_DIR):
 
20
                                        line = "~" + line[len(deskbar.HOME_DIR):]
 
21
                                sorted_lines.append(line)
 
22
                sorted_lines.sort()
 
23
                for path in sorted_lines:
 
24
                        head, tail = os.path.split(path)
 
25
                        bookmarks_index.add(tail, (path, tail))
 
26
        except IOError:
 
27
                pass
 
28
 
 
29
 
 
30
class Handler:
 
31
        def add_to_completions(self, text, completions, handler_icon, check_can_handle=True):
 
32
                name = self.name()
 
33
                for (path, tail) in bookmarks_index.look_up(text):
 
34
                        d = "Open the bookmark <b>%s</b> (%s)" % \
 
35
                                (deskbar.escape_markup(tail), deskbar.escape_markup(path))
 
36
                        completions.append([d, name, path, deskbar.FOLDER_BOOKMARK_IMAGE.get_pixbuf()])
 
37
                return handler_icon
 
38
 
 
39
 
 
40
        def name(self):
 
41
                return "Handler_Gtk_Bookmarks"
 
42
 
 
43
 
 
44
        def can_handle(self, text):
 
45
                return False
 
46
 
 
47
 
 
48
        def handle(self, text, check_can_handle=True):
 
49
                deskbar.run_command("gnome-open \"%s\"", text)
 
50
 
 
51
 
 
52
load_gtk_bookmarks()