1
import os, cgi, os.path, deskbar, deskbar.Match, deskbar.Handler, deskbar.Utils
1
import os, os.path, deskbar, deskbar.interfaces.Match, deskbar.interfaces.Module, deskbar.core.Utils, deskbar.core.GconfStore
2
2
import gnomevfs, gtk, gconf
4
4
from gettext import gettext as _
5
5
import xml.dom.minidom, urllib
6
6
from deskbar.defs import VERSION
7
from deskbar.handlers.actions.ShowUrlAction import ShowUrlAction
8
GCONF_DELICIOUS_USER = deskbar.GCONF_DIR+"/desklicious/user"
9
GCONF_DELICIOUS_USER = deskbar.core.GconfStore.GCONF_DIR+"/desklicious/user"
10
11
DEFAULT_QUERY_TAG = 'http://del.icio.us/rss/%s/%s'
13
def _check_requirements():
14
#We need user and password
15
if not deskbar.GCONF_CLIENT.get_string(GCONF_DELICIOUS_USER):
16
return (deskbar.Handler.HANDLER_HAS_REQUIREMENTS, _("You need to configure your del.icio.us account."), _on_config_account)
18
return (deskbar.Handler.HANDLER_IS_CONFIGURABLE, _("You can modify your del.icio.us account."), _on_config_account)
21
"DeliciousHandler" : {
22
"name": _("del.icio.us Bookmarks"),
23
"description": _("Search your del.icio.us bookmarks by tag name"),
24
"requirements" : _check_requirements,
29
def _on_config_account(dialog):
30
dialog = gtk.Dialog(_("del.icio.us Account"), dialog,
31
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
32
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
33
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
35
table = gtk.Table(rows=2, columns=2)
37
table.attach(gtk.Label(_("Enter your del.icio.us username below")), 0, 2, 0, 1)
39
user_entry = gtk.Entry()
40
t = deskbar.GCONF_CLIENT.get_string(GCONF_DELICIOUS_USER)
42
user_entry.set_text(t)
43
table.attach(gtk.Label(_("Username: ")), 0, 1, 1, 2)
44
table.attach(user_entry, 1, 2, 1, 2)
47
dialog.vbox.add(table)
49
response = dialog.run()
52
if response == gtk.RESPONSE_ACCEPT and user_entry.get_text() != "":
53
deskbar.GCONF_CLIENT.set_string(GCONF_DELICIOUS_USER, user_entry.get_text())
55
class DeliciousMatch(deskbar.Match.Match):
56
def __init__(self, handler, url=None, tags=None, author=None, **args):
57
deskbar.Match.Match.__init__ (self, handler, **args)
13
HANDLERS = ["DeliciousHandler"]
15
class DeliciousAction(ShowUrlAction):
17
def __init__(self, name, url, tags):
18
ShowUrlAction.__init__(self, name, url)
62
21
def get_verb(self):
63
22
return "<b>%(name)s</b>\n<span size='small' foreground='grey'>%(tags)s</span>"
65
24
def get_name(self, text=None):
67
"name": cgi.escape(self.name),
68
"tags": cgi.escape(' '.join(self.tags)),
27
"tags": ' '.join(self.tags),
71
def action(self, text=None):
72
deskbar.Utils.url_show(self.url)
74
def get_category(self):
30
class DeliciousMatch(deskbar.interfaces.Match):
31
def __init__(self, url=None, tags=None, author=None, **args):
32
deskbar.interfaces.Match.__init__ (self, icon="delicious.png", **args)
35
self.add_action( DeliciousAction(self.get_name(), self.url, tags) )
77
37
def get_hash(self, text=None):
80
class DeliciousHandler(deskbar.Handler.AsyncHandler):
40
class DeliciousHandler(deskbar.interfaces.Module):
42
INFOS = {'icon': deskbar.core.Utils.load_icon("delicious.png"),
43
"name": _("del.icio.us Bookmarks"),
44
"description": _("Search your del.icio.us bookmarks by tag name"),
81
48
def __init__(self):
82
deskbar.Handler.AsyncHandler.__init__ (self, "delicious.png")
49
deskbar.interfaces.Module.__init__ (self)
83
50
self._delicious = DeliciousTagQueryEngine(self)
85
52
def query(self, tag):
86
53
#Hey man, calm down and query once a time :P
87
self.check_query_changed (timeout=QUERY_DELAY)
55
#self.check_query_changed (timeout=QUERY_DELAY)
89
57
# Yes, the google and yahoo search might take a long time
90
58
# and of course deliciuos too !!! ... better check if we're still valid
91
self.check_query_changed ()
60
#self.check_query_changed ()
93
62
#The queryyyyYyyYy :)
94
63
print "Asking del.icio.us tags for %s" % tag
95
64
posts = self._delicious.get_posts_by_tag(tag)
97
self.check_query_changed (timeout=QUERY_DELAY)
98
print 'Returning del.icio.us result', posts
67
#self.check_query_changed (timeout=QUERY_DELAY)
68
print 'Returning del.icio.us result'
69
self.set_priority_for_matches( posts )
70
self._emit_query_ready(tag, posts )
75
def show_config(self, parent):
76
dialog = gtk.Dialog(_("del.icio.us Account"), parent,
77
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
78
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
79
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
81
table = gtk.Table(rows=2, columns=2)
83
table.attach(gtk.Label(_("Enter your del.icio.us username below")), 0, 2, 0, 1)
85
user_entry = gtk.Entry()
86
t = deskbar.core.GconfStore.get_instance().get_client().get_string(GCONF_DELICIOUS_USER)
88
user_entry.set_text(t)
89
table.attach(gtk.Label(_("Username: ")), 0, 1, 1, 2)
90
table.attach(user_entry, 1, 2, 1, 2)
93
dialog.vbox.add(table)
95
response = dialog.run()
98
if response == gtk.RESPONSE_ACCEPT and user_entry.get_text() != "":
99
deskbar.core.GconfStore.get_instance().get_client().set_string(GCONF_DELICIOUS_USER, user_entry.get_text())
102
def has_requirements():
103
#We need user and password
104
if not deskbar.core.GconfStore.get_instance().get_client().get_string(GCONF_DELICIOUS_USER):
105
DeliciousHandler.INSTRUCTIONS = _("You need to configure your del.icio.us account.")
107
#_on_config_account()
110
DeliciousHandler.INSTRUCTIONS = _("You can modify your del.icio.us account.")
112
#_on_config_account()
102
115
class DeliciousTagQueryEngine:
103
116
def __init__(self, handler):
104
117
"""We need use the globals DELICIOUS_USER and DELICIOUS_PASS"""
105
118
self.handler = handler
107
self._user = deskbar.GCONF_CLIENT.get_string(GCONF_DELICIOUS_USER)
120
self._user = deskbar.core.GconfStore.get_instance().get_client().get_string(GCONF_DELICIOUS_USER)
109
deskbar.GCONF_CLIENT.notify_add(GCONF_DELICIOUS_USER, lambda x, y, z, a: self.on_username_change(z.value))
122
deskbar.core.GconfStore.get_instance().get_client().notify_add(GCONF_DELICIOUS_USER, lambda x, y, z, a: self.on_username_change(z.value))
111
124
def on_username_change(self, value):
112
125
if value != None and value.type == gconf.VALUE_STRING: