]> cloud.milkyroute.net Git - dolphin.git/blob - src/revisioncontrolplugin.h
also provide revision control actions for the viewport-context-menu
[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. The methods
38 * RevisionControlPlugin::beginRetrieval(),
39 * RevisionControlPlugin::endRetrieval() and
40 * RevisionControlPlugin::revisionState() are invoked
41 * from a separate thread to assure that the GUI thread
42 * won't be blocked. All other methods are invoked in the
43 * scope of the GUI thread.
44 */
45 class LIBDOLPHINPRIVATE_EXPORT RevisionControlPlugin : public QObject
46 {
47 Q_OBJECT
48
49 public:
50 enum RevisionState
51 {
52 LocalRevision,
53 LatestRevision,
54 UpdateRequiredRevision,
55 EditingRevision,
56 ConflictingRevision
57 // TODO...
58 };
59
60 RevisionControlPlugin();
61 virtual ~RevisionControlPlugin();
62
63 /**
64 * Returns the name of the file which stores
65 * the revision control informations.
66 * (e. g. .svn, .cvs, .git).
67 */
68 virtual QString fileName() const = 0;
69
70 /**
71 * Is invoked whenever the revision control
72 * information will get retrieved for the directory
73 * \p directory. It is assured that the directory
74 * contains a trailing slash.
75 */
76 virtual bool beginRetrieval(const QString& directory) = 0;
77
78 /**
79 * Is invoked after the revision control information has been
80 * received. It is assured that
81 * RevisionControlPlugin::beginInfoRetrieval() has been
82 * invoked before.
83 */
84 virtual void endRetrieval() = 0;
85
86 /**
87 * Returns the revision state for the file \p item.
88 * It is assured that RevisionControlPlugin::beginInfoRetrieval() has been
89 * invoked before and that the file is part of the directory specified
90 * in beginInfoRetrieval().
91 */
92 virtual RevisionState revisionState(const KFileItem& item) = 0;
93
94 /**
95 * Returns the list of actions that should be shown in the context menu
96 * for the files \p items. If no files are provided by \p items, the context
97 * menu is valid for the current directory (see RevisionControlPlugin::beginRetrieval()).
98 * If an action triggers a change of the revisions, the signal
99 * RevisionControlPlugin::revisionStatesChanged() must be emitted.
100 */
101 virtual QList<QAction*> contextMenuActions(const KFileItemList& items) const = 0;
102
103 signals:
104 /**
105 * Should be emitted when the revision state of files has been changed
106 * after the last retrieval. The file manager will be triggered to
107 * update the revision states of the directory \p directory by invoking
108 * RevisionControlPlugin::beginRetrieval(),
109 * RevisionControlPlugin::revisionState() and
110 * RevisionControlPlugin::endRetrieval().
111 */
112 void revisionStatesChanged(const QString& directory);
113 };
114
115
116
117
118 // TODO: This is just a temporary test class. It will be made available as
119 // plugin outside Dolphin later.
120
121 #include <QFileInfoList>
122 #include <QHash>
123
124 class LIBDOLPHINPRIVATE_EXPORT SubversionPlugin : public RevisionControlPlugin
125 {
126 public:
127 SubversionPlugin();
128 virtual ~SubversionPlugin();
129 virtual QString fileName() const;
130 virtual bool beginRetrieval(const QString& directory);
131 virtual void endRetrieval();
132 virtual RevisionControlPlugin::RevisionState revisionState(const KFileItem& item);
133 virtual QList<QAction*> contextMenuActions(const KFileItemList& items) const;
134
135 private:
136 /**
137 * Returns true, if the content of the local file \p name is equal to the
138 * content of the revisioned file.
139 */
140 bool equalRevisionContent(const QString& name) const;
141
142 private:
143 struct RevisionInfo
144 {
145 quint64 size;
146 QDateTime timeStamp;
147 };
148
149 QString m_directory;
150 QHash<QString, RevisionInfo> m_revisionInfoHash;
151
152 QAction* m_updateAction;
153 QAction* m_commitAction;
154 QAction* m_addAction;
155 QAction* m_removeAction;
156 };
157 #endif // REVISIONCONTROLPLUGIN_H
158