1
0
Fork 0
forked from blue/squawk

beginning of keys setting

This commit is contained in:
Blue 2023-11-16 21:08:40 -03:00
parent 75554c7451
commit 8f5325b291
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
11 changed files with 385 additions and 323 deletions

View file

@ -1,18 +1,20 @@
// Squawk messenger.
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
//
// 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 <http://www.gnu.org/licenses/>.
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "keys.h"
@ -37,18 +39,34 @@ Models::Keys::~Keys() {
delete pair.second;
}
std::deque<Shared::KeyInfo> Models::Keys::modifiedKeys() const {
std::deque<Shared::KeyInfo> response(modified.size());
std::list<Shared::KeyInfo> Models::Keys::modifiedKeys() const {
std::list<Shared::KeyInfo> response;
for (const std::pair<const int, Shared::KeyInfo*>& pair: modified)
response.push_back(*(pair.second));
int i = 0;
for (const std::pair<const int, Shared::KeyInfo*>& pair: modified) {
response[i] = *(pair.second);
++i;
}
return response;
}
std::list<Shared::KeyInfo> Models::Keys::finalKeys() const {
std::list<Shared::KeyInfo> result;
finalKeys(result);
return result;
}
void Models::Keys::finalKeys(std::list<Shared::KeyInfo>& out) const {
for (int i = 0; i < rowCount(); ++i)
out.push_back(key(i));
}
const Shared::KeyInfo & Models::Keys::key(unsigned int i) const {
std::map<int, Shared::KeyInfo*>::const_iterator itr = modified.find(i);
if (itr != modified.end())
return*(itr->second);
else
return *(keys[i]);
}
void Models::Keys::addKey(const Shared::KeyInfo& info) {
beginInsertRows(QModelIndex(), keys.size(), keys.size());
keys.push_back(new Shared::KeyInfo(info));

View file

@ -1,21 +1,22 @@
// Squawk messenger.
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
//
// 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 <http://www.gnu.org/licenses/>.
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef MODELS_KEYS_H
#define MODELS_KEYS_H
#pragma once
#include <QAbstractListModel>
@ -23,11 +24,7 @@
namespace Models {
/**
* @todo write docs
*/
class Keys : public QAbstractListModel
{
class Keys : public QAbstractListModel {
public:
Keys(QObject *parent = nullptr);
~Keys();
@ -37,11 +34,14 @@ public:
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
const Shared::KeyInfo& key(unsigned int i) const;
QHash<int, QByteArray> roleNames() const override;
QModelIndex index(int row, int column, const QModelIndex & parent) const override;
std::deque<Shared::KeyInfo> modifiedKeys() const;
std::list<Shared::KeyInfo> modifiedKeys() const;
std::list<Shared::KeyInfo> finalKeys() const;
void finalKeys(std::list<Shared::KeyInfo>& out) const;
enum Roles {
Label = Qt::UserRole + 1,
@ -64,5 +64,3 @@ private:
};
}
#endif // MODELS_KEYS_H

View file

@ -114,6 +114,9 @@ void UI::Info::onButtonBoxAccepted() {
contactGeneral->fillVCard(card);
contactContacts->fillVCard(card);
card.setDescription(description->description());
#ifdef WITH_OMEMO
omemo->fillData(info.getActiveKeysRef());
#endif
emit saveInfo(info);
emit close();
}
@ -161,7 +164,8 @@ void UI::Info::initializeDescription(const QString& descr, bool editable) {
}
QString UI::Info::getJid() const {
return jid;}
return jid;
}
void UI::Info::clear() {
if (contactGeneral != nullptr) {

View file

@ -39,8 +39,7 @@
namespace UI {
namespace Ui
{
namespace Ui {
class Info;
}

View file

@ -88,6 +88,12 @@ void UI::Omemo::setData(const std::list<Shared::KeyInfo>& keys) {
deviceKeyVisibility(deviceKeyModel.rowCount() > 0);
}
void UI::Omemo::fillData(std::list<Shared::KeyInfo>& out) {
deviceKeyModel.finalKeys(out);
keysModel.finalKeys(out);
unusedKeysModel.finalKeys(out);
}
const QString UI::Omemo::title() const {
return m_ui->OMEMOHeading->text();
}

View file

@ -41,6 +41,7 @@ public:
~Omemo();
void setData(const std::list<Shared::KeyInfo>& keys);
void fillData(std::list<Shared::KeyInfo>& out);
const QString title() const;
private slots: