Add a Server section in the config file and use it to register only when needed
This commit is contained in:
parent
d398b37645
commit
5535aefc75
@ -57,9 +57,19 @@ class ServerPlugin(gobject.GObject):
|
|||||||
self._conn = self._init_connection()
|
self._conn = self._init_connection()
|
||||||
|
|
||||||
def _get_account_info(self):
|
def _get_account_info(self):
|
||||||
account_info = {'server': 'olpc.collabora.co.uk'}
|
account_info = {}
|
||||||
|
|
||||||
pubkey = profile.get_pubkey()
|
pubkey = profile.get_pubkey()
|
||||||
|
|
||||||
|
server = profile.get_server()
|
||||||
|
if not server:
|
||||||
|
account_info['server'] = 'olpc.collabora.co.uk'
|
||||||
|
else:
|
||||||
|
account_info['server'] = server
|
||||||
|
|
||||||
|
registered = profile.get_server_registered()
|
||||||
|
account_info['register'] = not registered
|
||||||
|
|
||||||
khash = util.printable_hash(util._sha_data(pubkey))
|
khash = util.printable_hash(util._sha_data(pubkey))
|
||||||
account_info['account'] = "%s@%s" % (khash, account_info['server'])
|
account_info['account'] = "%s@%s" % (khash, account_info['server'])
|
||||||
|
|
||||||
@ -88,7 +98,6 @@ class ServerPlugin(gobject.GObject):
|
|||||||
conn = self._find_existing_connection()
|
conn = self._find_existing_connection()
|
||||||
if not conn:
|
if not conn:
|
||||||
acct = self._account.copy()
|
acct = self._account.copy()
|
||||||
acct['register'] = True
|
|
||||||
|
|
||||||
# Create a new connection
|
# Create a new connection
|
||||||
print acct
|
print acct
|
||||||
@ -117,6 +126,10 @@ class ServerPlugin(gobject.GObject):
|
|||||||
return channel
|
return channel
|
||||||
|
|
||||||
def _connected_cb(self):
|
def _connected_cb(self):
|
||||||
|
if self._account['register']:
|
||||||
|
# we successfully register this account
|
||||||
|
profile.set_server_registered()
|
||||||
|
|
||||||
# the group of contacts who may receive your presence
|
# the group of contacts who may receive your presence
|
||||||
publish = self._request_list_channel('publish')
|
publish = self._request_list_channel('publish')
|
||||||
publish_handles, local_pending, remote_pending = publish[CHANNEL_INTERFACE_GROUP].GetAllMembers()
|
publish_handles, local_pending, remote_pending = publish[CHANNEL_INTERFACE_GROUP].GetAllMembers()
|
||||||
|
@ -239,6 +239,11 @@ class IntroBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
cp.set(section, 'NickName', name)
|
cp.set(section, 'NickName', name)
|
||||||
cp.set(section, 'Color', color.to_string())
|
cp.set(section, 'Color', color.to_string())
|
||||||
|
|
||||||
|
secion = 'Server'
|
||||||
|
cp.add_section(section)
|
||||||
|
cp.set(section, 'Server', 'olpc.collabora.co.uk')
|
||||||
|
cp.set(Section, 'Registered', 'False')
|
||||||
|
|
||||||
config_path = os.path.join(env.get_profile_path(), 'config')
|
config_path = os.path.join(env.get_profile_path(), 'config')
|
||||||
f = open(config_path, 'w')
|
f = open(config_path, 'w')
|
||||||
cp.write(f)
|
cp.write(f)
|
||||||
|
@ -28,6 +28,8 @@ class _Profile(object):
|
|||||||
self.color = None
|
self.color = None
|
||||||
self.pubkey = None
|
self.pubkey = None
|
||||||
self.privkey_hash = None
|
self.privkey_hash = None
|
||||||
|
self.server = None
|
||||||
|
self.server_registered = False
|
||||||
self._load()
|
self._load()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -44,6 +46,12 @@ class _Profile(object):
|
|||||||
if cp.has_option('Buddy', 'Color'):
|
if cp.has_option('Buddy', 'Color'):
|
||||||
self.color = XoColor(cp.get('Buddy', 'Color'))
|
self.color = XoColor(cp.get('Buddy', 'Color'))
|
||||||
|
|
||||||
|
if cp.has_option('Server', 'Server'):
|
||||||
|
self.server = cp.get('Server', 'Server')
|
||||||
|
|
||||||
|
if cp.has_option('Server', 'Registered'):
|
||||||
|
self.server_registered = cp.get('Server', 'Registered')
|
||||||
|
|
||||||
del cp
|
del cp
|
||||||
|
|
||||||
self._load_pubkey()
|
self._load_pubkey()
|
||||||
@ -110,6 +118,25 @@ def get_pubkey():
|
|||||||
def get_private_key_hash():
|
def get_private_key_hash():
|
||||||
return _profile.privkey_hash
|
return _profile.privkey_hash
|
||||||
|
|
||||||
|
def get_server():
|
||||||
|
return _profile.server
|
||||||
|
|
||||||
|
def get_server_registered():
|
||||||
|
return _profile.server_registered
|
||||||
|
|
||||||
|
def set_server_registered():
|
||||||
|
_profile.server_registered = True
|
||||||
|
|
||||||
|
cp = ConfigParser()
|
||||||
|
|
||||||
|
config_path = os.path.join(env.get_profile_path(), 'config')
|
||||||
|
cp.read([config_path])
|
||||||
|
|
||||||
|
if not cp.has_section('Server'):
|
||||||
|
cp.add_section('Server')
|
||||||
|
cp.set('Server', 'Registered', True)
|
||||||
|
cp.write(open(config_path, 'w'))
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
_profile.update()
|
_profile.update()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user