Changeset View
Changeset View
Standalone View
Standalone View
src/services/ServicePluginManager.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
63 | 63 | | |||
64 | 64 | | |||
65 | ServicePluginManager::~ServicePluginManager() | 65 | ServicePluginManager::~ServicePluginManager() | ||
66 | { | 66 | { | ||
67 | } | 67 | } | ||
68 | 68 | | |||
69 | 69 | | |||
70 | void | 70 | void | ||
71 | ServicePluginManager::setFactories( const QList<Plugins::PluginFactory*> &factories ) | 71 | ServicePluginManager::setFactories( const QList<QSharedPointer<Plugins::PluginFactory> > &factories ) | ||
72 | { | 72 | { | ||
73 | QSet<Plugins::PluginFactory*> newFactories = factories.toSet(); | 73 | QSet<QSharedPointer<Plugins::PluginFactory> > newFactories = factories.toSet(); | ||
74 | QSet<Plugins::PluginFactory*> oldFactories = m_factories.toSet(); | 74 | QSet<QSharedPointer<Plugins::PluginFactory> > oldFactories = m_factories.toSet(); | ||
75 | 75 | | |||
76 | // remove old factories | 76 | // remove old factories | ||
77 | foreach( Plugins::PluginFactory* pFactory, oldFactories - newFactories ) | 77 | for( const auto &pFactory : oldFactories - newFactories ) | ||
78 | { | 78 | { | ||
79 | ServiceFactory *factory = qobject_cast<ServiceFactory*>( pFactory ); | 79 | auto factory = qobject_cast<ServiceFactory*>( pFactory ); | ||
80 | if( !factory ) | 80 | if( !factory ) | ||
81 | continue; | 81 | continue; | ||
82 | 82 | | |||
83 | foreach( ServiceBase * service, factory->activeServices() ) | 83 | foreach( ServiceBase * service, factory->activeServices() ) | ||
84 | ServiceBrowser::instance()->removeCategory( service ); | 84 | ServiceBrowser::instance()->removeCategory( service ); | ||
85 | factory->clearActiveServices(); | 85 | factory->clearActiveServices(); | ||
86 | } | 86 | } | ||
87 | 87 | | |||
88 | // create new factories | 88 | // create new factories | ||
89 | foreach( Plugins::PluginFactory* pFactory, newFactories - oldFactories ) | 89 | for( const auto &pFactory : newFactories - oldFactories ) | ||
90 | { | 90 | { | ||
91 | ServiceFactory *factory = qobject_cast<ServiceFactory*>( pFactory ); | 91 | auto factory = qobject_cast<ServiceFactory*>( pFactory ); | ||
92 | if( !factory ) | 92 | if( !factory ) | ||
93 | continue; | 93 | continue; | ||
94 | 94 | | |||
95 | connect( factory, &ServiceFactory::newService, this, &ServicePluginManager::slotNewService ); | 95 | connect( factory.data(), &ServiceFactory::newService, this, &ServicePluginManager::slotNewService ); | ||
96 | connect( factory, &ServiceFactory::removeService, this, &ServicePluginManager::slotRemoveService ); | 96 | connect( factory.data(), &ServiceFactory::removeService, this, &ServicePluginManager::slotRemoveService ); | ||
97 | } | 97 | } | ||
98 | 98 | | |||
99 | m_factories = factories; | 99 | m_factories = factories; | ||
100 | } | 100 | } | ||
101 | 101 | | |||
102 | void | 102 | void | ||
103 | ServicePluginManager::slotNewService( ServiceBase *newService ) | 103 | ServicePluginManager::slotNewService( ServiceBase *newService ) | ||
104 | { | 104 | { | ||
Show All 9 Lines | 112 | { | |||
114 | debug() << "removed service:" << removedService->name(); | 114 | debug() << "removed service:" << removedService->name(); | ||
115 | ServiceBrowser::instance()->removeCategory( removedService ); | 115 | ServiceBrowser::instance()->removeCategory( removedService ); | ||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | QStringList | 118 | QStringList | ||
119 | ServicePluginManager::loadedServices() const | 119 | ServicePluginManager::loadedServices() const | ||
120 | { | 120 | { | ||
121 | QStringList names; | 121 | QStringList names; | ||
122 | foreach( Plugins::PluginFactory *pFactory, m_factories ) | 122 | for( const auto &pFactory : m_factories ) | ||
123 | { | 123 | { | ||
124 | ServiceFactory *factory = qobject_cast<ServiceFactory*>( pFactory ); | 124 | auto factory = qobject_cast<ServiceFactory*>( pFactory ); | ||
125 | if( !factory ) | 125 | if( !factory ) | ||
126 | continue; | 126 | continue; | ||
127 | 127 | | |||
128 | foreach( ServiceBase *service, factory->activeServices() ) | 128 | foreach( ServiceBase *service, factory->activeServices() ) | ||
129 | names << service->name(); | 129 | names << service->name(); | ||
130 | } | 130 | } | ||
131 | return names; | 131 | return names; | ||
132 | } | 132 | } | ||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |