#ifndef QTIMER_FACTORY_H
#define QTIMER_FACTORY_H

#include <QTimer>
#include <QDebug>

class Timer : public QObject
{
    Q_OBJECT
public:
    Timer(int interval, QObject *parent = 0) : QObject(parent) {
	timer = new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(callbackDispatch()));
	timer->setInterval(interval);
	timer->start();
    }
    ~Timer() {}
    void stop() { timer->stop(); }
signals:
    void timeout(Timer *t);
public slots:
    void callbackDispatch() {
        emit timeout(this);
    }
private:
    QTimer *timer;
};

class TimerFactory : public QObject
{
    Q_OBJECT
public slots:
    Timer *new_Timer(int interval, QObject *parent=0) { return new Timer(interval,parent); }
    void delete_Timer(Timer *t) { t->stop(); delete t; }
    void stop(Timer *o) { o->stop(); }
};

// Add PythonQt bindings
class QTimerFactory : public QObject
{
    Q_OBJECT

public slots:
    // Constructor and Destructor
    QTimer *new_QTimer() { return new QTimer(0); }
    QTimer *new_QTimer(QWidget *parent) { qWarning("create a new timer");return new QTimer((QObject*)parent); }
    void delete_QTimer(QTimer *o) { delete o; }

    // add access methods
    void setInterval(QTimer *o, int t) { o->setInterval(t); }
    void setSingleShot(QTimer *o, bool r) { o->setSingleShot(r); }
    void startTimer(QTimer *o) { o->start(); }
    int gettid(QTimer *o) { return tid; }
    void settid(QTimer *o, int t) { tid = t; }
    bool isActive(QTimer *o) {return o->isActive();}
private:
	int tid;
};


#endif // QTIMER_FACTORY_H
