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;
18
19class Akonadi::CachePolicyPagePrivate
20{
21public:
22 CachePolicyPagePrivate()
23 : mUi(new Ui::CachePolicyPage)
24 {
25 }
26
27 ~CachePolicyPagePrivate()
28 {
29 delete mUi;
30 }
31
32 void slotIntervalValueChanged(int /*interval*/);
33 void slotCacheValueChanged(int /*interval*/);
34 void slotRetrievalOptionsGroupBoxDisabled(bool disable);
35
36 Ui::CachePolicyPage *const mUi;
38};
39
40void CachePolicyPagePrivate::slotIntervalValueChanged(int interval)
41{
42 mUi->checkInterval->setSuffix(QLatin1Char(' ') + i18np("minute", "minutes", interval));
43}
44
45void CachePolicyPagePrivate::slotCacheValueChanged(int interval)
46{
47 mUi->localCacheTimeout->setSuffix(QLatin1Char(' ') + i18np("minute", "minutes", interval));
48}
49
50void CachePolicyPagePrivate::slotRetrievalOptionsGroupBoxDisabled(bool disable)
51{
52 mUi->retrieveFullMessages->setDisabled(disable);
53 mUi->retrieveFullMessages->setDisabled(disable);
54 mUi->retrieveOnlyHeaders->setDisabled(disable);
55 mUi->localCacheTimeout->setDisabled(disable);
56 mUi->retrievalOptionsLabel->setDisabled(disable);
57 mUi->label->setDisabled(disable);
58 if (!disable) {
59 mUi->label->setEnabled(mUi->retrieveOnlyHeaders->isChecked());
60 mUi->localCacheTimeout->setEnabled(mUi->retrieveOnlyHeaders->isChecked());
61 }
62}
63
66 , d(new CachePolicyPagePrivate)
67{
68 setObjectName(QLatin1StringView("Akonadi::CachePolicyPage"));
69 setPageTitle(i18n("Retrieval"));
70 d->mode = mode;
71
72 d->mUi->setupUi(this);
73 connect(d->mUi->checkInterval, &QSpinBox::valueChanged, this, [this](int value) {
74 d->slotIntervalValueChanged(value);
75 });
76 connect(d->mUi->localCacheTimeout, &QSpinBox::valueChanged, this, [this](int value) {
77 d->slotCacheValueChanged(value);
78 });
79 connect(d->mUi->inherit, &QCheckBox::toggled, this, [this](bool checked) {
80 d->slotRetrievalOptionsGroupBoxDisabled(checked);
81 });
82 if (mode == AdvancedMode) {
83 d->mUi->retrievalOptionsLabel->hide();
84 d->mUi->retrieveFullMessages->hide();
85 d->mUi->retrieveOnlyHeaders->hide();
86 d->mUi->localCacheTimeout->hide();
87 } else {
88 d->mUi->localParts->hide();
89 d->mUi->localPartsLabel->hide();
90 }
91}
92
94
96{
97 return !collection.isVirtual();
98}
99
100void CachePolicyPage::load(const Collection &collection)
101{
102 const CachePolicy policy = collection.cachePolicy();
103
104 int interval = policy.intervalCheckTime();
105 if (interval == -1) {
106 interval = 0;
107 }
108
109 int cache = policy.cacheTimeout();
110 if (cache == -1) {
111 cache = 0;
112 }
113
114 d->mUi->checkInterval->setValue(interval);
115 d->mUi->localCacheTimeout->setValue(cache);
116 d->mUi->syncOnDemand->setChecked(policy.syncOnDemand());
117 d->mUi->localParts->setItems(policy.localParts());
118
119 const bool fetchBodies = policy.localParts().contains(QLatin1StringView("RFC822"));
120 d->mUi->retrieveFullMessages->setChecked(fetchBodies);
121
122 // done explicitly to disable/enabled widgets
123 d->mUi->retrieveOnlyHeaders->setChecked(!fetchBodies);
124 d->mUi->label->setEnabled(!fetchBodies);
125 d->mUi->localCacheTimeout->setEnabled(!fetchBodies);
126 // last code otherwise it will call slotRetrievalOptionsGroupBoxDisabled before
127 // calling d->mUi->label->setEnabled(!fetchBodies);
128 d->mUi->inherit->setChecked(policy.inheritFromParent());
129}
130
132{
133 int interval = d->mUi->checkInterval->value();
134 if (interval == 0) {
135 interval = -1;
136 }
137
138 int cache = d->mUi->localCacheTimeout->value();
139 if (cache == 0) {
140 cache = -1;
141 }
142
143 CachePolicy policy = collection.cachePolicy();
144 policy.setInheritFromParent(d->mUi->inherit->isChecked());
145 policy.setIntervalCheckTime(interval);
146 policy.setCacheTimeout(cache);
147 policy.setSyncOnDemand(d->mUi->syncOnDemand->isChecked());
148
149 QStringList localParts = d->mUi->localParts->items();
150
151 // Unless we are in "raw" mode, add "bodies" to the list of message
152 // parts to keep around locally, if the user selected that, or remove
153 // it otherwise. In "raw" mode we simple use the values from the list
154 // view.
155 if (d->mode != AdvancedMode) {
156 if (d->mUi->retrieveFullMessages->isChecked() && !localParts.contains(QLatin1StringView("RFC822"))) {
157 localParts.append(QStringLiteral("RFC822"));
158 } else if (!d->mUi->retrieveFullMessages->isChecked() && localParts.contains(QLatin1StringView("RFC822"))) {
159 localParts.removeAll(QStringLiteral("RFC822"));
160 }
161 }
162
163 policy.setLocalParts(localParts);
164 collection.setCachePolicy(policy);
165}
166
167#include "moc_cachepolicypage.cpp"
A page in a collection properties dialog to configure the cache policy.
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:60
int cacheTimeout() const
Returns the cache timeout for non-permanently cached parts in minutes; -1 means indefinitely.
bool inheritFromParent() const
Returns whether it inherits cache policy from the parent collection.
int intervalCheckTime() const
Returns the interval check time in minutes, -1 for never.
void setLocalParts(const QStringList &parts)
Specifies the parts to permanently cache locally.
QStringList localParts() const
Returns the parts to permanently cache locally.
bool syncOnDemand() const
Returns whether the collection will be synced automatically when necessary, i.e.
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.
A single page in a collection properties dialog.
void setPageTitle(const QString &title)
Sets the page title.
Represents a collection of PIM items.
Definition collection.h:62
CachePolicy cachePolicy() const
Returns the cache policy of the collection.
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)
T qobject_cast(QObject *object)
void setObjectName(QAnyStringView name)
void valueChanged(int i)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:51:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.