Commit 854927e0 authored by Daniel Brötzmann's avatar Daniel Brötzmann
Browse files

GroupChatControl: Add settings page

parent 50f2fa49
Pipeline #6393 passed with stages
in 3 minutes and 51 seconds
......@@ -1940,6 +1940,67 @@
<property name="position">13</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid" id="settings_grid">
<property name="name">settings_grid</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">18</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="margin_top">6</property>
<property name="spacing">12</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">_Close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="_on_page_cancel_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="name">muc-settings</property>
<property name="position">14</property>
</packing>
</child>
</object>
<packing>
<property name="index">-1</property>
......
......@@ -73,12 +73,12 @@
from gajim.gtk.dataform import DataFormWidget
from gajim.gtk.groupchat_info import GroupChatInfoScrolled
from gajim.gtk.groupchat_invite import GroupChatInvite
from gajim.gtk.groupchat_settings import GroupChatSettingsScrolled
from gajim.gtk.groupchat_roster import GroupchatRoster
from gajim.gtk.util import NickCompletionGenerator
from gajim.gtk.util import get_app_window
from gajim.gtk.const import ControlType
log = logging.getLogger('gajim.groupchat_control')
......@@ -177,6 +177,12 @@ def __init__(self, parent_win, contact, muc_data, acct):
self._muc_info_box = GroupChatInfoScrolled(self.account, {'width': 600})
self.xml.info_grid.attach(self._muc_info_box, 0, 0, 1, 1)
# Groupchat settings
self._groupchat_settings_box = GroupChatSettingsScrolled(
self.account, self.room_jid, self.context)
self.xml.settings_grid.attach(self._groupchat_settings_box, 0, 0, 1, 1)
# Groupchat invite
self.xml.quick_invite_button.set_action_name(
'win.invite-%s' % self.control_id)
......@@ -279,6 +285,7 @@ def context(self):
def add_actions(self):
super().add_actions()
actions = [
('groupchat-settings-', None, self._on_groupchat_settings),
('rename-groupchat-', None, self._on_rename_groupchat),
('change-subject-', None, self._on_change_subject),
('change-nickname-', None, self._on_change_nick),
......@@ -305,66 +312,6 @@ def add_actions(self):
act.connect("activate", func)
self.parent_win.window.add_action(act)
minimize = self.contact.settings.get('minimize_on_close')
act = Gio.SimpleAction.new_stateful(
'minimize-on-close-' + self.control_id, None,
GLib.Variant.new_boolean(minimize))
act.connect('change-state', self._on_minimize_on_close)
self.parent_win.window.add_action(act)
minimize = self.contact.settings.get('minimize_on_autojoin')
act = Gio.SimpleAction.new_stateful(
'minimize-on-autojoin-' + self.control_id, None,
GLib.Variant.new_boolean(minimize))
act.connect('change-state', self._on_minimize_on_autojoin)
self.parent_win.window.add_action(act)
chatstate = self.contact.settings.get('send_chatstate')
act = Gio.SimpleAction.new_stateful(
'send-chatstate-' + self.control_id,
GLib.VariantType.new("s"),
GLib.Variant("s", chatstate))
act.connect('change-state', self._on_send_chatstate)
self.parent_win.window.add_action(act)
value = self.contact.settings.get('notify_on_all_messages',
context=self.context)
act = Gio.SimpleAction.new_stateful(
'notify-on-message-' + self.control_id,
None, GLib.Variant.new_boolean(value))
act.connect('change-state', self._on_notify_on_all_messages)
self.parent_win.window.add_action(act)
value = self.contact.settings.get('print_status')
act = Gio.SimpleAction.new_stateful(
'print-status-' + self.control_id,
None, GLib.Variant.new_boolean(value))
act.connect('change-state', self._on_print_status)
self.parent_win.window.add_action(act)
value = self.contact.settings.get('print_join_left')
act = Gio.SimpleAction.new_stateful(
'print-join-left-' + self.control_id,
None, GLib.Variant.new_boolean(value))
act.connect('change-state', self._on_print_join_left)
self.parent_win.window.add_action(act)
threshold = self.contact.settings.get('sync_threshold',
context=self.context)
initial = GLib.Variant.new_string(str(threshold))
act = Gio.SimpleAction.new_stateful(
'choose-sync-' + self.control_id,
initial.get_type(), initial)
act.connect('change-state', self._on_sync_threshold)
self.parent_win.window.add_action(act)
def update_actions(self, *args):
if self.parent_win is None:
return
......@@ -427,16 +374,6 @@ def update_actions(self, *args):
vcard_support and
contact.affiliation.is_owner)
# Print join/left
value = self.contact.settings.get('print_join_left')
self._get_action('print-join-left-').set_state(
GLib.Variant.new_boolean(value))
# Print join/left
value = self.contact.settings.get('print_status')
self._get_action('print-status-').set_state(
GLib.Variant.new_boolean(value))
self._get_action('contact-information-').set_enabled(self.is_connected)
self._get_action('execute-command-').set_enabled(self.is_connected)
......@@ -448,6 +385,7 @@ def update_actions(self, *args):
def remove_actions(self):
super().remove_actions()
actions = [
'groupchat-settings-',
'rename-groupchat-',
'change-subject-',
'change-nickname-',
......@@ -464,13 +402,6 @@ def remove_actions(self):
'kick-',
'change-role-',
'change-affiliation-',
'minimize-on-close-',
'minimize-on-autojoin-',
'send-chatstate-',
'notify-on-message-',
'print-status-',
'print-join-left-',
'choose-sync-',
]
for action in actions:
......@@ -531,19 +462,10 @@ def _get_current_page(self):
def _on_disco_update(self, _event):
if self.parent_win is None:
return
win = self.parent_win.window
self.update_actions()
self.draw_banner_text()
# After the room has been created, reevaluate threshold
if self.disco_info.has_mam:
threshold = self.contact.settings.get('sync_threshold',
context=self.context)
win.change_action_state('choose-sync-%s' % self.control_id,
GLib.Variant('s', str(threshold)))
# Actions
def _on_disconnect(self, _action, _param):
self.leave()
......@@ -555,6 +477,9 @@ def _on_information(self, _action, _param):
self._subject_data.user_timestamp)
self._show_page('muc-info')
def _on_groupchat_settings(self, _action, _param):
self._show_page('muc-settings')
def _on_invite(self, _action, _param):
self._invite_box.load_contacts()
self._show_page('invite')
......@@ -629,14 +554,6 @@ def _on_configure_form_received(self, result):
return
GroupchatConfig(self.account, result.jid, 'owner', result.form)
def _on_print_join_left(self, action, param):
action.set_state(param)
self.contact.settings.set('print_join_left', param.get_boolean())
def _on_print_status(self, action, param):
action.set_state(param)
self.contact.settings.set('print_status', param.get_boolean())
def _on_request_voice(self, _action, _param):
"""
Request voice in the current room
......@@ -644,29 +561,6 @@ def _on_request_voice(self, _action, _param):
con = app.connections[self.account]
con.get_module('MUC').request_voice(self.room_jid)
def _on_minimize_on_close(self, action, param):
action.set_state(param)
self.contact.settings.set('minimize_on_close', param.get_boolean())
def _on_minimize_on_autojoin(self, action, param):
action.set_state(param)
self.contact.settings.set('minimize_on_autojoin', param.get_boolean())
def _on_send_chatstate(self, action, param):
action.set_state(param)
self.contact.settings.set('send_chatstate', param.get_string())
def _on_notify_on_all_messages(self, action, param):
action.set_state(param)
self.contact.settings.set('notify_on_all_messages', param.get_boolean())
def _on_sync_threshold(self, action, param):
threshold = param.get_string()
action.set_state(param)
self.contact.settings.set('sync_threshold',
int(threshold),
context=self.context)
def _on_execute_command(self, _action, param):
jid = self.room_jid
nick = param.get_string()
......
# This file is part of Gajim.
#
# 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.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>.
from gi.repository import Gtk
from gajim.common.const import THRESHOLD_OPTIONS
from gajim.common.i18n import _
from gajim.gtk.const import Setting
from gajim.gtk.const import SettingKind
from gajim.gtk.const import SettingType
from gajim.gtk.settings import SettingsBox
class GroupChatSettingsScrolled(Gtk.ScrolledWindow):
def __init__(self, account, jid, context):
Gtk.ScrolledWindow.__init__(self)
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.set_max_content_height(400)
self.set_propagate_natural_height(True)
self.set_hexpand(True)
self.set_vexpand(True)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=18)
box.set_valign(Gtk.Align.CENTER)
label = Gtk.Label(label=_('Settings for this Chat'))
label.get_style_context().add_class('bold16')
label.set_halign(Gtk.Align.CENTER)
box.add(label)
chat_settings = ChatSettings(account, jid, context)
box.add(chat_settings)
self.add(box)
self.show_all()
class GroupchatSettingsBox(SettingsBox):
def __init__(self, account, jid, settings):
SettingsBox.__init__(self, account, jid)
self.get_style_context().add_class('settings-border')
self.set_selection_mode(Gtk.SelectionMode.NONE)
for setting in settings:
self.add_setting(setting)
self.update_states()
class ChatSettings(GroupchatSettingsBox):
def __init__(self, account, jid, context):
chat_state = {
'disabled': _('Disabled'),
'composing_only': _('Composing Only'),
'all': _('All Chat States')
}
settings = [
Setting(SettingKind.SWITCH,
_('Show Join/Leave'),
SettingType.GROUP_CHAT,
'print_join_left'),
Setting(SettingKind.SWITCH,
_('Show Status Changes'),
SettingType.GROUP_CHAT,
'print_status'),
Setting(SettingKind.SWITCH,
_('Notify on all Messages'),
SettingType.GROUP_CHAT,
'notify_on_all_messages',
context=context),
Setting(SettingKind.SWITCH,
_('Minimize on Close'),
SettingType.GROUP_CHAT,
'minimize_on_close'),
Setting(SettingKind.SWITCH,
_('Minimize When Joining Automatically'),
SettingType.GROUP_CHAT,
'minimize_on_autojoin'),
Setting(SettingKind.POPOVER,
_('Send Chat State'),
SettingType.GROUP_CHAT,
'send_chatstate',
props={'entries': chat_state}),
Setting(SettingKind.POPOVER,
_('Sync Threshold'),
SettingType.GROUP_CHAT,
'sync_threshold',
context=context,
props={'entries': THRESHOLD_OPTIONS}),
]
GroupchatSettingsBox.__init__(self, account, jid, settings)
......@@ -25,7 +25,6 @@
from gajim.common.i18n import _
from gajim.common.const import URIType
from gajim.common.const import URIAction
from gajim.common.const import THRESHOLD_OPTIONS
from gajim.gtk.util import get_builder
from gajim.gtk.const import ControlType
......@@ -572,6 +571,7 @@ def build_menu(preset):
def get_groupchat_menu(control_id, account, jid):
groupchat_menu = [
('win.information-', _('Information')),
('win.groupchat-settings-', _('Settings…')),
(_('Manage Group Chat'), [
('win.rename-groupchat-', _('Rename…')),
('win.change-subject-', _('Change Subject…')),
......@@ -579,16 +579,6 @@ def get_groupchat_menu(control_id, account, jid):
('win.configure-', _('Configure…')),
('win.destroy-', _('Destroy…')),
]),
(_('Chat Settings'), [
('win.print-join-left-', _('Show Join/Leave')),
('win.print-status-', _('Show Status Changes')),
('win.notify-on-message-', _('Notify on all Messages')),
('win.minimize-on-close-', _('Minimize on Close')),
('win.minimize-on-autojoin-',
_('Minimize When Joining Automatically')),
(_('Send Chatstate'), ['chatstate']),
]),
(_('Sync Threshold'), ['sync']),
('win.change-nickname-', _('Change Nickname…')),
('win.request-voice-', _('Request Voice')),
('win.execute-command-', _('Execute Command…')),
......@@ -620,38 +610,10 @@ def build_menu(preset):
menu.append(label, action_name + control_id)
else:
label, sub_menu = item
if 'sync' in sub_menu:
# Sync threshold menu
submenu = build_sync_menu()
elif 'chatstate' in sub_menu:
submenu = build_chatstate_menu()
else:
# This is a submenu
submenu = build_menu(sub_menu)
submenu = build_menu(sub_menu)
menu.append_submenu(label, submenu)
return menu
def build_sync_menu():
menu = Gio.Menu()
action_name = 'win.choose-sync-%s::' % control_id
for days, label in THRESHOLD_OPTIONS.items():
menu.append(label, '%s%s' % (action_name, days))
return menu
def build_chatstate_menu():
menu = Gio.Menu()
entries = [
(_('Disabled'), 'disabled'),
(_('Composing only'), 'composing_only'),
(_('All chat states'), 'all')
]
for entry in entries:
label, setting = entry
action = 'win.send-chatstate-%s::%s' % (control_id, setting)
menu.append(label, action)
return menu
return build_menu(groupchat_menu)
......
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