~ubuntu-branches/ubuntu/hardy/deskbar-applet/hardy-proposed

« back to all changes in this revision

Viewing changes to deskbar/handlers/desklicious.py

  • Committer: Bazaar Package Importer
  • Author(s): Aron Sisak
  • Date: 2007-08-07 17:00:18 UTC
  • mfrom: (1.1.31 upstream)
  • Revision ID: james.westby@ubuntu.com-20070807170018-ms9xlfneeo7x3aag
Tags: 2.19.6.1-0ubuntu1
* New upstream release (2.19.6.1):
  - Fixed bug #463974: 2.19.6 evolution handler does not build
  - Updated Translations: Gujarati, Spanish, Swedish, Thai
* New upstream release (2.19.6):
  - Added actions
  - Fixed bug #461627: Change the amount of items in history
  - Always show count in category header
  - Fixed evolution address book search with evo-ldap
  - Removed obsolete definitions from GConf and preferences and added
    new controls to preferences for previously unsupported options
  - Set process name to deskbar-applet
  - Cell containing the icon of a match doesn't expand anymore
  - Print tracebacks if module failed to load
  - Renamed gsoc_deskbar.py to deskbar-applet.py
  - Made sure that all icons are included in gnome-icon-theme
  - Added default icons for each category
  - Show window always in the foreground if triggered
  - Adjusted schema file so that intltool-merge works fast
  - Fixed: Pressing icon in panel didn't raise window
  - Don't show matches from a previous search if entry has been cleared by
    hand (i.e. not by hitting escape)
  - Fixed errors in epiphany and gdmactions module (Insted of printing error
    set INSTRUCION attribute)
  - Fixed bugs in BrowserMatch.py (fixes bug #438080)
  - Added: Check for duplicates
  - Make return value of get_hash() hashable for all modules
  - Only paste selection if keybinding has been activated
  - Each category has its own default icon
  - Fixed bug #456969: Desklicious plugin uses non-existent deskbar.Utils
  - Fixed bug #456968: Find /usr/lib*/firefox*/searchplugins
  - Fixed bug #456971: desklicious plugin improperly passess category to
    DeliciousMatch
  - Fixed bug #457133: DeliciousMatch has no 'name' and only default icon
  - Fixed bug #445145: Deskbar doesn't show up localized in the applet list
  - Fixed bug #456417: Poorly written schema descriptions
  - Updated Translations: Basque, Bengali, Dutch, Estonian, Finnish, French,
    German, Japanese, Norwegian, Slovenian, Spanish, Thai, Vietnamese
* New upstream release (2.19.5):
  - Major refactoring including a new GUI and Modules API.
  - Old modules won't work with this version
  - This release should contain almost all the features that Deskbar had
    before refactoring
* debian/patches/01_fix_python_interpreter.patch:
  - updated
* debian/patches/01_fix_pythonlib.patch:
  - dropped as not needed any more
* debian/patches/01_gpm_methods_naming_update.patch:
  - updated
* debian/patches/80-intltoolize.patch
  - updated via 'intltoolize --force'
* debian/patches/90_aclocal+autoconf+automake.patch:
  - updated via automagic

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
3
 
 
 
3
import sys
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
7
8
 
8
 
GCONF_DELICIOUS_USER  = deskbar.GCONF_DIR+"/desklicious/user"
 
9
GCONF_DELICIOUS_USER  = deskbar.core.GconfStore.GCONF_DIR+"/desklicious/user"
9
10
 
10
11
DEFAULT_QUERY_TAG = 'http://del.icio.us/rss/%s/%s'
11
12
QUERY_DELAY = 1
12
 
 
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)
17
 
        else:
18
 
                return (deskbar.Handler.HANDLER_IS_CONFIGURABLE, _("You can modify your del.icio.us account."), _on_config_account)
19
 
 
20
 
HANDLERS = {
21
 
        "DeliciousHandler" : {
22
 
                "name": _("del.icio.us Bookmarks"),
23
 
                "description": _("Search your del.icio.us bookmarks by tag name"),
24
 
                "requirements" : _check_requirements,
25
 
                "version": VERSION,
26
 
        }
27
 
}
28
 
 
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))
34
 
        
35
 
        table = gtk.Table(rows=2, columns=2)
36
 
        
37
 
        table.attach(gtk.Label(_("Enter your del.icio.us username below")), 0, 2, 0, 1)
38
 
 
39
 
        user_entry = gtk.Entry()
40
 
        t = deskbar.GCONF_CLIENT.get_string(GCONF_DELICIOUS_USER)
41
 
        if t != None:
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)
45
 
        
46
 
        table.show_all()
47
 
        dialog.vbox.add(table)
48
 
        
49
 
        response = dialog.run()
50
 
        dialog.destroy()
51
 
        
52
 
        if response == gtk.RESPONSE_ACCEPT and user_entry.get_text() != "":
