From 9e937c1d987d407d974c9a2840a9b0581e43dcd0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 24 Nov 2017 15:48:43 +0100 Subject: Support unlocking the keyring from the commandline --- CMakeLists.txt | 1 + applications/kube/CMakeLists.txt | 1 + applications/kube/main.cpp | 30 +++++++++++++++++++++++++++++- framework/src/CMakeLists.txt | 16 +++++++++++----- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f52c825..2cbde180 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ include(KDECMakeSettings NO_POLICY_SCOPE) enable_testing() +include_directories(.) add_subdirectory(framework) add_subdirectory(components) add_subdirectory(icons) diff --git a/applications/kube/CMakeLists.txt b/applications/kube/CMakeLists.txt index 2d4c9da7..c206f22a 100644 --- a/applications/kube/CMakeLists.txt +++ b/applications/kube/CMakeLists.txt @@ -22,6 +22,7 @@ target_link_libraries(${PROJECT_NAME} Qt5::WebEngine KF5::Package ${CMAKE_DL_LIBS} + kubeframework ) install(TARGETS ${PROJECT_NAME} DESTINATION ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/applications/kube/main.cpp b/applications/kube/main.cpp index a6b51c38..88e44eac 100644 --- a/applications/kube/main.cpp +++ b/applications/kube/main.cpp @@ -32,6 +32,8 @@ #include #include +#include +#include #include #include @@ -40,6 +42,7 @@ #include #include +#include "framework/src/keyring.h" //Print a demangled stacktrace void printStacktrace() @@ -169,14 +172,39 @@ public: int main(int argc, char *argv[]) { - std::signal(SIGSEGV, crashHandler); std::signal(SIGABRT, crashHandler); std::set_terminate(terminateHandler); QApplication app(argc, argv); + app.setApplicationName("kube"); app.setFont(QFont{"Noto Sans", app.font().pointSize(), QFont::Normal}); + QCommandLineParser parser; + parser.setApplicationDescription("A communication and collaboration client."); + parser.addHelpOption(); + parser.addOption({{"k", "keyring"}, + QCoreApplication::translate("main", "To automatically unlock the keyring pass in a keyring in the form of {\"accountId\": {\"resourceId\": \"secret\", *}}"), + "keyring dictionary"} + ); + parser.process(app); + + if (parser.isSet("keyring")) { + auto keyringDict = parser.value("keyring"); + auto json = QJsonDocument::fromJson(keyringDict.toUtf8()); + if (!json.isObject()) { + qWarning() << "Not a valid keyring dict " << keyringDict; + return -1; + } + auto object = json.object(); + for (const auto accountId : object.keys()) { + auto dict = object.value(accountId).toObject(); + for (const auto resourceId : dict.keys()) { + Kube::AccountKeyring{accountId.toUtf8()}.storePassword(resourceId.toUtf8(), dict.value(resourceId).toString().toUtf8()); + } + } + } + QtWebEngine::initialize(); QIcon::setThemeName("kube"); diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 7b188a49..2febf91b 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt @@ -14,7 +14,9 @@ set(CMAKE_CXX_VISIBILITY_PRESET default) include_directories(. domain/mime/mimetreeparser domain/ domain/mime) set(SRCS - frameworkplugin.cpp +) + +add_library(kubeframework SHARED settings/settings.cpp domain/maillistmodel.cpp domain/folderlistmodel.cpp @@ -48,10 +50,8 @@ set(SRCS webengineprofile.cpp startupcheck.cpp keyring.cpp -) - -add_library(frameworkplugin SHARED ${SRCS}) -target_link_libraries(frameworkplugin + ) +target_link_libraries(kubeframework sink kube_otp Qt5::Core @@ -66,6 +66,12 @@ target_link_libraries(frameworkplugin KAsync QGpgme ) +install(TARGETS kubeframework DESTINATION ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) + +add_library(frameworkplugin SHARED frameworkplugin.cpp) +target_link_libraries(frameworkplugin + kubeframework +) install(TARGETS frameworkplugin DESTINATION ${FRAMEWORK_INSTALL_DIR}) set(BUILD_TESTING ON) -- cgit v1.2.3