1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Fixed conditions

Added support for negative values
Added support to "play once per update"
Added "never" rule for value sound
Several other bugfixes
This commit is contained in:
zedamota 2011-12-03 02:36:47 +00:00
parent f5c7dba0b1
commit 78e25b1b8c
5 changed files with 106 additions and 49 deletions

View File

@ -49,6 +49,7 @@ class NotificationItem : public QObject
public:
enum { eDefaultTimeout = 15 }; // in sec
enum {equal,bigger,smaller,inrange};
explicit NotificationItem(QObject *parent = 0);
void copyTo(NotificationItem*) const;
@ -57,8 +58,11 @@ public:
DECLARE_SOUND(2)
DECLARE_SOUND(3)
QString range() const { return _rangeLimit; }
void setRange(QString text) { _rangeLimit = text; }
bool getCurrentUpdatePlayed() const {return _currentUpdatePlayed;}
void setCurrentUpdatePlayed(bool value){_currentUpdatePlayed=value;}
int getCondition() const { return _condition; }
void setCondition(int value) { _condition = value; }
QString getSayOrder() const { return _sayOrder; }
void setSayOrder(QString text) { _sayOrder = text; }
@ -100,8 +104,8 @@ public:
UAVDataObject* getUAVObject(void);
UAVObjectField* getUAVObjectField(void);
void seriaize(QDataStream& stream);
void deseriaize(QDataStream& stream);
void serialize(QDataStream& stream);
void deserialize(QDataStream& stream);
/**
* Convert notification item fields in single string,
@ -152,6 +156,8 @@ private:
private:
bool _currentUpdatePlayed;
QTimer* _timer;
//! time from putting notification in queue till moment when notification became out-of-date
@ -175,7 +181,7 @@ private:
QString _objectField;
//! fire condition for UAV field value (lower, greater, in range)
QString _rangeLimit;
int _condition;
//! possible sounds(at least one required to play notification)
QString _sound1;

View File

@ -45,7 +45,9 @@ static const QString cStrBefore1st("Before first");
static const QString cStrBefore2nd("Before second");
static const QString cStrAfter2nd("After second");
static const QString cStrRetryOncePUpdate("Repeat Once per update");
static const QString cStrRetryOnce("Repeat Once");
static const QString cStrRetryInstantly("Repeat Instantly");
static const QString cStrRetry10sec("Repeat 10 seconds");
static const QString cStrRetry30sec("Repeat 30 seconds");
@ -58,6 +60,7 @@ QStringList NotificationItem::retryValues;
NotificationItem::NotificationItem(QObject *parent)
: QObject(parent)
, _currentUpdatePlayed(false)
, isNowPlaying(0)
, _isPlayed(false)
, _timer(NULL)
@ -66,7 +69,7 @@ NotificationItem::NotificationItem(QObject *parent)
, _currentLanguage("default")
, _dataObject("")
, _objectField("")
, _rangeLimit("Equal to")
, _condition(0)
, _sound1("")
, _sound2("")
, _sound3("")
@ -78,12 +81,14 @@ NotificationItem::NotificationItem(QObject *parent)
, _mute(false)
{
NotificationItem::sayOrderValues.clear();
NotificationItem::sayOrderValues.append(cStrNever);
NotificationItem::sayOrderValues.append(cStrBefore1st);
NotificationItem::sayOrderValues.append(cStrBefore2nd);
NotificationItem::sayOrderValues.append(cStrAfter2nd);
NotificationItem::retryValues.clear();
NotificationItem::retryValues.append(cStrRetryOnce);
NotificationItem::retryValues.append(cStrRetryOncePUpdate);
NotificationItem::retryValues.append(cStrRetryInstantly);
NotificationItem::retryValues.append(cStrRetry10sec);
NotificationItem::retryValues.append(cStrRetry30sec);
@ -100,7 +105,7 @@ void NotificationItem::copyTo(NotificationItem* that) const
that->_soundCollectionPath = _soundCollectionPath;
that->_dataObject = _dataObject;
that->_objectField = _objectField;
that->_rangeLimit = _rangeLimit;
that->_condition = _condition;
that->_sound1 = _sound1;
that->_sound2 = _sound2;
that->_sound3 = _sound3;
@ -120,7 +125,7 @@ void NotificationItem::saveState(QSettings* settings) const
settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage());
settings->setValue(QLatin1String("ObjectField"), getObjectField());
settings->setValue(QLatin1String("DataObject"), getDataObject());
settings->setValue(QLatin1String("RangeLimit"), range());
settings->setValue(QLatin1String("RangeLimit"), getCondition());
settings->setValue(QLatin1String("Value1"), singleValue());
settings->setValue(QLatin1String("Value2"), valueRange2());
settings->setValue(QLatin1String("Sound1"), getSound1());
@ -139,7 +144,7 @@ void NotificationItem::restoreState(QSettings* settings)
setCurrentLanguage(settings->value(QLatin1String("CurrentLanguage"), tr("")).toString());
setDataObject(settings->value(QLatin1String("DataObject"), tr("")).toString());
setObjectField(settings->value(QLatin1String("ObjectField"), tr("")).toString());
setRange(settings->value(QLatin1String("RangeLimit"), tr("")).toString());
setCondition(settings->value(QLatin1String("RangeLimit"), tr("")).toInt());
setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString());
setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString());
setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString());
@ -152,13 +157,14 @@ void NotificationItem::restoreState(QSettings* settings)
setMute(settings->value(QLatin1String("Mute"), tr("")).toInt());
}
void NotificationItem::seriaize(QDataStream& stream)
void NotificationItem::serialize(QDataStream& stream)
{
stream << this->_soundCollectionPath;
stream << this->_currentLanguage;
stream << this->_dataObject;
stream << this->_objectField;
stream << this->_rangeLimit;
stream << this->_condition;
qNotifyDebug()<<"getOptionsPageValues seriaize"<<_condition;
stream << this->_sound1;
stream << this->_sound2;
stream << this->_sound3;
@ -170,13 +176,13 @@ void NotificationItem::seriaize(QDataStream& stream)
stream << this->_mute;
}
void NotificationItem::deseriaize(QDataStream& stream)
void NotificationItem::deserialize(QDataStream& stream)
{
stream >> this->_soundCollectionPath;
stream >> this->_currentLanguage;
stream >> this->_dataObject;
stream >> this->_objectField;
stream >> this->_rangeLimit;
stream >> this->_condition;
stream >> this->_sound1;
stream >> this->_sound2;
stream >> this->_sound3;
@ -252,7 +258,7 @@ void NotificationItem::disposeExpireTimer()
int getValuePosition(QString sayOrder)
{
return NotificationItem::sayOrderValues.indexOf(sayOrder);
return NotificationItem::sayOrderValues.indexOf(sayOrder)-1;
}
QString NotificationItem::checkSoundExists(QString fileName)
@ -275,11 +281,16 @@ QString NotificationItem::checkSoundExists(QString fileName)
QStringList valueToSoundList(QString value)
{
// replace point chr if exists
value = value.replace(',', '.');
QStringList numberParts = value.trimmed().split(".");
QStringList digitWavs;
if(numberParts.at(0).toInt()<0)
{
digitWavs.append("moved");
numberParts[0]=QString::number(numberParts.at(0).toInt()*-1);
}
if ( (numberParts.at(0).size() == 1) || (numberParts.at(0).toInt() < 20) ) {
// [1] check, is this number < 20, these numbers played by one wav file
digitWavs.append(numberParts.at(0));

View File

@ -246,7 +246,7 @@ void SoundNotifyPlugin::on_arrived_Notification(UAVObject *object)
// notification can be accepted again;
// 2. Once time notifications, they removed immediately after first playing;
// 3. Instant notifications(played one by one without interval);
if (ntf->retryString() != "Repeat Instantly" &&
if (ntf->retryString() != "Repeat Instantly" && ntf->retryString() != "Repeat Once per update" &&
ntf->retryString() != "Repeat Once" && ntf->_isPlayed)
continue;
@ -345,6 +345,7 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
NotificationItem* notification = _pendingNotifications.takeFirst();
qNotifyDebug_if(notification) << "play audioFree - " << notification->toString();
playNotification(notification);
qNotifyDebug()<<"end playNotification";
}
} else {
if (newstate == Phonon::ErrorState) {
@ -356,13 +357,13 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
}
}
bool checkRange(QString fieldValue, QString enumValue, QStringList values, char direction)
bool checkRange(QString fieldValue, QString enumValue, QStringList values, int direction)
{
bool ret = false;
switch(direction)
{
case 'E':
case NotificationItem::equal:
ret = !QString::compare(enumValue, fieldValue, Qt::CaseInsensitive) ? true : false;
break;
@ -373,21 +374,21 @@ bool checkRange(QString fieldValue, QString enumValue, QStringList values, char
return ret;
}
bool checkRange(double fieldValue, double min, double max, char direction)
bool checkRange(double fieldValue, double min, double max, int direction)
{
bool ret = false;
Q_ASSERT(min < max);
switch(direction)
{
case 'E':
case NotificationItem::equal:
ret = (fieldValue == min);
break;
case 'G':
case NotificationItem::bigger:
ret = (fieldValue > min);
break;
case 'L':
case NotificationItem::smaller:
ret = (fieldValue < min);
break;
@ -406,7 +407,7 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA
if (notification->mute())
return;
QString direction = notification->range();
int direction = notification->getCondition();
QString fieldName = notification->getObjectField();
UAVObjectField* field = object->getField(fieldName);
@ -415,15 +416,25 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA
QVariant value = field->getValue();
if(UAVObjectField::ENUM == field->getType()) {
qNotifyDebug()<<"Check range ENUM"<<value.toString()<<"|"<<notification->singleValue().toString()<<"|"<<field->getOptions()<<"|"<<
direction<<checkRange(value.toString(),
notification->singleValue().toString(),
field->getOptions(),
direction);;
condition = checkRange(value.toString(),
notification->singleValue().toString(),
field->getOptions(),
direction[0].toAscii());
direction);
} else {
qNotifyDebug()<<"Check range VAL"<<value.toString()<<"|"<<notification->singleValue().toString()<<"|"<<field->getOptions()<<"|"<<
direction<<checkRange(value.toDouble(),
notification->singleValue().toDouble(),
notification->valueRange2(),
direction);
condition = checkRange(value.toDouble(),
notification->singleValue().toDouble(),
notification->valueRange2(),
direction[0].toAscii());
direction);
}
notification->_isPlayed = condition;
@ -431,9 +442,11 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA
// we should reset _isPlayed flag and stop repeat timer
if (!notification->_isPlayed) {
notification->stopTimer();
notification->setCurrentUpdatePlayed(false);
return;
}
if(notification->retryString() == "Repeat Once per update" && notification->getCurrentUpdatePlayed())
return;
volatile QMutexLocker lock(&_mutex);
if (!playNotification(notification)) {
@ -473,7 +486,10 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
if (notification->retryString() == "Repeat Once") {
_toRemoveNotifications.append(_notificationList.takeAt(_notificationList.indexOf(notification)));
} else {
}
else if(notification->retryString() == "Repeat Once per update")
notification->setCurrentUpdatePlayed(true);
else {
if (notification->retryString() != "Repeat Instantly") {
QRegExp rxlen("(\\d+)");
QString value;
@ -505,7 +521,9 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
ms->setAutoDelete(true);
phonon.mo->enqueue(*ms);
}
qNotifyDebug()<<"begin play";
phonon.mo->play();
qNotifyDebug()<<"end play";
phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before
// the state is not "Loading" anymore.
return true;

View File

@ -57,7 +57,7 @@ NotifyPluginOptionsPage::NotifyPluginOptionsPage(QObject *parent)
: IOptionsPage(parent)
, _objManager(*ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>())
, _owner(qobject_cast<SoundNotifyPlugin*>(parent))
, _dynamicFieldLimit(NULL)
, _dynamicFieldCondition(NULL)
, _dynamicFieldWidget(NULL)
, _dynamicFieldType(-1)
, _sayOrder(NULL)
@ -74,7 +74,7 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
//main widget
QWidget* optionsPageWidget = new QWidget;
_dynamicFieldWidget = NULL;
_dynamicFieldLimit = NULL;
_dynamicFieldCondition = NULL;
resetFieldType();
//save ref to form, needed for binding dynamic fields in future
_form = optionsPageWidget;
@ -224,8 +224,8 @@ void NotifyPluginOptionsPage::addDynamicFieldLayout()
labelValueIs->setSizePolicy(labelSizePolicy);
_optionsPage->dynamicValueLayout->addWidget(labelValueIs);
_dynamicFieldLimit = new QComboBox(_form);
_optionsPage->dynamicValueLayout->addWidget(_dynamicFieldLimit);
_dynamicFieldCondition = new QComboBox(_form);
_optionsPage->dynamicValueLayout->addWidget(_dynamicFieldCondition);
UAVObjectField* field = getObjectFieldFromSelected();
addDynamicField(field);
}
@ -245,23 +245,42 @@ void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField)
return;
}
disconnect(_dynamicFieldLimit, SIGNAL(currentIndexChanged(QString)),
disconnect(_dynamicFieldCondition, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_changedIndex_rangeValue(QString)));
_dynamicFieldLimit->clear();
_dynamicFieldCondition->clear();
QStringList rangeValues;
QList<int> rangeCode;
if (UAVObjectField::ENUM == objField->getType()) {
rangeValues << cStrEqualTo << cStrInRange;
_dynamicFieldLimit->addItems(rangeValues);
_dynamicFieldLimit->setCurrentIndex(rangeValues.indexOf(_selectedNotification->range()));
rangeCode<<NotificationItem::equal<<NotificationItem::inrange;
int x=0;
int selected=0;
foreach (QString value, rangeValues) {
_dynamicFieldCondition->addItem(value,rangeCode[x]);
if(_selectedNotification->getCondition()==rangeCode[x])
selected=x;
++x;
}
qNotifyDebug()<<"setcurrentindex"<<x;
_dynamicFieldCondition->setCurrentIndex(selected);
} else {
rangeValues << cStrEqualTo << cStrLargeThan << cStrLowerThan << cStrInRange;
_dynamicFieldLimit->addItems(rangeValues);
connect(_dynamicFieldLimit, SIGNAL(currentIndexChanged(QString)),
rangeCode<<NotificationItem::equal<<NotificationItem::bigger<<NotificationItem::smaller<<NotificationItem::inrange;
int x=0;
int selected=0;
foreach (QString value, rangeValues) {
_dynamicFieldCondition->addItem(value,rangeCode[x]);
if(_selectedNotification->getCondition()==rangeCode[x])
selected=x;
++x;
}
qNotifyDebug()<<"setcurrentindex"<<x;
_dynamicFieldCondition->setCurrentIndex(selected);
connect(_dynamicFieldCondition, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_changedIndex_rangeValue(QString)));
}
addDynamicFieldWidget(objField);
}
@ -295,16 +314,16 @@ void NotifyPluginOptionsPage::addDynamicFieldWidget(UAVObjectField* objField)
break;
default:
Q_ASSERT(_dynamicFieldLimit);
if (_dynamicFieldLimit->currentText() == cStrInRange) {
Q_ASSERT(_dynamicFieldCondition);
if (_dynamicFieldCondition->currentText() == cStrInRange) {
_dynamicFieldWidget = new QLineEdit(_form);
(static_cast<QLineEdit*>(_dynamicFieldWidget))->setInputMask("999.99 - 999.99;");
(static_cast<QLineEdit*>(_dynamicFieldWidget))->setInputMask("#999.99 : #999.99;");
(static_cast<QLineEdit*>(_dynamicFieldWidget))->setText("0000000000");
(static_cast<QLineEdit*>(_dynamicFieldWidget))->setCursorPosition(0);
} else {
_dynamicFieldWidget = new QDoubleSpinBox(_form);
(dynamic_cast<QDoubleSpinBox*>(_dynamicFieldWidget))->setRange(000.00, 999.99);
(dynamic_cast<QDoubleSpinBox*>(_dynamicFieldWidget))->setRange(-999.99, 999.99);
}
break;
};
@ -351,7 +370,8 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio
notification->setSound2(_optionsPage->Sound2->currentText());
notification->setSound3(_optionsPage->Sound3->currentText());
notification->setSayOrder(_sayOrder->currentText());
notification->setRange(_dynamicFieldLimit->currentText());
notification->setCondition(_dynamicFieldCondition->itemData(_dynamicFieldCondition->currentIndex()).toInt());
qNotifyDebug()<<"getOptionsPageValues SETRANGE"<<_dynamicFieldCondition->currentIndex()<<_dynamicFieldCondition->itemData(_dynamicFieldCondition->currentIndex()).toInt();
if (QDoubleSpinBox* spinValue = dynamic_cast<QDoubleSpinBox*>(_dynamicFieldWidget))
notification->setSingleValue(spinValue->value());
else {
@ -360,7 +380,7 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio
else {
if (QLineEdit* rangeValue = dynamic_cast<QLineEdit*>(_dynamicFieldWidget)) {
QString str = rangeValue->text();
QStringList range = str.split('-');
QStringList range = str.split(':');
notification->setSingleValue(range.at(0).toDouble());
notification->setValueRange2(range.at(1).toDouble());
}
@ -435,11 +455,12 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification)
_optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default"));
_optionsPage->Sound3->setCurrentIndex(_optionsPage->Sound3->findText(notification->getSound3()));
}
if (-1 != _dynamicFieldLimit->findText(notification->range())) {
_dynamicFieldLimit->setCurrentIndex(_dynamicFieldLimit->findText(notification->range()));
for(int x=0;x<_dynamicFieldCondition->count();++x)
{
if (_dynamicFieldCondition->itemData(x)==notification->getCondition()) {
_dynamicFieldCondition->setCurrentIndex(x);
}
}
if (-1 != _sayOrder->findText(notification->getSayOrder())) {
_sayOrder->setCurrentIndex(_sayOrder->findText(notification->getSayOrder()));
}
@ -505,6 +526,7 @@ void NotifyPluginOptionsPage::on_changedIndex_soundLanguage(int index)
_optionsPage->Sound1->clear();
_optionsPage->Sound2->clear();
_optionsPage->Sound3->clear();
_optionsPage->Sound1->addItem("");
_optionsPage->Sound1->addItems(listSoundFiles);
_optionsPage->Sound2->addItem("");
_optionsPage->Sound2->addItems(listSoundFiles);

View File

@ -152,7 +152,7 @@ private:
QScopedPointer<Ui::NotifyPluginOptionsPage> _optionsPage;
//! Widget to convinient selection of condition for field value (equal, lower, greater)
QComboBox* _dynamicFieldLimit;
QComboBox* _dynamicFieldCondition;
//! Represents edit widget for dynamic UAVObjectfield,
//! can be spinbox - for numerics, combobox - enums, or