Mailcommon

collectionviewwidget.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 "collectionviewwidget.h"
8#include "mailcommon_debug.h"
9#include <KLocalizedString>
10#include <QFormLayout>
11
12#include <Akonadi/MessageFolderAttribute>
13#include <MessageList/AggregationComboBox>
14#include <MessageList/AggregationConfigButton>
15#include <MessageList/ThemeComboBox>
16#include <MessageList/ThemeConfigButton>
17
18#include <MessageViewer/Viewer>
19
20#include <QCheckBox>
21#include <QComboBox>
22#include <QRadioButton>
23using namespace MailCommon;
24CollectionViewWidget::CollectionViewWidget(QWidget *parent)
25 : QWidget(parent)
26 , mShowSenderReceiverComboBox(new QComboBox(this))
27 , mUseDefaultAggregationCheckBox(new QCheckBox(i18nc("@option:check", "Use default message list aggregation:"), this))
28 , mAggregationComboBox(new MessageList::Utils::AggregationComboBox(this))
29 , mUseDefaultThemeCheckBox(new QCheckBox(i18nc("@option:check", "Use default message list theme"), this))
30 , mThemeComboBox(new MessageList::Utils::ThemeComboBox(this))
31 , mPreferHtmlToText(new QRadioButton(i18nc("@option:radio", "Prefer HTML to text"), this))
32 , mPreferTextToHtml(new QRadioButton(i18nc("@option:radio", "Prefer text to HTML"), this))
33 , mUseGlobalSettings(new QRadioButton(i18nc("@option:radio", "Use Global Settings"), this))
34{
35 auto topLayout = new QFormLayout(this);
36 topLayout->setObjectName(QLatin1StringView("topLayout"));
37 topLayout->setContentsMargins({});
38
39 // sender or receiver column
40 const QString senderReceiverColumnTip = i18n("Show Sender/Receiver Column in List of Messages");
41
42 mShowSenderReceiverComboBox->setToolTip(senderReceiverColumnTip);
43 mShowSenderReceiverComboBox->insertItem(0, i18nc("@item:inlistbox Show default value.", "Default"));
44 mShowSenderReceiverComboBox->insertItem(1, i18nc("@item:inlistbox Show sender.", "Sender"));
45 mShowSenderReceiverComboBox->insertItem(2, i18nc("@item:inlistbox Show receiver.", "Receiver"));
46 topLayout->addRow(i18n("Sho&w column:"), mShowSenderReceiverComboBox);
47
48 // message list aggregation
49 connect(mUseDefaultAggregationCheckBox, &QCheckBox::checkStateChanged, this, &CollectionViewWidget::slotAggregationCheckboxChanged);
50 topLayout->addRow(QString(), mUseDefaultAggregationCheckBox);
51
53 auto aggregationConfigButton = new AggregationConfigButton(this, mAggregationComboBox);
54 // Make sure any changes made in the aggregations configure dialog are reflected in the combo.
55 connect(aggregationConfigButton, &AggregationConfigButton::configureDialogCompleted, this, &CollectionViewWidget::slotSelectFolderAggregation);
56
57 auto aggregationLayout = new QHBoxLayout;
58 aggregationLayout->addWidget(mAggregationComboBox, 1);
59 aggregationLayout->addWidget(aggregationConfigButton, 0);
60 topLayout->addRow(QString(), aggregationLayout);
61
62 // message list theme
63 connect(mUseDefaultThemeCheckBox, &QCheckBox::checkStateChanged, this, &CollectionViewWidget::slotThemeCheckboxChanged);
64 topLayout->addRow(QString(), mUseDefaultThemeCheckBox);
65
67 auto themeConfigButton = new ThemeConfigButton(this, mThemeComboBox);
68 // Make sure any changes made in the themes configure dialog are reflected in the combo.
69 connect(themeConfigButton, &ThemeConfigButton::configureDialogCompleted, this, &CollectionViewWidget::slotSelectFolderTheme);
70
71 auto themeLayout = new QHBoxLayout;
72 themeLayout->addWidget(mThemeComboBox, 1);
73 themeLayout->addWidget(themeConfigButton, 0);
74 topLayout->addRow(QString(), themeLayout);
75
76 // Message Default Format
77 topLayout->addRow(i18n("Message format:"), mPreferHtmlToText);
78 topLayout->addRow(QString(), mPreferTextToHtml);
79 topLayout->addRow(QString(), mUseGlobalSettings);
80}
81
82CollectionViewWidget::~CollectionViewWidget() = default;
83
84void CollectionViewWidget::load(const Akonadi::Collection &col)
85{
86 mCurrentCollection = col;
87 mFolderCollection = MailCommon::FolderSettings::forCollection(col);
89 const bool outboundFolder = col.attribute<Akonadi::MessageFolderAttribute>()->isOutboundFolder();
90 if (outboundFolder) {
91 mShowSenderReceiverComboBox->setCurrentIndex(2);
92 } else {
93 mShowSenderReceiverComboBox->setCurrentIndex(1);
94 }
95 } else {
96 mShowSenderReceiverComboBox->setCurrentIndex(0);
97 }
98 mShowSenderReceiverValue = mShowSenderReceiverComboBox->currentIndex();
99
100 // message list aggregation
101 slotSelectFolderAggregation();
102
103 // message list theme
104 slotSelectFolderTheme();
105
106 const MessageViewer::Viewer::DisplayFormatMessage formatMessage = mFolderCollection->formatMessage();
107 switch (formatMessage) {
108 case MessageViewer::Viewer::Html:
109 mPreferHtmlToText->setChecked(true);
110 break;
111 case MessageViewer::Viewer::Text:
112 mPreferTextToHtml->setChecked(true);
113 break;
114 case MessageViewer::Viewer::UseGlobalSetting:
115 mUseGlobalSettings->setChecked(true);
116 break;
117 default:
118 qCDebug(MAILCOMMON_LOG) << "No settings defined";
119 break;
120 }
121}
122
123void CollectionViewWidget::save(Akonadi::Collection &col)
124{
125 if (!mFolderCollection) {
126 mFolderCollection = MailCommon::FolderSettings::forCollection(col);
127 }
128 const int currentIndex = mShowSenderReceiverComboBox->currentIndex();
129 if (mShowSenderReceiverValue != currentIndex) {
130 if (currentIndex == 1) {
132 messageFolder->setOutboundFolder(false);
133 } else if (currentIndex == 2) {
135 messageFolder->setOutboundFolder(true);
136 } else {
138 }
139 }
140 // message list theme
141 const bool usePrivateTheme = !mUseDefaultThemeCheckBox->isChecked();
142 mThemeComboBox->writeStorageModelConfig(QString::number(mCurrentCollection.id()), usePrivateTheme);
143 // message list aggregation
144 const bool usePrivateAggregation = !mUseDefaultAggregationCheckBox->isChecked();
145 mAggregationComboBox->writeStorageModelConfig(QString::number(mCurrentCollection.id()), usePrivateAggregation);
146
147 MessageViewer::Viewer::DisplayFormatMessage formatMessage = MessageViewer::Viewer::Unknown;
148 if (mPreferHtmlToText->isChecked()) {
149 formatMessage = MessageViewer::Viewer::Html;
150 } else if (mPreferTextToHtml->isChecked()) {
151 formatMessage = MessageViewer::Viewer::Text;
152 } else if (mUseGlobalSettings->isChecked()) {
153 formatMessage = MessageViewer::Viewer::UseGlobalSetting;
154 } else {
155 qCDebug(MAILCOMMON_LOG) << "No settings defined";
156 }
157 if (formatMessage != MessageViewer::Viewer::Unknown) {
158 mFolderCollection->setFormatMessage(formatMessage);
159 mFolderCollection->writeConfig();
160 }
161 mFolderCollection.reset();
162}
163
164void CollectionViewWidget::slotSelectFolderAggregation()
165{
166 bool usesPrivateAggregation = false;
167 mAggregationComboBox->readStorageModelConfig(mCurrentCollection, usesPrivateAggregation);
168 mUseDefaultAggregationCheckBox->setChecked(!usesPrivateAggregation);
169}
170
171void CollectionViewWidget::slotSelectFolderTheme()
172{
173 bool usesPrivateTheme = false;
174 mThemeComboBox->readStorageModelConfig(mCurrentCollection, usesPrivateTheme);
175 mUseDefaultThemeCheckBox->setChecked(!usesPrivateTheme);
176}
177
178void CollectionViewWidget::slotAggregationCheckboxChanged()
179{
180 mAggregationComboBox->setEnabled(!mUseDefaultAggregationCheckBox->isChecked());
181}
182
183void CollectionViewWidget::slotThemeCheckboxChanged()
184{
185 mThemeComboBox->setEnabled(!mUseDefaultThemeCheckBox->isChecked());
186}
187
188#include "moc_collectionviewwidget.cpp"
const T * attribute() const
bool hasAttribute() const
void setOutboundFolder(bool outbound)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
void setChecked(bool)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setCurrentIndex(int index)
QString number(double n, char format, int precision)
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 Sat Dec 21 2024 17:00:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.