Code style

This commit is contained in:
Quentin Rouland 2019-03-21 00:04:05 +01:00
parent 3cbd834787
commit aa4018c680
12 changed files with 166 additions and 169 deletions

View File

@ -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) list(APPEND I18N_SRC_FILES ${DESKTOP_FILE_NAME}.in.h)
find_program(INTLTOOL_MERGE intltool-merge) 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") message(FATAL_ERROR "Could not find intltool-merge, please install the intltool package")
endif() endif ()
find_program(INTLTOOL_EXTRACT intltool-extract) 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") message(FATAL_ERROR "Could not find intltool-extract, please install the intltool package")
endif() endif ()
add_custom_target(${DESKTOP_FILE_NAME} ALL add_custom_target(${DESKTOP_FILE_NAME} ALL
COMMENT "Merging translations into ${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 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} 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}) 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 # We don't need to add plugin sources here as they get exposed
# via the library target. # via the library target.
file(GLOB_RECURSE PROJECT_SRC_FILES file(GLOB_RECURSE PROJECT_SRC_FILES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
qml/*.qml qml/*.qml
qml/*.js qml/*.js
*.json *.json
*.json.in *.json.in
*.apparmor *.apparmor
*.desktop.in *.desktop.in
) )
add_custom_target(${PROJECT_NAME}_FILES ALL SOURCES ${PROJECT_SRC_FILES} ) add_custom_target(${PROJECT_NAME}_FILES ALL SOURCES ${PROJECT_SRC_FILES})

View File

@ -2,7 +2,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(PLUGIN "Gpg") set(PLUGIN "Gpg")
set( set(
SRC SRC
plugin.cpp plugin.cpp
gpg.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) target_link_libraries(${PLUGIN} QGpgme Gpgmepp Gpgme GpgAssuan GpgError)
execute_process( execute_process(
COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
OUTPUT_VARIABLE ARCH_TRIPLET OUTPUT_VARIABLE ARCH_TRIPLET
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
) )
set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}") set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}")

View File

@ -1,7 +1,6 @@
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QtCore/QDirIterator>
#include <QtCore/QStandardPaths> #include <QtCore/QStandardPaths>
#include "gpg.h" #include "gpg.h"
@ -19,148 +18,147 @@ using namespace GpgME;
using namespace QGpgME; using namespace QGpgME;
Gpg::Gpg() { Gpg::Gpg() {
auto error = initializeLibrary(OpenPGP); auto error = initializeLibrary(OpenPGP);
if (error) { if (error) {
qDebug() << "Code Error : " << error.code(); qDebug() << "Code Error : " << error.code();
qDebug() << "Error str : " << error.asString(); qDebug() << "Error str : " << error.asString();
qFatal("GpgME init fail"); qFatal("GpgME init fail");
} }
QString gnuhome = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/gpghome"); QString gnuhome = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/gpghome");
QDir dir(gnuhome); QDir dir(gnuhome);
if (!dir.exists()) dir.mkpath("."); if (!dir.exists())
qputenv("GNUPGHOME", gnuhome.toStdString().c_str()); dir.mkpath(".");
qDebug() << "GNUPGHOME is :" << qgetenv("GNUPGHOME"); qputenv("GNUPGHOME", gnuhome.toStdString().c_str());
qDebug() << "GNUPGHOME is :" << qgetenv("GNUPGHOME");
error = checkEngine(OpenPGP); error = checkEngine(OpenPGP);
if (error) { if (error) {
qDebug() << "Code Error : " << error.code(); qDebug() << "Code Error : " << error.code();
qDebug() << "Error str : " << error.asString(); qDebug() << "Error str : " << error.asString();
qFatal("Engine check Fail"); qFatal("Engine check Fail");
} }
qDebug() << "GpgME Engine Version :" << engineInfo(OpenPGP).version(); qDebug() << "GpgME Engine Version :" << engineInfo(OpenPGP).version();
} }
void Gpg::list_dir() { void Gpg::list_dir() {
qDebug() << "hello world!"; qDebug() << "hello world!";
} }
QString Gpg::decrypt(const QByteArray cipherText) { QString Gpg::decrypt(const QByteArray cipherText) {
/*auto decJob = openpgp()->decryptJob(); /*auto decJob = openpgp()->decryptJob();
auto ctx = DecryptJob::context(decJob);*/ auto ctx = DecryptJob::context(decJob);*/
/* TODO /* TODO
* TestPassphraseProvider provider; * TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider); ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback);*/ ctx->setPinentryMode(Context::PinentryLoopback);*/
/*QByteArray plainText; /*QByteArray plainText;
decJob->exec(cipherText, plainText); decJob->exec(cipherText, plainText);
return QString::fromUtf8(plainText);*/ return QString::fromUtf8(plainText);*/
} }
QString Gpg::decrypt_file(const QString path) { QString Gpg::decrypt_file(const QString path) {
/*QFile file(path); /*QFile file(path);
if (!file.open(QIODevice::ReadOnly)) { if (!file.open(QIODevice::ReadOnly)) {
qErrnoWarning("Can't open the File"); qErrnoWarning("Can't open the File");
return nullptr; return nullptr;
} }
QByteArray plainText = file.readAll(); QByteArray plainText = file.readAll();
return this->decrypt(plainText);*/ return this->decrypt(plainText);*/
} }
QByteArray Gpg::encrypt(const QString str) { QByteArray Gpg::encrypt(const QString str) {
/*auto listjob = openpgp()->keyListJob(false, false, false); /*auto listjob = openpgp()->keyListJob(false, false, false);
std::vector<Key> keys; std::vector<Key> keys;
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"), false, keys); auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"), false, keys);
auto job = openpgp() auto job = openpgp()
->encryptJob( ->encryptJob(
true, //ASCII Armor true, //ASCII Armor
true //Textmode true //Textmode
); );
QByteArray cipherText; QByteArray cipherText;
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText); auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
return cipherText;*/ return cipherText;*/
} }
bool Gpg::encrypt_file(const QString str, const QString path) { bool Gpg::encrypt_file(const QString str, const QString path) {
/*QFile file(path); /*QFile file(path);
if (!file.open(QIODevice::WriteOnly)) { if (!file.open(QIODevice::WriteOnly)) {
qErrnoWarning("Can't open the File"); qErrnoWarning("Can't open the File");
return false; return false;
} }
file.write(Pass::encrypt(str)); file.write(Pass::encrypt(str));
return true;*/ return true;*/
} }
QString Gpg::get_key_id(QString uid) { QString Gpg::get_key_id(QString uid) {
qDebug() << "Getting the key id " << uid; qDebug() << "Getting the key id " << uid;
auto *job = openpgp()->keyListJob(false, false, false); auto *job = openpgp()->keyListJob(false, false, false);
std::vector<Key> keys; std::vector<Key> keys;
auto result = job->exec(QStringList() << uid, false, keys); auto result = job->exec(QStringList() << uid, false, keys);
delete job; delete job;
if (keys.empty()) { if (keys.empty()) {
qDebug() << "No key found for" << uid; qDebug() << "No key found for" << uid;
return nullptr; return nullptr;
} }
const QString kId = QLatin1String(keys.front().keyID()); const QString kId = QLatin1String(keys.front().keyID());
qDebug() << "Id key for " << uid << "is : " << kId; qDebug() << "Id key for " << uid << "is : " << kId;
return kId; return kId;
} }
QStringList Gpg::get_all_keys_id() { QStringList Gpg::get_all_keys_id() {
qDebug() << "Show all available key"; qDebug() << "Show all available key";
auto job = openpgp()->keyListJob(false, false, false); auto job = openpgp()->keyListJob(false, false, false);
std::vector<Key> keys; std::vector<Key> keys;
auto result = job->exec(QStringList(""), false, keys); auto result = job->exec(QStringList(""), false, keys);
delete job; delete job;
if (keys.empty()) { if (keys.empty()) {
qDebug() << "No key found" ; qDebug() << "No key found";
return QStringList(); return QStringList();
} }
auto r = QStringList(); auto r = QStringList();
for(const auto &key: keys) { for (const auto &key: keys) {
r.append(QLatin1String(key.keyID())); r.append(QLatin1String(key.keyID()));
qDebug() << "Key" << QLatin1String(key.keyID()); qDebug() << "Key" << QLatin1String(key.keyID());
} }
return r; return r;
} }
bool Gpg::import_key(QString path) { bool Gpg::import_key(QString path) {
qDebug() << "Importing the key file" << path; qDebug() << "Importing the key file" << path;
QFile file(path); QFile file(path);
if (!file.open(QIODevice::ReadOnly)) { if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Can't open the File"; qWarning() << "Can't open the File";
return false; return false;
} }
auto job = openpgp()->importJob(); auto job = openpgp()->importJob();
auto result = job->exec(file.readAll()); auto result = job->exec(file.readAll());
delete job; delete job;
file.close(); file.close();
if(result.error()) { if (result.error()) {
qWarning() << "Import go wrong"; qWarning() << "Import go wrong";
return false; return false;
} }
qDebug() << "Key imported" << result.numImported(); qDebug() << "Key imported" << result.numImported();
qDebug() << "Key not imported" << result.notImported(); qDebug() << "Key not imported" << result.notImported();
qDebug() << "Key unchanged" << result.numUnchanged(); qDebug() << "Key unchanged" << result.numUnchanged();
qDebug() << "Result null" << result.isNull(); qDebug() << "Result null" << result.isNull();
qDebug() << "newUserIDs" << result.newUserIDs(); qDebug() << "newUserIDs" << result.newUserIDs();
for(const auto &key: result.imports()) for (const auto &key: result.imports())
qDebug() << "Key" << key.fingerprint(); qDebug() << "Key" << key.fingerprint();
return true; return true;
} }

View File

@ -3,21 +3,21 @@
#include <QObject> #include <QObject>
class Gpg: public QObject { class Gpg : public QObject {
Q_OBJECT Q_OBJECT
public: public:
Gpg(); Gpg();
~Gpg() = default; ~Gpg() = default;
Q_INVOKABLE void list_dir(); Q_INVOKABLE void list_dir();
Q_INVOKABLE QString get_key_id(QString uid); Q_INVOKABLE QString get_key_id(QString uid);
Q_INVOKABLE QStringList get_all_keys_id(); Q_INVOKABLE QStringList get_all_keys_id();
Q_INVOKABLE bool import_key(QString path); Q_INVOKABLE bool import_key(QString path);
Q_INVOKABLE QString decrypt(QByteArray plainText); Q_INVOKABLE QString decrypt(QByteArray plainText);
Q_INVOKABLE QString decrypt_file(QString path); Q_INVOKABLE QString decrypt_file(QString path);
Q_INVOKABLE QByteArray encrypt(QString str); Q_INVOKABLE QByteArray encrypt(QString str);
Q_INVOKABLE bool encrypt_file(QString str, QString path); Q_INVOKABLE bool encrypt_file(QString str, QString path);
}; };
#endif #endif

View File

@ -1,10 +1,9 @@
#include <QtQml> #include <QtQml>
#include <QtQml/QQmlContext>
#include "plugin.h" #include "plugin.h"
#include "gpg.h" #include "gpg.h"
void FileSystemPlugin::registerTypes(const char *uri) { void FileSystemPlugin::registerTypes(const char *uri) {
//@uri Pass //@uri Pass
qmlRegisterSingletonType<Gpg>(uri, 1, 0, "Gpg", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Gpg; }); qmlRegisterSingletonType<Gpg>(uri, 1, 0, "Gpg", [](QQmlEngine *, QJSEngine *) -> QObject * { return new Gpg; });
} }

