┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views/versioncontrol
diff options
context:
space:
mode:
authorEmmanuel Pescosta <[email protected]>2015-02-25 12:12:55 +0100
committerEmmanuel Pescosta <[email protected]>2015-02-25 17:21:10 +0100
commit25751088c33ce507096a3e25ee1eeaa7de38c76b (patch)
treef3c046a0d41819f2081d4787d75bdb46a5262c94 /src/views/versioncontrol
parentf6b4f562167969365d4aae14d73060c6fdb8270f (diff)
Move the KVersionControlPlugin2 interface from konqlib to Dolphin and remove the deprecated KVersionControlPlugin interface from konqlib
REVIEW: 122687
Diffstat (limited to 'src/views/versioncontrol')
-rw-r--r--src/views/versioncontrol/kversioncontrolplugin.cpp29
-rw-r--r--src/views/versioncontrol/kversioncontrolplugin.h223
-rw-r--r--src/views/versioncontrol/updateitemstatesthread.cpp20
-rw-r--r--src/views/versioncontrol/updateitemstatesthread.h6
-rw-r--r--src/views/versioncontrol/versioncontrolobserver.cpp41
-rw-r--r--src/views/versioncontrol/versioncontrolobserver.h10
6 files changed, 270 insertions, 59 deletions
diff --git a/src/views/versioncontrol/kversioncontrolplugin.cpp b/src/views/versioncontrol/kversioncontrolplugin.cpp
new file mode 100644
index 000000000..2c0632878
--- /dev/null
+++ b/src/views/versioncontrol/kversioncontrolplugin.cpp
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (C) 2011 by Vishesh Yadav <[email protected]> *
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * *
+ * This library is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Library General Public *
+ * License version 2 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Library General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Library General Public License *
+ * along with this library; see the file COPYING.LIB. If not, write to *
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301, USA. *
+ *****************************************************************************/
+
+#include "kversioncontrolplugin.h"
+
+KVersionControlPlugin::KVersionControlPlugin(QObject* parent) :
+ QObject(parent)
+{
+}
+
+KVersionControlPlugin::~KVersionControlPlugin()
+{
+}
diff --git a/src/views/versioncontrol/kversioncontrolplugin.h b/src/views/versioncontrol/kversioncontrolplugin.h
new file mode 100644
index 000000000..e5a267848
--- /dev/null
+++ b/src/views/versioncontrol/kversioncontrolplugin.h
@@ -0,0 +1,223 @@
+/*****************************************************************************
+ * Copyright (C) 2011 by Vishesh Yadav <[email protected]> *
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * *
+ * This library is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Library General Public *
+ * License version 2 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Library General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Library General Public License *
+ * along with this library; see the file COPYING.LIB. If not, write to *
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301, USA. *
+ *****************************************************************************/
+
+#ifndef KVERSIONCONTROLPLUGIN_H
+#define KVERSIONCONTROLPLUGIN_H
+
+#include <dolphin_export.h>
+
+#include <QObject>
+#include <KFileItem>
+#include <QAction>
+
+/**
+ * @brief Base class for version control plugins.
+ *
+ * Enables the file manager to show the version state
+ * of a versioned file. To write a custom plugin, the following
+ * steps are required (in the example below it is assumed that a plugin for
+ * Subversion will be written):
+ *
+ * - Create a fileviewsvnplugin.desktop file with the following content:
+ * <code>
+ * [Desktop Entry]
+ * Type=Service
+ * Name=Subversion
+ * X-KDE-ServiceTypes=FileViewVersionControlPlugin
+ * MimeType=text/plain;
+ * X-KDE-Library=fileviewsvnplugin
+ * </code>
+ *
+ * - Create a class FileViewSvnPlugin derived from KVersionControlPlugin and
+ * implement all abstract interfaces (fileviewsvnplugin.h, fileviewsvnplugin.cpp).
+ *
+ * - Take care that the constructor has the following signature:
+ * <code>
+ * FileViewSvnPlugin(QObject* parent, const QList<QVariant>& args);
+ * </code>
+ *
+ * - Add the following lines at the top of fileviewsvnplugin.cpp:
+ * <code>
+ * #include <KPluginFactory>
+ * #include <KPluginLoader>
+ * K_PLUGIN_FACTORY(FileViewSvnPluginFactory, registerPlugin<FileViewSvnPlugin>();)
+ * K_EXPORT_PLUGIN(FileViewSvnPluginFactory("fileviewsvnplugin"))
+ * </code>
+ *
+ * - Add the following lines to your CMakeLists.txt file:
+ * <code>
+ * kde4_add_plugin(fileviewsvnplugin fileviewsvnplugin.cpp)
+ * target_link_libraries(fileviewsvnplugin konq)
+ * install(FILES fileviewsvnplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+ * </code>
+ *
+ * General implementation notes:
+ *
+ * - The implementations of beginRetrieval(), endRetrieval() and versionState()
+ * can contain blocking operations, as Dolphin will execute
+ * those methods in a separate thread. It is assured that
+ * all other methods are invoked in a serialized way, so that it is not necessary for
+ * the plugin to use any mutex.
+ *
+ * - Dolphin keeps only one instance of the plugin, which is instantiated shortly after
+ * starting Dolphin. Take care that the constructor does no expensive and time
+ * consuming operations.
+ *
+ * @since 4.8
+ */
+class DOLPHIN_EXPORT KVersionControlPlugin : public QObject
+{
+ Q_OBJECT
+
+public:
+ enum ItemVersion
+ {
+ /** The file is not under version control. */
+ UnversionedVersion,
+ /**
+ * The file is under version control and represents
+ * the latest version.
+ */
+ NormalVersion,
+ /**
+ * The file is under version control and a newer
+ * version exists on the main branch.
+ */
+ UpdateRequiredVersion,
+ /**
+ * The file is under version control and has been
+ * modified locally. All modifications will be part
+ * of the next commit.
+ */
+ LocallyModifiedVersion,
+ /**
+ * The file has not been under version control but
+ * has been marked to get added with the next commit.
+ */
+ AddedVersion,
+ /**
+ * The file is under version control but has been marked
+ * for getting removed with the next commit.
+ */
+ RemovedVersion,
+ /**
+ * The file is under version control and has been locally
+ * modified. A modification has also been done on the main
+ * branch.
+ */
+ ConflictingVersion,
+ /**
+ * The file is under version control and has local
+ * modifications, which will not be part of the next
+ * commit (or are "unstaged" in git jargon).
+ * @since 4.6
+ */
+ LocallyModifiedUnstagedVersion,
+ /**
+ * The file is not under version control and is listed
+ * in the ignore list of the version control system.
+ * @since 4.8
+ */
+ IgnoredVersion,
+ /**
+ * The file is is tracked by the version control system, but
+ * is missing in the directory (e.g. by deleted without using
+ * a version control command).
+ * @since 4.8
+ */
+ MissingVersion
+ };
+
+ KVersionControlPlugin(QObject* parent = 0);
+ virtual ~KVersionControlPlugin();
+
+ /**
+ * Returns the name of the file which stores
+ * the version controls information.
+ * (e. g. .svn, .cvs, .git).
+ */
+ virtual QString fileName() const = 0;
+
+ /**
+ * Is invoked whenever the version control
+ * information will get retrieved for the directory
+ * \p directory. It is assured that the directory
+ * contains a trailing slash.
+ */
+ virtual bool beginRetrieval(const QString& directory) = 0;
+
+ /**
+ * Is invoked after the version control information has been
+ * received. It is assured that
+ * KVersionControlPluginV2::beginInfoRetrieval() has been
+ * invoked before.
+ */
+ virtual void endRetrieval() = 0;
+
+ /**
+ * @return The version for the item \p item.
+ * It is assured that KVersionControlPlugin::beginInfoRetrieval() has been
+ * invoked before and that the file is part of the directory specified
+ * in beginInfoRetrieval().
+ */
+ virtual ItemVersion itemVersion(const KFileItem& item) const = 0;
+
+ /**
+ * @return List of actions that are available for the items \p items.
+ * It is recommended to keep the number of returned actions small
+ * in case if an item is an unversioned directory that is not
+ * inside the hierarchy tree of the version control system. This
+ * prevents having a cluttered context menu for directories
+ * outside the version control system.
+ */
+ virtual QList<QAction*> actions(const KFileItemList& items) const = 0;
+
+Q_SIGNALS:
+ /**
+ * Should be emitted when the version state of items might have been changed
+ * after the last retrieval (e. g. by executing a context menu action
+ * of the version control plugin). The file manager will be triggered to
+ * update the version states of the directory \p directory by invoking
+ * KVersionControlPlugin::beginRetrieval(),
+ * KVersionControlPlugin::itemVersion() and
+ * KVersionControlPlugin::endRetrieval().
+ */
+ void itemVersionsChanged();
+
+ /**
+ * Is emitted if an information message with the content \a msg
+ * should be shown.
+ */
+ void infoMessage(const QString& msg);
+
+ /**
+ * Is emitted if an error message with the content \a msg
+ * should be shown.
+ */
+ void errorMessage(const QString& msg);
+
+ /**
+ * Is emitted if an "operation completed" message with the content \a msg
+ * should be shown.
+ */
+ void operationCompletedMessage(const QString& msg);
+};
+
+#endif // KVERSIONCONTROLPLUGIN_H
+
diff --git a/src/views/versioncontrol/updateitemstatesthread.cpp b/src/views/versioncontrol/updateitemstatesthread.cpp
index 4f0122e0f..e4413fabf 100644
--- a/src/views/versioncontrol/updateitemstatesthread.cpp
+++ b/src/views/versioncontrol/updateitemstatesthread.cpp
@@ -19,9 +19,7 @@
#include "updateitemstatesthread.h"
-#include <kversioncontrolplugin2.h>
#include <QVector>
-
#include <QMutexLocker>
UpdateItemStatesThread::UpdateItemStatesThread(KVersionControlPlugin* plugin,
@@ -53,20 +51,10 @@ void UpdateItemStatesThread::run()
if (m_plugin->beginRetrieval(it.key())) {
QVector<VersionControlObserver::ItemState>& items = it.value();
const int count = items.count();
-
- KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
- if (pluginV2) {
- for (int i = 0; i < count; ++i) {
- const KFileItem& item = items.at(i).first;
- const KVersionControlPlugin2::ItemVersion version = pluginV2->itemVersion(item);
- items[i].second = version;
- }
- } else {
- for (int i = 0; i < count; ++i) {
- const KFileItem& item = items.at(i).first;
- const KVersionControlPlugin::VersionState state = m_plugin->versionState(item);
- items[i].second = static_cast<KVersionControlPlugin2::ItemVersion>(state);
- }
+ for (int i = 0; i < count; ++i) {
+ const KFileItem& item = items.at(i).first;
+ const KVersionControlPlugin::ItemVersion version = m_plugin->itemVersion(item);
+ items[i].second = version;
}
}
diff --git a/src/views/versioncontrol/updateitemstatesthread.h b/src/views/versioncontrol/updateitemstatesthread.h
index 92a9d59c9..3dc03fc75 100644
--- a/src/views/versioncontrol/updateitemstatesthread.h
+++ b/src/views/versioncontrol/updateitemstatesthread.h
@@ -20,20 +20,18 @@
#ifndef UPDATEITEMSTATESTHREAD_H
#define UPDATEITEMSTATESTHREAD_H
-#include "libdolphin_export.h"
+#include "dolphin_export.h"
#include <views/versioncontrol/versioncontrolobserver.h>
#include <QMutex>
#include <QThread>
-class KVersionControlPlugin;
-
/**
* The performance of updating the version state of items depends
* on the used plugin. To prevent that Dolphin gets blocked by a
* slow plugin, the updating is delegated to a thread.
*/
-class LIBDOLPHINPRIVATE_EXPORT UpdateItemStatesThread : public QThread
+class DOLPHIN_EXPORT UpdateItemStatesThread : public QThread
{
Q_OBJECT
diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp
index 47e3da357..13481cc7a 100644
--- a/src/views/versioncontrol/versioncontrolobserver.cpp
+++ b/src/views/versioncontrol/versioncontrolobserver.cpp
@@ -26,7 +26,6 @@
#include "dolphindebug.h"
#include <KServiceTypeTrader>
#include <kitemviews/kfileitemmodel.h>
-#include <kversioncontrolplugin2.h>
#include "updateitemstatesthread.h"
@@ -89,8 +88,6 @@ KFileItemModel* VersionControlObserver::model() const
QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) const
{
- QList<QAction*> actions;
-
bool hasNullItems = false;
foreach (const KFileItem& item, items) {
if (item.isNull()) {
@@ -101,30 +98,10 @@ QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) cons
}
if (!m_model || hasNullItems) {
- 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.
- 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();
- }
- }
-
- actions = directory.isEmpty() ? m_plugin->contextMenuActions(items)
- : m_plugin->contextMenuActions(directory);
+ return {};
}
- return actions;
+ return m_plugin->actions(items);
}
void VersionControlObserver::delayedDirectoryVerification()
@@ -156,14 +133,8 @@ void VersionControlObserver::verifyDirectory()
m_plugin = searchPlugin(rootItem.url());
if (m_plugin) {
- KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
- if (pluginV2) {
- connect(pluginV2, &KVersionControlPlugin2::itemVersionsChanged,
- this, &VersionControlObserver::silentDirectoryVerification);
- } else {
- connect(m_plugin, &KVersionControlPlugin::versionStatesChanged,
- this, &VersionControlObserver::silentDirectoryVerification);
- }
+ connect(m_plugin, &KVersionControlPlugin::itemVersionsChanged,
+ this, &VersionControlObserver::silentDirectoryVerification);
connect(m_plugin, &KVersionControlPlugin::infoMessage,
this, &VersionControlObserver::infoMessage);
connect(m_plugin, &KVersionControlPlugin::errorMessage,
@@ -205,7 +176,7 @@ void VersionControlObserver::slotThreadFinished()
foreach (const ItemState& item, items) {
const KFileItem& fileItem = item.first;
- const KVersionControlPlugin2::ItemVersion version = item.second;
+ const KVersionControlPlugin::ItemVersion version = item.second;
QHash<QByteArray, QVariant> values;
values.insert("version", QVariant(version));
m_model->setData(m_model->index(fileItem), values);
@@ -268,7 +239,7 @@ int VersionControlObserver::createItemStatesList(QMap<QString, QVector<ItemState
if (expansionLevel == currentExpansionLevel) {
ItemState itemState;
itemState.first = m_model->fileItem(index);
- itemState.second = KVersionControlPlugin2::UnversionedVersion;
+ itemState.second = KVersionControlPlugin::UnversionedVersion;
items.append(itemState);
} else if (expansionLevel > currentExpansionLevel) {
diff --git a/src/views/versioncontrol/versioncontrolobserver.h b/src/views/versioncontrol/versioncontrolobserver.h
index a43dc3415..c817c2187 100644
--- a/src/views/versioncontrol/versioncontrolobserver.h
+++ b/src/views/versioncontrol/versioncontrolobserver.h
@@ -20,11 +20,13 @@
#ifndef VERSIONCONTROLOBSERVER_H
#define VERSIONCONTROLOBSERVER_H
-#include "libdolphin_export.h"
+#include "dolphin_export.h"
+
+#include "kversioncontrolplugin.h"
#include <KFileItem>
+
#include <QUrl>
-#include <kversioncontrolplugin2.h>
#include <QList>
#include <QObject>
#include <QString>
@@ -43,7 +45,7 @@ class UpdateItemStatesThread;
*
* @see VersionControlPlugin
*/
-class LIBDOLPHINPRIVATE_EXPORT VersionControlObserver : public QObject
+class DOLPHIN_EXPORT VersionControlObserver : public QObject
{
Q_OBJECT
@@ -100,7 +102,7 @@ private slots:
void slotThreadFinished();
private:
- typedef QPair<KFileItem, KVersionControlPlugin2::ItemVersion> ItemState;
+ typedef QPair<KFileItem, KVersionControlPlugin::ItemVersion> ItemState;
void updateItemStates();