aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/call_window/participant_widget.vala
blob: cbf8df2d237160cf1e5550f65f538ac16a1b732f (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using Pango;
using Gee;
using Xmpp;
using Dino.Entities;
using Gtk;

namespace Dino.Ui {

    public class ParticipantWidget : Gtk.Overlay {

        public Widget main_widget;
        public Box outer_box = new Box(Orientation.HORIZONTAL, 0) { valign=Align.START, visible=true };
        public Box inner_box = new Box(Orientation.HORIZONTAL, 0) { margin_start=5, margin_top=5, hexpand=true, visible=true };
        public Box title_box = new Box(Orientation.VERTICAL, 0) { valign=Align.CENTER, hexpand=true, visible=true };
        public CallEncryptionButton encryption_button = new CallEncryptionButton() { opacity=0, relief=ReliefStyle.NONE, height_request=30, width_request=30, margin_end=5, visible=true };
        public Label status_label = new Label("") { ellipsize=EllipsizeMode.MIDDLE };
        public Label name_label = new Label("") { ellipsize=EllipsizeMode.MIDDLE, visible=true };
        public Button menu_button = new Button.from_icon_name("view-more-horizontal-symbolic") { relief=ReliefStyle.NONE, visible=true };
        public bool shows_video = false;
        public string? participant_name;

        bool is_highest_row = false;
        bool is_lowest_row = false;
        public bool controls_active { get; set; }

        public ParticipantWidget(string participant_name) {
            this.participant_name = participant_name;
            name_label.label = participant_name;

            name_label.attributes = new AttrList();
            name_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD)));

            name_label.attributes = new AttrList();
            name_label.attributes.filter((attr) => attr.equal(attr_scale_new(0.9)));
            status_label.get_style_context().add_class("dim-label");

            Util.force_css(outer_box, "* { color: white; text-shadow: 1px 1px black; }");
            menu_button.get_style_context().add_class("participant-title-button");
            encryption_button.get_style_context().add_class("participant-title-button");

            title_box.add(name_label);
            title_box.add(status_label);

            outer_box.add(inner_box);

            inner_box.add(menu_button);
            inner_box.add(encryption_button);
            inner_box.add(title_box);
            inner_box.add(new Button.from_icon_name("go-up-symbolic") { opacity=0, visible=true });
            inner_box.add(new Button.from_icon_name("go-up-symbolic") { opacity=0, visible=true });

            this.add_overlay(outer_box);

            this.notify["controls-active"].connect(reveal_or_hide_controls);
        }

        public void on_show_names_changed(bool show) {
            name_label.visible = show;
            reveal_or_hide_controls();
        }

        public void on_highest_row_changed(bool is_highest) {
            is_highest_row = is_highest;
            reveal_or_hide_controls();
        }

        public void on_lowest_row_changed(bool is_lowest) {
            is_lowest_row = is_lowest;
            reveal_or_hide_controls();
        }

        public void set_video(Widget widget) {
            shows_video = true;
            widget.visible = true;
            set_participant_widget(widget);
        }

        public void set_placeholder(Conversation? conversation, StreamInteractor stream_interactor) {
            shows_video = false;
            Box box = new Box(Orientation.HORIZONTAL, 0) { visible=true };
            box.get_style_context().add_class("video-placeholder-box");
            AvatarImage avatar = new AvatarImage() { allow_gray=false, hexpand=true, vexpand=true, halign=Align.CENTER, valign=Align.CENTER, height=100, width=100, visible=true };
            if (conversation != null) {
                avatar.set_conversation(stream_interactor, conversation);
            } else {
                avatar.set_text("?", false);
            }
            box.add(avatar);

            set_participant_widget(box);
        }

        private void set_participant_widget(Widget widget) {
            widget.expand = true;
            if (main_widget != null) this.remove(main_widget);
            main_widget = widget;
            this.add(main_widget);
        }

        public void set_status(string state) {
            status_label.visible = true;

            if (state == "requested") {
                status_label.label =  _("Calling…");
            } else if (state == "ringing") {
                status_label.label = _("Ringing…");
            } else if (state == "establishing") {
                status_label.label = _("Connecting…");
            } else {
                status_label.visible = false;
            }
        }

        private void reveal_or_hide_controls() {
            if (controls_active && name_label.visible) {
                title_box.opacity = 1;
                menu_button.opacity = 1;
            } else {
                title_box.opacity = 0;
                menu_button.opacity = 0;
            }
            if (is_highest_row && controls_active) {
                outer_box.get_style_context().add_class("call-header-bar");
            } else {
                outer_box.get_style_context().remove_class("call-header-bar");
            }
        }
    }
}