1
# -*- coding: utf-8 -*-
3
# This file is part of emesene.
5
# emesene is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
10
# emesene is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with emesene; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
class ContactInfoList(gtk.VBox):
29
'''A widget that contains the display picture of the contact in single chat.
30
If multi chat, it shows more information about contacts.
31
It also contains our own display picture.'''
33
NAME = 'Contact info list'
34
DESCRIPTION = 'A panel to show contacts info as a list'
35
AUTHOR = 'Ariel Juodziukynas (arielj)'
36
WEBSITE = 'www.arieljuod.com.ar'
38
def __init__(self, session, members):
39
gtk.VBox.__init__(self)
40
self.set_border_width(2)
41
self.session = session
46
self._first_alig = gtk.Alignment(xalign=0.5, yalign=0.0,
47
xscale=1.0, yscale=0.0)
48
self._last_alig = None
49
self._last_alig = gtk.Alignment(xalign=0.5, yalign=1.0,
50
xscale=0.0, yscale=0.0)
51
self.pack_start(self._first_alig)
52
self.pack_end(self._last_alig)
54
Avatar = extension.get_default('avatar')
55
avatar_size = self.session.config.get_or_set('i_conv_avatar_size', 64)
58
self.avatarBox = gtk.EventBox()
59
self.avatarBox.set_events(gtk.gdk.BUTTON_PRESS_MASK)
60
if self.session.session_has_service(e3.Session.SERVICE_PROFILE_PICTURE):
61
self.avatarBox.connect('button-press-event', self._on_avatar_click)
62
self.avatarBox.set_tooltip_text(_('Click here to set your avatar'))
64
self.avatar = Avatar(cell_dimension=avatar_size)
65
self.avatarBox.add(self.avatar)
67
self.avatarBox.set_border_width(4)
69
self.last = self.avatarBox
70
self.avatar.set_from_file(self.session.config.last_avatar)
72
#contact's avatar if single chat
73
self.his_avatarBox = gtk.EventBox()
74
self.his_avatarBox.set_events(gtk.gdk.BUTTON_PRESS_MASK)
75
self.his_avatarBox.connect('button-press-event',
76
self._on_his_avatar_click)
78
self.his_avatar = Avatar(cell_dimension=avatar_size)
79
self.his_avatarBox.add(self.his_avatar)
81
self.his_avatarBox.set_tooltip_text(_('Click to see informations'))
82
self.his_avatarBox.set_border_width(4)
84
#contacts list if multichat
86
self._contact_list = gtk.TreeView()
87
self._contact_list.set_can_focus(False)
88
avatar = gtk.CellRendererPixbuf()
89
nick = extension.get_and_instantiate('nick renderer')
90
status = gtk.CellRendererPixbuf()
92
nick.set_property('ellipsize', pango.ELLIPSIZE_END)
93
column = gtk.TreeViewColumn()
94
column.set_expand(True)
95
column.pack_start(avatar, False)
96
column.pack_start(nick, True)
97
column.pack_start(status, False)
98
column.add_attribute(avatar, 'pixbuf', 0)
99
column.add_attribute(nick, 'markup', 2)
100
column.add_attribute(status, 'pixbuf', 3)
101
self._contact_list.append_column(column)
102
self.tooltips = Tooltips.Tooltips()
103
self._contact_list.connect('motion-notify-event',
104
self.tooltips.on_motion)
106
self._contact_list.connect('leave-notify-event',
107
self.tooltips.on_leave)
109
if len(members) == 1:
110
self.update_single(members)
111
elif len(members) > 1:
112
self.update_group(members)
113
#else: can members by 0?
115
def _set_first(self, first):
116
'''set the first element and add it to the widget (remove the
117
previous if not None'''
118
if self._first is not None:
119
self._first_alig.remove(self._first)
121
self._first_alig.add(self._first)
122
self._first_alig.show_all()
124
def _get_first(self):
125
'''return the first widget'''
128
first = property(fget=_get_first, fset=_set_first)
130
def _set_last(self, last):
131
'''set the last element and add it to the widget (remove the
132
previous if not None'''
133
if self._last is not None:
134
self._last_alig.remove(self._last)
136
self._last_alig.add(self._last)
137
self._last_alig.show_all()
140
'''return the last widget'''
143
last = property(fget=_get_last, fset=_set_last)
145
def _on_avatar_click(self, widget, data):
146
'''method called when user click on his avatar '''
147
av_chooser = extension.get_and_instantiate('avatar chooser', self.session)
148
av_chooser.set_modal(True)
151
def _on_his_avatar_click(self, widget, data):
152
'''method called when user click on the other avatar '''
153
account = self.members[0]
154
contact = self.session.contacts.get(account)
156
dialog = extension.get_default('dialog')
157
dialog.contact_information_dialog(self.session, contact.account)
159
def _on_avatarsize_changed(self, value):
160
'''callback called when config.i_conv_avatar_size changes'''
161
self.avatarBox.remove(self.avatar)
162
self.his_avatarBox.remove(self.his_avatar)
164
self.avatar.set_property('dimension', value)
165
self.his_avatar.set_property('dimension', value)
167
self.avatarBox.add(self.avatar)
168
self.his_avatarBox.add(self.his_avatar)
171
#stop the avatars animation... if any...
173
self.his_avatar.stop()
175
def set_sensitive(self, is_sensitive):
176
self.avatarBox.set_sensitive(is_sensitive)
177
self.his_avatarBox.set_sensitive(is_sensitive)
179
def update_single(self, members):
180
''' sets the avatar of our contact '''
181
self.members = members
183
contact = self.session.contacts.safe_get(account)
184
self.his_avatar.set_from_file(contact.picture)
185
self._first_alig.set(0.5, 0.0, 1.0, 0.0)
186
self.set_size_request(-1, -1)
187
self.first = self.his_avatarBox
189
def update_group(self, members):
190
''' sets the contacts list instead of a contact's avatar '''
191
self._contact_list.set_model(None)
193
self._model = gtk.ListStore(gtk.gdk.Pixbuf, object,
195
self.members = members
196
for member in self.members:
197
contact = self.session.contacts.safe_get(member)
198
picture = contact.picture or gui.theme.image_theme.user
199
contact_data = (utils.safe_gtk_pixbuf_load(picture, (15, 15)),
200
contact, contact.nick, utils.safe_gtk_pixbuf_load(
201
gui.theme.image_theme.status_icons[contact.status], (15, 15)))
202
self._model.append(contact_data)
203
self._contact_list.set_model(self._model)
204
self._contact_list.show_all()
205
self._first_alig.set(0.5, 0.0, 1.0, 2.0)
206
self.first = self._contact_list
207
self.set_size_request(200, -1)