From a8ba4a397419b3b6d3d167b21a8da72dcdbe1961 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 24 Aug 2017 17:24:22 +0200 Subject: "Default" per-contact settings (change UI) --- main/src/ui/contact_details/settings_provider.vala | 71 ++++++++++++++-------- 1 file changed, 45 insertions(+), 26 deletions(-) (limited to 'main/src/ui/contact_details') diff --git a/main/src/ui/contact_details/settings_provider.vala b/main/src/ui/contact_details/settings_provider.vala index 47cdb795..b6da329d 100644 --- a/main/src/ui/contact_details/settings_provider.vala +++ b/main/src/ui/contact_details/settings_provider.vala @@ -16,38 +16,33 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) { if (type != Plugins.WidgetType.GTK) return; if (conversation.type_ == Conversation.Type.CHAT) { - ComboBoxText[] comboboxes = new ComboBoxText[2]; - for (int i = 0; i < 3; i++) { - comboboxes[i] = new ComboBoxText() { visible=true }; - comboboxes[i].append("default", _("Default")); - comboboxes[i].append("on", _("On")); - comboboxes[i].append("off", _("Off")); - } + ComboBoxText combobox_typing = get_combobox(Dino.Application.get_default().settings.send_typing); + combobox_typing.active_id = get_setting_id(conversation.send_typing); + combobox_typing.changed.connect(() => { conversation.send_typing = get_setting(combobox_typing.active_id); } ); + contact_details.add(_("Settings"), _("Send typing notifications"), "", combobox_typing); - contact_details.add(_("Settings"), _("Send typing notifications"), "", comboboxes[0]); - comboboxes[0].active_id = get_setting_id(conversation.get_send_typing_setting()); - comboboxes[0].changed.connect(() => { print("changed!\n"); conversation.send_typing = get_setting(comboboxes[0].active_id); } ); + ComboBoxText combobox_marker = get_combobox(Dino.Application.get_default().settings.send_marker); + contact_details.add(_("Settings"), _("Send message marker"), "", combobox_marker); + combobox_marker.active_id = get_setting_id(conversation.send_marker); + combobox_marker.changed.connect(() => { conversation.send_marker = get_setting(combobox_marker.active_id); } ); - contact_details.add(_("Settings"), _("Send message marker"), "", comboboxes[1]); - comboboxes[1].active_id = get_setting_id(conversation.get_send_marker_setting()); - comboboxes[1].changed.connect(() => { conversation.send_marker = get_setting(comboboxes[1].active_id); } ); - - contact_details.add(_("Settings"), _("Notifications"), "", comboboxes[2]); - comboboxes[2].active_id = get_notify_setting_id(conversation.get_notification_setting(stream_interactor)); - comboboxes[2].changed.connect(() => { conversation.notify_setting = get_notify_setting(comboboxes[2].active_id); } ); + ComboBoxText combobox_notifications = get_combobox(Dino.Application.get_default().settings.notifications); + contact_details.add(_("Settings"), _("Notifications"), "", combobox_notifications); + combobox_notifications.active_id = get_notify_setting_id(conversation.notify_setting); + combobox_notifications.changed.connect(() => { conversation.notify_setting = get_notify_setting(combobox_notifications.active_id); } ); } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { ComboBoxText combobox = new ComboBoxText() { visible=true }; - combobox.append("default", _("Default")); - combobox.append("highlight", _("Only when mentioned")); - combobox.append("on", _("On")); - combobox.append("off", _("Off")); + combobox.append("default", get_notify_setting_string(Conversation.NotifySetting.DEFAULT, conversation.get_notification_default_setting(stream_interactor))); + combobox.append("highlight", get_notify_setting_string(Conversation.NotifySetting.HIGHLIGHT)); + combobox.append("on", get_notify_setting_string(Conversation.NotifySetting.ON)); + combobox.append("off", get_notify_setting_string(Conversation.NotifySetting.OFF)); contact_details.add(_("Local Settings"), _("Notifications"), "", combobox); - combobox.active_id = get_notify_setting_id(conversation.get_notification_setting(stream_interactor)); + combobox.active_id = get_notify_setting_id(conversation.notify_setting); combobox.changed.connect(() => { conversation.notify_setting = get_notify_setting(combobox.active_id); } ); } } - public Conversation.Setting get_setting(string id) { + private Conversation.Setting get_setting(string id) { switch (id) { case "default": return Conversation.Setting.DEFAULT; @@ -59,7 +54,7 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { assert_not_reached(); } - public Conversation.NotifySetting get_notify_setting(string id) { + private Conversation.NotifySetting get_notify_setting(string id) { switch (id) { case "default": return Conversation.NotifySetting.DEFAULT; @@ -73,7 +68,21 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { assert_not_reached(); } - public string get_setting_id(Conversation.Setting setting) { + private string get_notify_setting_string(Conversation.NotifySetting setting, Conversation.NotifySetting? default_setting = null) { + switch (setting) { + case Conversation.NotifySetting.ON: + return _("On"); + case Conversation.NotifySetting.OFF: + return _("Off"); + case Conversation.NotifySetting.HIGHLIGHT: + return _("Only when mentioned"); + case Conversation.NotifySetting.DEFAULT: + return _("Default: %s").printf(get_notify_setting_string(default_setting)); + } + assert_not_reached(); + } + + private string get_setting_id(Conversation.Setting setting) { switch (setting) { case Conversation.Setting.DEFAULT: return "default"; @@ -85,7 +94,7 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { assert_not_reached(); } - public string get_notify_setting_id(Conversation.NotifySetting setting) { + private string get_notify_setting_id(Conversation.NotifySetting setting) { switch (setting) { case Conversation.NotifySetting.DEFAULT: return "default"; @@ -98,6 +107,16 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { } assert_not_reached(); } + + private ComboBoxText get_combobox(bool default_val) { + ComboBoxText combobox = new ComboBoxText(); + combobox = new ComboBoxText() { visible=true }; + string default_setting = default_val ? _("On") : _("Off"); + combobox.append("default", _("Default: %s").printf(default_setting) ); + combobox.append("on", _("On")); + combobox.append("off", _("Off")); + return combobox; + } } } -- cgit v1.2.3-70-g09d2