ServerInfo: Show if features are disabled by user

- Show new Symbol if a feature is available but not enabled
- Add this info to the tooltip
This commit is contained in:
Philipp Hörist 2017-11-06 21:46:25 +01:00
parent 6fc2cd30e8
commit 8c8b491846
3 changed files with 45 additions and 30 deletions

View file

@ -170,7 +170,7 @@ class CommonConnection:
self.roster_supported = True self.roster_supported = True
self.blocking_supported = False self.blocking_supported = False
self.addressing_supported = False self.addressing_supported = False
self.carbons_enabled = False self.carbons_available = False
self.muc_jid = {} # jid of muc server for each transport type self.muc_jid = {} # jid of muc server for each transport type
self._stun_servers = [] # STUN servers of our jabber server self._stun_servers = [] # STUN servers of our jabber server
@ -1942,9 +1942,10 @@ class Connection(CommonConnection, ConnectionHandlers):
self.blocking_supported = True self.blocking_supported = True
if nbxmpp.NS_ADDRESS in obj.features: if nbxmpp.NS_ADDRESS in obj.features:
self.addressing_supported = True self.addressing_supported = True
if nbxmpp.NS_CARBONS in obj.features and app.config.get_per( if nbxmpp.NS_CARBONS in obj.features:
'accounts', self.name, 'enable_message_carbons'): self.carbons_available = True
self.carbons_enabled = True if app.config.get_per('accounts', self.name,
'enable_message_carbons'):
# Server supports carbons, activate it # Server supports carbons, activate it
iq = nbxmpp.Iq('set') iq = nbxmpp.Iq('set')
iq.setTag('enable', namespace=nbxmpp.NS_CARBONS) iq.setTag('enable', namespace=nbxmpp.NS_CARBONS)

View file

@ -58,6 +58,7 @@ class Color:
GREEN = Gdk.RGBA(red=115/255, green=210/255, blue=22/255, alpha=1) GREEN = Gdk.RGBA(red=115/255, green=210/255, blue=22/255, alpha=1)
RED = Gdk.RGBA(red=204/255, green=0, blue=0, alpha=1) RED = Gdk.RGBA(red=204/255, green=0, blue=0, alpha=1)
GREY = Gdk.RGBA(red=195/255, green=195/255, blue=192/255, alpha=1) GREY = Gdk.RGBA(red=195/255, green=195/255, blue=192/255, alpha=1)
ORANGE = Gdk.RGBA(red=245/255, green=121/255, blue=0/255, alpha=1)
def get_icon_pixmap(icon_name, size=16, color=None, quiet=False): def get_icon_pixmap(icon_name, size=16, color=None, quiet=False):
try: try:

View file

