aboutsummaryrefslogtreecommitdiff
path: root/contacts.cpp
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-06-12 23:47:17 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-06-29 14:09:46 +0200
commit05b2584fa4d773f5a88ed3ce98f5dd8304e11c34 (patch)
treef72e73c3259b8100e886f49f67ecc669b7667502 /contacts.cpp
parent3b8fafc4122848219898245d52dabd669cacb4ba (diff)
First commit
Diffstat (limited to 'contacts.cpp')
-rw-r--r--contacts.cpp50
1 files changed, 50 insertions, 0 deletions
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 <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);
+}