]> git.lyx.org Git - lyx.git/blob - src/VCBackend.h
Kornel's gcc compile fix.
[lyx.git] / src / VCBackend.h
1 // -*- C++ -*-
2 /**
3  * \file VCBackend.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef VC_BACKEND_H
13 #define VC_BACKEND_H
14
15 #include "support/FileName.h"
16
17 #include <string>
18
19
20 namespace lyx {
21
22 class Buffer;
23
24 /// A simple version control system interface
25 class VCS {
26 public:
27         /// the status of the managed file
28         enum VCStatus {
29                 UNLOCKED,
30                 LOCKED,
31                 NOLOCKING
32         };
33
34         virtual ~VCS() {}
35
36         /// register a file for version control
37         virtual void registrer(std::string const & msg) = 0;
38         /// check in the current revision, returns log
39         virtual std::string checkIn(std::string const & msg) = 0;
40         // can be this operation processed in the current RCS?
41         virtual bool checkInEnabled() = 0;
42         /// check out for editing, returns log
43         virtual std::string checkOut() = 0;
44         // can be this operation processed in the current RCS?
45         virtual bool checkOutEnabled() = 0;
46         // toggle locking property of the file
47         virtual std::string lockingToggle() = 0;
48         // can be this operation processed in the current RCS?
49         virtual bool lockingToggleEnabled() = 0;
50         /// revert current edits
51         virtual void revert() = 0;
52         /// FIXME
53         virtual void undoLast() = 0;
54         // can be this operation processed in the current RCS?
55         virtual bool undoLastEnabled() = 0;
56         /**
57          * getLog - read the revision log into the given file
58          * @param fname file name to read into
59          */
60         virtual void getLog(support::FileName const &) = 0;
61         /// return the current version description
62         virtual std::string const versionString() const = 0;
63         /// return the current version
64         std::string const & version() const { return version_; }
65         /// return the user who has locked the file
66         std::string const & locker() const { return locker_; }
67         /// set the owning buffer
68         void owner(Buffer * b) { owner_ = b; }
69         /// return the owning buffer
70         Buffer * owner() const { return owner_; }
71         /// return the lock status of this file
72         VCStatus status() const { return vcstatus; }
73         /// do we need special handling for read-only toggling?
74         /// (also used for check-out operation)
75         virtual bool toggleReadOnlyEnabled() = 0;
76 protected:
77         /// parse information from the version file
78         virtual void scanMaster() = 0;
79
80         // GUI container for doVCCommandCall
81         int doVCCommand(std::string const & cmd, support::FileName const & path);
82         /**
83          * doVCCommandCall - call out to the version control utility
84          * @param cmd the command to execute
85          * @param path the path from which to execute
86          * @return exit status
87          */
88         static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
89
90         /**
91          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
92          * have full path.
93          */
94         support::FileName master_;
95
96         /// The status of the VC controlled file.
97         VCStatus vcstatus;
98
99         /**
100          * The version of the VC file. I am not sure if this can be a
101          * string or if it must be a float/int.
102          */
103         std::string version_;
104
105         /// The user currently keeping the lock on the VC file.
106         std::string locker_;
107         /// The buffer using this VC
108         Buffer * owner_;
109 };
110
111
112 ///
113 class RCS : public VCS {
114 public:
115
116         explicit
117         RCS(support::FileName const & m);
118
119         /// return the revision file for the given file, if found
120         static support::FileName const findFile(support::FileName const & file);
121
122         static void retrieve(support::FileName const & file);
123
124         virtual void registrer(std::string const & msg);
125
126         virtual std::string checkIn(std::string const & msg);
127
128         virtual bool checkInEnabled();
129
130         virtual std::string checkOut();
131
132         virtual bool checkOutEnabled();
133
134         virtual std::string lockingToggle();
135
136         virtual bool lockingToggleEnabled();
137
138         virtual void revert();
139
140         virtual void undoLast();
141
142         virtual bool undoLastEnabled();
143
144         virtual void getLog(support::FileName const &);
145
146         virtual std::string const versionString() const {
147                 return "RCS: " + version_;
148         }
149
150         virtual bool toggleReadOnlyEnabled();
151
152 protected:
153         virtual void scanMaster();
154 };
155
156
157 ///
158 class CVS : public VCS {
159 public:
160         ///
161         explicit
162         CVS(support::FileName const & m, support::FileName const & f);
163
164         /// return the revision file for the given file, if found
165         static support::FileName const findFile(support::FileName const & file);
166
167         virtual void registrer(std::string const & msg);
168
169         virtual std::string checkIn(std::string const & msg);
170
171         virtual bool checkInEnabled();
172
173         virtual std::string checkOut();
174
175         virtual bool checkOutEnabled();
176
177         virtual std::string lockingToggle();
178
179         virtual bool lockingToggleEnabled();
180
181         virtual void revert();
182
183         virtual void undoLast();
184
185         virtual bool undoLastEnabled();
186
187         virtual void getLog(support::FileName const &);
188
189         virtual std::string const versionString() const {
190                 return "CVS: " + version_;
191         }
192
193         virtual bool toggleReadOnlyEnabled();
194
195 protected:
196         virtual void scanMaster();
197
198 private:
199         support::FileName file_;
200 };
201
202
203 ///
204 class SVN : public VCS {
205 public:
206         ///
207         explicit
208         SVN(support::FileName const & m, support::FileName const & f);
209
210         /// return the revision file for the given file, if found
211         static support::FileName const findFile(support::FileName const & file);
212
213         virtual void registrer(std::string const & msg);
214
215         virtual std::string checkIn(std::string const & msg);
216
217         virtual bool checkInEnabled();
218
219         virtual std::string checkOut();
220
221         virtual bool checkOutEnabled();
222
223         virtual std::string lockingToggle();
224
225         virtual bool lockingToggleEnabled();
226
227         virtual void revert();
228
229         virtual void undoLast();
230
231         virtual bool undoLastEnabled();
232
233         virtual void getLog(support::FileName const &);
234
235         virtual std::string const versionString() const {
236                 return "SVN: " + version_;
237         }
238
239         virtual bool toggleReadOnlyEnabled();
240
241 protected:
242         virtual void scanMaster();
243         /// Check for messages in svn output. Returns error.
244         std::string scanLogFile(support::FileName const & f, std::string & status);
245         /// checks locking policy and setup locked_mode_
246         bool checkLockMode();
247         /// is the loaded file locked?
248         bool isLocked() const;
249         /// acquire/release write lock for the current file
250         void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
251
252 private:
253         support::FileName file_;
254         /// is the loaded file under locking policy?
255         bool locked_mode_;
256 };
257
258 } // namespace lyx
259
260 #endif // VCBACKEND_H