-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_user.py
710 lines (564 loc) · 24.9 KB
/
gui_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
#
# Proximate - Peer-to-peer social networking
#
# Copyright (c) 2008-2011 Nokia Corporation
#
# All rights reserved.
#
# This software is licensed under The Clear BSD license.
# See the LICENSE file for more details.
#
import gtk
import gobject
import proximatestate
from plugins import get_plugin_by_type
from support import get_debug_mode
from os.path import join
from pathname import get_dir, get_path, ICON_DIR, DEFAULT_COMMUNITY_ICON, \
DEFAULT_USER_ICON, SMALL_KEYS_ICON, PROXIMATE_COMMUNITY_ICON
from proximateprotocol import PLUGIN_TYPE_COMMUNITY, PLUGIN_TYPE_KEY_MANAGEMENT, \
PLUGIN_TYPE_STATE, MAX_FACE_DIMENSION, DEFAULT_COMMUNITY_NAME
from pic_choose_dlg import Picture_Choose_Dialog
from proximateprotocol import PLUGIN_TYPE_NOTIFICATION, valid_status
from guiutils import GUI_Page, Action_List, center_image, add_icon_to_image, \
new_scrollarea, pango_escape
from utils import str_to_int
ACTION_IMAGE_SIZE = 48
def get_status_icon(status, size):
if not valid_status(status):
status = 'normal'
fname = '%dpx-status_icon_%s.png' % (size, status)
return gtk.gdk.pixbuf_new_from_file_at_size(join(get_dir(ICON_DIR), fname), size, size)
# descriptive names for all profile fields
field_descriptions = {
'name': 'Name',
'age': 'Age',
'gender': 'Gender',
'city': 'City',
'state': 'State',
'country': 'Country',
'birth_date': 'Birth Date',
'email': 'E-mail',
'www': 'WWW',
'occupation': 'Occupation',
'phone_numbers': 'Phone Numbers',
'languages': 'Languages',
'description': 'Description',
'uid': 'uid',
'ip': 'IP',
'port': 'Port',
'hops': 'Hops',
'status_icon': 'Status icon',
'v': 'Version',
'faceversion': 'Face version',
'myfaceversion': 'My face version',
}
class User_Page(GUI_Page):
def __init__(self, gui, community_gui, user):
"""User_Page class is for showing user's profile information
defined in the Edit Profile dialog and for showing user's
communities.
update_user_page() have to be called after user's profile
is changed or after user's communities are changed so that
new values are loaded into GUI"""
GUI_Page.__init__(self, user.get('nick'))
self.main_gui = gui
self.community_gui = community_gui
self.user = user
self.community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY)
self.state_plugin = get_plugin_by_type(PLUGIN_TYPE_STATE)
self.notebook = gtk.Notebook()
self.notebook.set_show_tabs(True)
self.notebook.set_show_border(False)
self.initialize_profile_page()
self.initialize_user_action_page()
self.initialize_communities_page()
self.pack_start(self.notebook)
self.show_all()
def get_user(self):
return self.user
def back_action(self):
self.community_gui.user_pages.pop(self.user)
self.main_gui.remove_page(self)
self.destroy()
return True
def update_user_page(self):
""" Function calls other functions to update user's
profile, community, content and plugin pages. """
self.update_profile_widgets()
self.set_page_title(self.user.get('nick'))
def initialize_user_action_page(self):
vbox = gtk.VBox()
add_user_icon = gtk.gdk.pixbuf_new_from_file_at_size(join(get_dir(ICON_DIR), "64px-plus_icon.png"), ACTION_IMAGE_SIZE, ACTION_IMAGE_SIZE)
remove_user_icon = gtk.gdk.pixbuf_new_from_file_at_size(join(get_dir(ICON_DIR), "64px-no_icon.png"), ACTION_IMAGE_SIZE, ACTION_IMAGE_SIZE)
exchange_keys_icon = gtk.gdk.pixbuf_new_from_file_at_size(join(get_dir(ICON_DIR), "key.png"), ACTION_IMAGE_SIZE, ACTION_IMAGE_SIZE)
refetch_icon = gtk.gdk.pixbuf_new_from_file_at_size(join(get_dir(ICON_DIR), "64px-edit_metadata_icon.png"), ACTION_IMAGE_SIZE, ACTION_IMAGE_SIZE)
action_buttons = [(add_user_icon, 'Invite to\nCommunity', self.show_invite_dialog_cb),
(refetch_icon, 'Refetch\nProfile', self.refetch_profile_cb),
]
if self.state_plugin.options.personal_communities:
action_buttons.insert(0, (add_user_icon, 'Add to\n Community',
self.show_add_dialog_cb))
action_buttons.insert(1, (remove_user_icon, 'Remove from\nCommunity',
self.show_remove_dialog_cb))
if self.state_plugin.options.key_exchange:
action_buttons.insert(3, (exchange_keys_icon, 'Exchange\nKeys', self.show_exchange_keys_dialog_cb))
self.actions = Action_List()
for action in action_buttons:
(icon, text, cb) = action
self.actions.add_button(icon, text, cb)
vbox.pack_start(self.actions.get_widget())
self.announce_checkbox = gtk.CheckButton('Make an alarm when user appears')
vbox.pack_start(self.announce_checkbox, False, False)
self.announce_checkbox.set_active(self.user.get('friend'))
self.announce_checkbox.connect('toggled', self.set_announce)
self.notebook.append_page(vbox, gtk.Label('More actions'))
def initialize_profile_page(self):
profile_hbox = gtk.HBox()
vbox = gtk.VBox()
picture_hbox = gtk.HBox()
self.profile_image = gtk.Image()
self.profile_image.set_size_request(MAX_FACE_DIMENSION+10, MAX_FACE_DIMENSION+10)
picture_hbox.pack_start(self.profile_image, False, True)
self.status_label = gtk.Label()
self.status_label.set_line_wrap(True)
picture_hbox.pack_start(self.status_label)
vbox.pack_start(picture_hbox)
self.profile_info_label = gtk.Label()
self.profile_info_label.set_alignment(0.1, 0.01) # 0.01 on purpose
self.profile_info_label.set_line_wrap(True)
vbox.pack_start(self.profile_info_label)
profile_hbox.pack_start(vbox)
self.user_action_list = User_Action_List(self.community_gui,
self.get_user)
profile_hbox.pack_start(self.user_action_list.action_view)
swindow = new_scrollarea()
swindow.set_border_width(0)
swindow.add_with_viewport(profile_hbox)
self.update_profile_widgets()
self.notebook.append_page(swindow, gtk.Label('Profile'))
def initialize_communities_page(self):
vbox = gtk.VBox()
self.list = Community_List(self.view_community)
for com in self.community.get_user_communities(self.user):
self.list.add_community(com)
vbox.pack_start(self.list.get_widget())
self.notebook.append_page(vbox, gtk.Label('User communities'))
def view_community(self, com):
self.community_gui.show_com_page(com)
def update_profile_widgets(self):
""" Reads new profile information from user and
updates profile page's widgets."""
image = get_user_profile_picture(self.user)
if not self.user.present:
image.saturate_and_pixelate(image, 0.0, True)
self.profile_image.set_from_pixbuf(image)
value = self.user.get('status')
if value == None:
value = ''
self.status_label.set_text(value)
self.profile_info_label.set_markup(self.construct_profile_info_str())
def construct_profile_info_str(self):
def heading(s):
# Returns a heading string s formatted with pango markup and
# a new-line
return '<span color="slategray" weight="bold" size="large">%s</span>\n' % pango_escape(s)
def field(s):
value = self.user.get(s)
if value != None:
return '<b>%s:</b> %s\n' % (field_descriptions[s], pango_escape(str(value)))
else:
return ''
def join_list(l):
out = []
for s in l:
value = self.user.get(s)
if value != None:
out.append(pango_escape(str(value)))
if len(out) > 0:
return ', '.join(out) + '\n'
else:
return ''
s = heading(self.user.get('nick'))
s += field('name')
s += join_list(('age', 'gender'))
s += field('birth_date')
s += join_list(('city', 'state', 'country'))
s += field('phone_numbers')
s += field('email')
s += field('www')
s += field('occupation')
s += field('languages')
s += field('description')
s += heading('Last contact')
l = []
for (t, location) in self.user.log():
ss = t
if len(location) > 0:
ss += '\n(at %s)' %(location)
l.append(ss)
if len(l) == 0:
l = ['never']
s += pango_escape('\n'.join(l)) + '\n'
if get_debug_mode():
s += heading('Debug information')
s += field('uid')
s += field('ip')
s += field('port')
s += field('hops')
s += field('status_icon')
s += field('v')
s += field('faceversion')
s += field('myfaceversion')
return s
def show_add_dialog_cb(self, widget):
Add_To_Community_Dialog(self.main_gui, self.user)
def show_invite_dialog_cb(self, widget):
Invite_To_Community_Dialog(self.main_gui, self.user)
def show_remove_dialog_cb(self, widget):
Remove_From_Community_Dialog(self.main_gui, self.user)
def show_exchange_keys_dialog_cb(self, widget):
keymanagement = get_plugin_by_type(PLUGIN_TYPE_KEY_MANAGEMENT)
keymanagement.show_exchange_keys_gui(self.user)
def refetch_profile_cb(self, widget):
self.user.force_profile_update()
notification = get_plugin_by_type(PLUGIN_TYPE_NOTIFICATION)
notification.notify('Reloading profile for %s' %(self.user.tag()))
def set_announce(self, widget):
self.user.set('friend', widget.get_active())
class My_User_Page(GUI_Page):
def __init__(self, gui, user):
"""User_Page class is for showing user's profile information
defined in the Edit Profile dialog and for showing user's
communities.
update_user_page() have to be called after user's profile
is changed or after user's communities are changed so that
new values are loaded into GUI"""
GUI_Page.__init__(self, 'My profile')
# references to gui components which text or other
# attribute will be modified if user's profile changes
self.profile_widgets = {}
self.main_gui = gui
self.user = user
self.community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY)
self.initialize_profile_page_widgets()
self.pic_dialog = Picture_Choose_Dialog(self.main_gui, self.got_picture)
def update_user_page(self):
""" Function calls other functions to update user's
profile, community, content and plugin pages. """
self.update_profile_widgets()
def update_profile_widgets(self):
""" Reads new profile information from user and
updates profile page's widgets."""
image = get_user_profile_picture(self.user)
self.profile_image.set_from_pixbuf(image)
def initialize_profile_page_widgets(self):
self.profile_main_vbox = gtk.VBox()
swindow = new_scrollarea()
swindow.set_border_width(0)
main_hbox = gtk.HBox(False, 20)
picture_vbox = gtk.VBox()
self.profile_image = gtk.Image()
self.profile_image.set_size_request(MAX_FACE_DIMENSION+10, MAX_FACE_DIMENSION+10)
eventbox = gtk.EventBox()
eventbox.connect("button-press-event", self.image_clicked)
eventbox.add(self.profile_image)
picture_vbox.pack_start(gtk.Label('Click picture to change'))
picture_vbox.pack_start(eventbox, True, True)
# User always has a nick
widget = gtk.Entry()
widget.set_text(self.user.get('nick'))
widget.connect("focus-out-event", self.entry_focus_out, 'nick')
self.profile_widgets['nick'] = widget
nick_label = gtk.Label('Nick:')
nick_label.set_alignment(0, 0)
picture_vbox.pack_start(nick_label, False, False)
picture_vbox.pack_start(widget, False, False)
left_hbox = gtk.VBox(False, 20)
left_hbox.pack_start(picture_vbox, False, False)
user_info_vbox = gtk.VBox(False, 5)
profile_components = (('Name:', 'name'),
('Age:', 'age'),
('Gender:', 'gender'),
('City:', 'city'),
('State:', 'state'),
('Country:', 'country'),
('Birth Date:', 'birth_date'),
('E-mail:', 'email'),
('WWW:', 'www'),
('Occupation:', 'occupation'),
('Phone Numbers:', 'phone_numbers'),
('Languages:', 'languages'),
('Description:', 'description'),
)
genders = ('Male', 'Female')
for header, key in profile_components:
hbox = gtk.HBox()
label = gtk.Label(header)
label.set_size_request(130, -1)
label.set_alignment(0, 0)
value = self.user.get(key)
if value == None:
value = ''
if key == 'gender':
# create gender widget separately
widget = gtk.combo_box_entry_new_text()
for gender in genders:
widget.append_text(gender)
entry = widget.child
entry.set_text(str(value))
widget.connect("changed", self.combo_changed, key)
elif key == 'description':
widget = gtk.TextView()
widget.get_buffer().set_text(str(value))
widget.set_property("wrap-mode", gtk.WRAP_CHAR)
widget.set_size_request(-1, 100)
entry = widget
else:
widget = gtk.Entry()
widget.set_text(str(value))
entry = widget
entry.connect("focus-out-event", self.entry_focus_out, key)
hbox.pack_start(label, False, False)
hbox.pack_start(widget, True, True)
self.profile_widgets[key] = entry
user_info_vbox.pack_start(hbox, False, False)
main_hbox.pack_start(left_hbox, False, False)
main_hbox.pack_start(user_info_vbox, True, True)
swindow.add_with_viewport(main_hbox)
self.update_profile_widgets()
self.pack_start(swindow, True, True)
def image_clicked(self, widget, event):
self.pic_dialog.set_picture(proximatestate.seek_face_name(self.user))
self.pic_dialog.show()
def got_picture(self, fname):
self.community.set_my_face(fname)
def combo_changed(self, widget, key):
self.entry_focus_out(widget.child, None, key)
def entry_focus_out(self, entry, event, key):
if key == 'description':
buf = entry.get_buffer()
value = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
else:
value = entry.get_text()
if len(value) == 0:
value = None
if value != self.user.get(key):
if self.user.set(key, value):
self.community.announce_user_change(self.user, allowme=True)
else:
# re-insert old value if set fails
value = self.user.get(key)
if value == None:
value = ''
entry.set_text(str(value))
class Community_List:
COL_ICON = 0
COL_NAME = 1
COL_MEMBERS = 2
COL_DESC = 3
COL_COM = 4
def __init__(self, activate_cb=None):
self.community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY)
self.store = gtk.ListStore(gtk.gdk.Pixbuf, str, str, str, object)
self.scrollarea = new_scrollarea()
self.scrollarea.set_size_request(-1, 340)
self.view = gtk.TreeView()
self.view.set_headers_visible(True)
cr1 = gtk.CellRendererPixbuf()
cr2 = gtk.CellRendererText()
cr3 = gtk.CellRendererText()
cr4 = gtk.CellRendererText()
cr3.set_property('xalign', 0.1)
col = gtk.TreeViewColumn('Community')
col.pack_start(cr1, False)
col.pack_start(cr2)
col.add_attribute(cr1, 'pixbuf', self.COL_ICON)
col.add_attribute(cr2, 'text', self.COL_NAME)
col2 = gtk.TreeViewColumn('Members')
col2.pack_start(cr3)
col2.add_attribute(cr3, 'text', self.COL_MEMBERS)
self.column_desc = gtk.TreeViewColumn('Description')
self.column_desc.pack_start(cr4)
self.column_desc.add_attribute(cr4, 'text', self.COL_DESC)
self.view.append_column(col)
self.view.append_column(col2)
self.view.append_column(self.column_desc)
self.view.set_model(self.store)
self.view.connect('row-activated', self.row_activated_cb)
self.view.connect_after('size-allocate', self.resized)
self.activated = activate_cb
self.scrollarea.add_with_viewport(self.view)
def get_widget(self):
return self.scrollarea
def add_community(self, c):
n = len(self.community.get_community_members(c))
myself = self.community.get_myself()
if c in self.community.get_user_communities(myself):
n += 1
icon = get_community_icon(c).scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
desc = c.get('description')
if desc == None:
desc = ''
desc = desc.replace('\n', ' ')
if n == 0:
icon.saturate_and_pixelate(icon, 0.0, True)
self.store.append([icon, c.get('name'), str(n), desc, c])
else:
self.store.prepend([icon, c.get('name'), str(n), desc, c])
def get_selected(self):
model, selected = self.view.get_selection().get_selected_rows()
if len(selected) == 0:
return None
row = self.store[selected[0]]
return row[self.COL_COM]
def row_activated_cb(self, treeview, path, col):
store = treeview.get_model()
row = store[path]
com = row[self.COL_COM]
if self.activated != None:
self.activated(com)
def resized(self, view, rect):
columns_width = 0
for col in view.get_columns():
if col != self.column_desc:
columns_width += col.get_width()
if rect.width < columns_width:
return
wrap_width = rect.width - columns_width
self.column_desc.get_cell_renderers()[0].set_property('wrap-width', wrap_width)
self.column_desc.set_property('max-width', wrap_width)
store = view.get_model()
i = store.get_iter_first()
while i and store.iter_is_valid(i):
store.row_changed(store.get_path(i), i)
i = store.iter_next(i)
view.set_size_request(0, -1)
class Community_List_Dialog:
def __init__(self, gui, title, actiontext=gtk.STOCK_OK):
self.community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY)
self.notification = get_plugin_by_type(PLUGIN_TYPE_NOTIFICATION)
self.main_window = gui.get_main_window()
self.dialog = gtk.Dialog(title, self.main_window, gtk.DIALOG_DESTROY_WITH_PARENT,
(actiontext, gtk.RESPONSE_OK,
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
self.dialog.set_modal(True)
self.list = Community_List()
self.dialog.vbox.pack_start(self.list.get_widget(), True, True)
self.dialog.connect("response", self.response_handler)
self.dialog.set_default_size(400, 300)
self.dialog.show_all()
def add_community(self, com):
self.list.add_community(com)
def response_handler(self, widget, event):
if event == gtk.RESPONSE_OK:
com = self.list.get_selected()
if com != None:
self.community_selected(com)
self.dialog.destroy()
class Add_To_Community_Dialog(Community_List_Dialog):
def __init__(self, gui, user):
Community_List_Dialog.__init__(self, gui, 'Add User To Community', actiontext='Add')
self.user = user
communities = self.community.find_communities(None, False, None)
usercoms = self.community.get_user_personal_communities(self.user)
for com in communities:
if not self.community.personal_communities and com.get('peer') == False:
continue
if not com in usercoms:
self.add_community(com)
def community_selected(self, com):
self.community.add_member(com, self.user)
class Invite_To_Community_Dialog(Community_List_Dialog):
def __init__(self, gui, user):
Community_List_Dialog.__init__(self, gui, 'Invite User To Community', actiontext='Invite')
self.user = user
myself = self.community.get_myself()
communities = self.community.get_user_communities(myself)
usercoms = self.community.get_user_communities(self.user)
for com in communities:
if not com in usercoms:
self.add_community(com)
def community_selected(self, com):
if not self.community.invite_member(com, self.user, self.invite_sent):
self.notification.notify('Unable to send an invitation to %s' % self.user.tag(), True)
def invite_sent(self, success):
if not success:
self.notification.notify('Unable to send an invitation to %s' % self.user.tag(), True)
class Remove_From_Community_Dialog(Community_List_Dialog):
def __init__(self, gui, user):
Community_List_Dialog.__init__(self, gui, 'Remove User From Community', actiontext='Remove')
self.user = user
communities = self.community.get_user_personal_communities(self.user)
for com in communities:
self.add_community(com)
def community_selected(self, com):
self.community.remove_member(com, self.user)
class User_Action_List(Action_List):
def __init__(self, gui, get_selected_func):
Action_List.__init__(self)
self.get_selected = get_selected_func
self.community_gui = gui
for event in self.community_gui.user_events:
self.add_event(event)
self.community_gui.register_user_action_list(self)
def add_event(self, event):
(icon, name, callback) = event
self.add_button(icon, name, self.action, callback)
def action(self, callback):
callback(self.get_selected())
def get_default_community_icon(com):
if com == proximatestate.get_ordinary_community(DEFAULT_COMMUNITY_NAME):
fname = get_path(PROXIMATE_COMMUNITY_ICON)
else:
fname = get_path(DEFAULT_COMMUNITY_ICON)
return gtk.gdk.pixbuf_new_from_file(fname)
def get_community_icon(com):
fname = proximatestate.seek_community_icon_name(com)
try:
com_icon = gtk.gdk.pixbuf_new_from_file(fname)
except gobject.GError:
# if we have broken community information (picture missing)
# we must use default icon
com_icon = get_default_community_icon(com)
return com_icon
def create_default_user_picture(user):
# list of suitable colors to pick from
colors = (0x000000FF, 0x8A8A8AFF, 0x9B00AFFF, 0x5DAF00FF,
0x79AF00FF, 0xA8AF00FF, 0xAF9B00FF, 0xAF6000FF,
0xAF0016FF, 0xAF0092FF, 0xBC0086FF, 0x000FBCFF,
0x007403FF, 0x007466FF, 0xD5FFBAFF, 0xFFFFFFFF)
# use default icon and color it using the first char as an index
buf = gtk.gdk.pixbuf_new_from_file(get_path(DEFAULT_USER_ICON))
icon = buf.copy()
color = colors[int(user.get('uid')[0], 16)]
icon.fill(color)
buf.composite(icon, 0, 0, buf.get_width(), buf.get_height(),
0, 0, 1.0, 1.0, gtk.gdk.INTERP_NEAREST, 255)
return icon
def get_user_profile_picture(user, status_icons=True, center=True):
""" Returns picture saved in user's profile as a GDK Pixbuf,
or the default picture with a background color
generated from uid.
Status icons are added to the picture, if status_icons == True.
"""
try:
icon = gtk.gdk.pixbuf_new_from_file(proximatestate.seek_face_name(user))
except gobject.GError:
icon = create_default_user_picture(user)
if center:
# center image if it's smaller than MAX_FACE_DIMENSION
smaller_dimension = min(icon.get_width(), icon.get_height())
if smaller_dimension < MAX_FACE_DIMENSION:
icon = center_image(icon, MAX_FACE_DIMENSION, MAX_FACE_DIMENSION)
if status_icons:
# add small status icons
community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY)
if not user == community.get_myself():
if user.get('key_fname'):
status_icon = gtk.gdk.pixbuf_new_from_file(get_path(SMALL_KEYS_ICON))
add_icon_to_image(icon, status_icon, 4)
user_status = user.get('status_icon')
if user_status:
add_icon_to_image(icon, get_status_icon(user_status, 32), 0)
return icon