Request security catalog from the barejid

- Some Code/UI cleanup
This commit is contained in:
Philipp Hörist 2018-09-30 00:15:00 +02:00
parent 24e771266b
commit a8c0567bd0
3 changed files with 70 additions and 74 deletions

View File

@ -185,19 +185,18 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
def _sec_labels_received(self, event): def _sec_labels_received(self, event):
if event.account != self.account: if event.account != self.account:
return return
jid = nbxmpp.JID(self.contact.jid) if event.jid != self.contact.jid:
if event.host != jid.getDomain():
return return
lb = self.seclabel_combo.get_model() model = self.seclabel_combo.get_model()
lb.clear() model.clear()
i = 0
sel = 0 sel = 0
_label, labellist, default = event.catalog _label, labellist, default = event.catalog
for label in labellist: for index, label in enumerate(labellist):
lb.append([label]) model.append([label])
if label == default: if label == default:
sel = i sel = index
i += 1
self.seclabel_combo.set_active(sel) self.seclabel_combo.set_active(sel)
self.seclabel_combo.set_no_show_all(False) self.seclabel_combo.set_no_show_all(False)
self.seclabel_combo.show_all() self.seclabel_combo.show_all()
@ -773,8 +772,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
return return
con = app.connections[self.account] con = app.connections[self.account]
jid = nbxmpp.JID(self.contact.jid) catalog = con.get_module('SecLabels').get_catalog(self.contact.jid)
catalog = con.get_module('SecLabels').get_catalog(jid.getDomain())
labels, label_list, _ = catalog labels, label_list, _ = catalog
lname = label_list[idx] lname = label_list[idx]
label = labels[lname] label = labels[lname]

View File

@ -42,12 +42,11 @@ class SecLabels:
log.info('Discovered security labels: %s', from_) log.info('Discovered security labels: %s', from_)
def request_catalog(self, jid): def request_catalog(self, jid):
jid = nbxmpp.JID(jid)
server = app.get_jid_from_account(self._account).split("@")[1] server = app.get_jid_from_account(self._account).split("@")[1]
iq = nbxmpp.Iq(typ='get', to=server) iq = nbxmpp.Iq(typ='get', to=server)
iq.addChild(name='catalog', iq.addChild(name='catalog',
namespace=nbxmpp.NS_SECLABEL_CATALOG, namespace=nbxmpp.NS_SECLABEL_CATALOG,
attrs={'to': jid.getDomain()}) attrs={'to': jid})
log.info('Request catalog: server: %s, to: %s', server, jid) log.info('Request catalog: server: %s, to: %s', server, jid)
self._con.connection.SendAndCallForResponse( self._con.connection.SendAndCallForResponse(
iq, self._catalog_received) iq, self._catalog_received)
@ -74,11 +73,11 @@ class SecLabels:
catalog = (labels, label_list, default) catalog = (labels, label_list, default)
self._catalogs[to] = catalog self._catalogs[to] = catalog
log.info('Received catalog from %s', stanza.getFrom()) log.info('Received catalog: %s', to)
log.debug(catalog) log.debug(catalog)
app.nec.push_incoming_event(SecLabelCatalog( app.nec.push_incoming_event(SecLabelCatalog(
None, account=self._account, host=to, catalog=catalog)) None, account=self._account, jid=to, catalog=catalog))
def get_catalog(self, jid): def get_catalog(self, jid):
return self._catalogs.get(jid) return self._catalogs.get(jid)

View File

@ -634,17 +634,57 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child> <child>
<object class="GtkComboBox" id="label_selector"> <object class="GtkMenuButton" id="emoticons_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Show a list of emoticons (Alt+M)</property>
<property name="relief">none</property>
<child>
<object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="icon_name">face-smile-symbolic</property>
</object>
</child>
<style>
<class name="chatcontrol-actionbar-button"/>
</style>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkMenuButton" id="formattings_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="has_tooltip">True</property>
<property name="relief">none</property>
<property name="popup">formattings_menu</property>
<child>
<object class="GtkImage" id="image10">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">format-text-bold-symbolic</property>
<property name="icon_size">1</property>
</object>
</child>
<style>
<class name="chatcontrol-actionbar-button"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child> <child>
<object class="GtkBox" id="audio_buttons_hbox"> <object class="GtkBox" id="audio_buttons_hbox">
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -746,7 +786,18 @@ audio-mic-volume-low</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">1</property> <property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="label_selector">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -770,7 +821,7 @@ audio-mic-volume-low</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">2</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -797,7 +848,7 @@ audio-mic-volume-low</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">3</property> <property name="position">5</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -818,7 +869,7 @@ audio-mic-volume-low</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">4</property> <property name="position">6</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -845,58 +896,6 @@ audio-mic-volume-low</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="emoticons_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Show a list of emoticons (Alt+M)</property>
<property name="relief">none</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">face-smile-symbolic</property>
</object>
</child>
<style>
<class name="chatcontrol-actionbar-button"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="formattings_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="has_tooltip">True</property>
<property name="relief">none</property>
<property name="popup">formattings_menu</property>
<child>
<object class="GtkImage" id="image10">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">format-text-bold-symbolic</property>
<property name="icon_size">1</property>
</object>
</child>
<style>
<class name="chatcontrol-actionbar-button"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">7</property> <property name="position">7</property>
</packing> </packing>
</child> </child>