Akonadi

cachepolicypage.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "cachepolicypage.h"
21 
22 #include "ui_cachepolicypage.h"
23 
24 #include "cachepolicy.h"
25 #include "collection.h"
26 #include "collectionutils.h"
27 
28 #include <KLocalizedString>
29 
30 using namespace Akonadi;
31 
32 class Q_DECL_HIDDEN CachePolicyPage::Private
33 {
34 public:
35  Private()
36  : mUi(new Ui::CachePolicyPage)
37  {
38  }
39 
40  ~Private()
41  {
42  delete mUi;
43  }
44 
45  void slotIntervalValueChanged(int);
46  void slotCacheValueChanged(int);
47  void slotRetrievalOptionsGroupBoxDisabled(bool disable);
48 
49  Ui::CachePolicyPage *mUi = nullptr;
50 };
51 
52 void CachePolicyPage::Private::slotIntervalValueChanged(int interval)
53 {
54  mUi->checkInterval->setSuffix(QLatin1Char(' ') + i18np("minute", "minutes", interval));
55 }
56 
57 void CachePolicyPage::Private::slotCacheValueChanged(int interval)
58 {
59  mUi->localCacheTimeout->setSuffix(QLatin1Char(' ') + i18np("minute", "minutes", interval));
60 }
61 
62 void CachePolicyPage::Private::slotRetrievalOptionsGroupBoxDisabled(bool disable)
63 {
64  mUi->retrievalOptionsGroupBox->setDisabled(disable);
65  if (!disable) {
66  mUi->label->setEnabled(mUi->retrieveOnlyHeaders->isChecked());
67  mUi->localCacheTimeout->setEnabled(mUi->retrieveOnlyHeaders->isChecked());
68  }
69 }
70 
72  : CollectionPropertiesPage(parent)
73  , d(new Private)
74 {
75  setObjectName(QStringLiteral("Akonadi::CachePolicyPage"));
76  setPageTitle(i18n("Retrieval"));
77 
78  d->mUi->setupUi(this);
79  connect(d->mUi->checkInterval, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int value) { d->slotIntervalValueChanged(value); });
80  connect(d->mUi->localCacheTimeout, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int value) { d->slotCacheValueChanged(value); });
81  connect(d->mUi->inherit, &QCheckBox::toggled, this, [this](bool checked) { d->slotRetrievalOptionsGroupBoxDisabled(checked); });
82  if (mode == AdvancedMode) {
83  d->mUi->stackedWidget->setCurrentWidget(d->mUi->rawPage);
84  }
85 }
86 
88 {
89  delete d;
90 }
91 
92 bool Akonadi::CachePolicyPage::canHandle(const Collection &collection) const
93 {
94  return !collection.isVirtual();
95 }
96 
97 void CachePolicyPage::load(const Collection &collection)
98 {
99  const CachePolicy policy = collection.cachePolicy();
100 
101  int interval = policy.intervalCheckTime();
102  if (interval == -1) {
103  interval = 0;
104  }
105 
106  int cache = policy.cacheTimeout();
107  if (cache == -1) {
108  cache = 0;
109  }
110 
111  d->mUi->inherit->setChecked(policy.inheritFromParent());
112  d->mUi->checkInterval->setValue(interval);
113  d->mUi->localCacheTimeout->setValue(cache);
114  d->mUi->syncOnDemand->setChecked(policy.syncOnDemand());
115  d->mUi->localParts->setItems(policy.localParts());
116 
117  const bool fetchBodies = policy.localParts().contains(QLatin1String("RFC822"));
118  d->mUi->retrieveFullMessages->setChecked(fetchBodies);
119 
120  //done explicitly to disable/enabled widgets
121  d->mUi->retrieveOnlyHeaders->setChecked(!fetchBodies);
122  d->mUi->label->setEnabled(!fetchBodies);
123  d->mUi->localCacheTimeout->setEnabled(!fetchBodies);
124 }
125 
127 {
128  int interval = d->mUi->checkInterval->value();
129  if (interval == 0) {
130  interval = -1;
131  }
132 
133  int cache = d->mUi->localCacheTimeout->value();
134  if (cache == 0) {
135  cache = -1;
136  }
137 
138  CachePolicy policy = collection.cachePolicy();
139  policy.setInheritFromParent(d->mUi->inherit->isChecked());
140  policy.setIntervalCheckTime(interval);
141  policy.setCacheTimeout(cache);
142  policy.setSyncOnDemand(d->mUi->syncOnDemand->isChecked());
143 
144  QStringList localParts = d->mUi->localParts->items();
145 
146  // Unless we are in "raw" mode, add "bodies" to the list of message
147  // parts to keep around locally, if the user selected that, or remove
148  // it otherwise. In "raw" mode we simple use the values from the list
149  // view.
150  if (d->mUi->stackedWidget->currentWidget() != d->mUi->rawPage) {
151  if (d->mUi->retrieveFullMessages->isChecked() &&
152  !localParts.contains(QLatin1String("RFC822"))) {
153  localParts.append(QStringLiteral("RFC822"));
154  } else if (!d->mUi->retrieveFullMessages->isChecked() &&
155  localParts.contains(QLatin1String("RFC822"))) {
156  localParts.removeAll(QStringLiteral("RFC822"));
157  }
158  }
159 
160  policy.setLocalParts(localParts);
161  collection.setCachePolicy(policy);
162 }
163 
164 #include "moc_cachepolicypage.cpp"
An advanced UI for debugging will be provided.
int intervalCheckTime() const
Returns the interval check time in minutes, -1 for never.
void setSyncOnDemand(bool enable)
Sets whether the collection shall be synced automatically when necessary, i.e.
bool inheritFromParent() const
Returns whether it inherits cache policy from the parent collection.
Definition: cachepolicy.cpp:85
GuiMode
Describes the mode of the cache policy page.
void setIntervalCheckTime(int time)
Sets interval check time.
void setCacheTimeout(int timeout)
Sets cache timeout for non-permanently cached parts.
Represents a collection of PIM items.
Definition: collection.h:76
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
A single page in a collection properties dialog.
void save(Collection &collection) override
Saves page content to the given collection.
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
void setPageTitle(const QString &title)
Sets the page title.
void valueChanged(int i)
void append(const T &value)
void setObjectName(const QString &name)
int removeAll(const T &value)
int cacheTimeout() const
Returns the cache timeout for non-permanently cached parts in minutes; -1 means indefinitely.
bool canHandle(const Collection &collection) const override
Checks if the cache policy page can actually handle the given collection.
Represents the caching policy for a collection.
Definition: cachepolicy.h:72
void setCachePolicy(const CachePolicy &policy)
Sets the cache policy of the collection.
Definition: collection.cpp:358
void setLocalParts(const QStringList &parts)
Specifies the parts to permanently cache locally.
QString i18n(const char *text, const TYPE &arg...)
Helper integration between Akonadi and Qt.
void toggled(bool checked)
CachePolicy cachePolicy() const
Returns the cache policy of the collection.
Definition: collection.cpp:353
QStringList localParts() const
Returns the parts to permanently cache locally.
Definition: cachepolicy.cpp:95
~CachePolicyPage() override
Destroys the cache policy page.
void load(const Collection &collection) override
Loads the page content from the given collection.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
CachePolicyPage(QWidget *parent, GuiMode mode=UserMode)
Creates a new cache policy page.
A page in a collection properties dialog to configure the cache policy.
void setInheritFromParent(bool inherit)
Sets whether the cache policy should be inherited from the parent collection.
Definition: cachepolicy.cpp:90
bool isVirtual() const
Returns whether the collection is virtual, for example a search collection.
Definition: collection.cpp:364
bool syncOnDemand() const
Returns whether the collection will be synced automatically when necessary, i.e.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.