Add feature-discovered event

This lets us move more GUI code out of the common module
This commit is contained in:
Philipp Hörist 2018-12-18 22:41:06 +01:00
parent 89d9940933
commit 7286f4286f
4 changed files with 37 additions and 10 deletions

View File

@ -38,10 +38,14 @@ from datetime import datetime
from pathlib import Path
from urllib.parse import unquote
from gi.repository import GLib, Gio, Gtk
import nbxmpp
from gi.repository import Gio
from gi.repository import GLib
from gi.repository import Gtk
import gajim
from gajim.common import app
from gajim.common import ged
from gajim.common import configpaths
from gajim.common import logging_helpers
from gajim.common import exceptions
@ -227,6 +231,10 @@ class GajimApplication(Gtk.Application):
from gajim import gui_menu_builder
gui_menu_builder.build_accounts_menu()
app.ged.register_event_handler('feature-discovered',
ged.CORE,
self._on_feature_discovered)
def _open_uris(self, uris):
for uri in uris:
app.log('uri_handler').info('open %s', uri)
@ -498,3 +506,14 @@ class GajimApplication(Gtk.Application):
elif new_state and state == 'online':
# We go online
self.lookup_action(account + action_name).set_enabled(True)
def _on_feature_discovered(self, event):
if event.feature == nbxmpp.NS_VCARD:
action = '%s-profile' % event.account
self.lookup_action(action).set_enabled(True)
elif event.feature in (nbxmpp.NS_MAM_1, nbxmpp.NS_MAM_2):
action = '%s-archive' % event.account
self.lookup_action(action).set_enabled(True)
elif event.feature == nbxmpp.NS_PRIVACY:
action = '%s-privacylists' % event.account
self.lookup_action(action).set_enabled(True)

View File

@ -21,6 +21,7 @@ from datetime import datetime, timedelta
import nbxmpp
from gajim.common import app
from gajim.common.nec import NetworkEvent
from gajim.common.nec import NetworkIncomingEvent
from gajim.common.const import ArchiveState
from gajim.common.const import KindConstant
@ -65,9 +66,11 @@ class MAM:
self.available = True
log.info('Discovered MAM %s: %s', self.archiving_namespace, from_)
# TODO: Move this GUI code out
action = app.app.lookup_action('%s-archive' % self._account)
action.set_enabled(True)
app.nec.push_incoming_event(
NetworkEvent('feature-discovered',
account=self._account,
feature=self.archiving_namespace))
def _from_valid_archive(self, stanza, message, groupchat):
if groupchat:

View File

@ -20,6 +20,7 @@ import nbxmpp
from gajim.common import app
from gajim.common import helpers
from gajim.common.nec import NetworkEvent
from gajim.common.nec import NetworkIncomingEvent
from gajim.common.connection_handlers_events import InformationEvent
@ -51,9 +52,11 @@ class PrivacyLists:
self.supported = True
log.info('Discovered XEP-0016: Privacy Lists: %s', from_)
# TODO: Move this GUI code out
action = app.app.lookup_action('%s-privacylists' % self._account)
action.set_enabled(True)
app.nec.push_incoming_event(
NetworkEvent('feature-discovered',
account=self._account,
feature=nbxmpp.NS_PRIVACY))
def _list_push_received(self, _con, stanza):
result = stanza.buildReply('result')

View File

@ -23,6 +23,7 @@ import nbxmpp
from gajim.common import app
from gajim.common.const import RequestAvatar
from gajim.common.nec import NetworkEvent
from gajim.common.nec import NetworkIncomingEvent
from gajim.common.connection_handlers_events import InformationEvent
@ -47,9 +48,10 @@ class VCardTemp:
self.supported = True
log.info('Discovered vcard-temp: %s', from_)
# TODO: Move this GUI code out
action = app.app.lookup_action('%s-profile' % self._account)
action.set_enabled(True)
app.nec.push_incoming_event(NetworkEvent('feature-discovered',
account=self._account,
feature=nbxmpp.NS_VCARD))
@staticmethod
def _node_to_dict(node):