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/blacklistakonadisearchcompletion/blacklistakonadisearchemailcompletionwidget.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::BlackListAkonadiSearchEmailCompletionWidget *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::BlackListAkonadiSearchEmailCompletionWidget(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::setLdapActivitiesAbstract(KLDAPCore::LdapActivitiesAbstract *ldapActivities)
112{
113 d->mCompletionOrderWidget->setLdapActivitiesAbstract(ldapActivities);
114}
115
116void CompletionConfigureDialog::load()
117{
118 d->mCompletionOrderWidget->loadCompletionItems();
119#if !DISABLE_AKONADI_SEARCH
120 d->mBlackListBalooWidget->load();
121#endif
122}
123
124bool CompletionConfigureDialog::recentAddressWasChanged() const
125{
126 return d->mRecentaddressWidget->wasChanged();
127}
128
129void CompletionConfigureDialog::storeAddresses(KConfig *config)
130{
131 d->mRecentaddressWidget->storeAddresses(config);
132}
133
134void CompletionConfigureDialog::slotSaveAndClose()
135{
136 slotSave();
137 accept();
138}
139
140void CompletionConfigureDialog::slotSave()
141{
142#if !DISABLE_AKONADI_SEARCH
143 d->mBlackListBalooWidget->save();
144#endif
145 d->mCompletionOrderWidget->save();
146}
147
148void CompletionConfigureDialog::setEmailBlackList(const QStringList &lst)
149{
150#if !DISABLE_AKONADI_SEARCH
151 d->mBlackListBalooWidget->setEmailBlackList(lst);
152#endif
153}
154
155#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 Sat Dec 21 2024 17:02:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.