config option 'zeroconf_enabled' indicates
that zeroconf connection should be used. Create the neccessary config values if zeroconf account is not present
This commit is contained in:
parent
6bdc8eb210
commit
56cd8ba43b
|
@ -200,6 +200,7 @@ class Config:
|
||||||
'hide_groupchat_occupants_list': [opt_bool, False, _('Hides the room occupants list in groupchat window')],
|
'hide_groupchat_occupants_list': [opt_bool, False, _('Hides the room occupants list in groupchat window')],
|
||||||
'chat_merge_consecutive_nickname': [opt_bool, False, _('Merge consecutive nickname in chat window')],
|
'chat_merge_consecutive_nickname': [opt_bool, False, _('Merge consecutive nickname in chat window')],
|
||||||
'chat_merge_consecutive_nickname_indent': [opt_str, ' ', _('Indentation when using merge consecutive nickame')],
|
'chat_merge_consecutive_nickname_indent': [opt_str, ' ', _('Indentation when using merge consecutive nickame')],
|
||||||
|
'zeroconf_enabled': [opt_bool, True, _('Enable zeroconf network')],
|
||||||
}
|
}
|
||||||
|
|
||||||
__options_per_key = {
|
__options_per_key = {
|
||||||
|
|
|
@ -33,7 +33,7 @@ random.seed()
|
||||||
import signal
|
import signal
|
||||||
if os.name != 'nt':
|
if os.name != 'nt':
|
||||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||||
|
import getpass
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
from common import helpers
|
from common import helpers
|
||||||
|
@ -54,7 +54,6 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
ConnectionHandlersZeroconf.__init__(self)
|
ConnectionHandlersZeroconf.__init__(self)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.zeroconf = zeroconf.Zeroconf(self._on_new_service, self._on_remove_service)
|
|
||||||
self.connected = 0 # offline
|
self.connected = 0 # offline
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.gpg = None
|
self.gpg = None
|
||||||
|
@ -74,7 +73,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
#self.last_history_line = {}
|
#self.last_history_line = {}
|
||||||
|
|
||||||
#we don't need a password, but must be non-empty
|
#we don't need a password, but must be non-empty
|
||||||
self.password = 'dummy'
|
self.password = 'zeroconf'
|
||||||
|
|
||||||
self.privacy_rules_supported = False
|
self.privacy_rules_supported = False
|
||||||
# Do we continue connection when we get roster (send presence,get vcard...)
|
# Do we continue connection when we get roster (send presence,get vcard...)
|
||||||
|
@ -89,10 +88,30 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.on_connect_failure = None
|
self.on_connect_failure = None
|
||||||
self.retrycount = 0
|
self.retrycount = 0
|
||||||
self.jids_for_auto_auth = [] # list of jid to auto-authorize
|
self.jids_for_auto_auth = [] # list of jid to auto-authorize
|
||||||
|
self.get_config_values_or_default()
|
||||||
|
|
||||||
|
def get_config_values_or_default(self):
|
||||||
|
''' get name, host, port from config, or
|
||||||
|
create zeroconf account with default values'''
|
||||||
|
if not gajim.config.get_per('accounts', 'zeroconf', 'name'):
|
||||||
|
print 'Creating zeroconf account'
|
||||||
|
gajim.config.add_per('accounts', 'zeroconf')
|
||||||
|
gajim.config.set_per('accounts', 'zeroconf', 'autoconnect', True)
|
||||||
|
gajim.config.set_per('accounts', 'zeroconf', 'password', 'zeroconf')
|
||||||
|
gajim.config.set_per('accounts', 'zeroconf', 'sync_with_global_status', True)
|
||||||
|
username = unicode(getpass.getuser())
|
||||||
|
gajim.config.set_per('accounts', 'zeroconf', 'name', username)
|
||||||
|
#XXX make sure host is US-ASCII
|
||||||
|
host = unicode(socket.gethostname())
|
||||||
|
gajim.config.set_per('accounts', 'zeroconf', 'hostname', host)
|
||||||
|
port = 5298
|
||||||
|
gajim.config.set_per('accounts', 'zeroconf', 'custom_port', 5298)
|
||||||
|
else:
|
||||||
|
username = gajim.config.get_per('accounts', 'zeroconf', 'name')
|
||||||
|
host = gajim.config.get_per('accounts', 'zeroconf', 'hostname')
|
||||||
|
port = gajim.config.get_per('accounts', 'zeroconf', 'custom_port')
|
||||||
|
self.zeroconf = zeroconf.Zeroconf(self._on_new_service, self._on_remove_service, username, host, port)
|
||||||
|
|
||||||
gajim.config.set_per('accounts', name, 'name', self.zeroconf.username)
|
|
||||||
gajim.config.set_per('accounts', name, 'hostname', self.zeroconf.host)
|
|
||||||
|
|
||||||
# END __init__
|
# END __init__
|
||||||
def put_event(self, ev):
|
def put_event(self, ev):
|
||||||
if gajim.handlers.has_key(ev[0]):
|
if gajim.handlers.has_key(ev[0]):
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import getpass
|
|
||||||
import socket
|
import socket
|
||||||
|
from common import gajim
|
||||||
try:
|
try:
|
||||||
import avahi, gobject, dbus
|
import avahi, gobject, dbus
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -14,12 +13,12 @@ except ImportError, e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Zeroconf:
|
class Zeroconf:
|
||||||
def __init__(self, new_serviceCB, remove_serviceCB):
|
def __init__(self, new_serviceCB, remove_serviceCB, name, host, port):
|
||||||
self.domain = None # specific domain to browse
|
self.domain = None # specific domain to browse
|
||||||
self.stype = '_presence._tcp'
|
self.stype = '_presence._tcp'
|
||||||
self.port = 5298 # listening port that gets announced
|
self.port = port # listening port that gets announced
|
||||||
self.username = getpass.getuser()
|
self.username = name
|
||||||
self.host = socket.gethostname()
|
self.host = host
|
||||||
self.name = self.username+'@'+ self.host # service name
|
self.name = self.username+'@'+ self.host # service name
|
||||||
self.txt = {} # service data
|
self.txt = {} # service data
|
||||||
|
|
||||||
|
@ -37,7 +36,8 @@ class Zeroconf:
|
||||||
print "Error:", str(err)
|
print "Error:", str(err)
|
||||||
|
|
||||||
def new_service_callback(self, interface, protocol, name, stype, domain, flags):
|
def new_service_callback(self, interface, protocol, name, stype, domain, flags):
|
||||||
if name != self.name:
|
if True:
|
||||||
|
#XXX name != self.name
|
||||||
# print "Found service '%s' in domain '%s' on %i.%i." % (name, domain, interface, protocol)
|
# print "Found service '%s' in domain '%s' on %i.%i." % (name, domain, interface, protocol)
|
||||||
|
|
||||||
#synchronous resolving
|
#synchronous resolving
|
||||||
|
@ -183,9 +183,13 @@ class Zeroconf:
|
||||||
self.bus = dbus.SystemBus()
|
self.bus = dbus.SystemBus()
|
||||||
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, \
|
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, \
|
||||||
avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
|
avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
|
||||||
|
try:
|
||||||
self.server.connect_to_signal('StateChanged', self.server_state_changed_callback)
|
self.server.connect_to_signal('StateChanged', self.server_state_changed_callback)
|
||||||
|
except dbus.dbus_bindings.DBusException, e:
|
||||||
|
# Avahi service is not present
|
||||||
|
gajim.log.debug(str(e))
|
||||||
|
self.remove_announce()
|
||||||
|
return
|
||||||
# start browsing
|
# start browsing
|
||||||
if self.domain is None:
|
if self.domain is None:
|
||||||
# Explicitly browse .local
|
# Explicitly browse .local
|
||||||
|
|
|
@ -1739,10 +1739,10 @@ class Interface:
|
||||||
self.handle_event_file_progress)
|
self.handle_event_file_progress)
|
||||||
gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue)
|
gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue)
|
||||||
self.register_handlers()
|
self.register_handlers()
|
||||||
|
if gajim.config.get('zeroconf_enabled'):
|
||||||
|
gajim.connections['zeroconf'] = common.zeroconf.connection_zeroconf.ConnectionZeroconf('zeroconf')
|
||||||
for account in gajim.config.get_per('accounts'):
|
for account in gajim.config.get_per('accounts'):
|
||||||
if account == 'zeroconf':
|
if account != 'zeroconf':
|
||||||
gajim.connections[account] = common.zeroconf.connection_zeroconf.ConnectionZeroconf(account)
|
|
||||||
else:
|
|
||||||
gajim.connections[account] = common.connection.Connection(account)
|
gajim.connections[account] = common.connection.Connection(account)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -508,7 +508,7 @@ class RosterTooltip(NotificationAreaTooltip):
|
||||||
vcard_table.set_homogeneous(False)
|
vcard_table.set_homogeneous(False)
|
||||||
vcard_current_row = 1
|
vcard_current_row = 1
|
||||||
properties = []
|
properties = []
|
||||||
jid_markup = '<span weight="bold">' + unicode(prim_contact.jid) + '</span>'
|
jid_markup = '<span weight="bold">' + prim_contact.jid + '</span>'
|
||||||
properties.append((jid_markup, None))
|
properties.append((jid_markup, None))
|
||||||
properties.append((_('Name: '), gtkgui_helpers.escape_for_pango_markup(
|
properties.append((_('Name: '), gtkgui_helpers.escape_for_pango_markup(
|
||||||
prim_contact.get_shown_name())))
|
prim_contact.get_shown_name())))
|
||||||
|
|
Loading…
Reference in New Issue