"Default" per-contact settings (change UI)

This commit is contained in:
fiaxh 2017-08-24 17:24:22 +02:00
parent 5fcf8e73ef
commit a8ba4a3974
4 changed files with 55 additions and 34 deletions

View file

@ -91,15 +91,17 @@ public class Conversation : Object {
} }
public NotifySetting get_notification_setting(StreamInteractor stream_interactor) { public NotifySetting get_notification_setting(StreamInteractor stream_interactor) {
return notify_setting != NotifySetting.DEFAULT ? notify_setting : get_notification_default_setting(stream_interactor);
}
public NotifySetting get_notification_default_setting(StreamInteractor stream_interactor) {
Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(account); Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(account);
if (notify_setting != NotifySetting.DEFAULT) return notify_setting;
if (!Application.get_default().settings.notifications) return NotifySetting.OFF; if (!Application.get_default().settings.notifications) return NotifySetting.OFF;
if (type_ == Type.GROUPCHAT) { if (type_ == Type.GROUPCHAT) {
bool members_only = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY).has_room_feature(counterpart.bare_jid.to_string(), Xmpp.Xep.Muc.Feature.MEMBERS_ONLY); bool members_only = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY).has_room_feature(counterpart.bare_jid.to_string(), Xmpp.Xep.Muc.Feature.MEMBERS_ONLY);
return members_only ? NotifySetting.ON : NotifySetting.HIGHLIGHT; return members_only ? NotifySetting.ON : NotifySetting.HIGHLIGHT;
} else {
return NotifySetting.ON;
} }
return NotifySetting.ON;
} }
public Setting get_send_typing_setting() { public Setting get_send_typing_setting() {

View file

@ -77,6 +77,7 @@
<child> <child>
<object class="GtkLabel" id="jid_label"> <object class="GtkLabel" id="jid_label">
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="selectable">True</property>
<property name="expand">True</property> <property name="expand">True</property>
<property name="visible">True</property> <property name="visible">True</property>
</object> </object>

View file

@ -16,38 +16,33 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object {
public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) { public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) {
if (type != Plugins.WidgetType.GTK) return; if (type != Plugins.WidgetType.GTK) return;
if (conversation.type_ == Conversation.Type.CHAT) { if (conversation.type_ == Conversation.Type.CHAT) {
ComboBoxText[] comboboxes = new ComboBoxText[2]; ComboBoxText combobox_typing = get_combobox(Dino.Application.get_default().settings.send_typing);
for (int i = 0; i < 3; i++) { combobox_typing.active_id = get_setting_id(conversation.send_typing);
comboboxes[i] = new ComboBoxText() { visible=true }; combobox_typing.changed.connect(() => { conversation.send_typing = get_setting(combobox_typing.active_id); } );
comboboxes[i].append("default", _("Default")); contact_details.add(_("Settings"), _("Send typing notifications"), "", combobox_typing);
comboboxes[i].append("on", _("On"));
comboboxes[i].append("off", _("Off"));
}
contact_details.add(_("Settings"), _("Send typing notifications"), "", comboboxes[0]); ComboBoxText combobox_marker = get_combobox(Dino.Application.get_default().settings.send_marker);
comboboxes[0].active_id = get_setting_id(conversation.get_send_typing_setting()); contact_details.add(_("Settings"), _("Send message marker"), "", combobox_marker);
comboboxes[0].changed.connect(() => { print("changed!\n"); conversation.send_typing = get_setting(comboboxes[0].active_id); } ); 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]); ComboBoxText combobox_notifications = get_combobox(Dino.Application.get_default().settings.notifications);
comboboxes[1].active_id = get_setting_id(conversation.get_send_marker_setting()); contact_details.add(_("Settings"), _("Notifications"), "", combobox_notifications);
comboboxes[1].changed.connect(() => { conversation.send_marker = get_setting(comboboxes[1].active_id); } ); 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); } );
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); } );
} else if (conversation.type_ == Conversation.Type.GROUPCHAT) { } else if (conversation.type_ == Conversation.Type.GROUPCHAT) {
ComboBoxText combobox = new ComboBoxText() { visible=true }; ComboBoxText combobox = new ComboBoxText() { visible=true };
combobox.append("default", _("Default")); combobox.append("default", get_notify_setting_string(Conversation.NotifySetting.DEFAULT, conversation.get_notification_default_setting(stream_interactor)));
combobox.append("highlight", _("Only when mentioned")); combobox.append("highlight", get_notify_setting_string(Conversation.NotifySetting.HIGHLIGHT));
combobox.append("on", _("On")); combobox.append("on", get_notify_setting_string(Conversation.NotifySetting.ON));
combobox.append("off", _("Off")); combobox.append("off", get_notify_setting_string(Conversation.NotifySetting.OFF));
contact_details.add(_("Local Settings"), _("Notifications"), "", combobox); 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); } ); 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) { switch (id) {
case "default": case "default":
return Conversation.Setting.DEFAULT; return Conversation.Setting.DEFAULT;
@ -59,7 +54,7 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object {
assert_not_reached(); assert_not_reached();
} }
public Conversation.NotifySetting get_notify_setting(string id) { private Conversation.NotifySetting get_notify_setting(string id) {
switch (id) { switch (id) {
case "default": case "default":
return Conversation.NotifySetting.DEFAULT; return Conversation.NotifySetting.DEFAULT;
@ -73,7 +68,21 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object {
assert_not_reached(); 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) { switch (setting) {
case Conversation.Setting.DEFAULT: case Conversation.Setting.DEFAULT:
return "default"; return "default";
@ -85,7 +94,7 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object {
assert_not_reached(); assert_not_reached();
} }
public string get_notify_setting_id(Conversation.NotifySetting setting) { private string get_notify_setting_id(Conversation.NotifySetting setting) {
switch (setting) { switch (setting) {
case Conversation.NotifySetting.DEFAULT: case Conversation.NotifySetting.DEFAULT:
return "default"; return "default";
@ -98,6 +107,16 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object {
} }
assert_not_reached(); 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;
}
} }
} }

View file

@ -17,15 +17,14 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object {
if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK) { if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK) {
string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
if (key_id != null) { if (key_id != null) {
Label label = new Label("") { use_markup=true, justify=Justification.RIGHT, selectable=true, visible=true };
Gee.List<GPG.Key> keys = GPGHelper.get_keylist(key_id); Gee.List<GPG.Key> keys = GPGHelper.get_keylist(key_id);
if (keys.size > 0) { if (keys.size > 0) {
Label label = new Label(markup_colorize_id(keys[0].fpr, true)) { use_markup=true, justify=Justification.RIGHT, visible=true }; label.label = markup_colorize_id(keys[0].fpr, true);
contact_details.add(_("Encryption"), _("OpenPGP"), "", label);
} else { } else {
string s = _("Key not in keychain") + "\n" + markup_colorize_id(key_id, false); label.label = _("Key not in keychain") + "\n" + markup_colorize_id(key_id, false);
Label label = new Label(s) { use_markup=true, justify=Justification.RIGHT, visible=true };
contact_details.add(_("Encryption"), _("OpenPGP"), "", label);
} }
contact_details.add(_("Encryption"), _("OpenPGP"), "", label);
} }
} }
} }