/* Copyright © 2010 yan Verdavaine This file is part of QExtend. QExtend is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. QExtend is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with QExtend. If not, see . */ #include "actionscheduler.hpp" #include "connector.hpp" #include "signalcheckpoint.hpp" #include namespace QExtend { struct propertyParam { ExtendPtr object; const char * property; QString name; }; struct ActionSchedulerPrivate : public QObject { Q_OBJECT public : QStateMachine stateMachine; SignalCheckPoint listener; QList otherparams; ActionScheduler * actionSheduler; ActionSchedulerPrivate (ActionScheduler * actionSheduler) :QObject(actionSheduler),actionSheduler(actionSheduler) { QState * sBegin = new QState(&stateMachine); QState * sRuning = new QState(&stateMachine); QState * sWait = new QState(&stateMachine); sBegin -> addTransition ( &listener , SIGNAL(parameters(const QVariantMap &)) , sRuning ); sRuning -> addTransition ( &listener , SIGNAL(parameters(const QVariantMap &)) , sWait ); sWait -> addTransition ( this , SIGNAL(actionFinished()) , sRuning ); sRuning -> addTransition ( this , SIGNAL(actionFinished()) , sBegin ); EMITTER(sRuning , entered () ) >> RECEIVER ( this , launchAction()); stateMachine.setInitialState(sBegin); stateMachine.start(); } public Q_SLOTS : void emitActionFinished () { Q_EMIT actionFinished(); } void launchAction () { QVariantMap map = listener.getParameters(); Q_FOREACH(const propertyParam & pp,otherparams) { map[pp.name] = pp.object->property(pp.property); } Q_EMIT actionSheduler->launchAction( map ); } Q_SIGNALS: void actionFinished(); }; ActionScheduler::ActionScheduler(QObject * parent) :QObject(parent),m_internal(this) { } void ActionScheduler::addListenEmitter(const Emitter &emitter,const QStringList & list) { m_internal->listener.addEmitter(emitter , list ); } void ActionScheduler::addListenEmitterProperty(const Emitter &emitter,const char * p, const QString & s) { m_internal->listener.addEmitterProperty(emitter , p , s ); } void ActionScheduler::addListenProperty(const QObject * obj,const char * p, const QString & s ) { propertyParam tmp; tmp.object = obj; tmp.name = s; tmp.property = p; m_internal->otherparams << tmp; } void ActionScheduler::actionFinished() { m_internal->emitActionFinished(); } } #include "actionscheduler.moc"