From f8cd4c1bbf2c521fac18c39bacbc159d736c0846 Mon Sep 17 00:00:00 2001 From: Andras Mantia Date: Sat, 13 Oct 2012 16:29:11 +0300 Subject: [PATCH] Convert sync nepomuk calls to async ones. REVIEW: 106822 --- tagactionmanager.cpp | 46 ++++++++++++++++++++++++++++++++++---------- tagactionmanager.h | 16 ++++++++++++++- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/tagactionmanager.cpp b/tagactionmanager.cpp index 57ae39486..8d4c14336 100644 --- a/tagactionmanager.cpp +++ b/tagactionmanager.cpp @@ -22,8 +22,11 @@ #include "messageactions.h" #include "messagecore/taglistmonitor.h" -#include +#include #include +#include +#include +#include #include #include @@ -137,17 +140,21 @@ void TagActionManager::createActions() if ( mTags.isEmpty() ) { - const QList alltags( Nepomuk2::Tag::allTags() ); - if ( alltags.isEmpty() ) - return; - - // Build a sorted list of tags - foreach( const Nepomuk2::Tag &nepomukTag, alltags ) { - mTags.append( Tag::fromNepomuk( nepomukTag ) ); - } - qSort( mTags.begin(), mTags.end(), KMail::Tag::compare ); + mTagQueryClient = new Nepomuk2::Query::QueryServiceClient(this); + connect( mTagQueryClient, SIGNAL(newEntries(QList)), + this, SLOT(newTagEntries(QList)) ); + connect( mTagQueryClient, SIGNAL(finishedListing()), + this, SLOT(finishedTagListing()) ); + + Nepomuk2::Query::Query query( Nepomuk2::Query::ResourceTypeTerm( Soprano::Vocabulary::NAO::Tag() ) ); + mTagQueryClient->query(query); + } else { + createTagActions(); } +} +void TagActionManager::createTagActions() +{ //Use a mapper to understand which tag button is triggered mMessageTagToggleMapper = new QSignalMapper( this ); connect( mMessageTagToggleMapper, SIGNAL(mapped(QString)), @@ -184,6 +191,25 @@ void TagActionManager::createActions() } } +void TagActionManager::newTagEntries (const QList &results) +{ + foreach (const Nepomuk2::Query::Result &result, results) { + Nepomuk2::Resource resource = result.resource(); + mTags.append( Tag::fromNepomuk( resource ) ); + } +} + +void TagActionManager::finishedTagListing() +{ + mTagQueryClient->deleteLater(); + mTagQueryClient = 0; + if ( mTags.isEmpty() ) + return; + qSort( mTags.begin(), mTags.end(), KMail::Tag::compare ); + createTagActions(); +} + + void TagActionManager::updateActionStates( int numberOfSelectedMessages, const Akonadi::Item &selectedItem ) { diff --git a/tagactionmanager.h b/tagactionmanager.h index 85495f614..c54a0ee7a 100644 --- a/tagactionmanager.h +++ b/tagactionmanager.h @@ -25,6 +25,15 @@ #include "tag.h" #include +namespace Nepomuk2 +{ +namespace Query +{ +class QueryServiceClient; +class Result; +} +} + class KActionCollection; class KXMLGUIClient; class KToggleAction; @@ -105,11 +114,15 @@ namespace KMail { void tagMoreActionClicked(); private Q_SLOTS: + void newTagEntries(const QList& results); + void finishedTagListing(); void tagsChanged(); void slotNepomukStarted(); void slotNepomukStopped(); + private: void createTagAction( const KMail::Tag::Ptr &tag, bool addToMenu ); + void createTagActions(); KActionCollection *mActionCollection; MessageActions *mMessageActions; @@ -129,7 +142,8 @@ namespace KMail { // Cache of the tags to avoid expensive Nepomuk queries QList mTags; - }; + Nepomuk2::Query::QueryServiceClient *mTagQueryClient; + }; } #endif