contact.name can now be empty. So use contact.get_shown_name() that returns a user friendly name

This commit is contained in:
Yann Leboulanger 2006-01-10 18:30:57 +00:00
parent 9901ebbca0
commit d2ab3031f1
12 changed files with 61 additions and 49 deletions

View file

@ -791,7 +791,7 @@ class ChatControl(ChatControlBase):
jid = contact.jid jid = contact.jid
banner_name_label = self.xml.get_widget('banner_name_label') 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 status = contact.status
if status is not None: if status is not None:
@ -841,7 +841,7 @@ class ChatControl(ChatControlBase):
tb.set_sensitive(False) tb.set_sensitive(False)
#we talk about a contact here #we talk about a contact here
tt = _('%s has not broadcast an OpenPGP key, nor has one been assigned') %\ 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) gtk.Tooltips().set_tip(self.xml.get_widget('gpg_eventbox'), tt)
def send_message(self, message, keyID = '', chatstate = None): def send_message(self, message, keyID = '', chatstate = None):
@ -972,10 +972,10 @@ class ChatControl(ChatControlBase):
self.xml.get_widget('gpg_togglebutton').set_active(encrypted) self.xml.get_widget('gpg_togglebutton').set_active(encrypted)
if not frm: if not frm:
kind = 'incoming' kind = 'incoming'
name = contact.name name = contact.get_shown_name()
elif frm == 'print_queue': # incoming message, but do not update time elif frm == 'print_queue': # incoming message, but do not update time
kind = 'incoming_queue' kind = 'incoming_queue'
name = contact.name name = contact.get_shown_name()
else: else:
kind = 'outgoing' kind = 'outgoing'
name = gajim.nicks[self.account] name = gajim.nicks[self.account]
@ -1018,7 +1018,8 @@ class ChatControl(ChatControlBase):
self.parent_win.get_active_control() != self: self.parent_win.get_active_control() != self:
color = self.lighten_color(color) 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 if num_unread: # if unread, text in the label becomes bold
label_str = '<b>' + unread + label_str + '</b>' label_str = '<b>' + unread + label_str + '</b>'
return (label_str, color) return (label_str, color)
@ -1268,7 +1269,7 @@ class ChatControl(ChatControlBase):
elif row[1] in (constants.KIND_SINGLE_MSG_RECV, elif row[1] in (constants.KIND_SINGLE_MSG_RECV,
constants.KIND_CHAT_MSG_RECV): constants.KIND_CHAT_MSG_RECV):
kind = 'incoming' kind = 'incoming'
name = self.contact.name name = self.contact.get_shown_name()
tim = time.localtime(float(row[0])) tim = time.localtime(float(row[0]))

View file