@ -99,7 +99,7 @@ class ServerInfoDialog(Gtk.Dialog):
for index, item in enumerate(func()): for index, item in enumerate(func()):
row = listbox.get_row_at_index(index) row = listbox.get_row_at_index(index)
row.get_child().update(item) row.get_child().update(item)
row.set_tooltip_text(item.tooltip) row.set_tooltip_text(row.get_child().tooltip)
def request_last_activity(self): def request_last_activity(self):
if not app.account_is_connected(self.account): if not app.account_is_connected(self.account):
@ -144,31 +144,38 @@ class ServerInfoDialog(Gtk.Dialog):
def add_feature(self, feature): def add_feature(self, feature):
item = FeatureItem(feature) item = FeatureItem(feature)
self.feature_listbox.add(item) self.feature_listbox.add(item)
item.get_parent().set_tooltip_text(feature.tooltip) item.get_parent().set_tooltip_text(item.tooltip)
def get_features(self): def get_features(self):
con = app.connections[self.account] con = app.connections[self.account]
Feature = namedtuple('Feature', ['name', 'enabled', 'tooltip']) Feature = namedtuple('Feature',
['name', 'available', 'tooltip', 'enabled'])
carbons_enabled = app.config.get_per('accounts', self.account,
'enable_message_carbons')
mam_enabled = app.config.get_per('accounts', self.account,
'sync_logs_with_server')
return [ return [
Feature('XEP-0016: Privacy Lists', Feature('XEP-0016: Privacy Lists',
con.privacy_rules_supported, None), con.privacy_rules_supported, '', None),
Feature('XEP-0045: Multi-User Chat', con.muc_jid, None), Feature('XEP-0045: Multi-User Chat', con.muc_jid, '', None),
Feature('XEP-0054: vcard-temp', con.vcard_supported, None), Feature('XEP-0054: vcard-temp', con.vcard_supported, '', None),
Feature('XEP-0163: Personal Eventing Protocol', Feature('XEP-0163: Personal Eventing Protocol',
con.pep_supported, None), con.pep_supported, '', None),
Feature('XEP-0163: #publish-options', Feature('XEP-0163: #publish-options',
con.pubsub_publish_options_supported, None), con.pubsub_publish_options_supported, '', None),
Feature('XEP-0191: Blocking Command', Feature('XEP-0191: Blocking Command',
con.blocking_supported, nbxmpp.NS_BLOCKING), con.blocking_supported, nbxmpp.NS_BLOCKING, None),
Feature('XEP-0198: Stream Management', Feature('XEP-0198: Stream Management',
con.sm.enabled, nbxmpp.NS_STREAM_MGMT), con.sm.enabled, nbxmpp.NS_STREAM_MGMT, None),
Feature('XEP-0280: Message Carbons', Feature('XEP-0280: Message Carbons',
con.carbons_enabled, nbxmpp.NS_CARBONS), con.carbons_available, nbxmpp.NS_CARBONS, carbons_enabled),
Feature('XEP-0313: Message Archive Management', Feature('XEP-0313: Message Archive Management',
con.archiving_namespace, con.archiving_namespace), con.archiving_namespace, con.archiving_namespace,
mam_enabled),
Feature('XEP-0363: HTTP File Upload', Feature('XEP-0363: HTTP File Upload',
con.httpupload, nbxmpp.NS_HTTPUPLOAD)] con.httpupload, nbxmpp.NS_HTTPUPLOAD, None)]
def add_info(self, info): def add_info(self, info):
self.info_listbox.add(ServerInfoItem(info)) self.info_listbox.add(ServerInfoItem(info))
@ -198,32 +205,38 @@ class ServerInfoDialog(Gtk.Dialog):
class FeatureItem(Gtk.Grid): class FeatureItem(Gtk.Grid):
def __init__(self, feature): def __init__(self, feature):
super().__init__() super().__init__()
self.tooltip = feature.tooltip
self.set_column_spacing(6) self.set_column_spacing(6)
self.icon = Gtk.Image() self.icon = Gtk.Image()
self.feature_label = Gtk.Label(label=feature.name) self.feature_label = Gtk.Label(label=feature.name)
self.set_feature_enabled(bool(feature.enabled)) self.set_feature(feature.available, feature.enabled)
self.add(self.icon) self.add(self.icon)
self.add(self.feature_label) self.add(self.feature_label)
def set_feature_enabled(self, enabled): def set_feature(self, available, enabled):
if enabled: if not available:
self.icon.set_from_pixbuf(
get_icon_pixmap('emblem-ok-symbolic', color=[Color.GREEN]))
else:
self.icon.set_from_pixbuf( self.icon.set_from_pixbuf(
get_icon_pixmap('window-close-symbolic', color=[Color.RED])) get_icon_pixmap('window-close-symbolic', color=[Color.RED]))
elif enabled is False:
self.icon.set_from_pixbuf(
get_icon_pixmap('dialog-warning-symbolic',
color=[Color.ORANGE]))
self.tooltip += _('\nDisabled in config')
else:
self.icon.set_from_pixbuf(
get_icon_pixmap('emblem-ok-symbolic', color=[Color.GREEN]))
def update(self, feature): def update(self, feature):
self.set_feature_enabled(bool(feature.enabled)) self.tooltip = feature.tooltip
self.set_feature(feature.available, feature.enabled)
class ServerInfoItem(Gtk.Grid): class ServerInfoItem(Gtk.Grid):
def __init__(self, info): def __init__(self, info):
super().__init__() super().__init__()
self.tooltip = info.tooltip
self.set_hexpand(True) self.set_hexpand(True)
self.insert_column(0) self.insert_column(0)
self.set_column_homogeneous(True) self.set_column_homogeneous(True)