From 56cd8ba43b49445968a3c08c6ad53b2bc3a7a74a Mon Sep 17 00:00:00 2001 From: Dimitur Kirov Date: Tue, 11 Jul 2006 15:22:59 +0000 Subject: [PATCH] config option 'zeroconf_enabled' indicates that zeroconf connection should be used. Create the neccessary config values if zeroconf account is not present --- src/common/config.py | 1 + src/common/zeroconf/connection_zeroconf.py | 31 +++++++++++++++++----- src/common/zeroconf/zeroconf.py | 24 ++++++++++------- src/gajim.py | 6 ++--- src/tooltips.py | 2 +- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/common/config.py b/src/common/config.py index 0f8a2a00d..da7cc93f1 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -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 = { diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index 2a3fabfc7..f8e091092 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -33,7 +33,7 @@ random.seed() 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 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): #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 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): 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]): diff --git a/src/common/zeroconf/zeroconf.py b/src/common/zeroconf/zeroconf.py index 20a40b7f5..5aa793156 100755 --- a/src/common/zeroconf/zeroconf.py +++ b/src/common/zeroconf/zeroconf.py @@ -1,8 +1,7 @@ import os import sys -import getpass import socket - +from common import gajim try: import avahi, gobject, dbus except ImportError: @@ -14,12 +13,12 @@ except ImportError, e: 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 @@ class Zeroconf: 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 @@ class Zeroconf: 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 diff --git a/src/gajim.py b/src/gajim.py index 35de76b8b..703a089f5 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1739,10 +1739,10 @@ class Interface: 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) diff --git a/src/tooltips.py b/src/tooltips.py index cd41c22a9..f09cccbdd 100644 --- a/src/tooltips.py +++ b/src/tooltips.py @@ -508,7 +508,7 @@ class RosterTooltip(NotificationAreaTooltip): vcard_table.set_homogeneous(False) vcard_current_row = 1 properties = [] - jid_markup = '' + unicode(prim_contact.jid) + '' + jid_markup = '' + prim_contact.jid + '' properties.append((jid_markup, None)) properties.append((_('Name: '), gtkgui_helpers.escape_for_pango_markup( prim_contact.get_shown_name())))