File indexing completed on 2024-06-02 05:24:46

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     uiserver/importfilescommand.cpp
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include <config-kleopatra.h>
0011 
0012 #include "importfilescommand.h"
0013 
0014 #include <commands/importcertificatefromfilecommand.h>
0015 
0016 #include <Libkleo/KleoException>
0017 
0018 #include <gpgme++/key.h>
0019 
0020 #include <gpg-error.h>
0021 
0022 #include <algorithm>
0023 #include <string>
0024 
0025 using namespace Kleo;
0026 
0027 class ImportFilesCommand::Private
0028 {
0029     friend class ::Kleo::ImportFilesCommand;
0030     ImportFilesCommand *const q;
0031 
0032 public:
0033     Private(ImportFilesCommand *qq)
0034         : q(qq)
0035         , command(nullptr)
0036     {
0037         KDAB_SET_OBJECT_NAME(command);
0038         command.setAutoDelete(false);
0039 
0040         connect(&command, SIGNAL(finished()), q, SLOT(slotCommandFinished()));
0041         connect(&command, SIGNAL(canceled()), q, SLOT(slotCommandCanceled()));
0042     }
0043 
0044 private:
0045     void slotCommandFinished()
0046     {
0047         q->done();
0048     }
0049     void slotCommandCanceled()
0050     {
0051         q->done(makeError(GPG_ERR_CANCELED));
0052     }
0053 
0054 private:
0055     ImportCertificateFromFileCommand command;
0056 };
0057 
0058 ImportFilesCommand::ImportFilesCommand()
0059     : QObject()
0060     , AssuanCommandMixin<ImportFilesCommand>()
0061     , d(new Private(this))
0062 {
0063 }
0064 
0065 ImportFilesCommand::~ImportFilesCommand()
0066 {
0067 }
0068 
0069 int ImportFilesCommand::doStart()
0070 {
0071     d->command.setParentWId(parentWId());
0072     d->command.setFiles(fileNames());
0073     d->command.start();
0074 
0075     return 0;
0076 }
0077 
0078 void ImportFilesCommand::doCanceled()
0079 {
0080     d->command.cancel();
0081 }
0082 
0083 #include "moc_importfilescommand.cpp"