aboutsummaryrefslogtreecommitdiff
path: root/contacts.cpp
blob: 1729d2c48e036453172aba66120f752b595c8457 (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
#include "contacts.h"
#include "contact.h"
#include <QListWidgetItem>
#include <QScroller>

Contacts::Contacts(QList<JidDb *> &databases, QWidget *const parent) :
    QDialog(parent),
    databases(databases)
{
    ui.setupUi(this);
    QScroller::grabGesture(ui.contacts_list, QScroller::TouchGesture);

    for (const auto db : databases)
        for (const auto &contact : db->roster())
            add(db->jid, contact);

    connect(ui.contacts_list, &QListWidget::itemActivated, this,
    [this]
    {
        ui.chat->setEnabled(true);
    });

    connect(ui.chat, &QPushButton::released, this,
    [this]
    {
        const auto items = ui.contacts_list->selectedItems();

        if (items.isEmpty())
        {
            ui.chat->setEnabled(false);
            return;
        }

        for (const auto it : items)
        {
            const auto c = static_cast<Contact *>(it);

            Q_EMIT startChat(c->own, c->other);
        }

        close();
    });

    showMaximized();
}

void Contacts::add(const QString &own, const QString &other)
{
    new Contact(own, other, ui.contacts_list);
}