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