File indexing completed on 2024-06-23 05:14:13
0001 /* -*- mode: c++; c-basic-offset:4 -*- 0002 uiserver/createchecksumscommand.cpp 0003 0004 This file is part of Kleopatra, the KDE keymanager 0005 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include <config-kleopatra.h> 0011 0012 #include "createchecksumscommand.h" 0013 0014 #include <crypto/createchecksumscontroller.h> 0015 0016 #include <Libkleo/KleoException> 0017 0018 #include <KLocalizedString> 0019 0020 using namespace Kleo; 0021 using namespace Kleo::Crypto; 0022 0023 class CreateChecksumsCommand::Private 0024 { 0025 private: 0026 friend class ::Kleo::CreateChecksumsCommand; 0027 CreateChecksumsCommand *const q; 0028 0029 public: 0030 explicit Private(CreateChecksumsCommand *qq) 0031 : q(qq) 0032 , controller() 0033 { 0034 } 0035 0036 private: 0037 void checkForErrors() const; 0038 0039 private: 0040 std::shared_ptr<CreateChecksumsController> controller; 0041 }; 0042 0043 CreateChecksumsCommand::CreateChecksumsCommand() 0044 : AssuanCommandMixin<CreateChecksumsCommand>() 0045 , d(new Private(this)) 0046 { 0047 } 0048 0049 CreateChecksumsCommand::~CreateChecksumsCommand() 0050 { 0051 } 0052 0053 void CreateChecksumsCommand::Private::checkForErrors() const 0054 { 0055 if (!q->numFiles()) 0056 throw Exception(makeError(GPG_ERR_ASS_NO_INPUT), i18n("At least one FILE must be present")); 0057 } 0058 0059 int CreateChecksumsCommand::doStart() 0060 { 0061 d->checkForErrors(); 0062 0063 d->controller.reset(new CreateChecksumsController(shared_from_this())); 0064 0065 d->controller->setAllowAddition(hasOption("allow-addition")); 0066 0067 d->controller->setFiles(fileNames()); 0068 0069 connect( 0070 d->controller.get(), 0071 &Controller::done, 0072 this, 0073 [this]() { 0074 done(); 0075 }, 0076 Qt::QueuedConnection); 0077 connect( 0078 d->controller.get(), 0079 &Controller::error, 0080 this, 0081 [this](int err, const QString &details) { 0082 done(err, details); 0083 }, 0084 Qt::QueuedConnection); 0085 0086 d->controller->start(); 0087 0088 return 0; 0089 } 0090 0091 void CreateChecksumsCommand::doCanceled() 0092 { 0093 if (d->controller) { 0094 d->controller->cancel(); 0095 } 0096 } 0097 0098 #include "moc_createchecksumscommand.cpp"