diff --git a/src/gpgcardgui/CMakeLists.txt b/src/gpgcardgui/CMakeLists.txt index 1c31b4b..f461af2 100644 --- a/src/gpgcardgui/CMakeLists.txt +++ b/src/gpgcardgui/CMakeLists.txt @@ -1,34 +1,33 @@ # Copyright (C) 2018 Intevation GmbH # # This file is Free Software under the GNU GPL (v>=2) # and comes with ABSOLUTELY NO WARRANTY! # See LICENSE.txt for details. set(EXECUTABLE_NAME "gpgcardgui") set(EXECUTABLE_SRC main.cpp - gpgcard.cpp gpgcardgui.cpp mainwindow.cpp ${CMAKE_SOURCE_DIR}/src/util/strhelp.c ${CMAKE_SOURCE_DIR}/src/util/w32-gettext.c ) add_executable(${EXECUTABLE_NAME} ${_add_executable_params} ${EXECUTABLE_SRC} ) target_link_libraries(${EXECUTABLE_NAME} Qt5::Widgets KF5::Libkleo Gpgmepp QGpgme ) if (WIN32) set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINK_FLAGS "-municode") endif(WIN32) install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin) diff --git a/src/gpgcardgui/gpgcard.cpp b/src/gpgcardgui/gpgcard.cpp deleted file mode 100644 index 3a41176..0000000 --- a/src/gpgcardgui/gpgcard.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright (C) 2020 by g10 Code GmbH - * - * This file is Free Software under the GNU GPL (v>=2) - * and comes with ABSOLUTELY NO WARRANTY! - * See LICENSE.txt for details. - */ -#include "gpgcard.h" - -#include -#include -#include -#include - -#include - -GpgCard::GpgCard(QObject *parent): - QObject(parent), - mValid(false) -{ - const QFileInfo gpgInfo(Kleo::gpgPath()); - QStringList paths; - paths << gpgInfo.absoluteDir().absolutePath(); - - QString gpgCardPath = QStandardPaths::findExecutable(QStringLiteral("gpg-card"), - paths); - - if (gpgCardPath.isEmpty()) { - qDebug() << "Failed to find gpg-card in: " << paths; - } - - gpgCardPath = QStandardPaths::findExecutable(QStringLiteral("gpg-card")); - - if (gpgCardPath.isEmpty()) { - qDebug() << "Failed to find gpg-card in system paths"; - } else { - qDebug() << "Using: " << gpgCardPath; - } - - if (QFileInfo(gpgCardPath).isExecutable()) { - mValid = true; - } - - connect(&mProc, QOverload::of(&QProcess::finished), - [this] (int exitCode, QProcess::ExitStatus exitStatus) { - /* Guranteed to be utf-8 by using --with-colons */ - mStdout = QString::fromUtf8(mProc.readAllStandardOutput()); - mStderr = QString::fromUtf8(mProc.readAllStandardError()); - - Q_EMIT finished(); - }); - mProc.setProgram(gpgCardPath); -} - -void GpgCard::start(const QStringList &commands) -{ - mStderr = QString(); - mStdout = QString(); - - if (!mValid) { - return; - } - QStringList args; - args << QStringLiteral("--with-colons"); - args += commands; - - mProc.setArguments(args); - mProc.start(); -} - -QString GpgCard::stdOut() const -{ - return mStdout; -} - -QString GpgCard::stdErr() const -{ - return mStderr; -} - -int GpgCard::exitCode() const -{ - return mExitCode; -} diff --git a/src/gpgcardgui/gpgcard.h b/src/gpgcardgui/gpgcard.h deleted file mode 100644 index 9ea1da9..0000000 --- a/src/gpgcardgui/gpgcard.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (C) 2020 by g10 Code GmbH - * - * This file is Free Software under the GNU GPL (v>=2) - * and comes with ABSOLUTELY NO WARRANTY! - * See LICENSE.txt for details. - */ -#pragma once -#include -#include - -/** The GpgCard class to wrap a call to the gpg-card tool. */ -class GpgCard: public QObject -{ - Q_OBJECT; - -public: - explicit GpgCard(QObject *parent = nullptr); - - /* Start the command and signal finished with the result - * when done. */ - void start(const QStringList &commands); - - /* Get the stdOut from the call */ - QString stdOut () const; - - /* Get the stdErr from the call */ - QString stdErr () const; - - /* The exitCode of gpg-card. If the process - * did not exit normally -1 is returned. */ - int exitCode () const; - -Q_SIGNALS: - void finished(); - -private: - QProcess mProc; - QString mStdout; - QString mStderr; - bool mValid; - int mExitCode; -}; diff --git a/src/gpgcardgui/mainwindow.cpp b/src/gpgcardgui/mainwindow.cpp index 37d094c..c7071f8 100644 --- a/src/gpgcardgui/mainwindow.cpp +++ b/src/gpgcardgui/mainwindow.cpp @@ -1,43 +1,39 @@ /* Copyright (C) 2020 by g10 Code GmbH * * This file is Free Software under the GNU GPL (v>=2) * and comes with ABSOLUTELY NO WARRANTY! * See LICENSE.txt for details. */ #include "mainwindow.h" -#include "gpgcard.h" #include #include #include +#include +#include + #include "w32-gettext.h" MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags): QMainWindow(parent, flags) { mEdit = new QTextEdit (this); mEdit->setReadOnly(true); setCentralWidget(mEdit); - // Setup a new command - auto cmd = new GpgCard; - - connect (cmd, &GpgCard::finished, this, [this, cmd] () { - if (cmd->exitCode() != 0) { - qDebug() << "Process exited with: " << cmd->exitCode(); - const auto errMsg = QString::fromUtf8(_("Error")) + - QStringLiteral("%1\n%2").arg(cmd->exitCode()).arg(cmd->stdErr()); - mEdit->setText(errMsg); - } else { - // Here the output should be parsed. - mEdit->setText(cmd->stdOut()); + connect (&mManager, &Kleo::SmartCard::CardManager::cardsMayHaveChanged, this, [this] () { + const auto cards = mManager.cards(); + for (const auto card: cards) { + if (card) { + mEdit->setText(mEdit->toPlainText() + + "\nFound smartcard" + QString::fromStdString(card->serialNumber()) + + "\nIn Reader: " + card->reader()); + } } - cmd->deleteLater(); }); - cmd->start (QStringList() << QStringLiteral("--") - << QStringLiteral("list")); + mManager.startCardList(); } diff --git a/src/gpgcardgui/mainwindow.h b/src/gpgcardgui/mainwindow.h index e374fff..1659c0f 100644 --- a/src/gpgcardgui/mainwindow.h +++ b/src/gpgcardgui/mainwindow.h @@ -1,23 +1,26 @@ /* Copyright (C) 2020 by g10 Code GmbH * * This file is Free Software under the GNU GPL (v>=2) * and comes with ABSOLUTELY NO WARRANTY! * See LICENSE.txt for details. */ #pragma once #include +#include + class QTextEdit; /** MainWindow of the application. */ class MainWindow: public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); private: QTextEdit *mEdit; + Kleo::SmartCard::CardManager mManager; };