2017-07-20 00:01:24 +02:00
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
2018-07-16 23:22:33 +02:00
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
2017-07-20 00:01:24 +02:00
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2018-07-16 23:22:33 +02:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-07-20 00:01:24 +02:00
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-07-16 23:22:33 +02:00
|
|
|
import logging
|
2017-07-20 00:01:24 +02:00
|
|
|
from collections import namedtuple
|
2017-11-06 20:10:26 +01:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2017-11-06 20:14:36 +01:00
|
|
|
import nbxmpp
|
2018-07-16 23:22:33 +02:00
|
|
|
from gi.repository import Gtk
|
2017-07-20 00:01:24 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import ged
|
2018-10-04 23:55:35 +02:00
|
|
|
from gajim.common.i18n import _
|
2017-07-20 00:01:24 +02:00
|
|
|
|
2018-07-16 23:22:33 +02:00
|
|
|
log = logging.getLogger('gajim.gtk.serverinfo')
|
2017-11-06 20:10:26 +01:00
|
|
|
|
|
|
|
|
2017-07-20 00:01:24 +02:00
|
|
|
class ServerInfoDialog(Gtk.Dialog):
|
|
|
|
def __init__(self, account):
|
|
|
|
flags = Gtk.DialogFlags.DESTROY_WITH_PARENT
|
|
|
|
super().__init__(_('Server Info'), None, flags)
|
|
|
|
|
|
|
|
self.account = account
|
2017-08-13 13:18:56 +02:00
|
|
|
self.set_transient_for(app.interface.roster.window)
|
2017-07-20 00:01:24 +02:00
|
|
|
self.set_resizable(False)
|
|
|
|
|
|
|
|
grid = Gtk.Grid()
|
|
|
|
grid.set_name('ServerInfoGrid')
|
|
|
|
grid.set_row_spacing(10)
|
|
|
|
grid.set_hexpand(True)
|
|
|
|
|
|
|
|
self.info_listbox = Gtk.ListBox()
|
|
|
|
self.info_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
|
|
|
|
self.info_listbox.set_header_func(self.header_func, 'Information')
|
|
|
|
grid.attach(self.info_listbox, 0, 0, 1, 1)
|
|
|
|
|
|
|
|
self.feature_listbox = Gtk.ListBox()
|
|
|
|
self.feature_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
|
|
|
|
self.feature_listbox.set_header_func(self.header_func, 'Features')
|
|
|
|
grid.attach(self.feature_listbox, 0, 1, 1, 1)
|
|
|
|
|
|
|
|
box = self.get_content_area()
|
|
|
|
box.pack_start(grid, True, True, 0)
|
|
|
|
box.set_property('margin', 12)
|
|
|
|
box.set_spacing(18)
|
|
|
|
|
|
|
|
self.connect('response', self.on_response)
|
|
|
|
self.connect('destroy', self.on_destroy)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('version-result-received',
|
2017-11-06 20:14:36 +01:00
|
|
|
ged.CORE,
|
|
|
|
self._nec_version_result_received)
|
2017-07-20 00:01:24 +02:00
|
|
|
|
2018-07-22 12:18:24 +02:00
|
|
|
app.ged.register_event_handler('server-disco-received',
|
2017-11-06 20:14:36 +01:00
|
|
|
ged.GUI1,
|
2018-07-22 12:18:24 +02:00
|
|
|
self._server_disco_received)
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
self.version = ''
|
2017-11-06 20:10:26 +01:00
|
|
|
self.uptime = ''
|
2017-08-13 13:18:56 +02:00
|
|
|
self.hostname = app.get_hostname_from_account(account)
|
2018-06-24 19:53:09 +02:00
|
|
|
con = app.connections[account]
|
|
|
|
con.get_module('SoftwareVersion').request_os_info(self.hostname, None)
|
2017-11-06 20:10:26 +01:00
|
|
|
self.request_last_activity()
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
for feature in self.get_features():
|
|
|
|
self.add_feature(feature)
|
|
|
|
|
|
|
|
for info in self.get_infos():
|
|
|
|
self.add_info(info)
|
|
|
|
|
|
|
|
self.show_all()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def header_func(row, before, user_data):
|
|
|
|
if before:
|
|
|
|
row.set_header(None)
|
|
|
|
else:
|
|
|
|
label = Gtk.Label(label=user_data)
|
|
|
|
label.set_halign(Gtk.Align.START)
|
|
|
|
row.set_header(label)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def update(func, listbox):
|
|
|
|
for index, item in enumerate(func()):
|
|
|
|
row = listbox.get_row_at_index(index)
|
|
|
|
row.get_child().update(item)
|
2017-11-06 21:46:25 +01:00
|
|
|
row.set_tooltip_text(row.get_child().tooltip)
|
2017-07-20 00:01:24 +02:00
|
|
|
|
2017-11-06 20:10:26 +01:00
|
|
|
def request_last_activity(self):
|
|
|
|
if not app.account_is_connected(self.account):
|
|
|
|
return
|
|
|
|
con = app.connections[self.account]
|
|
|
|
iq = nbxmpp.Iq(to=self.hostname, typ='get', queryNS=nbxmpp.NS_LAST)
|
|
|
|
con.connection.SendAndCallForResponse(iq, self._on_last_activity)
|
|
|
|
|
|
|
|
def _on_last_activity(self, stanza):
|
|
|
|
if 'server_info' not in app.interface.instances[self.account]:
|
|
|
|
# Window got closed in the meantime
|
|
|
|
return
|
|
|
|
if not nbxmpp.isResultNode(stanza):
|
|
|
|
log.warning('Received malformed result: %s', stanza)
|
|
|
|
return
|
|
|
|
if stanza.getQueryNS() != nbxmpp.NS_LAST:
|
|
|
|
log.warning('Wrong namespace on result: %s', stanza)
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
seconds = int(stanza.getQuery().getAttr('seconds'))
|
|
|
|
except (ValueError, TypeError, AttributeError):
|
|
|
|
log.exception('Received malformed last activity result')
|
|
|
|
else:
|
|
|
|
delta = timedelta(seconds=seconds)
|
|
|
|
hours = 0
|
|
|
|
if seconds >= 3600:
|
|
|
|
hours = delta.seconds // 3600
|
2018-01-08 00:24:17 +01:00
|
|
|
self.uptime = _('%(days)s days, %(hours)s hours') % {
|
|
|
|
'days': delta.days, 'hours': hours}
|
2017-11-06 20:10:26 +01:00
|
|
|
self.update(self.get_infos, self.info_listbox)
|
|
|
|
|
2017-07-20 00:01:24 +02:00
|
|
|
def _nec_version_result_received(self, obj):
|
|
|
|
if obj.jid != self.hostname:
|
|
|
|
return
|
2018-08-26 10:38:42 +02:00
|
|
|
self.version = obj.client_info or _('Unknown')
|
2017-07-20 00:01:24 +02:00
|
|
|
self.update(self.get_infos, self.info_listbox)
|
|
|
|
|
2018-07-22 12:18:24 +02:00
|
|
|
def _server_disco_received(self, obj):
|
2017-07-20 00:01:24 +02:00
|
|
|
self.update(self.get_features, self.feature_listbox)
|
|
|
|
|
|
|
|
def add_feature(self, feature):
|
|
|
|
item = FeatureItem(feature)
|
|
|
|
self.feature_listbox.add(item)
|
2017-11-06 21:46:25 +01:00
|
|
|
item.get_parent().set_tooltip_text(item.tooltip)
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
def get_features(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
con = app.connections[self.account]
|
2017-11-06 21:46:25 +01:00
|
|
|
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')
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
return [
|
2017-11-06 20:14:36 +01:00
|
|
|
Feature('XEP-0016: Privacy Lists',
|
2018-07-22 12:18:24 +02:00
|
|
|
con.get_module('PrivacyLists').supported, '', None),
|
2017-11-06 21:46:25 +01:00
|
|
|
Feature('XEP-0045: Multi-User Chat', con.muc_jid, '', None),
|
2018-07-22 12:18:24 +02:00
|
|
|
Feature('XEP-0054: vcard-temp',
|
|
|
|
con.get_module('VCardTemp').supported, '', None),
|
2017-11-06 20:14:36 +01:00
|
|
|
Feature('XEP-0163: Personal Eventing Protocol',
|
2018-07-22 12:18:24 +02:00
|
|
|
con.get_module('PEP').supported, '', None),
|
2017-11-06 20:14:36 +01:00
|
|
|
Feature('XEP-0163: #publish-options',
|
2018-07-22 12:18:24 +02:00
|
|
|
con.get_module('PubSub').publish_options, '', None),
|
2017-11-06 20:14:36 +01:00
|
|
|
Feature('XEP-0191: Blocking Command',
|
2018-07-22 12:18:24 +02:00
|
|
|
con.get_module('Blocking').supported,
|
|
|
|
nbxmpp.NS_BLOCKING, None),
|
2017-11-06 20:14:36 +01:00
|
|
|
Feature('XEP-0198: Stream Management',
|
2017-11-06 21:46:25 +01:00
|
|
|
con.sm.enabled, nbxmpp.NS_STREAM_MGMT, None),
|
2018-07-21 13:24:29 +02:00
|
|
|
Feature('XEP-0258: Security Labels in XMPP',
|
|
|
|
con.get_module('SecLabels').supported,
|
|
|
|
nbxmpp.NS_SECLABEL, None),
|
2017-11-06 20:14:36 +01:00
|
|
|
Feature('XEP-0280: Message Carbons',
|
2018-07-22 12:18:24 +02:00
|
|
|
con.get_module('Carbons').supported,
|
|
|
|
nbxmpp.NS_CARBONS, carbons_enabled),
|
2017-11-06 20:14:36 +01:00
|
|
|
Feature('XEP-0313: Message Archive Management',
|
2018-07-09 00:21:24 +02:00
|
|
|
con.get_module('MAM').archiving_namespace,
|
|
|
|
con.get_module('MAM').archiving_namespace,
|
2017-11-06 21:46:25 +01:00
|
|
|
mam_enabled),
|
2017-11-06 20:14:36 +01:00
|
|
|
Feature('XEP-0363: HTTP File Upload',
|
2018-07-07 01:15:48 +02:00
|
|
|
con.get_module('HTTPUpload').available,
|
2018-09-01 20:34:56 +02:00
|
|
|
con.get_module('HTTPUpload').httpupload_namespace, None),
|
|
|
|
Feature('XEP-0398: Avatar Conversion',
|
|
|
|
con.avatar_conversion, '', None)
|
|
|
|
]
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
def add_info(self, info):
|
|
|
|
self.info_listbox.add(ServerInfoItem(info))
|
|
|
|
|
|
|
|
def get_infos(self):
|
|
|
|
Info = namedtuple('Info', ['name', 'value', 'tooltip'])
|
|
|
|
return [
|
|
|
|
Info(_('Hostname'), self.hostname, None),
|
2017-11-06 20:10:26 +01:00
|
|
|
Info(_('Server Software'), self.version, None),
|
|
|
|
Info(_('Server Uptime'), self.uptime, None)]
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
def on_response(self, dialog, response):
|
|
|
|
if response == Gtk.ResponseType.OK:
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
def on_destroy(self, *args):
|
2017-08-13 13:18:56 +02:00
|
|
|
del app.interface.instances[self.account]['server_info']
|
|
|
|
app.ged.remove_event_handler('version-result-received',
|
2017-11-06 20:14:36 +01:00
|
|
|
ged.CORE,
|
|
|
|
self._nec_version_result_received)
|
2017-07-20 00:01:24 +02:00
|
|
|
|
2018-07-22 12:18:24 +02:00
|
|
|
app.ged.remove_event_handler('server-disco-received',
|
2017-11-06 20:14:36 +01:00
|
|
|
ged.GUI1,
|
2018-07-22 12:18:24 +02:00
|
|
|
self._server_disco_received)
|
2017-11-06 20:14:36 +01:00
|
|
|
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
class FeatureItem(Gtk.Grid):
|
|
|
|
def __init__(self, feature):
|
|
|
|
super().__init__()
|
2017-11-06 21:46:25 +01:00
|
|
|
self.tooltip = feature.tooltip
|
2017-07-20 00:01:24 +02:00
|
|
|
self.set_column_spacing(6)
|
|
|
|
|
|
|
|
self.icon = Gtk.Image()
|
|
|
|
self.feature_label = Gtk.Label(label=feature.name)
|
2017-11-06 21:46:25 +01:00
|
|
|
self.set_feature(feature.available, feature.enabled)
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
self.add(self.icon)
|
|
|
|
self.add(self.feature_label)
|
|
|
|
|
2017-11-06 21:46:25 +01:00
|
|
|
def set_feature(self, available, enabled):
|
2018-07-21 13:24:29 +02:00
|
|
|
self.icon.get_style_context().remove_class('error-color')
|
|
|
|
self.icon.get_style_context().remove_class('warning-color')
|
|
|
|
self.icon.get_style_context().remove_class('success-color')
|
|
|
|
|
2017-11-06 21:46:25 +01:00
|
|
|
if not available:
|
2018-07-16 23:22:33 +02:00
|
|
|
self.icon.set_from_icon_name('window-close-symbolic',
|
|
|
|
Gtk.IconSize.MENU)
|
|
|
|
self.icon.get_style_context().add_class('error-color')
|
2017-11-06 21:46:25 +01:00
|
|
|
elif enabled is False:
|
2018-07-16 23:22:33 +02:00
|
|
|
self.icon.set_from_icon_name('dialog-warning-symbolic',
|
|
|
|
Gtk.IconSize.MENU)
|
2017-11-06 21:46:25 +01:00
|
|
|
self.tooltip += _('\nDisabled in config')
|
2018-07-16 23:22:33 +02:00
|
|
|
self.icon.get_style_context().add_class('warning-color')
|
2017-07-20 00:01:24 +02:00
|
|
|
else:
|
2018-07-16 23:22:33 +02:00
|
|
|
self.icon.set_from_icon_name('emblem-ok-symbolic',
|
|
|
|
Gtk.IconSize.MENU)
|
|
|
|
self.icon.get_style_context().add_class('success-color')
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
def update(self, feature):
|
2017-11-06 21:46:25 +01:00
|
|
|
self.tooltip = feature.tooltip
|
|
|
|
self.set_feature(feature.available, feature.enabled)
|
2017-07-20 00:01:24 +02:00
|
|
|
|
2017-11-06 20:14:36 +01:00
|
|
|
|
2017-07-20 00:01:24 +02:00
|
|
|
class ServerInfoItem(Gtk.Grid):
|
|
|
|
def __init__(self, info):
|
|
|
|
super().__init__()
|
2017-11-06 21:46:25 +01:00
|
|
|
self.tooltip = info.tooltip
|
2017-07-20 00:01:24 +02:00
|
|
|
self.set_hexpand(True)
|
|
|
|
self.insert_column(0)
|
|
|
|
self.set_column_homogeneous(True)
|
|
|
|
|
|
|
|
self.info = Gtk.Label(label=info.name)
|
|
|
|
self.info.set_halign(Gtk.Align.START)
|
|
|
|
self.info.set_hexpand(True)
|
|
|
|
self.value = Gtk.Label(label=info.value)
|
|
|
|
self.value.set_halign(Gtk.Align.START)
|
|
|
|
self.value.set_hexpand(True)
|
2017-11-06 23:02:57 +01:00
|
|
|
self.value.set_selectable(True)
|
2017-07-20 00:01:24 +02:00
|
|
|
|
|
|
|
self.add(self.info)
|
|
|
|
self.add(self.value)
|
|
|
|
|
|
|
|
def update(self, info):
|
|
|
|
self.value.set_text(info.value)
|