Commit 85c0a1e7 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move class here. It will be use by kdepim-addons plugins

parent af302bcd
Pipeline #35094 passed with stage
in 69 minutes and 23 seconds
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.15.43")
set(PIM_VERSION "5.15.44")
project(mailcommon VERSION ${PIM_VERSION})
......
......@@ -99,6 +99,7 @@ set(libmailcommon_collection_SRCS
collectionpage/collectionexpirywidget.cpp
collectionpage/attributes/expirecollectionattribute.cpp
collectionpage/collectionexpiryjob.cpp
collectionpage/collectiontemplateswidget.cpp
)
set(libmailcommon_folder_SRCS
......@@ -397,6 +398,7 @@ ecm_generate_headers(MailCommon_Camelcasecollectionpage_HEADERS
CollectionGeneralPage
CollectionExpiryPage
CollectionExpiryWidget
CollectionTemplatesWidget
REQUIRED_HEADERS MailCommon_collectionpage_HEADERS
PREFIX MailCommon
RELATIVE collectionpage
......
/*
SPDX-FileCopyrightText: 2020 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "collectiontemplateswidget.h"
#include <KLocalizedString>
#include "templatesconfiguration_kfg.h"
#include <MailCommon/FolderSettings>
#include <QCheckBox>
#include <QSharedPointer>
#include <QVBoxLayout>
#include <TemplateParser/TemplatesConfiguration>
using namespace MailCommon;
CollectionTemplatesWidget::CollectionTemplatesWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *topLayout = new QVBoxLayout(this);
QHBoxLayout *topItems = new QHBoxLayout;
topItems->setContentsMargins(0, 0, 0, 0);
topLayout->addLayout(topItems);
mCustom = new QCheckBox(i18n("&Use custom message templates in this folder"), this);
connect(mCustom, &QCheckBox::clicked, this, &CollectionTemplatesWidget::slotChanged);
topItems->addWidget(mCustom, Qt::AlignLeft);
mWidget = new TemplateParser::TemplatesConfiguration(this, QStringLiteral("folder-templates"));
connect(mWidget, &TemplateParser::TemplatesConfiguration::changed, this, &CollectionTemplatesWidget::slotChanged);
mWidget->setEnabled(false);
// Move the help label outside of the templates configuration widget,
// so that the help can be read even if the widget is not enabled.
topItems->addStretch(9);
topItems->addWidget(mWidget->helpLabel(), Qt::AlignRight);
topLayout->addWidget(mWidget);
QHBoxLayout *btns = new QHBoxLayout();
QPushButton *copyGlobal = new QPushButton(i18n("&Copy Global Templates"), this);
copyGlobal->setEnabled(false);
btns->addWidget(copyGlobal);
topLayout->addLayout(btns);
connect(mCustom, &QCheckBox::toggled, mWidget, &TemplateParser::TemplatesConfiguration::setEnabled);
connect(mCustom, &QCheckBox::toggled, copyGlobal, &QPushButton::setEnabled);
connect(copyGlobal, &QPushButton::clicked, this, &CollectionTemplatesWidget::slotCopyGlobal);
}
CollectionTemplatesWidget::~CollectionTemplatesWidget()
{
}
void CollectionTemplatesWidget::save(const Akonadi::Collection &)
{
if (mChanged && !mCollectionId.isEmpty()) {
TemplateParser::Templates t(mCollectionId);
//qCDebug(KMAIL_LOG) << "use custom templates for folder" << fid <<":" << mCustom->isChecked();
t.setUseCustomTemplates(mCustom->isChecked());
t.save();
mWidget->saveToFolder(mCollectionId);
}
}
void CollectionTemplatesWidget::slotCopyGlobal()
{
if (mIdentity) {
mWidget->loadFromIdentity(mIdentity);
} else {
mWidget->loadFromGlobal();
}
}
void CollectionTemplatesWidget::slotChanged()
{
mChanged = true;
}
void CollectionTemplatesWidget::load(const Akonadi::Collection &col)
{
const QSharedPointer<MailCommon::FolderSettings> fd = MailCommon::FolderSettings::forCollection(col, false);
if (!fd) {
return;
}
mCollectionId = QString::number(col.id());
TemplateParser::Templates t(mCollectionId);
mCustom->setChecked(t.useCustomTemplates());
mIdentity = fd->identity();
mWidget->loadFromFolder(mCollectionId, mIdentity);
mChanged = false;
}
/*
SPDX-FileCopyrightText: 2020 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef COLLECTIONTEMPLATESWIDGET_H
#define COLLECTIONTEMPLATESWIDGET_H
#include "mailcommon_export.h"
#include <QWidget>
#include <AkonadiCore/Collection>
class QCheckBox;
namespace TemplateParser {
class TemplatesConfiguration;
}
namespace MailCommon {
/**
* @brief The CollectionTemplateWidget class
* @author Laurent Montel <montel@kde.org>
*/
class MAILCOMMON_EXPORT CollectionTemplatesWidget : public QWidget
{
Q_OBJECT
public:
explicit CollectionTemplatesWidget(QWidget *parent = nullptr);
~CollectionTemplatesWidget();
void save(const Akonadi::Collection &);
void load(const Akonadi::Collection &col);
private:
void slotCopyGlobal();
void slotChanged();
QCheckBox *mCustom = nullptr;
TemplateParser::TemplatesConfiguration *mWidget = nullptr;
QString mCollectionId;
uint mIdentity = 0;
bool mChanged = false;
};
}
#endif // COLLECTIONTEMPLATESWIDGET_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment