diff --git a/src/chat_control.py b/src/chat_control.py
index 163355e87..f33e07cb5 100644
--- a/src/chat_control.py
+++ b/src/chat_control.py
@@ -791,7 +791,7 @@ class ChatControl(ChatControlBase):
jid = contact.jid
banner_name_label = self.xml.get_widget('banner_name_label')
- name = gtkgui_helpers.escape_for_pango_markup(contact.name)
+ name = gtkgui_helpers.escape_for_pango_markup(contact.get_shown_name())
status = contact.status
if status is not None:
@@ -841,7 +841,7 @@ class ChatControl(ChatControlBase):
tb.set_sensitive(False)
#we talk about a contact here
tt = _('%s has not broadcast an OpenPGP key, nor has one been assigned') %\
- self.contact.name
+ self.contact.get_shown_name()
gtk.Tooltips().set_tip(self.xml.get_widget('gpg_eventbox'), tt)
def send_message(self, message, keyID = '', chatstate = None):
@@ -972,10 +972,10 @@ class ChatControl(ChatControlBase):
self.xml.get_widget('gpg_togglebutton').set_active(encrypted)
if not frm:
kind = 'incoming'
- name = contact.name
+ name = contact.get_shown_name()
elif frm == 'print_queue': # incoming message, but do not update time
kind = 'incoming_queue'
- name = contact.name
+ name = contact.get_shown_name()
else:
kind = 'outgoing'
name = gajim.nicks[self.account]
@@ -1018,7 +1018,8 @@ class ChatControl(ChatControlBase):
self.parent_win.get_active_control() != self:
color = self.lighten_color(color)
- label_str = gtkgui_helpers.escape_for_pango_markup(self.contact.name)
+ label_str = gtkgui_helpers.escape_for_pango_markup(
+ self.contact.get_shown_name())
if num_unread: # if unread, text in the label becomes bold
label_str = '' + unread + label_str + ''
return (label_str, color)
@@ -1268,7 +1269,7 @@ class ChatControl(ChatControlBase):
elif row[1] in (constants.KIND_SINGLE_MSG_RECV,
constants.KIND_CHAT_MSG_RECV):
kind = 'incoming'
- name = self.contact.name
+ name = self.contact.get_shown_name()
tim = time.localtime(float(row[0]))
diff --git a/src/common/contacts.py b/src/common/contacts.py
index 2f222fbed..0e7e0b526 100644
--- a/src/common/contacts.py
+++ b/src/common/contacts.py
@@ -56,6 +56,11 @@ class Contact:
return self.jid + '/' + self.resource
return self.jid
+ def get_shown_name(self):
+ if self.name:
+ return self.name
+ return self.jid.split('@')[0]
+
class GC_Contact:
'''Information concerning each groupchat contact'''
def __init__(self, room_jid='', name='', show='', status='', role='',
@@ -72,6 +77,9 @@ class GC_Contact:
def get_full_jid(self):
return self.room_jid + '/' + self.name
+ def get_shown_name(self):
+ return self.name
+
class Contacts:
'''Information concerning all contacts and groupchat contacts'''
def __init__(self):
diff --git a/src/dialogs.py b/src/dialogs.py
index 36b016379..26fe02106 100644
--- a/src/dialogs.py
+++ b/src/dialogs.py
@@ -64,7 +64,7 @@ class EditGroupsDialog:
self.changes_made = False
self.list = self.xml.get_widget('groups_treeview')
self.xml.get_widget('nickname_label').set_markup(
- _("Contact's name: %s") % user.name)
+ _("Contact's name: %s") % user.get_shown_name())
self.xml.get_widget('jid_label').set_markup(
_('JID: %s') % user.jid)
@@ -842,10 +842,12 @@ class PopupNotificationWindow:
event_description_label = xml.get_widget('event_description_label')
eventbox = xml.get_widget('eventbox')
- event_type_label.set_markup('%s' %event_type)
+ event_type_label.set_markup(
+ '%s' % event_type)
if self.jid in gajim.contacts.get_jid_list(account):
- txt = gajim.contacts.get_first_contact_from_jid(account, self.jid).name
+ txt = gajim.contacts.get_first_contact_from_jid(account,
+ self.jid).get_shown_name()
else:
txt = self.jid
@@ -856,12 +858,14 @@ class PopupNotificationWindow:
limegreen = gtk.gdk.color_parse('limegreen')
close_button.modify_bg(gtk.STATE_NORMAL, limegreen)
eventbox.modify_bg(gtk.STATE_NORMAL, limegreen)
- event_description_label.set_markup('%s' % txt)
+ event_description_label.set_markup(
+ '%s' % txt)
elif event_type == _('Contact Signed Out'):
red = gtk.gdk.color_parse('red')
close_button.modify_bg(gtk.STATE_NORMAL, red)
eventbox.modify_bg(gtk.STATE_NORMAL, red)
- event_description_label.set_markup('%s' % txt)
+ event_description_label.set_markup(
+ '%s' % txt)
elif event_type in (_('New Message'), _('New Single Message'),
_('New Private Message')):
dodgerblue = gtk.gdk.color_parse('dodgerblue')
@@ -895,7 +899,7 @@ class PopupNotificationWindow:
# get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(account,
- sender).name
+ sender).get_shown_name()
txt = _('From %s') % name
else:
receiver = file_props['receiver']
@@ -904,7 +908,7 @@ class PopupNotificationWindow:
receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster
name = gajim.contacts.get_first_contact_from_jid(account,
- receiver).name
+ receiver).get_shown_name()
txt = _('To %s') % name
else:
txt = ''
diff --git a/src/filetransfers_window.py b/src/filetransfers_window.py
index 8742595b8..92ccb87e2 100644
--- a/src/filetransfers_window.py
+++ b/src/filetransfers_window.py
@@ -178,7 +178,7 @@ class FileTransfersWindow:
if file_props['type'] == 'r':
jid = unicode(file_props['sender']).split('/')[0]
sender_name = gajim.contacts.get_first_contact_from_jid(
- file_props['tt_account'], jid).name
+ file_props['tt_account'], jid).get_shown_name()
sender = gtkgui_helpers.escape_for_pango_markup(sender_name)
else:
#You is a reply of who sent a file
@@ -188,7 +188,7 @@ class FileTransfersWindow:
if file_props['type'] == 's':
jid = unicode(file_props['receiver']).split('/')[0]
receiver_name = gajim.contacts.get_first_contact_from_jid(
- file_props['tt_account'], jid).name
+ file_props['tt_account'], jid).get_shown_name()
recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name)
else:
#You is a reply of who received a file
@@ -567,7 +567,8 @@ _('Connection with peer cannot be established.'))
else:
file_name = file_props['name']
text_props = gtkgui_helpers.escape_for_pango_markup(file_name) + '\n'
- text_props += gtkgui_helpers.escape_for_pango_markup(contact.name)
+ text_props += gtkgui_helpers.escape_for_pango_markup(
+ contact.get_shown_name())
self.model.set(iter, 1, text_labels, 2, text_props, C_SID,
file_props['type'] + file_props['sid'])
self.set_progress(file_props['type'], file_props['sid'], 0, iter)
diff --git a/src/gajim.py b/src/gajim.py
index 116f40513..9bf895331 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -771,8 +771,9 @@ class Interface:
return
for contact in contacts:
name = array[1]
- if name:
- contact.name = name
+ if not name:
+ name = ''
+ contact.name = name
contact.sub = array[2]
contact.ask = array[3]
if array[4]:
diff --git a/src/history_window.py b/src/history_window.py
index c7a9ef2c8..b91eb6c92 100644
--- a/src/history_window.py
+++ b/src/history_window.py
@@ -108,7 +108,7 @@ class HistoryWindow:
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if contact:
- title = _('Conversation History with %s') % contact.name
+ title = _('Conversation History with %s') % contact.get_shown_name()
else:
title = _('Conversation History with %s') % jid
self.window.set_title(title)
@@ -241,7 +241,7 @@ class HistoryWindow:
self.jid)
if contact:
# he is in our roster, use the name
- contact_name = contact.name
+ contact_name = contact.get_shown_name()
else:
room_jid, nick = gajim.get_room_and_nick_from_fjid(self.jid)
# do we have him as gc_contact?
@@ -337,7 +337,7 @@ class HistoryWindow:
if self.account and gajim.contacts[self.account].has_key(self.jid):
contact = gajim.get_first_contact_instance_from_jid(
self.account, self.jid)
- contact_name = contact.name
+ contact_name = contact.get_shown_name()
else:
contact_name = self.jid
tim = row[1]
diff --git a/src/message_window.py b/src/message_window.py
index 165fb835d..c599628c7 100644
--- a/src/message_window.py
+++ b/src/message_window.py
@@ -190,10 +190,8 @@ class MessageWindow:
control = self.get_active_control()
if control.type_id == message_control.TYPE_GC:
title = control.room_jid
- elif control.contact.name:
- title = control.contact.name
else:
- title = control.contact.jid
+ title = control.contact.get_shown_name()
title = unread_str + title
self.window.set_title(title)
@@ -382,7 +380,7 @@ class MessageWindow:
jid = ctl.contact.jid
if jid != self.get_active_jid():
item = gtk.ImageMenuItem(_('Switch to %s') %\
- ctl.contact.name)
+ ctl.contact.get_shown_name())
img = gtk.image_new_from_stock(gtk.STOCK_JUMP_TO,
gtk.ICON_SIZE_MENU)
item.set_image(img)
diff --git a/src/notify.py b/src/notify.py
index 119b366c6..ecd59c5e3 100644
--- a/src/notify.py
+++ b/src/notify.py
@@ -107,7 +107,7 @@ class DesktopNotification:
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if contact:
- actor = contact.name
+ actor = contact.get_shown_name()
else:
actor = jid
@@ -168,7 +168,7 @@ class DesktopNotification:
# get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(account,
- sender).name
+ sender).get_shown_name()
filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'):
txt = _('You successfully received %(filename)s from %(name)s.')\
@@ -185,7 +185,7 @@ class DesktopNotification:
receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster
name = gajim.contacts.get_first_contact_from_jid(account,
- receiver).name
+ receiver).get_shown_name()
filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'):
txt = _('You successfully sent %(filename)s to %(name)s.')\
diff --git a/src/roster_window.py b/src/roster_window.py
index 73c9433d2..f6459c92f 100644
--- a/src/roster_window.py
+++ b/src/roster_window.py
@@ -199,9 +199,10 @@ class RosterWindow:
if g == _('Transports'):
typestr = 'agent'
+ name = contcat.get_shown_name()
# we add some values here. see draw_contact for more
- model.append(iterG, (None, contact.name,
- typestr, contact.jid, account, False, None))
+ model.append(iterG, (None, name, typestr, contact.jid, account,
+ False, None))
if gajim.groups[account][g]['expand']:
self.tree.expand_row(model.get_path(iterG), False)
@@ -267,7 +268,7 @@ class RosterWindow:
contact_instances)
if not contact:
return
- name = gtkgui_helpers.escape_for_pango_markup(contact.name)
+ name = gtkgui_helpers.escape_for_pango_markup(contact.get_shown_name())
if len(contact_instances) > 1:
name += ' (' + unicode(len(contact_instances)) + ')'
@@ -665,10 +666,7 @@ class RosterWindow:
#get name
name = array[jid]['name']
if not name:
- if ji.find('@') <= 0:
- name = ji
- else:
- name = jid.split('@')[0]
+ name = ''
show = 'offline' # show is offline by default
status = '' #no status message by default
@@ -731,7 +729,7 @@ class RosterWindow:
ctl.update_ui()
win.redraw_tab(contact)
- name = contact.name
+ name = contact.get_shown_name()
if contact.resource != '':
name += '/' + contact.resource
uf_show = helpers.get_uf_show(show)
@@ -1255,8 +1253,6 @@ class RosterWindow:
def req_sub(self, widget, jid, txt, account, group=None, pseudo=None):
'''Request subscription to a contact'''
- if not pseudo:
- pseudo = jid
gajim.connections[account].request_subscription(jid, txt)
if group:
group = [group]
@@ -1279,7 +1275,8 @@ class RosterWindow:
_('If "%s" accepts this request you will know his or her status.') % jid)
return
contact.groups = group
- contact.name = pseudo
+ if pseudo:
+ contact.name = pseudo
self.remove_contact(contact, account)
self.add_contact_to_roster(jid, account)
@@ -1434,7 +1431,8 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
def on_req_usub(self, widget, contact, account):
'''Remove a contact'''
window = dialogs.ConfirmationDialogCheck(
- _('Contact "%s" will be removed from your roster') % (contact.name),
+ _('Contact "%s" will be removed from your roster') % (
+ contact.get_shown_name()),
_('By removing this contact you also by default remove authorization resulting in him or her always seeing you as offline.'),
_('I want this contact to know my status after removal'))
# maybe use 2 optionboxes from which the contact can select? (better)
@@ -2414,13 +2412,13 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
contact1 = gajim.contacts.get_first_contact_from_jid(account1, jid1)
if not contact1:
return 0
- name1 = contact1.name
+ name1 = contact1.get_shown_name()
if type2 == 'contact':
lcontact2 = gajim.contacts.get_contact(account2, jid2)
contact2 = gajim.contacts.get_first_contact_from_jid(account2, jid2)
if not contact2:
return 0
- name2 = contact2.name
+ name2 = contact2.get_shown_name()
# We first compare by show if sort_by_show is True
if type1 == 'contact' and type2 == 'contact' and \
gajim.config.get('sort_by_show'):
diff --git a/src/systray.py b/src/systray.py
index e89073578..92f2393c3 100644
--- a/src/systray.py
+++ b/src/systray.py
@@ -255,7 +255,7 @@ class Systray:
if group in contact.groups and contact.show != 'offline' and \
contact.show != 'error':
at_least_one = True
- s = contact.name.replace('_', '__') # two _ show one _ and no underline happens
+ s = contact.get_shown_name().replace('_', '__') # two _ show one _ and no underline happens
item = gtk.ImageMenuItem(s)
# any given gtk widget can only be used in one place
# (here we use it in status menu too)
diff --git a/src/tooltips.py b/src/tooltips.py
index 5f2db2edf..64a78b0c2 100644
--- a/src/tooltips.py
+++ b/src/tooltips.py
@@ -323,7 +323,7 @@ class GCTooltip(BaseTooltip):
if contact.jid.strip() != '':
info = '' + contact.jid + ''
else:
- info = '' + contact.name + ''
+ info = '' + contact.get_shown_name() + ''
info += '\n' + _('Role: ') + '' + \
helpers.get_uf_role(contact.role)
@@ -404,7 +404,7 @@ class RosterTooltip(NotificationAreaTooltip):
info = '' + prim_contact.jid + ''
info += '\n' + _('Name: ') + '' + \
- gtkgui_helpers.escape_for_pango_markup(prim_contact.name)
+ gtkgui_helpers.escape_for_pango_markup(prim_contact.get_shown_name())
if prim_contact.sub:
info += '\n' + _('Subscription: ') + '' + \
gtkgui_helpers.escape_for_pango_markup(prim_contact.sub)
@@ -484,7 +484,7 @@ class FileTransfersTooltip(BaseTooltip):
text += '\n' + _('Sender: ') + ''
sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(
- file_props['tt_account'], sender).name
+ file_props['tt_account'], sender).get_shown_name()
else:
text += '\n' + _('Recipient: ') + ''
receiver = file_props['receiver']
@@ -495,7 +495,7 @@ class FileTransfersTooltip(BaseTooltip):
name = receiver
else:
name = gajim.contacts.get_first_contact_from_jid(
- file_props['tt_account'], receiver).name
+ file_props['tt_account'], receiver).get_shown_name()
text += gtkgui_helpers.escape_for_pango_markup(name)
text += '\n' + _('Size: ') + ''
text += helpers.convert_bytes(file_props['size'])
diff --git a/src/vcard.py b/src/vcard.py
index 076a4bf42..223f537cf 100644
--- a/src/vcard.py
+++ b/src/vcard.py
@@ -135,7 +135,7 @@ class VcardWindow:
if self.vcard:
self.window.destroy()
return
- #update contact.name if it's not ''
+ # update contact.name if it's not ''
name_entry = self.xml.get_widget('nickname_entry')
new_name = name_entry.get_text().decode('utf-8')
if new_name != self.contact.name and new_name != '':
@@ -283,7 +283,8 @@ class VcardWindow:
def fill_jabber_page(self):
tooltips = gtk.Tooltips()
- self.xml.get_widget('nickname_label').set_text(self.contact.name)
+ self.xml.get_widget('nickname_label').set_text(
+ self.contact.get_shown_name())
self.xml.get_widget('jid_label').set_text(self.contact.jid)
uf_sub = helpers.get_uf_sub(self.contact.sub)
self.xml.get_widget('subscription_label').set_text(uf_sub)