diff options
| author | Emmanuel Pescosta <[email protected]> | 2015-02-27 11:30:27 +0100 |
|---|---|---|
| committer | Emmanuel Pescosta <[email protected]> | 2015-02-27 11:30:27 +0100 |
| commit | 9aee5d22513f0367febab54b38b3a7dc58d120bb (patch) | |
| tree | 99cf391070ac5d4650a3f1b309c3ec2e814f1ac6 /src/views/versioncontrol | |
| parent | f025aeb63aa2a38e91c43d99ba9955793d3adf1e (diff) | |
| parent | b701b7e4edefb628d6f8b14146b2e299bd0ce5fc (diff) | |
Merge branch 'frameworks'
Diffstat (limited to 'src/views/versioncontrol')
| -rw-r--r-- | src/views/versioncontrol/kversioncontrolplugin.cpp | 29 | ||||
| -rw-r--r-- | src/views/versioncontrol/kversioncontrolplugin.h | 223 | ||||
| -rw-r--r-- | src/views/versioncontrol/updateitemstatesthread.cpp | 19 | ||||
| -rw-r--r-- | src/views/versioncontrol/updateitemstatesthread.h | 8 | ||||
| -rw-r--r-- | src/views/versioncontrol/versioncontrolobserver.cpp | 112 | ||||
| -rw-r--r-- | src/views/versioncontrol/versioncontrolobserver.h | 18 |
6 files changed, 310 insertions, 99 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 62fcd09aa..e4413fabf 100644 --- a/src/views/versioncontrol/updateitemstatesthread.cpp +++ b/src/views/versioncontrol/updateitemstatesthread.cpp @@ -19,8 +19,7 @@ #include "updateitemstatesthread.h" -#include <kversioncontrolplugin2.h> - +#include <QVector> #include <QMutexLocker> UpdateItemStatesThread::UpdateItemStatesThread(KVersionControlPlugin* plugin, @@ -52,17 +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) { - items[i].version = pluginV2->itemVersion(items[i].item); - } - } else { - for (int i = 0; i < count; ++i) { - const KVersionControlPlugin::VersionState state = m_plugin->versionState(items[i].item); - items[i].version = 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; } } @@ -75,4 +67,3 @@ QMap<QString, QVector<VersionControlObserver::ItemState> > UpdateItemStatesThrea return m_itemStates; } -#include "updateitemstatesthread.moc" diff --git a/src/views/versioncontrol/updateitemstatesthread.h b/src/views/versioncontrol/updateitemstatesthread.h index 5c6c6a208..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 @@ -53,7 +51,7 @@ public: QMap<QString, QVector<VersionControlObserver::ItemState> > itemStates() const; protected: - virtual void run(); + virtual void run() Q_DECL_OVERRIDE; private: QMutex* m_globalPluginMutex; // Protects the m_plugin globally diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp index 6affe80d3..4b0d65029 100644 --- a/src/views/versioncontrol/versioncontrolobserver.cpp +++ b/src/views/versioncontrol/versioncontrolobserver.cpp @@ -21,16 +21,15 @@ #include "dolphin_versioncontrolsettings.h" -#include <KLocale> +#include <KLocalizedString> #include <KService> +#include "dolphindebug.h" #include <KServiceTypeTrader> #include <kitemviews/kfileitemmodel.h> -#include <kversioncontrolplugin2.h> #include "updateitemstatesthread.h" #include <QFile> -#include <QMutexLocker> #include <QTimer> VersionControlObserver::VersionControlObserver(QObject* parent) : @@ -51,8 +50,8 @@ VersionControlObserver::VersionControlObserver(QObject* parent) : m_dirVerificationTimer = new QTimer(this); m_dirVerificationTimer->setSingleShot(true); m_dirVerificationTimer->setInterval(500); - connect(m_dirVerificationTimer, SIGNAL(timeout()), - this, SLOT(verifyDirectory())); + connect(m_dirVerificationTimer, &QTimer::timeout, + this, &VersionControlObserver::verifyDirectory); } VersionControlObserver::~VersionControlObserver() @@ -66,19 +65,19 @@ VersionControlObserver::~VersionControlObserver() void VersionControlObserver::setModel(KFileItemModel* model) { if (m_model) { - disconnect(m_model, SIGNAL(itemsInserted(KItemRangeList)), - this, SLOT(delayedDirectoryVerification())); - disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)), - this, SLOT(delayedDirectoryVerification())); + disconnect(m_model, &KFileItemModel::itemsInserted, + this, &VersionControlObserver::delayedDirectoryVerification); + disconnect(m_model, &KFileItemModel::itemsChanged, + this, &VersionControlObserver::delayedDirectoryVerification); } m_model = model; if (model) { - connect(m_model, SIGNAL(itemsInserted(KItemRangeList)), - this, SLOT(delayedDirectoryVerification())); - connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)), - this, SLOT(delayedDirectoryVerification())); + connect(m_model, &KFileItemModel::itemsInserted, + this, &VersionControlObserver::delayedDirectoryVerification); + connect(m_model, &KFileItemModel::itemsChanged, + this, &VersionControlObserver::delayedDirectoryVerification); } } @@ -89,42 +88,20 @@ 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()) { - kWarning() << "Requesting version-control-actions for empty items"; + qCWarning(DolphinDebug) << "Requesting version-control-actions for empty items"; hasNullItems = true; break; } } - 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(KUrl::AddTrailingSlash); - } - } - - actions = directory.isEmpty() ? m_plugin->contextMenuActions(items) - : m_plugin->contextMenuActions(directory); + if (!m_model || hasNullItems || !isVersioned()) { + return {}; } - return actions; + return m_plugin->actions(items); } void VersionControlObserver::delayedDirectoryVerification() @@ -156,20 +133,14 @@ void VersionControlObserver::verifyDirectory() m_plugin = searchPlugin(rootItem.url()); if (m_plugin) { - 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)), - this, SIGNAL(errorMessage(QString))); - connect(m_plugin, SIGNAL(operationCompletedMessage(QString)), - this, SIGNAL(operationCompletedMessage(QString))); + connect(m_plugin, &KVersionControlPlugin::itemVersionsChanged, + this, &VersionControlObserver::silentDirectoryVerification); + connect(m_plugin, &KVersionControlPlugin::infoMessage, + this, &VersionControlObserver::infoMessage); + connect(m_plugin, &KVersionControlPlugin::errorMessage, + this, &VersionControlObserver::errorMessage); + connect(m_plugin, &KVersionControlPlugin::operationCompletedMessage, + this, &VersionControlObserver::operationCompletedMessage); if (!m_versionedDirectory) { m_versionedDirectory = true; @@ -204,9 +175,11 @@ void VersionControlObserver::slotThreadFinished() const QVector<ItemState>& items = it.value(); foreach (const ItemState& item, items) { + const KFileItem& fileItem = item.first; + const KVersionControlPlugin::ItemVersion version = item.second; QHash<QByteArray, QVariant> values; - values.insert("version", QVariant(item.version)); - m_model->setData(m_model->index(item.item), values); + values.insert("version", QVariant(version)); + m_model->setData(m_model->index(fileItem), values); } } @@ -241,10 +214,10 @@ void VersionControlObserver::updateItemStates() emit infoMessage(i18nc("@info:status", "Updating version information...")); } m_updateItemStatesThread = new UpdateItemStatesThread(m_plugin, itemStates); - connect(m_updateItemStatesThread, SIGNAL(finished()), - this, SLOT(slotThreadFinished())); - connect(m_updateItemStatesThread, SIGNAL(finished()), - m_updateItemStatesThread, SLOT(deleteLater())); + connect(m_updateItemStatesThread, &UpdateItemStatesThread::finished, + this, &VersionControlObserver::slotThreadFinished); + connect(m_updateItemStatesThread, &UpdateItemStatesThread::finished, + m_updateItemStatesThread, &UpdateItemStatesThread::deleteLater); m_updateItemStatesThread->start(); // slotThreadFinished() is called when finished } @@ -265,8 +238,8 @@ int VersionControlObserver::createItemStatesList(QMap<QString, QVector<ItemState if (expansionLevel == currentExpansionLevel) { ItemState itemState; - itemState.item = m_model->fileItem(index); - itemState.version = KVersionControlPlugin2::UnversionedVersion; + itemState.first = m_model->fileItem(index); + itemState.second = KVersionControlPlugin::UnversionedVersion; items.append(itemState); } else if (expansionLevel > currentExpansionLevel) { @@ -278,14 +251,14 @@ int VersionControlObserver::createItemStatesList(QMap<QString, QVector<ItemState } if (items.count() > 0) { - const KUrl& url = items.first().item.url(); - itemStates.insert(url.directory(KUrl::AppendTrailingSlash), items); + const QUrl& url = items.first().first.url(); + itemStates.insert(url.adjusted(QUrl::RemoveFilename).path(), items); } return index - firstIndex; // number of processed items } -KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& directory) const +KVersionControlPlugin* VersionControlObserver::searchPlugin(const QUrl& directory) const { static bool pluginsAvailable = true; static QList<KVersionControlPlugin*> plugins; @@ -324,7 +297,7 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director // Verify whether the current directory contains revision information // like .svn, .git, ... foreach (KVersionControlPlugin* plugin, plugins) { - const QString fileName = directory.path(KUrl::AddTrailingSlash) + plugin->fileName(); + const QString fileName = directory.path() + '/' + plugin->fileName(); if (QFile::exists(fileName)) { // The score of this plugin is 0 (best), so we can just return this plugin, // instead of going through the plugin scoring procedure, we can't find a better one ;) @@ -338,11 +311,11 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director // m_versionedDirectory. Drawback: Until e. g. Git is recognized, the root directory // must be shown at least once. if (m_versionedDirectory) { - KUrl dirUrl(directory); - KUrl upUrl = dirUrl.upUrl(); + QUrl dirUrl(directory); + QUrl upUrl = KIO::upUrl(dirUrl); int upUrlCounter = 1; while ((upUrlCounter < bestScore) && (upUrl != dirUrl)) { - const QString fileName = dirUrl.path(KUrl::AddTrailingSlash) + plugin->fileName(); + const QString fileName = dirUrl.path() + '/' + plugin->fileName(); if (QFile::exists(fileName)) { if (upUrlCounter < bestScore) { bestPlugin = plugin; @@ -351,7 +324,7 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director break; } dirUrl = upUrl; - upUrl = dirUrl.upUrl(); + upUrl = KIO::upUrl(dirUrl); ++upUrlCounter; } } @@ -365,4 +338,3 @@ bool VersionControlObserver::isVersioned() const return m_versionedDirectory && m_plugin; } -#include "versioncontrolobserver.moc" diff --git a/src/views/versioncontrol/versioncontrolobserver.h b/src/views/versioncontrol/versioncontrolobserver.h index d12d2cfe0..c817c2187 100644 --- a/src/views/versioncontrol/versioncontrolobserver.h +++ b/src/views/versioncontrol/versioncontrolobserver.h @@ -20,12 +20,14 @@ #ifndef VERSIONCONTROLOBSERVER_H #define VERSIONCONTROLOBSERVER_H -#include <libdolphin_export.h> +#include "dolphin_export.h" + +#include "kversioncontrolplugin.h" #include <KFileItem> -#include <kversioncontrolplugin2.h> + +#include <QUrl> #include <QList> -#include <QMutex> #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,11 +102,7 @@ private slots: void slotThreadFinished(); private: - struct ItemState - { - KFileItem item; - KVersionControlPlugin2::ItemVersion version; - }; + typedef QPair<KFileItem, KVersionControlPlugin::ItemVersion> ItemState; void updateItemStates(); @@ -128,7 +126,7 @@ private: * Returns a matching plugin for the given directory. * 0 is returned, if no matching plugin has been found. */ - KVersionControlPlugin* searchPlugin(const KUrl& directory) const; + KVersionControlPlugin* searchPlugin(const QUrl& directory) const; /** * Returns true, if the directory contains a version control information. |
