1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-07-04 03:02:28 +00:00

Add search password feature (equivalent to pass find)

This commit is contained in:
2025-02-05 11:02:59 +01:00
parent e47d50072a
commit 2409f33f59
13 changed files with 250 additions and 89 deletions

View File

@ -1,7 +1,8 @@
#include <QUrl>
#include <QtCore/QStandardPaths>
#include <QtCore/QDir>
#include <QDirIterator>
#include <QtConcurrent/QtConcurrent>
#include "jobs/decryptjob.h"
#include "jobs/deletekeyjob.h"
#include "jobs/getkeysjob.h"
@ -61,8 +62,35 @@ void Pass::initPasswordStore()
qInfo() << "[Pass] Password Store is :" << m_password_store;
}
void Pass::lsJob()
{
QDirIterator it(this->m_password_store, QStringList() << "*.gpg", QDir::Files, QDirIterator::Subdirectories);
QList<QString> ret;
while (it.hasNext()) {
QFile f(it.next());
QString fname = f.fileName();
fname.remove(0, this->m_password_store.length() + 1); // remove system path
ret.append(fname);
}
qInfo() << "[Pass] ls Succeed";
emit lsSucceed(ret);
this->m_sem->release(1);
}
bool Pass::ls()
{
qInfo() << "[Pass] ls";
if (!this->m_sem->tryAcquire(1, 500)) {
qInfo() << "[Pass] A command is already running";
return false;
}
QtConcurrent::run(this, &Pass::lsJob );
return true;
}
bool Pass::show(QUrl url)
{
qInfo() << "[Pass] Show";
if (!this->m_sem->tryAcquire(1, 500)) {
qInfo() << "[Pass] A command is already running";
return false;
@ -111,7 +139,7 @@ void Pass::slotDeletePasswordStoreResult(bool err)
{
this->initPasswordStore(); // reinit an empty password-store
if (err) {
qInfo() << "[Pass] delete Password Store Failed";
qInfo() << "[Pass] Delete Password Store Failed";
emit deletePasswordStoreFailed("failed to delete password store");
} else {
qInfo() << "[Pass] Delete Password Store Succeed";

View File

@ -118,6 +118,9 @@ signals:
*/
void showSucceed(QString name, QString text);
void lsSucceed(QList<QString>);
/**
* @brief Emitted when showing a password fails.
* @param message The error message describing the failure.
@ -160,6 +163,8 @@ private:
*/
void initPasswordStore();
void lsJob();
public:
/**
* @brief Constructs the Pass object.
@ -229,6 +234,12 @@ public:
// Password store-related methods
/**
* @brief Get the list of password.
* @return The list of password in the password store.
*/
Q_INVOKABLE bool ls();
/**
* @brief Launch the job to shows the password associated with the specified URL.
* @param url The URL pointing to the password store entry.