Pimcommon

completionconfiguredialog.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5
6*/
7
8#include "completionconfiguredialog.h"
9using namespace Qt::Literals::StringLiterals;
10
11#include <KConfigGroup>
12#include <KLDAPCore/LdapClientSearch>
13#include <KLocalizedString>
14#include <KSharedConfig>
15#include <KWindowConfig>
16#include <QDialogButtonBox>
17#include <QPushButton>
18#include <QTabWidget>
19#include <QVBoxLayout>
20#include <QWindow>
21
22#include "addressline/completionorder/completionorderwidget.h"
23#include <config-akonadi-search.h>
24#if !DISABLE_AKONADI_SEARCH
25#include "addressline/blacklistbaloocompletion/blacklistbalooemailcompletionwidget.h"
26#endif
27#include "addressline/recentaddress/recentaddresswidget.h"
28
29using namespace PimCommon;
30namespace
31{
32static const char myCompletionConfigureDialogGroupName[] = "CompletionConfigureDialog";
33}
34class PimCommon::CompletionConfigureDialogPrivate
35{
36public:
37 CompletionConfigureDialogPrivate() = default;
38
39 QTabWidget *mTabWidget = nullptr;
40 PimCommon::CompletionOrderWidget *mCompletionOrderWidget = nullptr;
41#if !DISABLE_AKONADI_SEARCH
42 PimCommon::BlackListBalooEmailCompletionWidget *mBlackListBalooWidget = nullptr;
43#endif
44 PimCommon::RecentAddressWidget *mRecentaddressWidget = nullptr;
45};
46
47CompletionConfigureDialog::CompletionConfigureDialog(QWidget *parent)
48 : QDialog(parent)
49 , d(new PimCommon::CompletionConfigureDialogPrivate)
50{
51 setWindowTitle(i18nc("@title:window", "Configure Completion"));
52 auto mainLayout = new QVBoxLayout(this);
53
54 d->mTabWidget = new QTabWidget(this);
55 d->mTabWidget->setObjectName("tabwidget"_L1);
56 mainLayout->addWidget(d->mTabWidget);
57
58 d->mCompletionOrderWidget = new PimCommon::CompletionOrderWidget(this);
59 d->mCompletionOrderWidget->setObjectName("completionorder_widget"_L1);
60 d->mTabWidget->addTab(d->mCompletionOrderWidget, i18n("Completion Order"));
61
62 d->mRecentaddressWidget = new PimCommon::RecentAddressWidget(this);
63 d->mRecentaddressWidget->setObjectName("recentaddress_widget"_L1);
64 d->mTabWidget->addTab(d->mRecentaddressWidget, i18n("Recent Address"));
65
66#if !DISABLE_AKONADI_SEARCH
67 d->mBlackListBalooWidget = new PimCommon::BlackListBalooEmailCompletionWidget(this);
68 d->mBlackListBalooWidget->setObjectName("blacklistbaloo_widget"_L1);
69 d->mTabWidget->addTab(d->mBlackListBalooWidget, i18n("Blacklist Email Address"));
70#endif
71
73 buttonBox->setObjectName("buttonbox"_L1);
74 connect(buttonBox, &QDialogButtonBox::accepted, this, &CompletionConfigureDialog::slotSaveAndClose);
75 connect(buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &CompletionConfigureDialog::slotSave);
77 mainLayout->addWidget(buttonBox);
78 readConfig();
79}
80
81CompletionConfigureDialog::~CompletionConfigureDialog()
82{
83 writeConfig();
84}
85
86void CompletionConfigureDialog::readConfig()
87{
88 create(); // ensure a window is created
89 windowHandle()->resize(QSize(600, 400));
90 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myCompletionConfigureDialogGroupName));
92 resize(windowHandle()->size()); // workaround for QTBUG-40584
93}
94
95void CompletionConfigureDialog::writeConfig()
96{
97 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myCompletionConfigureDialogGroupName));
99}
100
101void CompletionConfigureDialog::setRecentAddresses(const QStringList &lst)
102{
103 d->mRecentaddressWidget->setAddresses(lst);
104}
105
106void CompletionConfigureDialog::setLdapClientSearch(KLDAPCore::LdapClientSearch *ldapSearch)
107{
108 d->mCompletionOrderWidget->setLdapClientSearch(ldapSearch);
109}
110
111void CompletionConfigureDialog::load()
112{
113 d->mCompletionOrderWidget->loadCompletionItems();
114#if !DISABLE_AKONADI_SEARCH
115 d->mBlackListBalooWidget->load();
116#endif
117}
118
119bool CompletionConfigureDialog::recentAddressWasChanged() const
120{
121 return d->mRecentaddressWidget->wasChanged();
122}
123
124void CompletionConfigureDialog::storeAddresses(KConfig *config)
125{
126 d->mRecentaddressWidget->storeAddresses(config);
127}
128
129void CompletionConfigureDialog::slotSaveAndClose()
130{
131 slotSave();
132 accept();
133}
134
135void CompletionConfigureDialog::slotSave()
136{
137#if !DISABLE_AKONADI_SEARCH
138 d->mBlackListBalooWidget->save();
139#endif
140 d->mCompletionOrderWidget->save();
141}
142
143void CompletionConfigureDialog::setEmailBlackList(const QStringList &lst)
144{
145#if !DISABLE_AKONADI_SEARCH
146 d->mBlackListBalooWidget->setEmailBlackList(lst);
147#endif
148}
149
150#include "moc_completionconfiguredialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
The RecentAddressWidget class.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
folderdialogacltab.h
void clicked(bool checked)
virtual void accept()
virtual void reject()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
void resize(const QSize &)
QWindow * windowHandle() const const
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.