File indexing completed on 2024-06-23 05:13:46
0001 // This file is part of Kleopatra, the KDE keymanager 0002 // SPDX-FileCopyrightText: 2023 g10 Code GmbH 0003 // SPDX-FileContributor: Carl Schwan <carl.schwan@gnupg.com> 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 #include "viewemailfilescommand.h" 0007 0008 #include "command_p.h" 0009 0010 #include <MimeTreeParserWidgets/MessageViewerDialog> 0011 0012 using namespace Kleo::Commands; 0013 using namespace MimeTreeParser::Widgets; 0014 0015 class ViewEmailFilesCommand::Private : public Command::Private 0016 { 0017 friend class ::Kleo::Commands::ViewEmailFilesCommand; 0018 ViewEmailFilesCommand *q_func() const 0019 { 0020 return static_cast<ViewEmailFilesCommand *>(q); 0021 } 0022 0023 public: 0024 Private(ViewEmailFilesCommand *qq, KeyListController *c); 0025 ~Private() override; 0026 0027 QList<QPointer<MessageViewerDialog>> dialogs; 0028 QStringList files; 0029 0030 void ensureDialogCreated(); 0031 }; 0032 0033 ViewEmailFilesCommand::Private::Private(ViewEmailFilesCommand *qq, KeyListController *c) 0034 : Command::Private(qq, c) 0035 { 0036 } 0037 0038 ViewEmailFilesCommand::Private::~Private() = default; 0039 0040 void ViewEmailFilesCommand::Private::ensureDialogCreated() 0041 { 0042 for (const auto &file : std::as_const(files)) { 0043 const auto dlg = new MessageViewerDialog(file); 0044 dlg->setAttribute(Qt::WA_DeleteOnClose); 0045 connect(dlg, &MessageViewerDialog::finished, q_func(), [this, dlg] { 0046 dialogs.removeAll(dlg); 0047 if (dialogs.isEmpty()) { 0048 finished(); 0049 } 0050 }); 0051 dialogs << dlg; 0052 dlg->show(); 0053 dlg->raise(); 0054 dlg->activateWindow(); 0055 } 0056 } 0057 0058 ViewEmailFilesCommand::Private *ViewEmailFilesCommand::d_func() 0059 { 0060 return static_cast<Private *>(d.get()); 0061 } 0062 const ViewEmailFilesCommand::Private *ViewEmailFilesCommand::d_func() const 0063 { 0064 return static_cast<const Private *>(d.get()); 0065 } 0066 0067 #define d d_func() 0068 #define q q_func() 0069 0070 ViewEmailFilesCommand::ViewEmailFilesCommand(const QStringList &files, KeyListController *c) 0071 : Command(new Private(this, c)) 0072 { 0073 Q_ASSERT(!files.isEmpty()); 0074 0075 setWarnWhenRunningAtShutdown(false); 0076 0077 d->files = files; 0078 } 0079 0080 ViewEmailFilesCommand::~ViewEmailFilesCommand() = default; 0081 0082 void ViewEmailFilesCommand::doStart() 0083 { 0084 d->ensureDialogCreated(); 0085 } 0086 0087 void ViewEmailFilesCommand::doCancel() 0088 { 0089 for (const auto &dialog : std::as_const(d->dialogs)) { 0090 dialog->close(); 0091 } 0092 } 0093 0094 #include "moc_viewemailfilescommand.cpp"