Commit 657050ad authored by Philipp Hörist's avatar Philipp Hörist

Add default chatstate setting

parent 5f84dffc
......@@ -289,8 +289,9 @@ class ChatControl(ChatControlBase):
self.video_action.connect('change-state', self._on_video)
self.parent_win.window.add_action(self.video_action)
default_chatstate = app.config.get('send_chatstate_default')
chatstate = app.config.get_per(
'contacts', self.contact.jid, 'send_chatstate', 'composing_only')
'contacts', self.contact.jid, 'send_chatstate', default_chatstate)
act = Gio.SimpleAction.new_stateful(
'send-chatstate-' + self.control_id,
......
......@@ -292,6 +292,8 @@ class Config:
'show_chatstate_in_roster': [opt_bool, True, _('If the contact row is colored according to the current chatstate of the contact')],
'show_chatstate_in_tabs': [opt_bool, True, _('If the tab is colored according to the current chatstate of the contact')],
'show_chatstate_in_banner': [opt_bool, True, _('Shows a text in the banner that describes the current chatstate of the contact')],
'send_chatstate_default': [opt_str, 'composing_only', _('Chat state notifications that are sent to contacts. Possible values: all, composing_only, disabled')],
'send_chatstate_muc_default': [opt_str, 'composing_only', _('Chat state notifications that are sent to the group chat. Possible values: all, composing_only, disabled')],
}, {}) # type: Tuple[Dict[str, List[Any]], Dict[Any, Any]]
__options_per_key = {
......@@ -617,6 +619,20 @@ class Config:
del opt[1][name][subname]
self._timeout_save()
def del_all_per(self, typename, subname):
# Deletes all settings per typename
# Example: Delete `account_label` for all accounts
if typename not in self.__options_per_key:
raise ValueError('typename %s does not exist' % typename)
opt = self.__options_per_key[typename]
for name in opt[1]:
try:
del opt[1][name][subname]
except KeyError:
pass
self._timeout_save()
def set_per(self, optname, key, subname, value): # per_group_of_option
if optname not in self.__options_per_key:
return
......
......@@ -356,10 +356,12 @@ class Chatstate(BaseModule):
@staticmethod
def _get_chatstate_setting(contact):
if contact.is_groupchat():
default = app.config.get('send_chatstate_muc_default')
return app.config.get_per(
'rooms', contact.jid, 'send_chatstate', 'composing_only')
'rooms', contact.jid, 'send_chatstate', default)
default = app.config.get('send_chatstate_default')
return app.config.get_per(
'contacts', contact.jid, 'send_chatstate', 'composing_only')
'contacts', contact.jid, 'send_chatstate', default)
def remove_delay_timeout(self, contact):
timeout = self._delay_timeout_ids.get(contact.jid)
......
......@@ -390,8 +390,9 @@ class GroupchatControl(ChatControlBase):
act.connect('change-state', self._on_minimize_on_autojoin)
self.parent_win.window.add_action(act)
default_muc_chatstate = app.config.get('send_chatstate_muc_default')
chatstate = app.config.get_per(
'rooms', self.contact.jid, 'send_chatstate', 'composing_only')
'rooms', self.contact.jid, 'send_chatstate', default_chatstate)
act = Gio.SimpleAction.new_stateful(
'send-chatstate-' + self.control_id,
......
......@@ -56,6 +56,7 @@ class SettingKind(IntEnum):
FILECHOOSER = 10
CHANGEPASSWORD = 11
COMBO = 12
CHATSTATE_COMBO = 13
@unique
......
......@@ -99,6 +99,7 @@ class SettingsBox(Gtk.ListBox):
SettingKind.HOSTNAME: CutstomHostnameSetting,
SettingKind.CHANGEPASSWORD: ChangePasswordSetting,
SettingKind.COMBO: ComboSetting,
SettingKind.CHATSTATE_COMBO: ChatstateComboSetting,
}
if extend is not None:
......@@ -535,6 +536,15 @@ class ComboSetting(GenericSetting):
self.set_value(combo.get_active_id())
class ChatstateComboSetting(ComboSetting):
def on_value_change(self, combo):
self.set_value(combo.get_active_id())
if 'muc' in self.value:
app.config.del_all_per('rooms', 'send_chatstate')
else:
app.config.del_all_per('contacts', 'send_chatstate')
class ProxyComboSetting(GenericSetting):
__gproperties__ = {
......
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