aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/call_window/participant_widget.vala
blob: ecd6cbb35fc7ea3e320796587f0e29e1043710e8 (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
130
131
132
133
134
135
136
137
138
139
140
141
using Pango;
using Gee;
using Xmpp;
using Dino.Entities;
using Gtk;

namespace Dino.Ui {

    public class ParticipantWidget : Box {

        public Overlay overlay = new Overlay();
        public Widget main_widget;
        public HeaderBar header_bar = new HeaderBar() { valign=Align.START, visible=true };
        public Label title_label = new Label("");
        public Label subtitle_label = new Label("");
        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 MenuButton encryption_button = new MenuButton() { opacity=0, has_frame=false, height_request=30, width_request=30, margin_end=5, visible=true };
        public CallEncryptionButtonController encryption_button_controller;
        public MenuButton menu_button = new MenuButton() { icon_name="open-menu-symbolic", has_frame=false, visible=true };
        public Button invite_button = new Button.from_icon_name("dino-account-plus") { has_frame=false, visible=true };
        public bool shows_video = false;
        public string? participant_name;

        bool is_highest_row = false;
        bool is_start_row = false;
        public bool controls_active { get; set; }
        public bool may_show_invite_button { get; set; }

        public signal void debug_information_clicked();
        public signal void invite_button_clicked();

        class construct {
            install_action("menu.debuginfo", null, (widget, action_name) => { ((ParticipantWidget) widget).debug_information_clicked(); });
        }

        public ParticipantWidget(string participant_name) {
            encryption_button_controller = new CallEncryptionButtonController(encryption_button);

            this.participant_name = participant_name;

            Box titles_box = new Box(Orientation.VERTICAL, 0) { valign=Align.CENTER };
            title_label.attributes = new AttrList();
            title_label.attributes.insert(Pango.attr_weight_new(Weight.BOLD));
            titles_box.append(title_label);
            subtitle_label.attributes = new AttrList();
            subtitle_label.attributes.insert(Pango.attr_scale_new(Pango.Scale.SMALL));
            subtitle_label.get_style_context().add_class("dim-label");
            titles_box.append(subtitle_label);

            header_bar.set_title_widget(titles_box);
            title_label.label = participant_name;

            header_bar.get_style_context().add_class("participant-header-bar");
            header_bar.pack_start(invite_button);
            header_bar.pack_start(encryption_button);
            header_bar.pack_end(menu_button);

            create_menu();

            invite_button.clicked.connect(() => invite_button_clicked());

            this.append(overlay);
            overlay.add_overlay(header_bar);

            this.notify["controls-active"].connect(reveal_or_hide_controls);
            this.notify["may-show-invite-button"].connect(reveal_or_hide_controls);
        }

        public void on_row_changed(bool is_highest, bool is_lowest, bool is_start, bool is_end) {
            this.is_highest_row = is_highest;
            this.is_start_row = is_start;

            header_bar.show_title_buttons = is_highest_row;
            if (is_highest_row) {
                header_bar.get_style_context().add_class("call-header-background");
                Gtk.Settings? gtk_settings = Gtk.Settings.get_default();
                if (gtk_settings != null) {
                    string[] buttons = gtk_settings.gtk_decoration_layout.split(":");
                    header_bar.decoration_layout = (is_start ? buttons[0] : "") + ":" + (is_end && buttons.length == 2 ? buttons[1] : "");
                }
            } else {
                header_bar.get_style_context().remove_class("call-header-background");
            }
            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.append(avatar);

            set_participant_widget(box);
        }

        private void set_participant_widget(Widget widget) {
            widget.hexpand = widget.vexpand = true;
            main_widget = widget;
            overlay.set_child(main_widget);
        }

        private void create_menu() {
            Menu menu_model = new Menu();
            menu_model.append(_("Debug information"), "menu.debuginfo");
            Gtk.PopoverMenu popover_menu = new Gtk.PopoverMenu.from_model(menu_model);
            menu_button.popover = popover_menu;
        }

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

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

        private void reveal_or_hide_controls() {
            header_bar.opacity = controls_active ? 1.0 : 0.0;
            invite_button.visible = may_show_invite_button && is_highest_row && is_start_row;
        }
    }
}