mirror of
https://github.com/QRouland/UTPass.git
synced 2025-07-02 10:12:28 +00:00
Add delete password store feature
This commit is contained in:
@ -11,8 +11,6 @@ extern "C" {
|
||||
* @class CloneJob
|
||||
* @brief A class to handle cloning Git repositories in a separate thread.
|
||||
*
|
||||
* The CloneJob runs a cloning process in a separate thread and emits
|
||||
* signals to indicate the success or failure of the operation.
|
||||
*/
|
||||
class CloneJob : public GitJob
|
||||
{
|
||||
@ -21,9 +19,8 @@ class CloneJob : public GitJob
|
||||
/**
|
||||
* @brief The main function that performs the cloning operation.
|
||||
*
|
||||
* This function overrides the `run()` method from the `QThread` class. It is
|
||||
* executed when the thread is started, and it handles the process of cloning
|
||||
* a repository from the specified URL to the target path.
|
||||
* Handles the process of cloning a repository from the specified URL
|
||||
* to the target path.
|
||||
*/
|
||||
void run() override;
|
||||
|
||||
@ -31,8 +28,7 @@ signals:
|
||||
/**
|
||||
* @brief Signal emitted when the cloning operation is complete.
|
||||
*
|
||||
* This signal is emitted once the cloning operation finishes. It notifies
|
||||
* the caller whether an error occurred during the cloning process.
|
||||
* This signal is emitted once the cloning operation finishes.
|
||||
*
|
||||
* @param err A boolean indicating whether an error occurred during cloning.
|
||||
* `true` if an error occurred, `false` if the clone was successful.
|
||||
@ -47,8 +43,6 @@ private:
|
||||
* @brief Prepares the temporary directory for cloning.
|
||||
*
|
||||
* This method sets up the required directory structure for cloning a repository.
|
||||
* It is called before the cloning process begins to ensure that a suitable
|
||||
* location exists for the repository to be cloned into.
|
||||
*
|
||||
* @return A `QDir` object representing the prepared temporary directory.
|
||||
*/
|
||||
|
@ -30,10 +30,8 @@ typedef std::variant<HTTP, HTTPUserPass, SSHPass, SSHKey> cred_type;
|
||||
* @class GitJob
|
||||
* @brief A class that manages Git-related tasks using libgit2.
|
||||
*
|
||||
* The GitJob class is used to perform Git operations, such as cloning repositories,
|
||||
* in a separate thread. It utilizes libgit2 for interacting with Git repositories.
|
||||
* The class handles credentials for repository access and allows the user to specify
|
||||
* the type of credentials to use.
|
||||
* The GitJob class is used abstraction class to perform Git operations, such as cloning repositories,
|
||||
* in a separate thread using libgit2 for interacting with Git repositories.
|
||||
*/
|
||||
class GitJob : public QThread
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ set(
|
||||
gpg.cpp
|
||||
passkeymodel.h
|
||||
passphraseprovider.h
|
||||
jobs/rmjob.cpp
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
|
||||
#include "gpg.h"
|
||||
#include "passkeymodel.h"
|
||||
#include "passphraseprovider.h"
|
||||
|
||||
|
||||
|
24
plugins/Pass/jobs/rmjob.cpp
Normal file
24
plugins/Pass/jobs/rmjob.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "rmjob.h"
|
||||
|
||||
RmJob::RmJob(QString path):
|
||||
m_path(path)
|
||||
{
|
||||
this->setObjectName("RmJob");
|
||||
}
|
||||
|
||||
|
||||
void RmJob::run()
|
||||
{
|
||||
auto info = QFileInfo(this->m_path);
|
||||
if (info.isFile()) {
|
||||
auto file = QFile(this->m_path);
|
||||
file.remove();
|
||||
emit resultReady(false);
|
||||
} else if (info.isDir()) {
|
||||
auto dir = QDir(this->m_path);
|
||||
dir.removeRecursively();
|
||||
emit resultReady(false);
|
||||
} else {
|
||||
emit resultReady(true);
|
||||
}
|
||||
}
|
46
plugins/Pass/jobs/rmjob.h
Normal file
46
plugins/Pass/jobs/rmjob.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef RMJOB_H
|
||||
#define RMJOB_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QDir>
|
||||
|
||||
/**
|
||||
* @class RmJob
|
||||
* @brief A class to handle removing recursively a path in a separate thread.
|
||||
*
|
||||
*/
|
||||
class RmJob : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/**
|
||||
* @brief The main function that performs the rm operation.
|
||||
*
|
||||
* Handles the process of removing recursively a target path.
|
||||
*/
|
||||
void run() override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when the rm operation is complete.
|
||||
*
|
||||
* @param err A boolean indicating whether an error occurred during cloning.
|
||||
* `true` if an error occurred, `false` if the clone was successful.
|
||||
*/
|
||||
void resultReady(const bool err);
|
||||
|
||||
private:
|
||||
QString m_path; ///< The path to be removed.
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for the RmJob class.
|
||||
*
|
||||
* Initializes the RmJob with the specified path to be removed.
|
||||
*
|
||||
* @param path Path to be remove.
|
||||
*/
|
||||
RmJob(QString path);
|
||||
};
|
||||
|
||||
#endif // RMJOB_H
|
@ -2,6 +2,7 @@
|
||||
#include <QtCore/QStandardPaths>
|
||||
#include <QtCore/QDir>
|
||||
|
||||
#include "jobs/rmjob.h"
|
||||
#include "pass.h"
|
||||
#include "gpg.h"
|
||||
#include "passkeymodel.h"
|
||||
@ -49,6 +50,7 @@ bool Pass::show(QUrl url)
|
||||
return this->m_gpg->decryptFromFile(path);
|
||||
}
|
||||
|
||||
|
||||
void Pass::showResult(Error err, QString plain_text)
|
||||
{
|
||||
qDebug() << "Pass show Result";
|
||||
@ -67,6 +69,31 @@ void Pass::showResult(Error err, QString plain_text)
|
||||
this->m_sem->release(1);
|
||||
}
|
||||
|
||||
bool Pass::deletePasswordStore()
|
||||
{
|
||||
qInfo() << "Pass delete Password Store";
|
||||
auto job = new RmJob(this->password_store());
|
||||
qDebug() << "Delete Password Store at " << this->password_store();
|
||||
connect(job, &RmJob::resultReady, this, &Pass::deletePasswordStoreResult);
|
||||
connect(job, &RmJob::finished, job, &QObject::deleteLater);
|
||||
job->start();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Pass::deletePasswordStoreResult(bool err)
|
||||
{
|
||||
qDebug() << "Pass delete Password StoreResult";
|
||||
if (err) { //dir.removeRecursively()) {
|
||||
qInfo() << "Pass delete Password Store Failed";
|
||||
emit deletePasswordStoreFailed("failed to delete password store");
|
||||
|
||||
} else {
|
||||
qInfo() << "Pass delete Password Store Succeed";
|
||||
emit deletePasswordStoreSucceed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Pass::deleteGPGKey(PassKeyModel* key)
|
||||
{
|
||||
if (!this->m_sem->tryAcquire(1, 500)) {
|
||||
|
@ -49,6 +49,12 @@ private slots:
|
||||
*/
|
||||
void getAllGPGKeysResult(Error err, std::vector<GpgME::Key> keys_info);
|
||||
|
||||
/**
|
||||
* @brief Slot to handle the result of a delete Password Store operation.
|
||||
* @param err True if an error occurred during the operation.
|
||||
*/
|
||||
void deletePasswordStoreResult(bool err);
|
||||
|
||||
signals:
|
||||
// GPG-related signals
|
||||
/**
|
||||
@ -111,6 +117,18 @@ signals:
|
||||
*/
|
||||
void showCancelled();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Emitted when the password store is successfully deleted.
|
||||
*/
|
||||
void deletePasswordStoreSucceed();
|
||||
|
||||
/**
|
||||
* @brief Emitted when deleting the password store fails.
|
||||
* @param message The error message describing the failure.
|
||||
*/
|
||||
void deletePasswordStoreFailed(QString message);
|
||||
|
||||
private:
|
||||
QString m_password_store; /**< The path to the password store. */
|
||||
std::unique_ptr<Gpg> m_gpg; /**< The GPG instance used for encryption/decryption. */
|
||||
@ -141,22 +159,22 @@ public:
|
||||
// GPG-related methods
|
||||
|
||||
/**
|
||||
* @brief Deletes the specified GPG key.
|
||||
* @brief Launch the job to delete the specified GPG key.
|
||||
* @param key The PassKeyModel to delete.
|
||||
* @return True if the operation was successful, false otherwise.
|
||||
* @return True if the job was start successfully, false otherwise.
|
||||
*/
|
||||
Q_INVOKABLE bool deleteGPGKey(PassKeyModel* key);
|
||||
|
||||
/**
|
||||
* @brief Imports a GPG key from the given URL.
|
||||
* @brief Launch the job to import a GPG key from the given URL.
|
||||
* @param url The URL to import the GPG key from.
|
||||
* @return True if the operation was successful, false otherwise.
|
||||
* @return True if the job was start was successfully, false otherwise.
|
||||
*/
|
||||
Q_INVOKABLE bool importGPGKey(QUrl url);
|
||||
|
||||
/**
|
||||
* @brief Retrieves all GPG keys.
|
||||
* @return True if the operation was successful, false otherwise.
|
||||
* @brief Launch the to retrieve all GPG keys.
|
||||
* @return True if the job was start was successfully, false otherwise.
|
||||
*/
|
||||
Q_INVOKABLE bool getAllGPGKeys();
|
||||
|
||||
@ -170,11 +188,17 @@ public:
|
||||
// Password store-related methods
|
||||
|
||||
/**
|
||||
* @brief Shows the password associated with the specified URL.
|
||||
* @brief Launch the job to shows the password associated with the specified URL.
|
||||
* @param url The URL pointing to the password store entry.
|
||||
* @return True if the operation was successful, false otherwise.
|
||||
* @return True if the job was start successfully, false otherwise.
|
||||
*/
|
||||
Q_INVOKABLE bool show(QUrl url);
|
||||
|
||||
/**
|
||||
* @brief Launch the job to delete the password store.
|
||||
* @return True if if the job was start successfully, false otherwise.
|
||||
*/
|
||||
Q_INVOKABLE bool deletePasswordStore();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user