]> git.lyx.org Git - lyx.git/blob - src/support/FileMonitor.h
Implement FileMonitor as a wrapper for QFileSystemWatcher
[lyx.git] / src / support / FileMonitor.h
1 // -*- C++ -*-
2 /**
3  * \file FileMonitor.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * FileMonitor monitors a file and informs a listener when that file has
12  * changed.
13  */
14
15 #ifndef FILEMONITOR_H
16 #define FILEMONITOR_H
17
18 // TODO: Remove FileMonitor
19 #include "support/FileMonitor2.h"
20
21 #include <boost/signals2.hpp>
22
23 namespace lyx {
24 namespace support {
25
26 class FileName;
27
28 class FileMonitor
29 {
30 public:
31         /** Once monitoring begins, the file will be monitored every
32          *  interval ms.
33          *
34          * This is now obsoleted by FileMonitor2 based on QFileSystemWatcher.
35          * FIXME: Remove FileMonitor
36          */
37         FileMonitor(FileName const & file_with_path, int interval);
38
39         /// Destructor
40         ~FileMonitor();
41
42         ///
43         void reset(FileName const & file_with_path) const;
44
45         ///
46         FileName const & filename() const;
47
48         /// Begin monitoring the file
49         void start() const;
50         ///
51         void stop() const;
52         ///
53         bool monitoring() const;
54
55         /** The checksum is recomputed whenever the file is modified.
56          *  If the file is not being monitored, then the checksum will be
57          *  recomputed each time this function is called.
58          */
59         unsigned long checksum() const;
60
61         /// Connect and you'll be informed when the file has changed.
62         typedef boost::signals2::signal<void()> FileChangedSig;
63         typedef FileChangedSig::slot_type slot_type;
64         ///
65         boost::signals2::connection connect(slot_type const &) const;
66
67 private:
68         /// noncopyable
69         FileMonitor(FileMonitor const &);
70         void operator=(FileMonitor const &);
71
72         /// Use the Pimpl idiom to hide the internals.
73         class Impl;
74         /// The pointer never changes although *pimpl_'s contents may.
75         Impl * const pimpl_;
76 };
77
78 } // namespace support
79 } // namespace lyx
80
81 #endif // FILEMONITOR_H