xxcc/contacts.cpp

51 lines
1.1 KiB
C++

#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);
}