@ -56,6 +56,11 @@ class Contact:
return self.jid + '/' + self.resource return self.jid + '/' + self.resource
return self.jid return self.jid
def get_shown_name(self):
if self.name:
return self.name
return self.jid.split('@')[0]
class GC_Contact: class GC_Contact:
'''Information concerning each groupchat contact''' '''Information concerning each groupchat contact'''
def __init__(self, room_jid='', name='', show='', status='', role='', def __init__(self, room_jid='', name='', show='', status='', role='',
@ -72,6 +77,9 @@ class GC_Contact:
def get_full_jid(self): def get_full_jid(self):
return self.room_jid + '/' + self.name return self.room_jid + '/' + self.name
def get_shown_name(self):
return self.name
class Contacts: class Contacts:
'''Information concerning all contacts and groupchat contacts''' '''Information concerning all contacts and groupchat contacts'''
def __init__(self): def __init__(self):

View file

@ -64,7 +64,7 @@ class EditGroupsDialog:
self.changes_made = False self.changes_made = False
self.list = self.xml.get_widget('groups_treeview') self.list = self.xml.get_widget('groups_treeview')
self.xml.get_widget('nickname_label').set_markup( self.xml.get_widget('nickname_label').set_markup(
_("Contact's name: <i>%s</i>") % user.name) _("Contact's name: <i>%s</i>") % user.get_shown_name())
self.xml.get_widget('jid_label').set_markup( self.xml.get_widget('jid_label').set_markup(
_('JID: <i>%s</i>') % user.jid) _('JID: <i>%s</i>') % user.jid)
@ -842,10 +842,12 @@ class PopupNotificationWindow:
event_description_label = xml.get_widget('event_description_label') event_description_label = xml.get_widget('event_description_label')
eventbox = xml.get_widget('eventbox') eventbox = xml.get_widget('eventbox')
event_type_label.set_markup('<span foreground="black" weight="bold">%s</span>' %event_type) event_type_label.set_markup(
'<span foreground="black" weight="bold">%s</span>' % event_type)
if self.jid in gajim.contacts.get_jid_list(account): 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: else:
txt = self.jid txt = self.jid
@ -856,12 +858,14 @@ class PopupNotificationWindow:
limegreen = gtk.gdk.color_parse('limegreen') limegreen = gtk.gdk.color_parse('limegreen')
close_button.modify_bg(gtk.STATE_NORMAL, limegreen) close_button.modify_bg(gtk.STATE_NORMAL, limegreen)
eventbox.modify_bg(gtk.STATE_NORMAL, limegreen) eventbox.modify_bg(gtk.STATE_NORMAL, limegreen)
event_description_label.set_markup('<span foreground="black">%s</span>' % txt) event_description_label.set_markup(
'<span foreground="black">%s</span>' % txt)
elif event_type == _('Contact Signed Out'): elif event_type == _('Contact Signed Out'):
red = gtk.gdk.color_parse('red') red = gtk.gdk.color_parse('red')
close_button.modify_bg(gtk.STATE_NORMAL, red) close_button.modify_bg(gtk.STATE_NORMAL, red)
eventbox.modify_bg(gtk.STATE_NORMAL, red) eventbox.modify_bg(gtk.STATE_NORMAL, red)
event_description_label.set_markup('<span foreground="black">%s</span>' % txt) event_description_label.set_markup(
'<span foreground="black">%s</span>' % txt)
elif event_type in (_('New Message'), _('New Single Message'), elif event_type in (_('New Message'), _('New Single Message'),
_('New Private Message')): _('New Private Message')):
dodgerblue = gtk.gdk.color_parse('dodgerblue') dodgerblue = gtk.gdk.color_parse('dodgerblue')
@ -895,7 +899,7 @@ class PopupNotificationWindow:
# get the name of the sender, as it is in the roster # get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0] sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(account, name = gajim.contacts.get_first_contact_from_jid(account,
sender).name sender).get_shown_name()
txt = _('From %s') % name txt = _('From %s') % name
else: else:
receiver = file_props['receiver'] receiver = file_props['receiver']
@ -904,7 +908,7 @@ class PopupNotificationWindow:
receiver = receiver.split('/')[0] receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster # get the name of the contact, as it is in the roster
name = gajim.contacts.get_first_contact_from_jid(account, name = gajim.contacts.get_first_contact_from_jid(account,
receiver).name receiver).get_shown_name()
txt = _('To %s') % name txt = _('To %s') % name
else: else:
txt = '' txt = ''

View file

@ -178,7 +178,7 @@ class FileTransfersWindow:
if file_props['type'] == 'r': if file_props['type'] == 'r':
jid = unicode(file_props['sender']).split('/')[0] jid = unicode(file_props['sender']).split('/')[0]
sender_name = gajim.contacts.get_first_contact_from_jid( 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) sender = gtkgui_helpers.escape_for_pango_markup(sender_name)
else: else:
#You is a reply of who sent a file #You is a reply of who sent a file
@ -188,7 +188,7 @@ class FileTransfersWindow:
if file_props['type'] == 's': if file_props['type'] == 's':
jid = unicode(file_props['receiver']).split('/')[0] jid = unicode(file_props['receiver']).split('/')[0]
receiver_name = gajim.contacts.get_first_contact_from_jid( 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) recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name)
else: else:
#You is a reply of who received a file #You is a reply of who received a file
@ -567,7 +567,8 @@ _('Connection with peer cannot be established.'))
else: else:
file_name = file_props['name'] file_name = file_props['name']
text_props = gtkgui_helpers.escape_for_pango_markup(file_name) + '\n' 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, self.model.set(iter, 1, text_labels, 2, text_props, C_SID,
file_props['type'] + file_props['sid']) file_props['type'] + file_props['sid'])
self.set_progress(file_props['type'], file_props['sid'], 0, iter) self.set_progress(file_props['type'], file_props['sid'], 0, iter)

