Changeset View
Changeset View
Standalone View
Standalone View
src/core-impl/collections/support/CollectionManager.cpp
Show All 38 Lines | |||||
39 | 39 | | |||
40 | typedef QPair<Collections::Collection*, CollectionManager::CollectionStatus> CollectionPair; | 40 | typedef QPair<Collections::Collection*, CollectionManager::CollectionStatus> CollectionPair; | ||
41 | 41 | | |||
42 | 42 | | |||
43 | /** Private structure of the collection manager */ | 43 | /** Private structure of the collection manager */ | ||
44 | struct CollectionManager::Private | 44 | struct CollectionManager::Private | ||
45 | { | 45 | { | ||
46 | QList<CollectionPair> collections; | 46 | QList<CollectionPair> collections; | ||
47 | QList<Plugins::PluginFactory*> factories; // factories belong to PluginManager | 47 | QList<QSharedPointer<Plugins::PluginFactory> > factories; // factories belong to PluginManager | ||
48 | 48 | | |||
49 | QList<Collections::TrackProvider*> trackProviders; | 49 | QList<Collections::TrackProvider*> trackProviders; | ||
50 | TimecodeTrackProvider *timecodeTrackProvider; | 50 | TimecodeTrackProvider *timecodeTrackProvider; | ||
51 | Collections::TrackProvider *fileTrackProvider; // special case | 51 | Collections::TrackProvider *fileTrackProvider; // special case | ||
52 | 52 | | |||
53 | Collections::Collection *primaryCollection; | 53 | Collections::Collection *primaryCollection; | ||
54 | 54 | | |||
55 | QReadWriteLock lock; ///< protects all other variables against threading issues | 55 | QReadWriteLock lock; ///< protects all other variables against threading issues | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 98 | { | |||
99 | QWriteLocker locker( &d->lock ); | 99 | QWriteLocker locker( &d->lock ); | ||
100 | 100 | | |||
101 | while (!d->collections.isEmpty() ) | 101 | while (!d->collections.isEmpty() ) | ||
102 | delete d->collections.takeFirst().first; | 102 | delete d->collections.takeFirst().first; | ||
103 | 103 | | |||
104 | d->trackProviders.clear(); | 104 | d->trackProviders.clear(); | ||
105 | delete d->timecodeTrackProvider; | 105 | delete d->timecodeTrackProvider; | ||
106 | delete d->fileTrackProvider; | 106 | delete d->fileTrackProvider; | ||
107 | | ||||
108 | // Hmm, qDeleteAll from Qt 4.8 crashes with our SmartPointerList, do it manually. Bug 285951 | | |||
109 | while (!d->factories.isEmpty() ) | | |||
110 | delete d->factories.takeFirst(); | | |||
111 | } | 107 | } | ||
112 | 108 | | |||
113 | delete d; | 109 | delete d; | ||
114 | } | 110 | } | ||
115 | 111 | | |||
116 | void | 112 | void | ||
117 | CollectionManager::init() | 113 | CollectionManager::init() | ||
118 | { | 114 | { | ||
119 | // register the timecode track provider now, as it needs to get added before loading | 115 | // register the timecode track provider now, as it needs to get added before loading | ||
120 | // the stored playlist... Since it can have playable urls that might also match other providers, it needs to get added first. | 116 | // the stored playlist... Since it can have playable urls that might also match other providers, it needs to get added first. | ||
121 | d->timecodeTrackProvider = new TimecodeTrackProvider(); | 117 | d->timecodeTrackProvider = new TimecodeTrackProvider(); | ||
122 | addTrackProvider( d->timecodeTrackProvider ); | 118 | addTrackProvider( d->timecodeTrackProvider ); | ||
123 | 119 | | |||
124 | // addint fileTrackProvider second since local tracks should be preferred even if the url matches two tracks | 120 | // addint fileTrackProvider second since local tracks should be preferred even if the url matches two tracks | ||
125 | d->fileTrackProvider = new FileTrackProvider(); | 121 | d->fileTrackProvider = new FileTrackProvider(); | ||
126 | addTrackProvider( d->fileTrackProvider ); | 122 | addTrackProvider( d->fileTrackProvider ); | ||
127 | } | 123 | } | ||
128 | 124 | | |||
129 | void | 125 | void | ||
130 | CollectionManager::setFactories( const QList<Plugins::PluginFactory*> &factories ) | 126 | CollectionManager::setFactories( const QList<QSharedPointer<Plugins::PluginFactory> > &factories ) | ||
131 | { | 127 | { | ||
132 | using Collections::CollectionFactory; | 128 | using Collections::CollectionFactory; | ||
133 | 129 | | |||
134 | 130 | | |||
135 | QSet<Plugins::PluginFactory*> newFactories = factories.toSet(); | 131 | QSet<QSharedPointer<Plugins::PluginFactory> > newFactories = factories.toSet(); | ||
136 | QSet<Plugins::PluginFactory*> oldFactories; | 132 | QSet<QSharedPointer<Plugins::PluginFactory> > oldFactories; | ||
137 | 133 | | |||
138 | { | 134 | { | ||
139 | QReadLocker locker( &d->lock ); | 135 | QReadLocker locker( &d->lock ); | ||
140 | oldFactories = d->factories.toSet(); | 136 | oldFactories = d->factories.toSet(); | ||
141 | } | 137 | } | ||
142 | 138 | | |||
143 | // remove old factories | 139 | // remove old factories | ||
144 | foreach( Plugins::PluginFactory* pFactory, oldFactories - newFactories ) | 140 | for( const auto &pFactory : oldFactories - newFactories ) | ||
145 | { | 141 | { | ||
146 | 142 | | |||
147 | CollectionFactory *factory = qobject_cast<CollectionFactory*>( pFactory ); | 143 | auto factory = qobject_cast<CollectionFactory*>( pFactory ); | ||
148 | if( !factory ) | 144 | if( !factory ) | ||
149 | continue; | 145 | continue; | ||
150 | 146 | | |||
151 | disconnect( factory, &CollectionFactory::newCollection, | 147 | disconnect( factory.data(), &CollectionFactory::newCollection, | ||
152 | this, &CollectionManager::slotNewCollection ); | 148 | this, &CollectionManager::slotNewCollection ); | ||
153 | { | 149 | { | ||
154 | QWriteLocker locker( &d->lock ); | 150 | QWriteLocker locker( &d->lock ); | ||
155 | d->factories.removeAll( factory ); | 151 | d->factories.removeAll( factory ); | ||
156 | } | 152 | } | ||
157 | } | 153 | } | ||
158 | 154 | | |||
159 | // create new factories | 155 | // create new factories | ||
160 | foreach( Plugins::PluginFactory* pFactory, newFactories - oldFactories ) | 156 | for( const auto &pFactory : newFactories - oldFactories ) | ||
161 | { | 157 | { | ||
162 | CollectionFactory *factory = qobject_cast<CollectionFactory*>( pFactory ); | 158 | auto factory = qobject_cast<CollectionFactory*>( pFactory ); | ||
163 | if( !factory ) | 159 | if( !factory ) | ||
164 | continue; | 160 | continue; | ||
165 | 161 | | |||
166 | connect( factory, &CollectionFactory::newCollection, | 162 | connect( factory.data(), &CollectionFactory::newCollection, | ||
167 | this, &CollectionManager::slotNewCollection ); | 163 | this, &CollectionManager::slotNewCollection ); | ||
168 | { | 164 | { | ||
169 | QWriteLocker locker( &d->lock ); | 165 | QWriteLocker locker( &d->lock ); | ||
170 | d->factories.append( factory ); | 166 | d->factories.append( factory ); | ||
171 | } | 167 | } | ||
172 | } | 168 | } | ||
173 | } | 169 | } | ||
174 | 170 | | |||
▲ Show 20 Lines • Show All 252 Lines • Show Last 20 Lines |