1
# Copyright (C) 2011 by Guillaume Hain (zedtux) <zedtux@zedroot.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
from bzrlib.plugins.gtk import _i18n
20
from bzrlib.config import parse_username
22
class Avatar(gtk.Box):
23
""" Author or committer avatar """
25
def __init__(self, username):
27
gtk.Box.__init__(self)
29
self.__username = username
30
self.__name, self.__email = parse_username(username)
34
# ~~~~~ Properties ~~~~~
36
def get_username(self):
37
return self.__username
38
def set_username(self, username):
39
self.__username = username
40
username = property(get_username, set_username)
45
def set_name(self, name):
47
name = property(get_name, set_name)
52
def set_email(self, email):
54
email = property(get_email, set_email)
59
def set_image(self, image):
61
image = property(get_image, set_image)
64
# ~~~~~ Public methods ~~~~~
65
def show_spinner(self):
67
Replace the current content of the Avatar with a gtk.Spinner
68
if an email address has been parsed. If not, show an gtk.Label with
69
the translatable 'No email' text.
71
if not self.email is "":
72
spinner = gtk.Spinner()
74
self.pack_start(spinner, False)
75
spinner.set_tooltip_text(_i18n("Retrieving avatar for %s...") % self.email)
76
spinner.set_size_request(20, 20)
79
no_email = gtk.Label(_i18n("No email"))
80
self.pack_start(no_email)
81
self.set_tooltip_text("self.username")
85
""" Replace the current content of the Avatar with the gtk.Image """
86
if not self.email is "" and self.image:
87
self.remove(self.get_children()[0])
88
self.pack_start(self.image)
89
self.image.set_tooltip_text(self.username)
92
def is_identical(self, avatar):
94
Return True if attributes of the given avatar
95
match to current object attributes otherwise return False
97
return self.username == avatar.username and \
98
self.name == avatar.name and \
99
self.email == avatar.email