Commit 5fbdf2f2 authored by Laurent Montel's avatar Laurent Montel 😁

Clean up expireclectionattribute

parent 7bf9ac3c
......@@ -1455,7 +1455,7 @@ void KMMainWidget::slotExpireFolder()
if ( !mCurrentFolder )
return;
bool mustDeleteExpirationAttribute = false;
MailCommon::ExpireCollectionAttribute *attr = MailCommon::ExpireCollectionAttribute::expirationCollectionAttribute( mCurrentFolder->collection(), mustDeleteExpirationAttribute );
MailCommon::ExpireCollectionAttribute *attr = MailCommon::Util::expirationCollectionAttribute( mCurrentFolder->collection(), mustDeleteExpirationAttribute );
bool canBeExpired = true;
if ( !attr->isAutoExpire() ) {
canBeExpired = false;
......
......@@ -135,7 +135,7 @@ void CollectionExpiryPage::load( const Akonadi::Collection &collection )
init();
bool mustDeleteExpirationAttribute = false;
MailCommon::ExpireCollectionAttribute *attr = MailCommon::ExpireCollectionAttribute::expirationCollectionAttribute( mCollection, mustDeleteExpirationAttribute );
MailCommon::ExpireCollectionAttribute *attr = MailCommon::Util::expirationCollectionAttribute( mCollection, mustDeleteExpirationAttribute );
// Load the values from the folder
bool expiryGloballyOn = attr->isAutoExpire();
......
......@@ -54,31 +54,6 @@ Akonadi::Attribute *ExpireCollectionAttribute::clone() const
return expireAttr;
}
void ExpireCollectionAttribute::loadFromConfig( const Akonadi::Collection &collection )
{
KConfigGroup configGroup( KernelIf->config(),
MailCommon::FolderCollection::configGroupName( collection ) );
if ( configGroup.hasKey( "ExpireMessages" ) ) {
mExpireMessages = configGroup.readEntry( "ExpireMessages", false );
mReadExpireAge = configGroup.readEntry( "ReadExpireAge", 3 );
mReadExpireUnits = (ExpireUnits)configGroup.readEntry( "ReadExpireUnits", (int)ExpireMonths );
mUnreadExpireAge = configGroup.readEntry( "UnreadExpireAge", 12 );
mUnreadExpireUnits =
(ExpireUnits)configGroup.readEntry( "UnreadExpireUnits", (int)ExpireNever );
mExpireAction = configGroup.readEntry( "ExpireAction", "Delete" ) == QLatin1String( "Move" ) ?
ExpireMove :
ExpireDelete;
mExpireToFolderId = configGroup.readEntry( "ExpireToFolder", -1 );
}
}
void ExpireCollectionAttribute::setAutoExpire( bool enabled )
{
mExpireMessages = enabled;
......@@ -180,21 +155,6 @@ void ExpireCollectionAttribute::daysToExpire( int &unreadDays, int &readDays )
readDays = ExpireCollectionAttribute::daysToExpire( readExpireAge(), readExpireUnits() );
}
ExpireCollectionAttribute *ExpireCollectionAttribute::expirationCollectionAttribute(
const Akonadi::Collection &collection, bool &mustDeleteExpirationAttribute )
{
MailCommon::ExpireCollectionAttribute *attr = 0;
if ( collection.hasAttribute<MailCommon::ExpireCollectionAttribute>() ) {
attr = collection.attribute<MailCommon::ExpireCollectionAttribute>();
mustDeleteExpirationAttribute = false;
} else {
attr = new MailCommon::ExpireCollectionAttribute();
attr->loadFromConfig( collection );
mustDeleteExpirationAttribute = true;
}
return attr;
}
QByteArray ExpireCollectionAttribute::serialized() const
{
QByteArray result;
......
......@@ -56,10 +56,6 @@ public:
static int daysToExpire( int number, ExpireCollectionAttribute::ExpireUnits units );
static ExpireCollectionAttribute *expirationCollectionAttribute(
const Akonadi::Collection &collection, bool &mustDeleteExpirationAttribute );
void daysToExpire( int &unreadDays, int &readDays );
/**
......@@ -135,7 +131,6 @@ public:
ExpireUnits readExpireUnits() const;
private:
void loadFromConfig( const Akonadi::Collection &collection );
bool mExpireMessages; // true if old messages are expired
int mUnreadExpireAge; // Given in unreadExpireUnits
int mReadExpireAge; // Given in readExpireUnits
......
......@@ -93,7 +93,7 @@ void FolderCollectionMonitor::expireAllCollection( const QAbstractItemModel *mod
bool mustDeleteExpirationAttribute = false;
MailCommon::ExpireCollectionAttribute *attr =
MailCommon::ExpireCollectionAttribute::expirationCollectionAttribute(
MailCommon::Util::expirationCollectionAttribute(
collection, mustDeleteExpirationAttribute );
if ( attr->isAutoExpire() ) {
......
......@@ -28,6 +28,7 @@
#include "expirejob.h"
#include "collectionpage/expirecollectionattribute.h"
#include "kernel/mailkernel.h"
#include "util/mailutil.h"
#include <libkdepim/misc/broadcaststatus.h>
using KPIM::BroadcastStatus;
......@@ -83,7 +84,7 @@ void ExpireJob::execute()
bool mustDeleteExpirationAttribute = false;
MailCommon::ExpireCollectionAttribute *expirationAttribute =
MailCommon::ExpireCollectionAttribute::expirationCollectionAttribute(
MailCommon::Util::expirationCollectionAttribute(
mSrcFolder, mustDeleteExpirationAttribute );
expirationAttribute->daysToExpire( unreadDays, readDays );
......@@ -165,7 +166,7 @@ void ExpireJob::done()
bool mustDeleteExpirationAttribute = false;
MailCommon::ExpireCollectionAttribute *expirationAttribute =
MailCommon::ExpireCollectionAttribute::expirationCollectionAttribute(
MailCommon::Util::expirationCollectionAttribute(
mSrcFolder, mustDeleteExpirationAttribute );
if ( expirationAttribute->expireAction() == MailCommon::ExpireCollectionAttribute::ExpireDelete ) {
......@@ -253,7 +254,7 @@ void ExpireJob::slotExpireDone( KJob *job )
bool mustDeleteExpirationAttribute = false;
MailCommon::ExpireCollectionAttribute *expirationAttribute =
MailCommon::ExpireCollectionAttribute::expirationCollectionAttribute(
MailCommon::Util::expirationCollectionAttribute(
mSrcFolder, mustDeleteExpirationAttribute );
switch ( error ) {
......
......@@ -83,6 +83,7 @@
#include <KMessageBox>
#include <KTemporaryFile>
#include <KIO/JobUiDelegate>
#include <collectionpage/expirecollectionattribute.h>
OrgKdeAkonadiPOP3SettingsInterface *MailCommon::Util::createPop3SettingsInterface(
......@@ -453,3 +454,31 @@ bool MailCommon::Util::foundMailer()
return false;
}
MailCommon::ExpireCollectionAttribute *MailCommon::Util::expirationCollectionAttribute(const Akonadi::Collection &collection, bool &mustDeleteExpirationAttribute )
{
MailCommon::ExpireCollectionAttribute *attr = 0;
if ( collection.hasAttribute<MailCommon::ExpireCollectionAttribute>() ) {
attr = collection.attribute<MailCommon::ExpireCollectionAttribute>();
mustDeleteExpirationAttribute = false;
} else {
attr = new MailCommon::ExpireCollectionAttribute();
KConfigGroup configGroup( KernelIf->config(),
MailCommon::FolderCollection::configGroupName( collection ) );
if ( configGroup.hasKey( "ExpireMessages" ) ) {
attr->setAutoExpire(configGroup.readEntry( "ExpireMessages", false ));
attr->setReadExpireAge(configGroup.readEntry( "ReadExpireAge", 3 ));
attr->setReadExpireUnits((MailCommon::ExpireCollectionAttribute::ExpireUnits)configGroup.readEntry( "ReadExpireUnits", (int)MailCommon::ExpireCollectionAttribute::ExpireMonths ));
attr->setUnreadExpireAge(configGroup.readEntry( "UnreadExpireAge", 12 ));
attr->setUnreadExpireUnits((MailCommon::ExpireCollectionAttribute::ExpireUnits)configGroup.readEntry( "UnreadExpireUnits", (int)MailCommon::ExpireCollectionAttribute::ExpireNever ));
attr->setExpireAction(configGroup.readEntry( "ExpireAction", "Delete" ) == QLatin1String( "Move" ) ?
MailCommon::ExpireCollectionAttribute::ExpireMove :
MailCommon::ExpireCollectionAttribute::ExpireDelete);
attr->setExpireToFolderId(configGroup.readEntry( "ExpireToFolder", -1 ));
}
mustDeleteExpirationAttribute = true;
}
return attr;
}
......@@ -48,7 +48,6 @@ class OrgKdeAkonadiPOP3SettingsInterface;
namespace Akonadi {
class Item;
}
class KJob;
class QAbstractItemModel;
......@@ -56,7 +55,7 @@ class QModelIndex;
class QString;
namespace MailCommon {
class ExpireCollectionAttribute;
/**
* The Util namespace contains a collection of helper functions use in
* various places.
......@@ -123,6 +122,7 @@ MAILCOMMON_EXPORT bool foundMailer();
MAILCOMMON_EXPORT bool isLocalCollection( const QString &resource );
MAILCOMMON_EXPORT bool ignoreNewMailInFolder(const Akonadi::Collection &collection);
MAILCOMMON_EXPORT MailCommon::ExpireCollectionAttribute *expirationCollectionAttribute(const Akonadi::Collection &collection, bool &mustDeleteExpirationAttribute );
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment