configuremiscpage.cpp 8.95 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
  Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "configuremiscpage.h"
Laurent Montel's avatar
Laurent Montel committed
19
#include "PimCommon/ConfigureImmutableWidgetUtils"
20
using namespace PimCommon::ConfigureImmutableWidgetUtils;
Laurent Montel's avatar
Laurent Montel committed
21
#include "configureagentswidget.h"
Laurent Montel's avatar
Laurent Montel committed
22
#include "settings/kmailsettings.h"
Laurent Montel's avatar
Laurent Montel committed
23

Laurent Montel's avatar
Laurent Montel committed
24
#include <MailCommon/FolderRequester>
25 26
#include "MessageViewer/InvitationSettings"
#include "MessageViewer/PrintingSettings"
27
#include "messageviewer/messageviewersettings.h"
Laurent Montel's avatar
Laurent Montel committed
28 29 30

#include <KCModuleProxy>
#include <KCModuleInfo>
Laurent Montel's avatar
Laurent Montel committed
31
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
32 33
#include <QDialog>
#include <KConfigGroup>
Laurent Montel's avatar
Laurent Montel committed
34 35
#include <QHBoxLayout>

36 37 38
#include <WebEngineViewer/NetworkPluginUrlInterceptorConfigureWidget>
#include <WebEngineViewer/NetworkUrlInterceptorPluginManager>
#include <WebEngineViewer/NetworkPluginUrlInterceptor>
Laurent Montel's avatar
Laurent Montel committed
39

Laurent Montel's avatar
Laurent Montel committed
40 41 42
using namespace MailCommon;
QString MiscPage::helpAnchor() const
{
Laurent Montel's avatar
Laurent Montel committed
43
    return QStringLiteral("configure-misc");
Laurent Montel's avatar
Laurent Montel committed
44 45
}

Laurent Montel's avatar
Laurent Montel committed
46 47
MiscPage::MiscPage(QWidget *parent)
    : ConfigModuleWithTabs(parent)
Laurent Montel's avatar
Laurent Montel committed
48
{
49 50
    FolderTab *folderTab = new FolderTab();
    addTab(folderTab, i18n("Folders"));
Laurent Montel's avatar
Laurent Montel committed
51

52 53
    InviteTab *inviteTab = new InviteTab();
    addTab(inviteTab, i18n("Invitations"));
Laurent Montel's avatar
Laurent Montel committed
54

55 56
    MiscPageAgentSettingsTab *agentSettingsTab = new MiscPageAgentSettingsTab();
    addTab(agentSettingsTab, i18n("Plugins Settings"));
Laurent Montel's avatar
Laurent Montel committed
57

58
    Q_FOREACH (WebEngineViewer::NetworkPluginUrlInterceptor *plugin, WebEngineViewer::NetworkUrlInterceptorPluginManager::self()->pluginsList()) {
59
        if (plugin->hasConfigureSupport()) {
60
            WebEngineViewer::NetworkPluginUrlInterceptorConfigureWidgetSetting settings = plugin->createConfigureWidget(this);
61 62 63 64 65

            AddonsPluginTab *tab = new AddonsPluginTab(settings.configureWidget, this);
            addTab(tab, settings.name);
        }
    }
Laurent Montel's avatar
Laurent Montel committed
66 67 68 69
}

QString MiscPageFolderTab::helpAnchor() const
{
Laurent Montel's avatar
Laurent Montel committed
70
    return QStringLiteral("configure-misc-folders");
Laurent Montel's avatar
Laurent Montel committed
71 72
}

Laurent Montel's avatar
Laurent Montel committed
73 74
MiscPageFolderTab::MiscPageFolderTab(QWidget *parent)
    : ConfigModuleTab(parent)
