aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_list_titlebar.vala
blob: e2d7fa26d07b4ad8032a2bfbcb9e40d28a913e3b (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
using Gtk;

using Dino.Entities;

namespace Dino.Ui {

[GtkTemplate (ui = "/org/dino-im/conversation_list_titlebar.ui")]
public class ConversationListTitlebar : Gtk.HeaderBar {

    public signal void conversation_opened(Conversation conversation);

    [GtkChild] private MenuButton add_button;
    [GtkChild] public ToggleButton search_button;

    private StreamInteractor stream_interactor;

    public ConversationListTitlebar(StreamInteractor stream_interactor, Window window) {
        this.stream_interactor = stream_interactor;
        create_add_menu(window);
    }

    private void create_add_menu(Window window) {
        SimpleAction contacts_action = new SimpleAction("add_chat", null);
        contacts_action.activate.connect(() => {
            AddConversation.Chat.Dialog add_chat_dialog = new AddConversation.Chat.Dialog(stream_interactor, stream_interactor.get_accounts());
            add_chat_dialog.set_transient_for(window);
            add_chat_dialog.title = _("Start Chat");
            add_chat_dialog.ok_button.label = _("Start");
            add_chat_dialog.selected.connect((account, jid) => {
                Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT);
                stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation, true);
                conversation_opened(conversation);
            });
            add_chat_dialog.present();
        });
        GLib.Application.get_default().add_action(contacts_action);

        SimpleAction conference_action = new SimpleAction("add_conference", null);
        conference_action.activate.connect(() => {
            AddConversation.Conference.Dialog add_conference_dialog = new AddConversation.Conference.Dialog(stream_interactor);
            add_conference_dialog.set_transient_for(window);
            add_conference_dialog.conversation_opened.connect((conversation) => conversation_opened(conversation));
            add_conference_dialog.present();
        });
        GLib.Application.get_default().add_action(conference_action);

        Builder builder = new Builder.from_resource("/org/dino-im/menu_add.ui");
        MenuModel menu = builder.get_object("menu_add") as MenuModel;
        add_button.set_menu_model(menu);
    }
}

}