1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef REVISIONCONTROLPLUGIN_H
21 #define REVISIONCONTROLPLUGIN_H
23 #include <libdolphin_export.h>
34 * @brief Base class for version control plugins.
36 * Enables the file manager to show the version state
37 * of a versioned file.
39 class LIBDOLPHINPRIVATE_EXPORT KVersionControlPlugin
: public QObject
46 /** The file is not under version control. */
49 * The file is under version control and represents
54 * The file is under version control and a newer
55 * version exists on the main branch.
57 UpdateRequiredVersion
,
59 * The file is under version control and has been
62 LocallyModifiedVersion
,
64 * The file has not been under version control but
65 * has been marked to get added with the next commit.
69 * The file is under version control but has been marked
70 * for getting removed with the next commit.
74 * The file is under version control and has been locally
75 * modified. A modification has also been done on the main
81 KVersionControlPlugin();
82 virtual ~KVersionControlPlugin();
85 * Returns the name of the file which stores
86 * the version control informations.
87 * (e. g. .svn, .cvs, .git).
89 virtual QString
fileName() const = 0;
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.
97 virtual bool beginRetrieval(const QString
& directory
) = 0;
100 * Is invoked after the version control information has been
101 * received. It is assured that
102 * KVersionControlPlugin::beginInfoRetrieval() has been
105 virtual void endRetrieval() = 0;
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().
113 virtual VersionState
versionState(const KFileItem
& item
) = 0;
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.
121 virtual QList
<QAction
*> contextMenuActions(const KFileItemList
& items
) = 0;
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.
128 virtual QList
<QAction
*> contextMenuActions(const QString
& directory
) = 0;
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().
140 void versionStatesChanged();
143 * Is emitted if an information message with the content \a msg
146 void infoMessage(const QString
& msg
);
149 * Is emitted if an error message with the content \a msg
152 void errorMessage(const QString
& msg
);
155 * Is emitted if an "operation completed" message with the content \a msg
158 void operationCompletedMessage(const QString
& msg
);
164 // TODO: This is just a temporary test class. It will be made available as
165 // plugin outside Dolphin later.
167 #include <kfileitem.h>
169 #include <QTemporaryFile>
171 class LIBDOLPHINPRIVATE_EXPORT SubversionPlugin
: public KVersionControlPlugin
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
);
187 void showLocalChanges();
192 void slotOperationCompleted();
193 void slotOperationError();
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
202 * @param operationCompletedMsg
203 * Message that should be shown if the execution of the command
204 * has been completed successfully.
206 void execSvnCommand(const QString
& svnCommand
,
207 const QString
& infoMsg
,
208 const QString
& errorMsg
,
209 const QString
& operationCompletedMsg
);
211 void startSvnCommandProcess();
214 QHash
<QString
, VersionState
> m_versionInfoHash
;
215 QList
<QString
> m_versionInfoKeys
; // cache for accessing the keys of the hash
217 QAction
* m_updateAction
;
218 QAction
* m_showLocalChangesAction
;
219 QAction
* m_commitAction
;
220 QAction
* m_addAction
;
221 QAction
* m_removeAction
;
225 QString m_operationCompletedMsg
;
227 QString m_contextDir
;
228 KFileItemList m_contextItems
;
230 QTemporaryFile m_tempFile
;
232 #endif // REVISIONCONTROLPLUGIN_H