1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-01-26 00:26:40 +00:00
UTPass/plugins/Pass/pass.cpp

75 lines
1.7 KiB
C++
Raw Normal View History

2019-09-20 21:29:39 +02:00
#include <QUrl>
#include <QtCore/QStandardPaths>
#include <QtCore/QDir>
#include "pass.h"
#include "git.h"
2019-09-20 21:29:39 +02:00
#include "gpg.h"
#include "passkeymodel.h"
Pass::Pass(): m_password_store (QStandardPaths::writableLocation(
QStandardPaths::AppDataLocation).append("/.password-store"))
{}
void Pass::init(QObject *window)
{
if (!window) {
qFatal("window is invalid. Abording.");
}
2019-09-20 21:29:39 +02:00
Gpg::instance()->setWindow(window);
QDir dir(m_password_store);
if (!dir.exists())
dir.mkpath(".");
qInfo() << "Password Store is :" << m_password_store;
2019-09-20 21:29:39 +02:00
}
void Pass::decrypt(QUrl url)
{
qInfo() << "Decrypting";
2019-09-20 21:29:39 +02:00
auto decrypt_ret = Gpg::instance()->decryptFromFile(url.toLocalFile());
if (decrypt_ret.first) {
qInfo() << "Decrypt Failed";
2019-09-20 21:29:39 +02:00
emit decryptFailed();
} else if (decrypt_ret.second.isNull()) {
qInfo() << "Decrypt Canceled";
2019-09-20 21:29:39 +02:00
emit decryptCanceled();
} else {
qInfo() << "Decrypt OK";
2019-09-20 21:29:39 +02:00
emit decrypted(decrypt_ret.second);
}
}
bool Pass::gpgDeleteKeyId(QString id)
{
qInfo() << "Deleting Key id " << id;
2019-09-20 21:29:39 +02:00
return !Gpg::instance()->deleteKeyId(id);
}
bool Pass::gpgImportKeyFromFile(QUrl url)
{
qInfo() << "Importing Key from " << url;
2019-09-20 21:29:39 +02:00
return !Gpg::instance()->importKeysFromFile(url.toLocalFile());
}
QVariant Pass::gpgGetAllKeysModel()
{
qInfo() << "Getting all key form gpg ";
2019-09-20 21:29:39 +02:00
return QVariant::fromValue(PassKeyModel::keysToPassKeyQObjectList(
Gpg::instance()->getAllKeys().second));
}
QString Pass::getPasswordStore()
{
return m_password_store;
}
bool Pass::gitClone(QString url)
{
qInfo() << "Cloning . password_store from " << url;
return Git::instance()->clone(url);
}