diff options
Diffstat (limited to 'contacts.cpp')
| -rw-r--r-- | contacts.cpp | 50 |
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); +} |
