Commit 407f65fd authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

ManagePEPServices: Rework window

parent a59679f5
Pipeline #3656 passed with stages
in 2 minutes and 30 seconds
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkImage" id="image1">
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="manage_pep_services">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-preferences</property>
</object>
<object class="GtkWindow" id="manage_pep_services_window">
<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="title" translatable="yes">PEP Service Configuration</property>
<property name="default_width">350</property>
<property name="default_height">150</property>
<property name="type_hint">dialog</property>
<signal name="destroy" handler="on_manage_pep_services_window_destroy" swapped="no"/>
<property name="border_width">18</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="vbox1">
<object class="GtkScrolledWindow">
<property name="width_request">350</property>
<property name="height_request">250</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="services_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="halign">end</property>
<property name="spacing">12</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<object class="GtkButton" id="configure_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Configure</property>
<property name="halign">center</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="_on_configure_button_clicked" swapped="no"/>
<child>
<object class="GtkTreeView" id="services_treeview">
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
<property name="can_focus">False</property>
<property name="icon_name">preferences-system-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="hbuttonbox1">
<object class="GtkButton" id="delete_button">
<property name="label">_Delete</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="delete_button">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">True</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="use_stock">True</property>
<signal name="clicked" handler="on_delete_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="configure_button">
<property name="label" translatable="yes">_Configure</property>
<property name="visible">True</property>
<property name="can_focus">True</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="image">image1</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="on_configure_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="close_button">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_close_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="_on_delete_button_clicked" swapped="no"/>
<style>
<class name="destructive-action"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">6</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</interface>
......@@ -12,6 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gdk
from gi.repository import Gtk
from gajim.common import app
......@@ -24,46 +25,57 @@ from gajim.gtk.dataform import DataFormDialog
from gajim.gtk.util import get_builder
class ManagePEPServicesWindow:
class ManagePEPServicesWindow(Gtk.ApplicationWindow):
def __init__(self, account):
self.xml = get_builder('manage_pep_services_window.ui')
self.window = self.xml.get_object('manage_pep_services_window')
self.window.set_transient_for(app.interface.roster.window)
self.xml.get_object('configure_button').set_sensitive(False)
self.xml.get_object('delete_button').set_sensitive(False)
self.xml.connect_signals(self)
Gtk.ApplicationWindow.__init__(self)
self.set_application(app.app)
self.set_position(Gtk.WindowPosition.CENTER)
self.set_show_menubar(False)
self.set_name('ManagePEPServicesWindow')
self.set_default_size(300, 350)
self.set_resizable(True)
self.set_transient_for(app.interface.roster.window)
self._ui = get_builder('manage_pep_services_window.ui')
self.add(self._ui.manage_pep_services)
self.account = account
self.set_title(_('PEP Service Configuration (%s)') % self.account)
self._con = app.connections[self.account]
self.init_services()
self.xml.get_object('services_treeview').get_selection().connect(
'changed', self.on_services_selection_changed)
self._init_services()
self._ui.services_treeview.get_selection().connect(
'changed', self._on_services_selection_changed)
app.ged.register_event_handler(
'pubsub-config-received', ged.GUI1, self._nec_pep_config_received)
self.window.show_all()
self.show_all()
self.connect('key-press-event', self._on_key_press_event)
self.connect('destroy', self._on_destroy)
self._ui.connect_signals(self)
def _on_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_Escape:
self.destroy()
def on_manage_pep_services_window_destroy(self, widget):
del app.interface.instances[self.account]['pep_services']
def _on_destroy(self, *args):
app.ged.remove_event_handler(
'pubsub-config-received', ged.GUI1, self._nec_pep_config_received)
def on_close_button_clicked(self, widget):
self.window.destroy()
def on_services_selection_changed(self, sel):
self.xml.get_object('configure_button').set_sensitive(True)
self.xml.get_object('delete_button').set_sensitive(True)
def _on_services_selection_changed(self, sel):
self._ui.configure_button.set_sensitive(True)
self._ui.delete_button.set_sensitive(True)
def init_services(self):
self.treeview = self.xml.get_object('services_treeview')
def _init_services(self):
# service, access_model, group
self.treestore = Gtk.ListStore(str)
self.treeview.set_model(self.treestore)
self.treestore.set_sort_column_id(0, Gtk.SortType.ASCENDING)
self._ui.services_treeview.set_model(self.treestore)
col = Gtk.TreeViewColumn('Service')
self.treeview.append_column(col)
col = Gtk.TreeViewColumn(_('Service'))
col.set_sort_column_id(0)
self._ui.services_treeview.append_column(col)
cellrenderer_text = Gtk.CellRendererText()
col.pack_start(cellrenderer_text, True)
......@@ -71,7 +83,9 @@ class ManagePEPServicesWindow:
jid = self._con.get_own_jid().getStripped()
self._con.get_module('Discovery').disco_items(
jid, success_cb=self._items_received, error_cb=self._items_error)
jid,
success_cb=self._items_received,
error_cb=self._items_error)
def _items_received(self, from_, node, items):
jid = self._con.get_own_jid().getStripped()
......@@ -82,10 +96,10 @@ class ManagePEPServicesWindow:
def _items_error(self, from_, error):
ErrorDialog('Error', error)
def node_removed(self, jid, node):
def _node_removed(self, jid, node):
if jid != app.get_jid_from_account(self.account):
return
model = self.treeview.get_model()
model = self._ui.services_treeview.get_model()
iter_ = model.get_iter_first()
while iter_:
if model[iter_][0] == node:
......@@ -93,16 +107,16 @@ class ManagePEPServicesWindow:
break
iter_ = model.iter_next(iter_)
def node_not_removed(self, jid, node, msg):
def _node_not_removed(self, jid, node, msg):
if jid != app.get_jid_from_account(self.account):
return
WarningDialog(
_('PEP node was not removed'),
_('PEP node %(node)s was not removed: %(message)s') % {
_('PEP node %(node)s was not removed:\n%(message)s') % {
'node': node, 'message': msg})
def on_delete_button_clicked(self, widget):
selection = self.treeview.get_selection()
def _on_delete_button_clicked(self, widget):
selection = self._ui.services_treeview.get_selection()
if not selection:
return
model, iter_ = selection.get_selected()
......@@ -110,11 +124,11 @@ class ManagePEPServicesWindow:
our_jid = app.get_jid_from_account(self.account)
con = app.connections[self.account]
con.get_module('PubSub').send_pb_delete(our_jid, node,
on_ok=self.node_removed,
on_fail=self.node_not_removed)
on_ok=self._node_removed,
on_fail=self._node_not_removed)
def on_configure_button_clicked(self, widget):
selection = self.treeview.get_selection()
def _on_configure_button_clicked(self, widget):
selection = self._ui.services_treeview.get_selection()
if not selection:
return
model, iter_ = selection.get_selected()
......@@ -130,7 +144,7 @@ class ManagePEPServicesWindow:
def _nec_pep_config_received(self, obj):
DataFormDialog(_('Configure %s') % obj.node,
self.window,
self,
obj.form,
obj.node,
self._on_config_submit)
......@@ -3488,12 +3488,12 @@ class RosterWindow:
helpers.update_optional_features(account)
def on_pep_services_menuitem_activate(self, widget, account):
if 'pep_services' in app.interface.instances[account]:
app.interface.instances[account]['pep_services'].window.present()
def _on_pep_services_menuitem_activate(self, widget, account):
window = app.get_app_window(ManagePEPServicesWindow, account)
if window is None:
ManagePEPServicesWindow(account)
else:
app.interface.instances[account]['pep_services'] = \
ManagePEPServicesWindow(account)
window.present()
def on_add_new_contact(self, widget, account):
AddNewContactWindow(account)
......@@ -4814,7 +4814,7 @@ class RosterWindow:
pep_config.set_sensitive(True)
pep_submenu.append(pep_config)
pep_config.connect('activate',
self.on_pep_services_menuitem_activate, account)
self._on_pep_services_menuitem_activate, account)
else:
pep_menuitem.set_sensitive(False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment