Commit e093a7eb authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

AddresseeLineEdit: create Akonadi::Session on-demand

We only need the session when autocompleting in composer, there's no point
opening the session once the widget is constructed. Makes it possible to
test components using AddresseeLineEdit without having to talk to Akonadi.
parent 092db47e
......@@ -512,7 +512,7 @@ void AddresseeLineEditPrivate::akonadiPerformSearch()
s_static->akonadiJobsInFlight.clear();
// now start new jobs
Akonadi::ContactSearchJob *contactJob = new Akonadi::ContactSearchJob(s_static->akonadiSession);
Akonadi::ContactSearchJob *contactJob = new Akonadi::ContactSearchJob(s_static->akonadiSession());
contactJob->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
contactJob->setQuery(Akonadi::ContactSearchJob::NameOrEmail, m_searchString,
Akonadi::ContactSearchJob::ContainsWordBoundaryMatch);
......@@ -521,7 +521,7 @@ void AddresseeLineEditPrivate::akonadiPerformSearch()
connect(contactJob, &KJob::result,
this, &AddresseeLineEditPrivate::slotAkonadiSearchResult);
Akonadi::ContactGroupSearchJob *groupJob = new Akonadi::ContactGroupSearchJob(s_static->akonadiSession);
Akonadi::ContactGroupSearchJob *groupJob = new Akonadi::ContactGroupSearchJob(s_static->akonadiSession());
groupJob->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
groupJob->setQuery(Akonadi::ContactGroupSearchJob::Name, m_searchString,
Akonadi::ContactGroupSearchJob::ContainsMatch);
......@@ -802,7 +802,7 @@ void AddresseeLineEditPrivate::slotAkonadiHandleItems(const Akonadi::Item::List
Akonadi::CollectionFetchJob *collectionJob =
new Akonadi::CollectionFetchJob(item.parentCollection(),
Akonadi::CollectionFetchJob::Base,
s_static->akonadiSession);
s_static->akonadiSession());
connect(collectionJob, &Akonadi::CollectionFetchJob::collectionsReceived,
this, &AddresseeLineEditPrivate::slotAkonadiCollectionsReceived);
/* we don't want to start multiple fetch jobs for the same collection,
......
......@@ -31,8 +31,8 @@ AddresseeLineEditStatic::AddresseeLineEditStatic()
ldapTimer(0),
ldapSearch(0),
ldapLineEdit(0),
akonadiSession(new Akonadi::Session("contactsCompletionSession")),
balooCompletionSource(0)
balooCompletionSource(0),
m_akonadiSession(Q_NULLPTR)
{
}
......@@ -106,3 +106,11 @@ void AddresseeLineEditStatic::removeCompletionSource(const QString &source)
completion->clear();
}
}
Akonadi::Session *AddresseeLineEditStatic::akonadiSession()
{
if (!m_akonadiSession) {
m_akonadiSession = new Akonadi::Session("contactsCompletionSession");
}
return m_akonadiSession;
}
......@@ -52,6 +52,8 @@ public:
void removeCompletionSource(const QString &source);
Akonadi::Session *akonadiSession();
KMailCompletion *completion;
CompletionItemsMap completionItemMap;
QStringList completionSources;
......@@ -83,9 +85,11 @@ public:
QMap<Akonadi::Collection::Id, collectionInfo> akonadiCollectionToCompletionSourceMap;
// a list of akonadi items (contacts) that have not had their collection fetched yet
Akonadi::Item::List akonadiPendingItems;
Akonadi::Session *akonadiSession;
QVector<QWeakPointer<Akonadi::Job> > akonadiJobsInFlight;
int balooCompletionSource;
private:
Akonadi::Session *m_akonadiSession;
};
}
#endif // ADDRESSEELINEEDITSTATIC_H
Supports Markdown
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