2019-09-20 21:29:39 +02:00
|
|
|
#ifndef PASSKEYMODEL_H
|
|
|
|
#define PASSKEYMODEL_H
|
|
|
|
|
2025-01-30 22:46:46 +01:00
|
|
|
#include <QDebug>
|
2019-09-20 21:29:39 +02:00
|
|
|
#include <QObject>
|
2025-01-30 22:46:46 +01:00
|
|
|
#include <QSet>
|
2019-09-20 21:29:39 +02:00
|
|
|
#include <gpgme++/key.h>
|
|
|
|
|
|
|
|
using namespace GpgME;
|
|
|
|
|
2025-01-15 23:40:35 +01:00
|
|
|
/**
|
|
|
|
* @class UserIdModel
|
|
|
|
* @brief A model representing a user ID associated with a GPG key.
|
|
|
|
*
|
|
|
|
* This class encapsulates the user ID information (UID) for a GPG key, providing access
|
2025-01-17 10:40:54 +01:00
|
|
|
* to the UID's identifier, name, and email.
|
2025-01-15 23:40:35 +01:00
|
|
|
*/
|
2025-01-14 12:20:55 +01:00
|
|
|
class UserIdModel : public QObject
|
2019-09-20 21:29:39 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2025-01-15 23:15:00 +01:00
|
|
|
Q_PROPERTY(QString uid READ uid CONSTANT)
|
|
|
|
Q_PROPERTY(QString name READ name CONSTANT)
|
|
|
|
Q_PROPERTY(QString email READ email CONSTANT)
|
2019-09-20 21:29:39 +02:00
|
|
|
|
2025-01-15 23:15:00 +01:00
|
|
|
private:
|
2025-01-15 23:40:35 +01:00
|
|
|
UserID m_user_id; /**< The GPG UserID associated with the model. */
|
2025-01-14 12:20:55 +01:00
|
|
|
|
2025-01-15 23:40:35 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Constructs a UserIdModel for the given UserID.
|
|
|
|
* @param key The GPG UserID to model.
|
|
|
|
*/
|
|
|
|
UserIdModel(UserID key) : m_user_id(key) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the unique identifier (UID) for this user ID.
|
|
|
|
* @return The UID as a QString.
|
|
|
|
*/
|
2025-01-14 12:20:55 +01:00
|
|
|
QString uid() const
|
|
|
|
{
|
|
|
|
return QString::fromUtf8(m_user_id.id());
|
|
|
|
};
|
2025-01-15 23:40:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the name associated with this user ID.
|
|
|
|
* @return The name as a QString.
|
|
|
|
*/
|
2025-01-14 12:20:55 +01:00
|
|
|
QString name() const
|
|
|
|
{
|
|
|
|
return QString::fromUtf8(m_user_id.name());
|
|
|
|
};
|
2025-01-15 23:40:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the email associated with this user ID.
|
|
|
|
* @return The email as a QString.
|
|
|
|
*/
|
2025-01-14 12:20:55 +01:00
|
|
|
QString email() const
|
|
|
|
{
|
|
|
|
return QString::fromUtf8(m_user_id.email());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-01-15 23:40:35 +01:00
|
|
|
/**
|
|
|
|
* @class PassKeyModel
|
|
|
|
* @brief A model representing a GPG key.
|
|
|
|
*
|
|
|
|
* This class encapsulates the properties of a GPG key, including its key ID, associated
|
|
|
|
* user IDs, secret key status, and expiration status. It is used as a model for managing
|
|
|
|
* GPG keys within an application, providing access to the key's data and its associated user IDs.
|
|
|
|
*/
|
2025-01-14 12:20:55 +01:00
|
|
|
class PassKeyModel : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2025-01-30 22:46:46 +01:00
|
|
|
Q_PROPERTY(QString fingeprint READ fingeprint MEMBER m_fingeprint CONSTANT)
|
|
|
|
// Q_PROPERTY(QString uid READ uid CONSTANT)
|
|
|
|
// Q_PROPERTY(QList<QObject *> userIds READ userIds CONSTANT)
|
|
|
|
// Q_PROPERTY(bool isSecret READ isSecret CONSTANT)
|
|
|
|
// Q_PROPERTY(bool isExpired READ isExpired CONSTANT)
|
2025-01-14 12:20:55 +01:00
|
|
|
|
2025-01-15 23:40:35 +01:00
|
|
|
private:
|
2025-01-30 22:46:46 +01:00
|
|
|
QString m_fingeprint; /**< The key fingeprint. */
|
2019-09-20 21:29:39 +02:00
|
|
|
|
2025-01-15 23:40:35 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Constructs a PassKeyModel for the given GPG key.
|
|
|
|
* @param key The GPG key to model.
|
|
|
|
*/
|
2025-01-30 22:46:46 +01:00
|
|
|
PassKeyModel(QString fingeprint) : m_fingeprint(fingeprint) {}
|
2025-01-15 23:40:35 +01:00
|
|
|
|
2019-09-20 21:29:39 +02:00
|
|
|
|
2025-01-30 22:46:46 +01:00
|
|
|
QString fingeprint() const
|
2025-01-15 23:15:00 +01:00
|
|
|
{
|
2025-01-30 22:46:46 +01:00
|
|
|
return m_fingeprint;
|
2025-01-15 23:15:00 +01:00
|
|
|
};
|
|
|
|
|
2025-01-30 22:46:46 +01:00
|
|
|
// /**
|
|
|
|
// * @brief Gets the GPG key associated with this model.
|
|
|
|
// * @return The GPG key.
|
|
|
|
// */
|
|
|
|
// Key key() const
|
|
|
|
// {
|
|
|
|
// return m_key;
|
|
|
|
// };
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * @brief Gets the unique identifier (UID) for this GPG key.
|
|
|
|
// * @return The UID as a QString.
|
|
|
|
// */
|
|
|
|
// QString uid() const
|
|
|
|
// {
|
|
|
|
// return QString::fromUtf8(m_key.keyID());
|
|
|
|
// };
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * @brief Gets the list of user IDs associated with this GPG key.
|
|
|
|
// * @return A list of UserIdModel objects representing the user IDs.
|
|
|
|
// */
|
|
|
|
// QList<QObject *> userIds() const
|
|
|
|
// {
|
|
|
|
// 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;
|
|
|
|
// };
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * @brief Checks if the GPG key is a secret key.
|
|
|
|
// * @return True if the key is a secret key, false otherwise.
|
|
|
|
// */
|
|
|
|
// bool isSecret() const
|
|
|
|
// {
|
|
|
|
// return m_key.hasSecret();
|
|
|
|
// };
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * @brief Checks if the GPG key is expired.
|
|
|
|
// * @return True if the key is expired, false otherwise.
|
|
|
|
// */
|
|
|
|
// bool isExpired() const
|
|
|
|
// {
|
|
|
|
// return m_key.isExpired();
|
|
|
|
// };
|
|
|
|
};
|
2025-01-14 12:20:55 +01:00
|
|
|
|
|
|
|
|
2025-01-30 22:46:46 +01:00
|
|
|
/**
|
|
|
|
* @class PassKeyModel
|
|
|
|
* @brief A model representing a GPG key.
|
|
|
|
*
|
|
|
|
* This class encapsulates the properties of a GPG key, including its key ID, associated
|
|
|
|
* user IDs, secret key status, and expiration status. It is used as a model for managing
|
|
|
|
* GPG keys within an application, providing access to the key's data and its associated user IDs.
|
|
|
|
*/
|
|
|
|
class PassKeyringModel : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(int length READ length CONSTANT)
|
2019-09-20 21:29:39 +02:00
|
|
|
|
2025-01-30 22:46:46 +01:00
|
|
|
private:
|
|
|
|
QList<PassKeyModel*> m_keys;
|
|
|
|
|
|
|
|
public:
|
2025-01-15 23:40:35 +01:00
|
|
|
/**
|
2025-01-30 22:46:46 +01:00
|
|
|
* @brief Constructs a PassKeyModel for the given GPG key.
|
|
|
|
* @param key The GPG key to model.
|
2025-01-15 23:40:35 +01:00
|
|
|
*/
|
2025-01-30 22:46:46 +01:00
|
|
|
PassKeyringModel(QSet<QString> fingeprints)
|
2019-09-20 21:29:39 +02:00
|
|
|
{
|
2025-01-30 22:46:46 +01:00
|
|
|
QSet<QString>::iterator i;
|
|
|
|
for (auto i = fingeprints.begin(), end = fingeprints.end(); i != end; ++i) {
|
|
|
|
this->m_keys.append(new PassKeyModel(*i));
|
|
|
|
}
|
|
|
|
qDebug() << "Test : " << this->m_keys;
|
|
|
|
}
|
|
|
|
|
|
|
|
~PassKeyringModel() {
|
|
|
|
qDeleteAll(this->m_keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
int length() {
|
|
|
|
qDebug() << "Test2 : " << this->m_keys.length();
|
|
|
|
return this->m_keys.length();
|
|
|
|
}
|
2019-09-20 21:29:39 +02:00
|
|
|
};
|
|
|
|
#endif
|