37 #include <QStringList>
43 static const QString VERSION =
"1.0.0";
47 SoundNotifyPlugin::SoundNotifyPlugin()
52 SoundNotifyPlugin::~SoundNotifyPlugin()
55 if (phonon.
mo != NULL)
59 bool SoundNotifyPlugin::initialize(
const QStringList &args, QString *errMsg)
70 void SoundNotifyPlugin::extensionsInitialized()
76 &SoundNotifyPlugin::onTelemetryManagerAdded);
77 _toRemoveNotifications.clear();
78 connectNotifications();
81 void SoundNotifyPlugin::saveConfig(QSettings *settings, UAVConfigInfo *configInfo)
84 configInfo->setVersion(VERSION);
86 settings->beginWriteArray(
"Current");
87 settings->setArrayIndex(0);
91 settings->beginGroup(
"listNotifies");
95 settings->beginWriteArray(
"listNotifies");
96 for (
int i = 0;
i < _notificationList.size();
i++) {
97 settings->setArrayIndex(
i);
98 _notificationList.at(
i)->saveState(settings);
100 settings->endArray();
101 settings->setValue(QLatin1String(
"EnableSound"), enableSound);
104 void SoundNotifyPlugin::readConfig(QSettings *settings, UAVConfigInfo * )
109 settings->beginReadArray(
"Current");
110 settings->setArrayIndex(0);
112 settings->endArray();
115 int size = settings->beginReadArray(
"listNotifies");
116 for (
int i = 0;
i < size; ++
i) {
117 settings->setArrayIndex(
i);
120 _notificationList.append(notification);
122 settings->endArray();
123 setEnableSound(settings->value(QLatin1String(
"EnableSound"), 0).toBool());
126 void SoundNotifyPlugin::onTelemetryManagerAdded(QObject *obj)
131 &SoundNotifyPlugin::onAutopilotDisconnect);
134 void SoundNotifyPlugin::shutdown()
139 void SoundNotifyPlugin::onAutopilotDisconnect()
141 connectNotifications();
148 void SoundNotifyPlugin::resetNotification(
void)
153 disconnect(ntf->
getTimer(), &QTimer::timeout,
this,
154 &SoundNotifyPlugin::on_timerRepeated_Notification);
157 &SoundNotifyPlugin::on_timerRepeated_Notification);
167 _toRemoveNotifications.clear();
169 _notificationList.clear();
170 _notificationList = list;
171 connectNotifications();
176 void SoundNotifyPlugin::connectNotifications()
181 &SoundNotifyPlugin::on_arrived_Notification);
183 if (phonon.
mo != NULL) {
194 lstNotifiedUAVObjects.clear();
195 _pendingNotifications.clear();
196 _notificationList.append(_toRemoveNotifications);
197 _toRemoveNotifications.clear();
214 if (!lstNotifiedUAVObjects.contains(obj)) {
215 lstNotifiedUAVObjects.append(obj);
218 &SoundNotifyPlugin::on_arrived_Notification, Qt::QueuedConnection);
225 if (_notificationList.isEmpty())
228 phonon.
mo =
new QMediaPlayer;
230 connect(phonon.
mo, &QMediaPlayer::stateChanged,
this, &SoundNotifyPlugin::stateChanged);
233 void SoundNotifyPlugin::on_arrived_Notification(
UAVObject *
object)
240 if (_nowPlayingNotification == ntf)
256 qNotifyDebug() << QString(
"new notification: | %1 | %2 | val1: %3 | val2: %4")
262 checkNotificationRule(ntf,
object);
265 Qt::UniqueConnection);
268 void SoundNotifyPlugin::on_timerRepeated_Notification()
276 if (_nowPlayingNotification == notification) {
277 qNotifyDebug() <<
"WARN: on_timerRepeated - notification was skipped!";
291 checkNotificationRule(notification,
object);
294 void SoundNotifyPlugin::on_expiredTimer_Notification()
302 if (!_pendingNotifications.isEmpty()) {
308 _pendingNotifications.removeOne(notification);
312 void SoundNotifyPlugin::stateChanged(QMediaPlayer::State newstate)
322 if ((newstate == QMediaPlayer::PausedState) || (newstate == QMediaPlayer::StoppedState)) {
323 qNotifyDebug() <<
"New State: " << QVariant(newstate).toString();
328 _nowPlayingNotification = NULL;
330 if (!_pendingNotifications.isEmpty()) {
332 qNotifyDebug_if(notification) <<
"play audioFree - " << notification->
toString();
333 playNotification(notification);
339 bool checkRange(QString fieldValue, QString enumValue, QStringList ,
int direction)
345 ret = !QString::compare(enumValue, fieldValue, Qt::CaseInsensitive) ?
true :
false;
355 bool checkRange(
double fieldValue,
double min,
double max,
int direction)
361 ret = (fieldValue == min);
365 ret = (fieldValue > min);
369 ret = (fieldValue < min);
373 ret = (fieldValue > min) && (fieldValue < max);
385 bool condition =
false;
387 if (notification->
mute())
394 if (field->
getName().isEmpty())
399 qNotifyDebug() <<
"Check range ENUM" << value.toString() <<
"|"
408 qNotifyDebug() <<
"Check range VAL" << value.toString() <<
"|"
426 && notification->getCurrentUpdatePlayed())
429 if (!playNotification(notification)) {
430 if (!_pendingNotifications.contains(notification)
431 && (_nowPlayingNotification != notification)) {
439 _pendingNotifications.append(notification);
442 &SoundNotifyPlugin::on_expiredTimer_Notification, Qt::UniqueConnection);
449 playlist =
new QMediaPlaylist;
454 if (phonon.
mo == NULL)
459 if ((phonon.
mo->state() == QMediaPlayer::PausedState)
460 || (phonon.
mo->state() == QMediaPlayer::StoppedState) || phonon.
firstPlay) {
461 _nowPlayingNotification = notification;
465 _toRemoveNotifications.append(
466 _notificationList.takeAt(_notificationList.indexOf(notification)));
471 QRegExp rxlen(
"(\\d+)");
477 value = rxlen.cap(1);
483 enum { eAverageDurationSec = 8 };
485 enum { eSecToMsec = 1000 };
487 timer_value = (value.toInt() + eAverageDurationSec) * eSecToMsec;
491 connect(notification->
getTimer(), &QTimer::timeout,
this,
492 &SoundNotifyPlugin::on_timerRepeated_Notification, Qt::UniqueConnection);
497 foreach (QString item, notification->
toSoundList()) {
498 playlist->addMedia(QUrl::fromLocalFile(item));
501 phonon.
mo->setPlaylist(playlist);
QVariant singleValue() const
Uses to logging only inside notify plugin, can be convinient turned on/off.
QStringList & toSoundList()
QString getObjectField() const
Core plugin system that manages the plugins, their life cycle and their registered objects...
QVariant getValue(int index=0) const
Notify Plugin options page header.
virtual void readSettings(IConfigurablePlugin *plugin, QSettings *qs=nullptr)=0
void disposeExpireTimer()
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
void saveState(QSettings *settings) const
void setCurrentUpdatePlayed(bool value)
QStringList getOptions() const
bool checkRange(QString fieldValue, QString enumValue, QStringList, int direction)
QTimer * getExpireTimer() const
void restoreState(QSettings *settings)
static ICore * instance()
void updateNotificationList(QList< NotificationItem * > list)
static QStringList retryValues
void startTimer(int value)
double valueRange2() const
void objectAdded(QObject *obj)
QTimer * getTimer() const
QString getDataObject() const
virtual void saveSettings(IConfigurablePlugin *plugin, QSettings *qs=nullptr)=0
void addAutoReleasedObject(QObject *obj)
UAVObject * getObject(const QString &name, quint32 instId=0)
FieldType getType() const