View file

@ -771,7 +771,8 @@ class Interface:
return return
for contact in contacts: for contact in contacts:
name = array[1] name = array[1]
if name: if not name:
name = ''
contact.name = name contact.name = name
contact.sub = array[2] contact.sub = array[2]
contact.ask = array[3] contact.ask = array[3]

View file

@ -108,7 +108,7 @@ class HistoryWindow:
contact = gajim.contacts.get_first_contact_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if contact: if contact:
title = _('Conversation History with %s') % contact.name title = _('Conversation History with %s') % contact.get_shown_name()
else: else:
title = _('Conversation History with %s') % jid title = _('Conversation History with %s') % jid
self.window.set_title(title) self.window.set_title(title)
@ -241,7 +241,7 @@ class HistoryWindow:
self.jid) self.jid)
if contact: if contact:
# he is in our roster, use the name # he is in our roster, use the name
contact_name = contact.name contact_name = contact.get_shown_name()
else: else:
room_jid, nick = gajim.get_room_and_nick_from_fjid(self.jid) room_jid, nick = gajim.get_room_and_nick_from_fjid(self.jid)
# do we have him as gc_contact? # 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): if self.account and gajim.contacts[self.account].has_key(self.jid):
contact = gajim.get_first_contact_instance_from_jid( contact = gajim.get_first_contact_instance_from_jid(
self.account, self.jid) self.account, self.jid)
contact_name = contact.name contact_name = contact.get_shown_name()
else: else:
contact_name = self.jid contact_name = self.jid
tim = row[1] tim = row[1]

View file

@ -190,10 +190,8 @@ class MessageWindow:
control = self.get_active_control() control = self.get_active_control()
if control.type_id == message_control.TYPE_GC: if control.type_id == message_control.TYPE_GC:
title = control.room_jid title = control.room_jid
elif control.contact.name:
title = control.contact.name
else: else:
title = control.contact.jid title = control.contact.get_shown_name()
title = unread_str + title title = unread_str + title
self.window.set_title(title) self.window.set_title(title)
@ -382,7 +380,7 @@ class MessageWindow:
jid = ctl.contact.jid jid = ctl.contact.jid
if jid != self.get_active_jid(): if jid != self.get_active_jid():
item = gtk.ImageMenuItem(_('Switch to %s') %\ item = gtk.ImageMenuItem(_('Switch to %s') %\
ctl.contact.name) ctl.contact.get_shown_name())
img = gtk.image_new_from_stock(gtk.STOCK_JUMP_TO, img = gtk.image_new_from_stock(gtk.STOCK_JUMP_TO,
gtk.ICON_SIZE_MENU) gtk.ICON_SIZE_MENU)
item.set_image(img) item.set_image(img)

View file

@ -107,7 +107,7 @@ class DesktopNotification:
contact = gajim.contacts.get_first_contact_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if contact: if contact:
actor = contact.name actor = contact.get_shown_name()
else: else:
actor = jid actor = jid
@ -168,7 +168,7 @@ class DesktopNotification:
# get the name of the sender, as it is in the roster # get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0] sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(account, name = gajim.contacts.get_first_contact_from_jid(account,
sender).name sender).get_shown_name()
filename = os.path.basename(file_props['file-name']) filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'): if event_type == _('File Transfer Completed'):
txt = _('You successfully received %(filename)s from %(name)s.')\ txt = _('You successfully received %(filename)s from %(name)s.')\
@ -185,7 +185,7 @@ class DesktopNotification:
receiver = receiver.split('/')[0] receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster # get the name of the contact, as it is in the roster
name = gajim.contacts.get_first_contact_from_jid(account, name = gajim.contacts.get_first_contact_from_jid(account,
receiver).name receiver).get_shown_name()
filename = os.path.basename(file_props['file-name']) filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'): if event_type == _('File Transfer Completed'):
txt = _('You successfully sent %(filename)s to %(name)s.')\ txt = _('You successfully sent %(filename)s to %(name)s.')\

