Changeset View
Changeset View
Standalone View
Standalone View
src/views/versioncontrol/versioncontrolobserver.cpp
Show All 31 Lines | |||||
32 | 32 | | |||
33 | VersionControlObserver::VersionControlObserver(QObject* parent) : | 33 | VersionControlObserver::VersionControlObserver(QObject* parent) : | ||
34 | QObject(parent), | 34 | QObject(parent), | ||
35 | m_pendingItemStatesUpdate(false), | 35 | m_pendingItemStatesUpdate(false), | ||
36 | m_versionedDirectory(false), | 36 | m_versionedDirectory(false), | ||
37 | m_silentUpdate(false), | 37 | m_silentUpdate(false), | ||
38 | m_model(nullptr), | 38 | m_model(nullptr), | ||
39 | m_dirVerificationTimer(nullptr), | 39 | m_dirVerificationTimer(nullptr), | ||
40 | m_pluginsInitialized(false), | ||||
40 | m_plugin(nullptr), | 41 | m_plugin(nullptr), | ||
41 | m_updateItemStatesThread(nullptr) | 42 | m_updateItemStatesThread(nullptr) | ||
42 | { | 43 | { | ||
43 | // The verification timer specifies the timeout until the shown directory | 44 | // The verification timer specifies the timeout until the shown directory | ||
44 | // is checked whether it is versioned. Per default it is assumed that users | 45 | // is checked whether it is versioned. Per default it is assumed that users | ||
45 | // don't iterate through versioned directories and a high timeout is used | 46 | // don't iterate through versioned directories and a high timeout is used | ||
46 | // The timeout will be decreased as soon as a versioned directory has been | 47 | // The timeout will be decreased as soon as a versioned directory has been | ||
47 | // found (see verifyDirectory()). | 48 | // found (see verifyDirectory()). | ||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Line(s) | 227 | { | |||
251 | if (items.count() > 0) { | 252 | if (items.count() > 0) { | ||
252 | const QUrl& url = items.first().first.url(); | 253 | const QUrl& url = items.first().first.url(); | ||
253 | itemStates.insert(url.adjusted(QUrl::RemoveFilename).path(), items); | 254 | itemStates.insert(url.adjusted(QUrl::RemoveFilename).path(), items); | ||
254 | } | 255 | } | ||
255 | 256 | | |||
256 | return index - firstIndex; // number of processed items | 257 | return index - firstIndex; // number of processed items | ||
257 | } | 258 | } | ||
258 | 259 | | |||
259 | KVersionControlPlugin* VersionControlObserver::searchPlugin(const QUrl& directory) const | 260 | KVersionControlPlugin* VersionControlObserver::searchPlugin(const QUrl& directory) | ||
260 | { | 261 | { | ||
261 | static bool pluginsAvailable = true; | 262 | if (!m_pluginsInitialized) { | ||
262 | static QList<KVersionControlPlugin*> plugins; | | |||
263 | | ||||
264 | if (!pluginsAvailable) { | | |||
265 | // A searching for plugins has already been done, but no | | |||
266 | // plugins are installed | | |||
267 | return nullptr; | | |||
268 | } | | |||
269 | | ||||
270 | if (plugins.isEmpty()) { | | |||
271 | // No searching for plugins has been done yet. Query the KServiceTypeTrader for | 263 | // No searching for plugins has been done yet. Query the KServiceTypeTrader for | ||
272 | // all fileview version control plugins and remember them in 'plugins'. | 264 | // all fileview version control plugins and remember them in 'plugins'. | ||
273 | const QStringList enabledPlugins = VersionControlSettings::enabledPlugins(); | 265 | const QStringList enabledPlugins = VersionControlSettings::enabledPlugins(); | ||
274 | 266 | | |||
275 | const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin")); | 267 | const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin")); | ||
276 | for (KService::List::ConstIterator it = pluginServices.constBegin(); it != pluginServices.constEnd(); ++it) { | 268 | for (KService::List::ConstIterator it = pluginServices.constBegin(); it != pluginServices.constEnd(); ++it) { | ||
277 | if (enabledPlugins.contains((*it)->name())) { | 269 | if (enabledPlugins.contains((*it)->name())) { | ||
278 | KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>(); | 270 | KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>(this); | ||
elvisangelaccio: This looks like an unrelated change. If a parent here is necessary, please add it with another… | |||||
It prevents leak, in previous commit plugins leave to application lifetime, now not. anthonyfieroni: It prevents leak, in previous commit plugins leave to application lifetime, now not. | |||||
279 | if (plugin) { | 271 | if (plugin) { | ||
280 | plugins.append(plugin); | 272 | m_plugins.append(plugin); | ||
281 | } | 273 | } | ||
282 | } | 274 | } | ||
283 | } | 275 | } | ||
284 | if (plugins.isEmpty()) { | 276 | m_pluginsInitialized = true; | ||
285 | pluginsAvailable = false; | | |||
286 | return nullptr; | | |||
287 | } | 277 | } | ||
278 | | ||||
279 | if (m_plugins.empty()) { | ||||
280 | // A searching for plugins has already been done, but no | ||||
281 | // plugins are installed | ||||
282 | return nullptr; | ||||
288 | } | 283 | } | ||
289 | 284 | | |||
290 | // We use the number of upUrl() calls to find the best matching plugin | 285 | // We use the number of upUrl() calls to find the best matching plugin | ||
291 | // for the given directory. The smaller value, the better it is (0 is best). | 286 | // for the given directory. The smaller value, the better it is (0 is best). | ||
292 | KVersionControlPlugin* bestPlugin = nullptr; | 287 | KVersionControlPlugin* bestPlugin = nullptr; | ||
293 | int bestScore = INT_MAX; | 288 | int bestScore = INT_MAX; | ||
294 | 289 | | |||
295 | // Verify whether the current directory contains revision information | 290 | // Verify whether the current directory contains revision information | ||
296 | // like .svn, .git, ... | 291 | // like .svn, .git, ... | ||
297 | foreach (KVersionControlPlugin* plugin, plugins) { | 292 | foreach (KVersionControlPlugin* plugin, m_plugins) { | ||
298 | const QString fileName = directory.path() + '/' + plugin->fileName(); | 293 | const QString fileName = directory.path() + '/' + plugin->fileName(); | ||
299 | if (QFile::exists(fileName)) { | 294 | if (QFile::exists(fileName)) { | ||
300 | // The score of this plugin is 0 (best), so we can just return this plugin, | 295 | // The score of this plugin is 0 (best), so we can just return this plugin, | ||
301 | // instead of going through the plugin scoring procedure, we can't find a better one ;) | 296 | // instead of going through the plugin scoring procedure, we can't find a better one ;) | ||
302 | return plugin; | 297 | return plugin; | ||
303 | } | 298 | } | ||
304 | 299 | | |||
305 | // Version control systems like Git provide the version information | 300 | // Version control systems like Git provide the version information | ||
Show All 33 Lines |
This looks like an unrelated change. If a parent here is necessary, please add it with another commit.
If instead this change is indeed related to this patch, please explain why in the commit message. I'm not confident about this code because there is multi-threading involved.