53
 
                deskbar.GCONF_CLIENT.set_string(GCONF_DELICIOUS_USER, user_entry.get_text())
54
 
 
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)
58
 
                self.url = url
 
13
HANDLERS = ["DeliciousHandler"]
 
14
 
 
15
class DeliciousAction(ShowUrlAction):
 
16
        
 
17
        def __init__(self, name, url, tags):
 
18
                ShowUrlAction.__init__(self, name, url)
59
19
                self.tags = tags
60
 
                self.author = author
61
20
                
62
21
        def get_verb(self):
63
22
                return "<b>%(name)s</b>\n<span size='small' foreground='grey'>%(tags)s</span>"
64
23
        
65
24
        def get_name(self, text=None):
66
25
                return {
67
 
                        "name": cgi.escape(self.name),
68
 
                        "tags": cgi.escape(' '.join(self.tags)),
 
26
                        "name": self._name,
 
27
                        "tags": ' '.join(self.tags),
69
28
                }
70
29
                
71
 
        def action(self, text=None):
72
 
                deskbar.Utils.url_show(self.url)
73
 
 
74
 
        def get_category(self):
75
 
                return "web"
 
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)
 
33
                self.url = url
 
34
                self.author = author
 
35
                self.add_action( DeliciousAction(self.get_name(), self.url, tags) )
76
36
 
77
37
        def get_hash(self, text=None):
78
38
                return self.url
79
39
                
80
 
class DeliciousHandler(deskbar.Handler.AsyncHandler):
 
40
class DeliciousHandler(deskbar.interfaces.Module):
 
41
        
 
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"),
 
45
                         "version": VERSION,
 
46
                         }
 
47
        
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)
84
51
 
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)
 
54
                # TODO: Missing
 
55
                #self.check_query_changed (timeout=QUERY_DELAY)
88
56
                
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 ()
 
59
                # TODO: Missing
 
60
                #self.check_query_changed ()
92
61
                
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)
96
65
 
97
 
                self.check_query_changed (timeout=QUERY_DELAY)
98
 
                print 'Returning del.icio.us result', posts
99
 
                
100
 
                return posts
 
66
                # TODO: Missing
 
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 )
 
71
                
 
72
        def has_config(self):
 
73
                return True
 
74
                
 
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))
 
80
        
 
81
                table = gtk.Table(rows=2, columns=2)
 
82
                
 
83
                table.attach(gtk.Label(_("Enter your del.icio.us username below")), 0, 2, 0, 1)
 
84
        
 
85
                user_entry = gtk.Entry()
 
86
                t = deskbar.core.GconfStore.get_instance().get_client().get_string(GCONF_DELICIOUS_USER)
 
87
                if t != None:
 
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)
 
91
                
 
92
                table.show_all()
 
93
                dialog.vbox.add(table)
 
94
                
 
95
                response = dialog.run()
 
96
                dialog.destroy()
 
97
                
 
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())
 
100
 
 
101
        @staticmethod
 
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.")
 
106
                        # TODO
 
107
                        #_on_config_account()
 
108
                        return True
 
109
                else:
 
110
                        DeliciousHandler.INSTRUCTIONS = _("You can modify your del.icio.us account.")
 
111
                        # TODO
 
112
                        #_on_config_account()
 
113
                        return True
101
114
 
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
106
119
                
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)
108
121
                        
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))
110
123
                
111
124
        def on_username_change(self, value):
112
125
                if value != None and value.type == gconf.VALUE_STRING:
116
129
                #Get the info from del.icio.us and parse
117
130
                url = DEFAULT_QUERY_TAG % (urllib.quote_plus(self._user), urllib.quote_plus(tag))
118
131
 
119
 
                stream = urllib.urlopen(url, proxies=deskbar.Utils.get_proxy())
 
132
                stream = urllib.urlopen(url, proxies=deskbar.core.Utils.get_proxy())
120
133
                dom = xml.dom.minidom.parse(stream)
121
134
                stream.close()
122
135
                
124
137
                posts=[]
125
138
                for item in dom.getElementsByTagName("item"):
126
139
                        posts.append(
127
 
                                DeliciousMatch(self.handler,
 
140
                                DeliciousMatch(
128
141
                                        name=item.getElementsByTagName("title")[0].firstChild.nodeValue,
129
142
                                        url=item.getElementsByTagName("link")[0].firstChild.nodeValue,
130
143
                                        tags=item.getElementsByTagName("dc:subject")[0].firstChild.nodeValue.split(" "),
131
 
                                        author=item.getElementsByTagName("dc:creator")[0].firstChild.nodeValue))
 
144
                                        author=item.getElementsByTagName("dc:creator")[0].firstChild.nodeValue,
 
145
                                        category="web"))
132
146
                
133
147
                return posts
134
148