Commit 81a9e5d2 authored by Volker Krause's avatar Volker Krause

Rewrite the cache policy stuff. Editing policies works, but they are so far

only honord by the cache cleaner.

svn path=/trunk/KDE/kdepim/akonadi/libakonadi/; revision=770143
parent eed70ed2
......@@ -34,6 +34,8 @@ set( akonadi_LIB_SRC
agentmanager.cpp
agenttypemodel.cpp
agentfilterproxymodel.cpp
cachepolicy.cpp
cachepolicypage.cpp
changerecorder.cpp
collection.cpp
collectionattribute.cpp
......@@ -77,6 +79,7 @@ set( akonadi_LIB_SRC
monitor_p.cpp
profilemanager.cpp
profilemodel.cpp
protocolhelper.cpp
resourcebase.cpp
resourcescheduler.cpp
searchcreatejob.cpp
......@@ -99,6 +102,7 @@ qt4_add_dbus_interfaces(akonadi_LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../server/in
qt4_add_dbus_adaptor( akonadi_LIB_SRC ${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.Resource.xml resourcebase.h Akonadi::ResourceBase )
qt4_add_dbus_adaptor( akonadi_LIB_SRC ${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.Agent.xml agentbase.h Akonadi::AgentBase )
kde4_add_ui_files( akonadi_LIB_SRC
cachepolicypage.ui
collectiongeneralpropertiespage.ui
subscriptiondialog.ui
)
......
/*
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "cachepolicy.h"
using namespace Akonadi;
class CachePolicy::Private : public QSharedData
{
public:
Private() :
QSharedData(),
inherit( true ),
timeout( -1 ),
interval( -1 ),
syncOnDemand( false )
{}
Private( const Private &other ) :
QSharedData( other )
{
inherit = other.inherit;
localParts = other.localParts;
timeout = other.timeout;
interval = other.interval;
syncOnDemand = other.syncOnDemand;
}
bool inherit;
QStringList localParts;
int timeout;
int interval;
bool syncOnDemand;
};
CachePolicy::CachePolicy() :
d( new Private )
{
}
CachePolicy::CachePolicy(const CachePolicy & other) :
d( other.d )
{
}
CachePolicy::~ CachePolicy()
{
}
CachePolicy & CachePolicy::operator =(const CachePolicy & other)
{
d = other.d;
return *this;
}
bool CachePolicy::inheritFromParent() const
{
return d->inherit;
}
void CachePolicy::setInheritFromParent(bool inherit)
{
d->inherit = inherit;
}
QStringList CachePolicy::localParts() const
{
return d->localParts;
}
void CachePolicy::setLocalParts(const QStringList & parts)
{
d->localParts = parts;
}
int CachePolicy::cacheTimeout() const
{
return d->timeout;
}
void CachePolicy::setCacheTimeout(int timeout)
{
d->timeout = timeout;
}
int CachePolicy::intervalCheckTime() const
{
return d->interval;
}
void CachePolicy::setIntervalCheckTime(int time)
{
d->interval = time;
}
bool CachePolicy::syncOnDemand() const
{
return d->syncOnDemand;
}
void CachePolicy::enableSyncOnDemand(bool enable)
{
d->syncOnDemand = enable;
}
/*
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef AKONADI_CACHEPOLICY_H
#define AKONADI_CACHEPOLICY_H
#include "libakonadi_export.h"
#include <QtCore/QSharedDataPointer>
#include <QtCore/QStringList>
namespace Akonadi {
/**
Represents the caching policy for a collection.
@todo on a POP3 account, is should not be possible to change locally cached parts, find a solution for that
*/
class AKONADI_EXPORT CachePolicy
{
public:
/**
Create a empty cache policy.
*/
CachePolicy();
/**
Copy constructor.
*/
CachePolicy( const CachePolicy &other );
/**
Destructor.
*/
~CachePolicy();
/**
Assignement operator.
*/
CachePolicy& operator=( const CachePolicy &other );
/**
Inherit cache policy from parent collection.
*/
bool inheritFromParent() const;
/**
Set if the cache policy should be inherited from the parent collection.
*/
void setInheritFromParent( bool inherit );
/**
Parts to permanently cache locally.
*/
QStringList localParts() const;
/**
Specify the parts to permanently cache locally.
*/
void setLocalParts( const QStringList &parts );
/**
Cache timeout for non-permanently cached parts in minutes,
-1 means indefinitely.
*/
int cacheTimeout() const;
/**
Set cache timeout for non-permanently cached parts.
@param timeout Timeout in minutes, -1 for indefinitely.
*/
void setCacheTimeout( int timeout );
/**
Interval check time in minutes, -1 for never.
*/
int intervalCheckTime() const;
/**
Set interval check time.
@param time Check time interval in minutes, -1 for never.
*/
void setIntervalCheckTime( int time );
/**
Sync collection automatically on every access.
*/
bool syncOnDemand() const;
/**
Enable on-demand syncing.
*/
void enableSyncOnDemand( bool enable );
private:
class Private;
QSharedDataPointer<Private> d;
};
}
#endif
/*
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "cachepolicypage.h"
using namespace Akonadi;
CachePolicyPage::CachePolicyPage(QWidget * parent) :
CollectionPropertiesPage( parent )
{
setPageTitle( i18n( "&Cache" ) );
ui.setupUi( this );
}
void CachePolicyPage::load(const Collection & collection)
{
CachePolicy policy = collection.cachePolicy();
ui.inherit->setChecked( policy.inheritFromParent() );
ui.checkInterval->setValue( policy.intervalCheckTime() );
ui.localCacheTimeout->setValue( policy.cacheTimeout() );
ui.syncOnDemand->setChecked( policy.syncOnDemand() );
ui.localParts->setItems( policy.localParts() );
}
void CachePolicyPage::save(Collection & collection)
{
CachePolicy policy = collection.cachePolicy();
policy.setInheritFromParent( ui.inherit->isChecked() );
policy.setIntervalCheckTime( ui.checkInterval->value() );
policy.setCacheTimeout( ui.localCacheTimeout->value() );
policy.enableSyncOnDemand( ui.syncOnDemand->isChecked() );
policy.setLocalParts( ui.localParts->items() );
collection.setCachePolicy( policy );
}
/*
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef AKONADI_CACHEPOLICYPAGE_H
#define AKONADI_CACHEPOLICYPAGE_H
#include <libakonadi/collectionpropertiespage.h>
#include "ui_cachepolicypage.h"
namespace Akonadi {
/**
@internal
Cache policy configuration page.
*/
class CachePolicyPage : public CollectionPropertiesPage
{
Q_OBJECT
public:
explicit CachePolicyPage( QWidget * parent );
void load( const Collection &collection );
void save( Collection &collection );
private:
Ui::CachePolicyPage ui;
};
AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY(CachePolicyPageFactory, CachePolicyPage)
}
#endif
<ui version="4.0" >
<class>CachePolicyPage</class>
<widget class="QWidget" name="CachePolicyPage" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>602</width>
<height>461</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="inherit" >
<property name="text" >
<string>Inherit cache policy from parent</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
<property name="tristate" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="title" >
<string>Cache Policy</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Interval check time:</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="KIntNumInput" name="checkInterval" >
<property name="value" >
<number>-1</number>
</property>
<property name="minimum" >
<number>-1</number>
</property>
<property name="suffix" >
<string>minutes</string>
</property>
<property name="specialValueText" >
<string>Never</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Local cache timerout:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="KIntNumInput" name="localCacheTimeout" >
<property name="value" >
<number>-1</number>
</property>
<property name="minimum" >
<number>-1</number>
</property>
<property name="suffix" >
<string>minutes</string>
</property>
<property name="specialValueText" >
<string>Never</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2" >
<widget class="QCheckBox" name="syncOnDemand" >
<property name="text" >
<string>Synchronize on demand</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="KEditListBox" name="localParts" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="title" >
<string>Locally Cached Parts</string>
</property>
<property name="buttons" >
<set>KEditListBox::Add|KEditListBox::Remove</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KEditListBox</class>
<extends>QGroupBox</extends>
<header>keditlistbox.h</header>
</customwidget>
<customwidget>
<class>KIntNumInput</class>
<extends>QWidget</extends>
<header>knuminput.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>inherit</sender>
<signal>toggled(bool)</signal>
<receiver>groupBox</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>65</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<x>71</x>
<y>39</y>
</hint>
</hints>
</connection>
<connection>
<sender>inherit</sender>
<signal>toggled(bool)</signal>
<receiver>localParts</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>199</x>
<y>14</y>
</hint>
<hint type="destinationlabel" >
<x>321</x>
<y>192</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -37,8 +37,7 @@ class Collection::Private : public QSharedData
QSharedData(),
id( -1 ),
parentId( -1 ),
type( Unknown ),
cachePolicyId( -1 )
type( Unknown )
{}
Private( const Private &other ) :
......@@ -53,9 +52,9 @@ class Collection::Private : public QSharedData
foreach ( CollectionAttribute* attr, other.attributes )
attributes.insert( attr->type(), attr->clone() );
resource = other.resource;
cachePolicyId = other.cachePolicyId;
status = other.status;
contentTypes = other.contentTypes;
cachePolicy = other.cachePolicy;
}
~Private()
......@@ -80,10 +79,10 @@ class Collection::Private : public QSharedData
Type type;
QHash<QByteArray, CollectionAttribute*> attributes;
QString resource;
int cachePolicyId;
CollectionStatus status;
QStringList contentTypes;
static const Collection root;
CachePolicy cachePolicy;
};
const Collection Collection::Private::root = Collection::Private::newRoot();
......@@ -301,16 +300,6 @@ void Collection::addRawAttribute(const QByteArray & type, const QByteArray & val
addAttribute( attr );
}
int Collection::cachePolicyId() const
{
return d->cachePolicyId;
}
void Collection::setCachePolicyId(int cachePolicyId)
{
d->cachePolicyId = cachePolicyId;
}
CollectionStatus Collection::status() const
{
return d->status;
......@@ -325,3 +314,13 @@ bool Collection::urlIsValid( const KUrl &url )
{
return url.protocol() == QString::fromLatin1("akonadi") && url.queryItems().contains( QString::fromLatin1("collection") );
}
CachePolicy Collection::cachePolicy() const
{
return d->cachePolicy;
}
void Collection::setCachePolicy(const CachePolicy & cachePolicy)
{
d->cachePolicy = cachePolicy;
}
......@@ -23,6 +23,7 @@
#include "libakonadi_export.h"
#include <libakonadi/collectionattribute.h>
#include <libakonadi/collectionstatus.h>
#include <libakonadi/cachepolicy.h>
#include <QtCore/QSharedDataPointer>
......@@ -295,16 +296,15 @@ class AKONADI_EXPORT Collection
void addRawAttribute( const QByteArray &type, const QByteArray &value );
/**
Returns the cache policy identifer of the effective cache policy
of this collection.
Returns the cache policy of this collection.
*/
int cachePolicyId() const;
CachePolicy cachePolicy() const;
/**
Sets the cache policy of this collection.
@param cachePolicyId The cache policy identifier.
@param cachePolicy The new cache policy.
*/
void setCachePolicyId( int cachePolicyId );
void setCachePolicy( const CachePolicy &cachePolicy );
/**
Returns the CollectionStatus object.
......
......@@ -19,6 +19,7 @@
#include "collectioncreatejob.h"
#include "imapparser.h"
#include "protocolhelper.h"
#include <kdebug.h>
......@@ -26,8 +27,7 @@ using namespace Akonadi;
class Akonadi::CollectionCreateJobPrivate {
public:
CollectionCreateJobPrivate() :
cachePolicyId( -1 )
CollectionCreateJobPrivate()
{}
Collection parent;
......@@ -36,7 +36,7 @@ class Akonadi::CollectionCreateJobPrivate {
Collection collection;
QString remoteId;
QList<QPair<QByteArray, QByteArray> > attributes;
int cachePolicyId;
CachePolicy cachePolicy;
};
CollectionCreateJob::CollectionCreateJob( const Collection &parentCollection, const QString &name, QObject * parent ) :
......@@ -67,8 +67,7 @@ void CollectionCreateJob::doStart( )