~ubuntu-branches/ubuntu/raring/kdepim/raring-proposed

« back to all changes in this revision

Viewing changes to archivemailagent/archivemailinfo.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-07 07:56:38 UTC
  • mfrom: (0.2.27)
  • Revision ID: package-import@ubuntu.com-20120607075638-0luhdq11z7sgvs4m
Tags: 4:4.8.80-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2012 Montel Laurent <montel@kde.org>
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
*/
 
17
#include "archivemailinfo.h"
 
18
 
 
19
#include <KLocale>
 
20
 
 
21
ArchiveMailInfo::ArchiveMailInfo()
 
22
  : mLastDateSaved(QDate::currentDate())
 
23
  , mArchiveAge( 1 )
 
24
  , mArchiveType( MailCommon::BackupJob::Zip )
 
25
  , mArchiveUnit( ArchiveMailInfo::ArchiveDays ) 
 
26
  , mSaveCollectionId(-1) 
 
27
  , mSaveSubCollection(false)
 
28
{
 
29
}
 
30
 
 
31
ArchiveMailInfo::ArchiveMailInfo(const KConfigGroup& config)
 
32
  : mLastDateSaved(QDate::currentDate())
 
33
  , mArchiveAge( 1 )
 
34
  , mArchiveType( MailCommon::BackupJob::Zip ) 
 
35
  , mArchiveUnit( ArchiveMailInfo::ArchiveDays ) 
 
36
  , mSaveCollectionId(-1)
 
37
  , mSaveSubCollection(false)
 
38
{
 
39
  readConfig(config);
 
40
}
 
41
 
 
42
 
 
43
ArchiveMailInfo::~ArchiveMailInfo()
 
44
{
 
45
}
 
46
 
 
47
KUrl ArchiveMailInfo::realUrl(const QString& foldername) const
 
48
{
 
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];
 
53
;
 
54
  KUrl real;
 
55
  real.setPath(path);
 
56
  return real;
 
57
}
 
58
 
 
59
 
 
60
bool ArchiveMailInfo::isEmpty() const
 
61
{
 
62
  return (mSaveCollectionId==-1);
 
63
}
 
64
 
 
65
 
 
66
void ArchiveMailInfo::setArchiveAge( int age )
 
67
{
 
68
  mArchiveAge = age;
 
69
}
 
70
    
 
71
int ArchiveMailInfo::archiveAge() const
 
72
{
 
73
  return mArchiveAge;
 
74
}
 
75
 
 
76
 
 
77
void ArchiveMailInfo::setArchiveUnit( ArchiveMailInfo::ArchiveUnit unit )
 
78
{
 
79
  mArchiveUnit = unit;
 
80
}
 
81
 
 
82
ArchiveMailInfo::ArchiveUnit ArchiveMailInfo::archiveUnit() const
 
83
{
 
84
  return mArchiveUnit;
 
85
}
 
86
 
 
87
 
 
88
void ArchiveMailInfo::setArchiveType( MailCommon::BackupJob::ArchiveType type )
 
89
{
 
90
  mArchiveType = type;
 
91
}
 
92
 
 
93
MailCommon::BackupJob::ArchiveType ArchiveMailInfo::archiveType() const
 
94
{
 
95
  return mArchiveType;
 
96
}
 
97
 
 
98
void ArchiveMailInfo::setLastDateSaved( const QDate& date )
 
99
{
 
100
  mLastDateSaved = date;
 
101
}
 
102
 
 
103
QDate ArchiveMailInfo::lastDateSaved() const
 
104
{
 
105
  return mLastDateSaved;
 
106
}
 
107
 
 
108
 
 
109
void ArchiveMailInfo::readConfig(const KConfigGroup& config)
 
110
{
 
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);
 
118
  if ( tId >= 0 ) {
 
119
    mSaveCollectionId = tId;
 
120
  }
 
121
}
 
122
 
 
123
void ArchiveMailInfo::writeConfig(KConfigGroup & config )
 
124
{
 
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);
 
132
  config.sync();
 
133
}
 
134
 
 
135
KUrl ArchiveMailInfo::url() const
 
136
{
 
137
  return mPath;
 
138
}
 
139
 
 
140
void ArchiveMailInfo::setUrl(const KUrl& url)
 
141
{
 
142
  mPath = url;
 
143
}
 
144
 
 
145
bool ArchiveMailInfo::saveSubCollection() const
 
146
{
 
147
  return mSaveSubCollection;
 
148
}
 
149
 
 
150
void ArchiveMailInfo::setSaveSubCollection( bool saveSubCol )
 
151
{
 
152
  mSaveSubCollection = saveSubCol;
 
153
}
 
154
 
 
155
void ArchiveMailInfo::setSaveCollectionId(Akonadi::Collection::Id collectionId)
 
156
{
 
157
  mSaveCollectionId = collectionId;
 
158
}
 
159
 
 
160
Akonadi::Collection::Id ArchiveMailInfo::saveCollectionId() const
 
161
{
 
162
  return mSaveCollectionId;
 
163
}