2005-10-30 10:58:13 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/disco.py
|
2005-10-30 10:58:13 +01:00
|
|
|
##
|
2008-08-15 19:31:51 +02:00
|
|
|
## Copyright (C) 2005-2006 Stéphan Kochen <stephan AT kochen.nl>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005-2007 Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
## Copyright (C) 2005-2008 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
## Copyright (C) 2007 Stephan Erb <steve-e AT h3c.de>
|
2005-10-30 10:58:13 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-10-30 10:58:13 +01:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-10-30 10:58:13 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-10-30 10:58:13 +01:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-10-30 10:58:13 +01:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
# The appearance of the treeview, and parts of the dialog, are controlled by
|
|
|
|
# AgentBrowser (sub-)classes. Methods that probably should be overridden when
|
|
|
|
# subclassing are: (look at the docstrings and source for additional info)
|
|
|
|
# - def cleanup(self) *
|
|
|
|
# - def _create_treemodel(self) *
|
|
|
|
# - def _add_actions(self)
|
|
|
|
# - def _clean_actions(self)
|
|
|
|
# - def update_theme(self) *
|
|
|
|
# - def update_actions(self)
|
|
|
|
# - def default_action(self)
|
|
|
|
# - def _find_item(self, jid, node)
|
2006-11-18 21:52:28 +01:00
|
|
|
# - def _add_item(self, jid, node, item, force)
|
2008-12-03 18:16:04 +01:00
|
|
|
# - def _update_item(self, iter_, jid, node, item)
|
|
|
|
# - def _update_info(self, iter_, jid, node, identities, features, data)
|
|
|
|
# - def _update_error(self, iter_, jid, node)
|
2005-10-30 10:58:13 +01:00
|
|
|
#
|
|
|
|
# * Should call the super class for this method.
|
|
|
|
# All others do not have to call back to the super class. (but can if they want
|
|
|
|
# the functionality)
|
2005-11-19 21:47:48 +01:00
|
|
|
# There are more methods, of course, but this is a basic set.
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
import os
|
2008-11-05 21:00:18 +01:00
|
|
|
import types
|
2005-10-30 10:58:13 +01:00
|
|
|
import weakref
|
|
|
|
import gobject
|
|
|
|
import gtk
|
2006-03-19 22:25:28 +01:00
|
|
|
import pango
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
import dialogs
|
2005-10-30 15:33:25 +01:00
|
|
|
import tooltips
|
2006-05-02 17:53:25 +02:00
|
|
|
import gtkgui_helpers
|
2006-08-20 12:18:20 +02:00
|
|
|
import groups
|
2007-01-18 10:12:03 +01:00
|
|
|
import adhoc_commands
|
2007-04-19 16:26:21 +02:00
|
|
|
import search_window
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
from common import gajim
|
|
|
|
from common import xmpp
|
2006-11-18 21:52:28 +01:00
|
|
|
from common.exceptions import GajimGeneralException
|
2008-09-14 09:15:15 +02:00
|
|
|
from common import helpers
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
# Dictionary mapping category, type pairs to browser class, image pairs.
|
|
|
|
# This is a function, so we can call it after the classes are declared.
|
|
|
|
# For the browser class, None means that the service will only be browsable
|
|
|
|
# when it advertises disco as it's feature, False means it's never browsable.
|
|
|
|
def _gen_agent_type_info():
|
|
|
|
return {
|
|
|
|
# Defaults
|
2005-11-20 16:10:34 +01:00
|
|
|
(0, 0): (None, None),
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
# Jabber server
|
2005-11-20 16:10:34 +01:00
|
|
|
('server', 'im'): (ToplevelAgentBrowser, 'jabber.png'),
|
2005-10-30 10:58:13 +01:00
|
|
|
('services', 'jabber'): (ToplevelAgentBrowser, 'jabber.png'),
|
2007-10-22 10:54:07 +02:00
|
|
|
('hierarchy', 'branch'): (AgentBrowser, 'jabber.png'),
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
# Services
|
2005-11-18 15:29:34 +01:00
|
|
|
('conference', 'text'): (MucBrowser, 'conference.png'),
|
2005-11-20 16:10:34 +01:00
|
|
|
('headline', 'rss'): (AgentBrowser, 'rss.png'),
|
2005-11-18 15:16:00 +01:00
|
|
|
('headline', 'weather'): (False, 'weather.png'),
|
|
|
|
('gateway', 'weather'): (False, 'weather.png'),
|
2005-11-20 16:10:34 +01:00
|
|
|
('_jid', 'weather'): (False, 'weather.png'),
|
2005-11-20 14:02:48 +01:00
|
|
|
('gateway', 'sip'): (False, 'sip.png'),
|
2005-11-20 13:53:26 +01:00
|
|
|
('directory', 'user'): (None, 'jud.png'),
|
2007-06-25 00:33:00 +02:00
|
|
|
('pubsub', 'generic'): (PubSubBrowser, 'pubsub.png'),
|
2006-08-04 22:12:00 +02:00
|
|
|
('pubsub', 'service'): (PubSubBrowser, 'pubsub.png'),
|
2005-11-20 15:10:53 +01:00
|
|
|
('proxy', 'bytestreams'): (None, 'bytestreams.png'), # Socks5 FT proxy
|
2007-11-07 15:29:43 +01:00
|
|
|
('headline', 'newmail'): (ToplevelAgentBrowser, 'mail.png'),
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
# Transports
|
2006-09-13 18:47:58 +02:00
|
|
|
('conference', 'irc'): (ToplevelAgentBrowser, 'irc.png'),
|
2005-11-20 16:10:34 +01:00
|
|
|
('_jid', 'irc'): (False, 'irc.png'),
|
2005-10-30 10:58:13 +01:00
|
|
|
('gateway', 'aim'): (False, 'aim.png'),
|
2005-11-20 16:10:34 +01:00
|
|
|
('_jid', 'aim'): (False, 'aim.png'),
|
2005-10-30 10:58:13 +01:00
|
|
|
('gateway', 'gadu-gadu'): (False, 'gadu-gadu.png'),
|
|
|
|
('_jid', 'gadugadu'): (False, 'gadu-gadu.png'),
|
2005-11-19 21:18:20 +01:00
|
|
|
('gateway', 'http-ws'): (False, 'http-ws.png'),
|
2005-10-30 10:58:13 +01:00
|
|
|
('gateway', 'icq'): (False, 'icq.png'),
|
2005-11-20 16:10:34 +01:00
|
|
|
('_jid', 'icq'): (False, 'icq.png'),
|
2005-10-30 10:58:13 +01:00
|
|
|
('gateway', 'msn'): (False, 'msn.png'),
|
2005-11-20 16:10:34 +01:00
|
|
|
('_jid', 'msn'): (False, 'msn.png'),
|
2005-11-19 21:18:20 +01:00
|
|
|
('gateway', 'sms'): (False, 'sms.png'),
|
2005-11-20 16:10:34 +01:00
|
|
|
('_jid', 'sms'): (False, 'sms.png'),
|
|
|
|
('gateway', 'smtp'): (False, 'mail.png'),
|
2005-10-30 10:58:13 +01:00
|
|
|
('gateway', 'yahoo'): (False, 'yahoo.png'),
|
|
|
|
('_jid', 'yahoo'): (False, 'yahoo.png'),
|
2008-07-10 14:18:26 +02:00
|
|
|
('gateway', 'mrim'): (False, 'mrim.png'),
|
|
|
|
('_jid', 'mrim'): (False, 'mrim.png'),
|
2009-06-27 09:50:50 +02:00
|
|
|
('gateway', 'facebook'): (False, 'facebook.png'),
|
|
|
|
('_jid', 'facebook'): (False, 'facebook.png'),
|
2005-10-30 10:58:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Category type to "human-readable" description string, and sort priority
|
|
|
|
_cat_to_descr = {
|
2005-11-16 13:50:18 +01:00
|
|
|
'other': (_('Others'), 2),
|
2005-10-30 10:58:13 +01:00
|
|
|
'gateway': (_('Transports'), 0),
|
|
|
|
'_jid': (_('Transports'), 0),
|
2005-12-02 15:08:40 +01:00
|
|
|
#conference is a category for listing mostly groupchats in service discovery
|
2005-10-30 10:58:13 +01:00
|
|
|
'conference': (_('Conference'), 1),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-16 13:50:18 +01:00
|
|
|
class CacheDictionary:
|
|
|
|
'''A dictionary that keeps items around for only a specific time.
|
|
|
|
Lifetime is in minutes. Getrefresh specifies whether to refresh when
|
|
|
|
an item is merely accessed instead of set aswell.'''
|
|
|
|
def __init__(self, lifetime, getrefresh = True):
|
|
|
|
self.lifetime = lifetime * 1000 * 60
|
|
|
|
self.getrefresh = getrefresh
|
|
|
|
self.cache = {}
|
|
|
|
|
|
|
|
class CacheItem:
|
|
|
|
'''An object to store cache items and their timeouts.'''
|
|
|
|
def __init__(self, value):
|
|
|
|
self.value = value
|
|
|
|
self.source = None
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
return self.value
|
|
|
|
|
2006-11-18 21:52:28 +01:00
|
|
|
def cleanup(self):
|
|
|
|
for key in self.cache.keys():
|
|
|
|
item = self.cache[key]
|
|
|
|
if item.source:
|
|
|
|
gobject.source_remove(item.source)
|
|
|
|
del self.cache[key]
|
|
|
|
|
2005-11-16 13:50:18 +01:00
|
|
|
def _expire_timeout(self, key):
|
|
|
|
'''The timeout has expired, remove the object.'''
|
2006-09-13 18:47:58 +02:00
|
|
|
if key in self.cache:
|
|
|
|
del self.cache[key]
|
2005-11-16 13:50:18 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
def _refresh_timeout(self, key):
|
|
|
|
'''The object was accessed, refresh the timeout.'''
|
|
|
|
item = self.cache[key]
|
|
|
|
if item.source:
|
|
|
|
gobject.source_remove(item.source)
|
2006-11-18 21:52:28 +01:00
|
|
|
if self.lifetime:
|
2008-02-14 20:18:07 +01:00
|
|
|
source = gobject.timeout_add_seconds(self.lifetime/1000, self._expire_timeout, key)
|
2006-11-18 21:52:28 +01:00
|
|
|
item.source = source
|
2005-11-16 13:50:18 +01:00
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
item = self.cache[key]
|
|
|
|
if self.getrefresh:
|
|
|
|
self._refresh_timeout(key)
|
|
|
|
return item()
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
item = self.CacheItem(value)
|
|
|
|
self.cache[key] = item
|
|
|
|
self._refresh_timeout(key)
|
|
|
|
|
|
|
|
def __delitem__(self, key):
|
|
|
|
item = self.cache[key]
|
|
|
|
if item.source:
|
|
|
|
gobject.source_remove(item.source)
|
|
|
|
del self.cache[key]
|
|
|
|
|
|
|
|
def __contains__(self, key):
|
|
|
|
return key in self.cache
|
|
|
|
has_key = __contains__
|
|
|
|
|
|
|
|
_icon_cache = CacheDictionary(15)
|
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def get_agent_address(jid, node = None):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Returns an agent's address for displaying in the GUI.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if node:
|
|
|
|
return '%s@%s' % (node, str(jid))
|
|
|
|
else:
|
|
|
|
return str(jid)
|
|
|
|
|
|
|
|
class Closure(object):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''A weak reference to a callback with arguments as an object.
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
Weak references to methods immediatly die, even if the object is still
|
|
|
|
alive. Besides a handy way to store a callback, this provides a workaround
|
|
|
|
that keeps a reference to the object instead.
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-11-02 12:03:42 +01:00
|
|
|
Userargs and removeargs must be tuples.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
def __init__(self, cb, userargs = (), remove = None, removeargs = ()):
|
|
|
|
self.userargs = userargs
|
|
|
|
self.remove = remove
|
|
|
|
self.removeargs = removeargs
|
2008-11-05 21:00:18 +01:00
|
|
|
if isinstance(cb, types.MethodType):
|
2005-10-30 10:58:13 +01:00
|
|
|
self.meth_self = weakref.ref(cb.im_self, self._remove)
|
|
|
|
self.meth_name = cb.func_name
|
|
|
|
elif callable(cb):
|
|
|
|
self.meth_self = None
|
|
|
|
self.cb = weakref.ref(cb, self._remove)
|
|
|
|
else:
|
|
|
|
raise TypeError('Object is not callable')
|
|
|
|
|
|
|
|
def _remove(self, ref):
|
|
|
|
if self.remove:
|
|
|
|
self.remove(self, *self.removeargs)
|
|
|
|
|
|
|
|
def __call__(self, *args, **kwargs):
|
|
|
|
if self.meth_self:
|
|
|
|
obj = self.meth_self()
|
|
|
|
cb = getattr(obj, self.meth_name)
|
|
|
|
else:
|
|
|
|
cb = self.cb()
|
|
|
|
args = args + self.userargs
|
|
|
|
return cb(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class ServicesCache:
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Class that caches our query results. Each connection will have it's own
|
|
|
|
ServiceCache instance.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
def __init__(self, account):
|
|
|
|
self.account = account
|
2006-11-18 21:52:28 +01:00
|
|
|
self._items = CacheDictionary(0, getrefresh = False)
|
|
|
|
self._info = CacheDictionary(0, getrefresh = False)
|
2006-08-20 12:18:20 +02:00
|
|
|
self._subscriptions = CacheDictionary(5, getrefresh=False)
|
2005-10-30 10:58:13 +01:00
|
|
|
self._cbs = {}
|
|
|
|
|
2006-11-18 21:52:28 +01:00
|
|
|
def cleanup(self):
|
|
|
|
self._items.cleanup()
|
|
|
|
self._info.cleanup()
|
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _clean_closure(self, cb, type_, addr):
|
2005-10-30 10:58:13 +01:00
|
|
|
# A closure died, clean up
|
2008-10-11 12:22:04 +02:00
|
|
|
cbkey = (type_, addr)
|
2005-10-30 10:58:13 +01:00
|
|
|
try:
|
|
|
|
self._cbs[cbkey].remove(cb)
|
|
|
|
except KeyError:
|
|
|
|
return
|
|
|
|
except ValueError:
|
|
|
|
return
|
|
|
|
# Clean an empty list
|
|
|
|
if not self._cbs[cbkey]:
|
|
|
|
del self._cbs[cbkey]
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-11-19 21:33:49 +01:00
|
|
|
def get_icon(self, identities = []):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Return the icon for an agent.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
# Grab the first identity with an icon
|
|
|
|
for identity in identities:
|
|
|
|
try:
|
2008-12-03 18:16:04 +01:00
|
|
|
cat, type_ = identity['category'], identity['type']
|
|
|
|
info = _agent_type_info[(cat, type_)]
|
2005-10-30 10:58:13 +01:00
|
|
|
except KeyError:
|
|
|
|
continue
|
|
|
|
filename = info[1]
|
|
|
|
if filename:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
# Loop fell through, default to unknown
|
|
|
|
info = _agent_type_info[(0, 0)]
|
|
|
|
filename = info[1]
|
2005-11-19 21:33:49 +01:00
|
|
|
if not filename: # we don't have an image to show for this type
|
2008-11-02 14:20:12 +01:00
|
|
|
filename = 'jabber.png'
|
2005-10-30 10:58:13 +01:00
|
|
|
# Use the cache if possible
|
|
|
|
if filename in _icon_cache:
|
|
|
|
return _icon_cache[filename]
|
|
|
|
# Or load it
|
2005-11-19 21:33:49 +01:00
|
|
|
filepath = os.path.join(gajim.DATA_DIR, 'pixmaps', 'agents', filename)
|
|
|
|
pix = gtk.gdk.pixbuf_new_from_file(filepath)
|
2005-10-30 10:58:13 +01:00
|
|
|
# Store in cache
|
|
|
|
_icon_cache[filename] = pix
|
|
|
|
return pix
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2008-07-11 09:42:57 +02:00
|
|
|
def get_browser(self, identities=[], features=[]):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Return the browser class for an agent.'''
|
2008-07-11 09:42:57 +02:00
|
|
|
# First pass, we try to find a ToplevelAgentBrowser
|
2005-10-30 10:58:13 +01:00
|
|
|
for identity in identities:
|
|
|
|
try:
|
2008-07-11 09:42:57 +02:00
|
|
|
cat, type_ = identity['category'], identity['type']
|
|
|
|
info = _agent_type_info[(cat, type_)]
|
|
|
|
except KeyError:
|
|
|
|
continue
|
|
|
|
browser = info[0]
|
|
|
|
if browser and browser == ToplevelAgentBrowser:
|
|
|
|
return browser
|
|
|
|
|
|
|
|
# second pass, we haven't found a ToplevelAgentBrowser
|
|
|
|
for identity in identities:
|
|
|
|
try:
|
|
|
|
cat, type_ = identity['category'], identity['type']
|
|
|
|
info = _agent_type_info[(cat, type_)]
|
2005-10-30 10:58:13 +01:00
|
|
|
except KeyError:
|
|
|
|
continue
|
|
|
|
browser = info[0]
|
2006-09-13 18:47:58 +02:00
|
|
|
if browser:
|
2008-07-11 09:42:57 +02:00
|
|
|
return browser
|
|
|
|
# NS_BROWSE is deprecated, but we check for it anyways.
|
|
|
|
# Some services list it in features and respond to
|
|
|
|
# NS_DISCO_ITEMS anyways.
|
|
|
|
# Allow browsing for unknown types aswell.
|
|
|
|
if (not features and not identities) or \
|
|
|
|
xmpp.NS_DISCO_ITEMS in features or xmpp.NS_BROWSE in features:
|
2008-11-17 16:08:22 +01:00
|
|
|
return ToplevelAgentBrowser
|
2008-07-11 09:42:57 +02:00
|
|
|
return None
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
def get_info(self, jid, node, cb, force = False, nofetch = False, args = ()):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Get info for an agent.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid, node)
|
|
|
|
# Check the cache
|
2008-10-07 22:41:59 +02:00
|
|
|
if addr in self._info:
|
2005-11-16 13:50:18 +01:00
|
|
|
args = self._info[addr] + args
|
|
|
|
cb(jid, node, *args)
|
|
|
|
return
|
2005-10-30 10:58:13 +01:00
|
|
|
if nofetch:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Create a closure object
|
|
|
|
cbkey = ('info', addr)
|
|
|
|
cb = Closure(cb, userargs = args, remove = self._clean_closure,
|
|
|
|
removeargs = cbkey)
|
|
|
|
# Are we already fetching this?
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
self._cbs[cbkey].append(cb)
|
|
|
|
else:
|
|
|
|
self._cbs[cbkey] = [cb]
|
|
|
|
gajim.connections[self.account].discoverInfo(jid, node)
|
|
|
|
|
|
|
|
def get_items(self, jid, node, cb, force = False, nofetch = False, args = ()):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Get a list of items in an agent.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid, node)
|
|
|
|
# Check the cache
|
2008-10-07 22:41:59 +02:00
|
|
|
if addr in self._items:
|
2005-11-16 13:50:18 +01:00
|
|
|
args = (self._items[addr],) + args
|
|
|
|
cb(jid, node, *args)
|
|
|
|
return
|
2005-10-30 10:58:13 +01:00
|
|
|
if nofetch:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Create a closure object
|
|
|
|
cbkey = ('items', addr)
|
|
|
|
cb = Closure(cb, userargs = args, remove = self._clean_closure,
|
|
|
|
removeargs = cbkey)
|
|
|
|
# Are we already fetching this?
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
self._cbs[cbkey].append(cb)
|
|
|
|
else:
|
|
|
|
self._cbs[cbkey] = [cb]
|
|
|
|
gajim.connections[self.account].discoverItems(jid, node)
|
|
|
|
|
|
|
|
def agent_info(self, jid, node, identities, features, data):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for when we receive an agent's info.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid, node)
|
2005-11-16 13:50:18 +01:00
|
|
|
|
|
|
|
# Store in cache
|
|
|
|
self._info[addr] = (identities, features, data)
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
# Call callbacks
|
|
|
|
cbkey = ('info', addr)
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
for cb in self._cbs[cbkey]:
|
|
|
|
cb(jid, node, identities, features, data)
|
|
|
|
# clean_closure may have beaten us to it
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
del self._cbs[cbkey]
|
|
|
|
|
|
|
|
def agent_items(self, jid, node, items):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for when we receive an agent's items.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid, node)
|
2005-11-16 13:50:18 +01:00
|
|
|
|
|
|
|
# Store in cache
|
|
|
|
self._items[addr] = items
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
# Call callbacks
|
|
|
|
cbkey = ('items', addr)
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
for cb in self._cbs[cbkey]:
|
|
|
|
cb(jid, node, items)
|
|
|
|
# clean_closure may have beaten us to it
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
del self._cbs[cbkey]
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def agent_info_error(self, jid):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for when a query fails. (even after the browse and agents
|
|
|
|
namespaces)'''
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid)
|
2005-11-16 13:50:18 +01:00
|
|
|
|
|
|
|
# Call callbacks
|
2005-10-30 10:58:13 +01:00
|
|
|
cbkey = ('info', addr)
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
for cb in self._cbs[cbkey]:
|
|
|
|
cb(jid, '', 0, 0, 0)
|
|
|
|
# clean_closure may have beaten us to it
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
del self._cbs[cbkey]
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def agent_items_error(self, jid):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for when a query fails. (even after the browse and agents
|
|
|
|
namespaces)'''
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid)
|
2005-11-16 13:50:18 +01:00
|
|
|
|
|
|
|
# Call callbacks
|
2005-10-30 10:58:13 +01:00
|
|
|
cbkey = ('items', addr)
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
for cb in self._cbs[cbkey]:
|
|
|
|
cb(jid, '', 0)
|
|
|
|
# clean_closure may have beaten us to it
|
2008-10-07 22:41:59 +02:00
|
|
|
if cbkey in self._cbs:
|
2005-10-30 10:58:13 +01:00
|
|
|
del self._cbs[cbkey]
|
|
|
|
|
2006-11-18 21:52:28 +01:00
|
|
|
# object is needed so that @property works
|
2006-04-25 21:38:08 +02:00
|
|
|
class ServiceDiscoveryWindow(object):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Class that represents the Services Discovery window.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
def __init__(self, account, jid = '', node = '',
|
|
|
|
address_entry = False, parent = None):
|
2006-11-18 21:52:28 +01:00
|
|
|
self.account = account
|
2005-10-30 10:58:13 +01:00
|
|
|
self.parent = parent
|
|
|
|
if not jid:
|
|
|
|
jid = gajim.config.get_per('accounts', account, 'hostname')
|
|
|
|
node = ''
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
self.jid = None
|
|
|
|
self.browser = None
|
|
|
|
self.children = []
|
|
|
|
self.dying = False
|
2008-12-03 20:56:37 +01:00
|
|
|
self.node = None
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
# Check connection
|
|
|
|
if gajim.connections[account].connected < 2:
|
|
|
|
dialogs.ErrorDialog(_('You are not connected to the server'),
|
2006-04-02 18:11:21 +02:00
|
|
|
_('Without a connection, you can not browse available services'))
|
2005-10-30 10:58:13 +01:00
|
|
|
raise RuntimeError, 'You must be connected to browse services'
|
|
|
|
|
|
|
|
# Get a ServicesCache object.
|
|
|
|
try:
|
|
|
|
self.cache = gajim.connections[account].services_cache
|
|
|
|
except AttributeError:
|
|
|
|
self.cache = ServicesCache(account)
|
|
|
|
gajim.connections[account].services_cache = self.cache
|
|
|
|
|
2006-05-02 17:53:25 +02:00
|
|
|
self.xml = gtkgui_helpers.get_glade('service_discovery_window.glade')
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window = self.xml.get_widget('service_discovery_window')
|
|
|
|
self.services_treeview = self.xml.get_widget('services_treeview')
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model = None
|
2005-10-30 10:58:13 +01:00
|
|
|
# This is more reliable than the cursor-changed signal.
|
|
|
|
selection = self.services_treeview.get_selection()
|
2005-12-06 18:43:21 +01:00
|
|
|
selection.connect_after('changed',
|
|
|
|
self.on_services_treeview_selection_changed)
|
2005-10-30 10:58:13 +01:00
|
|
|
self.services_scrollwin = self.xml.get_widget('services_scrollwin')
|
|
|
|
self.progressbar = self.xml.get_widget('services_progressbar')
|
|
|
|
self.banner = self.xml.get_widget('banner_agent_label')
|
2005-10-30 13:53:42 +01:00
|
|
|
self.banner_icon = self.xml.get_widget('banner_agent_icon')
|
2005-10-30 10:58:13 +01:00
|
|
|
self.banner_eventbox = self.xml.get_widget('banner_agent_eventbox')
|
2006-03-25 02:40:49 +01:00
|
|
|
self.style_event_id = 0
|
2006-03-25 03:07:02 +01:00
|
|
|
self.banner.realize()
|
2005-10-30 10:58:13 +01:00
|
|
|
self.paint_banner()
|
|
|
|
self.action_buttonbox = self.xml.get_widget('action_buttonbox')
|
|
|
|
|
|
|
|
# Address combobox
|
|
|
|
self.address_comboboxentry = None
|
2006-06-15 10:36:19 +02:00
|
|
|
address_table = self.xml.get_widget('address_table')
|
2005-10-30 10:58:13 +01:00
|
|
|
if address_entry:
|
2005-12-06 18:43:21 +01:00
|
|
|
self.address_comboboxentry = self.xml.get_widget(
|
|
|
|
'address_comboboxentry')
|
2005-10-30 10:58:13 +01:00
|
|
|
self.address_comboboxentry_entry = self.address_comboboxentry.child
|
|
|
|
self.address_comboboxentry_entry.set_activates_default(True)
|
|
|
|
|
|
|
|
liststore = gtk.ListStore(str)
|
|
|
|
self.address_comboboxentry.set_model(liststore)
|
2005-12-06 18:43:21 +01:00
|
|
|
self.latest_addresses = gajim.config.get(
|
|
|
|
'latest_disco_addresses').split()
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid in self.latest_addresses:
|
|
|
|
self.latest_addresses.remove(jid)
|
|
|
|
self.latest_addresses.insert(0, jid)
|
|
|
|
if len(self.latest_addresses) > 10:
|
|
|
|
self.latest_addresses = self.latest_addresses[0:10]
|
|
|
|
for j in self.latest_addresses:
|
|
|
|
self.address_comboboxentry.append_text(j)
|
|
|
|
self.address_comboboxentry.child.set_text(jid)
|
|
|
|
else:
|
|
|
|
# Don't show it at all if we didn't ask for it
|
2006-06-15 10:36:19 +02:00
|
|
|
address_table.set_no_show_all(True)
|
|
|
|
address_table.hide()
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
self._initial_state()
|
|
|
|
self.xml.signal_autoconnect(self)
|
|
|
|
self.travel(jid, node)
|
|
|
|
self.window.show_all()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2006-11-18 21:52:28 +01:00
|
|
|
@property
|
2005-10-30 10:58:13 +01:00
|
|
|
def _get_account(self):
|
2006-11-18 21:52:28 +01:00
|
|
|
return self.account
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2006-11-18 21:52:28 +01:00
|
|
|
@property
|
2005-10-30 10:58:13 +01:00
|
|
|
def _set_account(self, value):
|
2006-11-18 21:52:28 +01:00
|
|
|
self.account = value
|
2005-10-30 10:58:13 +01:00
|
|
|
self.cache.account = value
|
|
|
|
if self.browser:
|
|
|
|
self.browser.account = value
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _initial_state(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Set some initial state on the window. Separated in a method because
|
|
|
|
it's handy to use within browser's cleanup method.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
self.progressbar.hide()
|
2006-11-18 21:52:28 +01:00
|
|
|
title_text = _('Service Discovery using account %s') % self.account
|
|
|
|
self.window.set_title(title_text)
|
2006-03-19 22:25:28 +01:00
|
|
|
self._set_window_banner_text(_('Service Discovery'))
|
2007-01-17 00:26:38 +01:00
|
|
|
self.banner_icon.clear()
|
2006-11-18 21:52:28 +01:00
|
|
|
self.banner_icon.hide() # Just clearing it doesn't work
|
2005-10-30 10:58:13 +01:00
|
|
|
|
2006-03-19 22:25:28 +01:00
|
|
|
def _set_window_banner_text(self, text, text_after = None):
|
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
bannerfont = gajim.config.get_per('themes', theme, 'bannerfont')
|
2006-11-18 21:52:28 +01:00
|
|
|
bannerfontattrs = gajim.config.get_per('themes', theme,
|
|
|
|
'bannerfontattrs')
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-03-19 22:25:28 +01:00
|
|
|
if bannerfont:
|
|
|
|
font = pango.FontDescription(bannerfont)
|
|
|
|
else:
|
|
|
|
font = pango.FontDescription('Normal')
|
|
|
|
if bannerfontattrs:
|
|
|
|
# B is attribute set by default
|
|
|
|
if 'B' in bannerfontattrs:
|
|
|
|
font.set_weight(pango.WEIGHT_HEAVY)
|
|
|
|
if 'I' in bannerfontattrs:
|
|
|
|
font.set_style(pango.STYLE_ITALIC)
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-03-19 22:25:28 +01:00
|
|
|
font_attrs = 'font_desc="%s"' % font.to_string()
|
|
|
|
font_size = font.get_size()
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-03-19 22:25:28 +01:00
|
|
|
# in case there is no font specified we use x-large font size
|
|
|
|
if font_size == 0:
|
|
|
|
font_attrs = '%s size="large"' % font_attrs
|
|
|
|
markup = '<span %s>%s</span>' % (font_attrs, text)
|
|
|
|
if text_after:
|
|
|
|
font.set_weight(pango.WEIGHT_NORMAL)
|
2006-03-20 17:04:54 +01:00
|
|
|
markup = '%s\n<span font_desc="%s" size="small">%s</span>' % \
|
2006-03-19 22:25:28 +01:00
|
|
|
(markup, font.to_string(), text_after)
|
|
|
|
self.banner.set_markup(markup)
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def paint_banner(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Repaint the banner with theme color'''
|
2005-10-30 10:58:13 +01:00
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
bgcolor = gajim.config.get_per('themes', theme, 'bannerbgcolor')
|
|
|
|
textcolor = gajim.config.get_per('themes', theme, 'bannertextcolor')
|
2006-03-25 02:40:49 +01:00
|
|
|
self.disconnect_style_event()
|
2005-11-17 09:27:16 +01:00
|
|
|
if bgcolor:
|
|
|
|
color = gtk.gdk.color_parse(bgcolor)
|
2006-03-25 02:40:49 +01:00
|
|
|
self.banner_eventbox.modify_bg(gtk.STATE_NORMAL, color)
|
|
|
|
default_bg = False
|
2005-11-17 09:27:16 +01:00
|
|
|
else:
|
2006-03-25 02:40:49 +01:00
|
|
|
default_bg = True
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2005-11-17 09:27:16 +01:00
|
|
|
if textcolor:
|
|
|
|
color = gtk.gdk.color_parse(textcolor)
|
2006-03-25 02:40:49 +01:00
|
|
|
self.banner.modify_fg(gtk.STATE_NORMAL, color)
|
|
|
|
default_fg = False
|
2005-11-17 09:27:16 +01:00
|
|
|
else:
|
2006-03-25 02:40:49 +01:00
|
|
|
default_fg = True
|
|
|
|
if default_fg or default_bg:
|
|
|
|
self._on_style_set_event(self.banner, None, default_fg, default_bg)
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.browser:
|
|
|
|
self.browser.update_theme()
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-03-25 02:40:49 +01:00
|
|
|
def disconnect_style_event(self):
|
|
|
|
if self.style_event_id:
|
|
|
|
self.banner.disconnect(self.style_event_id)
|
|
|
|
self.style_event_id = 0
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-03-25 02:40:49 +01:00
|
|
|
def connect_style_event(self, set_fg = False, set_bg = False):
|
|
|
|
self.disconnect_style_event()
|
2008-12-03 22:56:12 +01:00
|
|
|
self.style_event_id = self.banner.connect('style-set',
|
2006-03-25 02:40:49 +01:00
|
|
|
self._on_style_set_event, set_fg, set_bg)
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-03-25 02:40:49 +01:00
|
|
|
def _on_style_set_event(self, widget, style, *opts):
|
2008-12-03 22:56:12 +01:00
|
|
|
''' set style of widget from style class *.Frame.Eventbox
|
2006-03-25 02:40:49 +01:00
|
|
|
opts[0] == True -> set fg color
|
|
|
|
opts[1] == True -> set bg color '''
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-03-25 02:40:49 +01:00
|
|
|
self.disconnect_style_event()
|
|
|
|
if opts[1]:
|
|
|
|
bg_color = widget.style.bg[gtk.STATE_SELECTED]
|
|
|
|
self.banner_eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
|
|
|
|
if opts[0]:
|
|
|
|
fg_color = widget.style.fg[gtk.STATE_SELECTED]
|
|
|
|
self.banner.modify_fg(gtk.STATE_NORMAL, fg_color)
|
|
|
|
self.banner.ensure_style()
|
|
|
|
self.connect_style_event(opts[0], opts[1])
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def destroy(self, chain = False):
|
2006-08-20 12:18:20 +02:00
|
|
|
'''Close the browser. This can optionally close its children and
|
2005-10-30 10:58:13 +01:00
|
|
|
propagate to the parent. This should happen on actions like register,
|
2005-11-02 12:03:42 +01:00
|
|
|
or join to kill off the entire browser chain.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.dying:
|
|
|
|
return
|
|
|
|
self.dying = True
|
|
|
|
|
|
|
|
# self.browser._get_agent_address() would break when no browser.
|
|
|
|
addr = get_agent_address(self.jid, self.node)
|
2009-02-09 20:46:26 +01:00
|
|
|
if addr in gajim.interface.instances[self.account]['disco']:
|
|
|
|
del gajim.interface.instances[self.account]['disco'][addr]
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
if self.browser:
|
|
|
|
self.window.hide()
|
|
|
|
self.browser.cleanup()
|
|
|
|
self.browser = None
|
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
for child in self.children[:]:
|
|
|
|
child.parent = None
|
|
|
|
if chain:
|
|
|
|
child.destroy(chain = chain)
|
|
|
|
self.children.remove(child)
|
|
|
|
if self.parent:
|
2006-08-20 12:18:20 +02:00
|
|
|
if self in self.parent.children:
|
|
|
|
self.parent.children.remove(self)
|
2005-10-30 10:58:13 +01:00
|
|
|
if chain and not self.parent.children:
|
|
|
|
self.parent.destroy(chain = chain)
|
|
|
|
self.parent = None
|
2006-12-11 00:01:37 +01:00
|
|
|
else:
|
|
|
|
self.cache.cleanup()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def travel(self, jid, node):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Travel to an agent within the current services window.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.browser:
|
|
|
|
self.browser.cleanup()
|
|
|
|
self.browser = None
|
|
|
|
# Update the window list
|
|
|
|
if self.jid:
|
|
|
|
old_addr = get_agent_address(self.jid, self.node)
|
2008-10-07 22:41:59 +02:00
|
|
|
if old_addr in gajim.interface.instances[self.account]['disco']:
|
2005-11-13 16:08:47 +01:00
|
|
|
del gajim.interface.instances[self.account]['disco'][old_addr]
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid, node)
|
2005-11-13 16:08:47 +01:00
|
|
|
gajim.interface.instances[self.account]['disco'][addr] = self
|
2005-10-30 10:58:13 +01:00
|
|
|
# We need to store these, self.browser is not always available.
|
|
|
|
self.jid = jid
|
|
|
|
self.node = node
|
|
|
|
self.cache.get_info(jid, node, self._travel)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _travel(self, jid, node, identities, features, data):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Continuation of travel.'''
|
2005-11-20 13:35:01 +01:00
|
|
|
if self.dying or jid != self.jid or node != self.node:
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
|
|
|
if not identities:
|
|
|
|
if not self.address_comboboxentry:
|
|
|
|
# We can't travel anywhere else.
|
|
|
|
self.destroy()
|
|
|
|
dialogs.ErrorDialog(_('The service could not be found'),
|
2006-04-02 18:11:21 +02:00
|
|
|
_('There is no service at the address you entered, or it is not responding. Check the address and try again.'))
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
|
|
|
klass = self.cache.get_browser(identities, features)
|
|
|
|
if not klass:
|
|
|
|
dialogs.ErrorDialog(_('The service is not browsable'),
|
2006-04-02 18:11:21 +02:00
|
|
|
_('This type of service does not contain any items to browse.'))
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
|
|
|
elif klass is None:
|
|
|
|
klass = AgentBrowser
|
|
|
|
self.browser = klass(self.account, jid, node)
|
|
|
|
self.browser.prepare_window(self)
|
|
|
|
self.browser.browse()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def open(self, jid, node):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Open an agent. By default, this happens in a new window.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
try:
|
2005-11-13 16:08:47 +01:00
|
|
|
win = gajim.interface.instances[self.account]['disco']\
|
2005-10-30 10:58:13 +01:00
|
|
|
[get_agent_address(jid, node)]
|
|
|
|
win.window.present()
|
|
|
|
return
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
win = ServiceDiscoveryWindow(self.account, jid, node, parent=self)
|
|
|
|
except RuntimeError:
|
|
|
|
# Disconnected, perhaps
|
|
|
|
return
|
|
|
|
self.children.append(win)
|
|
|
|
|
|
|
|
def on_service_discovery_window_destroy(self, widget):
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
def on_close_button_clicked(self, widget):
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
def on_address_comboboxentry_changed(self, widget):
|
|
|
|
if self.address_comboboxentry.get_active() != -1:
|
|
|
|
# user selected one of the entries so do auto-visit
|
|
|
|
jid = self.address_comboboxentry.child.get_text().decode('utf-8')
|
2008-09-14 09:15:15 +02:00
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(jid)
|
|
|
|
except helpers.InvalidFormat, s:
|
|
|
|
pritext = _('Invalid Server Name')
|
|
|
|
dialogs.ErrorDialog(pritext, str(s))
|
|
|
|
return
|
2005-10-30 10:58:13 +01:00
|
|
|
self.travel(jid, '')
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def on_go_button_clicked(self, widget):
|
|
|
|
jid = self.address_comboboxentry.child.get_text().decode('utf-8')
|
2008-09-14 09:15:15 +02:00
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(jid)
|
|
|
|
except helpers.InvalidFormat, s:
|
|
|
|
pritext = _('Invalid Server Name')
|
|
|
|
dialogs.ErrorDialog(pritext, str(s))
|
|
|
|
return
|
2005-12-19 21:37:35 +01:00
|
|
|
if jid == self.jid: # jid has not changed
|
|
|
|
return
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid in self.latest_addresses:
|
|
|
|
self.latest_addresses.remove(jid)
|
|
|
|
self.latest_addresses.insert(0, jid)
|
|
|
|
if len(self.latest_addresses) > 10:
|
|
|
|
self.latest_addresses = self.latest_addresses[0:10]
|
|
|
|
self.address_comboboxentry.get_model().clear()
|
|
|
|
for j in self.latest_addresses:
|
|
|
|
self.address_comboboxentry.append_text(j)
|
|
|
|
gajim.config.set('latest_disco_addresses',
|
|
|
|
' '.join(self.latest_addresses))
|
|
|
|
gajim.interface.save_config()
|
|
|
|
self.travel(jid, '')
|
|
|
|
|
|
|
|
def on_services_treeview_row_activated(self, widget, path, col = 0):
|
2008-11-17 22:13:12 +01:00
|
|
|
if self.browser:
|
|
|
|
self.browser.default_action()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def on_services_treeview_selection_changed(self, widget):
|
2008-11-17 22:13:12 +01:00
|
|
|
if self.browser:
|
|
|
|
self.browser.update_actions()
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AgentBrowser:
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Class that deals with browsing agents and appearance of the browser
|
2005-10-30 10:58:13 +01:00
|
|
|
window. This class and subclasses should basically be treated as "part"
|
|
|
|
of the ServiceDiscoveryWindow class, but had to be separated because this part
|
2005-11-02 12:03:42 +01:00
|
|
|
is dynamic.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
def __init__(self, account, jid, node):
|
|
|
|
self.account = account
|
|
|
|
self.jid = jid
|
|
|
|
self.node = node
|
|
|
|
self._total_items = 0
|
|
|
|
self.browse_button = None
|
|
|
|
# This is for some timeout callbacks
|
|
|
|
self.active = False
|
|
|
|
|
|
|
|
def _get_agent_address(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Returns the agent's address for displaying in the GUI.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
return get_agent_address(self.jid, self.node)
|
|
|
|
|
|
|
|
def _set_initial_title(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Set the initial window title based on agent address.'''
|
2008-08-01 11:30:36 +02:00
|
|
|
self.window.window.set_title(_('Browsing %(address)s using account '
|
|
|
|
'%(account)s') % {'address': self._get_agent_address(),
|
|
|
|
'account': self.account})
|
2006-03-19 22:25:28 +01:00
|
|
|
self.window._set_window_banner_text(self._get_agent_address())
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
def _create_treemodel(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Create the treemodel for the services treeview. When subclassing,
|
2005-10-30 10:58:13 +01:00
|
|
|
note that the first two columns should ALWAYS be of type string and
|
2005-11-02 12:03:42 +01:00
|
|
|
contain the JID and node of the item respectively.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
# JID, node, name, address
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model = gtk.ListStore(str, str, str, str)
|
|
|
|
self.model.set_sort_column_id(3, gtk.SORT_ASCENDING)
|
|
|
|
self.window.services_treeview.set_model(self.model)
|
2005-10-30 10:58:13 +01:00
|
|
|
# Name column
|
|
|
|
col = gtk.TreeViewColumn(_('Name'))
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
|
|
|
col.set_attributes(renderer, text = 2)
|
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
|
|
|
col.set_resizable(True)
|
|
|
|
# Address column
|
|
|
|
col = gtk.TreeViewColumn(_('JID'))
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
|
|
|
col.set_attributes(renderer, text = 3)
|
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
|
|
|
col.set_resizable(True)
|
|
|
|
self.window.services_treeview.set_headers_visible(True)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _clean_treemodel(self):
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model.clear()
|
2005-10-30 10:58:13 +01:00
|
|
|
for col in self.window.services_treeview.get_columns():
|
|
|
|
self.window.services_treeview.remove_column(col)
|
|
|
|
self.window.services_treeview.set_headers_visible(False)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _add_actions(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Add the action buttons to the buttonbox for actions the browser can
|
|
|
|
perform.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
self.browse_button = gtk.Button()
|
|
|
|
image = gtk.image_new_from_stock(gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON)
|
|
|
|
label = gtk.Label(_('_Browse'))
|
|
|
|
label.set_use_underline(True)
|
|
|
|
hbox = gtk.HBox()
|
|
|
|
hbox.pack_start(image, False, True, 6)
|
|
|
|
hbox.pack_end(label, True, True)
|
|
|
|
self.browse_button.add(hbox)
|
|
|
|
self.browse_button.connect('clicked', self.on_browse_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.browse_button)
|
|
|
|
self.browse_button.show_all()
|
|
|
|
|
|
|
|
def _clean_actions(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Remove the action buttons specific to this browser.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.browse_button:
|
|
|
|
self.browse_button.destroy()
|
|
|
|
self.browse_button = None
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _set_title(self, jid, node, identities, features, data):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Set the window title based on agent info.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
# Set the banner and window title
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'name' in identities[0]:
|
2005-10-30 10:58:13 +01:00
|
|
|
name = identities[0]['name']
|
2006-03-19 22:25:28 +01:00
|
|
|
self.window._set_window_banner_text(self._get_agent_address(), name)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
# Add an icon to the banner.
|
2005-11-19 21:33:49 +01:00
|
|
|
pix = self.cache.get_icon(identities)
|
2005-10-30 13:53:42 +01:00
|
|
|
self.window.banner_icon.set_from_pixbuf(pix)
|
|
|
|
self.window.banner_icon.show()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _clean_title(self):
|
2005-10-30 13:53:42 +01:00
|
|
|
# Everything done here is done in window._initial_state
|
|
|
|
# This is for subclasses.
|
|
|
|
pass
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
def prepare_window(self, window):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Prepare the service discovery window. Called when a browser is hooked
|
|
|
|
up with a ServiceDiscoveryWindow instance.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window = window
|
|
|
|
self.cache = window.cache
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
self._set_initial_title()
|
2005-12-19 21:37:35 +01:00
|
|
|
self._create_treemodel()
|
|
|
|
self._add_actions()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
# This is a hack. The buttonbox apparently doesn't care about pack_start
|
|
|
|
# or pack_end, so we repack the close button here to make sure it's last
|
|
|
|
close_button = self.window.xml.get_widget('close_button')
|
|
|
|
self.window.action_buttonbox.remove(close_button)
|
|
|
|
self.window.action_buttonbox.pack_end(close_button)
|
|
|
|
close_button.show_all()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
self.update_actions()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
self.active = True
|
|
|
|
self.cache.get_info(self.jid, self.node, self._set_title)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def cleanup(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Cleanup when the window intends to switch browsers.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
self.active = False
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
self._clean_actions()
|
|
|
|
self._clean_treemodel()
|
|
|
|
self._clean_title()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window._initial_state()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def update_theme(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Called when the default theme is changed.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
pass
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def on_browse_button_clicked(self, widget = None):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''When we want to browse an agent:
|
|
|
|
Open a new services window with a browser for the agent type.'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
jid = model[iter_][0].decode('utf-8')
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid:
|
2008-12-03 18:16:04 +01:00
|
|
|
node = model[iter_][1].decode('utf-8')
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window.open(jid, node)
|
2005-12-05 14:33:14 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def update_actions(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''When we select a row:
|
|
|
|
activate action buttons based on the agent's info.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.browse_button:
|
|
|
|
self.browse_button.set_sensitive(False)
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
jid = model[iter_][0].decode('utf-8')
|
|
|
|
node = model[iter_][1].decode('utf-8')
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid:
|
|
|
|
self.cache.get_info(jid, node, self._update_actions, nofetch = True)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _update_actions(self, jid, node, identities, features, data):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Continuation of update_actions.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if not identities or not self.browse_button:
|
|
|
|
return
|
|
|
|
klass = self.cache.get_browser(identities, features)
|
|
|
|
if klass:
|
|
|
|
self.browse_button.set_sensitive(True)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def default_action(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''When we double-click a row:
|
|
|
|
perform the default action on the selected item.'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
jid = model[iter_][0].decode('utf-8')
|
|
|
|
node = model[iter_][1].decode('utf-8')
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid:
|
|
|
|
self.cache.get_info(jid, node, self._default_action, nofetch = True)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _default_action(self, jid, node, identities, features, data):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Continuation of default_action.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.cache.get_browser(identities, features):
|
|
|
|
# Browse if we can
|
|
|
|
self.on_browse_button_clicked()
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def browse(self, force = False):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Fill the treeview with agents, fetching the info if necessary.'''
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model.clear()
|
2005-10-30 10:58:13 +01:00
|
|
|
self._total_items = self._progress = 0
|
|
|
|
self.window.progressbar.show()
|
|
|
|
self._pulse_timeout = gobject.timeout_add(250, self._pulse_timeout_cb)
|
2005-12-06 18:43:21 +01:00
|
|
|
self.cache.get_items(self.jid, self.node, self._agent_items,
|
2005-10-30 10:58:13 +01:00
|
|
|
force = force, args = (force,))
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _pulse_timeout_cb(self, *args):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Simple callback to keep the progressbar pulsing.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if not self.active:
|
|
|
|
return False
|
|
|
|
self.window.progressbar.pulse()
|
|
|
|
return True
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _find_item(self, jid, node):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Check if an item is already in the treeview. Return an iter to it
|
|
|
|
if so, None otherwise.'''
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self.model.get_iter_root()
|
|
|
|
while iter_:
|
|
|
|
cjid = self.model.get_value(iter_, 0).decode('utf-8')
|
|
|
|
cnode = self.model.get_value(iter_, 1).decode('utf-8')
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid == cjid and node == cnode:
|
|
|
|
break
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self.model.iter_next(iter_)
|
|
|
|
if iter_:
|
|
|
|
return iter_
|
2005-10-30 10:58:13 +01:00
|
|
|
return None
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _agent_items(self, jid, node, items, force):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for when we receive a list of agent items.'''
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model.clear()
|
|
|
|
self._total_items = 0
|
2005-10-30 10:58:13 +01:00
|
|
|
gobject.source_remove(self._pulse_timeout)
|
|
|
|
self.window.progressbar.hide()
|
|
|
|
# The server returned an error
|
|
|
|
if items == 0:
|
|
|
|
if not self.window.address_comboboxentry:
|
|
|
|
# We can't travel anywhere else.
|
|
|
|
self.window.destroy()
|
|
|
|
dialogs.ErrorDialog(_('The service is not browsable'),
|
2006-04-02 18:11:21 +02:00
|
|
|
_('This service does not contain any items to browse.'))
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
|
|
|
# We got a list of items
|
2006-11-18 21:52:28 +01:00
|
|
|
self.window.services_treeview.set_model(None)
|
2005-10-30 10:58:13 +01:00
|
|
|
for item in items:
|
|
|
|
jid = item['jid']
|
|
|
|
node = item.get('node', '')
|
2008-08-29 12:38:34 +02:00
|
|
|
# If such an item is already here: don't add it
|
|
|
|
if self._find_item(jid, node):
|
|
|
|
continue
|
2006-11-18 21:52:28 +01:00
|
|
|
self._total_items += 1
|
|
|
|
self._add_item(jid, node, item, force)
|
|
|
|
self.window.services_treeview.set_model(self.model)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _agent_info(self, jid, node, identities, features, data):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for when we receive info about an agent's item.'''
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self._find_item(jid, node)
|
|
|
|
if not iter_:
|
2005-10-30 10:58:13 +01:00
|
|
|
# Not in the treeview, stop
|
|
|
|
return
|
|
|
|
if identities == 0:
|
|
|
|
# The server returned an error
|
2008-12-03 18:16:04 +01:00
|
|
|
self._update_error(iter_, jid, node)
|
2005-10-30 10:58:13 +01:00
|
|
|
else:
|
|
|
|
# We got our info
|
2008-12-03 18:16:04 +01:00
|
|
|
self._update_info(iter_, jid, node, identities, features, data)
|
2005-10-30 10:58:13 +01:00
|
|
|
self.update_actions()
|
|
|
|
|
2006-11-18 21:52:28 +01:00
|
|
|
def _add_item(self, jid, node, item, force):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Called when an item should be added to the model. The result of a
|
|
|
|
disco#items query.'''
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model.append((jid, node, item.get('name', ''),
|
2005-10-30 10:58:13 +01:00
|
|
|
get_agent_address(jid, node)))
|
2007-10-22 10:54:07 +02:00
|
|
|
self.cache.get_info(jid, node, self._agent_info, force = force)
|
2005-10-30 10:58:13 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _update_item(self, iter_, jid, node, item):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Called when an item should be updated in the model. The result of a
|
|
|
|
disco#items query. (seldom)'''
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'name' in item:
|
2008-10-11 12:22:04 +02:00
|
|
|
self.model[iter_][2] = item['name']
|
2005-10-30 10:58:13 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _update_info(self, iter_, jid, node, identities, features, data):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Called when an item should be updated in the model with further info.
|
|
|
|
The result of a disco#info query.'''
|
2007-10-22 10:54:07 +02:00
|
|
|
name = identities[0].get('name', '')
|
|
|
|
if name:
|
2008-10-11 12:22:04 +02:00
|
|
|
self.model[iter_][2] = name
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _update_error(self, iter_, jid, node):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Called when a disco#info query failed for an item.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ToplevelAgentBrowser(AgentBrowser):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''This browser is used at the top level of a jabber server to browse
|
|
|
|
services such as transports, conference servers, etc.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
def __init__(self, *args):
|
|
|
|
AgentBrowser.__init__(self, *args)
|
|
|
|
self._progressbar_sourceid = None
|
|
|
|
self._renderer = None
|
|
|
|
self._progress = 0
|
2005-10-30 15:33:25 +01:00
|
|
|
self.tooltip = tooltips.ServiceDiscoveryTooltip()
|
2005-10-30 10:58:13 +01:00
|
|
|
self.register_button = None
|
2005-12-12 08:52:18 +01:00
|
|
|
self.join_button = None
|
2007-01-18 10:12:03 +01:00
|
|
|
self.execute_button = None
|
2007-04-19 15:31:28 +02:00
|
|
|
self.search_button = None
|
2005-10-30 15:33:25 +01:00
|
|
|
# Keep track of our treeview signals
|
|
|
|
self._view_signals = []
|
|
|
|
self._scroll_signal = None
|
2005-10-30 10:58:13 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _pixbuf_renderer_data_func(self, col, cell, model, iter_):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for setting the pixbuf renderer's properties.'''
|
2008-10-11 12:22:04 +02:00
|
|
|
jid = model.get_value(iter_, 0)
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid:
|
2008-10-11 12:22:04 +02:00
|
|
|
pix = model.get_value(iter_, 2)
|
2005-10-30 10:58:13 +01:00
|
|
|
cell.set_property('visible', True)
|
|
|
|
cell.set_property('pixbuf', pix)
|
|
|
|
else:
|
|
|
|
cell.set_property('visible', False)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _text_renderer_data_func(self, col, cell, model, iter_):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for setting the text renderer's properties.'''
|
2008-10-11 12:22:04 +02:00
|
|
|
jid = model.get_value(iter_, 0)
|
|
|
|
markup = model.get_value(iter_, 3)
|
|
|
|
state = model.get_value(iter_, 4)
|
2005-10-30 10:58:13 +01:00
|
|
|
cell.set_property('markup', markup)
|
|
|
|
if jid:
|
|
|
|
cell.set_property('cell_background_set', False)
|
|
|
|
if state > 0:
|
|
|
|
# 1 = fetching, 2 = error
|
|
|
|
cell.set_property('foreground_set', True)
|
|
|
|
else:
|
|
|
|
# Normal/succes
|
|
|
|
cell.set_property('foreground_set', False)
|
|
|
|
else:
|
2005-11-17 09:27:16 +01:00
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
bgcolor = gajim.config.get_per('themes', theme, 'groupbgcolor')
|
|
|
|
if bgcolor:
|
|
|
|
cell.set_property('cell_background_set', True)
|
2005-10-30 10:58:13 +01:00
|
|
|
cell.set_property('foreground_set', False)
|
|
|
|
|
|
|
|
def _treemodel_sort_func(self, model, iter1, iter2):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Sort function for our treemodel.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
# Compare state
|
|
|
|
statecmp = cmp(model.get_value(iter1, 4), model.get_value(iter2, 4))
|
|
|
|
if statecmp == 0:
|
|
|
|
# These can be None, apparently
|
|
|
|
descr1 = model.get_value(iter1, 3)
|
|
|
|
if descr1:
|
|
|
|
descr1 = descr1.decode('utf-8')
|
|
|
|
descr2 = model.get_value(iter2, 3)
|
|
|
|
if descr2:
|
|
|
|
descr2 = descr2.decode('utf-8')
|
|
|
|
# Compare strings
|
|
|
|
return cmp(descr1, descr2)
|
|
|
|
return statecmp
|
|
|
|
|
2005-10-30 15:33:25 +01:00
|
|
|
def _show_tooltip(self, state):
|
|
|
|
view = self.window.services_treeview
|
|
|
|
pointer = view.get_pointer()
|
|
|
|
props = view.get_path_at_pos(pointer[0], pointer[1])
|
2006-02-28 11:13:42 +01:00
|
|
|
# check if the current pointer is at the same path
|
|
|
|
# as it was before setting the timeout
|
2005-10-30 15:33:25 +01:00
|
|
|
if props and self.tooltip.id == props[0]:
|
2006-02-28 11:13:42 +01:00
|
|
|
# bounding rectangle of coordinates for the cell within the treeview
|
2007-06-25 19:49:14 +02:00
|
|
|
rect = view.get_cell_area(props[0], props[1])
|
2006-02-28 11:13:42 +01:00
|
|
|
# position of the treeview on the screen
|
2005-10-30 15:33:25 +01:00
|
|
|
position = view.window.get_origin()
|
2006-02-28 11:13:42 +01:00
|
|
|
self.tooltip.show_tooltip(state, rect.height, position[1] + rect.y)
|
2005-10-30 15:33:25 +01:00
|
|
|
else:
|
|
|
|
self.tooltip.hide_tooltip()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 15:33:25 +01:00
|
|
|
# These are all callbacks to make tooltips work
|
|
|
|
def on_treeview_leave_notify_event(self, widget, event):
|
|
|
|
props = widget.get_path_at_pos(int(event.x), int(event.y))
|
|
|
|
if self.tooltip.timeout > 0:
|
|
|
|
if not props or self.tooltip.id == props[0]:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
|
|
|
|
def on_treeview_motion_notify_event(self, widget, event):
|
|
|
|
props = widget.get_path_at_pos(int(event.x), int(event.y))
|
|
|
|
if self.tooltip.timeout > 0:
|
|
|
|
if not props or self.tooltip.id != props[0]:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
if props:
|
2008-12-02 16:53:23 +01:00
|
|
|
row = props[0]
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = None
|
2005-10-30 15:33:25 +01:00
|
|
|
try:
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self.model.get_iter(row)
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception:
|
2005-10-30 15:33:25 +01:00
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
jid = self.model[iter_][0]
|
|
|
|
state = self.model[iter_][4]
|
2005-10-30 15:33:25 +01:00
|
|
|
# Not a category, and we have something to say about state
|
|
|
|
if jid and state > 0 and \
|
|
|
|
(self.tooltip.timeout == 0 or self.tooltip.id != props[0]):
|
|
|
|
self.tooltip.id = row
|
|
|
|
self.tooltip.timeout = gobject.timeout_add(500,
|
|
|
|
self._show_tooltip, state)
|
|
|
|
|
|
|
|
def on_treeview_event_hide_tooltip(self, widget, event):
|
|
|
|
''' This happens on scroll_event, key_press_event
|
|
|
|
and button_press_event '''
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _create_treemodel(self):
|
|
|
|
# JID, node, icon, description, state
|
|
|
|
# State means 2 when error, 1 when fetching, 0 when succes.
|
2005-12-18 13:31:42 +01:00
|
|
|
view = self.window.services_treeview
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model = gtk.TreeStore(str, str, gtk.gdk.Pixbuf, str, int)
|
|
|
|
self.model.set_sort_func(4, self._treemodel_sort_func)
|
|
|
|
self.model.set_sort_column_id(4, gtk.SORT_ASCENDING)
|
|
|
|
view.set_model(self.model)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
col = gtk.TreeViewColumn()
|
|
|
|
# Icon Renderer
|
|
|
|
renderer = gtk.CellRendererPixbuf()
|
|
|
|
renderer.set_property('xpad', 6)
|
|
|
|
col.pack_start(renderer, expand = False)
|
|
|
|
col.set_cell_data_func(renderer, self._pixbuf_renderer_data_func)
|
|
|
|
# Text Renderer
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer, expand = True)
|
|
|
|
col.set_cell_data_func(renderer, self._text_renderer_data_func)
|
|
|
|
renderer.set_property('foreground', 'dark gray')
|
|
|
|
# Save this so we can go along with theme changes
|
|
|
|
self._renderer = renderer
|
|
|
|
self.update_theme()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 15:33:25 +01:00
|
|
|
view.insert_column(col, -1)
|
2005-10-30 10:58:13 +01:00
|
|
|
col.set_resizable(True)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 15:33:25 +01:00
|
|
|
# Connect signals
|
|
|
|
scrollwin = self.window.services_scrollwin
|
|
|
|
self._view_signals.append(view.connect('leave-notify-event',
|
|
|
|
self.on_treeview_leave_notify_event))
|
|
|
|
self._view_signals.append(view.connect('motion-notify-event',
|
|
|
|
self.on_treeview_motion_notify_event))
|
|
|
|
self._view_signals.append(view.connect('key-press-event',
|
|
|
|
self.on_treeview_event_hide_tooltip))
|
|
|
|
self._view_signals.append(view.connect('button-press-event',
|
|
|
|
self.on_treeview_event_hide_tooltip))
|
|
|
|
self._scroll_signal = scrollwin.connect('scroll-event',
|
|
|
|
self.on_treeview_event_hide_tooltip)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 15:33:25 +01:00
|
|
|
def _clean_treemodel(self):
|
|
|
|
# Disconnect signals
|
|
|
|
view = self.window.services_treeview
|
|
|
|
for sig in self._view_signals:
|
|
|
|
view.disconnect(sig)
|
|
|
|
self._view_signals = []
|
|
|
|
if self._scroll_signal:
|
|
|
|
scrollwin = self.window.services_scrollwin
|
|
|
|
scrollwin.disconnect(self._scroll_signal)
|
|
|
|
self._scroll_signal = None
|
|
|
|
AgentBrowser._clean_treemodel(self)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _add_actions(self):
|
|
|
|
AgentBrowser._add_actions(self)
|
2007-01-18 10:12:03 +01:00
|
|
|
self.execute_button = gtk.Button()
|
|
|
|
image = gtk.image_new_from_stock(gtk.STOCK_EXECUTE, gtk.ICON_SIZE_BUTTON)
|
2007-04-19 15:31:28 +02:00
|
|
|
label = gtk.Label(_('_Execute Command'))
|
2007-01-18 10:12:03 +01:00
|
|
|
label.set_use_underline(True)
|
|
|
|
hbox = gtk.HBox()
|
|
|
|
hbox.pack_start(image, False, True, 6)
|
|
|
|
hbox.pack_end(label, True, True)
|
|
|
|
self.execute_button.add(hbox)
|
|
|
|
self.execute_button.connect('clicked', self.on_execute_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.execute_button)
|
|
|
|
self.execute_button.show_all()
|
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
self.register_button = gtk.Button(label=_("Re_gister"),
|
|
|
|
use_underline=True)
|
|
|
|
self.register_button.connect('clicked', self.on_register_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.register_button)
|
|
|
|
self.register_button.show_all()
|
|
|
|
|
2005-12-05 14:33:14 +01:00
|
|
|
self.join_button = gtk.Button()
|
|
|
|
image = gtk.image_new_from_stock(gtk.STOCK_CONNECT, gtk.ICON_SIZE_BUTTON)
|
|
|
|
label = gtk.Label(_('_Join'))
|
|
|
|
label.set_use_underline(True)
|
|
|
|
hbox = gtk.HBox()
|
|
|
|
hbox.pack_start(image, False, True, 6)
|
|
|
|
hbox.pack_end(label, True, True)
|
|
|
|
self.join_button.add(hbox)
|
|
|
|
self.join_button.connect('clicked', self.on_join_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.join_button)
|
|
|
|
self.join_button.show_all()
|
|
|
|
|
2007-04-19 15:31:28 +02:00
|
|
|
self.search_button = gtk.Button()
|
|
|
|
image = gtk.image_new_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_BUTTON)
|
|
|
|
label = gtk.Label(_('_Search'))
|
|
|
|
label.set_use_underline(True)
|
|
|
|
hbox = gtk.HBox()
|
|
|
|
hbox.pack_start(image, False, True, 6)
|
|
|
|
hbox.pack_end(label, True, True)
|
|
|
|
self.search_button.add(hbox)
|
|
|
|
self.search_button.connect('clicked', self.on_search_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.search_button)
|
|
|
|
self.search_button.show_all()
|
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _clean_actions(self):
|
2007-01-18 10:12:03 +01:00
|
|
|
if self.execute_button:
|
|
|
|
self.execute_button.destroy()
|
|
|
|
self.execute_button = None
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.register_button:
|
|
|
|
self.register_button.destroy()
|
|
|
|
self.register_button = None
|
2005-12-12 08:52:18 +01:00
|
|
|
if self.join_button:
|
|
|
|
self.join_button.destroy()
|
|
|
|
self.join_button = None
|
2007-04-19 15:31:28 +02:00
|
|
|
if self.search_button:
|
|
|
|
self.search_button.destroy()
|
|
|
|
self.search_button = None
|
|
|
|
AgentBrowser._clean_actions(self)
|
|
|
|
|
|
|
|
def on_search_button_clicked(self, widget = None):
|
|
|
|
'''When we want to search something:
|
|
|
|
open search window'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2007-04-19 15:31:28 +02:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
service = model[iter_][0].decode('utf-8')
|
2008-10-07 22:41:59 +02:00
|
|
|
if service in gajim.interface.instances[self.account]['search']:
|
2009-06-04 17:34:38 +02:00
|
|
|
gajim.interface.instances[self.account]['search'][service].window.\
|
|
|
|
present()
|
2007-04-19 15:31:28 +02:00
|
|
|
else:
|
|
|
|
gajim.interface.instances[self.account]['search'][service] = \
|
2007-04-19 16:26:21 +02:00
|
|
|
search_window.SearchWindow(self.account, service)
|
2007-04-19 15:31:28 +02:00
|
|
|
|
2005-10-30 15:33:25 +01:00
|
|
|
def cleanup(self):
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
AgentBrowser.cleanup(self)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def update_theme(self):
|
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
bgcolor = gajim.config.get_per('themes', theme, 'groupbgcolor')
|
2005-11-17 18:21:11 +01:00
|
|
|
if bgcolor:
|
|
|
|
self._renderer.set_property('cell-background', bgcolor)
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window.services_treeview.queue_draw()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2009-06-05 21:26:23 +02:00
|
|
|
def on_execute_button_clicked(self, widget=None):
|
2007-01-18 10:12:03 +01:00
|
|
|
'''When we want to execute a command:
|
|
|
|
open adhoc command window'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2007-01-18 10:12:03 +01:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
service = model[iter_][0].decode('utf-8')
|
2009-06-05 21:26:23 +02:00
|
|
|
node = model[iter_][1].decode('utf-8')
|
|
|
|
adhoc_commands.CommandWindow(self.account, service, commandnode=node)
|
2007-01-18 10:12:03 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def on_register_button_clicked(self, widget = None):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''When we want to register an agent:
|
2005-10-30 10:58:13 +01:00
|
|
|
request information about registering with the agent and close the
|
2005-11-02 12:03:42 +01:00
|
|
|
window.'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
jid = model[iter_][0].decode('utf-8')
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid:
|
|
|
|
gajim.connections[self.account].request_register_agent_info(jid)
|
|
|
|
self.window.destroy(chain = True)
|
|
|
|
|
2005-12-05 14:33:14 +01:00
|
|
|
def on_join_button_clicked(self, widget):
|
|
|
|
'''When we want to join an IRC room or create a new MUC room:
|
|
|
|
Opens the join_groupchat_window.'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2005-12-05 14:33:14 +01:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
service = model[iter_][0].decode('utf-8')
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'join_gc' not in gajim.interface.instances[self.account]:
|
2006-09-13 18:47:58 +02:00
|
|
|
try:
|
2006-11-18 21:52:28 +01:00
|
|
|
dialogs.JoinGroupchatWindow(self.account, service)
|
|
|
|
except GajimGeneralException:
|
2006-09-13 18:47:58 +02:00
|
|
|
pass
|
2005-12-05 14:33:14 +01:00
|
|
|
else:
|
|
|
|
gajim.interface.instances[self.account]['join_gc'].window.present()
|
|
|
|
self.window.destroy(chain = True)
|
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def update_actions(self):
|
2007-01-18 10:12:03 +01:00
|
|
|
if self.execute_button:
|
|
|
|
self.execute_button.set_sensitive(False)
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.register_button:
|
|
|
|
self.register_button.set_sensitive(False)
|
|
|
|
if self.browse_button:
|
|
|
|
self.browse_button.set_sensitive(False)
|
2005-12-05 14:33:14 +01:00
|
|
|
if self.join_button:
|
|
|
|
self.join_button.set_sensitive(False)
|
2007-04-19 15:31:28 +02:00
|
|
|
if self.search_button:
|
|
|
|
self.search_button.set_sensitive(False)
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
if not model[iter_][0]:
|
Merged revisions 5017-5020,5022-5029 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5017 | asterix | 2006-01-06 01:55:51 -0700 (Fri, 06 Jan 2006) | 2 lines
use escape for pango markup
........
r5018 | asterix | 2006-01-06 02:21:39 -0700 (Fri, 06 Jan 2006) | 2 lines
missing new contacts function
........
r5019 | asterix | 2006-01-06 11:03:07 -0700 (Fri, 06 Jan 2006) | 2 lines
handle the click on toggle_gpg_encryption menuitem
........
r5020 | asterix | 2006-01-06 11:14:14 -0700 (Fri, 06 Jan 2006) | 2 lines
use the saved size even if a chat window is already opened
........
r5022 | asterix | 2006-01-07 03:43:47 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now resume filetransfert
........
r5023 | asterix | 2006-01-07 03:56:31 -0700 (Sat, 07 Jan 2006) | 2 lines
[Knuckles] Google E-Mail Notification
........
r5024 | asterix | 2006-01-07 04:02:16 -0700 (Sat, 07 Jan 2006) | 2 lines
better string
........
r5025 | asterix | 2006-01-07 04:14:32 -0700 (Sat, 07 Jan 2006) | 2 lines
fix a TB
........
r5026 | asterix | 2006-01-07 05:36:55 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now drag a file on a contact in the roster to send him a file
........
r5027 | asterix | 2006-01-07 06:26:28 -0700 (Sat, 07 Jan 2006) | 2 lines
contact.groups is always a list, even if emtpy
........
r5028 | asterix | 2006-01-07 06:54:30 -0700 (Sat, 07 Jan 2006) | 2 lines
make all buttons insensitive on a category row in disco
........
r5029 | asterix | 2006-01-07 07:19:25 -0700 (Sat, 07 Jan 2006) | 2 lines
auto open groupchat configuration window when we create a new room
........
2006-01-07 18:25:35 +01:00
|
|
|
# We're on a category row
|
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
if model[iter_][4] != 0:
|
2005-10-30 10:58:13 +01:00
|
|
|
# We don't have the info (yet)
|
|
|
|
# It's either unknown or a transport, register button should be active
|
|
|
|
if self.register_button:
|
|
|
|
self.register_button.set_sensitive(True)
|
|
|
|
# Guess what kind of service we're dealing with
|
|
|
|
if self.browse_button:
|
2008-12-03 18:16:04 +01:00
|
|
|
jid = model[iter_][0].decode('utf-8')
|
|
|
|
type_ = gajim.get_transport_name_from_jid(jid,
|
2005-10-30 10:58:13 +01:00
|
|
|
use_config_setting = False)
|
2008-12-03 18:16:04 +01:00
|
|
|
if type_:
|
|
|
|
identity = {'category': '_jid', 'type': type_}
|
2005-10-30 10:58:13 +01:00
|
|
|
klass = self.cache.get_browser([identity])
|
|
|
|
if klass:
|
|
|
|
self.browse_button.set_sensitive(True)
|
|
|
|
else:
|
|
|
|
# We couldn't guess
|
|
|
|
self.browse_button.set_sensitive(True)
|
|
|
|
else:
|
|
|
|
# Normal case, we have info
|
|
|
|
AgentBrowser.update_actions(self)
|
|
|
|
|
|
|
|
def _update_actions(self, jid, node, identities, features, data):
|
|
|
|
AgentBrowser._update_actions(self, jid, node, identities, features, data)
|
2007-01-18 10:12:03 +01:00
|
|
|
if self.execute_button and xmpp.NS_COMMANDS in features:
|
|
|
|
self.execute_button.set_sensitive(True)
|
2007-04-19 15:31:28 +02:00
|
|
|
if self.search_button and xmpp.NS_SEARCH in features:
|
|
|
|
self.search_button.set_sensitive(True)
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.register_button and xmpp.NS_REGISTER in features:
|
|
|
|
# We can register this agent
|
|
|
|
registered_transports = []
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
jid_list = gajim.contacts.get_jid_list(self.account)
|
2006-11-18 21:52:28 +01:00
|
|
|
for jid in jid_list:
|
|
|
|
contact = gajim.contacts.get_first_contact_from_jid(
|
|
|
|
self.account, jid)
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
if _('Transports') in contact.groups:
|
2006-11-18 21:52:28 +01:00
|
|
|
registered_transports.append(jid)
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid in registered_transports:
|
|
|
|
self.register_button.set_label(_('_Edit'))
|
|
|
|
else:
|
|
|
|
self.register_button.set_label(_('Re_gister'))
|
|
|
|
self.register_button.set_sensitive(True)
|
2005-12-05 14:33:14 +01:00
|
|
|
if self.join_button and xmpp.NS_MUC in features:
|
|
|
|
self.join_button.set_sensitive(True)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _default_action(self, jid, node, identities, features, data):
|
|
|
|
if AgentBrowser._default_action(self, jid, node, identities, features, data):
|
|
|
|
return True
|
|
|
|
if xmpp.NS_REGISTER in features:
|
|
|
|
# Register if we can't browse
|
|
|
|
self.on_register_button_clicked()
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def browse(self, force = False):
|
|
|
|
self._progress = 0
|
|
|
|
AgentBrowser.browse(self, force = force)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _expand_all(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Expand all items in the treeview'''
|
2005-10-30 10:58:13 +01:00
|
|
|
# GTK apparently screws up here occasionally. :/
|
|
|
|
#def expand_all(*args):
|
|
|
|
# self.window.services_treeview.expand_all()
|
|
|
|
# self.expanding = False
|
|
|
|
# return False
|
|
|
|
#self.expanding = True
|
|
|
|
#gobject.idle_add(expand_all)
|
|
|
|
self.window.services_treeview.expand_all()
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _update_progressbar(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Update the progressbar.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
# Refresh this every update
|
|
|
|
if self._progressbar_sourceid:
|
|
|
|
gobject.source_remove(self._progressbar_sourceid)
|
|
|
|
|
|
|
|
fraction = 0
|
|
|
|
if self._total_items:
|
2008-08-01 11:30:36 +02:00
|
|
|
self.window.progressbar.set_text(_("Scanning %(current)d / %(total)d.."
|
|
|
|
) % {'current': self._progress, 'total': self._total_items})
|
2005-10-30 10:58:13 +01:00
|
|
|
fraction = float(self._progress) / float(self._total_items)
|
|
|
|
if self._progress >= self._total_items:
|
|
|
|
# We show the progressbar for just a bit before hiding it.
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = gobject.timeout_add_seconds(2, self._hide_progressbar_cb)
|
|
|
|
self._progressbar_sourceid = id_
|
2005-10-30 10:58:13 +01:00
|
|
|
else:
|
|
|
|
self.window.progressbar.show()
|
|
|
|
# Hide the progressbar if we're timing out anyways. (20 secs)
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = gobject.timeout_add_seconds(20, self._hide_progressbar_cb)
|
|
|
|
self._progressbar_sourceid = id_
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window.progressbar.set_fraction(fraction)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _hide_progressbar_cb(self, *args):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Simple callback to hide the progressbar a second after we finish.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.active:
|
|
|
|
self.window.progressbar.hide()
|
|
|
|
return False
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _friendly_category(self, category, type_=None):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Get the friendly category name and priority.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
cat = None
|
2008-10-11 12:22:04 +02:00
|
|
|
if type_:
|
2005-10-30 10:58:13 +01:00
|
|
|
# Try type-specific override
|
|
|
|
try:
|
2008-10-11 12:22:04 +02:00
|
|
|
cat, prio = _cat_to_descr[(category, type_)]
|
2005-10-30 10:58:13 +01:00
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
if not cat:
|
|
|
|
try:
|
|
|
|
cat, prio = _cat_to_descr[category]
|
|
|
|
except KeyError:
|
|
|
|
cat, prio = _cat_to_descr['other']
|
|
|
|
return cat, prio
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _create_category(self, cat, type_=None):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Creates a category row.'''
|
2008-10-11 12:22:04 +02:00
|
|
|
cat, prio = self._friendly_category(cat, type_)
|
2006-11-18 21:52:28 +01:00
|
|
|
return self.model.append(None, ('', '', None, cat, prio))
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _find_category(self, cat, type_=None):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Looks up a category row and returns the iterator to it, or None.'''
|
2008-12-02 16:53:23 +01:00
|
|
|
cat = self._friendly_category(cat, type_)[0]
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self.model.get_iter_root()
|
|
|
|
while iter_:
|
|
|
|
if self.model.get_value(iter_, 3).decode('utf-8') == cat:
|
2005-10-30 10:58:13 +01:00
|
|
|
break
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self.model.iter_next(iter_)
|
|
|
|
if iter_:
|
|
|
|
return iter_
|
2005-10-30 10:58:13 +01:00
|
|
|
return None
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _find_item(self, jid, node):
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = None
|
2006-11-18 21:52:28 +01:00
|
|
|
cat_iter = self.model.get_iter_root()
|
2008-12-03 18:16:04 +01:00
|
|
|
while cat_iter and not iter_:
|
|
|
|
iter_ = self.model.iter_children(cat_iter)
|
|
|
|
while iter_:
|
|
|
|
cjid = self.model.get_value(iter_, 0).decode('utf-8')
|
|
|
|
cnode = self.model.get_value(iter_, 1).decode('utf-8')
|
2005-10-30 10:58:13 +01:00
|
|
|
if jid == cjid and node == cnode:
|
|
|
|
break
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self.model.iter_next(iter_)
|
2006-11-18 21:52:28 +01:00
|
|
|
cat_iter = self.model.iter_next(cat_iter)
|
2008-12-03 18:16:04 +01:00
|
|
|
if iter_:
|
|
|
|
return iter_
|
2005-10-30 10:58:13 +01:00
|
|
|
return None
|
|
|
|
|
2006-11-18 21:52:28 +01:00
|
|
|
def _add_item(self, jid, node, item, force):
|
2005-10-30 10:58:13 +01:00
|
|
|
# Row text
|
|
|
|
addr = get_agent_address(jid, node)
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'name' in item:
|
2005-10-30 10:58:13 +01:00
|
|
|
descr = "<b>%s</b>\n%s" % (item['name'], addr)
|
|
|
|
else:
|
|
|
|
descr = "<b>%s</b>" % addr
|
|
|
|
# Guess which kind of service this is
|
|
|
|
identities = []
|
2008-12-03 18:16:04 +01:00
|
|
|
type_ = gajim.get_transport_name_from_jid(jid,
|
2005-10-30 10:58:13 +01:00
|
|
|
use_config_setting = False)
|
2008-12-03 18:16:04 +01:00
|
|
|
if type_:
|
|
|
|
identity = {'category': '_jid', 'type': type_}
|
2005-10-30 10:58:13 +01:00
|
|
|
identities.append(identity)
|
2008-12-03 18:16:04 +01:00
|
|
|
cat_args = ('_jid', type_)
|
2005-10-30 10:58:13 +01:00
|
|
|
else:
|
|
|
|
# Put it in the 'other' category for now
|
|
|
|
cat_args = ('other',)
|
|
|
|
# Set the pixmap for the row
|
2005-11-19 21:33:49 +01:00
|
|
|
pix = self.cache.get_icon(identities)
|
2005-10-30 10:58:13 +01:00
|
|
|
# Put it in the right category
|
|
|
|
cat = self._find_category(*cat_args)
|
|
|
|
if not cat:
|
|
|
|
cat = self._create_category(*cat_args)
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model.append(cat, (item['jid'], item.get('node', ''), pix, descr, 1))
|
2005-10-30 10:58:13 +01:00
|
|
|
self._expand_all()
|
|
|
|
# Grab info on the service
|
|
|
|
self.cache.get_info(jid, node, self._agent_info, force = force)
|
|
|
|
self._update_progressbar()
|
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _update_item(self, iter_, jid, node, item):
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid, node)
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'name' in item:
|
2005-10-30 10:58:13 +01:00
|
|
|
descr = "<b>%s</b>\n%s" % (item['name'], addr)
|
|
|
|
else:
|
|
|
|
descr = "<b>%s</b>" % addr
|
2008-10-11 12:22:04 +02:00
|
|
|
self.model[iter_][3] = descr
|
2005-10-30 10:58:13 +01:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _update_info(self, iter_, jid, node, identities, features, data):
|
2005-10-30 10:58:13 +01:00
|
|
|
addr = get_agent_address(jid, node)
|
|
|
|
name = identities[0].get('name', '')
|
|
|
|
if name:
|
|
|
|
descr = "<b>%s</b>\n%s" % (name, addr)
|
|
|
|
else:
|
|
|
|
descr = "<b>%s</b>" % addr
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
# Update progress
|
|
|
|
self._progress += 1
|
|
|
|
self._update_progressbar()
|
|
|
|
|
|
|
|
# Search for an icon and category we can display
|
2005-11-19 21:33:49 +01:00
|
|
|
pix = self.cache.get_icon(identities)
|
2005-10-30 10:58:13 +01:00
|
|
|
for identity in identities:
|
|
|
|
try:
|
2008-12-03 18:16:04 +01:00
|
|
|
cat, type_ = identity['category'], identity['type']
|
2005-10-30 10:58:13 +01:00
|
|
|
except KeyError:
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
|
|
|
|
# Check if we have to move categories
|
2008-10-11 12:22:04 +02:00
|
|
|
old_cat_iter = self.model.iter_parent(iter_)
|
2006-11-18 21:52:28 +01:00
|
|
|
old_cat = self.model.get_value(old_cat_iter, 3).decode('utf-8')
|
|
|
|
if self.model.get_value(old_cat_iter, 3) == cat:
|
2005-10-30 10:58:13 +01:00
|
|
|
# Already in the right category, just update
|
2008-10-11 12:22:04 +02:00
|
|
|
self.model[iter_][2] = pix
|
|
|
|
self.model[iter_][3] = descr
|
|
|
|
self.model[iter_][4] = 0
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
|
|
|
# Not in the right category, move it.
|
2008-10-11 12:22:04 +02:00
|
|
|
self.model.remove(iter_)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
# Check if the old category is empty
|
2006-11-18 21:52:28 +01:00
|
|
|
if not self.model.iter_is_valid(old_cat_iter):
|
2005-10-30 10:58:13 +01:00
|
|
|
old_cat_iter = self._find_category(old_cat)
|
2006-11-18 21:52:28 +01:00
|
|
|
if not self.model.iter_children(old_cat_iter):
|
|
|
|
self.model.remove(old_cat_iter)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2008-12-03 18:16:04 +01:00
|
|
|
cat_iter = self._find_category(cat, type_)
|
2005-10-30 10:58:13 +01:00
|
|
|
if not cat_iter:
|
2008-12-03 18:16:04 +01:00
|
|
|
cat_iter = self._create_category(cat, type_)
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model.append(cat_iter, (jid, node, pix, descr, 0))
|
2005-10-30 10:58:13 +01:00
|
|
|
self._expand_all()
|
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _update_error(self, iter_, jid, node):
|
|
|
|
self.model[iter_][4] = 2
|
2005-10-30 10:58:13 +01:00
|
|
|
self._progress += 1
|
|
|
|
self._update_progressbar()
|
|
|
|
|
|
|
|
|
|
|
|
class MucBrowser(AgentBrowser):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
AgentBrowser.__init__(self, *args, **kwargs)
|
|
|
|
self.join_button = None
|
2009-06-22 18:30:02 +02:00
|
|
|
self.bookmark_button = None
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _create_treemodel(self):
|
2007-06-25 22:03:43 +02:00
|
|
|
# JID, node, name, users_int, users_str, description, fetched
|
2005-10-30 10:58:13 +01:00
|
|
|
# This is rather long, I'd rather not use a data_func here though.
|
|
|
|
# Users is a string, because want to be able to leave it empty.
|
2007-06-25 22:03:43 +02:00
|
|
|
self.model = gtk.ListStore(str, str, str, int, str, str, bool)
|
2006-11-18 21:52:28 +01:00
|
|
|
self.model.set_sort_column_id(2, gtk.SORT_ASCENDING)
|
|
|
|
self.window.services_treeview.set_model(self.model)
|
2005-10-30 10:58:13 +01:00
|
|
|
# Name column
|
|
|
|
col = gtk.TreeViewColumn(_('Name'))
|
2006-11-18 21:52:28 +01:00
|
|
|
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
|
|
|
col.set_fixed_width(100)
|
2005-10-30 10:58:13 +01:00
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
|
|
|
col.set_attributes(renderer, text = 2)
|
2007-06-25 19:49:14 +02:00
|
|
|
col.set_sort_column_id(2)
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
|
|
|
col.set_resizable(True)
|
|
|
|
# Users column
|
|
|
|
col = gtk.TreeViewColumn(_('Users'))
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
2007-06-25 22:03:43 +02:00
|
|
|
col.set_attributes(renderer, text = 4)
|
2007-06-25 19:49:14 +02:00
|
|
|
col.set_sort_column_id(3)
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
|
|
|
col.set_resizable(True)
|
|
|
|
# Description column
|
|
|
|
col = gtk.TreeViewColumn(_('Description'))
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
2007-06-25 22:03:43 +02:00
|
|
|
col.set_attributes(renderer, text = 5)
|
2007-06-25 19:49:14 +02:00
|
|
|
col.set_sort_column_id(4)
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
|
|
|
col.set_resizable(True)
|
2006-11-18 21:52:28 +01:00
|
|
|
# Id column
|
|
|
|
col = gtk.TreeViewColumn(_('Id'))
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
|
|
|
col.set_attributes(renderer, text = 0)
|
2007-06-25 19:49:14 +02:00
|
|
|
col.set_sort_column_id(0)
|
2006-11-18 21:52:28 +01:00
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
|
|
|
col.set_resizable(True)
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window.services_treeview.set_headers_visible(True)
|
2007-06-25 19:49:14 +02:00
|
|
|
self.window.services_treeview.set_headers_clickable(True)
|
2005-10-30 10:58:13 +01:00
|
|
|
# Source id for idle callback used to start disco#info queries.
|
|
|
|
self._fetch_source = None
|
|
|
|
# Query failure counter
|
|
|
|
self._broken = 0
|
|
|
|
# Connect to scrollwindow scrolling
|
|
|
|
self.vadj = self.window.services_scrollwin.get_property('vadjustment')
|
|
|
|
self.vadj_cbid = self.vadj.connect('value-changed', self.on_scroll)
|
|
|
|
# And to size changes
|
2006-11-18 21:52:28 +01:00
|
|
|
self.size_cbid = self.window.services_scrollwin.connect(
|
|
|
|
'size-allocate', self.on_scroll)
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
def _clean_treemodel(self):
|
|
|
|
if self.size_cbid:
|
|
|
|
self.window.services_scrollwin.disconnect(self.size_cbid)
|
|
|
|
self.size_cbid = None
|
|
|
|
if self.vadj_cbid:
|
|
|
|
self.vadj.disconnect(self.vadj_cbid)
|
|
|
|
self.vadj_cbid = None
|
|
|
|
AgentBrowser._clean_treemodel(self)
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def _add_actions(self):
|
2009-06-22 18:30:02 +02:00
|
|
|
self.bookmark_button = gtk.Button(label=_('_Bookmark'), use_underline=True)
|
|
|
|
self.bookmark_button.connect('clicked', self.on_bookmark_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.bookmark_button)
|
|
|
|
self.bookmark_button.show_all()
|
2005-12-06 18:43:21 +01:00
|
|
|
self.join_button = gtk.Button(label=_('_Join'), use_underline=True)
|
2005-10-30 10:58:13 +01:00
|
|
|
self.join_button.connect('clicked', self.on_join_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.join_button)
|
|
|
|
self.join_button.show_all()
|
|
|
|
|
|
|
|
def _clean_actions(self):
|
2009-06-22 18:30:02 +02:00
|
|
|
if self.bookmark_button:
|
|
|
|
self.bookmark_button.destroy()
|
|
|
|
self.bookmark_button = None
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.join_button:
|
|
|
|
self.join_button.destroy()
|
|
|
|
self.join_button = None
|
|
|
|
|
2009-06-22 18:30:02 +02:00
|
|
|
def on_bookmark_button_clicked(self, *args):
|
|
|
|
model, iter = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter:
|
|
|
|
return
|
|
|
|
name = gajim.config.get_per('accounts', self.account, 'name')
|
|
|
|
room_jid = model[iter][0].decode('utf-8')
|
|
|
|
bm = {
|
|
|
|
'name': room_jid.split('@')[0],
|
|
|
|
'jid': room_jid,
|
|
|
|
'autojoin': '0',
|
|
|
|
'minimize': '0',
|
|
|
|
'password': '',
|
|
|
|
'nick': name
|
|
|
|
}
|
|
|
|
|
|
|
|
for bookmark in gajim.connections[self.account].bookmarks:
|
|
|
|
if bookmark['jid'] == bm['jid']:
|
|
|
|
dialogs.ErrorDialog(
|
|
|
|
_('Bookmark already set'),
|
|
|
|
_('Group Chat "%s" is already in your bookmarks.') % bm['jid'])
|
|
|
|
return
|
|
|
|
|
|
|
|
gajim.connections[self.account].bookmarks.append(bm)
|
|
|
|
gajim.connections[self.account].store_bookmarks()
|
|
|
|
|
|
|
|
gajim.interface.roster.set_actions_menu_needs_rebuild()
|
|
|
|
|
|
|
|
dialogs.InformationDialog(
|
|
|
|
_('Bookmark has been added successfully'),
|
|
|
|
_('You can manage your bookmarks via Actions menu in your roster.'))
|
|
|
|
|
2005-10-30 10:58:13 +01:00
|
|
|
def on_join_button_clicked(self, *args):
|
|
|
|
'''When we want to join a conference:
|
|
|
|
Ask specific informations about the selected agent and close the window'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_:
|
2005-10-30 10:58:13 +01:00
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
service = model[iter_][0].decode('utf-8')
|
|
|
|
room = model[iter_][1].decode('utf-8')
|
2006-11-18 21:52:28 +01:00
|
|
|
if 'join_gc' not in gajim.interface.instances[self.account]:
|
2006-09-13 18:47:58 +02:00
|
|
|
try:
|
2006-11-18 21:52:28 +01:00
|
|
|
dialogs.JoinGroupchatWindow(self.account, service)
|
|
|
|
except GajimGeneralException:
|
2006-09-13 18:47:58 +02:00
|
|
|
pass
|
2005-10-30 10:58:13 +01:00
|
|
|
else:
|
2005-11-13 16:08:47 +01:00
|
|
|
gajim.interface.instances[self.account]['join_gc'].window.present()
|
2005-10-30 10:58:13 +01:00
|
|
|
self.window.destroy(chain = True)
|
|
|
|
|
|
|
|
def update_actions(self):
|
2009-06-22 18:30:02 +02:00
|
|
|
sens = self.window.services_treeview.get_selection().count_selected_rows()
|
|
|
|
if self.bookmark_button:
|
|
|
|
self.bookmark_button.set_sensitive(sens > 0)
|
2005-10-30 10:58:13 +01:00
|
|
|
if self.join_button:
|
|
|
|
self.join_button.set_sensitive(sens > 0)
|
|
|
|
|
|
|
|
def default_action(self):
|
|
|
|
self.on_join_button_clicked()
|
|
|
|
|
|
|
|
def _start_info_query(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Idle callback to start checking for visible rows.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
self._fetch_source = None
|
|
|
|
self._query_visible()
|
|
|
|
return False
|
|
|
|
|
|
|
|
def on_scroll(self, *args):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Scrollwindow callback to trigger new queries on scolling.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
# This apparently happens when inactive sometimes
|
|
|
|
self._query_visible()
|
|
|
|
|
|
|
|
def _query_visible(self):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Query the next visible row for info.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if self._fetch_source:
|
|
|
|
# We're already fetching
|
|
|
|
return
|
|
|
|
view = self.window.services_treeview
|
|
|
|
if not view.flags() & gtk.REALIZED:
|
|
|
|
# Prevent a silly warning, try again in a bit.
|
|
|
|
self._fetch_source = gobject.timeout_add(100, self._start_info_query)
|
|
|
|
return
|
|
|
|
# We have to do this in a pygtk <2.8 compatible way :/
|
|
|
|
#start, end = self.window.services_treeview.get_visible_range()
|
|
|
|
rect = view.get_visible_rect()
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = end = None
|
2005-10-30 10:58:13 +01:00
|
|
|
# Top row
|
|
|
|
try:
|
|
|
|
sx, sy = view.tree_to_widget_coords(rect.x, rect.y)
|
|
|
|
spath = view.get_path_at_pos(sx, sy)[0]
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self.model.get_iter(spath)
|
2005-10-30 10:58:13 +01:00
|
|
|
except TypeError:
|
|
|
|
self._fetch_source = None
|
|
|
|
return
|
|
|
|
# Bottom row
|
|
|
|
# Iter compare is broke, use the path instead
|
|
|
|
try:
|
2008-08-29 12:38:34 +02:00
|
|
|
ex, ey = view.tree_to_widget_coords(rect.x + rect.height,
|
|
|
|
rect.y + rect.height)
|
2005-10-30 10:58:13 +01:00
|
|
|
end = view.get_path_at_pos(ex, ey)[0]
|
|
|
|
# end is the last visible, we want to query that aswell
|
|
|
|
end = (end[0] + 1,)
|
|
|
|
except TypeError:
|
|
|
|
# We're at the end of the model, we can leave end=None though.
|
|
|
|
pass
|
2008-12-03 18:16:04 +01:00
|
|
|
while iter_ and self.model.get_path(iter_) != end:
|
|
|
|
if not self.model.get_value(iter_, 6):
|
|
|
|
jid = self.model.get_value(iter_, 0).decode('utf-8')
|
|
|
|
node = self.model.get_value(iter_, 1).decode('utf-8')
|
2005-10-30 10:58:13 +01:00
|
|
|
self.cache.get_info(jid, node, self._agent_info)
|
|
|
|
self._fetch_source = True
|
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self.model.iter_next(iter_)
|
2005-10-30 10:58:13 +01:00
|
|
|
self._fetch_source = None
|
|
|
|
|
2005-10-30 13:25:11 +01:00
|
|
|
def _channel_altinfo(self, jid, node, items, name = None):
|
2005-11-02 12:03:42 +01:00
|
|
|
'''Callback for the alternate disco#items query. We try to atleast get
|
2005-10-30 10:58:13 +01:00
|
|
|
the amount of users in the room if the service does not support MUC
|
2005-11-02 12:03:42 +01:00
|
|
|
dataforms.'''
|
2005-10-30 10:58:13 +01:00
|
|
|
if items == 0:
|
|
|
|
# The server returned an error
|
|
|
|
self._broken += 1
|
|
|
|
if self._broken >= 3:
|
|
|
|
# Disable queries completely after 3 failures
|
|
|
|
if self.size_cbid:
|
|
|
|
self.window.services_scrollwin.disconnect(self.size_cbid)
|
|
|
|
self.size_cbid = None
|
|
|
|
if self.vadj_cbid:
|
|
|
|
self.vadj.disconnect(self.vadj_cbid)
|
|
|
|
self.vadj_cbid = None
|
|
|
|
self._fetch_source = None
|
|
|
|
return
|
|
|
|
else:
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = self._find_item(jid, node)
|
|
|
|
if iter_:
|
2005-10-30 13:25:11 +01:00
|
|
|
if name:
|
2008-12-03 18:16:04 +01:00
|
|
|
self.model[iter_][2] = name
|
|
|
|
self.model[iter_][3] = len(items) # The number of users
|
|
|
|
self.model[iter_][4] = str(len(items)) # The number of users
|
|
|
|
self.model[iter_][6] = True
|
2005-10-30 10:58:13 +01:00
|
|
|
self._fetch_source = None
|
|
|
|
self._query_visible()
|
|
|
|
|
2006-11-18 21:52:28 +01:00
|
|
|
def _add_item(self, jid, node, item, force):
|
2007-06-25 22:03:43 +02:00
|
|
|
self.model.append((jid, node, item.get('name', ''), -1, '', '', False))
|
2005-10-30 10:58:13 +01:00
|
|
|
if not self._fetch_source:
|
|
|
|
self._fetch_source = gobject.idle_add(self._start_info_query)
|
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _update_info(self, iter_, jid, node, identities, features, data):
|
2005-10-30 10:58:13 +01:00
|
|
|
name = identities[0].get('name', '')
|
|
|
|
for form in data:
|
|
|
|
typefield = form.getField('FORM_TYPE')
|
2008-08-29 12:38:34 +02:00
|
|
|
if typefield and typefield.getValue() == \
|
|
|
|
'http://jabber.org/protocol/muc#roominfo':
|
2005-10-30 10:58:13 +01:00
|
|
|
# Fill model row from the form's fields
|
|
|
|
users = form.getField('muc#roominfo_occupants')
|
|
|
|
descr = form.getField('muc#roominfo_description')
|
|
|
|
if users:
|
2008-10-11 12:22:04 +02:00
|
|
|
self.model[iter_][3] = int(users.getValue())
|
|
|
|
self.model[iter_][4] = users.getValue()
|
2005-10-30 10:58:13 +01:00
|
|
|
if descr:
|
2008-10-11 12:22:04 +02:00
|
|
|
self.model[iter_][5] = descr.getValue()
|
2005-10-30 10:58:13 +01:00
|
|
|
# Only set these when we find a form with additional info
|
|
|
|
# Some servers don't support forms and put extra info in
|
|
|
|
# the name attribute, so we preserve it in that case.
|
2008-10-11 12:22:04 +02:00
|
|
|
self.model[iter_][2] = name
|
|
|
|
self.model[iter_][6] = True
|
2005-10-30 10:58:13 +01:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
# We didn't find a form, switch to alternate query mode
|
|
|
|
self.cache.get_items(jid, node, self._channel_altinfo, args = (name,))
|
|
|
|
return
|
|
|
|
# Continue with the next
|
|
|
|
self._fetch_source = None
|
|
|
|
self._query_visible()
|
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _update_error(self, iter_, jid, node):
|
2005-10-30 10:58:13 +01:00
|
|
|
# switch to alternate query mode
|
2005-10-30 13:25:11 +01:00
|
|
|
self.cache.get_items(jid, node, self._channel_altinfo)
|
2005-10-30 10:58:13 +01:00
|
|
|
|
2006-08-04 22:12:00 +02:00
|
|
|
def PubSubBrowser(account, jid, node):
|
|
|
|
''' Returns an AgentBrowser subclass that will display service discovery
|
|
|
|
for particular pubsub service. Different pubsub services may need to
|
|
|
|
present different data during browsing. '''
|
|
|
|
# for now, only discussion groups are supported...
|
|
|
|
# TODO: check if it has appropriate features to be such kind of service
|
|
|
|
return DiscussionGroupsBrowser(account, jid, node)
|
|
|
|
|
|
|
|
class DiscussionGroupsBrowser(AgentBrowser):
|
|
|
|
''' For browsing pubsub-based discussion groups service. '''
|
2006-08-20 12:18:20 +02:00
|
|
|
def __init__(self, account, jid, node):
|
|
|
|
AgentBrowser.__init__(self, account, jid, node)
|
|
|
|
|
|
|
|
# this will become set object when we get subscriptions; None means
|
|
|
|
# we don't know yet which groups are subscribed
|
|
|
|
self.subscriptions = None
|
|
|
|
|
|
|
|
# this will become our action widgets when we create them; None means
|
|
|
|
# we don't have them yet (needed for check in callback)
|
|
|
|
self.subscribe_button = None
|
|
|
|
self.unsubscribe_button = None
|
|
|
|
|
|
|
|
gajim.connections[account].send_pb_subscription_query(jid, self._subscriptionsCB)
|
|
|
|
|
2006-08-04 22:12:00 +02:00
|
|
|
def _create_treemodel(self):
|
|
|
|
''' Create treemodel for the window. '''
|
2006-08-20 12:18:20 +02:00
|
|
|
# JID, node, name (with description) - pango markup, dont have info?, subscribed?
|
2007-07-09 02:03:25 +02:00
|
|
|
self.model = gtk.TreeStore(str, str, str, bool, bool)
|
2007-06-25 00:33:00 +02:00
|
|
|
# sort by name
|
|
|
|
self.model.set_sort_column_id(2, gtk.SORT_ASCENDING)
|
2007-02-14 10:10:50 +01:00
|
|
|
self.window.services_treeview.set_model(self.model)
|
2006-08-04 22:12:00 +02:00
|
|
|
|
|
|
|
# Name column
|
|
|
|
# Pango markup for name and description, description printed with
|
|
|
|
# <small/> font
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col = gtk.TreeViewColumn(_('Name'))
|
|
|
|
col.pack_start(renderer)
|
|
|
|
col.set_attributes(renderer, markup=2)
|
|
|
|
col.set_resizable(True)
|
2007-06-25 19:49:14 +02:00
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
2007-06-25 00:33:00 +02:00
|
|
|
self.window.services_treeview.set_headers_visible(True)
|
2006-08-04 22:12:00 +02:00
|
|
|
|
|
|
|
# Subscription state
|
|
|
|
renderer = gtk.CellRendererToggle()
|
|
|
|
col = gtk.TreeViewColumn(_('Subscribed'))
|
|
|
|
col.pack_start(renderer)
|
2006-08-20 12:18:20 +02:00
|
|
|
col.set_attributes(renderer, inconsistent=3, active=4)
|
2006-08-04 22:12:00 +02:00
|
|
|
col.set_resizable(False)
|
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
|
|
|
|
2007-06-25 00:33:00 +02:00
|
|
|
# Node Column
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col = gtk.TreeViewColumn(_('Node'))
|
|
|
|
col.pack_start(renderer)
|
|
|
|
col.set_attributes(renderer, markup=1)
|
|
|
|
col.set_resizable(True)
|
|
|
|
self.window.services_treeview.insert_column(col, -1)
|
2006-08-04 22:12:00 +02:00
|
|
|
|
2007-07-09 02:03:25 +02:00
|
|
|
def _add_items(self, jid, node, items, force):
|
|
|
|
for item in items:
|
|
|
|
jid = item['jid']
|
|
|
|
node = item.get('node', '')
|
|
|
|
self._total_items += 1
|
|
|
|
self._add_item(jid, node, item, force)
|
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _in_list_foreach(self, model, path, iter_, node):
|
2007-07-11 00:52:19 +02:00
|
|
|
if model[path][1] == node:
|
|
|
|
self.in_list = True
|
|
|
|
|
|
|
|
def _in_list(self, node):
|
|
|
|
self.in_list = False
|
|
|
|
self.model.foreach(self._in_list_foreach, node)
|
|
|
|
return self.in_list
|
|
|
|
|
2007-02-14 10:10:50 +01:00
|
|
|
def _add_item(self, jid, node, item, force):
|
2006-08-20 12:18:20 +02:00
|
|
|
''' Called when we got basic information about new node from query.
|
|
|
|
Show the item. '''
|
|
|
|
name = item.get('name', '')
|
|
|
|
|
|
|
|
if self.subscriptions is not None:
|
|
|
|
dunno = False
|
2007-02-14 11:13:27 +01:00
|
|
|
subscribed = node in self.subscriptions
|
2006-08-20 12:18:20 +02:00
|
|
|
else:
|
|
|
|
dunno = True
|
|
|
|
subscribed = False
|
|
|
|
|
2007-01-17 00:26:38 +01:00
|
|
|
name = gobject.markup_escape_text(name)
|
2006-08-20 12:18:20 +02:00
|
|
|
name = '<b>%s</b>' % name
|
2007-07-09 02:03:25 +02:00
|
|
|
|
|
|
|
node_splitted = node.split('/')
|
|
|
|
parent_iter = None
|
|
|
|
while len(node_splitted) > 1:
|
|
|
|
parent_node = node_splitted.pop(0)
|
|
|
|
parent_iter = self._get_child_iter(parent_iter, parent_node)
|
|
|
|
node_splitted[0] = parent_node + '/' + node_splitted[0]
|
2007-07-11 00:52:19 +02:00
|
|
|
if not self._in_list(node):
|
|
|
|
self.model.append(parent_iter, (jid, node, name, dunno, subscribed))
|
|
|
|
self.cache.get_items(jid, node, self._add_items, force = force,
|
|
|
|
args = (force,))
|
2007-07-09 02:03:25 +02:00
|
|
|
|
|
|
|
def _get_child_iter(self, parent_iter, node):
|
|
|
|
child_iter = self.model.iter_children(parent_iter)
|
|
|
|
while child_iter:
|
|
|
|
if self.model[child_iter][1] == node:
|
|
|
|
return child_iter
|
|
|
|
child_iter = self.model.iter_next(child_iter)
|
|
|
|
return None
|
2006-08-20 12:18:20 +02:00
|
|
|
|
2006-08-04 22:12:00 +02:00
|
|
|
def _add_actions(self):
|
2006-08-20 12:18:20 +02:00
|
|
|
self.post_button = gtk.Button(label=_('New post'), use_underline=True)
|
|
|
|
self.post_button.set_sensitive(False)
|
|
|
|
self.post_button.connect('clicked', self.on_post_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.post_button)
|
|
|
|
self.post_button.show_all()
|
|
|
|
|
2006-08-04 22:12:00 +02:00
|
|
|
self.subscribe_button = gtk.Button(label=_('_Subscribe'), use_underline=True)
|
2006-08-20 12:18:20 +02:00
|
|
|
self.subscribe_button.set_sensitive(False)
|
2006-08-04 22:12:00 +02:00
|
|
|
self.subscribe_button.connect('clicked', self.on_subscribe_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.subscribe_button)
|
|
|
|
self.subscribe_button.show_all()
|
|
|
|
|
|
|
|
self.unsubscribe_button = gtk.Button(label=_('_Unsubscribe'), use_underline=True)
|
2006-08-20 12:18:20 +02:00
|
|
|
self.unsubscribe_button.set_sensitive(False)
|
2006-08-04 22:12:00 +02:00
|
|
|
self.unsubscribe_button.connect('clicked', self.on_unsubscribe_button_clicked)
|
|
|
|
self.window.action_buttonbox.add(self.unsubscribe_button)
|
|
|
|
self.unsubscribe_button.show_all()
|
|
|
|
|
|
|
|
def _clean_actions(self):
|
2006-08-20 12:18:20 +02:00
|
|
|
if self.post_button is not None:
|
|
|
|
self.post_button.destroy()
|
|
|
|
self.post_button = None
|
|
|
|
|
2006-08-04 22:12:00 +02:00
|
|
|
if self.subscribe_button is not None:
|
|
|
|
self.subscribe_button.destroy()
|
|
|
|
self.subscribe_button = None
|
|
|
|
|
|
|
|
if self.unsubscribe_button is not None:
|
|
|
|
self.unsubscribe_button.destroy()
|
|
|
|
self.unsubscribe_button = None
|
|
|
|
|
2006-08-20 12:18:20 +02:00
|
|
|
def update_actions(self):
|
|
|
|
'''Called when user selected a row. Make subscribe/unsubscribe buttons
|
|
|
|
sensitive appropriatelly.'''
|
|
|
|
# we have nothing to do if we don't have buttons...
|
|
|
|
if self.subscribe_button is None: return
|
|
|
|
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if not iter_ or self.subscriptions is None:
|
2006-08-20 12:18:20 +02:00
|
|
|
# no item selected or no subscriptions info, all buttons are insensitive
|
|
|
|
self.post_button.set_sensitive(False)
|
|
|
|
self.subscribe_button.set_sensitive(False)
|
|
|
|
self.unsubscribe_button.set_sensitive(False)
|
|
|
|
else:
|
2008-12-03 18:16:04 +01:00
|
|
|
subscribed = model.get_value(iter_, 4) # 4 = subscribed?
|
2006-08-20 12:18:20 +02:00
|
|
|
self.post_button.set_sensitive(subscribed)
|
|
|
|
self.subscribe_button.set_sensitive(not subscribed)
|
|
|
|
self.unsubscribe_button.set_sensitive(subscribed)
|
|
|
|
|
|
|
|
def on_post_button_clicked(self, widget):
|
|
|
|
'''Called when 'post' button is pressed. Open window to create post'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if iter_ is None: return
|
2006-08-20 12:18:20 +02:00
|
|
|
|
2008-12-03 18:16:04 +01:00
|
|
|
groupnode = model.get_value(iter_, 1) # 1 = groupnode
|
2006-08-20 12:18:20 +02:00
|
|
|
|
|
|
|
groups.GroupsPostWindow(self.account, self.jid, groupnode)
|
|
|
|
|
|
|
|
def on_subscribe_button_clicked(self, widget):
|
|
|
|
'''Called when 'subscribe' button is pressed. Send subscribtion request.'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if iter_ is None: return
|
2006-08-20 12:18:20 +02:00
|
|
|
|
2008-12-03 18:16:04 +01:00
|
|
|
groupnode = model.get_value(iter_, 1) # 1 = groupnode
|
2006-08-20 12:18:20 +02:00
|
|
|
|
|
|
|
gajim.connections[self.account].send_pb_subscribe(self.jid, groupnode, self._subscribeCB, groupnode)
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-08-20 12:18:20 +02:00
|
|
|
def on_unsubscribe_button_clicked(self, widget):
|
|
|
|
'''Called when 'unsubscribe' button is pressed. Send unsubscription request.'''
|
2008-12-03 18:16:04 +01:00
|
|
|
model, iter_ = self.window.services_treeview.get_selection().get_selected()
|
|
|
|
if iter_ is None: return
|
2006-08-20 12:18:20 +02:00
|
|
|
|
2008-12-03 18:16:04 +01:00
|
|
|
groupnode = model.get_value(iter_, 1) # 1 = groupnode
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-08-20 12:18:20 +02:00
|
|
|
gajim.connections[self.account].send_pb_unsubscribe(self.jid, groupnode, self._unsubscribeCB, groupnode)
|
|
|
|
|
|
|
|
def _subscriptionsCB(self, conn, request):
|
|
|
|
''' We got the subscribed groups list stanza. Now, if we already
|
|
|
|
have items on the list, we should actualize them. '''
|
|
|
|
try:
|
|
|
|
subscriptions = request.getTag('pubsub').getTag('subscriptions')
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception:
|
2008-12-03 22:56:12 +01:00
|
|
|
return
|
2006-08-20 12:18:20 +02:00
|
|
|
|
|
|
|
groups = set()
|
|
|
|
for child in subscriptions.getTags('subscription'):
|
|
|
|
groups.add(child['node'])
|
|
|
|
|
|
|
|
self.subscriptions = groups
|
|
|
|
|
|
|
|
# try to setup existing items in model
|
|
|
|
model = self.window.services_treeview.get_model()
|
|
|
|
for row in model:
|
|
|
|
# 1 = group node
|
|
|
|
# 3 = insensitive checkbox for subscribed
|
|
|
|
# 4 = subscribed?
|
|
|
|
groupnode = row[1]
|
|
|
|
row[3]=False
|
|
|
|
row[4]=groupnode in groups
|
|
|
|
|
|
|
|
# we now know subscriptions, update button states
|
|
|
|
self.update_actions()
|
|
|
|
|
|
|
|
raise xmpp.NodeProcessed
|
|
|
|
|
|
|
|
def _subscribeCB(self, conn, request, groupnode):
|
|
|
|
'''We have just subscribed to a node. Update UI'''
|
|
|
|
self.subscriptions.add(groupnode)
|
|
|
|
|
|
|
|
model = self.window.services_treeview.get_model()
|
|
|
|
for row in model:
|
|
|
|
if row[1] == groupnode: # 1 = groupnode
|
|
|
|
row[4]=True
|
|
|
|
break
|
|
|
|
|
|
|
|
self.update_actions()
|
|
|
|
|
|
|
|
raise xmpp.NodeProcessed
|
|
|
|
|
|
|
|
def _unsubscribeCB(self, conn, request, groupnode):
|
|
|
|
'''We have just unsubscribed from a node. Update UI'''
|
|
|
|
self.subscriptions.remove(groupnode)
|
|
|
|
|
|
|
|
model = self.window.services_treeview.get_model()
|
|
|
|
for row in model:
|
|
|
|
if row[1] == groupnode: # 1 = groupnode
|
|
|
|
row[4]=False
|
|
|
|
break
|
|
|
|
|
|
|
|
self.update_actions()
|
|
|
|
|
|
|
|
raise xmpp.NodeProcessed
|
2005-10-30 10:58:13 +01:00
|
|
|
|
|
|
|
# Fill the global agent type info dictionary
|
|
|
|
_agent_type_info = _gen_agent_type_info()
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-01 11:30:36 +02:00
|
|
|
# vim: se ts=3:
|