I dug this out of my store of things half-implemented. As you can see from
the SigC references, it's very old ;-)
The idea was to prevent the code in src/frontends from looking in the
different GUI dirs. Would anybody be upset if I brought this up to date and
applied it?
--
Angus
/**
* \file Timeout.C
* Copyright 2001 LyX Team
* Read COPYING
*
* \author Lars Gullik Bjønnes
* \author John Levon
* \author Angus Leeming
*/
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "Timeout.h"
#include "support/LAssert.h"
// Note that the c-tor is implemented in the GUI-specific frontends
Timeout::~Timeout()
{
gui_->stop();
delete gui_;
}
bool Timeout::running() const
{
return gui_->running();
}
void Timeout::start()
{
gui_->start();
}
void Timeout::stop()
{
gui_->stop();
}
void Timeout::restart()
{
gui_->stop();
gui_->start();
}
void Timeout::emit()
{
gui_->reset();
timeout.emit();
if (type == CONTINUOUS)
gui_->start();
}
Timeout & Timeout::setType(Type t)
{
type = t;
return * this;
}
Timeout & Timeout::setTimeout(unsigned int msec)
{
// Can't have a timeout of zero!
lyx::Assert(msec);
timeout_ms = msec;
return * this;
}
// -*- C++ -*-
/**
* \file Timeout.h
* Copyright 2001 LyX Team
* Read COPYING
*
* \author Lars Gullik Bjønnes
* \author John Levon
* \author Angus Leeming
*/
#ifndef TIMEOUT_H
#define TIMEOUT_H
#ifdef __GNUG__
#pragma interface
#endif
#include <sigc++/signal_system.h>
/**
* This class executes the callback when the timeout expires.
*/
class Timeout {
public:
///
enum Type {
/// one-shot timer
ONETIME,
/// repeating
CONTINUOUS
};
/// Note that the c-tor is implemented in the GUI-specific frontends
Timeout(unsigned int msec, Type = ONETIME);
///
~Timeout();
/// Is the timer running?
bool running() const;
/// start the timer
void start();
/// stop the timer
void stop();
/// restart the timer
void restart();
/// signal emitted on timer expiry
SigC::Signal0<void> timeout;
/// emit the signal
void emit();
/// set the timer type
Timeout & setType(Type t);
/// set the timeout value
Timeout & setTimeout(unsigned int msec);
/// Base class for the GUI implementation
class GUI
{
public:
///
GUI(Timeout & owner) : owner_(owner) {}
///
virtual ~GUI() {}
/// Is the timer running?
virtual bool running() const = 0;
/// start the timer
virtual void start() = 0;
/// stop the timer
virtual void stop() = 0;
/// reset
virtual void reset() = 0;
protected:
///
void emit() { owner_.emit(); }
///
unsigned int timeout_ms() const { return owner_.timeout_ms; }
private:
///
Timeout & owner_;
};
private:
///
friend class GUI;
/// implementation
GUI * gui_;
/// one-shot or repeating
Type type;
/// timeout value in milliseconds
unsigned int timeout_ms;
};
#endif