Commit 56cd8ba4 authored by dkirov's avatar dkirov
Browse files

config option 'zeroconf_enabled' indicates

that zeroconf connection should be used.
Create the neccessary config values if zeroconf
account is not present
parent 6bdc8eb2
......@@ -200,6 +200,7 @@ class Config:
'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_indent': [opt_str, ' ', _('Indentation when using merge consecutive nickame')],
'zeroconf_enabled': [opt_bool, True, _('Enable zeroconf network')],
}
__options_per_key = {
......
......@@ -33,7 +33,7 @@
import signal
if os.name != 'nt':
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
import getpass
import gobject
from common import helpers
......@@ -54,7 +54,6 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
def __init__(self, name):
ConnectionHandlersZeroconf.__init__(self)
self.name = name
self.zeroconf = zeroconf.Zeroconf(self._on_new_service, self._on_remove_service)
self.connected = 0 # offline
self.connection = None
self.gpg = None
......@@ -74,7 +73,7 @@ def __init__(self, name):
#self.last_history_line = {}
#we don't need a password, but must be non-empty
self.password = 'dummy'
self.password = 'zeroconf'
self.privacy_rules_supported = False
# Do we continue connection when we get roster (send presence,get vcard...)
......@@ -89,10 +88,30 @@ def __init__(self, name):
self.on_connect_failure = None
self.retrycount = 0
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__
def put_event(self, ev):
if gajim.handlers.has_key(ev[0]):
......
import os
import sys
import getpass
import socket
from common import gajim
try:
import avahi, gobject, dbus
except ImportError:
......@@ -14,12 +13,12 @@
pass
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.stype = '_presence._tcp'
self.port = 5298 # listening port that gets announced
self.username = getpass.getuser()
self.host = socket.gethostname()
self.port = port # listening port that gets announced
self.username = name
self.host = host
self.name = self.username+'@'+ self.host # service name
self.txt = {} # service data
......@@ -37,7 +36,8 @@ def print_error_callback(self, err):
print "Error:", str(err)
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)
#synchronous resolving
......@@ -183,9 +183,13 @@ def connect(self):
self.bus = dbus.SystemBus()
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, \
avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
self.server.connect_to_signal('StateChanged', self.server_state_changed_callback)
try:
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
if self.domain is None:
# Explicitly browse .local
......
......@@ -1739,10 +1739,10 @@ def __init__(self):
self.handle_event_file_progress)
gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue)
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'):
if account == 'zeroconf':
gajim.connections[account] = common.zeroconf.connection_zeroconf.ConnectionZeroconf(account)
else:
if account != 'zeroconf':
gajim.connections[account] = common.connection.Connection(account)
......
......@@ -508,7 +508,7 @@ def populate(self, contacts):
vcard_table.set_homogeneous(False)
vcard_current_row = 1
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((_('Name: '), gtkgui_helpers.escape_for_pango_markup(
prim_contact.get_shown_name())))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment