From befa0604ea6205a994eda9a60cb085d40708008a Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Tue, 22 Sep 2020 07:39:19 +0200 Subject: [PATCH] Move collectionviewwidget here --- CMakeLists.txt | 3 +- src/CMakeLists.txt | 3 + src/collectionpage/collectionviewwidget.cpp | 211 ++++++++++++++++++++ src/collectionpage/collectionviewwidget.h | 52 +++++ 4 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 src/collectionpage/collectionviewwidget.cpp create mode 100644 src/collectionpage/collectionviewwidget.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e1ab78..de293d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -set(PIM_VERSION "5.15.44") +set(PIM_VERSION "5.15.45") project(mailcommon VERSION ${PIM_VERSION}) @@ -66,6 +66,7 @@ find_package(KF5Libkdepim ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MailImporter ${MAILIMPORTER_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MailTransport ${KMAILTRANSPORT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageComposer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) +find_package(KF5MessageList ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageCore ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageViewer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Mime ${KMIME_LIB_VERSION} CONFIG REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index effc162..bccfdce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,6 +100,7 @@ set(libmailcommon_collection_SRCS collectionpage/attributes/expirecollectionattribute.cpp collectionpage/collectionexpiryjob.cpp collectionpage/collectiontemplateswidget.cpp + collectionpage/collectionviewwidget.cpp ) set(libmailcommon_folder_SRCS @@ -250,6 +251,7 @@ PRIVATE KF5::MailImporter KF5::MessageCore KF5::TemplateParser + KF5::MessageList KF5::Mime KF5::Codecs KF5::MailTransport @@ -399,6 +401,7 @@ ecm_generate_headers(MailCommon_Camelcasecollectionpage_HEADERS CollectionExpiryPage CollectionExpiryWidget CollectionTemplatesWidget + CollectionViewWidget REQUIRED_HEADERS MailCommon_collectionpage_HEADERS PREFIX MailCommon RELATIVE collectionpage diff --git a/src/collectionpage/collectionviewwidget.cpp b/src/collectionpage/collectionviewwidget.cpp new file mode 100644 index 0000000..b3d182e --- /dev/null +++ b/src/collectionpage/collectionviewwidget.cpp @@ -0,0 +1,211 @@ +/* + SPDX-FileCopyrightText: 2020 Laurent Montel + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "collectionviewwidget.h" +#include "mailcommon_debug.h" +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +using namespace MailCommon; +CollectionViewWidget::CollectionViewWidget(QWidget *parent) + : QWidget(parent) +{ + QVBoxLayout *topLayout = new QVBoxLayout(this); + topLayout->setObjectName(QStringLiteral("topLayout")); + topLayout->setContentsMargins({}); + + // sender or receiver column + const QString senderReceiverColumnTip = i18n("Show Sender/Receiver Column in List of Messages"); + + QLabel *senderReceiverColumnLabel = new QLabel(i18n("Sho&w column:"), this); + mShowSenderReceiverComboBox = new QComboBox(this); + mShowSenderReceiverComboBox->setToolTip(senderReceiverColumnTip); + senderReceiverColumnLabel->setBuddy(mShowSenderReceiverComboBox); + mShowSenderReceiverComboBox->insertItem(0, i18nc("@item:inlistbox Show default value.", "Default")); + mShowSenderReceiverComboBox->insertItem(1, i18nc("@item:inlistbox Show sender.", "Sender")); + mShowSenderReceiverComboBox->insertItem(2, i18nc("@item:inlistbox Show receiver.", "Receiver")); + + QHBoxLayout *senderReceiverColumnHLayout = new QHBoxLayout(); + senderReceiverColumnHLayout->addWidget(senderReceiverColumnLabel); + senderReceiverColumnHLayout->addWidget(mShowSenderReceiverComboBox); + topLayout->addLayout(senderReceiverColumnHLayout); + + // message list + QGroupBox *messageListGroup = new QGroupBox(i18n("Message List"), this); + QVBoxLayout *messageListGroupLayout = new QVBoxLayout(messageListGroup); + topLayout->addWidget(messageListGroup); + + // message list aggregation + mUseDefaultAggregationCheckBox = new QCheckBox(i18n("Use default aggregation"), messageListGroup); + messageListGroupLayout->addWidget(mUseDefaultAggregationCheckBox); + connect(mUseDefaultAggregationCheckBox, &QCheckBox::stateChanged, this, &CollectionViewWidget::slotAggregationCheckboxChanged); + + mAggregationComboBox = new MessageList::Utils::AggregationComboBox(messageListGroup); + + QLabel *aggregationLabel = new QLabel(i18n("Aggregation"), messageListGroup); + aggregationLabel->setBuddy(mAggregationComboBox); + + using MessageList::Utils::AggregationConfigButton; + AggregationConfigButton *aggregationConfigButton = new AggregationConfigButton(messageListGroup, mAggregationComboBox); + // Make sure any changes made in the aggregations configure dialog are reflected in the combo. + connect(aggregationConfigButton, &AggregationConfigButton::configureDialogCompleted, this, &CollectionViewWidget::slotSelectFolderAggregation); + + QHBoxLayout *aggregationLayout = new QHBoxLayout(); + aggregationLayout->addWidget(aggregationLabel, 1); + aggregationLayout->addWidget(mAggregationComboBox, 1); + aggregationLayout->addWidget(aggregationConfigButton, 0); + messageListGroupLayout->addLayout(aggregationLayout); + + // message list theme + mUseDefaultThemeCheckBox = new QCheckBox(i18n("Use default theme"), messageListGroup); + messageListGroupLayout->addWidget(mUseDefaultThemeCheckBox); + connect(mUseDefaultThemeCheckBox, &QCheckBox::stateChanged, this, &CollectionViewWidget::slotThemeCheckboxChanged); + + mThemeComboBox = new MessageList::Utils::ThemeComboBox(messageListGroup); + + QLabel *themeLabel = new QLabel(i18n("Theme"), messageListGroup); + themeLabel->setBuddy(mThemeComboBox); + + using MessageList::Utils::ThemeConfigButton; + ThemeConfigButton *themeConfigButton = new ThemeConfigButton(messageListGroup, mThemeComboBox); + // Make sure any changes made in the themes configure dialog are reflected in the combo. + connect(themeConfigButton, &ThemeConfigButton::configureDialogCompleted, this, &CollectionViewWidget::slotSelectFolderTheme); + + QHBoxLayout *themeLayout = new QHBoxLayout(); + themeLayout->addWidget(themeLabel, 1); + themeLayout->addWidget(mThemeComboBox, 1); + themeLayout->addWidget(themeConfigButton, 0); + messageListGroupLayout->addLayout(themeLayout); + + // Message Default Format + QGroupBox *messageFormatGroup = new QGroupBox(i18n("Message Default Format"), this); + QVBoxLayout *messageFormatGroupLayout = new QVBoxLayout(messageFormatGroup); + mPreferHtmlToText = new QRadioButton(i18n("Prefer HTML to text"), this); + messageFormatGroupLayout->addWidget(mPreferHtmlToText); + mPreferTextToHtml = new QRadioButton(i18n("Prefer text to HTML"), this); + messageFormatGroupLayout->addWidget(mPreferTextToHtml); + mUseGlobalSettings = new QRadioButton(i18n("Use Global Settings"), this); + messageFormatGroupLayout->addWidget(mUseGlobalSettings); + + topLayout->addWidget(messageFormatGroup); + + topLayout->addStretch(100); +} + +CollectionViewWidget::~CollectionViewWidget() +{ + +} + +void CollectionViewWidget::load(const Akonadi::Collection &col) +{ + mFolderCollection = MailCommon::FolderSettings::forCollection(col); + if (col.hasAttribute()) { + const bool outboundFolder = col.attribute()->isOutboundFolder(); + if (outboundFolder) { + mShowSenderReceiverComboBox->setCurrentIndex(2); + } else { + mShowSenderReceiverComboBox->setCurrentIndex(1); + } + } else { + mShowSenderReceiverComboBox->setCurrentIndex(0); + } + mShowSenderReceiverValue = mShowSenderReceiverComboBox->currentIndex(); + + // message list aggregation + slotSelectFolderAggregation(); + + // message list theme + slotSelectFolderTheme(); + + const MessageViewer::Viewer::DisplayFormatMessage formatMessage = mFolderCollection->formatMessage(); + switch (formatMessage) { + case MessageViewer::Viewer::Html: + mPreferHtmlToText->setChecked(true); + break; + case MessageViewer::Viewer::Text: + mPreferTextToHtml->setChecked(true); + break; + case MessageViewer::Viewer::UseGlobalSetting: + mUseGlobalSettings->setChecked(true); + break; + default: + qCDebug(MAILCOMMON_LOG) << "No settings defined"; + break; + } +} + +void CollectionViewWidget::save(Akonadi::Collection &col) +{ + const int currentIndex = mShowSenderReceiverComboBox->currentIndex(); + if (mShowSenderReceiverValue != currentIndex) { + if (currentIndex == 1) { + Akonadi::MessageFolderAttribute *messageFolder = col.attribute(Akonadi::Collection::AddIfMissing); + messageFolder->setOutboundFolder(false); + } else if (currentIndex == 2) { + Akonadi::MessageFolderAttribute *messageFolder = col.attribute(Akonadi::Collection::AddIfMissing); + messageFolder->setOutboundFolder(true); + } else { + col.removeAttribute(); + } + } + // message list theme + const bool usePrivateTheme = !mUseDefaultThemeCheckBox->isChecked(); + mThemeComboBox->writeStorageModelConfig(QString::number(mCurrentCollection.id()), usePrivateTheme); + // message list aggregation + const bool usePrivateAggregation = !mUseDefaultAggregationCheckBox->isChecked(); + mAggregationComboBox->writeStorageModelConfig(QString::number(mCurrentCollection.id()), usePrivateAggregation); + + MessageViewer::Viewer::DisplayFormatMessage formatMessage = MessageViewer::Viewer::Unknown; + if (mPreferHtmlToText->isChecked()) { + formatMessage = MessageViewer::Viewer::Html; + } else if (mPreferTextToHtml->isChecked()) { + formatMessage = MessageViewer::Viewer::Text; + } else if (mUseGlobalSettings->isChecked()) { + formatMessage = MessageViewer::Viewer::UseGlobalSetting; + } else { + qCDebug(MAILCOMMON_LOG) << "No settings defined"; + } + mFolderCollection->setFormatMessage(formatMessage); + mFolderCollection->writeConfig(); +} + +void CollectionViewWidget::slotSelectFolderAggregation() +{ + bool usesPrivateAggregation = false; + mAggregationComboBox->readStorageModelConfig(mCurrentCollection, usesPrivateAggregation); + mUseDefaultAggregationCheckBox->setChecked(!usesPrivateAggregation); +} + +void CollectionViewWidget::slotSelectFolderTheme() +{ + bool usesPrivateTheme = false; + mThemeComboBox->readStorageModelConfig(mCurrentCollection, usesPrivateTheme); + mUseDefaultThemeCheckBox->setChecked(!usesPrivateTheme); +} + +void CollectionViewWidget::slotAggregationCheckboxChanged() +{ + mAggregationComboBox->setEnabled(!mUseDefaultAggregationCheckBox->isChecked()); +} + +void CollectionViewWidget::slotThemeCheckboxChanged() +{ + mThemeComboBox->setEnabled(!mUseDefaultThemeCheckBox->isChecked()); +} diff --git a/src/collectionpage/collectionviewwidget.h b/src/collectionpage/collectionviewwidget.h new file mode 100644 index 0000000..c439cb3 --- /dev/null +++ b/src/collectionpage/collectionviewwidget.h @@ -0,0 +1,52 @@ +/* + SPDX-FileCopyrightText: 2020 Laurent Montel + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef COLLECTIONVIEWWIDGET_H +#define COLLECTIONVIEWWIDGET_H + +#include +#include +#include "mailcommon_export.h" +#include +class QCheckBox; +class QComboBox; +class QRadioButton; +namespace MessageList { +namespace Utils { +class AggregationComboBox; +class ThemeComboBox; +} +} +namespace MailCommon { +class MAILCOMMON_EXPORT CollectionViewWidget : public QWidget +{ + Q_OBJECT +public: + explicit CollectionViewWidget(QWidget *parent = nullptr); + ~CollectionViewWidget(); + void load(const Akonadi::Collection &col); + void save(Akonadi::Collection &col); +private: + void slotSelectFolderAggregation(); + void slotSelectFolderTheme(); + void slotThemeCheckboxChanged(); + void slotAggregationCheckboxChanged(); + QSharedPointer mFolderCollection; + QCheckBox *mIconsCheckBox = nullptr; + QComboBox *mShowSenderReceiverComboBox = nullptr; + QCheckBox *mUseDefaultAggregationCheckBox = nullptr; + MessageList::Utils::AggregationComboBox *mAggregationComboBox = nullptr; + QCheckBox *mUseDefaultThemeCheckBox = nullptr; + MessageList::Utils::ThemeComboBox *mThemeComboBox = nullptr; + QRadioButton *mPreferHtmlToText = nullptr; + QRadioButton *mPreferTextToHtml = nullptr; + QRadioButton *mUseGlobalSettings = nullptr; + Akonadi::Collection mCurrentCollection; + int mShowSenderReceiverValue = -1; +}; +} + +#endif // COLLECTIONVIEWWIDGET_H