summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-07-31 13:55:37 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-07-31 13:55:37 (GMT)
commite093a7ebb5817d956c7e3355d61c113f8f06c1b8 (patch)
tree55311431c961ab13e37c3eb5b7627f4f9da27358
parent092db47ea3b42df650563189623518039562c947 (diff)
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.
-rw-r--r--src/addressline/addresslineedit/addresseelineedit_p.cpp6
-rw-r--r--src/addressline/addresslineedit/addresseelineeditstatic.cpp12
-rw-r--r--src/addressline/addresslineedit/addresseelineeditstatic.h6
3 files changed, 18 insertions, 6 deletions
diff --git a/src/addressline/addresslineedit/addresseelineedit_p.cpp b/src/addressline/addresslineedit/addresseelineedit_p.cpp
index 7009dd8..fc631f9 100644
--- a/src/addressline/addresslineedit/addresseelineedit_p.cpp
+++ b/src/addressline/addresslineedit/addresseelineedit_p.cpp
@@ -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,
diff --git a/src/addressline/addresslineedit/addresseelineeditstatic.cpp b/src/addressline/addresslineedit/addresseelineeditstatic.cpp
index 85b67ee..f70f1de 100644
--- a/src/addressline/addresslineedit/addresseelineeditstatic.cpp
+++ b/src/addressline/addresslineedit/addresseelineeditstatic.cpp
@@ -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;
+}
diff --git a/src/addressline/addresslineedit/addresseelineeditstatic.h b/src/addressline/addresslineedit/addresseelineeditstatic.h
index 8f97a12..45a0cfc 100644
--- a/src/addressline/addresslineedit/addresseelineeditstatic.h
+++ b/src/addressline/addresslineedit/addresseelineeditstatic.h
@@ -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