added initial properties dialog for zeroconf

This commit is contained in:
Stefan Bethge 2006-09-19 23:07:54 +00:00
parent 12d125a4be
commit a393f121be
6 changed files with 229 additions and 18 deletions

View File

@ -147,17 +147,109 @@
</child>
<child>
<widget class="GtkCheckButton" id="enable_zeroconf_checkbutton">
<widget class="GtkHBox" id="hbox3023">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Enable link-local messaging (Zeroconf)</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>
<signal name="toggled" handler="on_enable_zeroconf_checkbutton_toggled" last_modification_time="Sun, 17 Sep 2006 15:13:22 GMT"/>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkCheckButton" id="enable_zeroconf_checkbutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Enable _link-local messaging (Zeroconf)</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>
<signal name="toggled" handler="on_enable_zeroconf_checkbutton_toggled" last_modification_time="Sun, 17 Sep 2006 15:13:22 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="properties_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_zeroconf_properties_button_clicked" last_modification_time="Tue, 19 Sep 2006 21:20:04 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment91">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox3024">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image1372">
<property name="visible">True</property>
<property name="stock">gtk-properties</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label385">
<property name="visible">True</property>
<property name="label" translatable="yes">Pr_operties</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>

View File

@ -471,6 +471,7 @@ class ClientZeroconf:
BindPortError(port)
return None
def getRoster(self):
return self.roster.getRoster()

View File

@ -227,6 +227,7 @@ class ConnectionHandlersZeroconf(ConnectionVcard):
idle.init()
except:
HAS_IDLE = False
def _messageCB(self, ip, con, msg):
'''Called when we receive a message'''
msgtxt = msg.getBody()

View File

@ -37,6 +37,7 @@ if os.name != 'nt':
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
import getpass
import gobject
import notify
from common import helpers
from common import gajim
@ -69,7 +70,11 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
#we don't need a password, but must be non-empty
self.password = 'zeroconf'
self.privacy_rules_supported = False
#XXX use that somewhere
self.autoconnect = False
self.sync_with_global_status = True
self.no_log_for = False
# Do we continue connection when we get roster (send presence,get vcard...)
self.continue_connect_info = None
if USE_GPG:
@ -93,6 +98,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
print 'Creating zeroconf account'
gajim.config.add_per('accounts', 'zeroconf')
gajim.config.set_per('accounts', 'zeroconf', 'autoconnect', True)
gajim.config.set_per('accounts', 'zeroconf', 'no_log_for', False)
gajim.config.set_per('accounts', 'zeroconf', 'password', 'zeroconf')
gajim.config.set_per('accounts', 'zeroconf', 'sync_with_global_status', True)
username = unicode(getpass.getuser())
@ -106,6 +112,10 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
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.autoconnect = gajim.config.get_per('accounts', 'zeroconf', 'autoconnect')
self.sync_with_global_status = gajim.config.get_per('accounts', 'zeroconf', 'sync_with_global_status')
self.no_log_for = gajim.config.get_per('accounts', 'zeroconf', 'no_log_for')
self.zeroconf = zeroconf.Zeroconf(self._on_new_service, self._on_remove_service, username, host, port)
# END __init__
@ -258,6 +268,10 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
if check:
self.dispatch('STATUS', show)
else:
# self.dispatch('ERROR', 'Could not change status. Please check if avahi-daemon is running.')
notify.popup(_('Connection problem:'), 'zeroconf', None,
title=_('Could not change status'),
text=_('Please check if avahi-daemon is running.') )
self.dispatch('STATUS', 'offline')
def get_status(self):

View File

@ -106,8 +106,8 @@ class Zeroconf:
return items
def service_resolved_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
print "Service data for service '%s' in domain '%s' on %i.%i:" % (name, domain, interface, protocol)
print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt))
#print "Service data for service '%s' in domain '%s' on %i.%i:" % (name, domain, interface, protocol)
#print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt))
bare_name = name
if name.find('@') == -1:
name = name + '@' + name
@ -293,7 +293,7 @@ class Zeroconf:
self.txt['status'] = self.replace_show(txt['status'])
txt = avahi.dict_to_txt_array(self.txt)
if self.entrygroup:
if self.connected and self.entrygroup:
self.entrygroup.UpdateServiceTxt(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), self.name, self.stype,'', txt, reply_handler=self.service_updated_callback, error_handler=self.print_error_callback)
return True
else:

View File

