]> cloud.milkyroute.net Git - dolphin.git/blob - src/kversioncontrolplugin.h
- The selection changed timer only needs to be created for a DolphinView instance.
[dolphin.git] / src / kversioncontrolplugin.h
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program 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 *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef REVISIONCONTROLPLUGIN_H
21 #define REVISIONCONTROLPLUGIN_H
22
23 #include <libdolphin_export.h>
24
25 #include <QDateTime>
26 #include <QString>
27 #include <QObject>
28
29 class KFileItem;
30 class KFileItemList;
31 class QAction;
32
33 /**
34 * @brief Base class for version control plugins.
35 *
36 * Enables the file manager to show the version state
37 * of a versioned file.
38 */
39 class LIBDOLPHINPRIVATE_EXPORT KVersionControlPlugin : public QObject
40 {
41 Q_OBJECT
42
43 public:
44 enum VersionState
45 {
46 /** The file is not under version control. */
47 UnversionedVersion,
48 /**
49 * The file is under version control and represents
50 * the latest version.
51 */
52 NormalVersion,
53 /**
54 * The file is under version control and a newer
55 * version exists on the main branch.
56 */
57 UpdateRequiredVersion,
58 /**
59 * The file is under version control and has been
60 * modified locally.
61 */
62 LocallyModifiedVersion,
63 /**
64 * The file has not been under version control but
65 * has been marked to get added with the next commit.
66 */
67 AddedVersion,
68 /**
69 * The file is under version control but has been marked
70 * for getting removed with the next commit.
71 */
72 RemovedVersion,
73 /**
74 * The file is under version control and has been locally
75 * modified. A modification has also been done on the main
76 * branch.
77 */
78 ConflictingVersion
79 };
80
81 KVersionControlPlugin();
82 virtual ~KVersionControlPlugin();
83
84 /**
85 * Returns the name of the file which stores
86 * the version control informations.
87 * (e. g. .svn, .cvs, .git).
88 */
89 virtual QString fileName() const = 0;
90
91 /**
92 * Is invoked whenever the version control
93 * information will get retrieved for the directory
94 * \p directory. It is assured that the directory
95 * contains a trailing slash.
96 */
97 virtual bool beginRetrieval(const QString& directory) = 0;
98
99 /**
100 * Is invoked after the version control information has been
101 * received. It is assured that
102 * KVersionControlPlugin::beginInfoRetrieval() has been
103 * invoked before.
104 */
105 virtual void endRetrieval() = 0;
106
107 /**
108 * Returns the version state for the file \p item.
109 * It is assured that KVersionControlPlugin::beginInfoRetrieval() has been
110 * invoked before and that the file is part of the directory specified
111 * in beginInfoRetrieval().
112 */
113 virtual VersionState versionState(const KFileItem& item) = 0;
114
115 /**
116 * Returns the list of actions that should be shown in the context menu
117 * for the files \p items. It is assured that the passed list is not empty.
118 * If an action triggers a change of the versions, the signal
119 * KVersionControlPlugin::versionStatesChanged() must be emitted.
120 */
121 virtual QList<QAction*> contextMenuActions(const KFileItemList& items) = 0;
122
123 /**
124 * Returns the list of actions that should be shown in the context menu
125 * for the directory \p directory. If an action triggers a change of the versions,
126 * the signal KVersionControlPlugin::versionStatesChanged() must be emitted.
127 */
128 virtual QList<QAction*> contextMenuActions(const QString& directory) = 0;
129
130 signals:
131 /**
132 * Should be emitted when the version state of files might have been changed
133 * after the last retrieval (e. g. by executing a context menu action
134 * of the version control plugin). The file manager will be triggered to
135 * update the version states of the directory \p directory by invoking
136 * KVersionControlPlugin::beginRetrieval(),
137 * KVersionControlPlugin::versionState() and
138 * KVersionControlPlugin::endRetrieval().
139 */
140 void versionStatesChanged();
141
142 /**
143 * Is emitted if an information message with the content \a msg
144 * should be shown.
145 */
146 void infoMessage(const QString& msg);
147
148 /**
149 * Is emitted if an error message with the content \a msg
150 * should be shown.
151 */
152 void errorMessage(const QString& msg);
153
154 /**
155 * Is emitted if an "operation completed" message with the content \a msg
156 * should be shown.
157 */
158 void operationCompletedMessage(const QString& msg);
159 };
160
161
162
163
164 // TODO: This is just a temporary test class. It will be made available as
165 // plugin outside Dolphin later.
166
167 #include <kfileitem.h>
168 #include <QHash>
169 #include <QTemporaryFile>
170
171 class LIBDOLPHINPRIVATE_EXPORT SubversionPlugin : public KVersionControlPlugin
172 {
173 Q_OBJECT
174
175 public:
176 SubversionPlugin();
177 virtual ~SubversionPlugin();
178 virtual QString fileName() const;
179 virtual bool beginRetrieval(const QString& directory);
180 virtual void endRetrieval();
181 virtual KVersionControlPlugin::VersionState versionState(const KFileItem& item);
182 virtual QList<QAction*> contextMenuActions(const KFileItemList& items);
183 virtual QList<QAction*> contextMenuActions(const QString& directory);
184
185 private slots:
186 void updateFiles();
187 void showLocalChanges();
188 void commitFiles();
189 void addFiles();
190 void removeFiles();
191
192 void slotOperationCompleted();
193 void slotOperationError();
194
195 private:
196 /**
197 * Executes the command "svn {svnCommand}" for the files that have been
198 * set by getting the context menu actions (see contextMenuActions()).
199 * @param infoMsg Message that should be shown before the command is executed.
200 * @param errorMsg Message that should be shown if the execution of the command
201 * has been failed.
202 * @param operationCompletedMsg
203 * Message that should be shown if the execution of the command
204 * has been completed successfully.
205 */
206 void execSvnCommand(const QString& svnCommand,
207 const QString& infoMsg,
208 const QString& errorMsg,
209 const QString& operationCompletedMsg);
210
211 void startSvnCommandProcess();
212
213 private:
214 QHash<QString, VersionState> m_versionInfoHash;
215 QList<QString> m_versionInfoKeys; // cache for accessing the keys of the hash
216
217 QAction* m_updateAction;
218 QAction* m_showLocalChangesAction;
219 QAction* m_commitAction;
220 QAction* m_addAction;
221 QAction* m_removeAction;
222
223 QString m_command;
224 QString m_errorMsg;
225 QString m_operationCompletedMsg;
226
227 QString m_contextDir;
228 KFileItemList m_contextItems;
229
230 QTemporaryFile m_tempFile;
231 };
232 #endif // REVISIONCONTROLPLUGIN_H
233