File indexing completed on 2024-12-22 05:01:15
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "undosendmanager.h" 0008 #include "kmail_undo_send_debug.h" 0009 0010 #include "undosendcreatejob.h" 0011 #include <KLocalizedString> 0012 0013 UndoSendManager::UndoSendManager(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 UndoSendManager::~UndoSendManager() = default; 0019 0020 UndoSendManager *UndoSendManager::self() 0021 { 0022 static UndoSendManager s_self; 0023 return &s_self; 0024 } 0025 0026 void UndoSendManager::addItem(const UndoSendManagerInfo &info) 0027 { 0028 if (info.isValid()) { 0029 auto job = new UndoSendCreateJob(this); 0030 job->setAkonadiIndex(info.index); 0031 job->setMessageInfoText(info.generateMessageInfoText()); 0032 job->setDelay(info.delay); 0033 if (!job->start()) { 0034 qCWarning(KMAIL_UNDO_SEND_LOG) << " Impossible to create job"; 0035 } 0036 } 0037 } 0038 0039 QString UndoSendManager::UndoSendManagerInfo::generateMessageInfoText() const 0040 { 0041 QString str = QStringLiteral("<qt>"); 0042 if (!to.isEmpty()) { 0043 str += i18n("<b>To:</b> %1", to); 0044 } 0045 if (!subject.isEmpty()) { 0046 if (!str.isEmpty()) { 0047 str += QStringLiteral("<br />"); 0048 } 0049 str += i18n("<b>Subject:</b> %1", subject); 0050 } 0051 str += QStringLiteral("</qt>"); 0052 return str; 0053 } 0054 0055 bool UndoSendManager::UndoSendManagerInfo::isValid() const 0056 { 0057 return index != -1 && delay != -1; 0058 } 0059 0060 #include "moc_undosendmanager.cpp"