From 1a528b0cf1f1059bc72a72729bca2f01f79bc7c3 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sun, 13 Sep 2009 14:49:26 +0000 Subject: [PATCH] Originally it was intended to move the SVN plugin from Dolphin to kdevplatform, but kdevplatform most probably won't get released with KDE 4.4. So for KDE 4.4 Dolphin will temporary contain the plugin in it's own codebase. As soon as kdevplatform will get released the SVN plugin will get moved to kdevplatform. Still open: KServiceTypeTrader::query does not find the "FileViewVersionControlPlugin", I could not find the root cause for this yet (old cache?) svn path=/trunk/KDE/kdebase/apps/; revision=1022921 --- src/CMakeLists.txt | 10 +- ...ontrolplugin.cpp => fileviewsvnplugin.cpp} | 54 ++-- src/fileviewsvnplugin.desktop | 6 + src/fileviewsvnplugin.h | 93 +++++++ src/kversioncontrolplugin.h | 233 ------------------ src/versioncontrolobserver.cpp | 15 +- 6 files changed, 139 insertions(+), 272 deletions(-) rename src/{kversioncontrolplugin.cpp => fileviewsvnplugin.cpp} (89%) create mode 100644 src/fileviewsvnplugin.desktop create mode 100644 src/fileviewsvnplugin.h delete mode 100644 src/kversioncontrolplugin.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6487faace3..deccbfe285 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,6 @@ set(dolphinprivate_LIB_SRCS dolphinremoteencoding.cpp draganddrophelper.cpp folderexpander.cpp - kversioncontrolplugin.cpp renamedialog.cpp selectiontoggle.cpp selectionmanager.cpp @@ -82,15 +81,22 @@ set(dolphinpart_SRCS dolphinpart.cpp ) +set(fileviewsvnplugin_SRCS + fileviewsvnplugin.cpp +) kde4_add_plugin(dolphinpart ${dolphinpart_SRCS}) +kde4_add_plugin(fileviewsvnplugin ${fileviewsvnplugin_SRCS}) target_link_libraries(dolphinpart dolphinprivate konq ${KDE4_KPARTS_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KFILE_LIBS}) +target_link_libraries(fileviewsvnplugin ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${KDE4_KIO_LIBS} konq) -install(TARGETS dolphinpart DESTINATION ${PLUGIN_INSTALL_DIR} ) +install(TARGETS dolphinpart DESTINATION ${PLUGIN_INSTALL_DIR}) +install(TARGETS fileviewsvnplugin DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES dolphinpart.rc DESTINATION ${DATA_INSTALL_DIR}/dolphinpart) install(FILES dolphinpart.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) +install(FILES fileviewsvnplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR}) ########################################## diff --git a/src/kversioncontrolplugin.cpp b/src/fileviewsvnplugin.cpp similarity index 89% rename from src/kversioncontrolplugin.cpp rename to src/fileviewsvnplugin.cpp index eb683c17cc..a543299544 100644 --- a/src/kversioncontrolplugin.cpp +++ b/src/fileviewsvnplugin.cpp @@ -17,19 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include "kversioncontrolplugin.h" - -KVersionControlPlugin::KVersionControlPlugin() -{ -} - -KVersionControlPlugin::~KVersionControlPlugin() -{ -} - -#include "kversioncontrolplugin.moc" - -// ---------------------------------------------------------------------------- +#include "fileviewsvnplugin.h" #include #include @@ -47,7 +35,7 @@ KVersionControlPlugin::~KVersionControlPlugin() #include #include -SubversionPlugin::SubversionPlugin() : +FileViewSvnPlugin::FileViewSvnPlugin() : m_versionInfoHash(), m_versionInfoKeys(), m_updateAction(0), @@ -92,16 +80,16 @@ SubversionPlugin::SubversionPlugin() : this, SLOT(removeFiles())); } -SubversionPlugin::~SubversionPlugin() +FileViewSvnPlugin::~FileViewSvnPlugin() { } -QString SubversionPlugin::fileName() const +QString FileViewSvnPlugin::fileName() const { return ".svn"; } -bool SubversionPlugin::beginRetrieval(const QString& directory) +bool FileViewSvnPlugin::beginRetrieval(const QString& directory) { Q_ASSERT(directory.endsWith('/')); @@ -142,11 +130,11 @@ bool SubversionPlugin::beginRetrieval(const QString& directory) return true; } -void SubversionPlugin::endRetrieval() +void FileViewSvnPlugin::endRetrieval() { } -KVersionControlPlugin::VersionState SubversionPlugin::versionState(const KFileItem& item) +KVersionControlPlugin::VersionState FileViewSvnPlugin::versionState(const KFileItem& item) { const QString itemUrl = item.localPath(); if (m_versionInfoHash.contains(itemUrl)) { @@ -174,7 +162,7 @@ KVersionControlPlugin::VersionState SubversionPlugin::versionState(const KFileIt return NormalVersion; } -QList SubversionPlugin::contextMenuActions(const KFileItemList& items) +QList FileViewSvnPlugin::contextMenuActions(const KFileItemList& items) { Q_ASSERT(!items.isEmpty()); foreach (const KFileItem& item, items) { @@ -214,7 +202,7 @@ QList SubversionPlugin::contextMenuActions(const KFileItemList& items) return actions; } -QList SubversionPlugin::contextMenuActions(const QString& directory) +QList FileViewSvnPlugin::contextMenuActions(const QString& directory) { const bool enabled = m_contextItems.isEmpty(); if (enabled) { @@ -235,7 +223,7 @@ QList SubversionPlugin::contextMenuActions(const QString& directory) return actions; } -void SubversionPlugin::updateFiles() +void FileViewSvnPlugin::updateFiles() { execSvnCommand("update", i18nc("@info:status", "Updating SVN repository..."), @@ -243,7 +231,7 @@ void SubversionPlugin::updateFiles() i18nc("@info:status", "Updated SVN repository.")); } -void SubversionPlugin::showLocalChanges() +void FileViewSvnPlugin::showLocalChanges() { Q_ASSERT(!m_contextDir.isEmpty()); Q_ASSERT(m_contextItems.isEmpty()); @@ -254,7 +242,7 @@ void SubversionPlugin::showLocalChanges() KRun::runCommand(command, 0); } -void SubversionPlugin::commitFiles() +void FileViewSvnPlugin::commitFiles() { KDialog dialog(0, Qt::Dialog); @@ -296,7 +284,7 @@ void SubversionPlugin::commitFiles() dialog.saveDialogSize(dialogConfig, KConfigBase::Persistent); } -void SubversionPlugin::addFiles() +void FileViewSvnPlugin::addFiles() { execSvnCommand("add", i18nc("@info:status", "Adding files to SVN repository..."), @@ -304,7 +292,7 @@ void SubversionPlugin::addFiles() i18nc("@info:status", "Added files to SVN repository.")); } -void SubversionPlugin::removeFiles() +void FileViewSvnPlugin::removeFiles() { execSvnCommand("remove", i18nc("@info:status", "Removing files from SVN repository..."), @@ -312,7 +300,7 @@ void SubversionPlugin::removeFiles() i18nc("@info:status", "Removed files from SVN repository.")); } -void SubversionPlugin::slotOperationCompleted() +void FileViewSvnPlugin::slotOperationCompleted() { if (m_contextItems.isEmpty()) { emit operationCompletedMessage(m_operationCompletedMsg); @@ -322,7 +310,7 @@ void SubversionPlugin::slotOperationCompleted() } } -void SubversionPlugin::slotOperationError() +void FileViewSvnPlugin::slotOperationError() { emit errorMessage(m_errorMsg); @@ -330,10 +318,10 @@ void SubversionPlugin::slotOperationError() m_contextItems.clear(); } -void SubversionPlugin::execSvnCommand(const QString& svnCommand, - const QString& infoMsg, - const QString& errorMsg, - const QString& operationCompletedMsg) +void FileViewSvnPlugin::execSvnCommand(const QString& svnCommand, + const QString& infoMsg, + const QString& errorMsg, + const QString& operationCompletedMsg) { emit infoMessage(infoMsg); @@ -344,7 +332,7 @@ void SubversionPlugin::execSvnCommand(const QString& svnCommand, startSvnCommandProcess(); } -void SubversionPlugin::startSvnCommandProcess() +void FileViewSvnPlugin::startSvnCommandProcess() { QProcess* process = new QProcess(this); connect(process, SIGNAL(finished(int)), diff --git a/src/fileviewsvnplugin.desktop b/src/fileviewsvnplugin.desktop new file mode 100644 index 0000000000..959f89af69 --- /dev/null +++ b/src/fileviewsvnplugin.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Type=Service +Name=Subversion +X-KDE-ServiceTypes=FileViewVersionControlPlugin +MimeType=text/plain; +X-KDE-Library=fileviewsvnplugin diff --git a/src/fileviewsvnplugin.h b/src/fileviewsvnplugin.h new file mode 100644 index 0000000000..2cb3d71fbe --- /dev/null +++ b/src/fileviewsvnplugin.h @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2009 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef FILEVIEWSVNPLUGIN_H +#define FILEVIEWSVNPLUGIN_H + +#include +#include +#include +#include + +// TODO: This class will be moved to kdevplatform as soon as kdevplatform will +// be released. Moving it to kdevplatform allows to reuse code for the context +// menu actions like commit, add, update, ... +class FileViewSvnPlugin : public KVersionControlPlugin +{ + Q_OBJECT + +public: + FileViewSvnPlugin(); + virtual ~FileViewSvnPlugin(); + virtual QString fileName() const; + virtual bool beginRetrieval(const QString& directory); + virtual void endRetrieval(); + virtual KVersionControlPlugin::VersionState versionState(const KFileItem& item); + virtual QList contextMenuActions(const KFileItemList& items); + virtual QList contextMenuActions(const QString& directory); + +private slots: + void updateFiles(); + void showLocalChanges(); + void commitFiles(); + void addFiles(); + void removeFiles(); + + void slotOperationCompleted(); + void slotOperationError(); + +private: + /** + * Executes the command "svn {svnCommand}" for the files that have been + * set by getting the context menu actions (see contextMenuActions()). + * @param infoMsg Message that should be shown before the command is executed. + * @param errorMsg Message that should be shown if the execution of the command + * has been failed. + * @param operationCompletedMsg + * Message that should be shown if the execution of the command + * has been completed successfully. + */ + void execSvnCommand(const QString& svnCommand, + const QString& infoMsg, + const QString& errorMsg, + const QString& operationCompletedMsg); + + void startSvnCommandProcess(); + +private: + QHash m_versionInfoHash; + QList m_versionInfoKeys; // cache for accessing the keys of the hash + + QAction* m_updateAction; + QAction* m_showLocalChangesAction; + QAction* m_commitAction; + QAction* m_addAction; + QAction* m_removeAction; + + QString m_command; + QString m_errorMsg; + QString m_operationCompletedMsg; + + QString m_contextDir; + KFileItemList m_contextItems; + + QTemporaryFile m_tempFile; +}; +#endif // FILEVIEWSVNPLUGIN_H + diff --git a/src/kversioncontrolplugin.h b/src/kversioncontrolplugin.h deleted file mode 100644 index e4f55a1c21..0000000000 --- a/src/kversioncontrolplugin.h +++ /dev/null @@ -1,233 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program 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 General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef REVISIONCONTROLPLUGIN_H -#define REVISIONCONTROLPLUGIN_H - -#include - -#include -#include -#include - -class KFileItem; -class KFileItemList; -class QAction; - -/** - * @brief Base class for version control plugins. - * - * Enables the file manager to show the version state - * of a versioned file. - */ -class LIBDOLPHINPRIVATE_EXPORT KVersionControlPlugin : public QObject -{ - Q_OBJECT - -public: - enum VersionState - { - /** 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. - */ - 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 - }; - - KVersionControlPlugin(); - virtual ~KVersionControlPlugin(); - - /** - * Returns the name of the file which stores - * the version control informations. - * (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 - * KVersionControlPlugin::beginInfoRetrieval() has been - * invoked before. - */ - virtual void endRetrieval() = 0; - - /** - * Returns the version state for the file \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 VersionState versionState(const KFileItem& item) = 0; - - /** - * Returns the list of actions that should be shown in the context menu - * for the files \p items. It is assured that the passed list is not empty. - * If an action triggers a change of the versions, the signal - * KVersionControlPlugin::versionStatesChanged() must be emitted. - */ - virtual QList contextMenuActions(const KFileItemList& items) = 0; - - /** - * Returns the list of actions that should be shown in the context menu - * for the directory \p directory. If an action triggers a change of the versions, - * the signal KVersionControlPlugin::versionStatesChanged() must be emitted. - */ - virtual QList contextMenuActions(const QString& directory) = 0; - -signals: - /** - * Should be emitted when the version state of files 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::versionState() and - * KVersionControlPlugin::endRetrieval(). - */ - void versionStatesChanged(); - - /** - * 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); -}; - - - - -// TODO: This is just a temporary test class. It will be made available as -// plugin outside Dolphin later. - -#include -#include -#include - -class LIBDOLPHINPRIVATE_EXPORT SubversionPlugin : public KVersionControlPlugin -{ - Q_OBJECT - -public: - SubversionPlugin(); - virtual ~SubversionPlugin(); - virtual QString fileName() const; - virtual bool beginRetrieval(const QString& directory); - virtual void endRetrieval(); - virtual KVersionControlPlugin::VersionState versionState(const KFileItem& item); - virtual QList contextMenuActions(const KFileItemList& items); - virtual QList contextMenuActions(const QString& directory); - -private slots: - void updateFiles(); - void showLocalChanges(); - void commitFiles(); - void addFiles(); - void removeFiles(); - - void slotOperationCompleted(); - void slotOperationError(); - -private: - /** - * Executes the command "svn {svnCommand}" for the files that have been - * set by getting the context menu actions (see contextMenuActions()). - * @param infoMsg Message that should be shown before the command is executed. - * @param errorMsg Message that should be shown if the execution of the command - * has been failed. - * @param operationCompletedMsg - * Message that should be shown if the execution of the command - * has been completed successfully. - */ - void execSvnCommand(const QString& svnCommand, - const QString& infoMsg, - const QString& errorMsg, - const QString& operationCompletedMsg); - - void startSvnCommandProcess(); - -private: - QHash m_versionInfoHash; - QList m_versionInfoKeys; // cache for accessing the keys of the hash - - QAction* m_updateAction; - QAction* m_showLocalChangesAction; - QAction* m_commitAction; - QAction* m_addAction; - QAction* m_removeAction; - - QString m_command; - QString m_errorMsg; - QString m_operationCompletedMsg; - - QString m_contextDir; - KFileItemList m_contextItems; - - QTemporaryFile m_tempFile; -}; -#endif // REVISIONCONTROLPLUGIN_H - diff --git a/src/versioncontrolobserver.cpp b/src/versioncontrolobserver.cpp index 03bba9f02a..b20db99514 100644 --- a/src/versioncontrolobserver.cpp +++ b/src/versioncontrolobserver.cpp @@ -20,10 +20,12 @@ #include "versioncontrolobserver.h" #include "dolphinmodel.h" -#include "kversioncontrolplugin.h" #include #include +#include +#include +#include #include #include @@ -189,9 +191,14 @@ void VersionControlObserver::verifyDirectory() return; } - if (m_plugin == 0) { - // TODO: just for testing purposes. A plugin approach will be used later. - m_plugin = new SubversionPlugin(); + if (m_plugin == 0) { + // TODO: does not work yet + const KService::List plugins = KServiceTypeTrader::self()->query("FileViewVersionControlPlugin"); + for (KService::List::ConstIterator it = plugins.begin(); it != plugins.end(); ++it) { + // kDebug() << "plugin: " << (*it)->desktopEntryName(); + } + return; + connect(m_plugin, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); connect(m_plugin, SIGNAL(errorMessage(const QString&)),