From 05b2584fa4d773f5a88ed3ce98f5dd8304e11c34 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Mon, 12 Jun 2023 23:47:17 +0200 Subject: First commit --- contacts.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 contacts.cpp (limited to 'contacts.cpp') diff --git a/contacts.cpp b/contacts.cpp new file mode 100644 index 0000000..1729d2c --- /dev/null +++ b/contacts.cpp @@ -0,0 +1,50 @@ +#include "contacts.h" +#include "contact.h" +#include +#include + +Contacts::Contacts(QList &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(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); +} -- cgit v1.2.3