1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-01-24 07:36:39 +00:00

Harmonize naming

This commit is contained in:
Quentin Rouland 2025-01-14 08:15:03 +01:00
parent 8ec593becc
commit 0e5df76787
12 changed files with 45 additions and 47 deletions

View File

@ -9,7 +9,7 @@
#include "utils.h" #include "utils.h"
QDir Git::clone_setup() QDir Git::cloneSetup()
{ {
QDir tmp_dir(QStandardPaths::writableLocation( QStandardPaths::CacheLocation).append("/clone")); QDir tmp_dir(QStandardPaths::writableLocation( QStandardPaths::CacheLocation).append("/clone"));
@ -20,12 +20,12 @@ QDir Git::clone_setup()
} }
bool Git::clone_tear_down(QDir tmp_dir) bool Git::cloneTearDown(QDir tmp_dir)
{ {
return tmp_dir.removeRecursively(); return tmp_dir.removeRecursively();
} }
bool Git::move_to_destination(QString path, QDir tmp_dir) bool Git::moveToDestination(QString path, QDir tmp_dir)
{ {
qDebug() << "Removing password_store " << path; qDebug() << "Removing password_store " << path;
QDir destination_dir(path); QDir destination_dir(path);
@ -37,42 +37,40 @@ bool Git::move_to_destination(QString path, QDir tmp_dir)
return dir.rename(tmp_dir.absolutePath(), destination_dir.absolutePath()); // TODO Better error handling return dir.rename(tmp_dir.absolutePath(), destination_dir.absolutePath()); // TODO Better error handling
} }
bool Git::clone(QString url, QString path, mode_type mode) //, GitPlugin::RepoType type, QString pass) bool Git::clone(QString url, QString path, mode_type mode) //, GitPlugin::RepoType type, QString pass)
{ {
auto v = overload { auto v = overload {
[](const Unset & x) { return "Unset"; }, [](const Unset & x) { return "Unset"; },
[](const HTTP & x) { return "Unset"; }, [](const HTTP & x) { return "HTTP"; },
[](const HTTPAuth & x) { return "HTTPAuth"; }, [](const HTTPAuth & x) { return "HTTPAuth"; },
[](const SSHAuth & x) { return "SSHAuth"; }, [](const SSHAuth & x) { return "SSHAuth"; },
[](const SSHKey & x) { return "SSHKey"; }, [](const SSHKey & x) { return "SSHKey"; },
}; };
qInfo() << "Cloning " << url << " to destination " << path << " using " << std::visit(v, mode); qInfo() << "Cloning " << url << " to destination " << path << " using " << std::visit(v, mode);
LibGit::instance()->set_mode(mode); LibGit::instance()->setMode(mode);
auto tmp_dir = this->clone_setup(); auto tmp_dir = this->cloneSetup();
qDebug() << "Cloning " << url << " to tmp dir " << tmp_dir.absolutePath(); qDebug() << "Cloning " << url << " to tmp dir " << tmp_dir.absolutePath();
auto ret = LibGit::instance()->clone(url, tmp_dir.absolutePath()); // TODO Better error handling auto ret = LibGit::instance()->clone(url, tmp_dir.absolutePath()); // TODO Better error handling
if (ret) { if (ret) {
this->move_to_destination(path, tmp_dir); this->moveToDestination(path, tmp_dir);
} }
this->clone_tear_down(tmp_dir); this->cloneTearDown(tmp_dir);
LibGit::instance()->set_mode(Unset()); LibGit::instance()->setMode(Unset());
return ret ; return ret ;
} }
bool Git::clone_http(QString url, QString path) //, GitPlugin::RepoType type, QString pass) bool Git::cloneHttp(QString url, QString path)
{ {
HTTP mode = {}; HTTP mode = {};
return this->clone(url, path, mode); return this->clone(url, path, mode);
} }
bool Git::clone_http_pass(QString url, QString path, QString pass) bool Git::cloneHttpPass(QString url, QString path, QString pass)
{ {
HTTPAuth mode = { pass }; HTTPAuth mode = { pass };
return this->clone(url, path, mode); return this->clone(url, path, mode);

View File

@ -7,14 +7,17 @@
#include "libgit.h" #include "libgit.h"
/**
* @brief The Git class is class that provide Git functionnly to clone and update a repo.
*/
class Git : public QObject class Git : public QObject
{ {
Q_OBJECT Q_OBJECT
private: private:
QDir clone_setup(); QDir cloneSetup();
bool move_to_destination(QString path, QDir tmp_dir); bool moveToDestination(QString path, QDir tmp_dir);
bool clone_tear_down(QDir tmp_dir); bool cloneTearDown(QDir tmp_dir);
bool clone(QString url, QString path, mode_type mode); bool clone(QString url, QString path, mode_type mode);
@ -22,8 +25,8 @@ public:
Git() = default; Git() = default;
~Git() override = default; ~Git() override = default;
Q_INVOKABLE bool clone_http(QString url, QString path); Q_INVOKABLE bool cloneHttp(QString url, QString path);
Q_INVOKABLE bool clone_http_pass(QString url, QString path, QString pass); Q_INVOKABLE bool cloneHttpPass(QString url, QString path, QString pass);
// Q_INVOKABLE bool clone_ssh_pass(QString url, QString path, QString pass); // Q_INVOKABLE bool clone_ssh_pass(QString url, QString path, QString pass);
// Q_INVOKABLE bool clone_ssh_key(QString url, QString path, QString pub_key, QString priv_key, QString passphrase); // Q_INVOKABLE bool clone_ssh_key(QString url, QString path, QString pub_key, QString priv_key, QString passphrase);
// Q_INVOKABLE bool update(QUrl url, QString path); // Q_INVOKABLE bool update(QUrl url, QString path);

View File

@ -21,12 +21,12 @@ LibGit::~LibGit()
git_libgit2_shutdown(); git_libgit2_shutdown();
} }
void LibGit::set_mode(mode_type type) void LibGit::setMode(mode_type type)
{ {
this->mode = type; this->mode = type;
} }
int LibGit::credentials_cb(git_cred **out, const char *url, const char *username_from_url, int LibGit::credentialsCB(git_cred **out, const char *url, const char *username_from_url,
unsigned int allowed_types, void *payload) unsigned int allowed_types, void *payload)
{ {
// TODO : More precise Error Handling for UI // TODO : More precise Error Handling for UI
@ -73,7 +73,7 @@ bool LibGit::clone(QString url, QString path)
git_repository *repo = NULL; git_repository *repo = NULL;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT; git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
opts.fetch_opts.callbacks.credentials = *credentials_cb; opts.fetch_opts.callbacks.credentials = *credentialsCB;
int ret = git_clone(&repo, url.toLocal8Bit().data(), path.toLocal8Bit().data(), &opts); int ret = git_clone(&repo, url.toLocal8Bit().data(), path.toLocal8Bit().data(), &opts);
if (ret != 0) { if (ret != 0) {

View File

@ -26,7 +26,7 @@ private:
mode_type mode; mode_type mode;
static int credentials_cb(git_cred **out, const char *url, const char *username_from_url, static int credentialsCB(git_cred **out, const char *url, const char *username_from_url,
unsigned int allowed_types, void *payload); unsigned int allowed_types, void *payload);
public: public:
@ -40,7 +40,7 @@ public:
void operator=(LibGit const &) = delete; void operator=(LibGit const &) = delete;
bool clone(QString url, QString path); bool clone(QString url, QString path);
void set_mode(mode_type type); void setMode(mode_type type);
}; };
#endif #endif

View File

@ -137,6 +137,7 @@ QPair<Error, QString> Gpg::decrypt(QByteArray cipherText)
auto decResult = job->exec(cipherText, plain_text); auto decResult = job->exec(cipherText, plain_text);
delete job; delete job;
delete provider;
if (decResult.error()) { if (decResult.error()) {
qWarning() << "something gone wrong on decrypt"; qWarning() << "something gone wrong on decrypt";
@ -245,9 +246,6 @@ Error Gpg::importKeysFromFile(QString path)
auto job = openpgp()->importJob(); auto job = openpgp()->importJob();
auto ctx = ImportJob::context(job); auto ctx = ImportJob::context(job);
auto provider = new UTPassphraseProvider;
ctx->setPassphraseProvider(provider);
ctx->setPinentryMode(Context::PinentryLoopback);
auto result = job->exec(file.readAll()); auto result = job->exec(file.readAll());
qDebug() << "numImported" << result.numImported(); qDebug() << "numImported" << result.numImported();
@ -258,7 +256,6 @@ Error Gpg::importKeysFromFile(QString path)
file.close(); file.close();
delete job; delete job;
delete provider;
if (result.error()) { if (result.error()) {
qWarning() << "Import go wrong"; qWarning() << "Import go wrong";

View File

@ -12,7 +12,7 @@ Pass::Pass(): m_password_store (QStandardPaths::writableLocation(
QStandardPaths::AppDataLocation).append("/.password-store")) QStandardPaths::AppDataLocation).append("/.password-store"))
{} {}
void Pass::init(QObject *window) void Pass::initialize(QObject *window)
{ {
if (!window) { if (!window) {
qFatal("window is invalid. Abording."); qFatal("window is invalid. Abording.");
@ -27,7 +27,7 @@ void Pass::init(QObject *window)
qInfo() << "Password Store is :" << m_password_store; qInfo() << "Password Store is :" << m_password_store;
} }
void Pass::decrypt(QUrl url) void Pass::show(QUrl url)
{ {
qInfo() << "Decrypting"; qInfo() << "Decrypting";
auto decrypt_ret = Gpg::instance()->decryptFromFile(url.toLocalFile()); auto decrypt_ret = Gpg::instance()->decryptFromFile(url.toLocalFile());
@ -43,19 +43,19 @@ void Pass::decrypt(QUrl url)
} }
} }
bool Pass::gpgDeleteKeyId(QString id) bool Pass::deleteGPGKey(QString id)
{ {
qInfo() << "Deleting Key id " << id; qInfo() << "Deleting Key id " << id;
return !Gpg::instance()->deleteKeyId(id); return !Gpg::instance()->deleteKeyId(id);
} }
bool Pass::gpgImportKeyFromFile(QUrl url) bool Pass::importGPGKey(QUrl url)
{ {
qInfo() << "Importing Key from " << url; qInfo() << "Importing Key from " << url;
return !Gpg::instance()->importKeysFromFile(url.toLocalFile()); return !Gpg::instance()->importKeysFromFile(url.toLocalFile());
} }
QVariant Pass::gpgGetAllKeysModel() QVariant Pass::getAllGPGKeys()
{ {
qInfo() << "Getting all key form gpg "; qInfo() << "Getting all key form gpg ";
return QVariant::fromValue(PassKeyModel::keysToPassKeyQObjectList( return QVariant::fromValue(PassKeyModel::keysToPassKeyQObjectList(

View File

@ -28,11 +28,11 @@ public:
return m_password_store; return m_password_store;
} }
Q_INVOKABLE void init(QObject *window); Q_INVOKABLE void initialize(QObject *window);
Q_INVOKABLE void decrypt(QUrl url); Q_INVOKABLE void show(QUrl url);
Q_INVOKABLE bool gpgDeleteKeyId(QString id); Q_INVOKABLE bool deleteGPGKey(QString id);
Q_INVOKABLE bool gpgImportKeyFromFile(QUrl url); Q_INVOKABLE bool importGPGKey(QUrl url);
Q_INVOKABLE QVariant gpgGetAllKeysModel(); Q_INVOKABLE QVariant getAllGPGKeys();
}; };
#endif #endif

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: utpass.qrouland\n" "Project-Id-Version: utpass.qrouland\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-13 20:49+0100\n" "POT-Creation-Date: 2025-01-14 09:52+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -47,7 +47,7 @@ msgid "Ok"
msgstr "" msgstr ""
#: ../qml/dialogs/PassphraseDialog.qml:41 #: ../qml/dialogs/PassphraseDialog.qml:41
#: ../qml/dialogs/SimpleValidationDialog.qml:33 #: ../qml/dialogs/SimpleValidationDialog.qml:34
msgid "Cancel" msgid "Cancel"
msgstr "" msgstr ""

View File

@ -13,7 +13,7 @@ MainView {
signal responsePassphraseDialog(bool canceled, string passphrase) signal responsePassphraseDialog(bool canceled, string passphrase)
function initPass(rootView) { function initPass(rootView) {
Pass.init(rootView); Pass.initialize(rootView);
pageStack.push(Qt.resolvedUrl("pages/PasswordList.qml")); pageStack.push(Qt.resolvedUrl("pages/PasswordList.qml"));
} }
@ -21,10 +21,10 @@ MainView {
//TODO use parameters to impove passphrase dialog //TODO use parameters to impove passphrase dialog
var passphraseDialog = PopupUtils.open(Qt.resolvedUrl("dialogs/PassphraseDialog.qml")); var passphraseDialog = PopupUtils.open(Qt.resolvedUrl("dialogs/PassphraseDialog.qml"));
passphraseDialog.activateFocus(); passphraseDialog.activateFocus();
var validated = function validated(passphrase) { var validated = function (passphrase) {
responsePassphraseDialog(false, passphrase); responsePassphraseDialog(false, passphrase);
}; };
var canceled = function canceled() { var canceled = function () {
responsePassphraseDialog(true, ""); responsePassphraseDialog(true, "");
}; };
passphraseDialog.validated.connect(validated); passphraseDialog.validated.connect(validated);

View File

@ -51,7 +51,7 @@ Component {
Pass.onDecryptFailed.connect(function() { Pass.onDecryptFailed.connect(function() {
PopupUtils.open(passwordPageDecryptError); PopupUtils.open(passwordPageDecryptError);
}); });
Pass.decrypt(folderModel.folder + "/" + fileName); Pass.show(folderModel.folder + "/" + fileName);
} }
} }
} }

View File

@ -28,7 +28,7 @@ Page {
if (importKeyFilePage.activeTransfer.state === ContentTransfer.Charged) { if (importKeyFilePage.activeTransfer.state === ContentTransfer.Charged) {
console.log("Charged"); console.log("Charged");
console.log(importKeyFilePage.activeTransfer.items[0].url); console.log(importKeyFilePage.activeTransfer.items[0].url);
var status = Pass.gpgImportKeyFromFile(importKeyFilePage.activeTransfer.items[0].url); var status = Pass.importGPGKey(importKeyFilePage.activeTransfer.items[0].url);
Utils.rmFile(importKeyFilePage.activeTransfer.items[0].url); Utils.rmFile(importKeyFilePage.activeTransfer.items[0].url);
if (status) if (status)
PopupUtils.open(dialogImportKeyPageSucess); PopupUtils.open(dialogImportKeyPageSucess);

View File

@ -18,7 +18,7 @@ Page {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
anchors.left: parent.left anchors.left: parent.left
model: Pass.gpgGetAllKeysModel() model: Pass.getAllGPGKeys()
delegate: Grid { delegate: Grid {
columns: 1 columns: 1
@ -77,7 +77,7 @@ Page {
continueText: i18n.tr("Yes") continueText: i18n.tr("Yes")
continueColor: theme.palette.normal.negative continueColor: theme.palette.normal.negative
onValidated: { onValidated: {
var status = Pass.gpgDeleteKeyId(infoKeysPage.currentKey); var status = Pass.deleteGPGKey(infoKeysPage.currentKey);
if (status) if (status)
PopupUtils.open(infoKeysPageDeleteSuccess); PopupUtils.open(infoKeysPageDeleteSuccess);
else else
@ -102,7 +102,7 @@ Page {
SuccessDialog { SuccessDialog {
textSuccess: i18n.tr("Key successfully deleted !") textSuccess: i18n.tr("Key successfully deleted !")
onDialogClosed: { onDialogClosed: {
infoKeysListView.model = Pass.gpgGetAllKeysModel(); infoKeysListView.model = Pass.getAllGPGKeys();
} }
} }