aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/contact_details/settings_provider.vala
blob: 70eab72c6ef569a6ccedcb6991973475d731652a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using Gtk;

using Dino.Entities;

namespace Dino.Ui.ContactDetails {

public class SettingsProvider : Plugins.ContactDetailsProvider {
    public override string id { get { return "chat_settings"; } }

    private StreamInteractor stream_interactor;

    public SettingsProvider(StreamInteractor stream_interactor) {
        this.stream_interactor = stream_interactor;
    }

    public override void populate(Conversation conversation, Plugins.ContactDetails contact_details) {
        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"));
            }

            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); } );

            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); } );
        } 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"));
            contact_details.add(_("Local Settings"), _("Notifications"), "", combobox);
            combobox.active_id = get_notify_setting_id(conversation.get_notification_setting(stream_interactor));
            combobox.changed.connect(() => { conversation.notify_setting = get_notify_setting(combobox.active_id); } );
        }
    }

    public Conversation.Setting get_setting(string id) {
        switch (id) {
            case "default":
                return Conversation.Setting.DEFAULT;
            case "on":
                return Conversation.Setting.ON;
            case "off":
                return Conversation.Setting.OFF;
        }
        assert_not_reached();
    }

    public Conversation.NotifySetting get_notify_setting(string id) {
        switch (id) {
            case "default":
                return Conversation.NotifySetting.DEFAULT;
            case "on":
                return Conversation.NotifySetting.ON;
            case "off":
                return Conversation.NotifySetting.OFF;
            case "highlight":
                return Conversation.NotifySetting.HIGHLIGHT;
        }
        assert_not_reached();
    }

    public string get_setting_id(Conversation.Setting setting) {
        switch (setting) {
            case Conversation.Setting.DEFAULT:
                return "default";
            case Conversation.Setting.ON:
                return "on";
            case Conversation.Setting.OFF:
                return "off";
        }
        assert_not_reached();
    }

    public string get_notify_setting_id(Conversation.NotifySetting setting) {
        switch (setting) {
            case Conversation.NotifySetting.DEFAULT:
                return "default";
            case Conversation.NotifySetting.ON:
                return "on";
            case Conversation.NotifySetting.OFF:
                return "off";
            case Conversation.NotifySetting.HIGHLIGHT:
                return "highlight";
        }
        assert_not_reached();
    }
}

}