[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdepimlibs/akregator_port] krss: Startup: Ensure that Akonadi is running
From:       Frank Osterfeld <frank.osterfeld () kdemail ! net>
Date:       2012-03-31 15:16:21
Message-ID: 20120331151621.D7971A60D8 () git ! kde ! org
[Download RAW message or body]

Git commit cb9ec91ca44c0a4fe7ea4beae6356abdfc3c8b2a by Frank Osterfeld.
Committed on 03/08/2009 at 19:52.
Pushed by osterfeld into branch 'akregator_port'.

Startup: Ensure that Akonadi is running
disable the mainwindow if Akonadi is not running
Add ResourceManager::forceUpdate to force a refresh of the available resources
There is still some race, when Control::start actually starts the server, existing \
rss resources are not found right after it returns, causing the creation of another \
resource.

svn path=/branches/work/akonadi-ports/kdepim/; revision=1006408

M  +23   -13   krss/resourcemanager.cpp
M  +2    -0    krss/resourcemanager.h

http://commits.kde.org/kdepimlibs/cb9ec91ca44c0a4fe7ea4beae6356abdfc3c8b2a

diff --git a/krss/resourcemanager.cpp b/krss/resourcemanager.cpp
index 8ec9478..04b1a6e 100644
--- a/krss/resourcemanager.cpp
+++ b/krss/resourcemanager.cpp
@@ -34,8 +34,9 @@
 #include <QtCore/QHash>
 #include <boost/shared_ptr.hpp>
 
+using namespace Akonadi;
 using namespace KRss;
-using boost::shared_ptr;
+using namespace boost;
 
 namespace KRss {
 
@@ -56,14 +57,23 @@ ResourceManager* ResourceManager::self()
 ResourceManager::ResourceManager()
     : d( new ResourceManagerPrivate() )
 {
-    QList<Akonadi::AgentInstance> instances = \
                Akonadi::AgentManager::self()->instances();
-    Q_FOREACH( const Akonadi::AgentInstance& instance, instances ) {
-        kDebug() << "Instance:" << instance.identifier();
-        kDebug() << "Capabilities:" << instance.type().capabilities();
-        if ( instance.type().capabilities().contains( "RssResource" ) ) {
-            NetResource* const resource = new NetResource( instance.identifier(), \
                instance.name() );
-            d->m_resources.insert( instance.identifier(), shared_ptr<NetResource>( \
                resource ) );
-        }
+    forceUpdate();
+}
+
+void ResourceManager::forceUpdate()
+{
+    const QHash<QString, shared_ptr<NetResource> > old = d->m_resources;
+
+    d->m_resources.clear();
+
+    const QList<AgentInstance> instances = AgentManager::self()->instances();
+    Q_FOREACH( const AgentInstance& instance, instances ) {
+        if ( !instance.type().capabilities().contains( "RssResource" ) )
+            continue;
+        shared_ptr<NetResource> res = old.value( instance.identifier() );
+        if ( !res )
+            res = shared_ptr<NetResource>( new NetResource( instance.identifier(), \
instance.name() ) ); +        d->m_resources.insert( instance.identifier(), res );
     }
 }
 
@@ -98,11 +108,11 @@ QList<shared_ptr<NetResource> > ResourceManager::netResources() \
const  
 void ResourceManager::registerAttributes()
 {
-    Akonadi::AttributeFactory::registerAttribute<TagIdsAttribute>();
-    Akonadi::AttributeFactory::registerAttribute<SubscriptionLabelsCollectionAttribute>();
                
-    Akonadi::AttributeFactory::registerAttribute<FeedPropertiesCollectionAttribute>();
 +    AttributeFactory::registerAttribute<TagIdsAttribute>();
+    AttributeFactory::registerAttribute<SubscriptionLabelsCollectionAttribute>();
+    AttributeFactory::registerAttribute<FeedPropertiesCollectionAttribute>();
 #ifndef HAVE_NEPOMUK
-    Akonadi::AttributeFactory::registerAttribute<TagPropertiesAttribute>();
+    AttributeFactory::registerAttribute<TagPropertiesAttribute>();
 #endif
 }
 
diff --git a/krss/resourcemanager.h b/krss/resourcemanager.h
index b5a5dbd..b3f99a0 100644
--- a/krss/resourcemanager.h
+++ b/krss/resourcemanager.h
@@ -47,6 +47,8 @@ public:
     QList<boost::shared_ptr<NetResource> > netResources() const;
     //QList<boost::shared_ptr<SearchResource> > searchResources();
 
+    void forceUpdate();
+
     // TODO: use a static initializer to register the attributes
     // automatically on library load?
     static void registerAttributes();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic