2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/vcard.py
|
2005-04-19 23:53:19 +02:00
|
|
|
##
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005 Vincent Hanquez <tab AT snarc.org>
|
|
|
|
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
|
2008-08-15 19:31:51 +02:00
|
|
|
## Copyright (C) 2006 Junglecow J <junglecow AT gmail.com>
|
|
|
|
## Dimitur Kirov <dkirov AT gmail.com>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Travis Shirk <travis AT pobox.com>
|
|
|
|
## Stefan Bethge <stefan AT lanpartei.de>
|
|
|
|
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
## Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net>
|
|
|
|
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Jonathan Schleifer <js-gajim AT webkeks.org>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
2005-04-19 23:53:19 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-04-19 23:53:19 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-04-19 23:53:19 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-04-19 23:53:19 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-04-19 23:53:19 +02:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-04-19 23:53:19 +02:00
|
|
|
|
2006-10-02 18:24:10 +02:00
|
|
|
# THIS FILE IS FOR **OTHERS'** PROFILE (when we VIEW their INFO)
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
2013-07-29 18:02:48 +02:00
|
|
|
from gi.repository import GLib
|
2012-12-31 16:38:32 +01:00
|
|
|
from gi.repository import Gdk
|
2017-09-16 11:49:31 +02:00
|
|
|
from gi.repository import GdkPixbuf
|
2005-06-06 22:16:51 +02:00
|
|
|
import base64
|
2017-10-17 20:36:27 +02:00
|
|
|
import binascii
|
2007-04-22 12:23:23 +02:00
|
|
|
import os
|
2006-03-24 19:48:26 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import gtkgui_helpers
|
2005-08-03 12:59:44 +02:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import helpers
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import ged
|
|
|
|
from gajim.common.i18n import Q_
|
2017-09-16 11:49:31 +02:00
|
|
|
from gajim.common.const import AvatarSize
|
2005-04-19 23:53:19 +02:00
|
|
|
|
2016-10-01 14:51:22 +02:00
|
|
|
# log = logging.getLogger('gajim.vcard')
|
|
|
|
|
2005-06-11 00:45:50 +02:00
|
|
|
class VcardWindow:
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Class for contact's information window
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, contact, account, gc_contact = None):
|
|
|
|
# the contact variable is the jid if vcard is true
|
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('vcard_information_window.ui')
|
|
|
|
self.window = self.xml.get_object('vcard_information_window')
|
|
|
|
self.progressbar = self.xml.get_object('progressbar')
|
|
|
|
|
|
|
|
self.contact = contact
|
|
|
|
self.account = account
|
|
|
|
self.gc_contact = gc_contact
|
2017-09-16 11:49:31 +02:00
|
|
|
self.avatar = None
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# Get real jid
|
|
|
|
if gc_contact:
|
|
|
|
# Don't use real jid if room is (semi-)anonymous
|
2017-08-13 13:18:56 +02:00
|
|
|
gc_control = app.interface.msg_win_mgr.get_gc_control(
|
2010-02-08 15:08:40 +01:00
|
|
|
gc_contact.room_jid, account)
|
|
|
|
if gc_contact.jid and not gc_control.is_anonymous:
|
|
|
|
self.real_jid = gc_contact.jid
|
|
|
|
self.real_jid_for_vcard = gc_contact.jid
|
|
|
|
if gc_contact.resource:
|
|
|
|
self.real_jid += '/' + gc_contact.resource
|
|
|
|
else:
|
|
|
|
self.real_jid = gc_contact.get_full_jid()
|
|
|
|
self.real_jid_for_vcard = self.real_jid
|
|
|
|
self.real_resource = gc_contact.name
|
|
|
|
else:
|
|
|
|
self.real_jid = contact.get_full_jid()
|
|
|
|
self.real_resource = contact.resource
|
|
|
|
|
|
|
|
puny_jid = helpers.sanitize_filename(contact.jid)
|
2017-08-13 13:18:56 +02:00
|
|
|
local_avatar_basepath = os.path.join(app.AVATAR_PATH, puny_jid) + \
|
2010-02-08 15:08:40 +01:00
|
|
|
'_local'
|
|
|
|
for extension in ('.png', '.jpeg'):
|
|
|
|
local_avatar_path = local_avatar_basepath + extension
|
|
|
|
if os.path.isfile(local_avatar_path):
|
|
|
|
image = self.xml.get_object('custom_avatar_image')
|
|
|
|
image.set_from_file(local_avatar_path)
|
|
|
|
image.show()
|
|
|
|
self.xml.get_object('custom_avatar_label').show()
|
|
|
|
break
|
|
|
|
self.vcard_arrived = False
|
|
|
|
self.os_info_arrived = False
|
|
|
|
self.entity_time_arrived = False
|
2016-09-30 19:38:00 +02:00
|
|
|
self.time = 0
|
|
|
|
self.update_intervall = 100 # Milliseconds
|
|
|
|
self.update_progressbar_timeout_id = GLib.timeout_add(self.update_intervall,
|
2013-07-29 18:02:48 +02:00
|
|
|
self.update_progressbar)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('version-result-received', ged.GUI1,
|
2010-07-20 16:53:07 +02:00
|
|
|
self.set_os_info)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('time-result-received', ged.GUI1,
|
2010-07-20 16:53:07 +02:00
|
|
|
self.set_entity_time)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.fill_jabber_page()
|
2017-08-13 13:18:56 +02:00
|
|
|
annotations = app.connections[self.account].annotations
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.contact.jid in annotations:
|
|
|
|
buffer_ = self.xml.get_object('textview_annotation').get_buffer()
|
|
|
|
buffer_.set_text(annotations[self.contact.jid])
|
|
|
|
|
2016-10-01 14:51:22 +02:00
|
|
|
for widget_name in ('URL_label',
|
|
|
|
'EMAIL_WORK_USERID_label',
|
|
|
|
'EMAIL_HOME_USERID_label'):
|
|
|
|
widget = self.xml.get_object(widget_name)
|
|
|
|
widget.hide()
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.xml.connect_signals(self)
|
|
|
|
self.xml.get_object('close_button').grab_focus()
|
2012-06-25 21:27:23 +02:00
|
|
|
self.window.show_all()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def update_progressbar(self):
|
|
|
|
self.progressbar.pulse()
|
2016-09-30 19:38:00 +02:00
|
|
|
self.time += self.update_intervall
|
|
|
|
# Timeout in Milliseconds
|
|
|
|
if (self.vcard_arrived and self.os_info_arrived and
|
|
|
|
self.entity_time_arrived) or self.time == 10000:
|
|
|
|
self.progressbar.hide()
|
|
|
|
self.update_progressbar_timeout_id = None
|
|
|
|
return False
|
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_vcard_information_window_destroy(self, widget):
|
|
|
|
if self.update_progressbar_timeout_id is not None:
|
2013-07-29 18:02:48 +02:00
|
|
|
GLib.source_remove(self.update_progressbar_timeout_id)
|
2017-08-13 13:18:56 +02:00
|
|
|
del app.interface.instances[self.account]['infos'][self.contact.jid]
|
2010-02-08 15:08:40 +01:00
|
|
|
buffer_ = self.xml.get_object('textview_annotation').get_buffer()
|
|
|
|
annotation = buffer_.get_text(buffer_.get_start_iter(),
|
2012-12-23 16:23:43 +01:00
|
|
|
buffer_.get_end_iter(), True)
|
2017-08-13 13:18:56 +02:00
|
|
|
connection = app.connections[self.account]
|
2010-02-08 15:08:40 +01:00
|
|
|
if annotation != connection.annotations.get(self.contact.jid, ''):
|
|
|
|
connection.annotations[self.contact.jid] = annotation
|
|
|
|
connection.store_annotations()
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.remove_event_handler('version-result-received', ged.GUI1,
|
2010-07-20 16:53:07 +02:00
|
|
|
self.set_os_info)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.remove_event_handler('time-result-received', ged.GUI1,
|
2010-07-20 16:53:07 +02:00
|
|
|
self.set_entity_time)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_vcard_information_window_key_press_event(self, widget, event):
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.keyval == Gdk.KEY_Escape:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.window.destroy()
|
|
|
|
|
2012-06-28 10:38:43 +02:00
|
|
|
def on_information_notebook_switch_page(self, widget, page, page_num):
|
2013-07-29 18:02:48 +02:00
|
|
|
GLib.idle_add(self.xml.get_object('close_button').grab_focus)
|
2012-06-28 10:38:43 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_PHOTO_eventbox_button_press_event(self, widget, event):
|
|
|
|
"""
|
|
|
|
If right-clicked, show popup
|
|
|
|
"""
|
|
|
|
if event.button == 3: # right click
|
2012-12-23 16:23:43 +01:00
|
|
|
menu = Gtk.Menu()
|
2014-11-11 23:11:15 +01:00
|
|
|
menuitem = Gtk.MenuItem.new_with_mnemonic(_('Save _As'))
|
2017-09-16 11:49:31 +02:00
|
|
|
if self.gc_contact:
|
|
|
|
sha = self.gc_contact.avatar_sha
|
|
|
|
name = self.gc_contact.get_shown_name()
|
|
|
|
else:
|
|
|
|
sha = app.contacts.get_avatar_sha(
|
|
|
|
self.account, self.contact.jid)
|
|
|
|
name = self.contact.get_shown_name()
|
|
|
|
if sha is None:
|
|
|
|
sha = self.avatar
|
2010-02-08 15:08:40 +01:00
|
|
|
menuitem.connect('activate',
|
2017-09-16 11:49:31 +02:00
|
|
|
gtkgui_helpers.on_avatar_save_as_menuitem_activate, sha, name)
|
2010-02-08 15:08:40 +01:00
|
|
|
menu.append(menuitem)
|
|
|
|
menu.connect('selection-done', lambda w:w.destroy())
|
|
|
|
# show the menu
|
|
|
|
menu.show_all()
|
2013-01-07 23:22:40 +01:00
|
|
|
menu.attach_to_widget(widget, None)
|
2012-12-27 21:58:52 +01:00
|
|
|
menu.popup(None, None, None, None, event.button, event.time)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def set_value(self, entry_name, value):
|
|
|
|
try:
|
2016-10-01 14:51:22 +02:00
|
|
|
widget = self.xml.get_object(entry_name)
|
|
|
|
if entry_name in ('URL_label',
|
|
|
|
'EMAIL_WORK_USERID_label',
|
|
|
|
'EMAIL_HOME_USERID_label'):
|
|
|
|
widget.set_uri('mailto:' + value)
|
|
|
|
widget.set_label(value)
|
|
|
|
self.xml.get_object(entry_name).show()
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2012-04-18 11:34:57 +02:00
|
|
|
val = widget.get_text()
|
|
|
|
if val:
|
|
|
|
value = val + ' / ' + value
|
|
|
|
widget.set_text(value)
|
2010-02-08 15:08:40 +01:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
|
2017-11-25 14:32:00 +01:00
|
|
|
def _set_values(self, vcard, jid):
|
2010-02-08 15:08:40 +01:00
|
|
|
for i in vcard.keys():
|
|
|
|
if i == 'PHOTO' and self.xml.get_object('information_notebook').\
|
|
|
|
get_n_pages() > 4:
|
2017-09-16 11:49:31 +02:00
|
|
|
if 'BINVAL' not in vcard[i]:
|
|
|
|
continue
|
|
|
|
photo_encoded = vcard[i]['BINVAL']
|
|
|
|
if photo_encoded == '':
|
|
|
|
continue
|
2017-10-17 20:36:27 +02:00
|
|
|
try:
|
|
|
|
photo_decoded = base64.b64decode(
|
|
|
|
photo_encoded.encode('utf-8'))
|
|
|
|
except binascii.Error as error:
|
2017-11-25 14:32:00 +01:00
|
|
|
app.log('avatar').warning('Invalid avatar for %s: %s', jid, error)
|
2017-10-17 20:36:27 +02:00
|
|
|
continue
|
2017-09-16 11:49:31 +02:00
|
|
|
pixbuf = gtkgui_helpers.get_pixbuf_from_data(photo_decoded)
|
|
|
|
if pixbuf is None:
|
|
|
|
continue
|
|
|
|
pixbuf = pixbuf.scale_simple(
|
|
|
|
AvatarSize.PROFILE, AvatarSize.PROFILE,
|
|
|
|
GdkPixbuf.InterpType.BILINEAR)
|
2010-02-08 15:08:40 +01:00
|
|
|
image = self.xml.get_object('PHOTO_image')
|
2017-09-16 11:49:31 +02:00
|
|
|
image.set_from_pixbuf(pixbuf)
|
2010-02-08 15:08:40 +01:00
|
|
|
image.show()
|
2017-09-16 11:49:31 +02:00
|
|
|
self.avatar = pixbuf
|
2010-02-08 15:08:40 +01:00
|
|
|
self.xml.get_object('user_avatar_label').show()
|
|
|
|
continue
|
|
|
|
if i in ('ADR', 'TEL', 'EMAIL'):
|
|
|
|
for entry in vcard[i]:
|
|
|
|
add_on = '_HOME'
|
|
|
|
if 'WORK' in entry:
|
|
|
|
add_on = '_WORK'
|
|
|
|
for j in entry.keys():
|
|
|
|
self.set_value(i + add_on + '_' + j + '_label', entry[j])
|
|
|
|
if isinstance(vcard[i], dict):
|
|
|
|
for j in vcard[i].keys():
|
|
|
|
self.set_value(i + '_' + j + '_label', vcard[i][j])
|
|
|
|
else:
|
|
|
|
if i == 'DESC':
|
|
|
|
self.xml.get_object('DESC_textview').get_buffer().set_text(
|
2016-06-16 21:49:09 +02:00
|
|
|
vcard[i], len(vcard[i].encode('utf-8')))
|
2010-02-08 15:08:40 +01:00
|
|
|
elif i != 'jid': # Do not override jid_label
|
|
|
|
self.set_value(i + '_label', vcard[i])
|
|
|
|
self.vcard_arrived = True
|
|
|
|
|
2013-07-18 21:14:39 +02:00
|
|
|
def clear_values(self):
|
|
|
|
for l in ('FN', 'NICKNAME', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE',
|
|
|
|
'N_PREFIX', 'N_SUFFIX', 'EMAIL_HOME_USERID', 'TEL_HOME_NUMBER', 'BDAY',
|
|
|
|
'ORG_ORGNAME', 'ORG_ORGUNIT', 'TITLE', 'ROLE', 'EMAIL_WORK_USERID',
|
2016-10-01 14:51:22 +02:00
|
|
|
'TEL_WORK_NUMBER', 'URL'):
|
2013-07-18 21:14:39 +02:00
|
|
|
widget = self.xml.get_object(l + '_label')
|
2016-10-01 14:51:22 +02:00
|
|
|
if l in ('EMAIL_HOME_USERID', 'EMAIL_WORK_USERID', 'URL'):
|
|
|
|
widget.hide()
|
|
|
|
else:
|
|
|
|
widget.set_text('')
|
2013-07-18 21:14:39 +02:00
|
|
|
for pref in ('ADR_HOME', 'ADR_WORK'):
|
|
|
|
for l in ('STREET', 'EXTADR', 'LOCALITY', 'PCODE', 'REGION',
|
|
|
|
'CTRY'):
|
|
|
|
widget = self.xml.get_object(pref + '_' + l + '_label')
|
|
|
|
widget.set_text('')
|
|
|
|
self.xml.get_object('DESC_textview').get_buffer().set_text('')
|
|
|
|
|
2017-09-16 11:49:31 +02:00
|
|
|
def _nec_vcard_received(self, jid, resource, room, vcard):
|
2013-07-18 21:14:39 +02:00
|
|
|
self.clear_values()
|
2017-11-25 14:32:00 +01:00
|
|
|
self._set_values(vcard, jid)
|
2010-11-26 21:14:59 +01:00
|
|
|
|
2010-07-20 16:53:07 +02:00
|
|
|
def set_os_info(self, obj):
|
2012-03-11 19:38:44 +01:00
|
|
|
if obj.conn.name != self.account:
|
|
|
|
return
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.xml.get_object('information_notebook').get_n_pages() < 5:
|
|
|
|
return
|
2016-10-01 17:35:10 +02:00
|
|
|
if self.gc_contact:
|
|
|
|
if obj.fjid != self.contact.jid:
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
elif app.get_jid_without_resource(obj.fjid) != self.contact.jid:
|
2010-12-09 11:16:52 +01:00
|
|
|
return
|
2010-02-08 15:08:40 +01:00
|
|
|
i = 0
|
|
|
|
client = ''
|
|
|
|
os = ''
|
|
|
|
while i in self.os_info:
|
2016-10-01 17:35:10 +02:00
|
|
|
if self.os_info[i]['resource'] == obj.resource:
|
|
|
|
if obj.client_info:
|
|
|
|
self.os_info[i]['client'] = obj.client_info
|
|
|
|
else:
|
|
|
|
self.os_info[i]['client'] = Q_('?Client:Unknown')
|
|
|
|
if obj.os_info:
|
|
|
|
self.os_info[i]['os'] = obj.os_info
|
|
|
|
else:
|
|
|
|
self.os_info[i]['os'] = Q_('?OS:Unknown')
|
|
|
|
else:
|
|
|
|
if not self.os_info[i]['client']:
|
|
|
|
self.os_info[i]['client'] = Q_('?Client:Unknown')
|
|
|
|
if not self.os_info[i]['os']:
|
|
|
|
self.os_info[i]['os'] = Q_('?OS:Unknown')
|
2010-02-08 15:08:40 +01:00
|
|
|
if i > 0:
|
|
|
|
client += '\n'
|
|
|
|
os += '\n'
|
|
|
|
client += self.os_info[i]['client']
|
|
|
|
os += self.os_info[i]['os']
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
self.xml.get_object('client_name_version_label').set_text(client)
|
|
|
|
self.xml.get_object('os_label').set_text(os)
|
|
|
|
self.os_info_arrived = True
|
|
|
|
|
2010-07-20 16:53:07 +02:00
|
|
|
def set_entity_time(self, obj):
|
2012-03-11 19:38:44 +01:00
|
|
|
if obj.conn.name != self.account:
|
|
|
|
return
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.xml.get_object('information_notebook').get_n_pages() < 5:
|
|
|
|
return
|
2016-10-01 17:35:10 +02:00
|
|
|
if self.gc_contact:
|
|
|
|
if obj.fjid != self.contact.jid:
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
elif app.get_jid_without_resource(obj.fjid) != self.contact.jid:
|
2010-12-09 11:16:52 +01:00
|
|
|
return
|
2010-02-08 15:08:40 +01:00
|
|
|
i = 0
|
|
|
|
time_s = ''
|
|
|
|
while i in self.time_info:
|
2016-10-01 17:35:10 +02:00
|
|
|
if self.time_info[i]['resource'] == obj.resource:
|
|
|
|
if obj.time_info:
|
|
|
|
self.time_info[i]['time'] = obj.time_info
|
|
|
|
else:
|
|
|
|
self.time_info[i]['time'] = Q_('?Time:Unknown')
|
|
|
|
else:
|
|
|
|
if not self.time_info[i]['time']:
|
|
|
|
self.time_info[i]['time'] = Q_('?Time:Unknown')
|
2010-02-08 15:08:40 +01:00
|
|
|
if i > 0:
|
|
|
|
time_s += '\n'
|
|
|
|
time_s += self.time_info[i]['time']
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
self.xml.get_object('time_label').set_text(time_s)
|
|
|
|
self.entity_time_arrived = True
|
|
|
|
|
|
|
|
def fill_status_label(self):
|
|
|
|
if self.xml.get_object('information_notebook').get_n_pages() < 5:
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
contact_list = app.contacts.get_contacts(self.account, self.contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
connected_contact_list = []
|
|
|
|
for c in contact_list:
|
|
|
|
if c.show not in ('offline', 'error'):
|
|
|
|
connected_contact_list.append(c)
|
|
|
|
if not connected_contact_list:
|
|
|
|
# no connected contact, get the offline one
|
|
|
|
connected_contact_list = contact_list
|
|
|
|
# stats holds show and status message
|
|
|
|
stats = ''
|
|
|
|
if connected_contact_list:
|
|
|
|
# Start with self.contact, as with resources
|
|
|
|
stats = helpers.get_uf_show(self.contact.show)
|
|
|
|
if self.contact.status:
|
|
|
|
stats += ': ' + self.contact.status
|
|
|
|
for c in connected_contact_list:
|
|
|
|
if c.resource != self.contact.resource:
|
|
|
|
stats += '\n'
|
|
|
|
stats += helpers.get_uf_show(c.show)
|
|
|
|
if c.status:
|
|
|
|
stats += ': ' + c.status
|
|
|
|
else: # Maybe gc_vcard ?
|
|
|
|
stats = helpers.get_uf_show(self.contact.show)
|
|
|
|
if self.contact.status:
|
|
|
|
stats += ': ' + self.contact.status
|
|
|
|
status_label = self.xml.get_object('status_label')
|
|
|
|
status_label.set_text(stats)
|
2017-06-12 22:04:22 +02:00
|
|
|
status_label.set_tooltip_text(stats)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def fill_jabber_page(self):
|
|
|
|
self.xml.get_object('nickname_label').set_markup(
|
|
|
|
'<b><span size="x-large">' +
|
|
|
|
self.contact.get_shown_name() +
|
|
|
|
'</span></b>')
|
|
|
|
self.xml.get_object('jid_label').set_text(self.contact.jid)
|
|
|
|
|
|
|
|
subscription_label = self.xml.get_object('subscription_label')
|
|
|
|
ask_label = self.xml.get_object('ask_label')
|
|
|
|
if self.gc_contact:
|
2010-04-03 13:38:12 +02:00
|
|
|
self.xml.get_object('subscription_title_label').set_markup(Q_("?Role in Group Chat:<b>Role:</b>"))
|
2010-02-08 15:08:40 +01:00
|
|
|
uf_role = helpers.get_uf_role(self.gc_contact.role)
|
|
|
|
subscription_label.set_text(uf_role)
|
|
|
|
|
|
|
|
self.xml.get_object('ask_title_label').set_markup(_("<b>Affiliation:</b>"))
|
|
|
|
uf_affiliation = helpers.get_uf_affiliation(self.gc_contact.affiliation)
|
|
|
|
ask_label.set_text(uf_affiliation)
|
|
|
|
else:
|
|
|
|
uf_sub = helpers.get_uf_sub(self.contact.sub)
|
|
|
|
subscription_label.set_text(uf_sub)
|
|
|
|
if self.contact.sub == 'from':
|
2017-02-04 23:29:45 +01:00
|
|
|
tt_text = _("This contact is interested in your presence information, but you are not interested in their presence")
|
2010-02-08 15:08:40 +01:00
|
|
|
elif self.contact.sub == 'to':
|
2017-02-04 23:29:45 +01:00
|
|
|
tt_text = _("You are interested in the contact's presence information, but it is not mutual")
|
2010-02-08 15:08:40 +01:00
|
|
|
elif self.contact.sub == 'both':
|
2017-02-04 23:29:45 +01:00
|
|
|
tt_text = _("The contact and you want to exchange presence information")
|
2010-02-08 15:08:40 +01:00
|
|
|
else: # None
|
2017-02-04 23:29:45 +01:00
|
|
|
tt_text = _("You and the contact have a mutual disinterest in each-others presence information")
|
2017-06-12 22:04:22 +02:00
|
|
|
subscription_label.set_tooltip_text(tt_text)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
uf_ask = helpers.get_uf_ask(self.contact.ask)
|
|
|
|
ask_label.set_text(uf_ask)
|
|
|
|
if self.contact.ask == 'subscribe':
|
|
|
|
tt_text = _("You are waiting contact's answer about your subscription request")
|
|
|
|
else:
|
|
|
|
tt_text = _("There is no pending subscription request.")
|
2017-06-12 22:04:22 +02:00
|
|
|
ask_label.set_tooltip_text(tt_text)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2013-01-01 21:06:16 +01:00
|
|
|
resources = '%s (%s)' % (self.contact.resource, str(
|
|
|
|
self.contact.priority))
|
2010-02-08 15:08:40 +01:00
|
|
|
uf_resources = self.contact.resource + _(' resource with priority ')\
|
2013-01-01 21:06:16 +01:00
|
|
|
+ str(self.contact.priority)
|
2010-02-08 15:08:40 +01:00
|
|
|
if not self.contact.status:
|
|
|
|
self.contact.status = ''
|
|
|
|
|
|
|
|
# do not wait for os_info if contact is not connected or has error
|
|
|
|
# additional check for observer is needed, as show is offline for him
|
|
|
|
if self.contact.show in ('offline', 'error')\
|
|
|
|
and not self.contact.is_observer():
|
|
|
|
self.os_info_arrived = True
|
|
|
|
else: # Request os info if contact is connected
|
|
|
|
if self.gc_contact:
|
2017-08-13 13:18:56 +02:00
|
|
|
j, r = app.get_room_and_nick_from_fjid(self.real_jid)
|
|
|
|
GLib.idle_add(app.connections[self.account].request_os_info,
|
2013-07-29 18:02:48 +02:00
|
|
|
j, r, self.contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
GLib.idle_add(app.connections[self.account].request_os_info,
|
2013-07-29 18:02:48 +02:00
|
|
|
self.contact.jid, self.contact.resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# do not wait for entity_time if contact is not connected or has error
|
|
|
|
# additional check for observer is needed, as show is offline for him
|
|
|
|
if self.contact.show in ('offline', 'error')\
|
|
|
|
and not self.contact.is_observer():
|
|
|
|
self.entity_time_arrived = True
|
|
|
|
else: # Request entity time if contact is connected
|
|
|
|
if self.gc_contact:
|
2017-08-13 13:18:56 +02:00
|
|
|
j, r = app.get_room_and_nick_from_fjid(self.real_jid)
|
|
|
|
GLib.idle_add(app.connections[self.account].\
|
2013-07-29 18:02:48 +02:00
|
|
|
request_entity_time, j, r, self.contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
GLib.idle_add(app.connections[self.account].\
|
2013-07-29 18:02:48 +02:00
|
|
|
request_entity_time, self.contact.jid, self.contact.resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.os_info = {0: {'resource': self.real_resource, 'client': '',
|
|
|
|
'os': ''}}
|
|
|
|
self.time_info = {0: {'resource': self.real_resource, 'time': ''}}
|
|
|
|
i = 1
|
2017-08-13 13:18:56 +02:00
|
|
|
contact_list = app.contacts.get_contacts(self.account, self.contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
if contact_list:
|
|
|
|
for c in contact_list:
|
|
|
|
if c.resource != self.contact.resource:
|
|
|
|
resources += '\n%s (%s)' % (c.resource,
|
2013-01-01 21:06:16 +01:00
|
|
|
str(c.priority))
|
2010-02-08 15:08:40 +01:00
|
|
|
uf_resources += '\n' + c.resource + \
|
2013-01-01 21:06:16 +01:00
|
|
|
_(' resource with priority ') + str(c.priority)
|
2010-02-08 15:08:40 +01:00
|
|
|
if c.show not in ('offline', 'error'):
|
2017-08-13 13:18:56 +02:00
|
|
|
GLib.idle_add(app.connections[self.account].\
|
2013-07-29 18:02:48 +02:00
|
|
|
request_os_info, c.jid, c.resource)
|
2017-08-13 13:18:56 +02:00
|
|
|
GLib.idle_add(app.connections[self.account].\
|
2013-07-29 18:02:48 +02:00
|
|
|
request_entity_time, c.jid, c.resource)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.os_info[i] = {'resource': c.resource, 'client': '',
|
|
|
|
'os': ''}
|
|
|
|
self.time_info[i] = {'resource': c.resource, 'time': ''}
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
self.xml.get_object('resource_prio_label').set_text(resources)
|
|
|
|
resource_prio_label_eventbox = self.xml.get_object(
|
|
|
|
'resource_prio_label_eventbox')
|
|
|
|
resource_prio_label_eventbox.set_tooltip_text(uf_resources)
|
|
|
|
|
|
|
|
self.fill_status_label()
|
|
|
|
|
2017-09-16 11:49:31 +02:00
|
|
|
con = app.connections[self.account]
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.gc_contact:
|
2017-09-16 11:49:31 +02:00
|
|
|
con.request_vcard(self._nec_vcard_received,
|
|
|
|
self.gc_contact.get_full_jid(), room=True)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-09-16 11:49:31 +02:00
|
|
|
con.request_vcard(self._nec_vcard_received, self.contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_close_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|
2006-09-29 16:39:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ZeroconfVcardWindow:
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, contact, account, is_fake = False):
|
|
|
|
# the contact variable is the jid if vcard is true
|
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('zeroconf_information_window.ui')
|
|
|
|
self.window = self.xml.get_object('zeroconf_information_window')
|
|
|
|
|
|
|
|
self.contact = contact
|
|
|
|
self.account = account
|
|
|
|
self.is_fake = is_fake
|
|
|
|
|
|
|
|
self.fill_contact_page()
|
|
|
|
self.fill_personal_page()
|
|
|
|
|
|
|
|
self.xml.connect_signals(self)
|
|
|
|
self.window.show_all()
|
|
|
|
|
|
|
|
def on_zeroconf_information_window_destroy(self, widget):
|
2017-08-13 13:18:56 +02:00
|
|
|
del app.interface.instances[self.account]['infos'][self.contact.jid]
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_zeroconf_information_window_key_press_event(self, widget, event):
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.keyval == Gdk.KEY_Escape:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def on_PHOTO_eventbox_button_press_event(self, widget, event):
|
|
|
|
"""
|
|
|
|
If right-clicked, show popup
|
|
|
|
"""
|
|
|
|
if event.button == 3: # right click
|
2012-12-23 16:23:43 +01:00
|
|
|
menu = Gtk.Menu()
|
2014-11-11 23:11:15 +01:00
|
|
|
menuitem = Gtk.MenuItem.new_with_mnemonic(_('Save _As'))
|
2010-02-08 15:08:40 +01:00
|
|
|
menuitem.connect('activate',
|
|
|
|
gtkgui_helpers.on_avatar_save_as_menuitem_activate,
|
2017-09-16 11:49:31 +02:00
|
|
|
self.contact.avatar_sha, self.contact.get_shown_name())
|
2010-02-08 15:08:40 +01:00
|
|
|
menu.append(menuitem)
|
|
|
|
menu.connect('selection-done', lambda w:w.destroy())
|
|
|
|
# show the menu
|
|
|
|
menu.show_all()
|
2013-01-07 23:22:40 +01:00
|
|
|
menu.attach_to_widget(widget, None)
|
2012-12-27 21:58:52 +01:00
|
|
|
menu.popup(None, None, None, None, event.button, event.time)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def set_value(self, entry_name, value):
|
|
|
|
try:
|
|
|
|
if value and entry_name == 'URL_label':
|
2015-07-30 15:18:03 +02:00
|
|
|
widget = Gtk.LinkButton(uri=value, label=value)
|
2010-02-08 15:08:40 +01:00
|
|
|
widget.set_alignment(0, 0)
|
|
|
|
table = self.xml.get_object('personal_info_table')
|
2015-08-30 23:22:42 +02:00
|
|
|
table.attach(widget, 1, 3, 2, 1)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self.xml.get_object(entry_name).set_text(value)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def fill_status_label(self):
|
|
|
|
if self.xml.get_object('information_notebook').get_n_pages() < 2:
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
contact_list = app.contacts.get_contacts(self.account, self.contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
# stats holds show and status message
|
|
|
|
stats = ''
|
|
|
|
one = True # Are we adding the first line ?
|
|
|
|
if contact_list:
|
|
|
|
for c in contact_list:
|
|
|
|
if not one:
|
|
|
|
stats += '\n'
|
|
|
|
stats += helpers.get_uf_show(c.show)
|
|
|
|
if c.status:
|
|
|
|
stats += ': ' + c.status
|
|
|
|
one = False
|
|
|
|
else: # Maybe gc_vcard ?
|
|
|
|
stats = helpers.get_uf_show(self.contact.show)
|
|
|
|
if self.contact.status:
|
|
|
|
stats += ': ' + self.contact.status
|
|
|
|
status_label = self.xml.get_object('status_label')
|
|
|
|
status_label.set_text(stats)
|
2017-06-12 22:04:22 +02:00
|
|
|
status_label.set_tooltip_text(stats)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def fill_contact_page(self):
|
|
|
|
self.xml.get_object('nickname_label').set_markup(
|
|
|
|
'<b><span size="x-large">' +
|
|
|
|
self.contact.get_shown_name() +
|
|
|
|
'</span></b>')
|
|
|
|
self.xml.get_object('local_jid_label').set_text(self.contact.jid)
|
|
|
|
|
2013-01-01 21:06:16 +01:00
|
|
|
resources = '%s (%s)' % (self.contact.resource, str(
|
|
|
|
self.contact.priority))
|
2010-02-08 15:08:40 +01:00
|
|
|
uf_resources = self.contact.resource + _(' resource with priority ')\
|
2013-01-01 21:06:16 +01:00
|
|
|
+ str(self.contact.priority)
|
2010-02-08 15:08:40 +01:00
|
|
|
if not self.contact.status:
|
|
|
|
self.contact.status = ''
|
|
|
|
|
|
|
|
self.xml.get_object('resource_prio_label').set_text(resources)
|
|
|
|
resource_prio_label_eventbox = self.xml.get_object(
|
|
|
|
'resource_prio_label_eventbox')
|
|
|
|
resource_prio_label_eventbox.set_tooltip_text(uf_resources)
|
|
|
|
|
|
|
|
self.fill_status_label()
|
|
|
|
|
|
|
|
def fill_personal_page(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.connections[app.ZEROCONF_ACC_NAME].roster.getItem(self.contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
for key in ('1st', 'last', 'jid', 'email'):
|
|
|
|
if key not in contact['txt_dict']:
|
|
|
|
contact['txt_dict'][key] = ''
|
|
|
|
self.xml.get_object('first_name_label').set_text(contact['txt_dict']['1st'])
|
|
|
|
self.xml.get_object('last_name_label').set_text(contact['txt_dict']['last'])
|
|
|
|
self.xml.get_object('jabber_id_label').set_text(contact['txt_dict']['jid'])
|
|
|
|
self.xml.get_object('email_label').set_text(contact['txt_dict']['email'])
|
|
|
|
|
|
|
|
def on_close_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|