From 1c9c217cdce90bce3935c2567525bb24e3dddea8 Mon Sep 17 00:00:00 2001 From: Stefan Bethge Date: Mon, 2 Oct 2006 12:16:13 +0000 Subject: [PATCH] add gpg items to zeroconf modify account dialog, gpg should work between gajim clients --- data/glade/zeroconf_properties_window.glade | 375 ++++++++++++++------ src/config.py | 111 +++++- 2 files changed, 369 insertions(+), 117 deletions(-) diff --git a/data/glade/zeroconf_properties_window.glade b/data/glade/zeroconf_properties_window.glade index e8f596a63..49c7e887b 100644 --- a/data/glade/zeroconf_properties_window.glade +++ b/data/glade/zeroconf_properties_window.glade @@ -106,42 +106,6 @@ False - - - False - True - - - - - - True - General - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - 6 - True - False - 6 @@ -152,6 +116,8 @@ True + If the default port that is used for incoming messages is unfitting for your setup you can select another one here. +You might consider to change possible firewall settings. True Use custom port: True @@ -185,14 +151,14 @@ 0 False - True + False - 0 + 10 False - False + True @@ -203,11 +169,11 @@ - + True - Connection + General False - False + True GTK_JUSTIFY_LEFT False False @@ -229,61 +195,12 @@ 6 True - 4 + 6 2 False - 4 + 5 2 - - - True - E-Mail: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 3 - 4 - fill - - - - - - - True - True - True - True - 0 - - True - - False - - - 1 - 2 - 3 - 4 - - - - True @@ -299,8 +216,8 @@ 1 2 - 2 - 3 + 4 + 5 @@ -326,13 +243,62 @@ 0 1 - 2 - 3 + 4 + 5 fill + + + True + E-Mail: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 5 + 6 + fill + + + + + + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 5 + 6 + + + + True @@ -354,8 +320,8 @@ 0 1 - 1 - 2 + 3 + 4 fill @@ -376,8 +342,8 @@ 1 2 - 1 - 2 + 3 + 4 @@ -403,8 +369,8 @@ 0 1 - 0 - 1 + 2 + 3 fill @@ -425,9 +391,210 @@ 1 2 + 2 + 3 + + + + + + + True + <b>Personal Information</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 2 + 1 + 2 + fill + + + + + + + True + False + 5 + + + + True + <b>OpenPGP</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + False + 5 + + + + True + No key selected + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + True + True + + + + + + True + True + Choose _Key... + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + False + + + + + 0 + True + True + + + + + + True + False + 0 + + + + True + If checked, Gajim will store the password in ~/.gajim/config with 'read' permission only for you + True + Save _passphrase (insecure) + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + False + False + + + + + + True + True + True + False + 0 + + True + * + False + + + 0 + True + True + + + + + 0 + True + True + + + + + 0 + 2 0 1 - + fill diff --git a/src/config.py b/src/config.py index 897907c31..d2b7a05d6 100644 --- a/src/config.py +++ b/src/config.py @@ -4,6 +4,7 @@ ## Copyright (C) 2005-2006 Nikos Kouremenos ## Copyright (C) 2005 Dimitur Kirov ## Copyright (C) 2003-2005 Vincent Hanquez +## Copyright (C) 2006 Stefan Bethge ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published @@ -1357,7 +1358,7 @@ class AccountModificationWindow: config['custom_host'] = self.xml.get_widget( 'custom_host_entry').get_text().decode('utf-8') - # update in case the name changed to local accounts name + # update in case the name was changed to local account's name config['is_zeroconf'] = False config['keyname'] = self.xml.get_widget('gpg_name_label').get_text().decode('utf-8') @@ -3112,6 +3113,13 @@ class ZeroconfPropertiesWindow: self.window.set_transient_for(gajim.interface.roster.window) self.xml.signal_autoconnect(self) + self.init_account() + self.init_account_gpg() + + self.xml.get_widget('save_button').grab_focus() + self.window.show_all() + + def init_account(self): st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'autoconnect') if st: self.xml.get_widget('autoconnect_checkbutton').set_active(st) @@ -3156,8 +3164,27 @@ class ZeroconfPropertiesWindow: if not st: gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port', '5298') - self.xml.get_widget('save_button').grab_focus() - self.window.show_all() + def init_account_gpg(self): + keyid = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'keyid') + keyname = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'keyname') + savegpgpass = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,'savegpgpass') + + if not keyid or not gajim.config.get('usegpg'): + return + + self.xml.get_widget('gpg_key_label').set_text(keyid) + self.xml.get_widget('gpg_name_label').set_text(keyname) + gpg_save_password_checkbutton = \ + self.xml.get_widget('gpg_save_password_checkbutton') + gpg_save_password_checkbutton.set_sensitive(True) + gpg_save_password_checkbutton.set_active(savegpgpass) + + if savegpgpass: + entry = self.xml.get_widget('gpg_password_entry') + entry.set_sensitive(True) + gpgpassword = gajim.config.get_per('accounts', + gajim.ZEROCONF_ACC_NAME, 'gpgpassword') + entry.set_text(gpgpassword) def on_zeroconf_properties_window_destroy(self, widget): #close window @@ -3172,33 +3199,35 @@ class ZeroconfPropertiesWindow: self.window.destroy() def on_save_button_clicked(self, widget): + config = {} + st = self.xml.get_widget('autoconnect_checkbutton').get_active() - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'autoconnect', st) + config['autoconnect'] = st list_no_log_for = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'no_log_for').split() if gajim.ZEROCONF_ACC_NAME in list_no_log_for: list_no_log_for.remove(gajim.ZEROCONF_ACC_NAME) if not self.xml.get_widget('log_history_checkbutton').get_active(): list_no_log_for.append(gajim.ZEROCONF_ACC_NAME) - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'no_log_for', ' '.join(list_no_log_for)) + config['no_log_for'] = ' '.join(list_no_log_for) st = self.xml.get_widget('sync_with_global_status_checkbutton').get_active() - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'sync_with_global_status', st) + config['sync_with_global_status'] = st st = self.xml.get_widget('first_name_entry').get_text() - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_first_name', st) + config['zeroconf_first_name'] = st st = self.xml.get_widget('last_name_entry').get_text() - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_last_name', st) + config['zeroconf_last_name'] = st st = self.xml.get_widget('jabber_id_entry').get_text() - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_jabber_id', st) + config['zeroconf_jabber_id'] = st st = self.xml.get_widget('email_entry').get_text() - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'zeroconf_email', st) + config['zeroconf_email'] = st use_custom_port = self.xml.get_widget('custom_port_checkbutton').get_active() - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'use_custom_host', use_custom_port) + config['use_custom_host'] = use_custom_port old_port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port') if use_custom_port: @@ -3206,16 +3235,72 @@ class ZeroconfPropertiesWindow: else: port = '5298' - gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'custom_port', port) - # force restart of listener (because port has changed) if port != old_port: use_custom_port = True else: use_custom_port = False + + config['custom_port'] = port + + config['keyname'] = self.xml.get_widget('gpg_name_label').get_text().decode('utf-8') + if config['keyname'] == '': #no key selected + config['keyid'] = '' + config['savegpgpass'] = False + config['gpgpassword'] = '' + else: + config['keyid'] = self.xml.get_widget('gpg_key_label').get_text().decode('utf-8') + config['savegpgpass'] = self.xml.get_widget( + 'gpg_save_password_checkbutton').get_active() + config['gpgpassword'] = self.xml.get_widget('gpg_password_entry' + ).get_text().decode('utf-8') + + for opt in config: + gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, opt, config[opt]) if gajim.connections.has_key(gajim.ZEROCONF_ACC_NAME): gajim.connections[gajim.ZEROCONF_ACC_NAME].reconnect(use_custom_port) self.window.destroy() + + def on_gpg_choose_button_clicked(self, widget, data = None): + if gajim.connections.has_key(gajim.ZEROCONF_ACC_NAME): + secret_keys = gajim.connections[gajim.ZEROCONF_ACC_NAME].ask_gpg_secrete_keys() + # self.account is None and/or gajim.connections is {} + else: + from common import GnuPG + if GnuPG.USE_GPG: + secret_keys = GnuPG.GnuPG().get_secret_keys() + else: + secret_keys = [] + if not secret_keys: + dialogs.ErrorDialog(_('Failed to get secret keys'), + _('There was a problem retrieving your OpenPGP secret keys.')) + return + secret_keys[_('None')] = _('None') + instance = dialogs.ChooseGPGKeyDialog(_('OpenPGP Key Selection'), + _('Choose your OpenPGP key'), secret_keys) + keyID = instance.run() + if keyID is None: + return + checkbutton = self.xml.get_widget('gpg_save_password_checkbutton') + gpg_key_label = self.xml.get_widget('gpg_key_label') + gpg_name_label = self.xml.get_widget('gpg_name_label') + if keyID[0] == _('None'): + gpg_key_label.set_text(_('No key selected')) + gpg_name_label.set_text('') + checkbutton.set_sensitive(False) + self.xml.get_widget('gpg_password_entry').set_sensitive(False) + else: + gpg_key_label.set_text(keyID[0]) + gpg_name_label.set_text(keyID[1]) + checkbutton.set_sensitive(True) + checkbutton.set_active(False) + self.xml.get_widget('gpg_password_entry').set_text('') + + def on_gpg_save_password_checkbutton_toggled(self, widget): + st = widget.get_active() + w = self.xml.get_widget('gpg_password_entry') + w.set_sensitive(bool(st)) +# w.set_text = ''