]> git.lyx.org Git - lyx.git/blob - src/VCBackend.h
Routines for calculating numerical labels for BibTeX citations.
[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         /// synchronize with repository, returns log
47         virtual std::string repoUpdate() = 0;
48         // can be this operation processed in the current RCS?
49         virtual bool repoUpdateEnabled() = 0;
50         // toggle locking property of the file
51         virtual std::string lockingToggle() = 0;
52         // can be this operation processed in the current RCS?
53         virtual bool lockingToggleEnabled() = 0;
54         /// revert current edits
55         virtual void revert() = 0;
56         /// FIXME
57         virtual void undoLast() = 0;
58         // can be this operation processed in the current RCS?
59         virtual bool undoLastEnabled() = 0;
60         /**
61          * getLog - read the revision log into the given file
62          * @param fname file name to read into
63          */
64         virtual void getLog(support::FileName const &) = 0;
65         /// return the current version description
66         virtual std::string const versionString() const = 0;
67         /// return the current version
68         std::string const & version() const { return version_; }
69         /// return the user who has locked the file
70         std::string const & locker() const { return locker_; }
71         /// set the owning buffer
72         void owner(Buffer * b) { owner_ = b; }
73         /// return the owning buffer
74         Buffer * owner() const { return owner_; }
75         /// return the lock status of this file
76         VCStatus status() const { return vcstatus; }
77         /// do we need special handling for read-only toggling?
78         /// (also used for check-out operation)
79         virtual bool toggleReadOnlyEnabled() = 0;
80 protected:
81         /// parse information from the version file
82         virtual void scanMaster() = 0;
83
84         // GUI container for doVCCommandCall
85         int doVCCommand(std::string const & cmd, support::FileName const & path);
86         /**
87          * doVCCommandCall - call out to the version control utility
88          * @param cmd the command to execute
89          * @param path the path from which to execute
90          * @return exit status
91          */
92         static int doVCCommandCall(std::string const & cmd, support::FileName const & path);
93
94         /**
95          * The master VC file. For RCS this is *,v or RCS/ *,v. master should
96          * have full path.
97          */
98         support::FileName master_;
99
100         /// The status of the VC controlled file.
101         VCStatus vcstatus;
102
103         /**
104          * The version of the VC file. I am not sure if this can be a
105          * string or if it must be a float/int.
106          */
107         std::string version_;
108
109         /// The user currently keeping the lock on the VC file.
110         std::string locker_;
111         /// The buffer using this VC
112         Buffer * owner_;
113 };
114
115
116 ///
117 class RCS : public VCS {
118 public:
119
120         explicit
121         RCS(support::FileName const & m);
122
123         /// return the revision file for the given file, if found
124         static support::FileName const findFile(support::FileName const & file);
125
126         static void retrieve(support::FileName const & file);
127
128         virtual void registrer(std::string const & msg);
129
130         virtual std::string checkIn(std::string const & msg);
131
132         virtual bool checkInEnabled();
133
134         virtual std::string checkOut();
135
136         virtual bool checkOutEnabled();
137
138         virtual std::string repoUpdate();
139
140         virtual bool repoUpdateEnabled();
141
142         virtual std::string lockingToggle();
143
144         virtual bool lockingToggleEnabled();
145
146         virtual void revert();
147
148         virtual void undoLast();
149
150         virtual bool undoLastEnabled();
151
152         virtual void getLog(support::FileName const &);
153
154         virtual std::string const versionString() const {
155                 return "RCS: " + version_;
156         }
157
158         virtual bool toggleReadOnlyEnabled();
159
160 protected:
161         virtual void scanMaster();
162 };
163
164
165 ///
166 class CVS : public VCS {
167 public:
168         ///
169         explicit
170         CVS(support::FileName const & m, support::FileName const & f);
171
172         /// return the revision file for the given file, if found
173         static support::FileName const findFile(support::FileName const & file);
174
175         virtual void registrer(std::string const & msg);
176
177         virtual std::string checkIn(std::string const & msg);
178
179         virtual bool checkInEnabled();
180
181         virtual std::string checkOut();
182
183         virtual bool checkOutEnabled();
184
185         virtual std::string repoUpdate();
186
187         virtual bool repoUpdateEnabled();
188
189         virtual std::string lockingToggle();
190
191         virtual bool lockingToggleEnabled();
192
193         virtual void revert();
194
195         virtual void undoLast();
196
197         virtual bool undoLastEnabled();
198
199         virtual void getLog(support::FileName const &);
200
201         virtual std::string const versionString() const {
202                 return "CVS: " + version_;
203         }
204
205         virtual bool toggleReadOnlyEnabled();
206
207 protected:
208         virtual void scanMaster();
209
210 private:
211         support::FileName file_;
212 };
213
214
215 ///
216 class SVN : public VCS {
217 public:
218         ///
219         explicit
220         SVN(support::FileName const & m, support::FileName const & f);
221
222         /// return the revision file for the given file, if found
223         static support::FileName const findFile(support::FileName const & file);
224
225         virtual void registrer(std::string const & msg);
226
227         virtual std::string checkIn(std::string const & msg);
228
229         virtual bool checkInEnabled();
230
231         virtual std::string checkOut();
232
233         virtual bool checkOutEnabled();
234
235         virtual std::string repoUpdate();
236
237         virtual bool repoUpdateEnabled();
238
239         virtual std::string lockingToggle();
240
241         virtual bool lockingToggleEnabled();
242
243         virtual void revert();
244
245         virtual void undoLast();
246
247         virtual bool undoLastEnabled();
248
249         virtual void getLog(support::FileName const &);
250
251         virtual std::string const versionString() const {
252                 return "SVN: " + version_;
253         }
254
255         virtual bool toggleReadOnlyEnabled();
256
257 protected:
258         virtual void scanMaster();
259         /// Check for messages in svn output. Returns error.
260         std::string scanLogFile(support::FileName const & f, std::string & status);
261         /// checks locking policy and setup locked_mode_
262         bool checkLockMode();
263         /// is the loaded file locked?
264         bool isLocked() const;
265         /// acquire/release write lock for the current file
266         void fileLock(bool lock, support::FileName const & tmpf, std::string & status);
267
268 private:
269         support::FileName file_;
270         /// is the loaded file under locking policy?
271         bool locked_mode_;
272 };
273
274 } // namespace lyx
275
276 #endif // VCBACKEND_H