Mailcommon

collectiontemplateswidget.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 "collectiontemplateswidget.h"
8
9#include <KLocalizedString>
10#include <templateparser/templatesconfiguration_kfg.h>
11
12#include <MailCommon/FolderSettings>
13#include <QCheckBox>
14#include <QSharedPointer>
15#include <QVBoxLayout>
16#include <TemplateParser/TemplatesConfiguration>
17using namespace MailCommon;
18CollectionTemplatesWidget::CollectionTemplatesWidget(QWidget *parent)
19 : QWidget(parent)
20 , mCustom(new QCheckBox(i18nc("@option:check", "&Use custom message templates in this folder"), this))
21{
22 auto topLayout = new QVBoxLayout(this);
23 auto topItems = new QHBoxLayout;
24 topItems->setContentsMargins({});
25 topLayout->addLayout(topItems);
26
27 connect(mCustom, &QCheckBox::clicked, this, &CollectionTemplatesWidget::slotChanged);
28 topItems->addWidget(mCustom, Qt::AlignLeft);
29
30 mWidget = new TemplateParser::TemplatesConfiguration(this, QStringLiteral("folder-templates"));
31 connect(mWidget, &TemplateParser::TemplatesConfiguration::changed, this, &CollectionTemplatesWidget::slotChanged);
32 mWidget->setEnabled(false);
33
34 // Move the help label outside of the templates configuration widget,
35 // so that the help can be read even if the widget is not enabled.
36 topItems->addStretch(9);
37 topItems->addWidget(mWidget->helpLabel(), Qt::AlignRight);
38
39 topLayout->addWidget(mWidget);
40
41 auto btns = new QHBoxLayout();
42 auto copyGlobal = new QPushButton(i18nc("@action:button", "&Copy Global Templates"), this);
43 copyGlobal->setEnabled(false);
44 btns->addWidget(copyGlobal);
45 topLayout->addLayout(btns);
46
48 connect(mCustom, &QCheckBox::toggled, copyGlobal, &QPushButton::setEnabled);
49
50 connect(copyGlobal, &QPushButton::clicked, this, &CollectionTemplatesWidget::slotCopyGlobal);
51}
52
53CollectionTemplatesWidget::~CollectionTemplatesWidget() = default;
54
55void CollectionTemplatesWidget::save(Akonadi::Collection &col)
56{
57 if (mCollectionId.isEmpty()) {
58 mCollectionId = QString::number(col.id());
59 }
60 if (mChanged) {
61 TemplateParser::Templates t(mCollectionId);
62 // qCDebug(KMAIL_LOG) << "use custom templates for folder" << fid <<":" << mCustom->isChecked();
63 t.setUseCustomTemplates(mCustom->isChecked());
64 t.save();
65
66 mWidget->saveToFolder(mCollectionId);
67 }
68}
69
70void CollectionTemplatesWidget::slotCopyGlobal()
71{
72 if (mIdentity) {
73 mWidget->loadFromIdentity(mIdentity);
74 } else {
75 mWidget->loadFromGlobal();
76 }
77}
78
79void CollectionTemplatesWidget::slotChanged()
80{
81 mChanged = true;
82}
83
84void CollectionTemplatesWidget::load(const Akonadi::Collection &col)
85{
86 const QSharedPointer<MailCommon::FolderSettings> fd = MailCommon::FolderSettings::forCollection(col, false);
87 if (fd.isNull()) {
88 return;
89 }
90
91 mCollectionId = QString::number(col.id());
92
93 TemplateParser::Templates t(mCollectionId);
94
95 mCustom->setChecked(t.useCustomTemplates());
96
97 mIdentity = fd->identity();
98
99 mWidget->loadFromFolder(mCollectionId, mIdentity);
100 mChanged = false;
101}
102
103#include "moc_collectiontemplateswidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
The filter dialog.
bool isChecked() const const
void clicked(bool checked)
void toggled(bool checked)
void setContentsMargins(const QMargins &margins)
bool isNull() const const
bool isEmpty() const const
QString number(double n, char format, int precision)
AlignLeft
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.