]> git.lyx.org Git - lyx.git/blob - src/support/FileMonitor.h
* support/os_unix.C (canAutoOpen, autoOpenFile): on Mac OS X, use
[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 #include <boost/utility.hpp>
19 #include <boost/scoped_ptr.hpp>
20 #include <boost/signal.hpp>
21
22 namespace lyx {
23 namespace support {
24
25 class FileName;
26
27 class FileMonitor : boost::noncopyable {
28 public:
29         /** Once monitoring begins, the file will be monitored every
30          *  interval ms.
31          */
32         FileMonitor(FileName const & file_with_path, int interval);
33
34         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
35         ~FileMonitor();
36
37         ///
38         void reset(FileName const & file_with_path) const;
39
40         ///
41         FileName const & filename() const;
42
43         /// Begin monitoring the file
44         void start() const;
45         ///
46         void stop() const;
47         ///
48         bool monitoring() const;
49
50         /** The checksum is recomputed whenever the file is modified.
51          *  If the file is not being monitored, then the checksum will be
52          *  recomputed each time this function is called.
53          */
54         unsigned long checksum() const;
55
56         /// Connect and you'll be informed when the file has changed.
57         typedef boost::signal<void()> FileChangedSig;
58         typedef FileChangedSig::slot_type slot_type;
59         ///
60         boost::signals::connection connect(slot_type const &) const;
61
62 private:
63         /// Use the Pimpl idiom to hide the internals.
64         class Impl;
65
66         /// The pointer never changes although *pimpl_'s contents may.
67         boost::scoped_ptr<Impl> const pimpl_;
68 };
69
70 } // namespace support
71 } // namespace lyx
72
73 #endif // FILEMONITOR_H