From d474d149f72eab59f2d5ee808d3e0a396a899f59 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Thu, 2 Dec 2004 00:00:57 +0000 Subject: [PATCH] it is not possible to launch a dialog.run() in a timeout function, so here is a workaround to do the same thing --- plugins/gtkgui/dialogs.py | 37 ++++++++++++++++++++++++++++++++----- plugins/gtkgui/gtkgui.glade | 3 +++ plugins/gtkgui/gtkgui.py | 22 +++++++++++++++------- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/plugins/gtkgui/dialogs.py b/plugins/gtkgui/dialogs.py index 3479d2e64..3a510dbc2 100644 --- a/plugins/gtkgui/dialogs.py +++ b/plugins/gtkgui/dialogs.py @@ -217,23 +217,50 @@ class passphrase_Window: """Class for Passphrase Window""" def run(self): """Wait for Ok button to be pressed and return passphrase""" - win = self.xml.get_widget("Passphrase") - rep = win.run() + rep = self.win.run() if rep == gtk.RESPONSE_OK: msg = self.entry.get_text() else: msg = -1 - win.destroy() + self.win.destroy() return msg def on_key_pressed(self, widget, event): if event.keyval == gtk.keysyms.Return: - self.xml.get_widget("Passphrase").response(gtk.RESPONSE_OK) + if self.autoconnect: + self.on_ok_clicked(widget) + else: + self.win.response(gtk.RESPONSE_OK) + + def on_ok_clicked(self, widget): + if self.autoconnect: + self.msg = self.entry.get_text() + gtk.main_quit() - def __init__(self, txt): + def on_cancel_clicked(self, widget): + if self.autoconnect: + gtk.main_quit() + + def get_pass(self): + self.autoconnect = 0 + self.win.destroy() + return self.msg + + def delete_event(self, widget=None): + """close window""" + if self.autoconnect: + gtk.main_quit() + + def __init__(self, txt, autoconnect=0): self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Passphrase', APP) + self.win = self.xml.get_widget("Passphrase") self.entry = self.xml.get_widget("entry") + self.msg = -1 + self.autoconnect = autoconnect self.xml.get_widget("label").set_text(txt) + self.xml.signal_connect('gtk_widget_destroy', self.delete_event) + self.xml.signal_connect('on_ok_clicked', self.on_ok_clicked) + self.xml.signal_connect('on_cancel_clicked', self.on_cancel_clicked) self.xml.signal_connect('on_Passphrase_key_press_event', \ self.on_key_pressed) diff --git a/plugins/gtkgui/gtkgui.glade b/plugins/gtkgui/gtkgui.glade index 0fe39cf66..a837d06ad 100644 --- a/plugins/gtkgui/gtkgui.glade +++ b/plugins/gtkgui/gtkgui.glade @@ -8766,6 +8766,7 @@ when NOT online GDK_GRAVITY_NORTH_WEST True + @@ -8788,6 +8789,7 @@ when NOT online GTK_RELIEF_NORMAL True -6 + @@ -8802,6 +8804,7 @@ when NOT online GTK_RELIEF_NORMAL True -5 + diff --git a/plugins/gtkgui/gtkgui.py b/plugins/gtkgui/gtkgui.py index 2a7502ac1..c2754387b 100644 --- a/plugins/gtkgui/gtkgui.py +++ b/plugins/gtkgui/gtkgui.py @@ -1357,15 +1357,19 @@ class roster_Window: self.remove_user(u, account) del self.contacts[account][u.jid] - def send_status(self, account, status, txt): + def send_status(self, account, status, txt, autoconnect=0): if status != 'offline': save_pass = 0 if self.plugin.accounts[account].has_key("savepass"): save_pass = self.plugin.accounts[account]["savepass"] if not save_pass and not self.plugin.connected[account]: passphrase = '' - w = passphrase_Window('Enter your password for your account %s' % account) - passphrase = w.run() + w = passphrase_Window('Enter your password for your account %s' % account, autoconnect) + if autoconnect: + gtk.main() + passphrase = w.get_pass() + else: + passphrase = w.run() if passphrase == -1: return self.plugin.send('PASSPHRASE', account, passphrase) @@ -1382,8 +1386,12 @@ class roster_Window: passphrase = self.plugin.accounts[account]['gpgpass'] else: passphrase = '' - w = passphrase_Window('Enter your passphrase for your the GPG key of your account %s' % account) - passphrase = w.run() + w = passphrase_Window('Enter your passphrase for your the GPG key of your account %s' % account, autoconnect) + if autoconnect: + gtk.main() + passphrase = w.get_pass() + else: + passphrase = w.run() if passphrase == -1: passphrase = '' self.plugin.send('GPGPASSPHRASE', account, passphrase) @@ -2432,7 +2440,7 @@ class plugin: for a in self.accounts.keys(): if self.accounts[a].has_key('autoconnect'): if self.accounts[a]['autoconnect']: - self.roster.send_status(a, 'online', 'Online') + self.roster.send_status(a, 'online', 'Online', 1) return 0 def __init__(self, quIN, quOUT): @@ -2513,7 +2521,6 @@ class plugin: self.roster = roster_Window(self) gtk.timeout_add(100, self.read_queue) gtk.timeout_add(100, self.read_sleepy) - gtk.timeout_add(100, self.autoconnect) self.sleeper = common.sleepy.Sleepy( \ self.config['autoawaytime']*60, \ self.config['autoxatime']*60) @@ -2530,6 +2537,7 @@ class plugin: else: self.systray = systrayDummy() gtk.gdk.threads_enter() + self.autoconnect() gtk.main() gtk.gdk.threads_leave()