31 #include <QtCore/QDataStream>
51 , _currentUpdatePlayed(false)
54 , _soundCollectionPath(
"")
55 , _currentLanguage(
"default")
65 , _repeatValue(repeatInstantly)
66 , _expireTimeout(eDefaultTimeout)
79 QString(tr(
"Repeat Once per update")));
90 that->_soundCollectionPath = _soundCollectionPath;
91 that->_currentLanguage = _currentLanguage;
92 that->_soundCollectionPath = _soundCollectionPath;
93 that->_dataObject = _dataObject;
94 that->_objectField = _objectField;
95 that->_condition = _condition;
96 that->_sound1 = _sound1;
97 that->_sound2 = _sound2;
98 that->_sound3 = _sound3;
99 that->_sayOrder = _sayOrder;
100 that->_singleValue = _singleValue;
101 that->_valueRange2 = _valueRange2;
102 that->_repeatValue = _repeatValue;
103 that->_expireTimeout = _expireTimeout;
109 settings->setValue(
"SoundCollectionPath",
112 settings->setValue(QLatin1String(
"ObjectField"),
getObjectField());
113 settings->setValue(QLatin1String(
"DataObject"),
getDataObject());
114 settings->setValue(QLatin1String(
"RangeLimit"),
getCondition());
115 settings->setValue(QLatin1String(
"Value1"),
singleValue());
116 settings->setValue(QLatin1String(
"Value2"),
valueRange2());
117 settings->setValue(QLatin1String(
"Sound1"), getSound1());
118 settings->setValue(QLatin1String(
"Sound2"), getSound2());
119 settings->setValue(QLatin1String(
"Sound3"), getSound3());
120 settings->setValue(QLatin1String(
"SayOrder"),
getSayOrder());
121 settings->setValue(QLatin1String(
"Repeat"),
retryValue());
122 settings->setValue(QLatin1String(
"ExpireTimeout"),
lifetime());
123 settings->setValue(QLatin1String(
"Mute"),
mute());
130 settings->value(QLatin1String(
"SoundCollectionPath"), tr(
"")).toString()));
131 setCurrentLanguage(settings->value(QLatin1String(
"CurrentLanguage"), tr(
"")).toString());
132 setDataObject(settings->value(QLatin1String(
"DataObject"), tr(
"")).toString());
133 setObjectField(settings->value(QLatin1String(
"ObjectField"), tr(
"")).toString());
134 setCondition(settings->value(QLatin1String(
"RangeLimit"), tr(
"")).toInt());
135 setSound1(settings->value(QLatin1String(
"Sound1"), tr(
"")).toString());
136 setSound2(settings->value(QLatin1String(
"Sound2"), tr(
"")).toString());
137 setSound3(settings->value(QLatin1String(
"Sound3"), tr(
"")).toString());
138 setSayOrder(settings->value(QLatin1String(
"SayOrder"), tr(
"")).toInt());
139 QVariant value = settings->value(QLatin1String(
"Value1"), tr(
""));
141 setValueRange2(settings->value(QLatin1String(
"Value2"), tr(
"")).toDouble());
142 setRetryValue(settings->value(QLatin1String(
"Repeat"), tr(
"")).toInt());
143 setLifetime(settings->value(QLatin1String(
"ExpireTimeout"), tr(
"")).toInt());
144 setMute(settings->value(QLatin1String(
"Mute"), tr(
"")).toInt());
149 stream << this->_soundCollectionPath;
150 stream << this->_currentLanguage;
151 stream << this->_dataObject;
152 stream << this->_objectField;
153 stream << this->_condition;
154 qNotifyDebug() <<
"getOptionsPageValues seriaize" << _condition;
155 stream << this->_sound1;
156 stream << this->_sound2;
157 stream << this->_sound3;
158 stream << this->_sayOrder;
159 stream << this->_singleValue;
160 stream << this->_valueRange2;
161 stream << this->_repeatValue;
162 stream << this->_expireTimeout;
163 stream << this->_mute;
168 stream >> this->_soundCollectionPath;
169 stream >> this->_currentLanguage;
170 stream >> this->_dataObject;
171 stream >> this->_objectField;
172 stream >> this->_condition;
173 stream >> this->_sound1;
174 stream >> this->_sound2;
175 stream >> this->_sound3;
176 stream >> this->_sayOrder;
177 stream >> this->_singleValue;
178 stream >> this->_valueRange2;
179 stream >> this->_repeatValue;
180 stream >> this->_expireTimeout;
181 stream >> this->_mute;
187 _timer =
new QTimer(
this);
188 _timer->setInterval(msec);
190 if (!_timer->isActive())
197 if (!_timer->isActive())
205 if (_timer->isActive())
222 _expireTimer =
new QTimer(
this);
224 _expireTimer->start(_expireTimeout * 1000);
231 _expireTimer->stop();
238 _expireTimer->stop();
249 QString NotificationItem::checkSoundExists(QString fileName)
251 QString name(fileName +
".wav");
254 if (QFile::exists(filePath))
258 if (!QFile::exists(filePath))
266 qNotifyDebug() <<
"notificationItem valueToSoundList input param" << value;
268 value = value.replace(
',',
'.');
269 QStringList numberParts = value.trimmed().split(
".");
270 QStringList digitWavs;
271 bool negative =
false;
272 if (numberParts.at(0).toInt() < 0) {
274 digitWavs.append(
"minus");
275 numberParts[0] = QString::number(numberParts.at(0).toInt() * -1);
277 if ((numberParts.at(0).size() == 1) || (numberParts.at(0).toInt() < 20)) {
279 digitWavs.append(numberParts.at(0));
283 int num = numberParts.at(0).right(2).toInt();
284 if (num < 20 && num != 0) {
286 digitWavs.append(numberParts.at(0).right(1 + num / 11));
290 for (; i < numberParts.at(0).size(); i++) {
294 digitWavs.insert(offset, numberParts.at(0).at(numberParts.at(0).size() - i - 1));
295 if (digitWavs.at(offset) == QString(
"0")) {
296 digitWavs.removeAt(offset);
300 digitWavs.replace(0 + offset, digitWavs.at(offset) +
'0');
302 digitWavs.insert(1 + offset,
"100");
304 digitWavs.insert(1 + offset,
"1000");
308 if (1 < numberParts.size()) {
309 digitWavs.append(
"point");
310 if (numberParts.at(1).size() == 1) {
312 digitWavs.append(numberParts.at(1));
315 QString left = numberParts.at(1).left(1);
316 (left ==
"0") ? digitWavs.append(left) : digitWavs.append(left +
'0');
317 digitWavs.append(numberParts.at(1).right(1));
320 qNotifyDebug() <<
"notificationItem valueToSoundList return value" << digitWavs;
329 Q_ASSERT(!value.isNull());
332 if (!field->
getOptions().contains(value.toString()))
334 str = value.toString();
336 str = QString(
"%L1").arg(value.toDouble());
354 foreach (QString sound, valueSounds) {
355 if (checkSoundExists(sound).isEmpty()) {
364 lst.insert(pos,
"[missed]" + value);
366 lst.insert(pos, value);
381 _messageSequence.clear();
384 if (!getSound1().isEmpty())
385 lst.append(getSound1());
386 if (!getSound2().isEmpty())
387 lst.append(getSound2());
388 if (!getSound3().isEmpty())
389 lst.append(getSound3());
394 foreach (QString sound, valueSounds)
395 lst.insert(pos++, sound);
398 foreach (QString sound, lst) {
399 QString path = checkSoundExists(sound);
400 if (!path.isEmpty()) {
401 _messageSequence.append(path);
403 _messageSequence.clear();
407 return _messageSequence;
412 if (fileName.isEmpty())
414 if (checkSoundExists(fileName).isEmpty()) {
415 return QString(
"[missed]") + fileName;
QVariant singleValue() const
Uses to logging only inside notify plugin, can be convinient turned on/off.
void setObjectField(QString text)
QStringList & toSoundList()
QString getObjectField() const
QString getCurrentLanguage() const
void copyTo(NotificationItem *) const
void disposeExpireTimer()
void setSayOrder(int text)
int getValuePosition(QString sayOrder)
QString stringFromValue(QVariant value, UAVObjectField *field)
void saveState(QSettings *settings) const
QStringList getOptions() const
void restoreState(QSettings *settings)
void setDataObject(QString text)
static QStringList sayOrderValues
UAVObjectField * getField(const QString &name)
void setSoundCollectionPath(QString path)
static QStringList retryValues
QString getSoundCollectionPath() const
void startTimer(int value)
double valueRange2() const
NotificationItem(QObject *parent=nullptr)
UAVObjectField * getUAVObjectField(void)
QString getDataObject() const
void deserialize(QDataStream &stream)
void serialize(QDataStream &stream)
QStringList valueToSoundList(QString value)
void setCurrentLanguage(QString text)
void setSingleValue(QVariant value)
UAVDataObject * getUAVObject(void)
void setCondition(int value)
QString getSoundCaption(QString fileName)
void setLifetime(int value)
void setRetryValue(int value)
void setValueRange2(double value)
FieldType getType() const