aboutsummaryrefslogtreecommitdiff
path: root/contacts.cpp
blob: 4336ac3377059e0abb4f34095158fae08e94e210 (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(const QList<Client *> &clients,
    QWidget *const parent) :
    QDialog(parent)
{
    ui.setupUi(this);
    QScroller::grabGesture(ui.contacts_list, QScroller::TouchGesture);

    for (const auto c : clients)
        for (const auto &contact : c->database().roster())
            add(c->jidBare(), 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);
}