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