Skip to content

Commit

Permalink
Use the twitter/identi.ca user avatar in the notifications
Browse files Browse the repository at this point in the history
We show the friend avatar in the notification and the sender name
  • Loading branch information
chuchiperriman committed Mar 29, 2010
1 parent 4e99a4d commit e403726
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
6 changes: 3 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Milestone 0.6.0
===============
* GUI time...
- Twitter/Identi.ca:
[ ] Select to use the profile avatar or the default icon in the indicator
[ ] Select to use the message avatar or the default icon in notifications
[ ] Show the friend name/icon in the notifications
[X] Select to use the profile avatar or the default icon in the indicator
[X] Select to use the message avatar or the default icon in notifications
[X] Show the friend name/icon in the notifications
[X] Show an stop emblem when an account has errors
[X] Show the stop emblem in the preferences dialog too
[ ] Create the about dialog
Expand Down
3 changes: 2 additions & 1 deletion src/cloudsn/core/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import gettext

class Notification:
def __init__(self, id = None, message = None, sender = None):
def __init__(self, id = None, message = None, sender = None, icon = None):
self.id = id
self.sender = sender
self.message = message
self.icon = icon

class Account:
def __init__ (self, properties, provider):
Expand Down
8 changes: 6 additions & 2 deletions src/cloudsn/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ def __real_update_account(self, acc):

if len(nots) > 0 and len(nots) <= max_notifications:
for n in nots:
notification.notify(acc.get_name(),
if n.icon:
icon = n.icon
else:
icon = acc.get_icon()
notification.notify(acc.get_name() + ": " + n.sender,
n.message,
acc.get_icon())
icon)

self.emit("account-checked", acc)
except notification.NotificationError, ne:
Expand Down
2 changes: 2 additions & 0 deletions src/cloudsn/core/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def get_name (self):
return self.name
def get_icon (self):
return self.icon
def validate(self, widget):
return True
def create_account_dialog(self, account_name, parent_window):
""" Returns the new created account"""
return None
Expand Down
22 changes: 22 additions & 0 deletions src/cloudsn/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import subprocess
from email.header import decode_header
from cloudsn.core import config
import tempfile
import urllib2

def show_url(url):
"""Open any @url with default viewer"""
Expand Down Expand Up @@ -53,6 +55,26 @@ def get_account_error_pixbuf (acc):
error.composite(original, 10, 10, 22, 22, 10, 10, 1.0, 1.0, gtk.gdk.INTERP_HYPER, 220)
return original

def download_image_to_tmp(url):
filename = url.replace('http://', '0_')
filename = filename.replace('/', '_')
fullname = os.path.join(tempfile.gettempdir(), filename)

if os.path.exists(fullname):
return fullname

f = urllib2.urlopen(url).read()

fich = open(fullname, 'w+')
fich.write(f)
fich.close()

return fullname

def download_image_to_pixbuf(url):
path = download_image_to_tmp(url)
return gtk.gdk.pixbuf_new_from_file(path)

if __name__ == "__main__":
print get_default_mail_reader()
open_mail_reader()
Expand Down
19 changes: 15 additions & 4 deletions src/cloudsn/providers/twitterprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from cloudsn.core import utils
from cloudsn.core import config
from cloudsn.providers import twitter
from cloudsn import logger
import gtk

class TwitterProvider(ProviderBase):
Expand Down Expand Up @@ -67,16 +68,26 @@ def update_account (self, account):
for m in messages:
if m.id not in account.notifications:
account.notifications[m.id] = m.id
news.append (Notification(m.id, m.text, m.user.screen_name))
news.append (Notification(m.id, m.text, m.user.screen_name,
self.get_message_icon(m)))
else:
#If it is the fist update, show the last message only
account.notifications[messages[0].id] = messages[0].id
news.append (Notification(messages[0].id, messages[0].text, messages[0].user.screen_name))

news.append (Notification(messages[0].id, messages[0].text,
messages[0].user.screen_name,
self.get_message_icon(messages[0])))

account.new_unread = news;
account.last_id = messages[0].id


def get_message_icon(self,m):
icon = None
try:
icon = utils.download_image_to_pixbuf(m.user.profile_image_url)
except Exception, e:
logger.exception("Error loading the user avatar",e)

return icon

class TwitterAccount (AccountCacheMails):

Expand Down

0 comments on commit e403726

Please sign in to comment.