squawk/ui/models/info/omemo/keys.h

67 lines
1.9 KiB
C
Raw Permalink Normal View History

2023-11-17 00:08:40 +00:00
/*
* 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/>.
*/
2023-01-03 15:27:03 +00:00
2023-11-17 00:08:40 +00:00
#pragma once
2023-01-03 15:27:03 +00:00
#include <QAbstractListModel>
#include <shared/keyinfo.h>
2023-02-01 15:56:00 +00:00
namespace Models {
2023-01-03 15:27:03 +00:00
2023-11-17 00:08:40 +00:00
class Keys : public QAbstractListModel {
2023-01-03 15:27:03 +00:00
public:
2023-02-01 15:56:00 +00:00
Keys(QObject *parent = nullptr);
~Keys();
2023-01-03 15:27:03 +00:00
void addKey(const Shared::KeyInfo& info);
void clear();
2023-01-03 15:27:03 +00:00
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
2023-11-17 00:08:40 +00:00
const Shared::KeyInfo& key(unsigned int i) const;
2023-01-03 15:27:03 +00:00
QHash<int, QByteArray> roleNames() const override;
QModelIndex index(int row, int column, const QModelIndex & parent) const override;
2023-11-17 00:08:40 +00:00
std::list<Shared::KeyInfo> modifiedKeys() const;
std::list<Shared::KeyInfo> finalKeys() const;
void finalKeys(std::list<Shared::KeyInfo>& out) const;
2023-01-15 18:17:38 +00:00
2023-01-03 15:27:03 +00:00
enum Roles {
Label = Qt::UserRole + 1,
FingerPrint,
TrustLevel,
LastInteraction,
Dirty
2023-01-03 15:27:03 +00:00
};
2023-01-15 18:17:38 +00:00
public slots:
void revertKey(int index);
void setTrustLevel(int index, Shared::TrustLevel level);
2023-01-03 15:27:03 +00:00
private:
std::deque<Shared::KeyInfo*> keys;
2023-01-15 18:17:38 +00:00
std::map<int, Shared::KeyInfo*> modified;
2023-01-03 15:27:03 +00:00
private:
static const QHash<int, QByteArray> roles;
};
}