Laurent Montel's avatar
Laurent Montel committed
75
{
Laurent Montel's avatar
Laurent Montel committed
76
    mMMTab.setupUi(this);
Laurent Montel's avatar
Laurent Montel committed
77
    //replace QWidget with FolderRequester. Promote to doesn't work due to the custom constructor
Laurent Montel's avatar
Laurent Montel committed
78
    QHBoxLayout *layout = new QHBoxLayout;
Laurent Montel's avatar
Laurent Montel committed
79
    layout->setContentsMargins(0, 0, 0, 0);
Laurent Montel's avatar
Laurent Montel committed
80 81 82
    mMMTab.mOnStartupOpenFolder->setLayout(layout);
    mOnStartupOpenFolder = new FolderRequester(mMMTab.mOnStartupOpenFolder);
    layout->addWidget(mOnStartupOpenFolder);
Laurent Montel's avatar
Laurent Montel committed
83 84

    mMMTab.mExcludeImportantFromExpiry->setWhatsThis(
Laurent Montel's avatar
Laurent Montel committed
85
        i18n(KMailSettings::self()->excludeImportantMailFromExpiryItem()->whatsThis().toUtf8()));
Laurent Montel's avatar
Laurent Montel committed
86

Laurent Montel's avatar
Laurent Montel committed
87 88 89 90 91
    connect(mMMTab.mEmptyFolderConfirmCheck, &QCheckBox::stateChanged, this, &MiscPageFolderTab::slotEmitChanged);
    connect(mMMTab.mExcludeImportantFromExpiry, &QCheckBox::stateChanged, this, &MiscPageFolderTab::slotEmitChanged);
    connect(mMMTab.mLoopOnGotoUnread, static_cast<void (KComboBox::*)(int)>(&KComboBox::activated), this, &MiscPageFolderTab::slotEmitChanged);
    connect(mMMTab.mActionEnterFolder, static_cast<void (KComboBox::*)(int)>(&KComboBox::activated), this, &MiscPageFolderTab::slotEmitChanged);
    connect(mMMTab.mDelayedMarkTime, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MiscPageFolderTab::slotEmitChanged);
Laurent Montel's avatar
Laurent Montel committed
92
    connect(mMMTab.mDelayedMarkAsRead, &QAbstractButton::toggled, mMMTab.mDelayedMarkTime, &QWidget::setEnabled);
Laurent Montel's avatar
Laurent Montel committed
93
    connect(mMMTab.mDelayedMarkAsRead, &QAbstractButton::toggled, this, &ConfigModuleTab::slotEmitChanged);
Laurent Montel's avatar
Laurent Montel committed
94 95 96 97 98
    connect(mMMTab.mShowPopupAfterDnD, &QCheckBox::stateChanged, this, &MiscPageFolderTab::slotEmitChanged);
    connect(mOnStartupOpenFolder, &MailCommon::FolderRequester::folderChanged, this, &MiscPageFolderTab::slotEmitChanged);
    connect(mMMTab.mEmptyTrashCheck, &QCheckBox::stateChanged, this, &MiscPageFolderTab::slotEmitChanged);
    connect(mMMTab.mStartUpFolderCheck, &QCheckBox::toggled, this, &MiscPageFolderTab::slotEmitChanged);
    connect(mMMTab.mStartUpFolderCheck, &QCheckBox::toggled, mOnStartupOpenFolder, &MailCommon::FolderRequester::setEnabled);
Laurent Montel's avatar
Laurent Montel committed
99 100 101 102
}

