mirror of
https://github.com/QRouland/UTPass.git
synced 2025-02-11 06:57:15 +00:00
WIP Rewrite get all key with rnp
This commit is contained in:
parent
4bec3dcbc9
commit
74a001eefc
@ -13,8 +13,7 @@ Pass::Pass():
|
||||
QStandardPaths::AppDataLocation).append("/.password-store")),
|
||||
m_gpg_home (QStandardPaths::writableLocation(
|
||||
QStandardPaths::AppDataLocation).append("/.rnp")),
|
||||
m_sem(std::unique_ptr<QSemaphore>(new QSemaphore(1))),
|
||||
m_show_filename(QString())
|
||||
m_sem(std::unique_ptr<QSemaphore>(new QSemaphore(1)))
|
||||
{
|
||||
|
||||
}
|
||||
@ -173,6 +172,7 @@ bool Pass::getAllGPGKeys()
|
||||
qInfo() << "[Pass] A job is already running";
|
||||
return false;
|
||||
}
|
||||
this->m_keyring_model = nullptr;
|
||||
auto job = new GetKeysJob(this->m_gpg_home);
|
||||
QObject::connect(job, &GetKeysJob::resultError, this, &Pass::slotGetAllGPGKeysError);
|
||||
QObject::connect(job, &GetKeysJob::resultSuccess, this, &Pass::slotGetAllGPGKeysSucceed);
|
||||
@ -184,6 +184,7 @@ bool Pass::getAllGPGKeys()
|
||||
void Pass::slotGetAllGPGKeysError(rnp_result_t err)
|
||||
{
|
||||
qInfo() << "[Pass] Get all GPG Keys Failed";
|
||||
this->m_keyring_model = nullptr;
|
||||
emit getAllGPGKeysFailed(rnp_result_to_string(err));
|
||||
this->m_sem->release(1);
|
||||
}
|
||||
@ -191,23 +192,11 @@ void Pass::slotGetAllGPGKeysError(rnp_result_t err)
|
||||
void Pass::slotGetAllGPGKeysSucceed(QSet<QString> result)
|
||||
{
|
||||
qInfo() << "[Pass] Get all GPG Keys Succeed";
|
||||
emit getAllGPGKeysSucceed(result.values());
|
||||
this->m_keyring_model = std::unique_ptr<PassKeyringModel>(new PassKeyringModel(result));
|
||||
emit getAllGPGKeysSucceed(this->m_keyring_model.get());
|
||||
this->m_sem->release(1);
|
||||
}
|
||||
|
||||
// void Pass::getAllGPGKeysResult(Error err, std::vector<GpgME::Key> keys_info)
|
||||
// {
|
||||
// qDebug() << "Get GPG keys Result";
|
||||
// if (err) {
|
||||
// qInfo() << "Get GPG Failed";
|
||||
// emit getAllGPGKeysFailed(err.asString());
|
||||
// } else {
|
||||
// qInfo() << "Get GPG Succeed";
|
||||
// emit getAllGPGKeysSucceed(QVariant::fromValue(PassKeyModel::keysToPassKey(keys_info)));
|
||||
// }
|
||||
// this->m_sem->release(1);
|
||||
// }
|
||||
|
||||
// void Pass::responsePassphraseDialog(bool cancel, QString passphrase)
|
||||
// {
|
||||
// qDebug() << "Propagate responsePassphraseDialog";
|
||||
|
@ -97,7 +97,7 @@ signals:
|
||||
* @brief Emitted when all GPG keys are successfully retrieved.
|
||||
* @param keys_info The list of retrieved keys.
|
||||
*/
|
||||
void getAllGPGKeysSucceed(QList<QString> keys_info);
|
||||
void getAllGPGKeysSucceed(QObject* keys_info);
|
||||
|
||||
/**
|
||||
* @brief Emitted when retrieving GPG keys fails.
|
||||
@ -146,9 +146,9 @@ signals:
|
||||
private:
|
||||
QString m_password_store; /**< The path to the password store. */
|
||||
QString m_gpg_home; /**< The path to the gpg home. */
|
||||
PassphraseProvider *m_passphrase_provider; /**< Semaphore for managing concurrent operations. */
|
||||
std::unique_ptr<PassKeyringModel> m_keyring_model; /**< Meta data on the keyring uid, name, secrecy ... of the availble keys. */
|
||||
PassphraseProvider *m_passphrase_provider; /**< Pointer on passphrase povider for operations using secret keys. */
|
||||
std::unique_ptr<QSemaphore> m_sem; /**< Semaphore for managing concurrent operations. */
|
||||
QString m_show_filename; /**< The filename associated with the password to show. */
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,9 @@
|
||||
#ifndef PASSKEYMODEL_H
|
||||
#define PASSKEYMODEL_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <gpgme++/key.h>
|
||||
|
||||
using namespace GpgME;
|
||||
@ -69,85 +71,117 @@ public:
|
||||
class PassKeyModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Key key READ key MEMBER m_key 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)
|
||||
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)
|
||||
|
||||
private:
|
||||
Key m_key; /**< The GPG key associated with the model. */
|
||||
QString m_fingeprint; /**< The key fingeprint. */
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a PassKeyModel for the given GPG key.
|
||||
* @param key The GPG key to model.
|
||||
*/
|
||||
PassKeyModel(Key key) : m_key(key) {}
|
||||
PassKeyModel(QString fingeprint) : m_fingeprint(fingeprint) {}
|
||||
|
||||
/**
|
||||
* @brief Converts a vector of GPG keys into a list of PassKeyModel objects.
|
||||
* @param keys The vector of GPG keys to convert.
|
||||
* @return A QList of PassKeyModel objects representing the keys.
|
||||
*/
|
||||
static QList<QObject *> keysToPassKey(std::vector<Key> keys)
|
||||
|
||||
QString fingeprint() const
|
||||
{
|
||||
QList<QObject *> ret;
|
||||
std::for_each(keys.begin(), keys.end(), [&ret](Key k) {
|
||||
ret.append(new PassKeyModel(k));
|
||||
});
|
||||
return ret;
|
||||
return m_fingeprint;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the GPG key associated with this model.
|
||||
* @return The GPG key.
|
||||
*/
|
||||
Key key() const
|
||||
{
|
||||
return m_key;
|
||||
};
|
||||
// /**
|
||||
// * @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 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 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 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();
|
||||
};
|
||||
// /**
|
||||
// * @brief Checks if the GPG key is expired.
|
||||
// * @return True if the key is expired, false otherwise.
|
||||
// */
|
||||
// bool isExpired() const
|
||||
// {
|
||||
// return m_key.isExpired();
|
||||
// };
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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)
|
||||
|
||||
private:
|
||||
QList<PassKeyModel*> m_keys;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a PassKeyModel for the given GPG key.
|
||||
* @param key The GPG key to model.
|
||||
*/
|
||||
PassKeyringModel(QSet<QString> fingeprints)
|
||||
{
|
||||
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();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: utpass.qrouland\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2025-01-30 16:16+0100\n"
|
||||
"POT-Creation-Date: 2025-01-30 22:45+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -43,7 +43,7 @@ msgid "Ok"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/dialogs/PassphraseDialog.qml:41
|
||||
#: ../qml/dialogs/SimpleValidationDialog.qml:29
|
||||
#: ../qml/dialogs/SimpleValidationDialog.qml:28
|
||||
msgid "Cancel"
|
||||
msgstr ""
|
||||
|
||||
@ -112,31 +112,31 @@ msgstr ""
|
||||
msgid "Search"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:43
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:42
|
||||
#: ../qml/pages/settings/Settings.qml:58
|
||||
msgid "Delete Password Store"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:56
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:55
|
||||
msgid "You're are about to delete<br>the current Password Store.<br>Continue ?"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:57
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:56
|
||||
#: ../qml/pages/settings/ImportZip.qml:64
|
||||
#: ../qml/pages/settings/InfoKeys.qml:170
|
||||
#: ../qml/pages/settings/git/ImportGitClone.qml:56
|
||||
msgid "Yes"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:70
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:69
|
||||
msgid "Password Store removal failed !"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:79
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:78
|
||||
msgid "Password Store deleted !"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:91
|
||||
#: ../qml/pages/settings/DeleteRepo.qml:90
|
||||
#: ../qml/pages/settings/InfoKeys.qml:212
|
||||
msgid "Info Keys"
|
||||
msgstr ""
|
||||
@ -171,11 +171,11 @@ msgstr ""
|
||||
msgid "Zip Password Store Import"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/pages/settings/InfoKeys.qml:49
|
||||
#: ../qml/pages/settings/InfoKeys.qml:50
|
||||
msgid "No key found"
|
||||
msgstr ""
|
||||
|
||||
#: ../qml/pages/settings/InfoKeys.qml:85
|
||||
#: ../qml/pages/settings/InfoKeys.qml:86
|
||||
msgid "Key ID :"
|
||||
msgstr ""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user