• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • job
removeduplicatemailjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014-2015 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 
18 #include "removeduplicatemailjob.h"
19 
20 #include "progresswidget/progressmanager.h"
21 #include <KLocalizedString>
22 #include <KMessageBox>
23 
24 #include <Akonadi/Collection>
25 #include <akonadi/kmime/removeduplicatesjob.h>
26 #include <Akonadi/EntityTreeModel>
27 
28 #include <QItemSelectionModel>
29 Q_DECLARE_METATYPE(KPIM::ProgressItem*)
30 Q_DECLARE_METATYPE(Akonadi::Job*)
31 
32 RemoveDuplicateMailJob::RemoveDuplicateMailJob(QItemSelectionModel *selectionModel, QWidget *widget, QObject *parent)
33  : QObject(parent),
34  mParent(widget),
35  mSelectionModel(selectionModel)
36 {
37 
38 }
39 
40 RemoveDuplicateMailJob::~RemoveDuplicateMailJob()
41 {
42 
43 }
44 
45 void RemoveDuplicateMailJob::start()
46 {
47  KPIM::ProgressItem *item = KPIM::ProgressManager::createProgressItem( i18n( "Removing duplicates" ) );
48  item->setUsesBusyIndicator( true );
49  item->setCryptoStatus(KPIM::ProgressItem::Unknown);
50 
51  QModelIndexList indexes = mSelectionModel->selectedIndexes();
52  Akonadi::Collection::List collections;
53 
54  Q_FOREACH (const QModelIndex &index, indexes) {
55  const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
56  if ( collection.isValid() ) {
57  collections << collection;
58  }
59  }
60 
61  Akonadi::RemoveDuplicatesJob *job = new Akonadi::RemoveDuplicatesJob( collections, this );
62  job->setProperty( "ProgressItem", QVariant::fromValue ( item ) );
63  item->setProperty( "RemoveDuplicatesJob", QVariant::fromValue( qobject_cast<Akonadi::Job*>( job ) ) );
64  connect( job, SIGNAL(finished(KJob*)), this, SLOT(slotRemoveDuplicatesDone(KJob*)) );
65  connect( job, SIGNAL(description(KJob*,QString,QPair<QString,QString>,QPair<QString,QString>)), this, SLOT(slotRemoveDuplicatesUpdate(KJob*,QString)) );
66  connect( item, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), this, SLOT(slotRemoveDuplicatesCanceled(KPIM::ProgressItem*)) );
67 }
68 
69 void RemoveDuplicateMailJob::slotRemoveDuplicatesDone( KJob *job )
70 {
71  KPIM::ProgressItem *item = job->property( "ProgressItem" ).value<KPIM::ProgressItem*>();
72  if ( item ) {
73  item->setComplete();
74  item->setStatus( i18n( "Done" ) );
75  item = 0;
76  }
77  if ( job->error() && job->error() != KJob::KilledJobError ) {
78  KMessageBox::error( mParent, job->errorText(), i18n( "Error while removing duplicates" ) );
79  }
80  deleteLater();
81 }
82 
83 void RemoveDuplicateMailJob::slotRemoveDuplicatesCanceled( KPIM::ProgressItem *item )
84 {
85  Akonadi::Job *job = item->property( "RemoveDuplicatesJob" ).value<Akonadi::Job*>();
86  if ( job ) {
87  job->kill( KJob::Quietly );
88  }
89 
90  item->setComplete();
91  item = 0;
92  deleteLater();
93 }
94 
95 void RemoveDuplicateMailJob::slotRemoveDuplicatesUpdate( KJob* job, const QString& description )
96 {
97  KPIM::ProgressItem *item = job->property( "ProgressItem" ).value<KPIM::ProgressItem*>();
98  if ( item ) {
99  item->setStatus( description );
100  }
101 }
QModelIndex
QWidget
RemoveDuplicateMailJob::~RemoveDuplicateMailJob
~RemoveDuplicateMailJob()
Definition: removeduplicatemailjob.cpp:40
KPIM::ProgressItem::setCryptoStatus
void setCryptoStatus(ProgressItem::CryptoStatus v)
KPIM::ProgressItem::Unknown
QVariant::value
T value() const
removeduplicatemailjob.h
QObject::property
QVariant property(const char *name) const
QObject
KPIM::ProgressItem::setComplete
void setComplete()
QItemSelectionModel::selectedIndexes
QModelIndexList selectedIndexes() const
progressmanager.h
RemoveDuplicateMailJob
Definition: removeduplicatemailjob.h:27
QObject::deleteLater
void deleteLater()
QString
QPair
QVariant::fromValue
QVariant fromValue(const T &value)
KPIM::ProgressItem::setUsesBusyIndicator
void setUsesBusyIndicator(bool useBusyIndicator)
QModelIndex::data
QVariant data(int role) const
KPIM::ProgressItem
QObject::setProperty
bool setProperty(const char *name, const QVariant &value)
QItemSelectionModel
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
RemoveDuplicateMailJob::start
void start()
Definition: removeduplicatemailjob.cpp:45
KJob
KPIM::ProgressItem::setStatus
void setStatus(const QString &v)
KPIM::ProgressManager::createProgressItem
static ProgressItem * createProgressItem(unsigned int progressType, const QString &label)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal