vcard window now uses label instead of entry

new profile_window to edit our vcard. For #2381
This commit is contained in:
Yann Leboulanger 2006-09-08 17:35:28 +00:00
parent 56f248c287
commit a678c35b3f
4 changed files with 793 additions and 1052 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1356,7 +1356,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
user_nick = msg.getTagData('nick') user_nick = msg.getTagData('nick')
if not user_nick: if not user_nick:
user_nick = '' user_nick = ''
if encTag and GnuPG.USE_GPG: if encTag and GnuPG.USE_GPG:
#decrypt #decrypt
encmsg = encTag.getData() encmsg = encTag.getData()

View File

@ -185,7 +185,7 @@ parser = optparser.OptionsParser(config_filename)
import roster_window import roster_window
import systray import systray
import vcard import profile_window
import config import config
class GlibIdleQueue(idlequeue.IdleQueue): class GlibIdleQueue(idlequeue.IdleQueue):
@ -339,9 +339,9 @@ class Interface:
def edit_own_details(self, account): def edit_own_details(self, account):
jid = gajim.get_jid_from_account(account) jid = gajim.get_jid_from_account(account)
if not self.instances[account]['infos'].has_key(jid): if not self.instances[account].has_key('profile'):
self.instances[account]['infos'][jid] = \ self.instances[account]['profile'] = \
vcard.VcardWindow(jid, account, True) profile_window.ProfileWindow(account)
gajim.connections[account].request_vcard(jid) gajim.connections[account].request_vcard(jid)
def handle_event_notify(self, account, array): def handle_event_notify(self, account, array):
@ -764,8 +764,8 @@ class Interface:
nick = array['NICKNAME'] nick = array['NICKNAME']
if nick: if nick:
gajim.nicks[account] = nick gajim.nicks[account] = nick
if self.instances[account]['infos'].has_key(array['jid']): if self.instances[account].has_key('profile'):
win = self.instances[account]['infos'][array['jid']] win = self.instances[account]['profile']
win.set_values(array) win.set_values(array)
if account in self.show_vcard_when_connect: if account in self.show_vcard_when_connect:
self.show_vcard_when_connect.remove(account) self.show_vcard_when_connect.remove(account)

View File

