Author: asterix Date: 2009-05-01 19:55:23 +0200 (Fri, 01 May 2009) New Revision: 11266
Modified: branches/gajim_0.12/src/common/caps.py branches/gajim_0.12/src/common/config.py branches/gajim_0.12/src/common/connection.py branches/gajim_0.12/src/common/connection_handlers.py branches/gajim_0.12/src/common/xmpp/idlequeue.py branches/gajim_0.12/src/common/xmpp/transports_nb.py branches/gajim_0.12/src/common/zeroconf/client_zeroconf.py branches/gajim_0.12/src/dialogs.py branches/gajim_0.12/src/gajim.py branches/gajim_0.12/src/message_control.py branches/gajim_0.12/src/music_track_listener.py branches/gajim_0.12/src/roster_window.py Log: import bugfixes from trunk: [11238] [11244] [11249] [11250] [11251] [11254] [11257] [11258] [11260] [11261] [11264] Fixes #4818 #4980 #4868 #4643
Modified: branches/gajim_0.12/src/common/caps.py =================================================================== --- branches/gajim_0.12/src/common/caps.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/common/caps.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -229,7 +229,11 @@ # for disco... so that disco will learn how to interpret # these caps pm_ctrl = None - jid = helpers.get_full_jid_from_iq(presence) + try: + jid = helpers.get_full_jid_from_iq(presence) + except: + # Bad jid + return contact = gajim.contacts.get_contact_from_full_jid(self.name, jid) if contact is None: room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
Modified: branches/gajim_0.12/src/common/config.py =================================================================== --- branches/gajim_0.12/src/common/config.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/common/config.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -304,11 +304,13 @@ 'no_log_for': [ opt_str, '' ], 'minimized_gc': [ opt_str, '' ], 'attached_gpg_keys': [ opt_str, '' ], - 'keep_alives_enabled': [ opt_bool, True], + 'keep_alives_enabled': [ opt_bool, True, _('Whitespace sent after inactivity')], + 'ping_alives_enabled': [ opt_bool, True, _('XMPP ping sent after inactivity')], # send keepalive every N seconds of inactivity 'keep_alive_every_foo_secs': [ opt_int, 55 ], - 'time_for_keep_alive_answer': [ opt_int, 30, _('How many seconds to wait for the answer of keepalive packet before we try to reconnect.') ], - # try for 2 minutes before giving up (aka. timeout after those seconds) + 'ping_alive_every_foo_secs': [ opt_int, 120 ], + 'time_for_ping_alive_answer': [ opt_int, 60, _('How many seconds to wait for the answer of ping alive packet before we try to reconnect.') ], + # try for 1 minutes before giving up (aka. timeout after those seconds) 'try_connecting_for_foo_secs': [ opt_int, 60 ], 'http_auth': [opt_str, 'ask'], # yes, no, ask 'dont_ack_subscription': [opt_bool, False, _('Jabberd2 workaround')],
Modified: branches/gajim_0.12/src/common/connection.py =================================================================== --- branches/gajim_0.12/src/common/connection.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/common/connection.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -146,9 +146,15 @@ 'hostname': socket.gethostname() }) if gajim.config.get_per('accounts', self.name, 'keep_alives_enabled'): - self.keepalives = gajim.config.get_per('accounts', self.name,'keep_alive_every_foo_secs') + self.keepalives = gajim.config.get_per('accounts', self.name, + 'keep_alive_every_foo_secs') else: self.keepalives = 0 + if gajim.config.get_per('accounts', self.name, 'ping_alives_enabled'): + self.pingalives = gajim.config.get_per('accounts', self.name, + 'ping_alive_every_foo_secs') + else: + self.pingalives = 0 self.privacy_rules_supported = False self.blocked_list = [] self.blocked_contacts = [] @@ -760,6 +766,11 @@ return common.xmpp.features_nb.getPrivacyLists(self.connection)
+ def send_keepalive(self): + # nothing received for the last foo seconds + if self.connection: + self.connection.send(' ') + def sendPing(self, pingTo=None): '''Send XMPP Ping (XEP-0199) request. If pingTo is not set, ping is sent to server to detect connection failure at application level.''' @@ -787,8 +798,8 @@ self.connection.SendAndCallForResponse(iq, _on_response) else: self.connection.send(iq) - gajim.idlequeue.set_alarm(self.check_keepalive, gajim.config.get_per( - 'accounts', self.name, 'time_for_keep_alive_answer')) + gajim.idlequeue.set_alarm(self.check_pingalive, gajim.config.get_per( + 'accounts', self.name, 'time_for_ping_alive_answer'))
def get_active_default_lists(self): if not self.connection: @@ -978,7 +989,8 @@ self.connection = con if not self.connection: return - self.connection.set_send_timeout(self.keepalives, self.sendPing) + self.connection.set_send_timeout(self.keepalives, self.send_keepalive) + self.connection.set_send_timeout2(self.pingalives, self.sendPing) self.connection.onreceive(None) iq = common.xmpp.Iq('get', common.xmpp.NS_PRIVACY, xmlns = '') id = self.connection.getAnID() @@ -1798,7 +1810,7 @@ c.setTagData('reason', reason) self.connection.send(message)
- def check_keepalive(self): + def check_pingalive(self): if self.awaiting_xmpp_ping_id: # We haven't got the pong in time, disco and reconnect self._disconnectedReconnCB()
Modified: branches/gajim_0.12/src/common/connection_handlers.py =================================================================== --- branches/gajim_0.12/src/common/connection_handlers.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/common/connection_handlers.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -109,13 +109,13 @@ for file_props in self.files_props.values(): if self.is_transfer_stopped(file_props): continue - receiver_jid = unicode(file_props['receiver']).split('/')[0] - if contact.jid == receiver_jid: + receiver_jid = unicode(file_props['receiver']) + if contact.get_full_jid() == receiver_jid: file_props['error'] = -5 self.remove_transfer(file_props) self.dispatch('FILE_REQUEST_ERROR', (contact.jid, file_props, '')) - sender_jid = unicode(file_props['sender']).split('/')[0] - if contact.jid == sender_jid: + sender_jid = unicode(file_props['sender']) + if contact.get_full_jid() == sender_jid: file_props['error'] = -3 self.remove_transfer(file_props)
@@ -1975,7 +1975,7 @@ try: who = helpers.get_full_jid_from_iq(prs) except Exception: - if prs.getTag('error').getTag('jid-malformed'): + if prs.getTag('error') and prs.getTag('error').getTag('jid-malformed'): # wrong jid, we probably tried to change our nick in a room to a non # valid one who = str(prs.getFrom())
Modified: branches/gajim_0.12/src/common/xmpp/idlequeue.py =================================================================== --- branches/gajim_0.12/src/common/xmpp/idlequeue.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/common/xmpp/idlequeue.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -43,6 +43,9 @@ # when there is a timeout it executes obj.read_timeout() # timeout is not removed automatically! + # {fd1: {timeout1: func1, timeout2: func2}} + # timout are unique (timeout1 must be != timeout2) + # If func1 is None, read_time function is called self.read_timeouts = {} # cb, which are executed after XX sec., alarms are removed automatically @@ -52,10 +55,16 @@ def init_idle(self): self.selector = select.poll() - def remove_timeout(self, fd): + def remove_timeout(self, fd, timeout=None): if fd in self.read_timeouts: - del(self.read_timeouts[fd]) - + if timeout: + if timeout in self.read_timeouts[fd]: + del(self.read_timeouts[fd][timeout]) + if len(self.read_timeouts[fd]) == 0: + del(self.read_timeouts[fd]) + else: + del(self.read_timeouts[fd]) + def set_alarm(self, alarm_cb, seconds): ''' set up a new alarm, to be called after alarm_cb sec. ''' alarm_time = self.current_time() + seconds @@ -65,21 +74,30 @@ else: self.alarms[alarm_time] = [alarm_cb] - def set_read_timeout(self, fd, seconds): + def set_read_timeout(self, fd, seconds, func=None): ''' set a new timeout, if it is not removed after 'seconds', - then obj.read_timeout() will be called ''' + then func or obj.read_timeout() will be called ''' timeout = self.current_time() + seconds - self.read_timeouts[fd] = timeout - + if fd in self.read_timeouts: + self.read_timeouts[fd][timeout] = func + else: + self.read_timeouts[fd] = {timeout: func} + def check_time_events(self): current_time = self.current_time() - for fd, timeout in self.read_timeouts.items(): - if timeout > current_time: + for fd, timeouts in self.read_timeouts.items(): + if fd not in self.queue: + self.remove_timeout(fd) continue - if fd in self.queue: - self.queue[fd].read_timeout() - else: - self.remove_timeout(fd) + for timeout, func in timeouts.items(): + if timeout > current_time: + continue + if func: + func() + else: + self.queue[fd].read_timeout() + self.remove_timeout(fd, timeout) + times = self.alarms.keys() for alarm_time in times: if alarm_time > current_time: @@ -220,4 +238,4 @@ self.check_time_events() return True
-# vim: se ts=3: \ No newline at end of file +# vim: se ts=3:
Modified: branches/gajim_0.12/src/common/xmpp/transports_nb.py =================================================================== --- branches/gajim_0.12/src/common/xmpp/transports_nb.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/common/xmpp/transports_nb.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -243,8 +243,9 @@ IdleObject.__init__(self) PlugIn.__init__(self) self.DBG_LINE='socket' - self._exported_methods=[self.send, self.disconnect, self.onreceive, self.set_send_timeout, - self.start_disconnect, self.set_timeout, self.remove_timeout] + self._exported_methods=[self.send, self.disconnect, self.onreceive, + self.set_send_timeout, self.set_send_timeout2, self.start_disconnect, + self.set_timeout, self.remove_timeout] self._server = server self._hostfqdn = server[0] self.on_connect = on_connect @@ -267,9 +268,11 @@ # time to wait for SOME stanza to come and then send keepalive self.sendtimeout = 0 + self.sendtimeout2 = 0 # in case we want to something different than sending keepalives self.on_timeout = None + self.on_timeout2 = None # writable, readable - keep state of the last pluged flags # This prevents replug of same object with the same flags @@ -288,7 +291,7 @@ if self.connect(self._server) is False: return False return True - + def read_timeout(self): if self.state == 0: self.idlequeue.unplug_idle(self.fd) @@ -299,6 +302,11 @@ self.on_timeout() self.renew_send_timeout()
+ def read_timeout2(self): + if self.on_timeout2: + self.on_timeout2() + self.renew_send_timeout2() + def connect(self,server=None, proxy = None, secure = None): ''' Try to establish connection. ''' if not server: @@ -408,6 +416,10 @@ def set_timeout(self, timeout): if self.state >= 0 and self.fd > 0: self.idlequeue.set_read_timeout(self.fd, timeout) + + def set_timeout2(self, timeout2): + if self.state >= 0 and self.fd > 0: + self.idlequeue.set_read_timeout(self.fd, timeout2, self.read_timeout2) def remove_timeout(self): if self.fd: @@ -493,7 +505,9 @@ return
# we have received some bites, stop the timeout! + self.remove_timeout() self.renew_send_timeout() + self.renew_send_timeout2() if self.on_receive: if received.strip(): log.info("Got: %s", received) @@ -643,13 +657,22 @@ self.on_timeout = on_timeout else: self.on_timeout = None - + + def set_send_timeout2(self, timeout2, on_timeout2): + self.sendtimeout2 = timeout2 + if self.sendtimeout2 > 0: + self.on_timeout2 = on_timeout2 + else: + self.on_timeout2 = None + def renew_send_timeout(self): if self.on_timeout and self.sendtimeout > 0: self.set_timeout(self.sendtimeout) - else: - self.remove_timeout() - + + def renew_send_timeout2(self): + if self.on_timeout2 and self.sendtimeout2 > 0: + self.set_timeout2(self.sendtimeout2) + def getHost(self): ''' Return the 'host' value that is connection is [will be] made to.''' return self._server[0]
Modified: branches/gajim_0.12/src/common/zeroconf/client_zeroconf.py =================================================================== --- branches/gajim_0.12/src/common/zeroconf/client_zeroconf.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/common/zeroconf/client_zeroconf.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -698,8 +698,9 @@ # look for hashed connections if to in self.recipient_to_hash: conn = self.connections[self.recipient_to_hash[to]] - id = conn.Dispatcher.getAnID() - stanza.setID(id) + if not stanza.getID(): + id_ = conn.Dispatcher.getAnID() + stanza.setID(id_) if conn.add_stanza(stanza, is_message): if on_ok: on_ok() @@ -709,15 +710,17 @@ hash = self.ip_to_hash[item['address']] if self.hash_to_port[hash] == item['port']: conn = self.connections[hash] - id = conn.Dispatcher.getAnID() - stanza.setID(id) + if not stanza.getID(): + id_ = conn.Dispatcher.getAnID() + stanza.setID(id_) if conn.add_stanza(stanza, is_message): if on_ok: on_ok() return id
# otherwise open new connection - stanza.setID('zero') + if not stanza.getID(): + stanza.setID('zero') P2PClient(None, item['address'], item['port'], self, [(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
Modified: branches/gajim_0.12/src/dialogs.py =================================================================== --- branches/gajim_0.12/src/dialogs.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/dialogs.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -2426,13 +2426,13 @@ self.tagIn = buffer.create_tag('incoming') color = gajim.config.get('inmsgcolor') self.tagIn.set_property('foreground', color) - self.tagInComment = buffer_.create_tag('in_comment') + self.tagInComment = buffer.create_tag('in_comment') self.tagInComment.set_property('foreground', color)
self.tagOut = buffer.create_tag('outgoing') color = gajim.config.get('outmsgcolor') self.tagOut.set_property('foreground', color) - self.tagOutComment = buffer_.create_tag('out_comment') + self.tagOutComment = buffer.create_tag('out_comment') self.tagOutComment.set_property('foreground', color)
self.enabled = False
Modified: branches/gajim_0.12/src/gajim.py =================================================================== --- branches/gajim_0.12/src/gajim.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/gajim.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -424,8 +424,8 @@ # delete pid file on normal exit if os.path.exists(pid_filename): os.remove(pid_filename) - # Save config - gajim.interface.save_config() + # Shutdown GUI and save config + gajim.interface.roster.prepare_quit() if sys.platform == 'darwin': try: import osx @@ -3486,6 +3486,7 @@ except Exception: pass gobject.timeout_add_seconds(5, remote_init) + self.create_ipython_window()
if __name__ == '__main__': def sigint_cb(num, stack):
Modified: branches/gajim_0.12/src/message_control.py =================================================================== --- branches/gajim_0.12/src/message_control.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/message_control.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -179,7 +179,10 @@ jid += '/' + self.resource
if not sess: - sess = conn.make_new_session(jid) + if self.type_id == TYPE_PM: + sess = conn.make_new_session(jid, type_='pm') + else: + sess = conn.make_new_session(jid)
self.set_session(sess)
Modified: branches/gajim_0.12/src/music_track_listener.py =================================================================== --- branches/gajim_0.12/src/music_track_listener.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/music_track_listener.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -130,7 +130,7 @@ return info
def _mpris_playing_changed_cb(self, playing): - if playing == 0: + if playing[0] == 0: self.emit('music-track-changed', self._last_playing_music) else: self.emit('music-track-changed', None)
Modified: branches/gajim_0.12/src/roster_window.py =================================================================== --- branches/gajim_0.12/src/roster_window.py 2009-05-01 17:07:31 UTC (rev 11265) +++ branches/gajim_0.12/src/roster_window.py 2009-05-01 17:55:23 UTC (rev 11266) @@ -2204,9 +2204,7 @@ self.on_quit_request() return True # do NOT destroy the window
- def quit_gtkgui_interface(self): - '''When we quit the gtk interface : - tell that to the core and exit gtk''' + def prepare_quit(self): msgwin_width_adjust = 0
# in case show_roster_on_start is False and roster is never shown @@ -2237,6 +2235,10 @@ self.close_all(account) if gajim.interface.systray_enabled: gajim.interface.hide_systray() + + def quit_gtkgui_interface(self): + '''When we quit the gtk interface : exit gtk''' + self.prepare_quit() gtk.main_quit()
def on_quit_request(self, widget=None):