Commit e6faa50f authored by Laurent Montel's avatar Laurent Montel 😁

improve job

parent 2cde960b
...@@ -20,9 +20,17 @@ ...@@ -20,9 +20,17 @@
#include "automaticaddcontactsjob.h" #include "automaticaddcontactsjob.h"
#include "automaticaddcontactsplugin_debug.h" #include "automaticaddcontactsplugin_debug.h"
#include <Libkdepim/AddEmailAddressJob> #include <Libkdepim/AddEmailAddressJob>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiCore/CollectionFetchScope>
#include <AkonadiCore/AgentInstanceCreateJob>
#include <KContacts/Addressee>
#include <KMessageBox>
#include <KLocalizedString>
#include <AkonadiWidgets/AgentTypeDialog>
AutomaticAddContactsJob::AutomaticAddContactsJob(QObject *parent) AutomaticAddContactsJob::AutomaticAddContactsJob(QObject *parent)
: QObject(parent) : QObject(parent),
mCurrentIndex(0)
{ {
} }
...@@ -44,13 +52,109 @@ void AutomaticAddContactsJob::start() ...@@ -44,13 +52,109 @@ void AutomaticAddContactsJob::start()
return; return;
} }
} }
mCurrentIndex = 0;
//1) fetch collection to be sure that it's ok
fetchCollection();
addNextContact();
//TODO //TODO
//Remove it when implemented //Remove it when implemented
deleteLater(); deleteLater();
} }
void AutomaticAddContactsJob::fetchCollection()
{
Akonadi::CollectionFetchJob *const addressBookJob = new Akonadi::CollectionFetchJob(mCollection, Akonadi::CollectionFetchJob::Base);
const QStringList mimeTypes(KContacts::Addressee::mimeType());
addressBookJob->fetchScope().setContentMimeTypes(mimeTypes);
connect(addressBookJob, &KJob::result, this, &AutomaticAddContactsJob::slotCollectionsFetched);
}
void AutomaticAddContactsJob::slotCollectionsFetched(KJob *job)
{
#if 0
if (job->error()) {
if (KMessageBox::questionYesNo(
0,
i18nc("@info",
"You must create an address book before adding a contact. Do you want to create an address book?"),
i18nc("@title:window", "No Address Book Available")) == KMessageBox::Yes) {
Akonadi::AgentTypeDialog dlg(mParentWidget);
dlg.setWindowTitle(i18n("Add Address Book"));
dlg.agentFilterProxyModel()->addMimeTypeFilter(KContacts::Addressee::mimeType());
dlg.agentFilterProxyModel()->addCapabilityFilter(QStringLiteral("Resource"));
if (dlg.exec()) {
const Akonadi::AgentType agentType = dlg.agentType();
if (agentType.isValid()) {
Akonadi::AgentInstanceCreateJob *job = new Akonadi::AgentInstanceCreateJob(agentType, q);
connect(job, SIGNAL(result(KJob*)), SLOT(slotResourceCreationDone(KJob*)));
job->configure(mParentWidget);
job->start();
return;
} else {
deleteLater();
return;
}
} else { //Canceled create agent => return error and finish job
deleteLater();
return;
}
} else {
deleteLater();
return;
}
} else if (nbItemCollection == 1) {
addressBook = canCreateItemCollections[0];
} else {
// ask user in which address book the new contact shall be stored
QPointer<Akonadi::SelectAddressBookDialog> dlg = new Akonadi::SelectAddressBookDialog(mParentWidget);
bool gotIt = true;
if (dlg->exec()) {
addressBook = dlg->selectedCollection();
} else {
q->setError(UserDefinedError);
q->emitResult();
gotIt = false;
}
delete dlg;
if (!gotIt) {
return;
}
}
if (!addressBook.isValid()) {
q->setError(UserDefinedError);
q->emitResult();
return;
}
#endif
}
void AutomaticAddContactsJob::verifyContactExist()
{
#if 0
Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob(this);
searchJob->setLimit(1);
searchJob->setQuery(Akonadi::ContactSearchJob::Email, d->mEmail.toLower(),
Akonadi::ContactSearchJob::ExactMatch);
connect(searchJob, SIGNAL(result(KJob*)), SLOT(slotSearchDone(KJob*)));
#endif
}
void AutomaticAddContactsJob::addNextContact()
{
if (mCurrentIndex < mEmails.count()) {
} else {
deleteLater();
}
}
void AutomaticAddContactsJob::setEmails(const QStringList &emails) void AutomaticAddContactsJob::setEmails(const QStringList &emails)
{ {
mEmails = emails; mEmails = emails;
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <QObject> #include <QObject>
#include <AkonadiCore/Collection> #include <AkonadiCore/Collection>
class KJob;
class AutomaticAddContactsJob : public QObject class AutomaticAddContactsJob : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -36,9 +36,13 @@ public: ...@@ -36,9 +36,13 @@ public:
void setCollection(const Akonadi::Collection &collection); void setCollection(const Akonadi::Collection &collection);
private: private:
void fetchCollection();
void verifyContactExist();
void addNextContact();
QStringList mEmails; QStringList mEmails;
QStringList mProcessedEmails; QStringList mProcessedEmails;
Akonadi::Collection mCollection; Akonadi::Collection mCollection;
int mCurrentIndex;
void slotCollectionsFetched(KJob *job);
}; };
#endif // AUTOMATICADDCONTACTSJOB_H #endif // AUTOMATICADDCONTACTSJOB_H
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