]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/versioncontrol/versioncontrolobserver.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / versioncontrol / versioncontrolobserver.cpp
index cab62be39d6b7619a972b2c17a4d8bae339e0a55..744d81f4ff250de8b1cc4e759655c4fb312c12b1 100644 (file)
@@ -58,7 +58,7 @@ VersionControlObserver::VersionControlObserver(QAbstractItemView* view) :
         m_dirLister = m_dolphinModel->dirLister();
         connect(m_dirLister, SIGNAL(completed()),
                 this, SLOT(delayedDirectoryVerification()));
+
         // The verification timer specifies the timeout until the shown directory
         // is checked whether it is versioned. Per default it is assumed that users
         // don't iterate through versioned directories and a high timeout is used
@@ -99,9 +99,9 @@ VersionControlObserver::~VersionControlObserver()
 QList<QAction*> VersionControlObserver::contextMenuActions(const KFileItemList& items) const
 {
     QList<QAction*> actions;
-    if (isVersioned() && m_updateItemStatesThread->beginReadItemStates()) {
+    if (isVersioned() && m_updateItemStatesThread->lockPlugin()) {
         actions = m_plugin->contextMenuActions(items);
-        m_updateItemStatesThread->endReadItemStates();
+        m_updateItemStatesThread->unlockPlugin();
     }
     return actions;
 }
@@ -109,9 +109,9 @@ QList<QAction*> VersionControlObserver::contextMenuActions(const KFileItemList&
 QList<QAction*> VersionControlObserver::contextMenuActions(const QString& directory) const
 {
     QList<QAction*> actions;
-    if (isVersioned() && m_updateItemStatesThread->beginReadItemStates()) {
+    if (isVersioned() && m_updateItemStatesThread->lockPlugin()) {
         actions = m_plugin->contextMenuActions(directory);
-        m_updateItemStatesThread->endReadItemStates();
+        m_updateItemStatesThread->unlockPlugin();
     }
 
     return actions;
@@ -131,7 +131,7 @@ void VersionControlObserver::silentDirectoryVerification()
 
 void VersionControlObserver::verifyDirectory()
 {
-    KUrl versionControlUrl = m_dirLister->url();
+    const KUrl versionControlUrl = m_dirLister->url();
     if (!versionControlUrl.isLocalFile()) {
         return;
     }
@@ -141,16 +141,16 @@ void VersionControlObserver::verifyDirectory()
     }
 
     m_plugin = searchPlugin(versionControlUrl);
-    const bool foundVersionInfo = (m_plugin != 0);
-    if (!foundVersionInfo && m_versionedDirectory) {
-        // Version control systems like Git provide the version information
-        // file only in the root directory. Check whether the version information file can
-        // be found in one of the parent directories.
-
-        // TODO...
-    }
+    if (m_plugin != 0) {
+        connect(m_plugin, SIGNAL(versionStatesChanged()),
+                this, SLOT(silentDirectoryVerification()));
+        connect(m_plugin, SIGNAL(infoMessage(QString)),
+                this, SIGNAL(infoMessage(QString)));
+        connect(m_plugin, SIGNAL(errorMessage(QString)),
+                this, SIGNAL(errorMessage(QString)));
+        connect(m_plugin, SIGNAL(operationCompletedMessage(QString)),
+                this, SIGNAL(operationCompletedMessage(QString)));
 
-    if (foundVersionInfo) {
         if (!m_versionedDirectory) {
             m_versionedDirectory = true;
 
@@ -161,14 +161,6 @@ void VersionControlObserver::verifyDirectory()
                     this, SLOT(delayedDirectoryVerification()));
             connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)),
                     this, SLOT(delayedDirectoryVerification()));
-            connect(m_plugin, SIGNAL(versionStatesChanged()),
-                    this, SLOT(silentDirectoryVerification()));
-            connect(m_plugin, SIGNAL(infoMessage(const QString&)),
-                    this, SIGNAL(infoMessage(const QString&)));
-            connect(m_plugin, SIGNAL(errorMessage(const QString&)),
-                    this, SIGNAL(errorMessage(const QString&)));
-            connect(m_plugin, SIGNAL(operationCompletedMessage(const QString&)),
-                    this, SIGNAL(operationCompletedMessage(const QString&)));
         }
         updateItemStates();
     } else if (m_versionedDirectory) {
@@ -241,7 +233,7 @@ void VersionControlObserver::updateItemStates()
         m_pendingItemStatesUpdate = true;
         return;
     }
-    
+
     QList<ItemState> itemStates;
     addDirectory(QModelIndex(), itemStates);
     if (!itemStates.isEmpty()) {
@@ -259,7 +251,7 @@ void VersionControlObserver::addDirectory(const QModelIndex& parentIndex, QList<
     for (int row = 0; row < rowCount; ++row) {
         const QModelIndex index = m_dolphinModel->index(row, DolphinModel::Version, parentIndex);
         addDirectory(index, itemStates);
-        
+
         ItemState itemState;
         itemState.index = index;
         itemState.item = m_dolphinModel->itemForIndex(index);
@@ -275,7 +267,7 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director
     static QList<KVersionControlPlugin*> plugins;
 
     if (!pluginsAvailable) {
-        // a searching for plugins has already been done, but no
+        // A searching for plugins has already been done, but no
         // plugins are installed
         return 0;
     }
@@ -283,12 +275,11 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director
     if (plugins.isEmpty()) {
         // No searching for plugins has been done yet. Query the KServiceTypeTrader for
         // all fileview version control plugins and remember them in 'plugins'.
-        const QString disabledPlugins = VersionControlSettings::disabledPlugins();
-        const QStringList disabledPluginsList = disabledPlugins.split(',');
+        const QStringList enabledPlugins = VersionControlSettings::enabledPlugins();
 
         const KService::List pluginServices = KServiceTypeTrader::self()->query("FileViewVersionControlPlugin");
         for (KService::List::ConstIterator it = pluginServices.constBegin(); it != pluginServices.constEnd(); ++it) {
-            if (!disabledPluginsList.contains((*it)->name())) {
+            if (enabledPlugins.contains((*it)->name())) {
                 KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>();
                 Q_ASSERT(plugin != 0);
                 plugins.append(plugin);
@@ -300,15 +291,36 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director
         }
     }
 
-    // verify whether the current directory contains revision information
+    // Verify whether the current directory contains revision information
     // like .svn, .git, ...
     foreach (KVersionControlPlugin* plugin, plugins) {
-        KUrl fileUrl = directory;
+        // Use the KDirLister cache to check for .svn, .git, ... files
+        KUrl dirUrl(directory);
+        KUrl fileUrl = dirUrl;
         fileUrl.addPath(plugin->fileName());
         const KFileItem item = m_dirLister->findByUrl(fileUrl);
         if (!item.isNull()) {
             return plugin;
         }
+
+        // Version control systems like Git provide the version information
+        // file only in the root directory. Check whether the version information file can
+        // be found in one of the parent directories. For performance reasons this
+        // step is only done, if the previous directory was marked as versioned by
+        // m_versionedDirectory. Drawback: Until e. g. Git is recognized, the root directory
+        // must be shown at least once.
+        if (m_versionedDirectory) {
+            KUrl upUrl = dirUrl.upUrl();
+            while (upUrl != dirUrl) {
+                const QString filePath = dirUrl.pathOrUrl(KUrl::AddTrailingSlash) + plugin->fileName();
+                QFileInfo file(filePath);
+                if (file.exists()) {
+                    return plugin;
+                }
+                dirUrl = upUrl;
+                upUrl = dirUrl.upUrl();
+            }
+        }
     }
 
     return 0;