@ -557,8 +557,7 @@ class PreferencesWindow:
if gajim.interface.instances.has_key('accounts'):
gajim.interface.instances['accounts'].init_accounts()
else:
#enable
#gajim.config.add_per('accounts', 'zeroconf') # if not already there (how?)
#enable (will create new account if not present)
gajim.connections['zeroconf'] = common.zeroconf.connection_zeroconf.ConnectionZeroconf('zeroconf')
# update variables
gajim.interface.instances['zeroconf'] = {'infos': {}, 'disco': {},
@ -590,6 +589,12 @@ class PreferencesWindow:
self.on_checkbutton_toggled(widget, 'enable_zeroconf')
def on_zeroconf_properties_button_clicked(self, widget):
if gajim.interface.instances.has_key('zeroconf_properties'):
gajim.interface.instances['zeroconf_properties'].window.present()
else:
gajim.interface.instances['zeroconf_properties'] = \
ZeroconfPropertiesWindow()
def on_show_status_msgs_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_status_msgs_in_roster')
@ -1168,8 +1173,7 @@ class AccountModificationWindow:
def init_account_gpg(self):
keyid = gajim.config.get_per('accounts', self.account, 'keyid')
keyname = gajim.config.get_per('accounts', self.account, 'keyname')
savegpgpass = gajim.config.get_per('accounts', self.account,
'savegpgpass')
savegpgpass = gajim.config.get_per('accounts', self.account,'savegpgpass')
if not keyid or not gajim.config.get('usegpg'):
return
@ -3029,3 +3033,102 @@ _('You can set advanced account options by pressing Advanced button, or later by
gajim.interface.roster.draw_roster()
gajim.interface.roster.actions_menu_needs_rebuild = True
gajim.interface.save_config()
#---------- ZeroconfPropertiesWindow class -------------#
class ZeroconfPropertiesWindow:
def __init__(self):
self.xml = gtkgui_helpers.get_glade('zeroconf_properties_window.glade')
self.window = self.xml.get_widget('zeroconf_properties_window')
self.window.set_transient_for(gajim.interface.roster.window)
self.xml.signal_autoconnect(self)
st = gajim.config.get_per('accounts', 'zeroconf', 'autoconnect')
if st:
self.xml.get_widget('autoconnect_checkbutton').set_active(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'no_log_for')
if st:
self.xml.get_widget('log_history_checkbutton').set_active(bool(st))
st = gajim.config.get_per('accounts', 'zeroconf', 'sync_with_global_status')
if st:
self.xml.get_widget('sync_with_global_status_checkbutton').set_active(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'first_name')
if st:
self.xml.get_widget('first_name_entry').set_text(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'last_name')
if st:
self.xml.get_widget('last_name_entry').set_text(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'jabber_id')
if st:
self.xml.get_widget('jabber_id_entry').set_text(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'email')
if st:
self.xml.get_widget('email_entry').set_text(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'use_tls')
if st:
self.xml.get_widget('use_tls_checkbutton').set_active(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'custom_port')
if st:
self.xml.get_widget('custom_port_entry').set_text(str(st))
self.xml.get_widget('custom_port_entry').set_sensitive(True)
self.xml.get_widget('save_button').grab_focus()
self.window.show_all()
def on_zeroconf_properties_window_destroy(self, widget):
#close window
if gajim.interface.instances.has_key('zeroconf_properties'):
del gajim.interface.instances['zeroconf_properties']
def on_cancel_button_clicked(self, widget):
self.window.destroy()
def on_save_button_clicked(self, widget):
st = self.xml.get_widget('autoconnect_checkbutton').get_active()
gajim.config.set_per('accounts', 'zeroconf', 'autoconnect', st)
st = self.xml.get_widget('log_history_checkbutton').get_active()
gajim.config.set_per('accounts', 'zeroconf', 'no_log_for', st)
st = self.xml.get_widget('sync_with_global_status_checkbutton').get_active()
gajim.config.set_per('accounts', 'zeroconf', 'sync_with_global_status', st)
st = self.xml.get_widget('custom_port_entry').get_text()
gajim.config.set_per('accounts', 'zeroconf', 'custom_port', st)
'''
st = gajim.config.get_per('accounts', 'zeroconf', 'first_name')
if st:
self.xml.get_widget('first_name_entry').set_text(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'last_name')
if st:
self.xml.get_widget('last_name_entry').set_text(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'jabber_id')
if st:
self.xml.get_widget('jabber_id_entry').set_text(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'email')
if st:
self.xml.get_widget('email_entry').set_text(st)
st = gajim.config.get_per('accounts', 'zeroconf', 'use_tls')
if st:
self.xml.get_widget('use_tls_checkbutton').set_active(st)
'''
self.window.destroy()
def on_custom_port_checkbutton(self, widget):
pass