]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Provide KVersionControlPlugin version 2
authorPeter Penz <peter.penz19@gmail.com>
Sat, 10 Sep 2011 16:08:03 +0000 (18:08 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 10 Sep 2011 16:11:09 +0000 (18:11 +0200)
Based on the work of Vishesh Yadav some extensions where required
for the KVersionControlPlugin interface that have found there way
now into KVersionControlPlugin2.

Beside some interface cleanups it is now possible that a version
control plugin may also provide context actions for directories or
files that are not versioned yet.

REVIEW: 102541

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/views/dolphinfileitemlistwidget.cpp
src/views/dolphinfileitemlistwidget.h
src/views/dolphinview.cpp
src/views/versioncontrol/updateitemstatesthread.cpp
src/views/versioncontrol/versioncontrolobserver.cpp
src/views/versioncontrol/versioncontrolobserver.h

index ff0c4a02d9d0394832df493d42be6e0bd4392ded..c0287340ee7039c2fb67c4cf35bcfb764f5cc7c7 100644 (file)
@@ -223,13 +223,13 @@ int KFileItemModel::index(const KFileItem& item) const
     return m_items.value(item.url(), -1);
 }
 
-KUrl KFileItemModel::rootDirectory() const
+KFileItem KFileItemModel::rootItem() const
 {
     const KDirLister* dirLister = m_dirLister.data();
     if (dirLister) {
-        return dirLister->url();
+        return dirLister->rootItem();
     }
-    return KUrl();
+    return KFileItem();
 }
 
 void KFileItemModel::clear()
index 5d75329d1b8d7bc3ea35de44dc0e1ee18e5f800d..16081704314d5cbb3cce6824581ef0032220be37 100644 (file)
@@ -97,9 +97,9 @@ public:
     int index(const KFileItem& item) const;
 
     /**
-     * @return Root directory of all items.
+     * @return Root item of all items.
      */
