2
Copyright (c) 2012 Montel Laurent <montel@kde.org>
4
This program is free software; you can redistribute it and/or modify it
5
under the terms of the GNU General Public License, version 2, as
6
published by the Free Software Foundation.
8
This program is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
General Public License for more details.
13
You should have received a copy of the GNU General Public License along
14
with this program; if not, write to the Free Software Foundation, Inc.,
15
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
#include "archivemailinfo.h"
21
ArchiveMailInfo::ArchiveMailInfo()
22
: mLastDateSaved(QDate::currentDate())
24
, mArchiveType( MailCommon::BackupJob::Zip )
25
, mArchiveUnit( ArchiveMailInfo::ArchiveDays )
26
, mSaveCollectionId(-1)
27
, mSaveSubCollection(false)
31
ArchiveMailInfo::ArchiveMailInfo(const KConfigGroup& config)
32
: mLastDateSaved(QDate::currentDate())
34
, mArchiveType( MailCommon::BackupJob::Zip )
35
, mArchiveUnit( ArchiveMailInfo::ArchiveDays )
36
, mSaveCollectionId(-1)
37
, mSaveSubCollection(false)
43
ArchiveMailInfo::~ArchiveMailInfo()
47
KUrl ArchiveMailInfo::realUrl(const QString& foldername) const
49
const int numExtensions = 4;
50
// The extensions here are also sorted, like the enum order of BackupJob::ArchiveType
51
const char *extensions[numExtensions] = { ".zip", ".tar", ".tar.bz2", ".tar.gz" };
52
QString path = url().path() + QLatin1Char( '/' ) + i18nc( "Start of the filename for a mail archive file" , "Archive" ) + QLatin1Char( '_' ) + foldername + QLatin1Char( '_' ) + QDate::currentDate().toString( Qt::ISODate ) + extensions[mArchiveType];
60
bool ArchiveMailInfo::isEmpty() const
62
return (mSaveCollectionId==-1);
66
void ArchiveMailInfo::setArchiveAge( int age )
71
int ArchiveMailInfo::archiveAge() const
77
void ArchiveMailInfo::setArchiveUnit( ArchiveMailInfo::ArchiveUnit unit )
82
ArchiveMailInfo::ArchiveUnit ArchiveMailInfo::archiveUnit() const
88
void ArchiveMailInfo::setArchiveType( MailCommon::BackupJob::ArchiveType type )
93
MailCommon::BackupJob::ArchiveType ArchiveMailInfo::archiveType() const
98
void ArchiveMailInfo::setLastDateSaved( const QDate& date )
100
mLastDateSaved = date;
103
QDate ArchiveMailInfo::lastDateSaved() const
105
return mLastDateSaved;
109
void ArchiveMailInfo::readConfig(const KConfigGroup& config)
111
mPath = config.readEntry("storePath",KUrl());
112
mLastDateSaved = QDate::fromString(config.readEntry("lastDateSaved"),Qt::ISODate);
113
mSaveSubCollection = config.readEntry("saveSubCollection",false);
114
mArchiveType = static_cast<MailCommon::BackupJob::ArchiveType>( config.readEntry( "archiveType", ( int )MailCommon::BackupJob::Zip ) );
115
mArchiveUnit = static_cast<ArchiveUnit>( config.readEntry( "archiveUnit", ( int )ArchiveDays ) );
116
Akonadi::Collection::Id tId = config.readEntry("saveCollectionId",mSaveCollectionId);
117
mArchiveAge = config.readEntry("archiveAge",1);
119
mSaveCollectionId = tId;
123
void ArchiveMailInfo::writeConfig(KConfigGroup & config )
125
config.writeEntry("storePath",mPath);
126
config.writeEntry("lastDateSaved", mLastDateSaved.toString(Qt::ISODate) );
127
config.writeEntry("saveSubCollection",mSaveSubCollection);
128
config.writeEntry("archiveType", ( int )mArchiveType );
129
config.writeEntry("archiveUnit", ( int )mArchiveUnit );
130
config.writeEntry("saveCollectionId",mSaveCollectionId);
131
config.writeEntry("archiveAge",mArchiveAge);
135
KUrl ArchiveMailInfo::url() const
140
void ArchiveMailInfo::setUrl(const KUrl& url)
145
bool ArchiveMailInfo::saveSubCollection() const
147
return mSaveSubCollection;
150
void ArchiveMailInfo::setSaveSubCollection( bool saveSubCol )
152
mSaveSubCollection = saveSubCol;
155
void ArchiveMailInfo::setSaveCollectionId(Akonadi::Collection::Id collectionId)
157
mSaveCollectionId = collectionId;
160
Akonadi::Collection::Id ArchiveMailInfo::saveCollectionId() const
162
return mSaveCollectionId;