void MiscPage::FolderTab::doLoadFromGlobalSettings()
{
Laurent Montel's avatar
Laurent Montel committed
103
    loadWidget(mMMTab.mExcludeImportantFromExpiry, KMailSettings::self()->excludeImportantMailFromExpiryItem());
Laurent Montel's avatar
Laurent Montel committed
104
    // default = "Loop in current folder"
Laurent Montel's avatar
Laurent Montel committed
105 106
    loadWidget(mMMTab.mLoopOnGotoUnread, KMailSettings::self()->loopOnGotoUnreadItem());
    loadWidget(mMMTab.mActionEnterFolder, KMailSettings::self()->actionEnterFolderItem());
Laurent Montel's avatar
Laurent Montel committed
107 108
    loadWidget(mMMTab.mDelayedMarkAsRead, MessageViewer::MessageViewerSettings::self()->delayedMarkAsReadItem());
    loadWidget(mMMTab.mDelayedMarkTime, MessageViewer::MessageViewerSettings::self()->delayedMarkTimeItem());
Laurent Montel's avatar
Laurent Montel committed
109 110 111
    loadWidget(mMMTab.mShowPopupAfterDnD, KMailSettings::self()->showPopupAfterDnDItem());
    loadWidget(mMMTab.mStartUpFolderCheck, KMailSettings::self()->startSpecificFolderAtStartupItem());
    mOnStartupOpenFolder->setEnabled(KMailSettings::self()->startSpecificFolderAtStartup());
Laurent Montel's avatar
Laurent Montel committed
112 113 114 115 116
    doLoadOther();
}

void MiscPage::FolderTab::doLoadOther()
{
Laurent Montel's avatar
Laurent Montel committed
117 118 119
    loadWidget(mMMTab.mEmptyTrashCheck, KMailSettings::self()->emptyTrashOnExitItem());
    mOnStartupOpenFolder->setCollection(Akonadi::Collection(KMailSettings::self()->startupFolder()));
    loadWidget(mMMTab.mEmptyFolderConfirmCheck, KMailSettings::self()->confirmBeforeEmptyItem());
Laurent Montel's avatar
Laurent Montel committed
120 121 122 123
}

void MiscPage::FolderTab::save()
{
Laurent Montel's avatar
Laurent Montel committed
124 125 126 127
    saveCheckBox(mMMTab.mEmptyTrashCheck, KMailSettings::self()->emptyTrashOnExitItem());
    saveCheckBox(mMMTab.mEmptyFolderConfirmCheck, KMailSettings::self()->confirmBeforeEmptyItem());
    saveComboBox(mMMTab.mActionEnterFolder, KMailSettings::self()->actionEnterFolderItem());
    KMailSettings::self()->setStartupFolder(mOnStartupOpenFolder->collection().id());
Laurent Montel's avatar
Laurent Montel committed
128

Laurent Montel's avatar
Laurent Montel committed
129 130
    saveCheckBox(mMMTab.mDelayedMarkAsRead, MessageViewer::MessageViewerSettings::self()->delayedMarkAsReadItem());
    saveSpinBox(mMMTab.mDelayedMarkTime, MessageViewer::MessageViewerSettings::self()->delayedMarkTimeItem());
Laurent Montel's avatar
Laurent Montel committed
131
    saveComboBox(mMMTab.mLoopOnGotoUnread, KMailSettings::self()->loopOnGotoUnreadItem());
132

Laurent Montel's avatar
Laurent Montel committed
133 134 135
    saveCheckBox(mMMTab.mExcludeImportantFromExpiry, KMailSettings::self()->excludeImportantMailFromExpiryItem());
    saveCheckBox(mMMTab.mShowPopupAfterDnD, KMailSettings::self()->showPopupAfterDnDItem());
    saveCheckBox(mMMTab.mStartUpFolderCheck, KMailSettings::self()->startSpecificFolderAtStartupItem());
Laurent Montel's avatar
Laurent Montel committed
136 137
}

Laurent Montel's avatar
Laurent Montel committed
138 139
MiscPageAgentSettingsTab::MiscPageAgentSettingsTab(QWidget *parent)
    : ConfigModuleTab(parent)
