Commit acc18364 authored by Daniel Brötzmann's avatar Daniel Brötzmann

MAMPrefereces: Slight layout and code rework

parent ead6d4f2
Pipeline #3740 passed with stages
in 2 minutes and 58 seconds
......@@ -32,143 +32,76 @@
<column type="gboolean"/>
</columns>
</object>
<object class="GtkGrid" id="preferences_grid">
<object class="GtkBox" id="mam_box">
<property name="width_request">400</property>
<property name="height_request">300</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">18</property>
<property name="margin_right">18</property>
<property name="margin_top">18</property>
<property name="margin_bottom">18</property>
<property name="row_spacing">5</property>
<property name="column_spacing">10</property>
<property name="border_width">18</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButtonBox">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="spacing">5</property>
<property name="layout_style">start</property>
<property name="halign">center</property>
<property name="spacing">12</property>
<child>
<object class="GtkButton" id="add_button">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="_on_add" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-add-symbolic</property>
</object>
</child>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Default</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="non_homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkButton" id="remove_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="_on_remove" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-remove-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="non_homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="column_spacing">5</property>
<child>
<object class="GtkLabel" id="default_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Default:</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="default_cb">
<object class="GtkComboBox" id="default_combo">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">False</property>
<property name="model">default_store</property>
<property name="active">0</property>
<property name="id_column">1</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="save_button">
<property name="label">Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">end</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="_on_save" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkOverlay" id="overlay">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<child>
<object class="GtkScrolledWindow">
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="pref_view">
......@@ -177,17 +110,17 @@
<property name="model">preferences_store</property>
<property name="search_column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection2"/>
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Jabber ID</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<property name="sort_indicator">True</property>
<property name="sort_column_id">0</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3">
<object class="GtkCellRendererText">
<property name="editable">True</property>
<property name="placeholder_text">user@example.org</property>
<signal name="edited" handler="_jid_edited" swapped="no"/>
......@@ -199,7 +132,7 @@
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Archive</property>
<property name="clickable">True</property>
<property name="alignment">0.5</property>
......@@ -224,13 +157,86 @@
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">2</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkToolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">icons</property>
<property name="icon_size">4</property>
<child>
<object class="GtkToolButton" id="add">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Add</property>
<property name="use_underline">True</property>
<property name="icon_name">list-add-symbolic</property>
<signal name="clicked" handler="_on_add" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="remove">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Remove</property>
<property name="use_underline">True</property>
<property name="icon_name">list-remove-symbolic</property>
<signal name="clicked" handler="_on_remove" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<style>
<class name="inline-toolbar"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="save_button">
<property name="label">_Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="valign">center</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="_on_save" swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</interface>
......@@ -22,7 +22,9 @@ from gajim.common import ged
from gajim.common.i18n import _
from gajim.gtk.util import get_builder
from gajim.gtk.dialogs import HigDialog
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import InformationDialog
log = logging.getLogger('gajim.gtk.mam_preferences')
......@@ -41,14 +43,11 @@ class MamPreferences(Gtk.ApplicationWindow):
self.account = account
self._con = app.connections[account]
self._builder = get_builder('mam_preferences.ui')
self.add(self._builder.get_object('preferences_grid'))
self._ui = get_builder('mam_preferences.ui')
self.add(self._ui.get_object('mam_box'))
self._default = self._builder.get_object('default_cb')
self._pref_store = self._builder.get_object('preferences_store')
self._overlay = self._builder.get_object('overlay')
self._spinner = Gtk.Spinner()
self._overlay.add_overlay(self._spinner)
self._ui.overlay.add_overlay(self._spinner)
app.ged.register_event_handler('mam-prefs-received', ged.GUI1,
self._mam_prefs_received)
......@@ -57,8 +56,8 @@ class MamPreferences(Gtk.ApplicationWindow):
app.ged.register_event_handler('mam-prefs-error', ged.GUI1,
self._mam_prefs_error)
self._set_grid_state(False)
self._builder.connect_signals(self)
self._set_mam_box_state(False)
self._ui.connect_signals(self)
self.show_all()
self._activate_spinner()
......@@ -69,12 +68,12 @@ class MamPreferences(Gtk.ApplicationWindow):
if obj.conn.name != self.account:
return
self._disable_spinner()
self._set_grid_state(True)
self._set_mam_box_state(True)
self._default.set_active_id(obj.default)
self._pref_store.clear()
self._ui.default_combo.set_active_id(obj.default)
self._ui.preferences_store.clear()
for item in obj.rules:
self._pref_store.append(item)
self._ui.preferences_store.append(item)
def _mam_prefs_saved(self, obj):
if obj.conn.name != self.account:
......@@ -82,13 +81,15 @@ class MamPreferences(Gtk.ApplicationWindow):
self._disable_spinner()
def on_ok(dialog):
def _on_ok():
self.destroy()
dialog = HigDialog(
self, Gtk.MessageType.INFO, Gtk.ButtonsType.OK,
_('Success!'), _('Your Archiving Preferences have been saved!'),
on_response_ok=on_ok, on_response_cancel=on_ok)
dialog.popup()
NewConfirmationDialog(
_('Archiving Preferences'),
_('Archiving Preferences Saved'),
_('Your archiving preferences have successfully been saved.'),
[DialogButton.make('OK',
callback=_on_ok)]).show()
def _mam_prefs_error(self, obj=None):
if obj and obj.conn.name != self.account:
......@@ -101,40 +102,37 @@ class MamPreferences(Gtk.ApplicationWindow):
else:
msg = _('Error received: {}').format(obj.error_msg)
dialog = HigDialog(
self, Gtk.MessageType.INFO, Gtk.ButtonsType.OK,
_('Error!'), msg)
dialog.popup()
self._set_grid_state(True)
InformationDialog(_('Archiving Preferences Error'), msg)
self._set_mam_box_state(True)
def _set_grid_state(self, state):
self._builder.get_object('preferences_grid').set_sensitive(state)
def _set_mam_box_state(self, state):
self._ui.mam_box.set_sensitive(state)
def _jid_edited(self, renderer, path, new_text):
iter_ = self._pref_store.get_iter(path)
self._pref_store.set_value(iter_, 0, new_text)
iter_ = self._ui.preferences_store.get_iter(path)
self._ui.preferences_store.set_value(iter_, 0, new_text)
def _pref_toggled(self, renderer, path):
iter_ = self._pref_store.get_iter(path)
current_value = self._pref_store[iter_][1]
self._pref_store.set_value(iter_, 1, not current_value)
iter_ = self._ui.preferences_store.get_iter(path)
current_value = self._ui.preferences_store[iter_][1]
self._ui.preferences_store.set_value(iter_, 1, not current_value)
def _on_add(self, button):
self._pref_store.append(['', False])
self._ui.preferences_store.append(['', False])
def _on_remove(self, button):
pref_view = self._builder.get_object('pref_view')
mod, paths = pref_view.get_selection().get_selected_rows()
mod, paths = self._ui.pref_view.get_selection().get_selected_rows()
for path in paths:
iter_ = mod.get_iter(path)
self._pref_store.remove(iter_)
self._ui.preferences_store.remove(iter_)
def _on_save(self, button):
self._activate_spinner()
self._set_grid_state(False)
self._set_mam_box_state(False)
items = []
default = self._default.get_active_id()
for item in self._pref_store:
default = self._ui.default_combo.get_active_id()
for item in self._ui.preferences_store:
items.append((item[0].lower(), item[1]))
self._con.get_module('MAM').set_mam_preferences(items, default)
......
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