bool TimerUnit::enableTimer(const QString & name ) { bool found = false; QMap<QString, TTimer *>::const_iterator it = mLookupTable.find( name ); while( it != mLookupTable.end() && it.key() == name ) { TTimer * pT = it.value(); if( ! pT->isOffsetTimer() ) /* ret = */ pT->setIsActive( true ); else pT->setShouldBeActive( true ); if( pT->isFolder() ) { // disable or enable all timers in the respective branch // irrespective of the user defined state. if( pT->shouldBeActive() ) { pT->enableTimer(); } else { pT->disableTimer(); } } else { if( pT->isOffsetTimer() ) { // state of offset timers is managed by the trigger engine if( pT->shouldBeActive() ) { pT->enableTimer(); } else { pT->disableTimer(); } } } ++it; found = true; } return found; }
void TTimer::enableTimer() { if( canBeUnlocked( 0 ) ) { if( activate() ) { if( mScript.size() > 0 ) { mpTimer->start(); } } else { deactivate(); mpTimer->stop(); } } if( ! isOffsetTimer() ) { typedef list<TTimer *>::const_iterator I; for( I it = mpMyChildrenList->begin(); it != mpMyChildrenList->end(); it++) { TTimer * pChild = *it; if( ! pChild->isOffsetTimer() ) pChild->enableTimer(); } } }
void TTimer::disableTimer( qint64 id ) { if( mID == id ) { deactivate(); mpTimer->stop(); } typedef list<TTimer *>::const_iterator I; for( I it = mpMyChildrenList->begin(); it != mpMyChildrenList->end(); it++) { TTimer * pChild = *it; if( ! pChild->isOffsetTimer() && pChild->shouldBeActive() ) { pChild->disableTimer( pChild->getID() ); } } }
bool TimerUnit::disableTimer( QString & name ) { bool found = false; QMap<QString, TTimer *>::const_iterator it = mLookupTable.find( name ); while( it != mLookupTable.end() && it.key() == name ) { TTimer * pT = it.value(); if( pT->isOffsetTimer() ) pT->setShouldBeActive( false ); else pT->setIsActive( false ); pT->disableTimer(); ++it; found = true; } return found; }
void XMLimport::readTimerGroup( TTimer * pParent ) { TTimer * pT; if( pParent ) { pT = new TTimer( pParent, mpHost ); } else { pT = new TTimer( 0, mpHost ); } pT->registerTimer(); pT->setShouldBeActive( ( attributes().value("isActive") == "yes" ) ); pT->mIsFolder = ( attributes().value("isFolder") == "yes" ); pT->mIsTempTimer = ( attributes().value("isTempTimer") == "yes" ); if (module) pT->mModuleMember = true; while( ! atEnd() ) { readNext(); if( isEndElement() ) break; if( isStartElement() ) { if( name() == "name" ) { pT->setName( readElementText() ); continue; } else if( name() == "packageName") { pT->mPackageName = readElementText(); continue; } else if( name() == "script") { QString script = readElementText(); pT->setScript( script ); continue; } else if( name() == "command") { pT->mCommand = readElementText(); continue; } else if( name() == "time") { QString timeString = readElementText(); QTime time = QTime::fromString( timeString, "hh:mm:ss.zzz" ); pT->setTime( time ); continue; } else if( name() == "TimerGroup" ) { readTimerGroup( pT ); } else if( name() == "Timer" ) { readTimerGroup( pT ); } else { readUnknownTimerElement(); } } } if( ( ! pT->isOffsetTimer() ) && ( pT->shouldBeActive() ) ) pT->enableTimer( pT->getID() ); else pT->disableTimer( pT->getID() ); }
void TTreeWidget::rowsInserted( const QModelIndex & parent, int start, int end ) { // determine position in parent list if( mIsDropAction ) { QModelIndex child = parent.child( start, 0 ); int parentPosition = parent.row(); int childPosition = child.row(); if( mChildID == 0 ) { if( ! parent.model() ) goto END; if( ! mpHost ) goto END; mChildID = parent.model()->index( start, 0 ).data( Qt::UserRole ).toInt(); } int newParentID = parent.data( Qt::UserRole ).toInt(); if( mIsTriggerTree ) mpHost->getTriggerUnit()->reParentTrigger( mChildID, mOldParentID, newParentID, parentPosition, childPosition ); if( mIsAliasTree ) mpHost->getAliasUnit()->reParentAlias( mChildID, mOldParentID, newParentID, parentPosition, childPosition ); if( mIsKeyTree ) mpHost->getKeyUnit()->reParentKey( mChildID, mOldParentID, newParentID, parentPosition, childPosition ); if( mIsTimerTree ) { mpHost->getTimerUnit()->reParentTimer( mChildID, mOldParentID, newParentID, parentPosition, childPosition ); TTimer * pTChild = mpHost->getTimerUnit()->getTimer( mChildID ); //TTimer * pTnewParent = mpHost->getTimerUnit()->getTimer( newParentID ); if( pTChild ) { QIcon icon; if( pTChild->isOffsetTimer() ) { if( pTChild->shouldBeActive() ) { icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/offsettimer-on.png")), QIcon::Normal, QIcon::Off); } else { icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/offsettimer-off.png")), QIcon::Normal, QIcon::Off); } } else { if( pTChild->shouldBeActive() ) { icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/tag_checkbox_checked.png")), QIcon::Normal, QIcon::Off); } else { icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/tag_checkbox.png")), QIcon::Normal, QIcon::Off); } } QTreeWidgetItem * pParent = itemFromIndex( parent ); if( ! pParent ) goto END; for( int i=0; i<pParent->childCount(); i++ ) { QTreeWidgetItem * pItem = pParent->child(i); if( ! pItem ) goto END; int id = pItem->data(0, Qt::UserRole).toInt(); if( id == mChildID ) { pItem->setIcon(0, icon); } } } } if( mIsScriptTree ) mpHost->getScriptUnit()->reParentScript( mChildID, mOldParentID, newParentID, parentPosition, childPosition ); if( mIsActionTree ) { mpHost->getActionUnit()->reParentAction( mChildID, mOldParentID, newParentID, parentPosition, childPosition ); mpHost->getActionUnit()->updateToolbar(); } mChildID = 0; mOldParentID = 0; mIsDropAction = false; } END: QTreeWidget::rowsInserted( parent, start, end ); }
void TTimer::execute() { if( ! isActive() || mIsFolder ) { mpTimer->stop(); return; } if( mudlet::debugMode ) {TDebug(QColor(Qt::darkYellow),QColor(Qt::darkBlue)) << "\n[TIMER EXECUTES]: "<<mName<<" fired. Executing command="<<mCommand<<" and executing script:"<<mScript<<"\n" >> 0;} if( mIsTempTimer ) { if( mScript == "" ) { mpHost->mLuaInterpreter.call_luafunction( this ); } else { mpHost->mLuaInterpreter.compileAndExecuteScript( mScript ); } mpTimer->stop(); mpHost->mTimerUnit.markCleanup( this ); return; } if( ( ! isFolder() && hasChildren() ) || ( isOffsetTimer() ) ) { typedef list<TTimer *>::const_iterator I; for( I it = mpMyChildrenList->begin(); it != mpMyChildrenList->end(); it++) { TTimer * pChild = *it; if( pChild->isOffsetTimer() ) { pChild->enableTimer( pChild->getID() ); } } if( isOffsetTimer() ) { disableTimer( mID ); deactivate(); } } if( mCommand.size() > 0 ) { mpHost->send( mCommand ); } if( mScript.size() > 0 ) { if( mNeedsToBeCompiled ) { if( ! compileScript() ) { disableTimer(); return; } } if( ! mpHost->mLuaInterpreter.call( mFuncName, mName ) ) { mpTimer->stop(); } } }