]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/versioncontrol/fileviewsvnplugin.cpp
Share one tooltip instance for all tooltip manager instances
[dolphin.git] / src / versioncontrol / fileviewsvnplugin.cpp
index 91a37a8782939e00633e3b582c39f74c633b88a3..00bb373fe0ed55c32b64ca23a2e64039dc47f937 100644 (file)
@@ -43,8 +43,8 @@ K_EXPORT_PLUGIN(FileViewSvnPluginFactory("fileviewsvnplugin"))
 
 FileViewSvnPlugin::FileViewSvnPlugin(QObject* parent, const QList<QVariant>& args) :
     KVersionControlPlugin(parent),
+    m_pendingOperation(false),
     m_versionInfoHash(),
-    m_versionInfoKeys(),
     m_updateAction(0),
     m_showLocalChangesAction(0),
     m_commitAction(0),
@@ -102,6 +102,16 @@ bool FileViewSvnPlugin::beginRetrieval(const QString& directory)
 {
     Q_ASSERT(directory.endsWith('/'));
 
+    // Clear all entries for this directory including the entries
+    // for sub directories
+    QMutableHashIterator<QString, VersionState> it(m_versionInfoHash);
+    while (it.hasNext()) {
+        it.next();
+        if (it.key().startsWith(directory)) {
+            it.remove();
+        }
+    }
+
     QStringList arguments;
     arguments << "status" << "--show-updates" << directory;
 
@@ -126,16 +136,21 @@ bool FileViewSvnPlugin::beginRetrieval(const QString& directory)
                 break;
             }
 
-            int pos = filePath.indexOf('/');
-            const int length = filePath.length() - pos - 1;
-            filePath = filePath.mid(pos, length);
-            if (!filePath.isEmpty()) {
-                m_versionInfoHash.insert(filePath, state);
+            // Only values with a different state as 'NormalVersion'
+            // are added to the hash table. If a value is not in the
+            // hash table, it is automatically defined as 'NormalVersion'
+            // (see FileViewSvnPlugin::versionState()).
+            if (state != NormalVersion) {
+                int pos = filePath.indexOf('/');
+                const int length = filePath.length() - pos - 1;
+                filePath = filePath.mid(pos, length);
+                if (!filePath.isEmpty()) {
+                    m_versionInfoHash.insert(filePath, state);
+                }
             }
         }
     }
 
-    m_versionInfoKeys = m_versionInfoHash.keys();
     return true;
 }
 
@@ -159,13 +174,15 @@ KVersionControlPlugin::VersionState FileViewSvnPlugin::versionState(const KFileI
     // The item is a directory. Check whether an item listed by 'svn status' (= m_versionInfoHash)
     // is part of this directory. In this case a local modification should be indicated in the
     // directory already.
-    foreach (const QString& key, m_versionInfoKeys) {
-        if (key.startsWith(itemUrl)) {
-            const VersionState state = m_versionInfoHash.value(key);
+    QHash<QString, VersionState>::const_iterator it = m_versionInfoHash.constBegin();
+    while (it != m_versionInfoHash.constEnd()) {
+        if (it.key().startsWith(itemUrl)) {
+            const VersionState state = m_versionInfoHash.value(it.key());
             if (state == LocallyModifiedVersion) {
                 return LocallyModifiedVersion;
             }
         }
+        ++it;
     }
 
     return NormalVersion;
@@ -213,7 +230,7 @@ QList<QAction*> FileViewSvnPlugin::contextMenuActions(const KFileItemList& items
 
 QList<QAction*> FileViewSvnPlugin::contextMenuActions(const QString& directory)
 {
-    const bool enabled = m_contextItems.isEmpty();
+    const bool enabled = !m_pendingOperation;
     if (enabled) {
         m_contextDir = directory;
     }
@@ -311,6 +328,8 @@ void FileViewSvnPlugin::removeFiles()
 
 void FileViewSvnPlugin::slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus)
 {
+    m_pendingOperation = false;
+
     if ((exitStatus != QProcess::NormalExit) || (exitCode != 0)) {
         emit errorMessage(m_errorMsg);
     } else if (m_contextItems.isEmpty()) {
@@ -323,10 +342,11 @@ void FileViewSvnPlugin::slotOperationCompleted(int exitCode, QProcess::ExitStatu
 
 void FileViewSvnPlugin::slotOperationError()
 {
-    emit errorMessage(m_errorMsg);
-
     // don't do any operation on other items anymore
     m_contextItems.clear();
+    m_pendingOperation = false;
+
+    emit errorMessage(m_errorMsg);
 }
 
 void FileViewSvnPlugin::execSvnCommand(const QString& svnCommand,
@@ -345,6 +365,8 @@ void FileViewSvnPlugin::execSvnCommand(const QString& svnCommand,
 
 void FileViewSvnPlugin::startSvnCommandProcess()
 {
+    m_pendingOperation = true;
+
     QProcess* process = new QProcess(this);
     connect(process, SIGNAL(finished(int, QProcess::ExitStatus)),
             this, SLOT(slotOperationCompleted(int, QProcess::ExitStatus)));