-    KUrl rootDirectory() const;
+    KFileItem rootItem() const;
 
     /**
      * Clears all items of the model.
index d39d58cd03ecff7183a6d976a49ce72ae94b4fa7..f3489e1b5e4f2fb17f9fce822cd10407dc7d0926 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <KIcon>
 #include <KIconLoader>
+#include <kversioncontrolplugin2.h>
 #include <QColor>
 
 #include <KDebug>
@@ -41,7 +42,7 @@ void DolphinFileItemListWidget::refreshCache()
     if (values.contains("version")) {
         // The item is under version control. Apply the text color corresponding
         // to its version state.
-        const KVersionControlPlugin::VersionState version = static_cast<KVersionControlPlugin::VersionState>(values.value("version").toInt());
+        const KVersionControlPlugin2::ItemVersion version = static_cast<KVersionControlPlugin2::ItemVersion>(values.value("version").toInt());
         const QColor textColor = styleOption().palette.text().color();
         QColor tintColor = textColor;
 
@@ -49,14 +50,16 @@ void DolphinFileItemListWidget::refreshCache()
         // as tint colors and are mixed with the current set text color. The tint colors
         // have been optimized for the base colors of the corresponding Oxygen emblems.
         switch (version) {
-        case KVersionControlPlugin::UpdateRequiredVersion:          tintColor = Qt::yellow; break;
-        case KVersionControlPlugin::LocallyModifiedUnstagedVersion: tintColor = Qt::green; break;
-        case KVersionControlPlugin::LocallyModifiedVersion:         tintColor = Qt::green; break;
-        case KVersionControlPlugin::AddedVersion:                   tintColor = Qt::green; break;
-        case KVersionControlPlugin::RemovedVersion:                 tintColor = Qt::darkRed; break;
-        case KVersionControlPlugin::ConflictingVersion:             tintColor = Qt::red; break;
-        case KVersionControlPlugin::UnversionedVersion:             tintColor = Qt::white; break;
-        case KVersionControlPlugin::NormalVersion:
+        case KVersionControlPlugin2::UpdateRequiredVersion:          tintColor = Qt::yellow; break;
+        case KVersionControlPlugin2::LocallyModifiedUnstagedVersion: tintColor = Qt::green; break;
+        case KVersionControlPlugin2::LocallyModifiedVersion:         tintColor = Qt::green; break;
+        case KVersionControlPlugin2::AddedVersion:                   tintColor = Qt::green; break;
+        case KVersionControlPlugin2::RemovedVersion:                 tintColor = Qt::darkRed; break;
+        case KVersionControlPlugin2::ConflictingVersion:             tintColor = Qt::red; break;
+        case KVersionControlPlugin2::UnversionedVersion:             tintColor = Qt::white; break;
+        case KVersionControlPlugin2::IgnoredVersion:                 tintColor = Qt::white; break;
+        case KVersionControlPlugin2::MissingVersion:                 tintColor = Qt::red; break;
+        case KVersionControlPlugin2::NormalVersion:
         default:
             break;
         }
@@ -74,7 +77,7 @@ void DolphinFileItemListWidget::refreshCache()
     setTextColor(color);
 }
 
-QPixmap DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::VersionState version, int size)
+QPixmap DolphinFileItemListWidget::overlayForState(KVersionControlPlugin2::ItemVersion version, int size)
 {
     int overlayHeight = KIconLoader::SizeSmall;
     if (size >= KIconLoader::SizeEnormous) {
index 8435b5c18bd387bead782c4e31ea91405e4718e9..87ed0333bccde23aa2b8d7edd0b1342a800877da 100644 (file)
@@ -23,7 +23,7 @@
 #include <libdolphin_export.h>
 
 #include <kitemviews/kfileitemlistwidget.h>
-#include <kversioncontrolplugin.h>
+#include <kversioncontrolplugin2.h>
 
 /**
  * @brief Extends KFileItemListWidget to handle the "version" role.
@@ -43,7 +43,7 @@ protected:
     virtual void refreshCache();
 
 private:
-    static QPixmap overlayForState(KVersionControlPlugin::VersionState state, int size);
+    static QPixmap overlayForState(KVersionControlPlugin2::ItemVersion version, int size);
 
 };
 
index a53934ddcfc036c68cd00f058a6eef74800c1956..7cb594d8e91c825e2a90e67737c1cd745c863ac5 100644 (file)
@@ -521,10 +521,10 @@ QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) c
     QList<QAction*> actions;
 
     if (items.isEmpty()) {
-        const KUrl url = fileItemModel()->rootDirectory();
-        actions = m_versionControlObserver->contextMenuActions(url.path(KUrl::AddTrailingSlash));
+        const KFileItem item = fileItemModel()->rootItem();
+        actions = m_versionControlObserver->actions(KFileItemList() << item);
     } else {
-        actions = m_versionControlObserver->contextMenuActions(items);
+        actions = m_versionControlObserver->actions(items);
     }
 
     return actions;
index 1fa3a6255c815f7029b9fda4a377af1eea925605..f9746aaddb3ec80452f3a158d4c91354c58b7e73 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "updateitemstatesthread.h"
 
+#include <kversioncontrolplugin2.h>
+
 #include <QMutexLocker>
 
 UpdateItemStatesThread::UpdateItemStatesThread() :
@@ -64,9 +66,19 @@ void UpdateItemStatesThread::run()
     if (m_plugin->beginRetrieval(directory)) {
         itemLocker.relock();
         const int count = m_itemStates.count();
-        for (int i = 0; i < count; ++i) {
-            m_itemStates[i].version = m_plugin->versionState(m_itemStates[i].item);
+
+        KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
+        if (pluginV2) {
+            for (int i = 0; i < count; ++i) {
+                m_itemStates[i].version = pluginV2->itemVersion(m_itemStates[i].item);
+            }
+        } else {
+            for (int i = 0; i < count; ++i) {
+                const KVersionControlPlugin::VersionState state = m_plugin->versionState(m_itemStates[i].item);
+                m_itemStates[i].version = static_cast<KVersionControlPlugin2::ItemVersion>(state);
+            }
         }
+
         m_plugin->endRetrieval();
         m_retrievedItems = true;
     }
index c8d9d6874fb5c3d3b1945741c2b5a91774e3df54..20b059035e0d96c006eb97694efa99ab804097bf 100644 (file)
@@ -26,7 +26,7 @@
 #include <KService>
 #include <KServiceTypeTrader>
 #include <kitemviews/kfileitemmodel.h>
-#include <kversioncontrolplugin.h>
+#include <kversioncontrolplugin2.h>
 
 #include "updateitemstatesthread.h"
 
@@ -87,30 +87,41 @@ KFileItemModel* VersionControlObserver::model() const
     return m_model;
 }
 
-QList<QAction*> VersionControlObserver::contextMenuActions(const KFileItemList& items) const
+QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) const
 {
     QList<QAction*> actions;
-    if (isVersioned()) {
+    if (!m_model) {
+        return actions;
+    }
+
+    KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
+    if (pluginV2) {
+        // Use version 2 of the KVersionControlPlugin which allows providing actions
+        // also for non-versioned directories.
         if (m_updateItemStatesThread && m_updateItemStatesThread->lockPlugin()) {
-            actions = m_plugin->contextMenuActions(items);
+            actions = pluginV2->actions(items);
             m_updateItemStatesThread->unlockPlugin();
         } else {
-            actions = m_plugin->contextMenuActions(items);
+            actions = pluginV2->actions(items);
+        }
+    } else if (isVersioned()) {
+        // Support deprecated interfaces from KVersionControlPlugin version 1.
+        // Context menu actions where only available for versioned directories.
+        QString directory;
+        if (items.count() == 1) {
+            const KFileItem rootItem = m_model->rootItem();
+            if (!rootItem.isNull() && items.first().url() == rootItem.url()) {
+                directory = rootItem.url().path(KUrl::AddTrailingSlash);
+            }
         }
-    }
-
-    return actions;
-}
 
-QList<QAction*> VersionControlObserver::contextMenuActions(const QString& directory) const
-{
-    QList<QAction*> actions;
-    if (isVersioned()) {
         if (m_updateItemStatesThread && m_updateItemStatesThread->lockPlugin()) {
-            actions = m_plugin->contextMenuActions(directory);
+            actions = directory.isEmpty() ? m_plugin->contextMenuActions(items)
+                                          : m_plugin->contextMenuActions(directory);
             m_updateItemStatesThread->unlockPlugin();
         } else {
-            actions = m_plugin->contextMenuActions(directory);
+            actions = directory.isEmpty() ? m_plugin->contextMenuActions(items)
+                                          : m_plugin->contextMenuActions(directory);
         }
     }
 
@@ -135,7 +146,7 @@ void VersionControlObserver::verifyDirectory()
         return;
     }
 
-    const KUrl versionControlUrl = m_model->rootDirectory();
+    const KUrl versionControlUrl = m_model->rootItem().url();
     if (!versionControlUrl.isLocalFile()) {
         return;
     }
@@ -146,8 +157,14 @@ void VersionControlObserver::verifyDirectory()
 
     m_plugin = searchPlugin(versionControlUrl);
     if (m_plugin) {
-        connect(m_plugin, SIGNAL(versionStatesChanged()),
-                this, SLOT(silentDirectoryVerification()));
+        KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
+        if (pluginV2) {
+            connect(pluginV2, SIGNAL(itemVersionsChanged()),
+                    this, SLOT(silentDirectoryVerification()));
+        } else {
+            connect(m_plugin, SIGNAL(versionStatesChanged()),
+                    this, SLOT(silentDirectoryVerification()));
+        }
         connect(m_plugin, SIGNAL(infoMessage(QString)),
                 this, SIGNAL(infoMessage(QString)));
         connect(m_plugin, SIGNAL(errorMessage(QString)),
@@ -233,7 +250,7 @@ void VersionControlObserver::updateItemStates()
         ItemState itemState;
         itemState.index = i;
         itemState.item = m_model->fileItem(i);
-        itemState.version = KVersionControlPlugin::UnversionedVersion;
+        itemState.version = KVersionControlPlugin2::UnversionedVersion;
 
         itemStates.append(itemState);
     }
index e160008d7b7652cca27906405bb0aea8ee5e14c4..501af7d6fd450d5198deaa8ddb6548f02471dca0 100644 (file)
@@ -23,7 +23,7 @@
 #include <libdolphin_export.h>
 
 #include <KFileItem>
-#include <kversioncontrolplugin.h>
+#include <kversioncontrolplugin2.h>
 #include <QList>
 #include <QMutex>
 #include <QObject>
@@ -54,8 +54,7 @@ public:
     void setModel(KFileItemModel* model);
     KFileItemModel* model() const;
 
-    QList<QAction*> contextMenuActions(const KFileItemList& items) const;
-    QList<QAction*> contextMenuActions(const QString& directory) const;
+    QList<QAction*> actions(const KFileItemList& items) const;
 
 signals:
     /**
@@ -105,7 +104,7 @@ private:
     {
         int index;
         KFileItem item;
-        KVersionControlPlugin::VersionState version;
+        KVersionControlPlugin2::ItemVersion version;
     };
 
     void updateItemStates();