@ -57,55 +57,32 @@ def get_avatar_pixbuf_encoded_mime(photo):
class VcardWindow: class VcardWindow:
'''Class for contact's information window''' '''Class for contact's information window'''
def __init__(self, contact, account, vcard = False, is_fake = False): def __init__(self, contact, account, is_fake = False):
# the contact variable is the jid if vcard is true # the contact variable is the jid if vcard is true
self.xml = gtkgui_helpers.get_glade('vcard_information_window.glade') self.xml = gtkgui_helpers.get_glade('vcard_information_window.glade')
self.window = self.xml.get_widget('vcard_information_window') self.window = self.xml.get_widget('vcard_information_window')
self.publish_button = self.xml.get_widget('publish_button') self.contact = contact
self.retrieve_button = self.xml.get_widget('retrieve_button')
self.nickname_entry = self.xml.get_widget('nickname_entry')
if not vcard: # Maybe gc_vcard ?
self.nickname_entry.set_property('editable', False)
self.publish_button.set_no_show_all(True)
self.retrieve_button.set_no_show_all(True)
self.contact = contact # don't use it if vcard is true
self.account = account self.account = account
self.vcard = vcard
self.is_fake = is_fake self.is_fake = is_fake
self.avatar_mime_type = None self.avatar_mime_type = None
self.avatar_encoded = None self.avatar_encoded = None
self.avatar_save_as_id = None self.avatar_save_as_id = None
if vcard: # we view/edit our own vcard self.fill_jabber_page()
self.jid = contact
# remove Jabber tab & show publish/retrieve/close/set_avatar buttons button = self.xml.get_widget('set_avatar_button')
# and make entries and textview editable button.set_no_show_all(True)
self.change_to_vcard() button.connect('clicked',
else: # we see someone else's vcard gtkgui_helpers.on_avatar_save_as_menuitem_activate,
self.publish_button.hide() self.contact.jid, self.account, self.contact.name + '.jpeg')
self.retrieve_button.hide()
self.jid = contact.jid
self.fill_jabber_page()
# if we are editing our own vcard publish button should publish
# vcard data we have typed including nickname, it's why we connect only
# here (when we see someone else's vcard)
self.nickname_entry.connect('focus-out-event',
self.on_nickname_entry_focus_out_event)
button = self.xml.get_widget('set_avatar_button')
button.set_no_show_all(True)
button.connect('clicked',
gtkgui_helpers.on_avatar_save_as_menuitem_activate,
self.jid, self.account, self.contact.name + '.jpeg')
self.xml.signal_autoconnect(self) self.xml.signal_autoconnect(self)
self.window.show_all() self.window.show_all()
def on_vcard_information_window_destroy(self, widget): def on_vcard_information_window_destroy(self, widget):
del gajim.interface.instances[self.account]['infos'][self.jid] del gajim.interface.instances[self.account]['infos'][self.contact.jid]
def on_vcard_information_window_key_press_event(self, widget, event): def on_vcard_information_window_key_press_event(self, widget, event):
if event.keyval == gtk.keysyms.Escape: if event.keyval == gtk.keysyms.Escape:
@ -126,115 +103,16 @@ class VcardWindow:
if oldlog != log: if oldlog != log:
gajim.config.set_per('accounts', self.account, 'no_log_for', gajim.config.set_per('accounts', self.account, 'no_log_for',
' '.join(no_log_for)) ' '.join(no_log_for))
def on_nickname_entry_focus_out_event(self, widget, event):
'''Save contact information and update
the roster item on the Jabber server'''
new_name = self.nickname_entry.get_text().decode('utf-8')
# update contact.name with new nickname if that is not ''
if new_name != self.contact.name and new_name != '':
self.contact.name = new_name
# update roster model
model = gajim.interface.roster.tree.get_model()
for iter_ in gajim.interface.roster.get_contact_iter(self.contact.jid,
self.account):
model[iter_][1] = new_name
gajim.connections[self.account].update_contact(self.contact.jid,
self.contact.name, self.contact.groups)
# update opened chat window
ctrl = gajim.interface.msg_win_mgr.get_control(self.contact.jid,
self.account)
if ctrl:
ctrl.update_ui()
win = gajim.interface.msg_win_mgr.get_window(self.contact.jid,
self.account)
win.redraw_tab(ctrl)
win.show_title()
def on_close_button_clicked(self, widget):
self.window.destroy()
def on_clear_button_clicked(self, widget):
# empty the image
path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'person.png')
self.xml.get_widget('PHOTO_image').set_from_file(path)
self.avatar_encoded = None
if self.avatar_save_as_id:
self.xml.get_widget('set_avatar_button').disconnect(
self.avatar_save_as_id)
self.avatar_save_as_id = None
def on_set_avatar_button_clicked(self, widget):
f = None
def on_ok(widget, path_to_file):
filesize = os.path.getsize(path_to_file) # in bytes
#FIXME: use messages for invalid file for 0.11
invalid_file = False
msg = ''
if os.path.isfile(path_to_file):
stat = os.stat(path_to_file)
if stat[6] == 0:
invalid_file = True
else:
invalid_file = True
if not invalid_file and filesize > 16384: # 16 kb
try:
pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file)
# get the image at 'notification size'
# and use that user did not specify in ACE crazy size
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf,
'tooltip')
except gobject.GError, msg: # unknown format
# msg should be string, not object instance
msg = str(msg)
invalid_file = True
if invalid_file:
if True: # keep identation
dialogs.ErrorDialog(_('Could not load image'), msg)
return
if filesize > 16384:
if scaled_pixbuf:
path_to_file = os.path.join(gajim.TMP,
'avatar_scaled.png')
scaled_pixbuf.save(path_to_file, 'png')
self.dialog.destroy()
fd = open(path_to_file, 'rb')
data = fd.read()
pixbuf = gtkgui_helpers.get_pixbuf_from_data(data)
# rescale it
pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'vcard')
image = self.xml.get_widget('PHOTO_image')
image.set_from_pixbuf(pixbuf)
self.avatar_encoded = base64.encodestring(data)
# returns None if unknown type
self.avatar_mime_type = mimetypes.guess_type(path_to_file)[0]
self.dialog = dialogs.ImageChooserDialog(on_response_ok = on_ok)
def on_PHOTO_button_press_event(self, widget, event): def on_PHOTO_button_press_event(self, widget, event):
'''If right-clicked, show popup''' '''If right-clicked, show popup'''
if event.button == 3: # right click if event.button == 3: # right click
if self.vcard:
# our own avatar
account = None
nick = gajim.config.get_per('accounts', self.account, 'name')
else:
account = self.account
nick = self.contact.name
menu = gtk.Menu() menu = gtk.Menu()
menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS)
menuitem.connect('activate', menuitem.connect('activate',
gtkgui_helpers.on_avatar_save_as_menuitem_activate, gtkgui_helpers.on_avatar_save_as_menuitem_activate,
self.jid, account, nick + '.jpeg') self.contact.jid, self.account, self.contact.name + '.jpeg')
menu.append(menuitem) menu.append(menuitem)
# show clear for own avatar
if self.vcard:
menuitem = gtk.ImageMenuItem(gtk.STOCK_CLEAR)
menuitem.connect('activate',
self.on_clear_button_clicked)
menu.append(menuitem)
menu.show_all()
menu.connect('selection-done', lambda w:w.destroy()) menu.connect('selection-done', lambda w:w.destroy())
# show the menu # show the menu
menu.show_all() menu.show_all()
@ -269,16 +147,16 @@ class VcardWindow:
if 'WORK' in entry: if 'WORK' in entry:
add_on = '_WORK' add_on = '_WORK'
for j in entry.keys(): for j in entry.keys():
self.set_value(i + add_on + '_' + j + '_entry', entry[j]) self.set_value(i + add_on + '_' + j + '_label', entry[j])
if isinstance(vcard[i], dict): if isinstance(vcard[i], dict):
for j in vcard[i].keys(): for j in vcard[i].keys():
self.set_value(i + '_' + j + '_entry', vcard[i][j]) self.set_value(i + '_' + j + '_label', vcard[i][j])
else: else:
if i == 'DESC': if i == 'DESC':
self.xml.get_widget('DESC_textview').get_buffer().set_text( self.xml.get_widget('DESC_textview').get_buffer().set_text(
vcard[i], 0) vcard[i], 0)
else: else:
self.set_value(i + '_entry', vcard[i]) self.set_value(i + '_label', vcard[i])
def set_last_status_time(self): def set_last_status_time(self):
self.fill_status_label() self.fill_status_label()
@ -365,7 +243,6 @@ class VcardWindow:
if self.contact.ask == 'subscribe': if self.contact.ask == 'subscribe':
tooltips.set_tip(eb, tooltips.set_tip(eb,
_("You are waiting contact's answer about your subscription request")) _("You are waiting contact's answer about your subscription request"))
self.nickname_entry.set_text(self.contact.name)
log = True log = True
if self.contact.jid in gajim.config.get_per('accounts', self.account, if self.contact.jid in gajim.config.get_per('accounts', self.account,
'no_log_for').split(' '): 'no_log_for').split(' '):
@ -417,124 +294,3 @@ class VcardWindow:
self.fill_status_label() self.fill_status_label()
gajim.connections[self.account].request_vcard(self.contact.jid, self.is_fake) gajim.connections[self.account].request_vcard(self.contact.jid, self.is_fake)
def add_to_vcard(self, vcard, entry, txt):
'''Add an information to the vCard dictionary'''
entries = entry.split('_')
loc = vcard
if len(entries) == 3: # We need to use lists
if not loc.has_key(entries[0]):
loc[entries[0]] = []
found = False
for e in loc[entries[0]]:
if entries[1] in e:
found = True
break
if found:
e[entries[2]] = txt
else:
loc[entries[0]].append({entries[1]: '', entries[2]: txt})
return vcard
while len(entries) > 1:
if not loc.has_key(entries[0]):
loc[entries[0]] = {}
loc = loc[entries[0]]
del entries[0]
loc[entries[0]] = txt
return vcard
def make_vcard(self):
'''make the vCard dictionary'''
entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'URL',
'TEL_HOME_NUMBER', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE', 'N_PREFIX',
'N_SUFFIX', 'ADR_HOME_STREET', 'ADR_HOME_EXTADR', 'ADR_HOME_LOCALITY',
'ADR_HOME_REGION', 'ADR_HOME_PCODE', 'ADR_HOME_CTRY', 'ORG_ORGNAME',
'ORG_ORGUNIT', 'TITLE', 'ROLE', 'TEL_WORK_NUMBER', 'EMAIL_WORK_USERID',
'ADR_WORK_STREET', 'ADR_WORK_EXTADR', 'ADR_WORK_LOCALITY',
'ADR_WORK_REGION', 'ADR_WORK_PCODE', 'ADR_WORK_CTRY']
vcard = {}
for e in entries:
txt = self.xml.get_widget(e + '_entry').get_text().decode('utf-8')
if txt != '':
vcard = self.add_to_vcard(vcard, e, txt)
# DESC textview
buff = self.xml.get_widget('DESC_textview').get_buffer()
start_iter = buff.get_start_iter()
end_iter = buff.get_end_iter()
txt = buff.get_text(start_iter, end_iter, 0)
if txt != '':
vcard['DESC'] = txt.decode('utf-8')
# Avatar
if self.avatar_encoded:
vcard['PHOTO'] = {'BINVAL': self.avatar_encoded}
if self.avatar_mime_type:
vcard['PHOTO']['TYPE'] = self.avatar_mime_type
return vcard
def on_publish_button_clicked(self, widget):
if gajim.connections[self.account].connected < 2:
dialogs.ErrorDialog(_('You are not connected to the server'),
_('Without a connection you can not publish your contact '
'information.'))
return
vcard = self.make_vcard()
nick = ''
if vcard.has_key('NICKNAME'):
nick = vcard['NICKNAME']
if nick == '':
nick = gajim.config.get_per('accounts', self.account, 'name')
gajim.nicks[self.account] = nick
gajim.connections[self.account].send_vcard(vcard)
def on_retrieve_button_clicked(self, widget):
entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'URL',
'TEL_HOME_NUMBER', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE', 'N_PREFIX',
'N_SUFFIX', 'ADR_HOME_STREET', 'ADR_HOME_EXTADR', 'ADR_HOME_LOCALITY',
'ADR_HOME_REGION', 'ADR_HOME_PCODE', 'ADR_HOME_CTRY', 'ORG_ORGNAME',
'ORG_ORGUNIT', 'TITLE', 'ROLE', 'ADR_WORK_STREET', 'ADR_WORK_EXTADR',
'ADR_WORK_LOCALITY', 'ADR_WORK_REGION', 'ADR_WORK_PCODE',
'ADR_WORK_CTRY']
if gajim.connections[self.account].connected > 1:
# clear all entries
for e in entries:
self.xml.get_widget(e + '_entry').set_text('')
self.xml.get_widget('DESC_textview').get_buffer().set_text('')
self.xml.get_widget('PHOTO_image').set_from_pixbuf(None)
if self.avatar_save_as_id:
self.xml.get_widget('set_avatar_button').disconnect(
self.avatar_save_as_id)
self.avatar_save_as_id = None
gajim.connections[self.account].request_vcard(self.jid)
else:
dialogs.ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not get your contact information.'))
def change_to_vcard(self):
self.xml.get_widget('information_notebook').remove_page(0)
self.xml.get_widget('nickname_label').set_markup(
'<b><span size="x-large">' +
_('Personal details') +
'</span></b>')
self.xml.get_widget('set_avatar_button').connect('clicked',
self.on_set_avatar_button_clicked)
self.xml.get_widget('set_avatar_button').show()
self.publish_button.show()
self.retrieve_button.show()
#make all entries editable
entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'URL',
'TEL_HOME_NUMBER', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE', 'N_PREFIX',
'N_SUFFIX', 'ADR_HOME_STREET', 'ADR_HOME_EXTADR', 'ADR_HOME_LOCALITY',
'ADR_HOME_REGION', 'ADR_HOME_PCODE', 'ADR_HOME_CTRY', 'ORG_ORGNAME',
'ORG_ORGUNIT', 'TITLE', 'ROLE', 'TEL_WORK_NUMBER', 'EMAIL_WORK_USERID',
'ADR_WORK_STREET', 'ADR_WORK_EXTADR', 'ADR_WORK_LOCALITY',
'ADR_WORK_REGION', 'ADR_WORK_PCODE', 'ADR_WORK_CTRY']
for e in entries:
self.xml.get_widget(e + '_entry').set_property('editable', True)
description_textview = self.xml.get_widget('DESC_textview')
description_textview.set_editable(True)
description_textview.set_cursor_visible(True)