Convert sync nepomuk calls to async ones.

REVIEW: 106822
wilder-work
Andras Mantia 14 years ago
parent cfe0ab8364
commit f8cd4c1bbf
  1. 46
      tagactionmanager.cpp
  2. 16
      tagactionmanager.h

@ -22,8 +22,11 @@
#include "messageactions.h"
#include "messagecore/taglistmonitor.h"
#include <nepomuk2/tag.h>
#include <Nepomuk2/Tag>
#include <Nepomuk2/ResourceManager>
#include <Nepomuk2/Query/QueryServiceClient>
#include <Nepomuk2/Query/Result>
#include <Nepomuk2/Query/ResourceTypeTerm>
#include <KAction>
#include <KActionCollection>
@ -137,17 +140,21 @@ void TagActionManager::createActions()
if ( mTags.isEmpty() ) {
const QList<Nepomuk2::Tag> 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<Nepomuk2::Query::Result>)),
this, SLOT(newTagEntries(QList<Nepomuk2::Query::Result>)) );
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<Nepomuk2::Query::Result> &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 )
{

@ -25,6 +25,15 @@
#include "tag.h"
#include <QMap>
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<Nepomuk2::Query::Result>& 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<Tag::Ptr> mTags;
};
Nepomuk2::Query::QueryServiceClient *mTagQueryClient;
};
}
#endif

Loading…
Cancel
Save