Akonadi

cachepolicypage.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "cachepolicypage.h"
8
9#include "ui_cachepolicypage.h"
10
11#include "cachepolicy.h"
12#include "collection.h"
13#include "collectionutils.h"
14
15#include <KLocalizedString>
16
17using namespace Akonadi;
18using namespace Qt::StringLiterals;
19
20class Akonadi::CachePolicyPagePrivate
21{
22public:
23 CachePolicyPagePrivate()
24 : mUi(new Ui::CachePolicyPage)
25 {
26 }
27
28 ~CachePolicyPagePrivate()
29 {
30 delete mUi;
31 }
32
33 void slotIntervalValueChanged(int /*interval*/);
34 void slotCacheValueChanged(int /*interval*/);
35 void slotRetrievalOptionsGroupBoxDisabled(bool disable);
36
37 Ui::CachePolicyPage *const mUi;
39};
40
41void CachePolicyPagePrivate::slotIntervalValueChanged(int interval)
42{
43 mUi->checkInterval->setSuffix(QLatin1Char(' ') + i18np("minute", "minutes", interval));
44}
45
46void CachePolicyPagePrivate::slotCacheValueChanged(int interval)
47{
48 mUi->localCacheTimeout->setSuffix(QLatin1Char(' ') + i18np("minute", "minutes", interval));
49}
50
51void CachePolicyPagePrivate::slotRetrievalOptionsGroupBoxDisabled(bool disable)
52{
53 mUi->retrieveFullMessages->setDisabled(disable);
54 mUi->retrieveFullMessages->setDisabled(disable);
55 mUi->retrieveOnlyHeaders->setDisabled(disable);
56 mUi->localCacheTimeout->setDisabled(disable);
57 mUi->retrievalOptionsLabel->setDisabled(disable);
58 mUi->label->setDisabled(disable);
59 if (!disable) {
60 mUi->label->setEnabled(mUi->retrieveOnlyHeaders->isChecked());
61 mUi->localCacheTimeout->setEnabled(mUi->retrieveOnlyHeaders->isChecked());
62 }
63}
64
67 , d(new CachePolicyPagePrivate)
68{
69 setObjectName(QLatin1StringView("Akonadi::CachePolicyPage"));
70 setPageTitle(i18n("Retrieval"));
71 d->mode = mode;
72
73 d->mUi->setupUi(this);
74 connect(d->mUi->checkInterval, &QSpinBox::valueChanged, this, [this](int value) {
75 d->slotIntervalValueChanged(value);
76 });
77 connect(d->mUi->localCacheTimeout, &QSpinBox::valueChanged, this, [this](int value) {
78 d->slotCacheValueChanged(value);
79 });
80 connect(d->mUi->inherit, &QCheckBox::toggled, this, [this](bool checked) {
81 d->slotRetrievalOptionsGroupBoxDisabled(checked);
82 });
83 if (mode == AdvancedMode) {
84 d->mUi->retrievalOptionsLabel->hide();
85 d->mUi->retrieveFullMessages->hide();
86 d->mUi->retrieveOnlyHeaders->hide();
87 d->mUi->localCacheTimeout->hide();
88 } else {
89 d->mUi->localParts->hide();
90 d->mUi->localPartsLabel->hide();
91 }
92}
93
95
97{
98 return !collection.isVirtual();
99}
100
101void CachePolicyPage::load(const Collection &collection)
102{
103 const CachePolicy policy = collection.cachePolicy();
104
105 int interval = policy.intervalCheckTime();
106 if (interval == -1) {
107 interval = 0;
108 }
109
110 int cache = policy.cacheTimeout();
111 if (cache == -1) {
112 cache = 0;
113 }
114
115 d->mUi->checkInterval->setValue(interval);
116 d->mUi->localCacheTimeout->setValue(cache);
117 d->mUi->syncOnDemand->setChecked(policy.syncOnDemand());
118 d->mUi->localParts->setItems(policy.localParts());
119
120 const bool fetchBodies = policy.localParts().contains(QLatin1StringView("RFC822"));
121 d->mUi->retrieveFullMessages->setChecked(fetchBodies);
122
123 // done explicitly to disable/enabled widgets
124 d->mUi->retrieveOnlyHeaders->setChecked(!fetchBodies);
125 d->mUi->label->setEnabled(!fetchBodies);
126 d->mUi->localCacheTimeout->setEnabled(!fetchBodies);
127 // last code otherwise it will call slotRetrievalOptionsGroupBoxDisabled before
128 // calling d->mUi->label->setEnabled(!fetchBodies);
129 d->mUi->inherit->setChecked(policy.inheritFromParent());
130
131 const auto containsEmails = collection.contentMimeTypes().contains(u"message/rfc822"_s);
132 d->mUi->retrievalOptionsLabel->setVisible(containsEmails);
133 d->mUi->retrieveFullMessages->setVisible(containsEmails);
134 d->mUi->retrieveOnlyHeaders->setVisible(containsEmails);
135 d->mUi->label->setVisible(containsEmails);
136 d->mUi->localCacheTimeout->setVisible(containsEmails);
137}
138
140{
141 int interval = d->mUi->checkInterval->value();
142 if (interval == 0) {
143 interval = -1;
144 }
145
146 int cache = d->mUi->localCacheTimeout->value();
147 if (cache == 0) {
148 cache = -1;
149 }
150
151 CachePolicy policy = collection.cachePolicy();
152 policy.setInheritFromParent(d->mUi->inherit->isChecked());
153 policy.setIntervalCheckTime(interval);
154 policy.setCacheTimeout(cache);
155 policy.setSyncOnDemand(d->mUi->syncOnDemand->isChecked());
156
157 QStringList localParts = d->mUi->localParts->items();
158
159 // Unless we are in "raw" mode, add "bodies" to the list of message
160 // parts to keep around locally, if the user selected that, or remove
161 // it otherwise. In "raw" mode we simple use the values from the list
162 // view.
163 if (d->mode != AdvancedMode) {
164 if (d->mUi->retrieveFullMessages->isChecked() && !localParts.contains(QLatin1StringView("RFC822"))) {
165 localParts.append(QStringLiteral("RFC822"));
166 } else if (!d->mUi->retrieveFullMessages->isChecked() && localParts.contains(QLatin1StringView("RFC822"))) {
167 localParts.removeAll(QStringLiteral("RFC822"));
168 }
169 }
170
171 policy.setLocalParts(localParts);
172 collection.setCachePolicy(policy);
173}
174
175#include "moc_cachepolicypage.cpp"
bool canHandle(const Collection &collection) const override
Checks if the cache policy page can actually handle the given collection.
CachePolicyPage(QWidget *parent, GuiMode mode=UserMode)
Creates a new cache policy page.
void load(const Collection &collection) override
Loads the page content from the given collection.
void save(Collection &collection) override
Saves page content to the given collection.
GuiMode
Describes the mode of the cache policy page.
@ AdvancedMode
An advanced UI for debugging will be provided.
~CachePolicyPage() override
Destroys the cache policy page.
Represents the caching policy for a collection.
Definition cachepolicy.h:61
void setLocalParts(const QStringList &parts)
Specifies the parts to permanently cache locally.
void setIntervalCheckTime(int time)
Sets interval check time.
void setCacheTimeout(int timeout)
Sets cache timeout for non-permanently cached parts.
void setInheritFromParent(bool inherit)
Sets whether the cache policy should be inherited from the parent collection.
void setSyncOnDemand(bool enable)
Sets whether the collection shall be synced automatically when necessary, i.e.
void setPageTitle(const QString &title)
Sets the page title.
CollectionPropertiesPage(QWidget *parent=nullptr)
Creates a new collection properties page.
Represents a collection of PIM items.
Definition collection.h:62
void setCachePolicy(const CachePolicy &policy)
Sets the cache policy of the collection.
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Helper integration between Akonadi and Qt.
void toggled(bool checked)
void append(QList< T > &&value)
qsizetype removeAll(const AT &t)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
void setObjectName(QAnyStringView name)
void valueChanged(int i)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QWidget(QWidget *parent, Qt::WindowFlags f)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:53:22 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.