View File

@ -4,11 +4,12 @@
#include <QQmlExtensionPlugin> #include <QQmlExtensionPlugin>
class FileSystemPlugin : public QQmlExtensionPlugin { class FileSystemPlugin : public QQmlExtensionPlugin {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") Q_PLUGIN_METADATA(IID
"org.qt-project.Qt.QQmlExtensionInterface")
public: public:
void registerTypes(const char *uri); void registerTypes(const char *uri);
}; };
#endif #endif

View File

@ -2,9 +2,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(PLUGIN "Pass") set(PLUGIN "Pass")
set( set(
SRC SRC
plugin.cpp plugin.cpp
pass.cpp pass.cpp
) )
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
@ -15,9 +15,9 @@ qt5_use_modules(${PLUGIN} Qml Quick DBus)
execute_process( execute_process(
COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
OUTPUT_VARIABLE ARCH_TRIPLET OUTPUT_VARIABLE ARCH_TRIPLET
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
) )
set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}") set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}")

View File

@ -3,13 +3,12 @@
#include "pass.h" #include "pass.h"
Pass::Pass() { Pass::Pass() {
} }
void Pass::speak() { void Pass::speak() {
qDebug() << "Starting app from main.cpp"; qDebug() << "Starting app from main.cpp";
} }