View file

@ -199,9 +199,10 @@ class RosterWindow:
if g == _('Transports'): if g == _('Transports'):
typestr = 'agent' typestr = 'agent'
name = contcat.get_shown_name()
# we add some values here. see draw_contact for more # we add some values here. see draw_contact for more
model.append(iterG, (None, contact.name, model.append(iterG, (None, name, typestr, contact.jid, account,
typestr, contact.jid, account, False, None)) False, None))
if gajim.groups[account][g]['expand']: if gajim.groups[account][g]['expand']:
self.tree.expand_row(model.get_path(iterG), False) self.tree.expand_row(model.get_path(iterG), False)
@ -267,7 +268,7 @@ class RosterWindow:
contact_instances) contact_instances)
if not contact: if not contact:
return 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: if len(contact_instances) > 1:
name += ' (' + unicode(len(contact_instances)) + ')' name += ' (' + unicode(len(contact_instances)) + ')'
@ -665,10 +666,7 @@ class RosterWindow:
#get name #get name
name = array[jid]['name'] name = array[jid]['name']
if not name: if not name:
if ji.find('@') <= 0: name = ''
name = ji
else:
name = jid.split('@')[0]
show = 'offline' # show is offline by default show = 'offline' # show is offline by default
status = '' #no status message by default status = '' #no status message by default
@ -731,7 +729,7 @@ class RosterWindow:
ctl.update_ui() ctl.update_ui()
win.redraw_tab(contact) win.redraw_tab(contact)
name = contact.name name = contact.get_shown_name()
if contact.resource != '': if contact.resource != '':
name += '/' + contact.resource name += '/' + contact.resource
uf_show = helpers.get_uf_show(show) 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): def req_sub(self, widget, jid, txt, account, group=None, pseudo=None):
'''Request subscription to a contact''' '''Request subscription to a contact'''
if not pseudo:
pseudo = jid
gajim.connections[account].request_subscription(jid, txt) gajim.connections[account].request_subscription(jid, txt)
if group: if group:
group = [group] group = [group]
@ -1279,6 +1275,7 @@ class RosterWindow:
_('If "%s" accepts this request you will know his or her status.') % jid) _('If "%s" accepts this request you will know his or her status.') % jid)
return return
contact.groups = group contact.groups = group
if pseudo:
contact.name = pseudo contact.name = pseudo
self.remove_contact(contact, account) self.remove_contact(contact, account)
self.add_contact_to_roster(jid, 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): def on_req_usub(self, widget, contact, account):
'''Remove a contact''' '''Remove a contact'''
window = dialogs.ConfirmationDialogCheck( 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.'), _('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')) _('I want this contact to know my status after removal'))
# maybe use 2 optionboxes from which the contact can select? (better) # 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) contact1 = gajim.contacts.get_first_contact_from_jid(account1, jid1)
if not contact1: if not contact1:
return 0 return 0
name1 = contact1.name name1 = contact1.get_shown_name()
if type2 == 'contact': if type2 == 'contact':
lcontact2 = gajim.contacts.get_contact(account2, jid2) lcontact2 = gajim.contacts.get_contact(account2, jid2)
contact2 = gajim.contacts.get_first_contact_from_jid(account2, jid2) contact2 = gajim.contacts.get_first_contact_from_jid(account2, jid2)
if not contact2: if not contact2:
return 0 return 0
name2 = contact2.name name2 = contact2.get_shown_name()
# We first compare by show if sort_by_show is True # We first compare by show if sort_by_show is True
if type1 == 'contact' and type2 == 'contact' and \ if type1 == 'contact' and type2 == 'contact' and \
gajim.config.get('sort_by_show'): gajim.config.get('sort_by_show'):

View file

@ -255,7 +255,7 @@ class Systray:
if group in contact.groups and contact.show != 'offline' and \ if group in contact.groups and contact.show != 'offline' and \
contact.show != 'error': contact.show != 'error':
at_least_one = True 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) item = gtk.ImageMenuItem(s)
# any given gtk widget can only be used in one place # any given gtk widget can only be used in one place
# (here we use it in status menu too) # (here we use it in status menu too)

