some further work on omemo, far from done yet

This commit is contained in:
Blue 2023-03-02 21:17:06 +03:00
parent 6f32e99593
commit 77dd28b600
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
18 changed files with 161 additions and 43 deletions

View file

@ -134,5 +134,11 @@ void Models::Keys::setTrustLevel(int row, Shared::TrustLevel level) {
dataChanged(index, index, {Keys::Dirty});
}
void Models::Keys::clear() {
beginResetModel();
keys.clear();
modified.clear();
endResetModel();
}

View file

@ -33,6 +33,7 @@ public:
~Keys();
void addKey(const Shared::KeyInfo& info);
void clear();
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;

View file

@ -24,6 +24,9 @@ UI::Info::Info(const QString& p_jid, QWidget* parent):
m_ui(new Ui::Info()),
contactGeneral(nullptr),
contactContacts(nullptr),
#ifdef WITH_OMEMO
omemo(nullptr),
#endif
description(nullptr),
overlay(new QWidget()),
progress(new Progress(100)),
@ -57,6 +60,9 @@ void UI::Info::setData(const Shared::Info& info) {
initializeContactGeneral(jid, card, editable);
initializeContactContacts(jid, card, editable);
initializeDescription(card.getDescription(), editable);
#ifdef WITH_OMEMO
initializeOmemo(info.getActiveKeysRef());
#endif
type = info.getType();
}
break;
@ -170,5 +176,24 @@ void UI::Info::clear() {
description->deleteLater();
description = nullptr;
}
#ifdef WITH_OMEMO
if (omemo != nullptr) {
omemo->deleteLater();
omemo = nullptr;
}
#endif
type = Shared::EntryType::none;
}
#ifdef WITH_OMEMO
void UI::Info::initializeOmemo(const std::list<Shared::KeyInfo>& keys) {
if (omemo == nullptr) {
omemo = new Omemo();
m_ui->tabWidget->addTab(omemo, omemo->title());
}
omemo->setData(keys);
}
#endif

View file

@ -17,6 +17,8 @@
#ifndef UI_WIDGETS_INFO_H
#define UI_WIDGETS_INFO_H
#include <list>
#include <QWidget>
#include <QScopedPointer>
#include <QGraphicsOpacityEffect>
@ -30,6 +32,10 @@
#include "contactgeneral.h"
#include "contactcontacts.h"
#include "description.h"
#ifdef WITH_OMEMO
#include "omemo/omemo.h"
#endif
namespace UI {
namespace Ui
@ -58,6 +64,9 @@ private:
void initializeContactGeneral(const QString& jid, const Shared::VCard& card, bool editable);
void initializeContactContacts(const QString& jid, const Shared::VCard& card, bool editable);
void initializeDescription(const QString& description, bool editable);
#ifdef WITH_OMEMO
void initializeOmemo(const std::list<Shared::KeyInfo>& keys);
#endif
void initializeOverlay();
void initializeButtonBox();
void clear();
@ -68,6 +77,9 @@ private:
QScopedPointer<Ui::Info> m_ui;
ContactGeneral* contactGeneral;
ContactContacts* contactContacts;
#ifdef WITH_OMEMO
Omemo* omemo;
#endif
Description* description;
QWidget* overlay;
Progress* progress;

View file

@ -20,7 +20,7 @@
#include <random>
constexpr uint8_t fingerprintLength = 32;
Omemo::Omemo(QWidget* parent):
UI::Omemo::Omemo(QWidget* parent):
QWidget(parent),
m_ui(new Ui::Omemo()),
keysDelegate(),
@ -31,8 +31,6 @@ Omemo::Omemo(QWidget* parent):
{
m_ui->setupUi(this);
generateMockData();
m_ui->keysView->setItemDelegate(&keysDelegate);
m_ui->keysView->setModel(&keysModel);
m_ui->unusedKeysView->setItemDelegate(&unusedKeysDelegate);
@ -42,12 +40,12 @@ Omemo::Omemo(QWidget* parent):
connect(m_ui->keysView, &QWidget::customContextMenuRequested, this, &Omemo::onActiveKeysContextMenu);
}
Omemo::~Omemo()
UI::Omemo::~Omemo()
{
contextMenu->deleteLater();
}
void Omemo::generateMockData() {
void UI::Omemo::generateMockData() {
std::random_device rd;
std::uniform_int_distribution<char> dist(CHAR_MIN, CHAR_MAX);
for (int i = 0; i < 5; ++i) {
@ -67,7 +65,19 @@ void Omemo::generateMockData() {
}
}
void Omemo::onActiveKeysContextMenu(const QPoint& pos) {
void UI::Omemo::setData(const std::list<Shared::KeyInfo>& keys) {
keysModel.clear();
unusedKeysModel.clear();
for (const Shared::KeyInfo& key : keys) {
keysModel.addKey(key);
}
}
const QString UI::Omemo::title() const {
return m_ui->OMEMOHeading->text();}
void UI::Omemo::onActiveKeysContextMenu(const QPoint& pos) {
contextMenu->clear();
QModelIndex index = m_ui->keysView->indexAt(pos);
if (index.isValid()) {

View file

@ -17,6 +17,8 @@
#ifndef VCARD_OMEMO_H
#define VCARD_OMEMO_H
#include <list>
#include <QWidget>
#include <QScopedPointer>
#include <QMenu>
@ -24,7 +26,9 @@
#include "ui/models/info/omemo/keys.h"
#include "keydelegate.h"
#include "shared/icons.h"
#include "shared/keyinfo.h"
namespace UI {
namespace Ui
{
class Omemo;
@ -36,6 +40,9 @@ public:
Omemo(QWidget* parent = nullptr);
~Omemo();
void setData(const std::list<Shared::KeyInfo>& keys);
const QString title() const;
private slots:
void onActiveKeysContextMenu(const QPoint& pos);
@ -50,5 +57,5 @@ private:
Models::Keys unusedKeysModel;
QMenu* contextMenu;
};
}
#endif // VCARD_OMEMO_H

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Omemo</class>
<widget class="QWidget" name="Omemo">
<class>UI::Omemo</class>
<widget class="QWidget" name="UI::Omemo">
<property name="geometry">
<rect>
<x>0</x>