diff options
| author | Peter Penz <[email protected]> | 2011-09-10 18:08:03 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-09-10 18:11:09 +0200 |
| commit | ff243261742ecd70fb9e417614e757b5956c04aa (patch) | |
| tree | 5ea6591846826b8b7f26179dc69bd2fab06c8ce5 /src/views/versioncontrol/versioncontrolobserver.cpp | |
| parent | c7272df5c17c804fd379e4bac2758850f03695da (diff) | |
Provide KVersionControlPlugin version 2
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
Diffstat (limited to 'src/views/versioncontrol/versioncontrolobserver.cpp')
| -rw-r--r-- | src/views/versioncontrol/versioncontrolobserver.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp index c8d9d6874..20b059035 100644 --- a/src/views/versioncontrol/versioncontrolobserver.cpp +++ b/src/views/versioncontrol/versioncontrolobserver.cpp @@ -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); } |
