File indexing completed on 2024-05-12 05:47:52
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Vishesh Yadav <vishesh3y@gmail.com> 0003 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef KVERSIONCONTROLPLUGIN_H 0009 #define KVERSIONCONTROLPLUGIN_H 0010 0011 #include <dolphinvcs_export.h> 0012 0013 #include <QAction> 0014 #include <QObject> 0015 0016 class KFileItemList; 0017 class KFileItem; 0018 /** 0019 * @brief Base class for version control plugins. 0020 * 0021 * Enables the file manager to show the version state 0022 * of a versioned file. To write a custom plugin, the following 0023 * steps are required (in the example below it is assumed that a plugin for 0024 * Subversion will be written): 0025 * 0026 * - Create a fileviewsvnplugin.json file with the following content: 0027 * <code> 0028 * { 0029 * "KPlugin": { 0030 * "Description": "The svn plugin", 0031 * "Name": "Svn" 0032 * } 0033 * } 0034 0035 * </code> 0036 * 0037 * - Create a class FileViewSvnPlugin derived from KVersionControlPlugin and 0038 * implement all abstract interfaces (fileviewsvnplugin.h, fileviewsvnplugin.cpp). 0039 * 0040 * - Take care that the constructor has the following signature: 0041 * <code> 0042 * FileViewSvnPlugin(QObject* parent, const QList<QVariant>& args); 0043 * </code> 0044 * 0045 * - Add the following lines at the top of fileviewsvnplugin.cpp: 0046 * <code> 0047 * #include <KPluginFactory> 0048 * K_PLUGIN_CLASS_WITH_JSON(FileViewSvnPlugin, "fileviewsvnplugin.json") 0049 * </code> 0050 * 0051 * - Add the following lines to your CMakeLists.txt file: 0052 * <code> 0053 * kcoreaddons_add_plugin(fileviewsvnplugin SOURCES fileviewsvnplugin.cpp INSTALL_NAMESPACE "dolphin/vcs") 0054 * target_link_libraries(fileviewsvnplugin DolphinVcs) 0055 * </code> 0056 * 0057 * General implementation notes: 0058 * 0059 * - The implementations of beginRetrieval(), endRetrieval() and versionState() 0060 * can contain blocking operations, as Dolphin will execute 0061 * those methods in a separate thread. It is assured that 0062 * all other methods are invoked in a serialized way, so that it is not necessary for 0063 * the plugin to use any mutex. 0064 * 0065 * - Dolphin keeps only one instance of the plugin, which is instantiated shortly after 0066 * starting Dolphin. Take care that the constructor does no expensive and time 0067 * consuming operations. 0068 * 0069 * @since 4.8 0070 */ 0071 class DOLPHINVCS_EXPORT KVersionControlPlugin : public QObject 0072 { 0073 Q_OBJECT 0074 0075 public: 0076 enum ItemVersion { 0077 /** The file is not under version control. */ 0078 UnversionedVersion, 0079 /** 0080 * The file is under version control and represents 0081 * the latest version. 0082 */ 0083 NormalVersion, 0084 /** 0085 * The file is under version control and a newer 0086 * version exists on the main branch. 0087 */ 0088 UpdateRequiredVersion, 0089 /** 0090 * The file is under version control and has been 0091 * modified locally. All modifications will be part 0092 * of the next commit. 0093 */ 0094 LocallyModifiedVersion, 0095 /** 0096 * The file has not been under version control but 0097 * has been marked to get added with the next commit. 0098 */ 0099 AddedVersion, 0100 /** 0101 * The file is under version control but has been marked 0102 * for getting removed with the next commit. 0103 */ 0104 RemovedVersion, 0105 /** 0106 * The file is under version control and has been locally 0107 * modified. A modification has also been done on the main 0108 * branch. 0109 */ 0110 ConflictingVersion, 0111 /** 0112 * The file is under version control and has local 0113 * modifications, which will not be part of the next 0114 * commit (or are "unstaged" in git jargon). 0115 * @since 4.6 0116 */ 0117 LocallyModifiedUnstagedVersion, 0118 /** 0119 * The file is not under version control and is listed 0120 * in the ignore list of the version control system. 0121 * @since 4.8 0122 */ 0123 IgnoredVersion, 0124 /** 0125 * The file is tracked by the version control system, but 0126 * is missing in the directory (e.g. by deleted without using 0127 * a version control command). 0128 * @since 4.8 0129 */ 0130 MissingVersion 0131 }; 0132 0133 KVersionControlPlugin(QObject *parent = nullptr); 0134 ~KVersionControlPlugin() override; 0135 0136 /** 0137 * Returns the name of the file which stores 0138 * the version controls information. 0139 * (e. g. .svn, .cvs, .git). 0140 */ 0141 virtual QString fileName() const = 0; 0142 0143 /** 0144 * Returns the path of the local repository root for the versioned directory 0145 * Returns an empty QString when directory is not part of a working copy 0146 */ 0147 virtual QString localRepositoryRoot(const QString &directory) const; 0148 0149 /** 0150 * Is invoked whenever the version control 0151 * information will get retrieved for the directory 0152 * \p directory. It is assured that the directory 0153 * contains a trailing slash. 0154 */ 0155 virtual bool beginRetrieval(const QString &directory) = 0; 0156 0157 /** 0158 * Is invoked after the version control information has been 0159 * received. It is assured that 0160 * KVersionControlPlugin::beginRetrieval() has been 0161 * invoked before. 0162 */ 0163 virtual void endRetrieval() = 0; 0164 0165 /** 0166 * @return The version for the item \p item. 0167 * It is assured that KVersionControlPlugin::beginRetrieval() has been 0168 * invoked before and that the file is part of the directory specified 0169 * in beginRetrieval(). 0170 */ 0171 virtual ItemVersion itemVersion(const KFileItem &item) const = 0; 0172 0173 /** 0174 * @return List of actions that are available for the \p items in a version controlled 0175 * path. 0176 */ 0177 virtual QList<QAction *> versionControlActions(const KFileItemList &items) const = 0; 0178 0179 /** 0180 * @return List of actions that are available for the out of version control 0181 * items \p items. It's opposed to the \p versionedActions. Common usage 0182 * is for clone/checkout actions. 0183 * @since 21.04 0184 */ 0185 virtual QList<QAction *> outOfVersionControlActions(const KFileItemList &items) const = 0; 0186 0187 Q_SIGNALS: 0188 /** 0189 * Should be emitted when the version state of items might have been changed 0190 * after the last retrieval (e. g. by executing a context menu action 0191 * of the version control plugin). The file manager will be triggered to 0192 * update the version states of the directory \p directory by invoking 0193 * KVersionControlPlugin::beginRetrieval(), 0194 * KVersionControlPlugin::itemVersion() and 0195 * KVersionControlPlugin::endRetrieval(). 0196 */ 0197 void itemVersionsChanged(); 0198 0199 /** 0200 * Is emitted if an information message with the content \a msg 0201 * should be shown. 0202 */ 0203 void infoMessage(const QString &msg); 0204 0205 /** 0206 * Is emitted if an error message with the content \a msg 0207 * should be shown. 0208 */ 0209 void errorMessage(const QString &msg); 0210 0211 /** 0212 * Is emitted if an "operation completed" message with the content \a msg 0213 * should be shown. 0214 */ 0215 void operationCompletedMessage(const QString &msg); 0216 }; 0217 0218 #endif // KVERSIONCONTROLPLUGIN_H