1 /*****************************************************************************
2 * Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
3 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License version 2 as published by the Free Software Foundation. *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Library General Public License for more details. *
14 * You should have received a copy of the GNU Library General Public License *
15 * along with this library; see the file COPYING.LIB. If not, write to *
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301, USA. *
18 *****************************************************************************/
20 #ifndef KVERSIONCONTROLPLUGIN_H
21 #define KVERSIONCONTROLPLUGIN_H
23 #include <dolphinvcs_export.h>
31 * @brief Base class for version control plugins.
33 * Enables the file manager to show the version state
34 * of a versioned file. To write a custom plugin, the following
35 * steps are required (in the example below it is assumed that a plugin for
36 * Subversion will be written):
38 * - Create a fileviewsvnplugin.desktop file with the following content:
43 * X-KDE-ServiceTypes=FileViewVersionControlPlugin
44 * MimeType=text/plain;
45 * X-KDE-Library=fileviewsvnplugin
48 * - Create a class FileViewSvnPlugin derived from KVersionControlPlugin and
49 * implement all abstract interfaces (fileviewsvnplugin.h, fileviewsvnplugin.cpp).
51 * - Take care that the constructor has the following signature:
53 * FileViewSvnPlugin(QObject* parent, const QList<QVariant>& args);
56 * - Add the following lines at the top of fileviewsvnplugin.cpp:
58 * #include <KPluginFactory>
59 * #include <KPluginLoader>
60 * K_PLUGIN_FACTORY(FileViewSvnPluginFactory, registerPlugin<FileViewSvnPlugin>();)
61 * K_EXPORT_PLUGIN(FileViewSvnPluginFactory("fileviewsvnplugin"))
64 * - Add the following lines to your CMakeLists.txt file:
66 * kde4_add_plugin(fileviewsvnplugin fileviewsvnplugin.cpp)
67 * target_link_libraries(fileviewsvnplugin konq)
68 * install(FILES fileviewsvnplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
71 * General implementation notes:
73 * - The implementations of beginRetrieval(), endRetrieval() and versionState()
74 * can contain blocking operations, as Dolphin will execute
75 * those methods in a separate thread. It is assured that
76 * all other methods are invoked in a serialized way, so that it is not necessary for
77 * the plugin to use any mutex.
79 * - Dolphin keeps only one instance of the plugin, which is instantiated shortly after
80 * starting Dolphin. Take care that the constructor does no expensive and time
81 * consuming operations.
85 class DOLPHINVCS_EXPORT KVersionControlPlugin
: public QObject
92 /** The file is not under version control. */
95 * The file is under version control and represents
100 * The file is under version control and a newer
101 * version exists on the main branch.
103 UpdateRequiredVersion
,
105 * The file is under version control and has been
106 * modified locally. All modifications will be part
107 * of the next commit.
109 LocallyModifiedVersion
,
111 * The file has not been under version control but
112 * has been marked to get added with the next commit.
116 * The file is under version control but has been marked
117 * for getting removed with the next commit.
121 * The file is under version control and has been locally
122 * modified. A modification has also been done on the main
127 * The file is under version control and has local
128 * modifications, which will not be part of the next
129 * commit (or are "unstaged" in git jargon).
132 LocallyModifiedUnstagedVersion
,
134 * The file is not under version control and is listed
135 * in the ignore list of the version control system.
140 * The file is tracked by the version control system, but
141 * is missing in the directory (e.g. by deleted without using
142 * a version control command).
148 KVersionControlPlugin(QObject
* parent
= nullptr);
149 ~KVersionControlPlugin() override
;
152 * Returns the name of the file which stores
153 * the version controls information.
154 * (e. g. .svn, .cvs, .git).
156 virtual QString
fileName() const = 0;
159 * Is invoked whenever the version control
160 * information will get retrieved for the directory
161 * \p directory. It is assured that the directory
162 * contains a trailing slash.
164 virtual bool beginRetrieval(const QString
& directory
) = 0;
167 * Is invoked after the version control information has been
168 * received. It is assured that
169 * KVersionControlPlugin::beginRetrieval() has been
172 virtual void endRetrieval() = 0;
175 * @return The version for the item \p item.
176 * It is assured that KVersionControlPlugin::beginRetrieval() has been
177 * invoked before and that the file is part of the directory specified
178 * in beginRetrieval().
180 virtual ItemVersion
itemVersion(const KFileItem
& item
) const = 0;
183 * @return List of actions that are available for the \p items in a version controlled
186 virtual QList
<QAction
*> versionControlActions(const KFileItemList
& items
) const = 0;
189 * @return List of actions that are available for the out of version control
190 * items \p items. It's opposed to the \p versionedActions. Common usage
191 * is for clone/checkout actions.
193 virtual QList
<QAction
*> outOfVersionControlActions(const KFileItemList
& items
) const = 0;
197 * Should be emitted when the version state of items might have been changed
198 * after the last retrieval (e. g. by executing a context menu action
199 * of the version control plugin). The file manager will be triggered to
200 * update the version states of the directory \p directory by invoking
201 * KVersionControlPlugin::beginRetrieval(),
202 * KVersionControlPlugin::itemVersion() and
203 * KVersionControlPlugin::endRetrieval().
205 void itemVersionsChanged();
208 * Is emitted if an information message with the content \a msg
211 void infoMessage(const QString
& msg
);
214 * Is emitted if an error message with the content \a msg
217 void errorMessage(const QString
& msg
);
220 * Is emitted if an "operation completed" message with the content \a msg
223 void operationCompletedMessage(const QString
& msg
);
226 #endif // KVERSIONCONTROLPLUGIN_H