Warning, file /pim/mailcommon/src/collectionpage/collectiongeneralwidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002   SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "collectiongeneralwidget.h"
0008 #include "folder/foldersettings.h"
0009 #include "kernel/mailkernel.h"
0010 #include "util/mailutil_p.h"
0011 #include <Akonadi/NewMailNotifierAttribute>
0012 #include <KIdentityManagementWidgets/IdentityCombo>
0013 #include <KLocalizedString>
0014 #include <QCheckBox>
0015 #include <QFormLayout>
0016 using namespace MailCommon;
0017 
0018 CollectionGeneralWidget::CollectionGeneralWidget(QWidget *parent)
0019     : QWidget(parent)
0020 {
0021     auto topLayout = new QFormLayout(this);
0022     topLayout->setObjectName(QLatin1StringView("topLayout"));
0023     topLayout->setContentsMargins({});
0024     // should new mail in this folder be ignored?
0025     mNotifyOnNewMailCheckBox = new QCheckBox(i18n("Act on new/unread mail in this folder"), this);
0026     mNotifyOnNewMailCheckBox->setWhatsThis(
0027         i18n("<qt><p>If this option is enabled then you will be notified about "
0028              "new/unread mail in this folder. Moreover, going to the "
0029              "next/previous folder with unread messages will stop at this "
0030              "folder.</p>"
0031              "<p>Uncheck this option if you do not want to be notified about "
0032              "new/unread mail in this folder and if you want this folder to "
0033              "be skipped when going to the next/previous folder with unread "
0034              "messages. This is useful for ignoring any new/unread mail in "
0035              "your trash and spam folder.</p></qt>"));
0036     topLayout->addRow(QString(), mNotifyOnNewMailCheckBox);
0037     // should replies to mails in this folder be kept in this same folder?
0038     mKeepRepliesInSameFolderCheckBox = new QCheckBox(i18n("Keep replies in this folder"), this);
0039     mKeepRepliesInSameFolderCheckBox->setWhatsThis(
0040         i18n("Check this option if you want replies you write "
0041              "to mails in this folder to be put in this same folder "
0042              "after sending, instead of in the configured sent-mail folder."));
0043     topLayout->addRow(QString(), mKeepRepliesInSameFolderCheckBox);
0044 
0045     // should this folder be shown in the folder selection dialog?
0046     mHideInSelectionDialogCheckBox = new QCheckBox(i18n("Hide this folder in the folder selection dialog"), this);
0047     mHideInSelectionDialogCheckBox->setWhatsThis(xi18nc("@info:whatsthis",
0048                                                         "Check this option if you do not want this folder "
0049                                                         "to be shown in folder selection dialogs, such as the <interface>"
0050                                                         "Jump to Folder</interface> dialog."));
0051     topLayout->addRow(QString(), mHideInSelectionDialogCheckBox);
0052 
0053     // sender identity
0054     mUseDefaultIdentityCheckBox = new QCheckBox(i18n("Use &default identity"), this);
0055     topLayout->addRow(QString(), mUseDefaultIdentityCheckBox);
0056     connect(mUseDefaultIdentityCheckBox, &QCheckBox::stateChanged, this, &CollectionGeneralWidget::slotIdentityCheckboxChanged);
0057 
0058     mIdentityComboBox = new KIdentityManagementWidgets::IdentityCombo(KernelIf->identityManager(), this);
0059     mIdentityComboBox->setWhatsThis(
0060         i18n("Select the sender identity to be used when writing new mail "
0061              "or replying to mail in this folder. This means that if you are in "
0062              "one of your work folders, you can make KMail use the corresponding "
0063              "sender email address, signature and signing or encryption keys "
0064              "automatically. Identities can be set up in the main configuration "
0065              "dialog. (Settings -> Configure KMail)"));
0066     topLayout->addRow(i18n("&Sender identity:"), mIdentityComboBox);
0067 }
0068 
0069 CollectionGeneralWidget::~CollectionGeneralWidget() = default;
0070 
0071 void CollectionGeneralWidget::slotIdentityCheckboxChanged()
0072 {
0073     mIdentityComboBox->setEnabled(!mUseDefaultIdentityCheckBox->isChecked());
0074     if (!mFolderCollection.isNull() && mUseDefaultIdentityCheckBox->isChecked()) {
0075         mIdentityComboBox->setCurrentIdentity(mFolderCollection->fallBackIdentity());
0076     }
0077 }
0078 
0079 void CollectionGeneralWidget::save(Akonadi::Collection &collection)
0080 {
0081     if (mFolderCollection.isNull()) {
0082         mFolderCollection = FolderSettings::forCollection(collection);
0083     }
0084     if (!mNotifyOnNewMailCheckBox->isChecked()) {
0085         auto *newMailNotifierAttr = collection.attribute<Akonadi::NewMailNotifierAttribute>(Akonadi::Collection::AddIfMissing);
0086         newMailNotifierAttr->setIgnoreNewMail(true);
0087     } else {
0088         collection.removeAttribute<Akonadi::NewMailNotifierAttribute>();
0089     }
0090     if (!mFolderCollection.isNull()) {
0091         mFolderCollection->setIdentity(mIdentityComboBox->currentIdentity());
0092         mFolderCollection->setUseDefaultIdentity(mUseDefaultIdentityCheckBox->isChecked());
0093 
0094         mFolderCollection->setPutRepliesInSameFolder(mKeepRepliesInSameFolderCheckBox->isChecked());
0095         mFolderCollection->setHideInSelectionDialog(mHideInSelectionDialogCheckBox->isChecked());
0096         mFolderCollection->writeConfig();
0097     }
0098     mFolderCollection.reset();
0099 }
0100 
0101 void CollectionGeneralWidget::load(const Akonadi::Collection &col)
0102 {
0103     mFolderCollection = MailCommon::FolderSettings::forCollection(col);
0104     // folder identity
0105     mIdentityComboBox->setCurrentIdentity(mFolderCollection->identity());
0106     mUseDefaultIdentityCheckBox->setChecked(mFolderCollection->useDefaultIdentity());
0107 
0108     // ignore new mail
0109     mNotifyOnNewMailCheckBox->setChecked(!Util::ignoreNewMailInFolder(col));
0110 
0111     const bool keepInFolder = (mFolderCollection->canCreateMessages() && mFolderCollection->putRepliesInSameFolder());
0112 
0113     mKeepRepliesInSameFolderCheckBox->setChecked(keepInFolder);
0114     mKeepRepliesInSameFolderCheckBox->setEnabled(mFolderCollection->canCreateMessages());
0115     mHideInSelectionDialogCheckBox->setChecked(mFolderCollection->hideInSelectionDialog());
0116 }
0117 
0118 #include "moc_collectiongeneralwidget.cpp"