Akonadi

cachepolicypage.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
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 
17 using namespace Akonadi;
18 
19 class Akonadi::CachePolicyPagePrivate
20 {
21 public:
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 
40 void CachePolicyPagePrivate::slotIntervalValueChanged(int interval)
41 {
42  mUi->checkInterval->setSuffix(QLatin1Char(' ') + i18np("minute", "minutes", interval));
43 }
44 
45 void CachePolicyPagePrivate::slotCacheValueChanged(int interval)
46 {
47  mUi->localCacheTimeout->setSuffix(QLatin1Char(' ') + i18np("minute", "minutes", interval));
48 }
49 
50 void 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 
65  : CollectionPropertiesPage(parent)
66  , d(new CachePolicyPagePrivate)
67 {
68  setObjectName(QStringLiteral("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 
95 bool Akonadi::CachePolicyPage::canHandle(const Collection &collection) const
96 {
97  return !collection.isVirtual();
98 }
99 
100 void 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(QLatin1String("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(QLatin1String("RFC822"))) {
157  localParts.append(QStringLiteral("RFC822"));
158  } else if (!d->mUi->retrieveFullMessages->isChecked() && localParts.contains(QLatin1String("RFC822"))) {
159  localParts.removeAll(QStringLiteral("RFC822"));
160  }
161  }
162 
163  policy.setLocalParts(localParts);
164  collection.setCachePolicy(policy);
165 }
166 
167 #include "moc_cachepolicypage.cpp"
void append(const T &value)
int cacheTimeout() const
Returns the cache timeout for non-permanently cached parts in minutes; -1 means indefinitely.
Definition: cachepolicy.cpp:75
@ AdvancedMode
An advanced UI for debugging will be provided.
CachePolicyPage(QWidget *parent, GuiMode mode=UserMode)
Creates a new cache policy page.
void setPageTitle(const QString &title)
Sets the page title.
int removeAll(const T &value)
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
Represents a collection of PIM items.
Definition: collection.h:61
int intervalCheckTime() const
Returns the interval check time in minutes, -1 for never.
Definition: cachepolicy.cpp:85
Represents the caching policy for a collection.
Definition: cachepolicy.h:59
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void toggled(bool checked)
GuiMode
Describes the mode of the cache policy page.
void save(Collection &collection) override
Saves page content to the given collection.
void setInheritFromParent(bool inherit)
Sets whether the cache policy should be inherited from the parent collection.
Definition: cachepolicy.cpp:60
QString i18n(const char *text, const TYPE &arg...)
CachePolicy cachePolicy() const
Returns the cache policy of the collection.
Definition: collection.cpp:336
void setCachePolicy(const CachePolicy &policy)
Sets the cache policy of the collection.
Definition: collection.cpp:341
QStringList localParts() const
Returns the parts to permanently cache locally.
Definition: cachepolicy.cpp:65
bool syncOnDemand() const
Returns whether the collection will be synced automatically when necessary, i.e.
Definition: cachepolicy.cpp:95
A page in a collection properties dialog to configure the cache policy.
void setSyncOnDemand(bool enable)
Sets whether the collection shall be synced automatically when necessary, i.e.
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
void setCacheTimeout(int timeout)
Sets cache timeout for non-permanently cached parts.
Definition: cachepolicy.cpp:80
void setIntervalCheckTime(int time)
Sets interval check time.
Definition: cachepolicy.cpp:90
void setObjectName(const QString &name)
bool inheritFromParent() const
Returns whether it inherits cache policy from the parent collection.
Definition: cachepolicy.cpp:55
void load(const Collection &collection) override
Loads the page content from the given collection.
void valueChanged(int i)
bool canHandle(const Collection &collection) const override
Checks if the cache policy page can actually handle the given collection.
A single page in a collection properties dialog.
~CachePolicyPage() override
Destroys the cache policy page.
Helper integration between Akonadi and Qt.
void setLocalParts(const QStringList &parts)
Specifies the parts to permanently cache locally.
Definition: cachepolicy.cpp:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Jun 6 2023 03:52:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.