Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 7f1c07c8 authored by Laurent Montel's avatar Laurent Montel 😁

improve job

parent 3e23f365
......@@ -19,6 +19,7 @@
*/
#include "sendvcardsjobtest.h"
#include "sendvcards/sendvcardsjob.h"
#include <qtest_kde.h>
SendVcardsJobTest::SendVcardsJobTest(QObject *parent)
: QObject(parent)
......
......@@ -19,11 +19,19 @@
*/
#include "sendvcardsjob.h"
#include <KABC/Addressee>
#include <KABC/ContactGroup>
#include <Akonadi/Item>
#include <Akonadi/ItemFetchJob>
#include <Akonadi/ItemFetchScope>
#include <QDebug>
using namespace KABSendVCards;
SendVcardsJob::SendVcardsJob(QObject *parent)
: QObject(parent)
SendVcardsJob::SendVcardsJob(const Akonadi::Item::List &listItem, QObject *parent)
: QObject(parent),
mListItem(listItem),
mFetchJobCount(0)
{
}
......@@ -33,3 +41,93 @@ SendVcardsJob::~SendVcardsJob()
}
void SendVcardsJob::start()
{
if (mListItem.isEmpty()) {
qDebug()<<" No Item found";
deleteLater();
return;
}
Q_FOREACH (const Akonadi::Item &item, mListItem) {
if (item.hasPayload<KABC::Addressee>()) {
const KABC::Addressee contact = item.payload<KABC::Addressee>();
//TODO
} else if (item.hasPayload<KABC::ContactGroup>()) {
const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
unsigned int nbDataCount(group.dataCount());
for(unsigned int i=0; i<nbDataCount; ++i) {
const QString currentEmail(group.data(i).email());
//TODO
}
const unsigned int nbContactReference(group.contactReferenceCount());
for(unsigned int i=0; i<nbContactReference; ++i){
KABC::ContactGroup::ContactReference reference = group.contactReference(i);
Akonadi::Item item;
if (reference.gid().isEmpty()) {
item.setId( reference.uid().toLongLong() );
} else {
item.setGid( reference.gid() );
}
mItemToFetch << item;
}
}
}
if(mItemToFetch.isEmpty()) {
finishJob();
} else {
fetchNextItem();
}
}
void SendVcardsJob::fetchNextItem()
{
if (mFetchJobCount < mItemToFetch.count()) {
fetchItem(mItemToFetch.at(mFetchJobCount));
++mFetchJobCount;
} else {
finishJob();
}
}
void SendVcardsJob::fetchItem(const Akonadi::Item &item)
{
Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( item, this );
job->fetchScope().fetchFullPayload();
connect( job, SIGNAL(result(KJob*)), SLOT(fetchJobFinished(KJob*)) );
}
void SendVcardsJob::fetchJobFinished(KJob *job)
{
if ( job->error() ) {
qDebug()<<" error during fetching "<<job->errorString();
fetchNextItem();
return;
}
Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob*>( job );
if ( fetchJob->items().count() != 1 ) {
fetchNextItem();
return;
}
const Akonadi::Item item = fetchJob->items().first();
const KABC::Addressee contact = item.payload<KABC::Addressee>();
//TODO
fetchNextItem();
}
void SendVcardsJob::finishJob()
{
#if 0
if (!mEmailAddresses.isEmpty()) {
//emit sendMails(mEmailAddresses);
}
#endif
deleteLater();
}
......@@ -22,14 +22,27 @@
#define SENDVCARDSJOB_H
#include <QObject>
#include <Akonadi/Item>
namespace KABSendVCards {
class SendVcardsJob : public QObject
{
Q_OBJECT
public:
explicit SendVcardsJob(QObject *parent = 0);
explicit SendVcardsJob(const Akonadi::Item::List &listItem, QObject *parent = 0);
~SendVcardsJob();
void start();
private slots:
void fetchJobFinished(KJob *job);
private:
void fetchNextItem();
void fetchItem(const Akonadi::Item &item);
void finishJob();
Akonadi::Item::List mListItem;
Akonadi::Item::List mItemToFetch;
int mFetchJobCount;
};
}
......
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