dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
notifypluginoptionspage.cpp
Go to the documentation of this file.
1 
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, see <http://www.gnu.org/licenses/>
28  */
29 
31 #include <coreplugin/icore.h>
32 #include "notificationitem.h"
33 #include "ui_notifypluginoptionspage.h"
35 #include "utils/pathutils.h"
36 
37 #include <QFileDialog>
38 #include <QtAlgorithms>
39 #include <QStringList>
40 #include <QtCore/QSettings>
41 #include <QTableWidget>
42 #include <QPalette>
43 #include <QBuffer>
44 #include <QSpinBox>
45 #include <QLineEdit>
46 #include <QMediaPlayer>
47 
48 #include "notifyplugin.h"
49 #include "notifyitemdelegate.h"
50 #include "notifytablemodel.h"
51 #include "notifylogging.h"
52 
54 
56  : IOptionsPage(parent)
57  , _objManager(*ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>())
58  , _owner(qobject_cast<SoundNotifyPlugin *>(parent))
59  , _dynamicFieldCondition(NULL)
60  , _dynamicFieldWidget(NULL)
61  , _dynamicFieldType(-1)
62  , _sayOrder(NULL)
63  , _form(NULL)
64  , _selectedNotification(NULL)
65 {
66  NotifyPluginOptionsPage::conditionValues.insert(equal, tr("Equal to"));
67  NotifyPluginOptionsPage::conditionValues.insert(bigger, tr("Large than"));
68  NotifyPluginOptionsPage::conditionValues.insert(smaller, tr("Lower than"));
69  NotifyPluginOptionsPage::conditionValues.insert(inrange, tr("In range"));
70 }
71 
73 {
74 }
75 
76 QWidget *NotifyPluginOptionsPage::createPage(QWidget * /* parent */)
77 {
78  _optionsPage.reset(new Ui::NotifyPluginOptionsPage());
79  // main widget
80  QWidget *optionsPageWidget = new QWidget;
81  _dynamicFieldWidget = NULL;
82  _dynamicFieldCondition = NULL;
83  resetFieldType();
84  // save ref to form, needed for binding dynamic fields in future
85  _form = optionsPageWidget;
86  // main layout
87  _optionsPage->setupUi(optionsPageWidget);
88 
89  _optionsPage->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
90  _optionsPage->SoundDirectoryPathChooser->setPromptDialogTitle(
91  tr("Choose sound collection directory"));
92 
93  connect(_optionsPage->SoundDirectoryPathChooser, &Utils::PathChooser::changed, this,
94  &NotifyPluginOptionsPage::on_clicked_buttonSoundFolder);
95  connect(_optionsPage->SoundCollectionList, QOverload<int>::of(&QComboBox::currentIndexChanged),
96  this, &NotifyPluginOptionsPage::on_changedIndex_soundLanguage);
97 
98  connect(this, &NotifyPluginOptionsPage::updateNotifications, _owner,
100  // connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification()));
101 
102  _privListNotifications = _owner->getListNotifications();
103 
104  // [1]
105  setSelectedNotification(_owner->getCurrentNotification());
106  addDynamicFieldLayout();
107  // [2]
108  updateConfigView(_selectedNotification);
109 
110  initRulesTable();
111  initButtons();
112  initPhononPlayer();
113 
114  int curr_row = _privListNotifications.indexOf(_selectedNotification);
115  _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(curr_row, 0, QModelIndex()),
116  QItemSelectionModel::ClearAndSelect
117  | QItemSelectionModel::Rows);
118 
119  return optionsPageWidget;
120 }
121 
123 {
124  getOptionsPageValues(_owner->getCurrentNotification());
125  _owner->setEnableSound(_optionsPage->chkEnableSound->isChecked());
126  emit updateNotifications(_privListNotifications);
127 }
128 
130 {
131  disconnect(_optionsPage->UAVObjectField,
132  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
133  &NotifyPluginOptionsPage::on_changedIndex_UAVField);
134 
135  disconnect(_testSound, &QMediaPlayer::stateChanged, this,
136  &NotifyPluginOptionsPage::on_changed_playButtonText);
137  if (_testSound) {
138  _testSound->stop();
139  }
140 }
141 
142 void NotifyPluginOptionsPage::initButtons()
143 {
144  _optionsPage->chkEnableSound->setChecked(_owner->getEnableSound());
145 
146  _optionsPage->buttonModify->setEnabled(false);
147  _optionsPage->buttonDelete->setEnabled(false);
148  _optionsPage->buttonPlayNotification->setEnabled(false);
149  connect(_optionsPage->buttonAdd, &QAbstractButton::pressed, this,
150  &NotifyPluginOptionsPage::on_clicked_buttonAddNotification);
151  connect(_optionsPage->buttonDelete, &QAbstractButton::pressed, this,
152  &NotifyPluginOptionsPage::on_clicked_buttonDeleteNotification);
153  connect(_optionsPage->buttonModify, &QAbstractButton::pressed, this,
154  &NotifyPluginOptionsPage::on_clicked_buttonModifyNotification);
155  connect(_optionsPage->buttonPlayNotification, &QAbstractButton::clicked, this,
156  &NotifyPluginOptionsPage::on_clicked_buttonTestSoundNotification);
157 }
158 
159 void NotifyPluginOptionsPage::initPhononPlayer()
160 {
161  _testSound = new QMediaPlayer;
162  connect(_testSound, &QMediaPlayer::stateChanged, this,
163  &NotifyPluginOptionsPage::on_changed_playButtonText);
164 }
165 
166 void NotifyPluginOptionsPage::initRulesTable()
167 {
168  qNotifyDebug_if(_notifyRulesModel.isNull()) << "_notifyRulesModel.isNull())";
169  qNotifyDebug_if(!_notifyRulesSelection) << "_notifyRulesSelection.isNull())";
170  _notifyRulesModel.reset(new NotifyTableModel(_privListNotifications));
171  _notifyRulesSelection = new QItemSelectionModel(_notifyRulesModel.data());
172 
173  connect(_notifyRulesSelection, &QItemSelectionModel::selectionChanged, this,
174  &NotifyPluginOptionsPage::on_changedSelection_notifyTable);
175  connect(this, &NotifyPluginOptionsPage::entryUpdated, _notifyRulesModel.data(),
177 
178  _optionsPage->notifyRulesView->setModel(_notifyRulesModel.data());
179  _optionsPage->notifyRulesView->setSelectionModel(_notifyRulesSelection);
180  _optionsPage->notifyRulesView->setItemDelegate(new NotifyItemDelegate(this));
181 
182  _optionsPage->notifyRulesView->resizeRowsToContents();
183  _optionsPage->notifyRulesView->setColumnWidth(eMessageName, 200);
184  _optionsPage->notifyRulesView->setColumnWidth(eRepeatValue, 120);
185  _optionsPage->notifyRulesView->setColumnWidth(eExpireTimer, 100);
186  _optionsPage->notifyRulesView->setColumnWidth(eTurnOn, 60);
187  _optionsPage->notifyRulesView->setDragEnabled(true);
188  _optionsPage->notifyRulesView->setAcceptDrops(true);
189  _optionsPage->notifyRulesView->setDropIndicatorShown(true);
190  _optionsPage->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove);
191 }
192 
193 UAVObjectField *NotifyPluginOptionsPage::getObjectFieldFromSelected()
194 {
195  return (_currUAVObject) ? _currUAVObject->getField(_selectedNotification->getObjectField())
196  : NULL;
197 }
198 
199 void NotifyPluginOptionsPage::setSelectedNotification(NotificationItem *ntf)
200 {
201  _selectedNotification = ntf;
202  _currUAVObject = dynamic_cast<UAVDataObject *>(
203  _objManager.getObject(_selectedNotification->getDataObject()));
204  if (!_currUAVObject) {
205  qNotifyDebug() << "no such UAVObject: " << _selectedNotification->getDataObject();
206  }
207 }
208 
209 void NotifyPluginOptionsPage::addDynamicFieldLayout()
210 {
211  // there is no need to check (objField == NULL),
212  // thus it doesn't use in this field directly
213 
214  QSizePolicy labelSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
215  labelSizePolicy.setHorizontalStretch(0);
216  labelSizePolicy.setVerticalStretch(0);
217  // labelSizePolicy.setHeightForWidth(UAVObject->sizePolicy().hasHeightForWidth());
218 
219  QLabel *labelSayOrder = new QLabel("Say order ", _form);
220  labelSayOrder->setSizePolicy(labelSizePolicy);
221 
222  _optionsPage->dynamicValueLayout->addWidget(labelSayOrder);
223  _sayOrder = new QComboBox(_form);
224  _optionsPage->dynamicValueLayout->addWidget(_sayOrder);
225  _sayOrder->addItems(NotificationItem::sayOrderValues);
226 
227  QLabel *labelValueIs = new QLabel("Value is ", _form);
228  labelValueIs->setSizePolicy(labelSizePolicy);
229  _optionsPage->dynamicValueLayout->addWidget(labelValueIs);
230 
231  _dynamicFieldCondition = new QComboBox(_form);
232  _optionsPage->dynamicValueLayout->addWidget(_dynamicFieldCondition);
233  UAVObjectField *field = getObjectFieldFromSelected();
234  addDynamicField(field);
235 }
236 
237 void NotifyPluginOptionsPage::addDynamicField(UAVObjectField *objField)
238 {
239  if (!objField) {
240  qNotifyDebug() << "addDynamicField | input objField == NULL";
241  return;
242  }
243  if (objField->getType() == _dynamicFieldType) {
244  if (QComboBox *fieldValue = dynamic_cast<QComboBox *>(_dynamicFieldWidget)) {
245  fieldValue->clear();
246  QStringList enumValues(objField->getOptions());
247  fieldValue->addItems(enumValues);
248  }
249  return;
250  }
251 
252  disconnect(_dynamicFieldCondition,
253  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
254  &NotifyPluginOptionsPage::on_changedIndex_rangeValue);
255 
256  _dynamicFieldCondition->clear();
257  _dynamicFieldCondition->addItems(NotifyPluginOptionsPage::conditionValues);
258  if (UAVObjectField::ENUM == objField->getType()) {
259  _dynamicFieldCondition->removeItem(smaller);
260  _dynamicFieldCondition->removeItem(bigger);
261  }
262  int cond = _selectedNotification->getCondition();
263  if (cond < 0)
264  return;
265  _dynamicFieldCondition->setCurrentIndex(
266  _dynamicFieldCondition->findText(NotifyPluginOptionsPage::conditionValues.at(cond)));
267 
268  connect(_dynamicFieldCondition, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
269  this, &NotifyPluginOptionsPage::on_changedIndex_rangeValue);
270 
271  addDynamicFieldWidget(objField);
272 }
273 
274 void NotifyPluginOptionsPage::addDynamicFieldWidget(UAVObjectField *objField)
275 {
276  if (!objField) {
277  qNotifyDebug() << "objField == NULL!";
278  return;
279  }
280  // check if dynamic fileld already settled,
281  // so if its exists remove it and install new field
282  if (_dynamicFieldWidget) {
283  _optionsPage->dynamicValueLayout->removeWidget(_dynamicFieldWidget);
284  delete _dynamicFieldWidget;
285  _dynamicFieldWidget = NULL;
286  }
287 
288  QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
289  sizePolicy.setHorizontalStretch(0);
290  sizePolicy.setVerticalStretch(0);
291 
292  _dynamicFieldType = objField->getType();
293  switch (_dynamicFieldType) {
294  case UAVObjectField::ENUM: {
295  _dynamicFieldWidget = new QComboBox(_form);
296  QStringList enumValues(objField->getOptions());
297  (dynamic_cast<QComboBox *>(_dynamicFieldWidget))->addItems(enumValues);
298  } break;
299 
300  default:
301  Q_ASSERT(_dynamicFieldCondition);
302  if (NotifyPluginOptionsPage::conditionValues.indexOf(_dynamicFieldCondition->currentText())
304  _dynamicFieldWidget = new QLineEdit(_form);
305 
306  (static_cast<QLineEdit *>(_dynamicFieldWidget))->setInputMask("#999.99 : #999.99;");
307  (static_cast<QLineEdit *>(_dynamicFieldWidget))->setText("0000000000");
308  (static_cast<QLineEdit *>(_dynamicFieldWidget))->setCursorPosition(0);
309  } else {
310  _dynamicFieldWidget = new QDoubleSpinBox(_form);
311  (dynamic_cast<QDoubleSpinBox *>(_dynamicFieldWidget))->setRange(-999.99, 999.99);
312  }
313  break;
314  };
315  enum { eDynamicFieldWidth = 100 };
316  _dynamicFieldWidget->setSizePolicy(sizePolicy);
317  _dynamicFieldWidget->setFixedWidth(eDynamicFieldWidth);
318  _optionsPage->dynamicValueLayout->addWidget(_dynamicFieldWidget);
319 }
320 
321 void NotifyPluginOptionsPage::setDynamicFieldValue(NotificationItem *notification)
322 {
323  if (QDoubleSpinBox *seValue = dynamic_cast<QDoubleSpinBox *>(_dynamicFieldWidget))
324  seValue->setValue(notification->singleValue().toDouble());
325  else {
326  if (QComboBox *cbValue = dynamic_cast<QComboBox *>(_dynamicFieldWidget)) {
327  int idx = cbValue->findText(notification->singleValue().toString());
328  if (-1 != idx)
329  cbValue->setCurrentIndex(idx);
330  } else {
331  if (QLineEdit *rangeValue = dynamic_cast<QLineEdit *>(_dynamicFieldWidget)) {
332  QString str = QString("%1%2")
333  .arg(notification->singleValue().toDouble(), 5, 'f', 2, '0')
334  .arg(notification->valueRange2(), 5, 'f', 2, '0');
335  rangeValue->setText(str);
336  } else {
337  qNotifyDebug()
338  << "NotifyPluginOptionsPage::setDynamicValueField | unknown _fieldValue: "
339  << _dynamicFieldWidget;
340  }
341  }
342  }
343 }
344 
345 void NotifyPluginOptionsPage::resetFieldType()
346 {
347  _dynamicFieldType = -1;
348 }
349 
350 void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem *notification)
351 {
352  Q_ASSERT(notification);
353  notification->setSoundCollectionPath(_optionsPage->SoundDirectoryPathChooser->path());
354  notification->setCurrentLanguage(_optionsPage->SoundCollectionList->currentText());
355  notification->setDataObject(_optionsPage->UAVObject->currentText());
356  notification->setObjectField(_optionsPage->UAVObjectField->currentText());
357  notification->setSound1(_optionsPage->Sound1->currentText());
358  notification->setSound2(_optionsPage->Sound2->currentText());
359  notification->setSound3(_optionsPage->Sound3->currentText());
360  notification->setSayOrder(_sayOrder->currentIndex());
361  notification->setCondition(
362  NotifyPluginOptionsPage::conditionValues.indexOf(_dynamicFieldCondition->currentText()));
363  if (QDoubleSpinBox *spinValue = dynamic_cast<QDoubleSpinBox *>(_dynamicFieldWidget))
364  notification->setSingleValue(spinValue->value());
365  else {
366  if (QComboBox *comboBoxValue = dynamic_cast<QComboBox *>(_dynamicFieldWidget))
367  notification->setSingleValue(comboBoxValue->currentText());
368  else {
369  if (QLineEdit *rangeValue = dynamic_cast<QLineEdit *>(_dynamicFieldWidget)) {
370  QString str = rangeValue->text();
371  QStringList range = str.split(':');
372  notification->setSingleValue(range.at(0).toDouble());
373  notification->setValueRange2(range.at(1).toDouble());
374  }
375  }
376  }
377 }
378 
379 void NotifyPluginOptionsPage::updateConfigView(NotificationItem *notification)
380 {
381  Q_ASSERT(notification);
382  disconnect(_optionsPage->UAVObject,
383  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
384  &NotifyPluginOptionsPage::on_changedIndex_UAVObject);
385  disconnect(_optionsPage->UAVObjectField,
386  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
387  &NotifyPluginOptionsPage::on_changedIndex_UAVField);
388 
389  QString path = notification->getSoundCollectionPath();
390  if (path.isEmpty()) {
391  path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds");
392  }
393 
394  _optionsPage->SoundDirectoryPathChooser->setPath(path);
395 
396  if (-1 != _optionsPage->SoundCollectionList->findText(notification->getCurrentLanguage())) {
397  _optionsPage->SoundCollectionList->setCurrentIndex(
398  _optionsPage->SoundCollectionList->findText(notification->getCurrentLanguage()));
399  } else {
400  _optionsPage->SoundCollectionList->setCurrentIndex(
401  _optionsPage->SoundCollectionList->findText("default"));
402  }
403 
404  // Fills the combo boxes for the UAVObjects
405  QVector<QVector<UAVDataObject *>> objList = _objManager.getDataObjectsVector();
406  foreach (QVector<UAVDataObject *> list, objList) {
407  foreach (UAVDataObject *obj, list) {
408  _optionsPage->UAVObject->addItem(obj->getName());
409  }
410  }
411 
412  if (-1 != _optionsPage->UAVObject->findText(notification->getDataObject())) {
413  _optionsPage->UAVObject->setCurrentIndex(
414  _optionsPage->UAVObject->findText(notification->getDataObject()));
415  }
416 
417  _optionsPage->UAVObjectField->clear();
418  if (_currUAVObject) {
419  QList<UAVObjectField *> fieldList = _currUAVObject->getFields();
420  foreach (UAVObjectField *field, fieldList)
421  _optionsPage->UAVObjectField->addItem(field->getName());
422  }
423 
424  if (-1 != _optionsPage->UAVObjectField->findText(notification->getObjectField())) {
425  _optionsPage->UAVObjectField->setCurrentIndex(
426  _optionsPage->UAVObjectField->findText(notification->getObjectField()));
427  }
428 
429  if (-1 != _optionsPage->Sound1->findText(notification->getSound1())) {
430  _optionsPage->Sound1->setCurrentIndex(
431  _optionsPage->Sound1->findText(notification->getSound1()));
432  } else {
433  // show item from default location
434  _optionsPage->SoundCollectionList->setCurrentIndex(
435  _optionsPage->SoundCollectionList->findText("default"));
436  _optionsPage->Sound1->setCurrentIndex(
437  _optionsPage->Sound1->findText(notification->getSound1()));
438  }
439 
440  if (-1 != _optionsPage->Sound2->findText(notification->getSound2())) {
441  _optionsPage->Sound2->setCurrentIndex(
442  _optionsPage->Sound2->findText(notification->getSound2()));
443  } else {
444  // show item from default location
445  _optionsPage->SoundCollectionList->setCurrentIndex(
446  _optionsPage->SoundCollectionList->findText("default"));
447  _optionsPage->Sound2->setCurrentIndex(
448  _optionsPage->Sound2->findText(notification->getSound2()));
449  }
450 
451  if (-1 != _optionsPage->Sound3->findText(notification->getSound3())) {
452  _optionsPage->Sound3->setCurrentIndex(
453  _optionsPage->Sound3->findText(notification->getSound3()));
454  } else {
455  // show item from default location
456  _optionsPage->SoundCollectionList->setCurrentIndex(
457  _optionsPage->SoundCollectionList->findText("default"));
458  _optionsPage->Sound3->setCurrentIndex(
459  _optionsPage->Sound3->findText(notification->getSound3()));
460  }
461  int cond = notification->getCondition();
462  if (cond < 0)
463  return;
464  _dynamicFieldCondition->setCurrentIndex(
465  _dynamicFieldCondition->findText(NotifyPluginOptionsPage::conditionValues.at(cond)));
466 
467  _sayOrder->setCurrentIndex(notification->getSayOrder());
468 
469  setDynamicFieldValue(notification);
470 
471  connect(_optionsPage->UAVObject,
472  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
473  &NotifyPluginOptionsPage::on_changedIndex_UAVObject);
474  connect(_optionsPage->UAVObjectField,
475  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
476  &NotifyPluginOptionsPage::on_changedIndex_UAVField);
477 }
478 
479 void NotifyPluginOptionsPage::on_changedIndex_rangeValue(QString /* rangeStr */)
480 {
481  Q_ASSERT(_dynamicFieldWidget);
482  UAVObjectField *field = getObjectFieldFromSelected();
483  Q_ASSERT(!!field);
484  addDynamicFieldWidget(field);
485  setDynamicFieldValue(_selectedNotification);
486 }
487 
488 void NotifyPluginOptionsPage::on_changedIndex_UAVField(QString field)
489 {
490  resetFieldType();
491  Q_ASSERT(_currUAVObject);
492  addDynamicField(_currUAVObject->getField(field));
493 }
494 
495 void NotifyPluginOptionsPage::on_changedIndex_UAVObject(QString val)
496 {
497  resetFieldType();
498  _currUAVObject = dynamic_cast<UAVDataObject *>(_objManager.getObject(val));
499  if (!_currUAVObject) {
500  qNotifyDebug() << "on_UAVObject_indexChanged | no such UAVOBject";
501  return;
502  }
503  QList<UAVObjectField *> fieldList = _currUAVObject->getFields();
504  disconnect(_optionsPage->UAVObjectField,
505  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
506  &NotifyPluginOptionsPage::on_changedIndex_UAVField);
507  _optionsPage->UAVObjectField->clear();
508  foreach (UAVObjectField *field, fieldList) {
509  _optionsPage->UAVObjectField->addItem(field->getName());
510  }
511  connect(_optionsPage->UAVObjectField,
512  QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this,
513  &NotifyPluginOptionsPage::on_changedIndex_UAVField);
514  _selectedNotification->setObjectField(fieldList.at(0)->getName());
515  addDynamicField(fieldList.at(0));
516 }
517 
518 void NotifyPluginOptionsPage::on_changedIndex_soundLanguage(int index)
519 {
520  _optionsPage->SoundCollectionList->setCurrentIndex(index);
521  QString collectionPath = _optionsPage->SoundDirectoryPathChooser->path()
522  + QDir::toNativeSeparators("/" + _optionsPage->SoundCollectionList->currentText());
523 
524  QDir dirPath(collectionPath);
525  QStringList filters;
526  filters << "*.mp3"
527  << "*.wav";
528  dirPath.setNameFilters(filters);
529  QStringList listSoundFiles = dirPath.entryList(filters);
530  listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), "");
531  _optionsPage->Sound1->clear();
532  _optionsPage->Sound2->clear();
533  _optionsPage->Sound3->clear();
534  _optionsPage->Sound1->addItem("");
535  _optionsPage->Sound1->addItems(listSoundFiles);
536  _optionsPage->Sound2->addItem("");
537  _optionsPage->Sound2->addItems(listSoundFiles);
538  _optionsPage->Sound3->addItem("");
539  _optionsPage->Sound3->addItems(listSoundFiles);
540 }
541 
542 void NotifyPluginOptionsPage::on_changed_playButtonText(QMediaPlayer::State newstate)
543 {
544  // Q_ASSERT(Phonon::ErrorState != newstate);
545 
546  if (newstate == QMediaPlayer::PausedState || newstate == QMediaPlayer::StoppedState) {
547  _optionsPage->buttonPlayNotification->setText("Play");
548  _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png"));
549  } else {
550  if (newstate == QMediaPlayer::PlayingState) {
551  _optionsPage->buttonPlayNotification->setText("Stop");
552  _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png"));
553  }
554  }
555 }
556 
557 void NotifyPluginOptionsPage::on_changedSelection_notifyTable(
558  const QItemSelection &selected, const QItemSelection & /* deselected */)
559 {
560  bool select = false;
561  _testSound->stop();
562  if (selected.indexes().size()) {
563  select = true;
564  setSelectedNotification(_privListNotifications.at(selected.indexes().at(0).row()));
565  UAVObjectField *field = getObjectFieldFromSelected();
566  addDynamicField(field);
567  updateConfigView(_selectedNotification);
568  }
569 
570  _optionsPage->buttonModify->setEnabled(select);
571  _optionsPage->buttonDelete->setEnabled(select);
572  _optionsPage->buttonPlayNotification->setEnabled(select);
573 }
574 
575 void NotifyPluginOptionsPage::on_clicked_buttonSoundFolder(const QString &path)
576 {
577  QDir dirPath(path);
578  QStringList listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
579  _optionsPage->SoundCollectionList->clear();
580  _optionsPage->SoundCollectionList->addItems(listDirCollections);
581 }
582 
583 void NotifyPluginOptionsPage::on_clicked_buttonTestSoundNotification()
584 {
585  NotificationItem *notification = NULL;
586 
587  playlist = new QMediaPlaylist;
588  qNotifyDebug() << "on_buttonTestSoundNotification_clicked";
589  Q_ASSERT(-1 != _notifyRulesSelection->currentIndex().row());
590  _testSound->stop();
591  notification = _privListNotifications.at(_notifyRulesSelection->currentIndex().row());
592  QStringList sequence = notification->toSoundList();
593  if (sequence.isEmpty()) {
594  qNotifyDebug() << "message sequense is empty!";
595  return;
596  }
597  foreach (QString item, sequence) {
598  qNotifyDebug() << item;
599  playlist->addMedia(QUrl::fromLocalFile(item));
600  }
601  _testSound->setPlaylist(playlist);
602  _testSound->play();
603 }
604 
605 void NotifyPluginOptionsPage::on_clicked_buttonAddNotification()
606 {
607  NotificationItem *notification = new NotificationItem;
608 
609  if (_optionsPage->SoundDirectoryPathChooser->path().isEmpty()) {
610  QPalette textPalette = _optionsPage->SoundDirectoryPathChooser->palette();
611  textPalette.setColor(QPalette::Normal, QPalette::Text, Qt::red);
612  _optionsPage->SoundDirectoryPathChooser->setPalette(textPalette);
613  _optionsPage->SoundDirectoryPathChooser->setPath("please select sound collection folder");
614  delete notification;
615  return;
616  }
617  getOptionsPageValues(notification);
618 
619  if (((!_optionsPage->Sound2->currentText().isEmpty())
620  && (_sayOrder->currentText() == "After second"))
621  || ((!_optionsPage->Sound3->currentText().isEmpty())
622  && (_sayOrder->currentText() == "After third"))) {
623  delete notification;
624  return;
625  } else {
626  notification->setSayOrder(_sayOrder->currentIndex());
627  }
628 
629  _notifyRulesModel->entryAdded(notification);
630  _notifyRulesSelection->setCurrentIndex(
631  _notifyRulesModel->index(_privListNotifications.size() - 1, 0, QModelIndex()),
632  QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
633 }
634 
635 void NotifyPluginOptionsPage::on_clicked_buttonDeleteNotification()
636 {
637  _notifyRulesModel->removeRow(_notifyRulesSelection->currentIndex().row());
638  if (!_notifyRulesModel->rowCount()
639  && (_notifyRulesSelection->currentIndex().row() > 0
640  && _notifyRulesSelection->currentIndex().row() < _notifyRulesModel->rowCount())) {
641  _optionsPage->buttonDelete->setEnabled(false);
642  _optionsPage->buttonModify->setEnabled(false);
643  _optionsPage->buttonPlayNotification->setEnabled(false);
644  }
645 }
646 
647 void NotifyPluginOptionsPage::on_clicked_buttonModifyNotification()
648 {
649  NotificationItem *notification = new NotificationItem;
650  getOptionsPageValues(notification);
651  notification->setRetryValue(
652  _privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryValue());
653  notification->setLifetime(
654  _privListNotifications.at(_notifyRulesSelection->currentIndex().row())->lifetime());
655  notification->setMute(
656  _privListNotifications.at(_notifyRulesSelection->currentIndex().row())->mute());
657 
658  _privListNotifications.replace(_notifyRulesSelection->currentIndex().row(), notification);
659  entryUpdated(_notifyRulesSelection->currentIndex().row());
660 }
661 
662 void NotifyPluginOptionsPage::on_FinishedPlaying()
663 {
664  _testSound->stop();
665 }
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
void changed(const QString &text)
void setMute(bool value)
static QStringList conditionValues
QString getCurrentLanguage() const
int getSayOrder() const
Notify Plugin options page header.
int getCondition() const
void setSayOrder(int text)
QDebug qNotifyDebug()
QStringList getOptions() const
void setDataObject(QString text)
static QStringList sayOrderValues
void updateNotificationList(QList< NotificationItem * > list)
UAVObjectField * getField(const QString &name)
Definition: uavobject.cpp:236
void setSoundCollectionPath(QString path)
QString getSoundCollectionPath() const
NotifyPluginOptionsPage(QObject *parent=nullptr)
double valueRange2() const
QString getName() const
QList< UAVObjectField * > getFields()
Definition: uavobject.cpp:196
QWidget * createPage(QWidget *parent)
QString getDataObject() const
QString getName()
Definition: uavobject.cpp:131
void entryUpdated(int offset)
void setCurrentLanguage(QString text)
void setSingleValue(QVariant value)
void setCondition(int value)
UAVObject * getObject(const QString &name, quint32 instId=0)
void updateNotifications(QList< NotificationItem * > list)
QVector< QVector< UAVDataObject * > > getDataObjectsVector()
void setLifetime(int value)
void entryUpdated(int index)
static QString InsertDataPath(QString path)
Definition: pathutils.cpp:84
void setRetryValue(int value)
void setValueRange2(double value)
FieldType getType() const