View file

@ -323,7 +323,7 @@ class GCTooltip(BaseTooltip):
if contact.jid.strip() != '': if contact.jid.strip() != '':
info = '<span size="large" weight="bold">' + contact.jid + '</span>' info = '<span size="large" weight="bold">' + contact.jid + '</span>'
else: else:
info = '<span size="large" weight="bold">' + contact.name + '</span>' info = '<span size="large" weight="bold">' + contact.get_shown_name() + '</span>'
info += '\n<span weight="bold">' + _('Role: ') + '</span>' + \ info += '\n<span weight="bold">' + _('Role: ') + '</span>' + \
helpers.get_uf_role(contact.role) helpers.get_uf_role(contact.role)
@ -404,7 +404,7 @@ class RosterTooltip(NotificationAreaTooltip):
info = '<span size="large" weight="bold">' + prim_contact.jid + '</span>' info = '<span size="large" weight="bold">' + prim_contact.jid + '</span>'
info += '\n<span weight="bold">' + _('Name: ') + '</span>' + \ info += '\n<span weight="bold">' + _('Name: ') + '</span>' + \
gtkgui_helpers.escape_for_pango_markup(prim_contact.name) gtkgui_helpers.escape_for_pango_markup(prim_contact.get_shown_name())
if prim_contact.sub: if prim_contact.sub:
info += '\n<span weight="bold">' + _('Subscription: ') + '</span>' + \ info += '\n<span weight="bold">' + _('Subscription: ') + '</span>' + \
gtkgui_helpers.escape_for_pango_markup(prim_contact.sub) gtkgui_helpers.escape_for_pango_markup(prim_contact.sub)
@ -484,7 +484,7 @@ class FileTransfersTooltip(BaseTooltip):
text += '\n<b>' + _('Sender: ') + '</b>' text += '\n<b>' + _('Sender: ') + '</b>'
sender = unicode(file_props['sender']).split('/')[0] sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid( name = gajim.contacts.get_first_contact_from_jid(
file_props['tt_account'], sender).name file_props['tt_account'], sender).get_shown_name()
else: else:
text += '\n<b>' + _('Recipient: ') + '</b>' text += '\n<b>' + _('Recipient: ') + '</b>'
receiver = file_props['receiver'] receiver = file_props['receiver']
@ -495,7 +495,7 @@ class FileTransfersTooltip(BaseTooltip):
name = receiver name = receiver
else: else:
name = gajim.contacts.get_first_contact_from_jid( 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 += gtkgui_helpers.escape_for_pango_markup(name)
text += '\n<b>' + _('Size: ') + '</b>' text += '\n<b>' + _('Size: ') + '</b>'
text += helpers.convert_bytes(file_props['size']) text += helpers.convert_bytes(file_props['size'])

View file

@ -283,7 +283,8 @@ class VcardWindow:
def fill_jabber_page(self): def fill_jabber_page(self):
tooltips = gtk.Tooltips() 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) self.xml.get_widget('jid_label').set_text(self.contact.jid)
uf_sub = helpers.get_uf_sub(self.contact.sub) uf_sub = helpers.get_uf_sub(self.contact.sub)
self.xml.get_widget('subscription_label').set_text(uf_sub) self.xml.get_widget('subscription_label').set_text(uf_sub)