mirror of
https://github.com/QRouland/UTPass.git
synced 2024-12-22 01:42:39 +00:00
Code style
This commit is contained in:
parent
3cbd834787
commit
aa4018c680
@ -62,19 +62,19 @@ file(GLOB_RECURSE I18N_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/po qml/*.q
|
||||
list(APPEND I18N_SRC_FILES ${DESKTOP_FILE_NAME}.in.h)
|
||||
|
||||
find_program(INTLTOOL_MERGE intltool-merge)
|
||||
if(NOT INTLTOOL_MERGE)
|
||||
if (NOT INTLTOOL_MERGE)
|
||||
message(FATAL_ERROR "Could not find intltool-merge, please install the intltool package")
|
||||
endif()
|
||||
endif ()
|
||||
find_program(INTLTOOL_EXTRACT intltool-extract)
|
||||
if(NOT INTLTOOL_EXTRACT)
|
||||
if (NOT INTLTOOL_EXTRACT)
|
||||
message(FATAL_ERROR "Could not find intltool-extract, please install the intltool package")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
add_custom_target(${DESKTOP_FILE_NAME} ALL
|
||||
COMMENT "Merging translations into ${DESKTOP_FILE_NAME}..."
|
||||
COMMAND LC_ALL=C ${INTLTOOL_MERGE} -d -u ${CMAKE_SOURCE_DIR}/po ${CMAKE_SOURCE_DIR}/${DESKTOP_FILE_NAME}.in ${DESKTOP_FILE_NAME}
|
||||
COMMAND sed -i 's/${PROJECT_NAME}-//g' ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE_NAME}
|
||||
)
|
||||
COMMENT "Merging translations into ${DESKTOP_FILE_NAME}..."
|
||||
COMMAND LC_ALL=C ${INTLTOOL_MERGE} -d -u ${CMAKE_SOURCE_DIR}/po ${CMAKE_SOURCE_DIR}/${DESKTOP_FILE_NAME}.in ${DESKTOP_FILE_NAME}
|
||||
COMMAND sed -i 's/${PROJECT_NAME}-//g' ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE_NAME}
|
||||
)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE_NAME} DESTINATION ${DATA_DIR})
|
||||
|
||||
@ -88,13 +88,13 @@ add_dependencies(${PROJECT_NAME} Gnupg)
|
||||
# We don't need to add plugin sources here as they get exposed
|
||||
# via the library target.
|
||||
file(GLOB_RECURSE PROJECT_SRC_FILES
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
qml/*.qml
|
||||
qml/*.js
|
||||
*.json
|
||||
*.json.in
|
||||
*.apparmor
|
||||
*.desktop.in
|
||||
)
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
qml/*.qml
|
||||
qml/*.js
|
||||
*.json
|
||||
*.json.in
|
||||
*.apparmor
|
||||
*.desktop.in
|
||||
)
|
||||
|
||||
add_custom_target(${PROJECT_NAME}_FILES ALL SOURCES ${PROJECT_SRC_FILES} )
|
||||
add_custom_target(${PROJECT_NAME}_FILES ALL SOURCES ${PROJECT_SRC_FILES})
|
@ -2,7 +2,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(PLUGIN "Gpg")
|
||||
|
||||
set(
|
||||
SRC
|
||||
SRC
|
||||
plugin.cpp
|
||||
gpg.cpp
|
||||
)
|
||||
@ -37,9 +37,9 @@ set_property(TARGET QGpgme PROPERTY IMPORTED_LOCATION "${EXTERNAL_LIBS}/lib/libq
|
||||
target_link_libraries(${PLUGIN} QGpgme Gpgmepp Gpgme GpgAssuan GpgError)
|
||||
|
||||
execute_process(
|
||||
COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
|
||||
OUTPUT_VARIABLE ARCH_TRIPLET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
|
||||
OUTPUT_VARIABLE ARCH_TRIPLET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}")
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QtCore/QDirIterator>
|
||||
#include <QtCore/QStandardPaths>
|
||||
|
||||
#include "gpg.h"
|
||||
@ -19,148 +18,147 @@ using namespace GpgME;
|
||||
using namespace QGpgME;
|
||||
|
||||
Gpg::Gpg() {
|
||||
auto error = initializeLibrary(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
qFatal("GpgME init fail");
|
||||
}
|
||||
auto error = initializeLibrary(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
qFatal("GpgME init fail");
|
||||
}
|
||||
|
||||
QString gnuhome = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/gpghome");
|
||||
QDir dir(gnuhome);
|
||||
if (!dir.exists()) dir.mkpath(".");
|
||||
qputenv("GNUPGHOME", gnuhome.toStdString().c_str());
|
||||
qDebug() << "GNUPGHOME is :" << qgetenv("GNUPGHOME");
|
||||
QString gnuhome = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/gpghome");
|
||||
QDir dir(gnuhome);
|
||||
if (!dir.exists())
|
||||
dir.mkpath(".");
|
||||
qputenv("GNUPGHOME", gnuhome.toStdString().c_str());
|
||||
qDebug() << "GNUPGHOME is :" << qgetenv("GNUPGHOME");
|
||||
|
||||
error = checkEngine(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
qFatal("Engine check Fail");
|
||||
error = checkEngine(OpenPGP);
|
||||
if (error) {
|
||||
qDebug() << "Code Error : " << error.code();
|
||||
qDebug() << "Error str : " << error.asString();
|
||||
qFatal("Engine check Fail");
|
||||
|
||||
}
|
||||
qDebug() << "GpgME Engine Version :" << engineInfo(OpenPGP).version();
|
||||
}
|
||||
qDebug() << "GpgME Engine Version :" << engineInfo(OpenPGP).version();
|
||||
}
|
||||
|
||||
void Gpg::list_dir() {
|
||||
qDebug() << "hello world!";
|
||||
qDebug() << "hello world!";
|
||||
}
|
||||
|
||||
QString Gpg::decrypt(const QByteArray cipherText) {
|
||||
/*auto decJob = openpgp()->decryptJob();
|
||||
auto ctx = DecryptJob::context(decJob);*/
|
||||
/*auto decJob = openpgp()->decryptJob();
|
||||
auto ctx = DecryptJob::context(decJob);*/
|
||||
|
||||
/* TODO
|
||||
* TestPassphraseProvider provider;
|
||||
ctx->setPassphraseProvider(&provider);
|
||||
ctx->setPinentryMode(Context::PinentryLoopback);*/
|
||||
/* TODO
|
||||
* TestPassphraseProvider provider;
|
||||
ctx->setPassphraseProvider(&provider);
|
||||
ctx->setPinentryMode(Context::PinentryLoopback);*/
|
||||
|
||||
/*QByteArray plainText;
|
||||
decJob->exec(cipherText, plainText);
|
||||
/*QByteArray plainText;
|
||||
decJob->exec(cipherText, plainText);
|
||||
|
||||
return QString::fromUtf8(plainText);*/
|
||||
return QString::fromUtf8(plainText);*/
|
||||
}
|
||||
|
||||
QString Gpg::decrypt_file(const QString path) {
|
||||
/*QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qErrnoWarning("Can't open the File");
|
||||
return nullptr;
|
||||
}
|
||||
QByteArray plainText = file.readAll();
|
||||
return this->decrypt(plainText);*/
|
||||
/*QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qErrnoWarning("Can't open the File");
|
||||
return nullptr;
|
||||
}
|
||||
QByteArray plainText = file.readAll();
|
||||
return this->decrypt(plainText);*/
|
||||
}
|
||||
|
||||
QByteArray Gpg::encrypt(const QString str) {
|
||||
/*auto listjob = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"), false, keys);
|
||||
/*auto listjob = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"), false, keys);
|
||||
|
||||
auto job = openpgp()
|
||||
->encryptJob(
|
||||
true, //ASCII Armor
|
||||
true //Textmode
|
||||
);
|
||||
QByteArray cipherText;
|
||||
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
|
||||
return cipherText;*/
|
||||
auto job = openpgp()
|
||||
->encryptJob(
|
||||
true, //ASCII Armor
|
||||
true //Textmode
|
||||
);
|
||||
QByteArray cipherText;
|
||||
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
|
||||
return cipherText;*/
|
||||
}
|
||||
|
||||
bool Gpg::encrypt_file(const QString str, const QString path) {
|
||||
/*QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
qErrnoWarning("Can't open the File");
|
||||
return false;
|
||||
}
|
||||
file.write(Pass::encrypt(str));
|
||||
return true;*/
|
||||
/*QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
qErrnoWarning("Can't open the File");
|
||||
return false;
|
||||
}
|
||||
file.write(Pass::encrypt(str));
|
||||
return true;*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString Gpg::get_key_id(QString uid) {
|
||||
qDebug() << "Getting the key id " << uid;
|
||||
auto *job = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto result = job->exec(QStringList() << uid, false, keys);
|
||||
delete job;
|
||||
qDebug() << "Getting the key id " << uid;
|
||||
auto *job = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto result = job->exec(QStringList() << uid, false, keys);
|
||||
delete job;
|
||||
|
||||
if (keys.empty()) {
|
||||
qDebug() << "No key found for" << uid;
|
||||
return nullptr;
|
||||
}
|
||||
const QString kId = QLatin1String(keys.front().keyID());
|
||||
qDebug() << "Id key for " << uid << "is : " << kId;
|
||||
return kId;
|
||||
if (keys.empty()) {
|
||||
qDebug() << "No key found for" << uid;
|
||||
return nullptr;
|
||||
}
|
||||
const QString kId = QLatin1String(keys.front().keyID());
|
||||
qDebug() << "Id key for " << uid << "is : " << kId;
|
||||
return kId;
|
||||
}
|
||||
|
||||
QStringList Gpg::get_all_keys_id() {
|
||||
qDebug() << "Show all available key";
|
||||
auto job = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto result = job->exec(QStringList(""), false, keys);
|
||||
delete job;
|
||||
qDebug() << "Show all available key";
|
||||
auto job = openpgp()->keyListJob(false, false, false);
|
||||
std::vector<Key> keys;
|
||||
auto result = job->exec(QStringList(""), false, keys);
|
||||
delete job;
|
||||
|
||||
if (keys.empty()) {
|
||||
qDebug() << "No key found" ;
|
||||
return QStringList();
|
||||
}
|
||||
if (keys.empty()) {
|
||||
qDebug() << "No key found";
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
auto r = QStringList();
|
||||
for(const auto &key: keys) {
|
||||
r.append(QLatin1String(key.keyID()));
|
||||
qDebug() << "Key" << QLatin1String(key.keyID());
|
||||
}
|
||||
return r;
|
||||
auto r = QStringList();
|
||||
for (const auto &key: keys) {
|
||||
r.append(QLatin1String(key.keyID()));
|
||||
qDebug() << "Key" << QLatin1String(key.keyID());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
bool Gpg::import_key(QString path) {
|
||||
qDebug() << "Importing the key file" << path;
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Can't open the File";
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Importing the key file" << path;
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "Can't open the File";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto job = openpgp()->importJob();
|
||||
auto result = job->exec(file.readAll());
|
||||
auto job = openpgp()->importJob();
|
||||
auto result = job->exec(file.readAll());
|
||||
|
||||
delete job;
|
||||
file.close();
|
||||
delete job;
|
||||
file.close();
|
||||
|
||||
if(result.error()) {
|
||||
qWarning() << "Import go wrong";
|
||||
return false;
|
||||
}
|
||||
if (result.error()) {
|
||||
qWarning() << "Import go wrong";
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Key imported" << result.numImported();
|
||||
qDebug() << "Key not imported" << result.notImported();
|
||||
qDebug() << "Key unchanged" << result.numUnchanged();
|
||||
qDebug() << "Result null" << result.isNull();
|
||||
qDebug() << "newUserIDs" << result.newUserIDs();
|
||||
qDebug() << "Key imported" << result.numImported();
|
||||
qDebug() << "Key not imported" << result.notImported();
|
||||
qDebug() << "Key unchanged" << result.numUnchanged();
|
||||
qDebug() << "Result null" << result.isNull();
|
||||
qDebug() << "newUserIDs" << result.newUserIDs();
|
||||
|
||||
for(const auto &key: result.imports())
|
||||
qDebug() << "Key" << key.fingerprint();
|
||||
for (const auto &key: result.imports())
|
||||
qDebug() << "Key" << key.fingerprint();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
@ -3,21 +3,21 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Gpg: public QObject {
|
||||
Q_OBJECT
|
||||
class Gpg : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Gpg();
|
||||
~Gpg() = default;
|
||||
public:
|
||||
Gpg();
|
||||
~Gpg() = default;
|
||||
|
||||
Q_INVOKABLE void list_dir();
|
||||
Q_INVOKABLE QString get_key_id(QString uid);
|
||||
Q_INVOKABLE QStringList get_all_keys_id();
|
||||
Q_INVOKABLE bool import_key(QString path);
|
||||
Q_INVOKABLE QString decrypt(QByteArray plainText);
|
||||
Q_INVOKABLE QString decrypt_file(QString path);
|
||||
Q_INVOKABLE QByteArray encrypt(QString str);
|
||||
Q_INVOKABLE bool encrypt_file(QString str, QString path);
|
||||
Q_INVOKABLE void list_dir();
|
||||
Q_INVOKABLE QString get_key_id(QString uid);
|
||||
Q_INVOKABLE QStringList get_all_keys_id();
|
||||
Q_INVOKABLE bool import_key(QString path);
|
||||
Q_INVOKABLE QString decrypt(QByteArray plainText);
|
||||
Q_INVOKABLE QString decrypt_file(QString path);
|
||||
Q_INVOKABLE QByteArray encrypt(QString str);
|
||||
Q_INVOKABLE bool encrypt_file(QString str, QString path);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,10 +1,9 @@
|
||||
#include <QtQml>
|
||||
#include <QtQml/QQmlContext>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "gpg.h"
|
||||
|
||||
void FileSystemPlugin::registerTypes(const char *uri) {
|
||||
//@uri Pass
|
||||
qmlRegisterSingletonType<Gpg>(uri, 1, 0, "Gpg", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Gpg; });
|
||||
//@uri Pass
|
||||
qmlRegisterSingletonType<Gpg>(uri, 1, 0, "Gpg", [](QQmlEngine *, QJSEngine *) -> QObject * { return new Gpg; });
|
||||
}
|
||||
|
@ -4,11 +4,12 @@
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class FileSystemPlugin : public QQmlExtensionPlugin {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID
|
||||
"org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char *uri);
|
||||
public:
|
||||
void registerTypes(const char *uri);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2,9 +2,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(PLUGIN "Pass")
|
||||
|
||||
set(
|
||||
SRC
|
||||
plugin.cpp
|
||||
pass.cpp
|
||||
SRC
|
||||
plugin.cpp
|
||||
pass.cpp
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
@ -15,9 +15,9 @@ qt5_use_modules(${PLUGIN} Qml Quick DBus)
|
||||
|
||||
|
||||
execute_process(
|
||||
COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
|
||||
OUTPUT_VARIABLE ARCH_TRIPLET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
|
||||
OUTPUT_VARIABLE ARCH_TRIPLET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}")
|
||||
|
@ -3,13 +3,12 @@
|
||||
|
||||
#include "pass.h"
|
||||
|
||||
|
||||
Pass::Pass() {
|
||||
|
||||
}
|
||||
|
||||
void Pass::speak() {
|
||||
qDebug() << "Starting app from main.cpp";
|
||||
qDebug() << "Starting app from main.cpp";
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,15 +3,15 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Pass: public QObject {
|
||||
Q_OBJECT
|
||||
QString gpgHome;
|
||||
class Pass : public QObject {
|
||||
Q_OBJECT
|
||||
QString gpgHome;
|
||||
|
||||
public:
|
||||
Pass();
|
||||
~Pass() override = default;
|
||||
public:
|
||||
Pass();
|
||||
~Pass() override = default;
|
||||
|
||||
Q_INVOKABLE void speak();
|
||||
Q_INVOKABLE void speak();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,10 +1,9 @@
|
||||
#include <QtQml>
|
||||
#include <QtQml/QQmlContext>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "pass.h"
|
||||
|
||||
void PassPlugin::registerTypes(const char *uri) {
|
||||
//@uri Pass
|
||||
qmlRegisterSingletonType<Pass>(uri, 1, 0, "Pass", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Pass; });
|
||||
//@uri Pass
|
||||
qmlRegisterSingletonType<Pass>(uri, 1, 0, "Pass", [](QQmlEngine *, QJSEngine *) -> QObject * { return new Pass; });
|
||||
}
|
||||
|
@ -4,11 +4,12 @@
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class PassPlugin : public QQmlExtensionPlugin {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID
|
||||
"org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char *uri) override;
|
||||
public:
|
||||
void registerTypes(const char *uri) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: utpass.qrouland\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-03-20 22:15+0000\n"
|
||||
"POT-Creation-Date: 2019-03-20 22:31+0000\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"
|
||||
|
Loading…
Reference in New Issue
Block a user