From 5aa0f4bca90a701238260eb28e082b124fcac0cc Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 3 Jan 2023 18:27:03 +0300 Subject: [PATCH] some initial classes for keys form --- shared/keyinfo.cpp | 23 ++- shared/keyinfo.h | 5 +- ui/widgets/messageline/messagefeed.cpp | 5 +- ui/widgets/vcard/omemo/CMakeLists.txt | 2 + ui/widgets/vcard/omemo/keysmodel.cpp | 71 +++++++ ui/widgets/vcard/omemo/keysmodel.h | 58 ++++++ ui/widgets/vcard/omemo/omemo.cpp | 29 ++- ui/widgets/vcard/omemo/omemo.h | 24 ++- ui/widgets/vcard/omemo/omemo.ui | 4 +- ui/widgets/vcard/vcard.cpp | 276 +++++++++++++------------ ui/widgets/vcard/vcard.h | 23 ++- 11 files changed, 361 insertions(+), 159 deletions(-) create mode 100644 ui/widgets/vcard/omemo/keysmodel.cpp create mode 100644 ui/widgets/vcard/omemo/keysmodel.h diff --git a/shared/keyinfo.cpp b/shared/keyinfo.cpp index 0c09d1f..bff716e 100644 --- a/shared/keyinfo.cpp +++ b/shared/keyinfo.cpp @@ -39,8 +39,29 @@ Shared::KeyInfo::KeyInfo(): id(0), fingerPrint(), label(), - trustLevel(TrustLevel::Undecided), + trustLevel(TrustLevel::undecided), protocol(EncryptionProtocol::omemo), currentDevice(false) { } + +Shared::KeyInfo::KeyInfo(const Shared::KeyInfo& other): + id(other.id), + fingerPrint(other.fingerPrint), + label(other.label), + trustLevel(other.trustLevel), + protocol(other.protocol), + currentDevice(other.currentDevice) +{ +} + +Shared::KeyInfo & Shared::KeyInfo::operator=(const Shared::KeyInfo& other) { + id = other.id; + fingerPrint = other.fingerPrint; + label = other.label; + trustLevel = other.trustLevel; + protocol = other.protocol; + currentDevice = other.currentDevice; + + return *this; +} diff --git a/shared/keyinfo.h b/shared/keyinfo.h index b5dc793..360a8b9 100644 --- a/shared/keyinfo.h +++ b/shared/keyinfo.h @@ -39,8 +39,11 @@ public: bool currentDevice = false ); KeyInfo(); + KeyInfo(const KeyInfo& other); -private: + KeyInfo& operator=(const KeyInfo& other); + +public: uint32_t id; QByteArray fingerPrint; QString label; diff --git a/ui/widgets/messageline/messagefeed.cpp b/ui/widgets/messageline/messagefeed.cpp index ad67bb3..af772fd 100644 --- a/ui/widgets/messageline/messagefeed.cpp +++ b/ui/widgets/messageline/messagefeed.cpp @@ -440,10 +440,7 @@ QModelIndex Models::MessageFeed::index(int row, int column, const QModelIndex& p } } -QHash Models::MessageFeed::roleNames() const -{ - return roles; -} +QHash Models::MessageFeed::roleNames() const {return roles;} bool Models::MessageFeed::sentByMe(const Shared::Message& msg) const { diff --git a/ui/widgets/vcard/omemo/CMakeLists.txt b/ui/widgets/vcard/omemo/CMakeLists.txt index 1468841..19a9fe9 100644 --- a/ui/widgets/vcard/omemo/CMakeLists.txt +++ b/ui/widgets/vcard/omemo/CMakeLists.txt @@ -2,4 +2,6 @@ target_sources(squawk PRIVATE omemo.cpp omemo.h omemo.ui + keysmodel.cpp + keysmodel.h ) diff --git a/ui/widgets/vcard/omemo/keysmodel.cpp b/ui/widgets/vcard/omemo/keysmodel.cpp new file mode 100644 index 0000000..b70fefd --- /dev/null +++ b/ui/widgets/vcard/omemo/keysmodel.cpp @@ -0,0 +1,71 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "keysmodel.h" + +const QHash UI::KeysModel::roles = { + {Label, "label"}, + {FingerPrint, "fingerPrint"}, + {TrustLevel, "trustLevel"} +}; + +UI::KeysModel::KeysModel(QObject* parent): + QAbstractListModel(parent), + keys() +{ +} + +UI::KeysModel::~KeysModel() { + +} + +void UI::KeysModel::addKey(const Shared::KeyInfo& info) { + beginInsertRows(QModelIndex(), keys.size(), keys.size()); + keys.push_back(new Shared::KeyInfo(info)); + endInsertRows(); +} + +QVariant UI::KeysModel::data(const QModelIndex& index, int role) const { + int i = index.row(); + QVariant answer; + + switch (role) { + case Qt::DisplayRole: + answer = keys[i]->label; + break; + } + + return answer; +} + +int UI::KeysModel::rowCount(const QModelIndex& parent) const { + return keys.size(); +} + +QHash UI::KeysModel::roleNames() const {return roles;} + +QModelIndex UI::KeysModel::index(int row, int column, const QModelIndex& parent) const { + if (!hasIndex(row, column, parent)) { + return QModelIndex(); + } + + return createIndex(row, column, keys[row]); +} + + + + + diff --git a/ui/widgets/vcard/omemo/keysmodel.h b/ui/widgets/vcard/omemo/keysmodel.h new file mode 100644 index 0000000..853c5c6 --- /dev/null +++ b/ui/widgets/vcard/omemo/keysmodel.h @@ -0,0 +1,58 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef UI_KEYSMODEL_H +#define UI_KEYSMODEL_H + +#include + +#include + +namespace UI { + +/** + * @todo write docs + */ +class KeysModel : public QAbstractListModel +{ +public: + KeysModel(QObject *parent = nullptr); + ~KeysModel(); + + void addKey(const Shared::KeyInfo& info); + + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + + QHash roleNames() const override; + QModelIndex index(int row, int column, const QModelIndex & parent) const override; + + enum Roles { + Label = Qt::UserRole + 1, + FingerPrint, + TrustLevel + }; + +private: + std::deque keys; + +private: + static const QHash roles; +}; + +} + +#endif // UI_KEYSMODEL_H diff --git a/ui/widgets/vcard/omemo/omemo.cpp b/ui/widgets/vcard/omemo/omemo.cpp index 7e39ec0..8a1e1cc 100644 --- a/ui/widgets/vcard/omemo/omemo.cpp +++ b/ui/widgets/vcard/omemo/omemo.cpp @@ -17,4 +17,31 @@ #include "omemo.h" #include "ui_omemo.h" -using namespace Ui; +Omemo::Omemo(QWidget* parent): + QWidget(parent), + m_ui(new Ui::Omemo()), + keysModel(), + unusedKeysModel() +{ + m_ui->setupUi(this); + + generateMockData(); + + m_ui->keysView->setModel(&keysModel); + m_ui->unusedKeysView->setModel(&unusedKeysModel); +} + +Omemo::~Omemo() +{ + +} + +void Omemo::generateMockData() +{ + for (int i = 0; i < 5; ++i) { + Shared::KeyInfo info; + info.id = i; + info.label = QString("test_") + std::to_string(i).c_str(); + keysModel.addKey(info); + } +} diff --git a/ui/widgets/vcard/omemo/omemo.h b/ui/widgets/vcard/omemo/omemo.h index 3dccbd3..d01f4a8 100644 --- a/ui/widgets/vcard/omemo/omemo.h +++ b/ui/widgets/vcard/omemo/omemo.h @@ -14,30 +14,32 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef UI_OMEMO_H -#define UI_OMEMO_H +#ifndef VCARD_OMEMO_H +#define VCARD_OMEMO_H #include #include -namespace Ui { +#include "keysmodel.h" namespace Ui { class Omemo; } -/** - * @todo write docs - */ -class Omemo : public QWidget -{ +class Omemo : public QWidget { Q_OBJECT +public: + Omemo(QWidget* parent = nullptr); + ~Omemo(); + +private: + void generateMockData(); private: QScopedPointer m_ui; + UI::KeysModel keysModel; + UI::KeysModel unusedKeysModel; }; -} - -#endif // UI_OMEMO_H +#endif // VCARD_OMEMO_H diff --git a/ui/widgets/vcard/omemo/omemo.ui b/ui/widgets/vcard/omemo/omemo.ui index 095a3e0..7052486 100644 --- a/ui/widgets/vcard/omemo/omemo.ui +++ b/ui/widgets/vcard/omemo/omemo.ui @@ -1,7 +1,7 @@ - Ui::Omemo - + Omemo + 0 diff --git a/ui/widgets/vcard/vcard.cpp b/ui/widgets/vcard/vcard.cpp index f1cfe3b..a3e877b 100644 --- a/ui/widgets/vcard/vcard.cpp +++ b/ui/widgets/vcard/vcard.cpp @@ -41,105 +41,29 @@ VCard::VCard(const QString& jid, bool edit, QWidget* parent): phones(edit), roleDelegate(new ComboboxDelegate()), phoneTypeDelegate(new ComboboxDelegate()) + +#ifdef WITH_OMEMO + ,omemo(new Omemo()) +#endif { m_ui->setupUi(this); m_ui->jabberID->setText(jid); m_ui->jabberID->setReadOnly(true); - QAction* setAvatar = m_ui->actionSetAvatar; - QAction* clearAvatar = m_ui->actionClearAvatar; - - connect(setAvatar, &QAction::triggered, this, &VCard::onSetAvatar); - connect(clearAvatar, &QAction::triggered, this, &VCard::onClearAvatar); - - setAvatar->setEnabled(true); - clearAvatar->setEnabled(false); - - roleDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Email::roleNames[0].toStdString().c_str())); - roleDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Email::roleNames[1].toStdString().c_str())); - roleDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Email::roleNames[2].toStdString().c_str())); - - phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[0].toStdString().c_str())); - phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[1].toStdString().c_str())); - phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[2].toStdString().c_str())); - phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[3].toStdString().c_str())); - phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[4].toStdString().c_str())); - phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[5].toStdString().c_str())); - phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[6].toStdString().c_str())); - - m_ui->emailsView->setContextMenuPolicy(Qt::CustomContextMenu); - m_ui->emailsView->setModel(&emails); - m_ui->emailsView->setItemDelegateForColumn(1, roleDelegate); - m_ui->emailsView->setColumnWidth(2, 25); - m_ui->emailsView->horizontalHeader()->setStretchLastSection(false); - m_ui->emailsView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); - - m_ui->phonesView->setContextMenuPolicy(Qt::CustomContextMenu); - m_ui->phonesView->setModel(&phones); - m_ui->phonesView->setItemDelegateForColumn(1, roleDelegate); - m_ui->phonesView->setItemDelegateForColumn(2, phoneTypeDelegate); - m_ui->phonesView->setColumnWidth(3, 25); - m_ui->phonesView->horizontalHeader()->setStretchLastSection(false); - m_ui->phonesView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); - - connect(m_ui->phonesView, &QWidget::customContextMenuRequested, this, &VCard::onContextMenu); - connect(m_ui->emailsView, &QWidget::customContextMenuRequested, this, &VCard::onContextMenu); - - if (edit) { - avatarMenu = new QMenu(); - m_ui->avatarButton->setMenu(avatarMenu); - avatarMenu->addAction(setAvatar); - avatarMenu->addAction(clearAvatar); - m_ui->title->setText(tr("Account %1 card").arg(jid)); - } else { - m_ui->buttonBox->hide(); - m_ui->fullName->setReadOnly(true); - m_ui->firstName->setReadOnly(true); - m_ui->middleName->setReadOnly(true); - m_ui->lastName->setReadOnly(true); - m_ui->nickName->setReadOnly(true); - m_ui->birthday->setReadOnly(true); - m_ui->organizationName->setReadOnly(true); - m_ui->organizationDepartment->setReadOnly(true); - m_ui->organizationTitle->setReadOnly(true); - m_ui->organizationRole->setReadOnly(true); - m_ui->description->setReadOnly(true); - m_ui->url->setReadOnly(true); - m_ui->title->setText(tr("Contact %1 card").arg(jid)); - } - - connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &VCard::onButtonBoxAccepted); - connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &VCard::close); - - avatarButtonMargins = m_ui->avatarButton->size(); - - int height = m_ui->personalForm->minimumSize().height() - avatarButtonMargins.height(); - m_ui->avatarButton->setIconSize(QSize(height, height)); - - QGridLayout* gr = static_cast(layout()); - gr->addWidget(overlay, 0, 0, 4, 1); - QVBoxLayout* nl = new QVBoxLayout(); - QGraphicsOpacityEffect* opacity = new QGraphicsOpacityEffect(); - opacity->setOpacity(0.8); - overlay->setLayout(nl); - overlay->setBackgroundRole(QPalette::Base); - overlay->setAutoFillBackground(true); - overlay->setGraphicsEffect(opacity); - progressLabel->setAlignment(Qt::AlignCenter); - QFont pf = progressLabel->font(); - pf.setBold(true); - pf.setPointSize(26); - progressLabel->setFont(pf); - progressLabel->setWordWrap(true); - nl->addStretch(); - nl->addWidget(progress); - nl->addWidget(progressLabel); - nl->addStretch(); - overlay->hide(); + initializeActions(); + initializeDelegates(); + initializeViews(); + initializeInteractiveElements(jid); + initializeOverlay(); +#ifdef WITH_OMEMO + initializeOmemo(); +#endif } -VCard::~VCard() -{ +VCard::~VCard() { +#ifdef WITH_OMEMO + delete omemo; +#endif if (editable) { avatarMenu->deleteLater(); } @@ -149,14 +73,12 @@ VCard::~VCard() contextMenu->deleteLater(); } -void VCard::setVCard(const QString& jid, const Shared::VCard& card) -{ +void VCard::setVCard(const QString& jid, const Shared::VCard& card) { m_ui->jabberID->setText(jid); setVCard(card); } -void VCard::setVCard(const Shared::VCard& card) -{ +void VCard::setVCard(const Shared::VCard& card) { m_ui->fullName->setText(card.getFullName()); m_ui->firstName->setText(card.getFirstName()); m_ui->middleName->setText(card.getMiddleName()); @@ -183,13 +105,11 @@ void VCard::setVCard(const Shared::VCard& card) phones.setPhones(phs); } -QString VCard::getJid() const -{ +QString VCard::getJid() const { return m_ui->jabberID->text(); } -void VCard::onButtonBoxAccepted() -{ +void VCard::onButtonBoxAccepted() { Shared::VCard card; card.setFullName(m_ui->fullName->text()); card.setFirstName(m_ui->firstName->text()); @@ -212,16 +132,14 @@ void VCard::onButtonBoxAccepted() emit saveVCard(card); } -void VCard::onClearAvatar() -{ +void VCard::onClearAvatar() { currentAvatarType = Shared::Avatar::empty; currentAvatarPath = ""; updateAvatar(); } -void VCard::onSetAvatar() -{ +void VCard::onSetAvatar() { QFileDialog* d = new QFileDialog(this, tr("Chose your new avatar")); d->setFileMode(QFileDialog::ExistingFile); d->setNameFilter(tr("Images (*.png *.jpg *.jpeg)")); @@ -232,8 +150,7 @@ void VCard::onSetAvatar() d->show(); } -void VCard::updateAvatar() -{ +void VCard::updateAvatar() { int height = m_ui->personalForm->minimumSize().height() - avatarButtonMargins.height(); switch (currentAvatarType) { case Shared::Avatar::empty: @@ -254,8 +171,7 @@ void VCard::updateAvatar() } } -void VCard::onAvatarSelected() -{ +void VCard::onAvatarSelected() { QFileDialog* d = static_cast(sender()); QMimeDatabase db; QString path = d->selectedFiles().front(); @@ -290,21 +206,18 @@ void VCard::onAvatarSelected() } } -void VCard::showProgress(const QString& line) -{ +void VCard::showProgress(const QString& line) { progressLabel->setText(line); overlay->show(); progress->start(); } -void VCard::hideProgress() -{ +void VCard::hideProgress() { overlay->hide(); progress->stop(); } -void VCard::onContextMenu(const QPoint& point) -{ +void VCard::onContextMenu(const QPoint& point) { contextMenu->clear(); bool hasMenu = false; QAbstractItemView* snd = static_cast(sender()); @@ -371,28 +284,20 @@ void VCard::onContextMenu(const QPoint& point) } } -void VCard::onAddEmail() -{ +void VCard::onAddEmail() { QModelIndex index = emails.addNewEmptyLine(); m_ui->emailsView->setCurrentIndex(index); m_ui->emailsView->edit(index); } -void VCard::onAddAddress() -{ - -} -void VCard::onAddPhone() -{ +void VCard::onAddAddress() {} +void VCard::onAddPhone() { QModelIndex index = phones.addNewEmptyLine(); m_ui->phonesView->setCurrentIndex(index); m_ui->phonesView->edit(index); } -void VCard::onRemoveAddress() -{ -} -void VCard::onRemoveEmail() -{ +void VCard::onRemoveAddress() {} +void VCard::onRemoveEmail() { QItemSelection selection(m_ui->emailsView->selectionModel()->selection()); QList rows; @@ -412,8 +317,7 @@ void VCard::onRemoveEmail() } } -void VCard::onRemovePhone() -{ +void VCard::onRemovePhone() { QItemSelection selection(m_ui->phonesView->selectionModel()->selection()); QList rows; @@ -433,8 +337,7 @@ void VCard::onRemovePhone() } } -void VCard::onCopyEmail() -{ +void VCard::onCopyEmail() { QList selection(m_ui->emailsView->selectionModel()->selectedRows()); QList addrs; @@ -448,8 +351,7 @@ void VCard::onCopyEmail() cb->setText(list); } -void VCard::onCopyPhone() -{ +void VCard::onCopyPhone() { QList selection(m_ui->phonesView->selectionModel()->selectedRows()); QList phs; @@ -462,3 +364,111 @@ void VCard::onCopyPhone() QClipboard* cb = QApplication::clipboard(); cb->setText(list); } + +void VCard::initializeDelegates() { + roleDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Email::roleNames[0].toStdString().c_str())); + roleDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Email::roleNames[1].toStdString().c_str())); + roleDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Email::roleNames[2].toStdString().c_str())); + + phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[0].toStdString().c_str())); + phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[1].toStdString().c_str())); + phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[2].toStdString().c_str())); + phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[3].toStdString().c_str())); + phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[4].toStdString().c_str())); + phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[5].toStdString().c_str())); + phoneTypeDelegate->addEntry(QCoreApplication::translate("Global", Shared::VCard::Phone::typeNames[6].toStdString().c_str())); +} + +void VCard::initializeViews() { + m_ui->emailsView->setContextMenuPolicy(Qt::CustomContextMenu); + m_ui->emailsView->setModel(&emails); + m_ui->emailsView->setItemDelegateForColumn(1, roleDelegate); + m_ui->emailsView->setColumnWidth(2, 25); + m_ui->emailsView->horizontalHeader()->setStretchLastSection(false); + m_ui->emailsView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + + m_ui->phonesView->setContextMenuPolicy(Qt::CustomContextMenu); + m_ui->phonesView->setModel(&phones); + m_ui->phonesView->setItemDelegateForColumn(1, roleDelegate); + m_ui->phonesView->setItemDelegateForColumn(2, phoneTypeDelegate); + m_ui->phonesView->setColumnWidth(3, 25); + m_ui->phonesView->horizontalHeader()->setStretchLastSection(false); + m_ui->phonesView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + + connect(m_ui->phonesView, &QWidget::customContextMenuRequested, this, &VCard::onContextMenu); + connect(m_ui->emailsView, &QWidget::customContextMenuRequested, this, &VCard::onContextMenu); +} + +void VCard::initializeActions() { + QAction* setAvatar = m_ui->actionSetAvatar; + QAction* clearAvatar = m_ui->actionClearAvatar; + + connect(setAvatar, &QAction::triggered, this, &VCard::onSetAvatar); + connect(clearAvatar, &QAction::triggered, this, &VCard::onClearAvatar); + + setAvatar->setEnabled(true); + clearAvatar->setEnabled(false); +} + +void VCard::initializeInteractiveElements(const QString& jid) { + if (editable) { + avatarMenu = new QMenu(); + m_ui->avatarButton->setMenu(avatarMenu); + avatarMenu->addAction(m_ui->actionSetAvatar); + avatarMenu->addAction(m_ui->actionClearAvatar); + m_ui->title->setText(tr("Account %1 card").arg(jid)); + } else { + m_ui->buttonBox->hide(); + m_ui->fullName->setReadOnly(true); + m_ui->firstName->setReadOnly(true); + m_ui->middleName->setReadOnly(true); + m_ui->lastName->setReadOnly(true); + m_ui->nickName->setReadOnly(true); + m_ui->birthday->setReadOnly(true); + m_ui->organizationName->setReadOnly(true); + m_ui->organizationDepartment->setReadOnly(true); + m_ui->organizationTitle->setReadOnly(true); + m_ui->organizationRole->setReadOnly(true); + m_ui->description->setReadOnly(true); + m_ui->url->setReadOnly(true); + m_ui->title->setText(tr("Contact %1 card").arg(jid)); + } + + connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &VCard::onButtonBoxAccepted); + connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &VCard::close); + + avatarButtonMargins = m_ui->avatarButton->size(); + + int height = m_ui->personalForm->minimumSize().height() - avatarButtonMargins.height(); + m_ui->avatarButton->setIconSize(QSize(height, height)); +} + +void VCard::initializeOverlay() { + QGridLayout* gr = static_cast(layout()); + gr->addWidget(overlay, 0, 0, 4, 1); + QVBoxLayout* nl = new QVBoxLayout(); + QGraphicsOpacityEffect* opacity = new QGraphicsOpacityEffect(); + opacity->setOpacity(0.8); + overlay->setLayout(nl); + overlay->setBackgroundRole(QPalette::Base); + overlay->setAutoFillBackground(true); + overlay->setGraphicsEffect(opacity); + progressLabel->setAlignment(Qt::AlignCenter); + QFont pf = progressLabel->font(); + pf.setBold(true); + pf.setPointSize(26); + progressLabel->setFont(pf); + progressLabel->setWordWrap(true); + nl->addStretch(); + nl->addWidget(progress); + nl->addWidget(progressLabel); + nl->addStretch(); + overlay->hide(); +} + +#ifdef WITH_OMEMO +void VCard::initializeOmemo() { + m_ui->tabWidget->addTab(omemo, "OMEMO"); +} + +#endif diff --git a/ui/widgets/vcard/vcard.h b/ui/widgets/vcard/vcard.h index 4d579e1..82b7d53 100644 --- a/ui/widgets/vcard/vcard.h +++ b/ui/widgets/vcard/vcard.h @@ -42,16 +42,16 @@ #include "ui/utils/progress.h" #include "ui/utils/comboboxdelegate.h" +#ifdef WITH_OMEMO +#include "omemo/omemo.h" +#endif + namespace Ui { class VCard; } -/** - * @todo write docs - */ -class VCard : public QWidget -{ +class VCard : public QWidget { Q_OBJECT public: VCard(const QString& jid, bool edit = false, QWidget* parent = nullptr); @@ -96,11 +96,22 @@ private: UI::VCard::PhonesModel phones; ComboboxDelegate* roleDelegate; ComboboxDelegate* phoneTypeDelegate; +#ifdef WITH_OMEMO + Omemo* omemo; +#endif static const std::set supportedTypes; - + private: void updateAvatar(); + void initializeDelegates(); + void initializeViews(); + void initializeActions(); + void initializeInteractiveElements(const QString& jid); + void initializeOverlay(); +#ifdef WITH_OMEMO + void initializeOmemo(); +#endif }; #endif // VCARD_H