View File

@ -3,15 +3,15 @@
#include <QObject> #include <QObject>
class Pass: public QObject { class Pass : public QObject {
Q_OBJECT Q_OBJECT
QString gpgHome; QString gpgHome;
public: public:
Pass(); Pass();
~Pass() override = default; ~Pass() override = default;
Q_INVOKABLE void speak(); Q_INVOKABLE void speak();
}; };
#endif #endif

View File

@ -1,10 +1,9 @@
#include <QtQml> #include <QtQml>
#include <QtQml/QQmlContext>
#include "plugin.h" #include "plugin.h"
#include "pass.h" #include "pass.h"
void PassPlugin::registerTypes(const char *uri) { void PassPlugin::registerTypes(const char *uri) {
//@uri Pass //@uri Pass
qmlRegisterSingletonType<Pass>(uri, 1, 0, "Pass", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Pass; }); qmlRegisterSingletonType<Pass>(uri, 1, 0, "Pass", [](QQmlEngine *, QJSEngine *) -> QObject * { return new Pass; });
} }

View File

@ -4,11 +4,12 @@
#include <QQmlExtensionPlugin> #include <QQmlExtensionPlugin>
class PassPlugin : public QQmlExtensionPlugin { class PassPlugin : public QQmlExtensionPlugin {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") Q_PLUGIN_METADATA(IID
"org.qt-project.Qt.QQmlExtensionInterface")
public: public:
void registerTypes(const char *uri) override; void registerTypes(const char *uri) override;
}; };
#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: 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" "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"