Commit 85fbc708 authored by Laurent Montel's avatar Laurent Montel 😁

Split remove duplicate mail in own class.

parent 0c1377a5
......@@ -155,6 +155,7 @@ if (KDEPIM_BUILD_DESKTOP)
job/addemailtoexistingcontactjob.cpp
job/createtaskjob.cpp
job/savedraftjob.cpp
job/removeduplicatemailjob.cpp
)
set(kmailprivate_widgets_LIB_SRCS
......
/*
Copyright (c) 2014 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 "removeduplicatemailjob.h"
#include "progresswidget/progressmanager.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <Akonadi/Collection>
#include <akonadi/kmime/removeduplicatesjob.h>
#include <Akonadi/EntityTreeModel>
#include <QItemSelectionModel>
Q_DECLARE_METATYPE(KPIM::ProgressItem*)
Q_DECLARE_METATYPE(Akonadi::Job*)
RemoveDuplicateMailJob::RemoveDuplicateMailJob(QItemSelectionModel *selectionModel, QWidget *widget, QObject *parent)
: QObject(parent),
mParent(widget),
mSelectionModel(selectionModel)
{
}
RemoveDuplicateMailJob::~RemoveDuplicateMailJob()
{
}
void RemoveDuplicateMailJob::start()
{
KPIM::ProgressItem *item = KPIM::ProgressManager::createProgressItem( i18n( "Removing duplicates" ) );
item->setUsesBusyIndicator( true );
item->setCryptoStatus(KPIM::ProgressItem::Unknown);
QModelIndexList indexes = mSelectionModel->selectedIndexes();
Akonadi::Collection::List collections;
Q_FOREACH (const QModelIndex &index, indexes) {
const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if ( collection.isValid() ) {
collections << collection;
}
}
Akonadi::RemoveDuplicatesJob *job = new Akonadi::RemoveDuplicatesJob( collections, this );
job->setProperty( "ProgressItem", QVariant::fromValue ( item ) );
item->setProperty( "RemoveDuplicatesJob", QVariant::fromValue( qobject_cast<Akonadi::Job*>( job ) ) );
connect( job, SIGNAL(finished(KJob*)), this, SLOT(slotRemoveDuplicatesDone(KJob*)) );
connect( job, SIGNAL(description(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>)), this, SLOT(slotRemoveDuplicatesUpdate(KJob*,QString)) );
connect( item, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), this, SLOT(slotRemoveDuplicatesCanceled(KPIM::ProgressItem*)) );
}
void RemoveDuplicateMailJob::slotRemoveDuplicatesDone( KJob *job )
{
KPIM::ProgressItem *item = job->property( "ProgressItem" ).value<KPIM::ProgressItem*>();
if ( item ) {
item->setComplete();
item->setStatus( i18n( "Done" ) );
item = 0;
}
if ( job->error() && job->error() != KJob::KilledJobError ) {
KMessageBox::error( mParent, job->errorText(), i18n( "Error while removing duplicates" ) );
}
deleteLater();
}
void RemoveDuplicateMailJob::slotRemoveDuplicatesCanceled( KPIM::ProgressItem *item )
{
Akonadi::Job *job = item->property( "RemoveDuplicatesJob" ).value<Akonadi::Job*>();
if ( job ) {
job->kill( KJob::Quietly );
}
item->setComplete();
item = 0;
deleteLater();
}
void RemoveDuplicateMailJob::slotRemoveDuplicatesUpdate( KJob* job, const QString& description )
{
KPIM::ProgressItem *item = job->property( "ProgressItem" ).value<KPIM::ProgressItem*>();
if ( item ) {
item->setStatus( description );
}
}
/*
Copyright (c) 2014 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 REMOVEDUPLICATEMAILJOB_H
#define REMOVEDUPLICATEMAILJOB_H
#include <QObject>
class QItemSelectionModel;
namespace KPIM {
class ProgressItem;
}
class KJob;
class RemoveDuplicateMailJob : public QObject
{
Q_OBJECT
public:
explicit RemoveDuplicateMailJob(QItemSelectionModel *selectionModel, QWidget *widget, QObject *parent = 0);
~RemoveDuplicateMailJob();
void start();
private Q_SLOTS:
void slotRemoveDuplicatesDone(KJob *job);
void slotRemoveDuplicatesCanceled(KPIM::ProgressItem *item);
void slotRemoveDuplicatesUpdate(KJob *job, const QString &description);
private:
QWidget *mParent;
QItemSelectionModel *mSelectionModel;
};
#endif // REMOVEDUPLICATEMAILJOB_H
......@@ -199,6 +199,7 @@ using KSieveUi::SieveDebugDialog;
#include <assert.h>
#include <errno.h> // ugh
#include <akonadi/standardactionmanager.h>
#include <job/removeduplicatemailjob.h>
using namespace KMime;
......@@ -4692,63 +4693,10 @@ void KMMainWidget::slotCollectionPropertiesFinished( KJob *job )
void KMMainWidget::slotRemoveDuplicates()
{
KPIM::ProgressItem *item = KPIM::ProgressManager::createProgressItem( i18n( "Removing duplicates" ) );
item->setUsesBusyIndicator( true );
item->setCryptoStatus(KPIM::ProgressItem::Unknown);
QItemSelectionModel *selectionModel = mFolderTreeWidget->folderTreeView()->selectionModel();
QModelIndexList indexes = selectionModel->selectedIndexes();
Akonadi::Collection::List collections;
Q_FOREACH (const QModelIndex &index, indexes) {
Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if ( collection.isValid() ) {
collections << collection;
}
}
Akonadi::RemoveDuplicatesJob *job = new RemoveDuplicatesJob( collections, this );
job->setProperty( "ProgressItem", QVariant::fromValue ( item ) );
item->setProperty( "RemoveDuplicatesJob", QVariant::fromValue( qobject_cast<Akonadi::Job*>( job ) ) );
connect( job, SIGNAL(finished(KJob*)), this, SLOT(slotRemoveDuplicatesDone(KJob*)) );
connect( job, SIGNAL(description(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>)), this, SLOT(slotRemoveDuplicatesUpdate(KJob*,QString)) );
connect( item, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), this, SLOT(slotRemoveDuplicatesCanceled(KPIM::ProgressItem*)) );
}
void KMMainWidget::slotRemoveDuplicatesDone( KJob *job )
{
if ( job->error() && job->error() != KJob::KilledJobError ) {
KMessageBox::error( this, job->errorText(), i18n( "Error while removing duplicates" ) );
}
KPIM::ProgressItem *item = job->property( "ProgressItem" ).value<KPIM::ProgressItem*>();
if ( item ) {
item->setComplete();
item->setStatus( i18n( "Done" ) );
item = 0;
}
}
void KMMainWidget::slotRemoveDuplicatesCanceled( KPIM::ProgressItem *item )
{
Akonadi::Job *job = item->property( "RemoveDuplicatesJob" ).value<Akonadi::Job*>();
if ( job ) {
job->kill( KJob::Quietly );
}
item->setComplete();
item = 0;
}
void KMMainWidget::slotRemoveDuplicatesUpdate( KJob* job, const QString& description )
{
KPIM::ProgressItem *item = job->property( "ProgressItem" ).value<KPIM::ProgressItem*>();
if ( item ) {
item->setStatus( description );
}
RemoveDuplicateMailJob *job = new RemoveDuplicateMailJob(mFolderTreeWidget->folderTreeView()->selectionModel(), this, this);
job->start();
}
void KMMainWidget::slotServerSideSubscription()
{
if ( !mCurrentFolder )
......
......@@ -257,9 +257,6 @@ public slots:
void slotCollectionProperties();
void slotRemoveDuplicates();
void slotRemoveDuplicatesDone( KJob* );
void slotRemoveDuplicatesCanceled( KPIM::ProgressItem* );
void slotRemoveDuplicatesUpdate( KJob *, const QString& );
void slotSelectCollectionFolder( const Akonadi::Collection & col );
......
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