diff options
author | Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com> | 2012-02-29 11:37:47 +0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2012-03-04 14:54:40 -0600 |
commit | b7ef5096bf8b1d438bfac03f9e0b63392bb0af67 (patch) | |
tree | 2d1ca0c33998fc12064c0cd440114c3f9a8f164b | |
parent | 8b90f28159c5982bb226fcf3f9692c95ab93683a (diff) | |
download | phonesim-b7ef5096bf8b1d438bfac03f9e0b63392bb0af67.tar.gz |
phonesim: Add timer to set the variable with delay
In order to set the variable with the delay, specify the
delay in milliseconds:
<chat>
<set name="AAA" value="BBB" delay="30000"/>
</chat>
-rw-r--r-- | src/phonesim.cpp | 29 | ||||
-rw-r--r-- | src/phonesim.h | 14 |
2 files changed, 41 insertions, 2 deletions
diff --git a/src/phonesim.cpp b/src/phonesim.cpp index 6931317..276ae47 100644 --- a/src/phonesim.cpp +++ b/src/phonesim.cpp @@ -268,8 +268,12 @@ SimChat::SimChat( SimState *state, SimXmlNode& e ) } else if ( n->tag == "switch" ) { switchTo = n->getAttribute( "name" ); } else if ( n->tag == "set" ) { - variables += n->getAttribute( "name" ); + QString name = n->getAttribute( "name" ); + variables += name; values += n->getAttribute( "value" ); + int delay = n->getAttribute( "delay" ).toInt(); + if (delay) + delays[name] = delay; } else if ( n->tag == "newcall" ) { newCallVar = n->getAttribute( "name" ); } else if ( n->tag == "forgetcall" ) { @@ -331,6 +335,7 @@ bool SimChat::command( const QString& cmd ) for ( int varNum = 0; varNum < variables.size(); ++varNum ) { QString variable = variables[varNum]; QString value = values[varNum]; + int delay = delays.value(variable, 0); QString val; if ( value == "*" ) @@ -348,7 +353,18 @@ bool SimChat::command( const QString& cmd ) val = value; } - state()->rules()->setVariable( variable, val ); + if (delay) { + QVariantTimer *timer = new QVariantTimer(this->state()->rules()); + + timer->param = QVariant::fromValue(QPairKV(variable, val)); + + timer->setSingleShot( true ); + + connect(timer, SIGNAL(timeout()), this->state()->rules(), + SLOT(delaySetVariable())); + timer->start( delay ); + } else + state()->rules()->setVariable( variable, val ); } // Switch to the new state. @@ -1637,6 +1653,15 @@ void SimRules::delayTimeout() timer->deleteLater(); } +void SimRules::delaySetVariable() +{ + QVariantTimer *timer = (QVariantTimer *)sender(); + QPairKV kv = timer->param.value<QPairKV>(); + + setVariable( kv.first, kv.second ); + + delete timer; +} void SimRules::dialCheck( const QString& number, bool& ok ) { diff --git a/src/phonesim.h b/src/phonesim.h index aa693cd..ce69155 100644 --- a/src/phonesim.h +++ b/src/phonesim.h @@ -162,6 +162,7 @@ private: bool eol; QStringList variables; QStringList values; + QMap<QString, int> delays; QString newCallVar; QString forgetCallId; bool listSMS; @@ -315,6 +316,7 @@ private slots: void tryReadCommand(); void destruct(); void delayTimeout(); + void delaySetVariable(); void dialCheck( const QString& number, bool& ok ); private: @@ -373,4 +375,16 @@ public: int channel; }; +class QVariantTimer : public QTimer +{ + Q_OBJECT +public: + QVariantTimer( QObject *parent = 0 ) : QTimer(parent) { } + QVariant param; +}; + +typedef QPair<QString,QString> QPairKV; + +Q_DECLARE_METATYPE(QPairKV); + #endif |