]> git.lyx.org Git - lyx.git/blob - src/frontends/Timeout.h
Restor 1.4.x behaviour: Don't touch the preamble QTextEdit if the preamble text is...
[lyx.git] / src / frontends / Timeout.h
1 // -*- C++ -*-
2 /**
3  * \file Timeout.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  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef TIMEOUT_H
14 #define TIMEOUT_H
15
16 #include <boost/signal.hpp>
17
18
19 namespace lyx {
20
21
22 /**
23  * This class executes the callback when the timeout expires.
24  */
25 class Timeout {
26 public:
27         /// the timeout type
28         enum Type {
29                 ONETIME, //< one-shot timer
30                 CONTINUOUS //< repeating
31         };
32         /// Note that the c-tor is implemented in the GUI-specific frontends
33         Timeout(unsigned int msec, Type = ONETIME);
34         ///
35         ~Timeout();
36         /// Is the timer running?
37         bool running() const;
38         /// start the timer
39         void start();
40         /// stop the timer
41         void stop();
42         /// restart the timer
43         void restart();
44         /// signal emitted on timer expiry
45         boost::signal<void()> timeout;
46         /// emit the signal
47         void emit();
48         /// set the timer type
49         Timeout & setType(Type t);
50         /// set the timeout value
51         Timeout & setTimeout(unsigned int msec);
52
53         /** Base class for the GUI implementation.
54             It must be public so that C callback functions can access its
55             daughter classes.
56          */
57         class Impl
58         {
59         public:
60                 ///
61                 Impl(Timeout & owner) : owner_(owner) {}
62                 ///
63                 virtual ~Impl() {}
64                 /// Is the timer running?
65                 virtual bool running() const = 0;
66                 /// start the timer
67                 virtual void start() = 0;
68                 /// stop the timer
69                 virtual void stop() = 0;
70                 /// reset
71                 virtual void reset() = 0;
72
73         protected:
74                 ///
75                 void emit() { owner_.emit(); }
76                 ///
77                 unsigned int timeout_ms() const { return owner_.timeout_ms; }
78
79         private:
80                 ///
81                 Timeout & owner_;
82         };
83
84 private:
85         ///
86         friend class Impl;
87         ///
88         boost::scoped_ptr<Impl> const pimpl_;
89         /// one-shot or repeating
90         Type type;
91         /// timeout value in milliseconds
92         unsigned int timeout_ms;
93 };
94
95
96 } // namespace lyx
97
98 #endif