1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-01-26 00:26:40 +00:00
UTPass/plugins/Pass/passkeymodel.h

90 lines
1.9 KiB
C
Raw Normal View History

2019-09-20 21:29:39 +02:00
#ifndef PASSKEYMODEL_H
#define PASSKEYMODEL_H
#include <QObject>
#include <gpgme++/key.h>
using namespace GpgME;
2025-01-14 12:20:55 +01:00
class UserIdModel : public QObject
2019-09-20 21:29:39 +02:00
{
Q_OBJECT
2025-01-14 12:20:55 +01:00
Q_PROPERTY(QString uid READ uid MEMBER m_uid CONSTANT)
Q_PROPERTY(QString name READ name MEMBER m_name CONSTANT)
Q_PROPERTY(QString email READ email MEMBER m_email CONSTANT)
2019-09-20 21:29:39 +02:00
2025-01-14 12:20:55 +01:00
UserID m_user_id;
2019-09-20 21:29:39 +02:00
public:
2025-01-14 12:20:55 +01:00
UserIdModel(UserID key):
m_user_id(key)
2025-01-14 13:05:09 +01:00
{};
2025-01-14 12:20:55 +01:00
QString uid() const
{
return QString::fromUtf8(m_user_id.id());
};
QString name() const
{
return QString::fromUtf8(m_user_id.name());
};
QString email() const
{
return QString::fromUtf8(m_user_id.email());
};
};
class PassKeyModel : public QObject
{
Q_OBJECT
Q_PROPERTY(QString uid READ uid MEMBER m_uid CONSTANT)
Q_PROPERTY(QList<QObject *> userIds READ userIds MEMBER m_user_ids CONSTANT)
Q_PROPERTY(bool isSecret READ isSecret MEMBER m_secret CONSTANT)
Q_PROPERTY(bool isExpired READ isExpired MEMBER m_expired CONSTANT)
Key m_key;
public:
2019-09-20 21:29:39 +02:00
PassKeyModel(Key key):
2025-01-14 12:20:55 +01:00
m_key(key)
2019-09-20 21:29:39 +02:00
{};
2025-01-14 12:20:55 +01:00
static QList<QObject *> keysToPassKey(std::vector<Key> keys)
2019-09-20 21:29:39 +02:00
{
2025-01-14 12:20:55 +01:00
QList<QObject *> ret;
std::for_each(keys.begin(), keys.end(), [&ret](Key k) {
ret.append(new PassKeyModel(k));
2019-09-20 21:29:39 +02:00
});
2025-01-14 12:20:55 +01:00
return ret;
2019-09-20 21:29:39 +02:00
};
QString uid() const
{
2025-01-14 12:20:55 +01:00
return QString::fromUtf8(m_key.keyID());
2019-09-20 21:29:39 +02:00
};
2025-01-14 12:20:55 +01:00
QList<QObject *> userIds() const
2019-09-20 21:29:39 +02:00
{
2025-01-14 12:20:55 +01:00
auto user_ids = m_key.userIDs();
QList<QObject *> ret;
std::for_each(user_ids.begin(), user_ids.end(), [&ret](UserID k) {
ret.append(new UserIdModel(k));
});
return ret;
2019-09-20 21:29:39 +02:00
};
2025-01-14 12:20:55 +01:00
bool isSecret() const
2019-09-20 21:29:39 +02:00
{
2025-01-14 12:20:55 +01:00
return m_key.hasSecret();
2019-09-20 21:29:39 +02:00
};
2025-01-14 12:20:55 +01:00
bool isExpired() const
2019-09-20 21:29:39 +02:00
{
2025-01-14 12:20:55 +01:00
return m_key.hasSecret();
};
2019-09-20 21:29:39 +02:00
};
2025-01-14 12:20:55 +01:00
2019-09-20 21:29:39 +02:00
#endif