File indexing completed on 2024-12-22 05:01:02

0001 /*
0002   SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "configuremiscpage.h"
0008 #include <PimCommon/ConfigureImmutableWidgetUtils>
0009 using namespace PimCommon::ConfigureImmutableWidgetUtils;
0010 #include "kmkernel.h"
0011 #include "settings/kmailsettings.h"
0012 #include <MailCommon/FolderRequester>
0013 #include <MessageViewer/InvitationSettings>
0014 #include <MessageViewer/MessageViewerSettings>
0015 #include <MessageViewer/PrintingSettings>
0016 
0017 #include <KLocalizedString>
0018 #include <QHBoxLayout>
0019 
0020 #ifdef WITH_KUSERFEEDBACK
0021 #include <KUserFeedback/FeedbackConfigWidget>
0022 #endif
0023 
0024 using namespace MailCommon;
0025 QString MiscPage::helpAnchor() const
0026 {
0027     return QStringLiteral("configure-misc");
0028 }
0029 
0030 MiscPage::MiscPage(QObject *parent, const KPluginMetaData &data)
0031     : ConfigModuleWithTabs(parent, data)
0032 {
0033     auto folderTab = new MiscPageFolderTab();
0034     addTab(folderTab, i18n("Folders"));
0035 
0036     auto inviteTab = new MiscPageInviteTab();
0037     addTab(inviteTab, i18n("Invitations"));
0038 
0039     auto printingTab = new MiscPagePrintingTab();
0040     addTab(printingTab, i18n("Printing"));
0041 #ifdef WITH_KUSERFEEDBACK
0042     auto userFeedBackTab = new KuserFeedBackPageTab();
0043     addTab(userFeedBackTab, i18n("User Feedback"));
0044 #endif
0045 }
0046 
0047 QString MiscPageFolderTab::helpAnchor() const
0048 {
0049     return QStringLiteral("configure-misc-folders");
0050 }
0051 
0052 MiscPageFolderTab::MiscPageFolderTab(QWidget *parent)
0053     : ConfigModuleTab(parent)
0054 {
0055     mMMTab.setupUi(this);
0056     // replace QWidget with FolderRequester. Promote to doesn't work due to the custom constructor
0057     auto layout = new QHBoxLayout;
0058     layout->setContentsMargins({});
0059     mMMTab.mOnStartupOpenFolder->setLayout(layout);
0060     mOnStartupOpenFolder = new FolderRequester(mMMTab.mOnStartupOpenFolder);
0061     layout->addWidget(mOnStartupOpenFolder);
0062 
0063     mMMTab.mExcludeImportantFromExpiry->setWhatsThis(i18n(KMailSettings::self()->excludeImportantMailFromExpiryItem()->whatsThis().toUtf8().constData()));
0064 
0065     connect(mMMTab.mExcludeImportantFromExpiry, &QCheckBox::stateChanged, this, &MiscPageFolderTab::slotEmitChanged);
0066     connect(mMMTab.mLoopOnGotoUnread, &QComboBox::activated, this, &MiscPageFolderTab::slotEmitChanged);
0067     connect(mMMTab.mActionEnterFolder, &QComboBox::activated, this, &MiscPageFolderTab::slotEmitChanged);
0068     connect(mMMTab.mDelayedMarkTime, &QSpinBox::valueChanged, this, &MiscPageFolderTab::slotEmitChanged);
0069     connect(mMMTab.mDelayedMarkAsRead, &QAbstractButton::toggled, mMMTab.mDelayedMarkTime, &QWidget::setEnabled);
0070     connect(mMMTab.mDelayedMarkAsRead, &QAbstractButton::toggled, this, &ConfigModuleTab::slotEmitChanged);
0071     connect(mMMTab.mShowPopupAfterDnD, &QCheckBox::stateChanged, this, &MiscPageFolderTab::slotEmitChanged);
0072     connect(mOnStartupOpenFolder, &MailCommon::FolderRequester::folderChanged, this, &MiscPageFolderTab::slotEmitChanged);
0073     connect(mMMTab.mEmptyTrashCheck, &QCheckBox::stateChanged, this, &MiscPageFolderTab::slotEmitChanged);
0074     connect(mMMTab.mStartUpFolderCheck, &QCheckBox::toggled, this, &MiscPageFolderTab::slotEmitChanged);
0075     connect(mMMTab.mStartUpFolderCheck, &QCheckBox::toggled, mOnStartupOpenFolder, &MailCommon::FolderRequester::setEnabled);
0076     connect(mMMTab.mDeleteMessagesWithoutConfirmation, &QCheckBox::toggled, this, &MiscPageFolderTab::slotEmitChanged);
0077     connect(mMMTab.mEnableFolderDragAndDrop, &QCheckBox::toggled, this, &MiscPageFolderTab::slotEmitChanged);
0078 }
0079 
0080 void MiscPageFolderTab::doLoadFromGlobalSettings()
0081 {
0082     loadWidget(mMMTab.mEnableFolderDragAndDrop, KMailSettings::self()->enableFolderDnDItem());
0083     loadWidget(mMMTab.mExcludeImportantFromExpiry, KMailSettings::self()->excludeImportantMailFromExpiryItem());
0084     // default = "Loop in current folder"
0085     loadWidget(mMMTab.mLoopOnGotoUnread, KMailSettings::self()->loopOnGotoUnreadItem());
0086     loadWidget(mMMTab.mActionEnterFolder, KMailSettings::self()->actionEnterFolderItem());
0087     loadWidget(mMMTab.mDelayedMarkAsRead, MessageViewer::MessageViewerSettings::self()->delayedMarkAsReadItem());
0088     loadWidget(mMMTab.mDelayedMarkTime, MessageViewer::MessageViewerSettings::self()->delayedMarkTimeItem());
0089     loadWidget(mMMTab.mShowPopupAfterDnD, KMailSettings::self()->showPopupAfterDnDItem());
0090     loadWidget(mMMTab.mStartUpFolderCheck, KMailSettings::self()->startSpecificFolderAtStartupItem());
0091     mOnStartupOpenFolder->setEnabled(KMailSettings::self()->startSpecificFolderAtStartup());
0092 
0093     loadWidget(mMMTab.mDeleteMessagesWithoutConfirmation, KMailSettings::self()->deleteMessageWithoutConfirmationItem());
0094 
0095     doLoadOther();
0096 }
0097 
0098 void MiscPageFolderTab::doLoadOther()
0099 {
0100     loadWidget(mMMTab.mEmptyTrashCheck, KMailSettings::self()->emptyTrashOnExitItem());
0101     mOnStartupOpenFolder->setCollection(Akonadi::Collection(KMailSettings::self()->startupFolder()));
0102 }
0103 
0104 void MiscPageFolderTab::save()
0105 {
0106     saveCheckBox(mMMTab.mEmptyTrashCheck, KMailSettings::self()->emptyTrashOnExitItem());
0107     saveComboBox(mMMTab.mActionEnterFolder, KMailSettings::self()->actionEnterFolderItem());
0108     KMailSettings::self()->setStartupFolder(mOnStartupOpenFolder->collection().id());
0109 
0110     saveCheckBox(mMMTab.mDelayedMarkAsRead, MessageViewer::MessageViewerSettings::self()->delayedMarkAsReadItem());
0111     saveSpinBox(mMMTab.mDelayedMarkTime, MessageViewer::MessageViewerSettings::self()->delayedMarkTimeItem());
0112     saveComboBox(mMMTab.mLoopOnGotoUnread, KMailSettings::self()->loopOnGotoUnreadItem());
0113 
0114     saveCheckBox(mMMTab.mExcludeImportantFromExpiry, KMailSettings::self()->excludeImportantMailFromExpiryItem());
0115     saveCheckBox(mMMTab.mShowPopupAfterDnD, KMailSettings::self()->showPopupAfterDnDItem());
0116     saveCheckBox(mMMTab.mStartUpFolderCheck, KMailSettings::self()->startSpecificFolderAtStartupItem());
0117     saveCheckBox(mMMTab.mDeleteMessagesWithoutConfirmation, KMailSettings::self()->deleteMessageWithoutConfirmationItem());
0118     saveCheckBox(mMMTab.mEnableFolderDragAndDrop, KMailSettings::self()->enableFolderDnDItem());
0119 }
0120 
0121 MiscPageInviteTab::MiscPageInviteTab(QWidget *parent)
0122     : ConfigModuleTab(parent)
0123     , mInvitationUi(new MessageViewer::InvitationSettings(this))
0124 {
0125     auto l = new QHBoxLayout(this);
0126     l->setContentsMargins({});
0127     l->addWidget(mInvitationUi);
0128     connect(mInvitationUi, &MessageViewer::InvitationSettings::changed, this, &MiscPageInviteTab::slotEmitChanged);
0129 }
0130 
0131 void MiscPageInviteTab::doLoadFromGlobalSettings()
0132 {
0133     mInvitationUi->doLoadFromGlobalSettings();
0134 }
0135 
0136 void MiscPageInviteTab::save()
0137 {
0138     mInvitationUi->save();
0139 }
0140 
0141 void MiscPageInviteTab::doResetToDefaultsOther()
0142 {
0143     mInvitationUi->doResetToDefaultsOther();
0144 }
0145 
0146 MiscPagePrintingTab::MiscPagePrintingTab(QWidget *parent)
0147     : ConfigModuleTab(parent)
0148     , mPrintingUi(new MessageViewer::PrintingSettings(this))
0149 {
0150     auto l = new QHBoxLayout(this);
0151     l->setContentsMargins({});
0152     l->addWidget(mPrintingUi);
0153     connect(mPrintingUi, &MessageViewer::PrintingSettings::changed, this, &MiscPagePrintingTab::slotEmitChanged);
0154 }
0155 
0156 void MiscPagePrintingTab::doLoadFromGlobalSettings()
0157 {
0158     mPrintingUi->doLoadFromGlobalSettings();
0159 }
0160 
0161 void MiscPagePrintingTab::doResetToDefaultsOther()
0162 {
0163     mPrintingUi->doResetToDefaultsOther();
0164 }
0165 
0166 void MiscPagePrintingTab::save()
0167 {
0168     mPrintingUi->save();
0169 }
0170 
0171 #ifdef WITH_KUSERFEEDBACK
0172 KuserFeedBackPageTab::KuserFeedBackPageTab(QWidget *parent)
0173     : ConfigModuleTab(parent)
0174     , mUserFeedbackWidget(new KUserFeedback::FeedbackConfigWidget(this))
0175 {
0176     auto l = new QHBoxLayout(this);
0177     l->setContentsMargins({});
0178     l->addWidget(mUserFeedbackWidget);
0179     connect(mUserFeedbackWidget, &KUserFeedback::FeedbackConfigWidget::configurationChanged, this, &KuserFeedBackPageTab::slotEmitChanged);
0180 
0181     if (KMKernel::self()) {
0182         mUserFeedbackWidget->setFeedbackProvider(KMKernel::self()->userFeedbackProvider());
0183     }
0184 }
0185 
0186 void KuserFeedBackPageTab::save()
0187 {
0188     if (KMKernel::self()) {
0189         // set current active mode + write back the config for future starts
0190         KMKernel::self()->userFeedbackProvider()->setTelemetryMode(mUserFeedbackWidget->telemetryMode());
0191         KMKernel::self()->userFeedbackProvider()->setSurveyInterval(mUserFeedbackWidget->surveyInterval());
0192     }
0193 }
0194 
0195 void KuserFeedBackPageTab::doResetToDefaultsOther()
0196 {
0197     if (KMKernel::self()) {
0198         mUserFeedbackWidget->setFeedbackProvider(KMKernel::self()->userFeedbackProvider());
0199     }
0200 }
0201 
0202 void KuserFeedBackPageTab::doLoadFromGlobalSettings()
0203 {
0204     if (KMKernel::self()) {
0205         mUserFeedbackWidget->setFeedbackProvider(KMKernel::self()->userFeedbackProvider());
0206     }
0207 }
0208 
0209 #endif
0210 
0211 #include "moc_configuremiscpage.cpp"