aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/manage_accounts/add_account_dialog.vala
blob: 8501f4762f73dd14432660fec41e4467b1d05201 (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
using Gee;
using Gtk;

using Dino.Entities;

namespace Dino.Ui.ManageAccounts {

[GtkTemplate (ui = "/org/dino-im/manage_accounts/add_account_dialog.ui")]
public class AddAccountDialog : Gtk.Dialog {

    public signal void added(Account account);

    [GtkChild] private Button cancel_button;
    [GtkChild] private Button ok_button;
    [GtkChild] private Entry alias_entry;
    [GtkChild] private Entry jid_entry;
    [GtkChild] private Entry password_entry;

    public AddAccountDialog(StreamInteractor stream_interactor) {
        Object(use_header_bar : 1);
        this.title = "Add Account";

        cancel_button.clicked.connect(() => { close(); });
        ok_button.clicked.connect(on_ok_button_clicked);
        jid_entry.changed.connect(on_jid_entry_changed);
        jid_entry.focus_out_event.connect(on_jid_entry_focus_out_event);
    }

    private void on_jid_entry_changed() {
        Jid? jid = Jid.parse(jid_entry.text);
        if (jid != null && jid.localpart != null && jid.resourcepart == null) {
            ok_button.set_sensitive(true);
            jid_entry.secondary_icon_name = null;
        } else {
            ok_button.set_sensitive(false);
        }
    }

    private bool on_jid_entry_focus_out_event() {
        Jid? jid = Jid.parse(jid_entry.text);
        if (jid == null || jid.localpart == null || jid.resourcepart != null) {
            jid_entry.secondary_icon_name = "dialog-warning-symbolic";
            // TODO why doesn't the tooltip work
            jid_entry.set_icon_tooltip_text(EntryIconPosition.SECONDARY, "JID should be of the form \"user@example.com\"");
        } else {
            jid_entry.secondary_icon_name = null;
        }
        return false;
    }

    private void on_ok_button_clicked() {
        Jid jid = new Jid(jid_entry.get_text());
        string password = password_entry.get_text();
        string alias = alias_entry.get_text();
        Account account = new Account(jid, null, password, alias);
        added(account);
        close();
    }
}

}