File indexing completed on 2024-12-22 05:01:08
0001 /* 0002 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only 0005 */ 0006 0007 #include "validatesendmailshortcut.h" 0008 #include "kmail_debug.h" 0009 #include "pimmessagebox.h" 0010 #include "settings/kmailsettings.h" 0011 0012 #include <KActionCollection> 0013 #include <KLocalizedString> 0014 #include <QAction> 0015 0016 ValidateSendMailShortcut::ValidateSendMailShortcut(KActionCollection *actionCollection, QWidget *parent) 0017 : mParent(parent) 0018 , mActionCollection(actionCollection) 0019 { 0020 } 0021 0022 ValidateSendMailShortcut::~ValidateSendMailShortcut() = default; 0023 0024 bool ValidateSendMailShortcut::validate() 0025 { 0026 bool sendNow = false; 0027 const int result = 0028 PIMMessageBox::fourBtnMsgBox(mParent, 0029 QMessageBox::Question, 0030 i18n("This shortcut allows to send mail directly.\nMail can be send accidentally.\nWhat do you want to do?"), 0031 i18n("Configure shortcut"), 0032 i18n("Remove Shortcut"), 0033 i18n("Ask Before Sending"), 0034 i18n("Sending Without Confirmation")); 0035 if (result == QDialogButtonBox::Yes) { 0036 QAction *act = mActionCollection->action(QStringLiteral("send_mail")); 0037 if (act) { 0038 act->setShortcut(QKeySequence()); 0039 mActionCollection->writeSettings(); 0040 } else { 0041 qCDebug(KMAIL_LOG) << "Unable to find action named \"send_mail\""; 0042 } 0043 sendNow = false; 0044 } else if (result == QDialogButtonBox::No) { 0045 KMailSettings::self()->setConfirmBeforeSendWhenUseShortcut(true); 0046 sendNow = true; 0047 } else if (result == QDialogButtonBox::Ok) { 0048 KMailSettings::self()->setConfirmBeforeSendWhenUseShortcut(false); 0049 sendNow = true; 0050 } else if (result == QDialogButtonBox::Cancel) { 0051 return false; 0052 } 0053 KMailSettings::self()->setCheckSendDefaultActionShortcut(true); 0054 KMailSettings::self()->save(); 0055 return sendNow; 0056 }