Commit 29e3155a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Remove duplicate code

parent a82d30ea
......@@ -12,6 +12,7 @@ set(archivemailagent_SRCS
archivemailinfo.cpp
addarchivemaildialog.cpp
archivejob.cpp
archivemailagentutil.cpp
)
qt4_add_dbus_adaptor(archivemailagent_SRCS org.freedesktop.Akonadi.ArchiveMailAgent.xml archivemailagent.h ArchiveMailAgent)
......
/*
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "archivemailagentutil.h"
QDate ArchiveMailAgentUtil::diffDate(ArchiveMailInfo*info)
{
QDate diffDate(info->lastDateSaved());
switch(info->archiveUnit()) {
case ArchiveMailInfo::ArchiveDays:
diffDate = diffDate.addDays(info->archiveAge());
break;
case ArchiveMailInfo::ArchiveWeeks:
diffDate = diffDate.addDays(info->archiveAge()*7);
break;
case ArchiveMailInfo::ArchiveMonths:
diffDate = diffDate.addMonths(info->archiveAge());
break;
default:
qDebug()<<"archiveUnit not defined :"<<info->archiveUnit();
break;
}
return diffDate;
}
/*
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ARCHIVEMAILAGENTUTIL_H
#define ARCHIVEMAILAGENTUTIL_H
#include "archivemailinfo.h"
#include <QDate>
namespace ArchiveMailAgentUtil {
QDate diffDate(ArchiveMailInfo*info);
}
#endif // ARCHIVEMAILAGENTUTIL_H
......@@ -17,6 +17,7 @@
#include "archivemaildialog.h"
#include "addarchivemaildialog.h"
#include "archivemailagentutil.h"
#include <mailcommon/mailutil.h>
#include <KGlobal>
#include <KLocale>
......@@ -127,21 +128,7 @@ void ArchiveMailWidget::createOrUpdateItem(ArchiveMailInfo *info, ArchiveMailIte
}
item->setText(0,i18n("Folder: %1",MailCommon::Util::fullCollectionPath(Akonadi::Collection(info->saveCollectionId()))));
item->setText(1,KGlobal::locale()->formatDate(info->lastDateSaved()));
QDate diffDate(info->lastDateSaved());
switch(info->archiveUnit()) {
case ArchiveMailInfo::ArchiveDays:
diffDate = diffDate.addDays(info->archiveAge());
break;
case ArchiveMailInfo::ArchiveWeeks:
diffDate = diffDate.addDays(info->archiveAge()*7);
break;
case ArchiveMailInfo::ArchiveMonths:
diffDate = diffDate.addMonths(info->archiveAge());
break;
default:
qDebug()<<"archiveUnit not defined :"<<info->archiveUnit();
break;
}
QDate diffDate = ArchiveMailAgentUtil::diffDate(info);
item->setText(2,i18np("1 day", "%1 days",QString::number(info->lastDateSaved().daysTo(diffDate))));
item->setInfo(info);
}
......
......@@ -46,7 +46,6 @@ ArchiveMailInfo::~ArchiveMailInfo()
KUrl ArchiveMailInfo::realUrl(const QString& foldername) const
{
//FIXME
const int numExtensions = 4;
// The extensions here are also sorted, like the enum order of BackupJob::ArchiveType
const char *extensions[numExtensions] = { ".zip", ".tar", ".tar.bz2", ".tar.gz" };
......
......@@ -19,6 +19,7 @@
#include "archivemailinfo.h"
#include "archivejob.h"
#include "archivemailkernel.h"
#include "archivemailagentutil.h"
#include <mailcommon/mailkernel.h>
......@@ -54,21 +55,7 @@ void ArchiveMailManager::load()
KConfigGroup group = config->group(collectionList.at(i));
ArchiveMailInfo *info = new ArchiveMailInfo(group);
QDate diffDate(info->lastDateSaved());
switch(info->archiveUnit()) {
case ArchiveMailInfo::ArchiveDays:
diffDate = diffDate.addDays(info->archiveAge());
break;
case ArchiveMailInfo::ArchiveWeeks:
diffDate = diffDate.addDays(info->archiveAge()*7);
break;
case ArchiveMailInfo::ArchiveMonths:
diffDate = diffDate.addMonths(info->archiveAge());
break;
default:
qDebug()<<"archiveUnit not defined :"<<info->archiveUnit();
break;
}
QDate diffDate = ArchiveMailAgentUtil::diffDate(info);
if(QDate::currentDate() > diffDate) {
//Store task started
mListArchiveInfo.append(info);
......
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