gpg key chooser dialog not blocker

This commit is contained in:
Yann Leboulanger 2008-08-08 10:26:11 +00:00
parent d290f1ea91
commit e02beb9eee
3 changed files with 66 additions and 66 deletions

View File

@ -2021,37 +2021,40 @@ class AccountsWindow:
_('There was a problem retrieving your OpenPGP secret keys.'))
return
secret_keys[_('None')] = _('None')
def on_key_selected(keyID):
if keyID is None:
return
if self.current_account == gajim.ZEROCONF_ACC_NAME:
wiget_name_ext = '2'
else:
wiget_name_ext = '1'
gpg_key_label = self.xml.get_widget('gpg_key_label' + wiget_name_ext)
gpg_name_label = self.xml.get_widget('gpg_name_label' + wiget_name_ext)
use_gpg_agent_checkbutton = self.xml.get_widget(
'use_gpg_agent_checkbutton' + wiget_name_ext)
if keyID[0] == _('None'):
gpg_key_label.set_text(_('No key selected'))
gpg_name_label.set_text('')
use_gpg_agent_checkbutton.set_sensitive(False)
if self.option_changed('keyid', ''):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'keyname',
'')
gajim.config.set_per('accounts', self.current_account, 'keyid', '')
else:
gpg_key_label.set_text(keyID[0])
gpg_name_label.set_text(keyID[1])
use_gpg_agent_checkbutton.set_sensitive(True)
if self.option_changed('keyid', keyID[0]):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'keyname',
keyID[1])
gajim.config.set_per('accounts', self.current_account, 'keyid',
keyID[0])
instance = dialogs.ChooseGPGKeyDialog(_('OpenPGP Key Selection'),
_('Choose your OpenPGP key'), secret_keys)
keyID = instance.run()
if keyID is None:
return
if self.current_account == gajim.ZEROCONF_ACC_NAME:
wiget_name_ext = '2'
else:
wiget_name_ext = '1'
gpg_key_label = self.xml.get_widget('gpg_key_label' + wiget_name_ext)
gpg_name_label = self.xml.get_widget('gpg_name_label' + wiget_name_ext)
use_gpg_agent_checkbutton = self.xml.get_widget(
'use_gpg_agent_checkbutton' + wiget_name_ext)
if keyID[0] == _('None'):
gpg_key_label.set_text(_('No key selected'))
gpg_name_label.set_text('')
use_gpg_agent_checkbutton.set_sensitive(False)
if self.option_changed('keyid', ''):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'keyname', '')
gajim.config.set_per('accounts', self.current_account, 'keyid', '')
else:
gpg_key_label.set_text(keyID[0])
gpg_name_label.set_text(keyID[1])
use_gpg_agent_checkbutton.set_sensitive(True)
if self.option_changed('keyid', keyID[0]):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'keyname',
keyID[1])
gajim.config.set_per('accounts', self.current_account, 'keyid',
keyID[0])
_('Choose your OpenPGP key'), secret_keys, on_key_selected)
def on_use_gpg_agent_checkbutton_toggled(self, widget):
if self.current_account == gajim.ZEROCONF_ACC_NAME:

View File

@ -256,8 +256,10 @@ class PassphraseDialog:
class ChooseGPGKeyDialog:
'''Class for GPG key dialog'''
def __init__(self, title_text, prompt_text, secret_keys, selected = None):
#list : {keyID: userName, ...}
def __init__(self, title_text, prompt_text, secret_keys, on_response,
selected=None):
'''secret_keys : {keyID: userName, ...}'''
self.on_response = on_response
xml = gtkgui_helpers.get_glade('choose_gpg_key_dialog.glade')
self.window = xml.get_widget('choose_gpg_key_dialog')
self.window.set_title(title_text)
@ -279,6 +281,7 @@ class ChooseGPGKeyDialog:
col.set_sort_column_id(1)
self.keys_treeview.set_search_column(1)
self.fill_tree(secret_keys, selected)
self.window.connect('response', self.on_dialog_response)
self.window.show_all()
def sort_keys(self, model, iter1, iter2):
@ -292,17 +295,16 @@ class ChooseGPGKeyDialog:
return -1
return 1
def run(self):
rep = self.window.run()
def on_dialog_response(self, dialog, response):
selection = self.keys_treeview.get_selection()
(model, iter) = selection.get_selected()
if iter and rep == gtk.RESPONSE_OK:
if iter and response == gtk.RESPONSE_OK:
keyID = [ model[iter][0].decode('utf-8'),
model[iter][1].decode('utf-8') ]
else:
keyID = None
self.on_response(keyID)
self.window.destroy()
return keyID
def fill_tree(self, list, selected):
model = self.keys_treeview.get_model()
@ -1583,12 +1585,6 @@ class DubbleInputDialog:
def on_cancelbutton_clicked(self, widget):
self.dialog.destroy()
def get_response(self):
if self.is_modal:
response = self.dialog.run()
self.dialog.destroy()
return response
class SubscriptionRequestWindow:
def __init__(self, jid, text, account, user_nick=None):
xml = gtkgui_helpers.get_glade('subscription_request_window.glade')

View File

@ -2747,41 +2747,42 @@ class RosterWindow:
attached_keys = gajim.config.get_per('accounts', account,
'attached_gpg_keys').split()
keys = {}
#GPG Key
keyID = _('None')
for i in xrange(len(attached_keys)/2):
keys[attached_keys[2*i]] = attached_keys[2*i+1]
if attached_keys[2*i] == contact.jid:
keyID = attached_keys[2*i+1]
public_keys = gajim.connections[account].ask_gpg_keys()
#GPG Key
public_keys[_('None')] = _('None')
instance = dialogs.ChooseGPGKeyDialog(_('Assign OpenPGP Key'),
_('Select a key to apply to the contact'), public_keys, keyID)
keyID = instance.run()
if keyID is None:
return
#GPG Key
if keyID[0] == _('None'):
if contact.jid in keys:
del keys[contact.jid]
keyID = ''
else:
keyID = keyID[0]
keys[contact.jid] = keyID
ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid, account)
if ctrl:
ctrl.update_ui()
def on_key_selected(keyID):
if keyID is None:
return
if keyID[0] == _('None'):
if contact.jid in keys:
del keys[contact.jid]
keyID = ''
else:
keyID = keyID[0]
keys[contact.jid] = keyID
keys_str = ''
for jid in keys:
keys_str += jid + ' ' + keys[jid] + ' '
gajim.config.set_per('accounts', account, 'attached_gpg_keys', keys_str)
for u in gajim.contacts.get_contacts(account, contact.jid):
u.keyID = helpers.prepare_and_validate_gpg_keyID(account,
ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid, account)
if ctrl:
ctrl.update_ui()
keys_str = ''
for jid in keys:
keys_str += jid + ' ' + keys[jid] + ' '
gajim.config.set_per('accounts', account, 'attached_gpg_keys',
keys_str)
for u in gajim.contacts.get_contacts(account, contact.jid):
u.keyID = helpers.prepare_and_validate_gpg_keyID(account,
contact.jid, keyID)
instance = dialogs.ChooseGPGKeyDialog(_('Assign OpenPGP Key'),
_('Select a key to apply to the contact'), public_keys,
on_key_selected, selected=keyID)
def on_set_custom_avatar_activate(self, widget, contact, account):
def on_ok(widget, path_to_file):
filesize = os.path.getsize(path_to_file) # in bytes