Laurent Montel's avatar
Laurent Montel committed
140
{
Laurent Montel's avatar
Laurent Montel committed
141
    QHBoxLayout *l = new QHBoxLayout(this);
Laurent Montel's avatar
Laurent Montel committed
142
    l->setContentsMargins(0, 0, 0, 0);
Laurent Montel's avatar
Laurent Montel committed
143
    mConfigureAgent = new ConfigureAgentsWidget;
Laurent Montel's avatar
Laurent Montel committed
144
    l->addWidget(mConfigureAgent);
Laurent Montel's avatar
Laurent Montel committed
145

Laurent Montel's avatar
Laurent Montel committed
146
    connect(mConfigureAgent, &ConfigureAgentsWidget::changed, this, &MiscPageAgentSettingsTab::slotEmitChanged);
Laurent Montel's avatar
Laurent Montel committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
}

void MiscPageAgentSettingsTab::doLoadFromGlobalSettings()
{
    mConfigureAgent->doLoadFromGlobalSettings();
}

void MiscPageAgentSettingsTab::save()
{
    mConfigureAgent->save();
}

void MiscPageAgentSettingsTab::doResetToDefaultsOther()
{
    mConfigureAgent->doResetToDefaultsOther();
}

QString MiscPageAgentSettingsTab::helpAnchor() const
{
    return mConfigureAgent->helpAnchor();
}

Laurent Montel's avatar
Laurent Montel committed
169 170
MiscPageInviteTab::MiscPageInviteTab(QWidget *parent)
    : ConfigModuleTab(parent)
Laurent Montel's avatar
Laurent Montel committed
171
{
Laurent Montel's avatar
Laurent Montel committed
172 173
    mInvitationUi = new MessageViewer::InvitationSettings(this);
    QHBoxLayout *l = new QHBoxLayout(this);
Laurent Montel's avatar
Laurent Montel committed
174
    l->setContentsMargins(0, 0, 0, 0);
Laurent Montel's avatar
Laurent Montel committed
175
    l->addWidget(mInvitationUi);
Laurent Montel's avatar
Laurent Montel committed
176
    connect(mInvitationUi, &MessageViewer::InvitationSettings::changed, this, &MiscPageInviteTab::slotEmitChanged);
Laurent Montel's avatar
Laurent Montel committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
}

void MiscPage::InviteTab::doLoadFromGlobalSettings()
{
    mInvitationUi->doLoadFromGlobalSettings();
}

void MiscPage::InviteTab::save()
{
    mInvitationUi->save();
}

void MiscPage::InviteTab::doResetToDefaultsOther()
{
    mInvitationUi->doResetToDefaultsOther();
}
//----------------------------
194

195
AddonsPluginTab::AddonsPluginTab(WebEngineViewer::NetworkPluginUrlInterceptorConfigureWidget *configureWidget, QWidget *parent)
Laurent Montel's avatar
Laurent Montel committed
196 197
    : ConfigModuleTab(parent),
      mConfigureWidget(configureWidget)
198
{
Laurent Montel's avatar
Laurent Montel committed
199 200 201
    QHBoxLayout *l = new QHBoxLayout(this);
    l->setContentsMargins(0, 0, 0, 0);
    l->addWidget(mConfigureWidget);
202
    connect(configureWidget, &WebEngineViewer::NetworkPluginUrlInterceptorConfigureWidget::configureChanged, this, &AddonsPluginTab::slotEmitChanged);
203 204 205 206 207 208 209 210 211
}

AddonsPluginTab::~AddonsPluginTab()
{

}

void AddonsPluginTab::save()
{
Laurent Montel's avatar
Laurent Montel committed
212
    mConfigureWidget->saveSettings();
213 214 215 216
}

void AddonsPluginTab::doLoadFromGlobalSettings()
{
Laurent Montel's avatar
Laurent Montel committed
217
    //TODO ?
218 219 220 221
}

void AddonsPluginTab::doLoadOther()
{
Laurent Montel's avatar
Laurent Montel committed
222
    mConfigureWidget->loadSettings();
223 224 225 226
}

void AddonsPluginTab::doResetToDefaultsOther()
{
Laurent Montel's avatar
Laurent Montel committed
227
    mConfigureWidget->resetSettings();
228
}