autoreconnect of account is ready
This commit is contained in:
parent
1ccb1e5514
commit
72393ac068
|
@ -159,6 +159,7 @@ class Config:
|
||||||
'resource': [ opt_str, 'gajim' ],
|
'resource': [ opt_str, 'gajim' ],
|
||||||
'priority': [ opt_int, 5 ],
|
'priority': [ opt_int, 5 ],
|
||||||
'autoconnect': [ opt_bool, False ],
|
'autoconnect': [ opt_bool, False ],
|
||||||
|
'autoreconnect': [ opt_bool, False ],
|
||||||
'proxy': [ opt_str, '' ],
|
'proxy': [ opt_str, '' ],
|
||||||
'keyid': [ opt_str, '' ],
|
'keyid': [ opt_str, '' ],
|
||||||
'keyname': [ opt_str, '' ],
|
'keyname': [ opt_str, '' ],
|
||||||
|
|
|
@ -124,6 +124,8 @@ class Connection:
|
||||||
self.gpg = None
|
self.gpg = None
|
||||||
self.vcard_sha = None
|
self.vcard_sha = None
|
||||||
self.status = ''
|
self.status = ''
|
||||||
|
self.old_show = ''
|
||||||
|
self.time_to_reconnect = None
|
||||||
self.new_account_info = None
|
self.new_account_info = None
|
||||||
self.bookmarks = []
|
self.bookmarks = []
|
||||||
self.on_purpose = False
|
self.on_purpose = False
|
||||||
|
@ -138,6 +140,7 @@ class Connection:
|
||||||
gajim.config.set('usegpg', True)
|
gajim.config.set('usegpg', True)
|
||||||
else:
|
else:
|
||||||
gajim.config.set('usegpg', False)
|
gajim.config.set('usegpg', False)
|
||||||
|
self.retrycount = 0
|
||||||
# END __init__
|
# END __init__
|
||||||
|
|
||||||
def put_event(self, ev):
|
def put_event(self, ev):
|
||||||
|
@ -217,9 +220,7 @@ class Connection:
|
||||||
self.vcard_sha = ''
|
self.vcard_sha = ''
|
||||||
self.dispatch('MYVCARD', vcard)
|
self.dispatch('MYVCARD', vcard)
|
||||||
#we re-send our presence with sha
|
#we re-send our presence with sha
|
||||||
sshow = STATUS_LIST[self.connected]
|
sshow = helpers.get_xmpp_show(STATUS_LIST[self.connected])
|
||||||
if sshow == 'online':
|
|
||||||
sshow = None
|
|
||||||
prio = unicode(gajim.config.get_per('accounts', self.name,
|
prio = unicode(gajim.config.get_per('accounts', self.name,
|
||||||
'priority'))
|
'priority'))
|
||||||
p = common.xmpp.Presence(typ = None, priority = prio, show = sshow,
|
p = common.xmpp.Presence(typ = None, priority = prio, show = sshow,
|
||||||
|
@ -411,6 +412,52 @@ class Connection:
|
||||||
self.on_purpose = False
|
self.on_purpose = False
|
||||||
|
|
||||||
# END disconenctedCB
|
# END disconenctedCB
|
||||||
|
|
||||||
|
def _reconnect(self):
|
||||||
|
gajim.log.debug('reconnect')
|
||||||
|
signed = self.get_signed_msg(self.status)
|
||||||
|
self.connect_and_init(self.old_show, self.status, signed)
|
||||||
|
if self.connected < 2: #connection failed
|
||||||
|
if self.retrycount > 10:
|
||||||
|
self.connected = 0
|
||||||
|
self.dispatch('STATUS', 'offline')
|
||||||
|
self.dispatch('ERROR',
|
||||||
|
(_('Connection with account "%s" has been lost') % self.name,
|
||||||
|
_('To continue sending and receiving messages, you will need to reconnect.')))
|
||||||
|
self.time_to_reconnect = None
|
||||||
|
self.retrycount = 0
|
||||||
|
return
|
||||||
|
self.retrycount = self.retrycount + 1
|
||||||
|
if self.retrycount > 5:
|
||||||
|
self.time_to_reconnect = time.time() + 20
|
||||||
|
else:
|
||||||
|
self.time_to_reconnect = time.time() + 10
|
||||||
|
else:
|
||||||
|
#reconnect succeeded
|
||||||
|
self.time_to_reconnect = None
|
||||||
|
self.retrycount = 0
|
||||||
|
|
||||||
|
def _disconnectedReconnCB(self):
|
||||||
|
"""Called when we are disconnected"""
|
||||||
|
gajim.log.debug('disconnectedReconnCB')
|
||||||
|
if not self.connection:
|
||||||
|
return
|
||||||
|
self.old_show = STATUS_LIST[self.connected]
|
||||||
|
self.connected = 0
|
||||||
|
self.dispatch('STATUS', 'offline')
|
||||||
|
self.connection = None
|
||||||
|
if not self.on_purpose:
|
||||||
|
if gajim.config.get_per('accounts', self.name, 'autoreconnect'):
|
||||||
|
self.connected = 1
|
||||||
|
self.dispatch('STATUS', 'connecting')
|
||||||
|
self.time_to_reconnect = time.time() + 10
|
||||||
|
else:
|
||||||
|
self.dispatch('ERROR',
|
||||||
|
(_('Connection with account "%s" has been lost') % self.name,
|
||||||
|
_('To continue sending and receiving messages, you will need to reconnect.')))
|
||||||
|
self.on_purpose = False
|
||||||
|
# END disconenctedReconnCB
|
||||||
|
|
||||||
def _bytestreamErrorCB(self, con, iq_obj):
|
def _bytestreamErrorCB(self, con, iq_obj):
|
||||||
gajim.log.debug('_bytestreamErrorCB')
|
gajim.log.debug('_bytestreamErrorCB')
|
||||||
frm = unicode(iq_obj.getFrom())
|
frm = unicode(iq_obj.getFrom())
|
||||||
|
@ -1244,7 +1291,7 @@ class Connection:
|
||||||
con = common.xmpp.Client(hostname, debug = [])
|
con = common.xmpp.Client(hostname, debug = [])
|
||||||
common.xmpp.dispatcher.DefaultTimeout = try_connecting_for_foo_secs
|
common.xmpp.dispatcher.DefaultTimeout = try_connecting_for_foo_secs
|
||||||
con.UnregisterDisconnectHandler(con.DisconnectHandler)
|
con.UnregisterDisconnectHandler(con.DisconnectHandler)
|
||||||
con.RegisterDisconnectHandler(self._disconnectedCB)
|
con.RegisterDisconnectHandler(self._disconnectedReconnCB)
|
||||||
|
|
||||||
h = hostname
|
h = hostname
|
||||||
p = 5222
|
p = 5222
|
||||||
|
@ -1260,6 +1307,7 @@ class Connection:
|
||||||
con_type = con.connect((h, p), proxy = proxy, secure=secur) #FIXME: blocking
|
con_type = con.connect((h, p), proxy = proxy, secure=secur) #FIXME: blocking
|
||||||
if not con_type:
|
if not con_type:
|
||||||
gajim.log.debug("Couldn't connect to %s" % self.name)
|
gajim.log.debug("Couldn't connect to %s" % self.name)
|
||||||
|
if not self.time_to_reconnect:
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
self.dispatch('STATUS', 'offline')
|
self.dispatch('STATUS', 'offline')
|
||||||
self.dispatch('ERROR', (_('Could not connect to "%s"') % self.name,
|
self.dispatch('ERROR', (_('Could not connect to "%s"') % self.name,
|
||||||
|
@ -1403,28 +1451,10 @@ class Connection:
|
||||||
#Get bookmarks from private namespace
|
#Get bookmarks from private namespace
|
||||||
self.get_bookmarks()
|
self.get_bookmarks()
|
||||||
|
|
||||||
def change_status(self, show, msg, sync = False, auto = False):
|
def get_signed_msg(self, msg):
|
||||||
if sync:
|
|
||||||
self.change_status2(show, msg, auto)
|
|
||||||
else:
|
|
||||||
t = threading.Thread(target=self.change_status2, args = (show, msg, auto))
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
def change_status2(self, show, msg, auto = False):
|
|
||||||
if not show in STATUS_LIST:
|
|
||||||
return -1
|
|
||||||
sshow = show # show to be send
|
|
||||||
if show == 'online':
|
|
||||||
sshow = None
|
|
||||||
if not msg:
|
|
||||||
lowered_uf_status_msg = helpers.get_uf_show(show).lower()
|
|
||||||
if lowered_uf_status_msg == _('invisible'): # do not show I'm invisible!
|
|
||||||
lowered_uf_status_msg = _('offline')
|
|
||||||
msg = _("I'm %s") % lowered_uf_status_msg
|
|
||||||
|
|
||||||
signed = ''
|
signed = ''
|
||||||
keyID = gajim.config.get_per('accounts', self.name, 'keyid')
|
keyID = gajim.config.get_per('accounts', self.name, 'keyid')
|
||||||
if keyID and USE_GPG and not auto and not show == 'offline':
|
if keyID and USE_GPG:
|
||||||
use_gpg_agent = gajim.config.get('use_gpg_agent')
|
use_gpg_agent = gajim.config.get('use_gpg_agent')
|
||||||
if self.connected < 2 and self.gpg.passphrase is None and not use_gpg_agent:
|
if self.connected < 2 and self.gpg.passphrase is None and not use_gpg_agent:
|
||||||
# We didn't set a passphrase
|
# We didn't set a passphrase
|
||||||
|
@ -1437,11 +1467,13 @@ class Connection:
|
||||||
signed = ''
|
signed = ''
|
||||||
if self.connected < 2:
|
if self.connected < 2:
|
||||||
self.dispatch('BAD_PASSPHRASE', ())
|
self.dispatch('BAD_PASSPHRASE', ())
|
||||||
self.status = msg
|
return signed
|
||||||
if show != 'offline' and not self.connected:
|
|
||||||
|
def connect_and_init(self, show, msg, signed):
|
||||||
self.connection = self.connect()
|
self.connection = self.connect()
|
||||||
if self.connected == 2:
|
if self.connected == 2:
|
||||||
self.connected = STATUS_LIST.index(show)
|
self.connected = STATUS_LIST.index(show)
|
||||||
|
sshow = helpers.get_xmpp_show(show)
|
||||||
#send our presence
|
#send our presence
|
||||||
if show == 'invisible':
|
if show == 'invisible':
|
||||||
self.send_invisible_presence(msg, signed, True)
|
self.send_invisible_presence(msg, signed, True)
|
||||||
|
@ -1464,6 +1496,30 @@ class Connection:
|
||||||
#Get bookmarks from private namespace
|
#Get bookmarks from private namespace
|
||||||
self.get_bookmarks()
|
self.get_bookmarks()
|
||||||
|
|
||||||
|
def change_status(self, show, msg, sync = False, auto = False):
|
||||||
|
if sync:
|
||||||
|
self.change_status2(show, msg, auto)
|
||||||
|
else:
|
||||||
|
t = threading.Thread(target=self.change_status2, args = (show, msg, auto))
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
def change_status2(self, show, msg, auto = False):
|
||||||
|
if not show in STATUS_LIST:
|
||||||
|
return -1
|
||||||
|
sshow = helpers.get_xmpp_show(show)
|
||||||
|
if not msg:
|
||||||
|
lowered_uf_status_msg = helpers.get_uf_show(show).lower()
|
||||||
|
if lowered_uf_status_msg == _('invisible'): # do not show I'm invisible!
|
||||||
|
lowered_uf_status_msg = _('offline')
|
||||||
|
msg = _("I'm %s") % lowered_uf_status_msg
|
||||||
|
|
||||||
|
signed = ''
|
||||||
|
if not auto and not show == 'offline':
|
||||||
|
signed = self.get_signed_msg(msg)
|
||||||
|
self.status = msg
|
||||||
|
if show != 'offline' and not self.connected:
|
||||||
|
self.connect_and_init(show, msg, signed)
|
||||||
|
|
||||||
elif show == 'offline' and self.connected:
|
elif show == 'offline' and self.connected:
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
if self.connection:
|
if self.connection:
|
||||||
|
@ -1764,10 +1820,8 @@ class Connection:
|
||||||
def join_gc(self, nick, room, server, password):
|
def join_gc(self, nick, room, server, password):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
show = STATUS_LIST[self.connected]
|
show = helpers.get_xmpp_show(STATUS_LIST[self.connected])
|
||||||
ptype = None
|
ptype = None
|
||||||
if show == 'online':
|
|
||||||
show = None
|
|
||||||
p = common.xmpp.Presence(to = '%s@%s/%s' % (room, server, nick),
|
p = common.xmpp.Presence(to = '%s@%s/%s' % (room, server, nick),
|
||||||
show = show, status = self.status)
|
show = show, status = self.status)
|
||||||
p = self.add_sha(p)
|
p = self.add_sha(p)
|
||||||
|
@ -1807,9 +1861,7 @@ class Connection:
|
||||||
ptype = None
|
ptype = None
|
||||||
if show == 'offline':
|
if show == 'offline':
|
||||||
ptype = 'unavailable'
|
ptype = 'unavailable'
|
||||||
show = None
|
show = helpers.get_xmpp_show(show)
|
||||||
if show == 'online':
|
|
||||||
show = None
|
|
||||||
p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype,
|
p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype,
|
||||||
show = show, status = status)
|
show = show, status = status)
|
||||||
p = self.add_sha(p)
|
p = self.add_sha(p)
|
||||||
|
@ -1912,6 +1964,12 @@ class Connection:
|
||||||
self.to_be_sent.append(' ')
|
self.to_be_sent.append(' ')
|
||||||
|
|
||||||
def process(self, timeout):
|
def process(self, timeout):
|
||||||
|
if self.time_to_reconnect:
|
||||||
|
if self.connected < 2:
|
||||||
|
if time.time() > self.time_to_reconnect:
|
||||||
|
self._reconnect()
|
||||||
|
else:
|
||||||
|
self.time_to_reconnect = None
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
if self.connected:
|
if self.connected:
|
||||||
|
|
|
@ -313,3 +313,8 @@ def ensure_unicode_string(s):
|
||||||
s = s.decode('utf-8')
|
s = s.decode('utf-8')
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def get_xmpp_show(show):
|
||||||
|
if show in ['online', 'offline']:
|
||||||
|
return None
|
||||||
|
return show
|
||||||
|
|
||||||
|
|
|
@ -1210,6 +1210,8 @@ class AccountModificationWindow:
|
||||||
self.xml.get_widget('gpg_choose_button').set_sensitive(False)
|
self.xml.get_widget('gpg_choose_button').set_sensitive(False)
|
||||||
self.xml.get_widget('autoconnect_checkbutton').set_active(gajim.config.\
|
self.xml.get_widget('autoconnect_checkbutton').set_active(gajim.config.\
|
||||||
get_per('accounts', self.account, 'autoconnect'))
|
get_per('accounts', self.account, 'autoconnect'))
|
||||||
|
self.xml.get_widget('autoreconnect_checkbutton').set_active(gajim.config.\
|
||||||
|
get_per('accounts', self.account, 'autoreconnect'))
|
||||||
|
|
||||||
if len(gajim.connections) != 0:
|
if len(gajim.connections) != 0:
|
||||||
# only if we already have one account already
|
# only if we already have one account already
|
||||||
|
@ -1260,6 +1262,8 @@ _('To change the account name, you must be disconnected.')).get_response()
|
||||||
get_value_as_int()
|
get_value_as_int()
|
||||||
config['autoconnect'] = self.xml.get_widget('autoconnect_checkbutton').\
|
config['autoconnect'] = self.xml.get_widget('autoconnect_checkbutton').\
|
||||||
get_active()
|
get_active()
|
||||||
|
config['autoreconnect'] = self.xml.get_widget('autoreconnect_checkbutton').\
|
||||||
|
get_active()
|
||||||
|
|
||||||
if self.account:
|
if self.account:
|
||||||
list_no_log_for = gajim.config.get_per('accounts',
|
list_no_log_for = gajim.config.get_per('accounts',
|
||||||
|
|
|
@ -200,6 +200,8 @@ class Interface:
|
||||||
|
|
||||||
def handle_event_status(self, account, status): # OUR status
|
def handle_event_status(self, account, status): # OUR status
|
||||||
#('STATUS', account, status)
|
#('STATUS', account, status)
|
||||||
|
if status == 'connecting':
|
||||||
|
self.roster.set_connecting_state(account)
|
||||||
if status != 'offline':
|
if status != 'offline':
|
||||||
gobject.timeout_add(30000, self.allow_notif, account)
|
gobject.timeout_add(30000, self.allow_notif, account)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1037,6 +1037,25 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
|
||||||
|
<child>
|
||||||
|
<widget class="GtkCheckButton" id="autoreconnect_checkbutton">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="label" translatable="yes">Reconnect automatically</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||||
|
<property name="focus_on_click">True</property>
|
||||||
|
<property name="active">False</property>
|
||||||
|
<property name="inconsistent">False</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="padding">0</property>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkCheckButton" id="log_history_checkbutton">
|
<widget class="GtkCheckButton" id="log_history_checkbutton">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|
|
@ -1171,9 +1171,7 @@ _('If "%s" accepts this request you will know his status.') %jid)
|
||||||
del self.gpg_passphrase[keyid]
|
del self.gpg_passphrase[keyid]
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def send_status(self, account, status, txt, sync = False, auto = False):
|
def set_connecting_state(self, account):
|
||||||
if status != 'offline':
|
|
||||||
if gajim.connections[account].connected < 2:
|
|
||||||
model = self.tree.get_model()
|
model = self.tree.get_model()
|
||||||
accountIter = self.get_account_iter(account)
|
accountIter = self.get_account_iter(account)
|
||||||
if accountIter:
|
if accountIter:
|
||||||
|
@ -1181,6 +1179,11 @@ _('If "%s" accepts this request you will know his status.') %jid)
|
||||||
if self.plugin.systray_enabled:
|
if self.plugin.systray_enabled:
|
||||||
self.plugin.systray.change_status('connecting')
|
self.plugin.systray.change_status('connecting')
|
||||||
|
|
||||||
|
def send_status(self, account, status, txt, sync = False, auto = False):
|
||||||
|
if status != 'offline':
|
||||||
|
if gajim.connections[account].connected < 2:
|
||||||
|
self.set_connecting_state(account)
|
||||||
|
|
||||||
save_pass = gajim.config.get_per('accounts', account, 'savepass')
|
save_pass = gajim.config.get_per('accounts', account, 'savepass')
|
||||||
if not save_pass and gajim.connections[account].connected < 2:
|
if not save_pass and gajim.connections[account].connected < 2:
|
||||||
passphrase = ''
|
passphrase = ''
|
||||||
|
|
Loading…
Reference in New Issue