Mailcommon

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

KDE's Doxygen guidelines are available online.