]> cloud.milkyroute.net Git - dolphin.git/blob - src/revisioncontrolplugin.h
Use the output of 'svn status' instead of doing a custom and error-prone .svn-parsing...
[dolphin.git] / src / revisioncontrolplugin.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 revision control plugins.
35 *
36 * Enables the file manager to show the revision state
37 * of a revisioned file.
38 */
39 class LIBDOLPHINPRIVATE_EXPORT RevisionControlPlugin : public QObject
40 {
41 Q_OBJECT
42
43 public:
44 enum RevisionState
45 {
46 /** The file is not under revision control. */
47 UnversionedRevision,
48 /**
49 * The file is under revision control and represents
50 * the latest version.
51 */
52 NormalRevision,
53 /**
54 * The file is under revision control and a newer
55 * version exists on the main branch.
56 */
57 UpdateRequiredRevision,
58 /**
59 * The file is under revision control and has been
60 * modified locally.
61 */
62 LocallyModifiedRevision,
63 /**
64 * The file has not been under revision control but
65 * has been marked to get added with the next commit.
66 */
67 AddedRevision,
68 /**
69 * The file is under revision control but has been marked
70 * for getting removed with the next commit.
71 */
72 RemovedRevision,
73 /**
74 * The file is under revision control and has been locally
75 * modified. A modification has also been done on the main
76 * branch.
77 */
78 ConflictingRevision
79 };
80
81 RevisionControlPlugin();
82 virtual ~RevisionControlPlugin();
83
84 /**
85 * Returns the name of the file which stores
86 * the revision control informations.
87 * (e. g. .svn, .cvs, .git).
88 */
89 virtual QString fileName() const = 0;
90
91 /**
92 * Is invoked whenever the revision 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 revision control information has been
101 * received. It is assured that
102 * RevisionControlPlugin::beginInfoRetrieval() has been
103 * invoked before.
104 */
105 virtual void endRetrieval() = 0;
106
107 /**
108 * Returns the revision state for the file \p item.
109 * It is assured that RevisionControlPlugin::beginInfoRetrieval() has been
110 * invoked before and that the file is part of the directory specified
111 * in beginInfoRetrieval().
112 */
113 virtual RevisionState revisionState(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 revisions, the signal
119 * RevisionControlPlugin::revisionStatesChanged() 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 revisions,
126 * the signal RevisionControlPlugin::revisionStatesChanged() must be emitted.
127 */
128 virtual QList<QAction*> contextMenuActions(const QString& directory) = 0;
129
130 signals:
131 /**
132 * Should be emitted when the revision state of files has been changed
133 * after the last retrieval. The file manager will be triggered to
134 * update the revision states of the directory \p directory by invoking
135 * RevisionControlPlugin::beginRetrieval(),
136 * RevisionControlPlugin::revisionState() and
137 * RevisionControlPlugin::endRetrieval().
138 */
139 void revisionStatesChanged(const QString& directory);
140 };
141
142
143
144
145 // TODO: This is just a temporary test class. It will be made available as
146 // plugin outside Dolphin later.
147
148 #include <kfileitem.h>
149 #include <QHash>
150
151 class LIBDOLPHINPRIVATE_EXPORT SubversionPlugin : public RevisionControlPlugin
152 {
153 Q_OBJECT
154
155 public:
156 SubversionPlugin();
157 virtual ~SubversionPlugin();
158 virtual QString fileName() const;
159 virtual bool beginRetrieval(const QString& directory);
160 virtual void endRetrieval();
161 virtual RevisionControlPlugin::RevisionState revisionState(const KFileItem& item);
162 virtual QList<QAction*> contextMenuActions(const KFileItemList& items);
163 virtual QList<QAction*> contextMenuActions(const QString& directory);
164
165 private slots:
166 void updateFiles();
167 void showLocalChanges();
168 void commitFiles();
169 void addFiles();
170 void removeFiles();
171
172 private:
173 /**
174 * Executes the command "svn {svnCommand}" for the files that have been
175 * set by getting the context menu actions (see contextMenuActions()).
176 */
177 void execSvnCommand(const QString& svnCommand);
178
179 private:
180 QHash<QString, RevisionState> m_revisionInfoHash;
181 QList<QString> m_revisionInfoKeys; // cache for accessing the keys of the hash
182
183 QAction* m_updateAction;
184 QAction* m_showLocalChangesAction;
185 QAction* m_commitAction;
186 QAction* m_addAction;
187 QAction* m_removeAction;
188 mutable QString m_contextDir;
189 mutable KFileItemList m_contextItems;
190 };
191 #endif // REVISIONCONTROLPLUGIN_H
192