Mailcommon

collectiongeneralwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "collectiongeneralwidget.h"
8#include "folder/foldersettings.h"
9#include "kernel/mailkernel.h"
10#include "util/mailutil_p.h"
11#include <Akonadi/NewMailNotifierAttribute>
12#include <KIdentityManagementWidgets/IdentityCombo>
13#include <KLocalizedString>
14#include <QCheckBox>
15#include <QFormLayout>
16using namespace MailCommon;
17
18CollectionGeneralWidget::CollectionGeneralWidget(QWidget *parent)
19 : QWidget(parent)
20{
21 auto topLayout = new QFormLayout(this);
22 topLayout->setObjectName(QLatin1StringView("topLayout"));
23 topLayout->setContentsMargins({});
24 // should new mail in this folder be ignored?
25 mNotifyOnNewMailCheckBox = new QCheckBox(i18nc("@option:check", "Act on new/unread mail in this folder"), this);
26 mNotifyOnNewMailCheckBox->setWhatsThis(
27 i18n("<qt><p>If this option is enabled then you will be notified about "
28 "new/unread mail in this folder. Moreover, going to the "
29 "next/previous folder with unread messages will stop at this "
30 "folder.</p>"
31 "<p>Uncheck this option if you do not want to be notified about "
32 "new/unread mail in this folder and if you want this folder to "
33 "be skipped when going to the next/previous folder with unread "
34 "messages. This is useful for ignoring any new/unread mail in "
35 "your trash and spam folder.</p></qt>"));
36 topLayout->addRow(QString(), mNotifyOnNewMailCheckBox);
37 // should replies to mails in this folder be kept in this same folder?
38 mKeepRepliesInSameFolderCheckBox = new QCheckBox(i18nc("@option:check", "Keep replies in this folder"), this);
39 mKeepRepliesInSameFolderCheckBox->setWhatsThis(
40 i18n("Check this option if you want replies you write "
41 "to mails in this folder to be put in this same folder "
42 "after sending, instead of in the configured sent-mail folder."));
43 topLayout->addRow(QString(), mKeepRepliesInSameFolderCheckBox);
44
45 // should this folder be shown in the folder selection dialog?
46 mHideInSelectionDialogCheckBox = new QCheckBox(i18nc("@option:check", "Hide this folder in the folder selection dialog"), this);
47 mHideInSelectionDialogCheckBox->setWhatsThis(xi18nc("@info:whatsthis",
48 "Check this option if you do not want this folder "
49 "to be shown in folder selection dialogs, such as the <interface>"
50 "Jump to Folder</interface> dialog."));
51 topLayout->addRow(QString(), mHideInSelectionDialogCheckBox);
52
53 // sender identity
54 mUseDefaultIdentityCheckBox = new QCheckBox(i18nc("@option:check", "Use &default identity"), this);
55 topLayout->addRow(QString(), mUseDefaultIdentityCheckBox);
56 connect(mUseDefaultIdentityCheckBox, &QCheckBox::checkStateChanged, this, &CollectionGeneralWidget::slotIdentityCheckboxChanged);
57
58 mIdentityComboBox = new KIdentityManagementWidgets::IdentityCombo(KernelIf->identityManager(), this);
59 mIdentityComboBox->setWhatsThis(
60 i18n("Select the sender identity to be used when writing new mail "
61 "or replying to mail in this folder. This means that if you are in "
62 "one of your work folders, you can make KMail use the corresponding "
63 "sender email address, signature and signing or encryption keys "
64 "automatically. Identities can be set up in the main configuration "
65 "dialog. (Settings -> Configure KMail)"));
66 topLayout->addRow(i18n("&Sender identity:"), mIdentityComboBox);
67}
68
69CollectionGeneralWidget::~CollectionGeneralWidget() = default;
70
71void CollectionGeneralWidget::slotIdentityCheckboxChanged()
72{
73 mIdentityComboBox->setEnabled(!mUseDefaultIdentityCheckBox->isChecked());
74 if (!mFolderCollection.isNull() && mUseDefaultIdentityCheckBox->isChecked()) {
75 mIdentityComboBox->setCurrentIdentity(mFolderCollection->fallBackIdentity());
76 }
77}
78
79void CollectionGeneralWidget::save(Akonadi::Collection &collection)
80{
81 if (mFolderCollection.isNull()) {
82 mFolderCollection = FolderSettings::forCollection(collection);
83 }
84 if (!mNotifyOnNewMailCheckBox->isChecked()) {
85 auto *newMailNotifierAttr = collection.attribute<Akonadi::NewMailNotifierAttribute>(Akonadi::Collection::AddIfMissing);
86 newMailNotifierAttr->setIgnoreNewMail(true);
87 } else {
88 collection.removeAttribute<Akonadi::NewMailNotifierAttribute>();
89 }
90 if (!mFolderCollection.isNull()) {
91 mFolderCollection->setIdentity(mIdentityComboBox->currentIdentity());
92 mFolderCollection->setUseDefaultIdentity(mUseDefaultIdentityCheckBox->isChecked());
93
94 mFolderCollection->setPutRepliesInSameFolder(mKeepRepliesInSameFolderCheckBox->isChecked());
95 mFolderCollection->setHideInSelectionDialog(mHideInSelectionDialogCheckBox->isChecked());
96 mFolderCollection->writeConfig();
97 }
98 mFolderCollection.reset();
99}
100
101void CollectionGeneralWidget::load(const Akonadi::Collection &col)
102{
103 mFolderCollection = MailCommon::FolderSettings::forCollection(col);
104 // folder identity
105 mIdentityComboBox->setCurrentIdentity(mFolderCollection->identity());
106 mUseDefaultIdentityCheckBox->setChecked(mFolderCollection->useDefaultIdentity());
107
108 // ignore new mail
109 mNotifyOnNewMailCheckBox->setChecked(!Util::ignoreNewMailInFolder(col));
110
111 const bool keepInFolder = (mFolderCollection->canCreateMessages() && mFolderCollection->putRepliesInSameFolder());
112
113 mKeepRepliesInSameFolderCheckBox->setChecked(keepInFolder);
114 mKeepRepliesInSameFolderCheckBox->setEnabled(mFolderCollection->canCreateMessages());
115 mHideInSelectionDialogCheckBox->setChecked(mFolderCollection->hideInSelectionDialog());
116}
117
118#include "moc_collectiongeneralwidget.cpp"
const T * attribute() const
void setCurrentIdentity(const KIdentityManagementCore::Identity &identity)
KIdentityManagementCore::Identity::Id currentIdentity() const
void setUseDefaultIdentity(bool useDefaultIdentity)
Get / set whether the default identity should be used instead of the identity specified by setIdentit...
bool putRepliesInSameFolder() const
Returns true if the replies to mails from this folder should be put in the same folder.
bool hideInSelectionDialog() const
Returns true if this folder should be hidden from all folder selection dialogs.
QString xi18nc(const char *context, const char *text, const TYPE &arg...)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
bool isChecked() const const
bool isNull() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:18:39 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.