2 ******************************************************************************
4 * @file notifypluginoptionspage.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief Notify Plugin options page
7 * @see The GNU Public License (GPL) Version 3
8 * @defgroup notifyplugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "notifypluginoptionspage.h"
29 #include <coreplugin/icore.h>
30 #include "notificationitem.h"
31 #include "ui_notifypluginoptionspage.h"
32 #include "extensionsystem/pluginmanager.h"
33 #include "utils/pathutils.h"
35 #include <QFileDialog>
36 #include <QtAlgorithms>
37 #include <QStringList>
38 #include <QtCore/QSettings>
39 #include <QTableWidget>
44 #include <QMediaPlaylist>
46 #include "notifyplugin.h"
47 #include "notifyitemdelegate.h"
48 #include "notifytablemodel.h"
49 #include "notifylogging.h"
51 QStringList
NotifyPluginOptionsPage::conditionValues
;
53 NotifyPluginOptionsPage::NotifyPluginOptionsPage(QObject
*parent
)
54 : IOptionsPage(parent
)
55 , _objManager(*ExtensionSystem::PluginManager::instance()->getObject
<UAVObjectManager
>())
56 , _owner(qobject_cast
<SoundNotifyPlugin
*>(parent
))
57 , _dynamicFieldCondition(NULL
)
58 , _dynamicFieldWidget(NULL
)
59 , _dynamicFieldType(-1)
62 , _selectedNotification(NULL
)
64 NotifyPluginOptionsPage::conditionValues
.insert(equal
, tr("Equal to"));
65 NotifyPluginOptionsPage::conditionValues
.insert(bigger
, tr("Large than"));
66 NotifyPluginOptionsPage::conditionValues
.insert(smaller
, tr("Lower than"));
67 NotifyPluginOptionsPage::conditionValues
.insert(inrange
, tr("In range"));
70 NotifyPluginOptionsPage::~NotifyPluginOptionsPage()
73 QWidget
*NotifyPluginOptionsPage::createPage(QWidget
* /* parent */)
75 _optionsPage
.reset(new Ui::NotifyPluginOptionsPage());
77 QWidget
*optionsPageWidget
= new QWidget
;
78 _dynamicFieldWidget
= NULL
;
79 _dynamicFieldCondition
= NULL
;
81 // save ref to form, needed for binding dynamic fields in future
82 _form
= optionsPageWidget
;
84 _optionsPage
->setupUi(optionsPageWidget
);
86 _optionsPage
->SoundDirectoryPathChooser
->setExpectedKind(Utils::PathChooser::Directory
);
87 _optionsPage
->SoundDirectoryPathChooser
->setPromptDialogTitle(tr("Choose sound collection directory"));
89 connect(_optionsPage
->SoundDirectoryPathChooser
, SIGNAL(changed(const QString
&)),
90 this, SLOT(on_clicked_buttonSoundFolder(const QString
&)));
91 connect(_optionsPage
->SoundCollectionList
, SIGNAL(currentIndexChanged(int)),
92 this, SLOT(on_changedIndex_soundLanguage(int)));
94 connect(this, SIGNAL(updateNotifications(QList
<NotificationItem
*>)),
95 _owner
, SLOT(updateNotificationList(QList
<NotificationItem
*>)));
96 // connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification()));
98 _privListNotifications
= _owner
->getListNotifications();
102 setSelectedNotification(_owner
->getCurrentNotification());
103 addDynamicFieldLayout();
105 updateConfigView(_selectedNotification
);
111 int curr_row
= _privListNotifications
.indexOf(_selectedNotification
);
112 _notifyRulesSelection
->setCurrentIndex(_notifyRulesModel
->index(curr_row
, 0, QModelIndex()),
113 QItemSelectionModel::ClearAndSelect
| QItemSelectionModel::Rows
);
115 return optionsPageWidget
;
118 void NotifyPluginOptionsPage::apply()
120 getOptionsPageValues(_owner
->getCurrentNotification());
121 _owner
->setEnableSound(_optionsPage
->chkEnableSound
->isChecked());
122 emit
updateNotifications(_privListNotifications
);
125 void NotifyPluginOptionsPage::finish()
127 disconnect(_optionsPage
->UAVObjectField
, SIGNAL(currentIndexChanged(QString
)),
128 this, SLOT(on_changedIndex_UAVField(QString
)));
130 disconnect(_testSound
, SIGNAL(stateChanged(QMediaPlayer::State
)),
131 this, SLOT(on_changed_playButtonText(QMediaPlayer::State
)));
134 // _testSound->clear();
138 void NotifyPluginOptionsPage::initButtons()
140 _optionsPage
->chkEnableSound
->setChecked(_owner
->getEnableSound());
141 connect(_optionsPage
->chkEnableSound
, SIGNAL(toggled(bool)),
142 this, SLOT(on_toggled_checkEnableSound(bool)));
144 _optionsPage
->buttonModify
->setEnabled(false);
145 _optionsPage
->buttonDelete
->setEnabled(false);
146 _optionsPage
->buttonPlayNotification
->setEnabled(false);
147 connect(_optionsPage
->buttonAdd
, SIGNAL(pressed()),
148 this, SLOT(on_clicked_buttonAddNotification()));
149 connect(_optionsPage
->buttonDelete
, SIGNAL(pressed()),
150 this, SLOT(on_clicked_buttonDeleteNotification()));
151 connect(_optionsPage
->buttonModify
, SIGNAL(pressed()),
152 this, SLOT(on_clicked_buttonModifyNotification()));
153 connect(_optionsPage
->buttonPlayNotification
, SIGNAL(clicked()),
154 this, SLOT(on_clicked_buttonTestSoundNotification()));
157 void NotifyPluginOptionsPage::initPhononPlayer()
159 _testSound
= new QMediaPlayer
;
160 // _testSound.reset(Phonon::createPlayer(Phonon::NotificationCategory));
161 connect(_testSound
, SIGNAL(stateChanged(QMediaPlayer::State
)),
162 this, SLOT(on_changed_playButtonText(QMediaPlayer::State
)));
163 // connect(_testSound, SIGNAL(finished(void)), this, SLOT(on_FinishedPlaying(void)));
166 void NotifyPluginOptionsPage::initRulesTable()
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());
173 connect(_notifyRulesSelection
, SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
174 this, SLOT(on_changedSelection_notifyTable(const QItemSelection
&, const QItemSelection
&)));
175 connect(this, SIGNAL(entryUpdated(int)),
176 _notifyRulesModel
.data(), SLOT(entryUpdated(int)));
178 _optionsPage
->notifyRulesView
->setModel(_notifyRulesModel
.data());
179 _optionsPage
->notifyRulesView
->setSelectionModel(_notifyRulesSelection
);
180 _optionsPage
->notifyRulesView
->setItemDelegate(new NotifyItemDelegate(this));
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
);
193 UAVObjectField
*NotifyPluginOptionsPage::getObjectFieldFromSelected()
195 return (_currUAVObject
) ? _currUAVObject
->getField(_selectedNotification
->getObjectField()) : NULL
;
198 void NotifyPluginOptionsPage::setSelectedNotification(NotificationItem
*ntf
)
200 _selectedNotification
= ntf
;
201 _currUAVObject
= dynamic_cast<UAVDataObject
*>(_objManager
.getObject(_selectedNotification
->getDataObject()));
202 if (!_currUAVObject
) {
203 qNotifyDebug() << "no such UAVObject: " << _selectedNotification
->getDataObject();
207 void NotifyPluginOptionsPage::addDynamicFieldLayout()
209 // there is no need to check (objField == NULL),
210 // thus it doesn't use in this field directly
212 QSizePolicy
labelSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
214 labelSizePolicy
.setHorizontalStretch(0);
215 labelSizePolicy
.setVerticalStretch(0);
216 // labelSizePolicy.setHeightForWidth(UAVObject->sizePolicy().hasHeightForWidth());
219 QLabel
*labelSayOrder
= new QLabel("Say order ", _form
);
220 labelSayOrder
->setSizePolicy(labelSizePolicy
);
222 _optionsPage
->dynamicValueLayout
->addWidget(labelSayOrder
);
223 _sayOrder
= new QComboBox(_form
);
224 _optionsPage
->dynamicValueLayout
->addWidget(_sayOrder
);
225 _sayOrder
->addItems(NotificationItem::sayOrderValues
);
227 QLabel
*labelValueIs
= new QLabel("Value is ", _form
);
228 labelValueIs
->setSizePolicy(labelSizePolicy
);
229 _optionsPage
->dynamicValueLayout
->addWidget(labelValueIs
);
231 _dynamicFieldCondition
= new QComboBox(_form
);
232 _optionsPage
->dynamicValueLayout
->addWidget(_dynamicFieldCondition
);
233 UAVObjectField
*field
= getObjectFieldFromSelected();
234 addDynamicField(field
);
237 void NotifyPluginOptionsPage::addDynamicField(UAVObjectField
*objField
)
240 qNotifyDebug() << "addDynamicField | input objField == NULL";
243 if (objField
->getType() == _dynamicFieldType
) {
244 if (QComboBox
* fieldValue
= dynamic_cast<QComboBox
*>(_dynamicFieldWidget
)) {
246 QStringList
enumValues(objField
->getOptions());
247 fieldValue
->addItems(enumValues
);
252 disconnect(_dynamicFieldCondition
, SIGNAL(currentIndexChanged(QString
)),
253 this, SLOT(on_changedIndex_rangeValue(QString
)));
255 _dynamicFieldCondition
->clear();
256 _dynamicFieldCondition
->addItems(NotifyPluginOptionsPage::conditionValues
);
257 if (UAVObjectField::ENUM
== objField
->getType()) {
258 _dynamicFieldCondition
->removeItem(smaller
);
259 _dynamicFieldCondition
->removeItem(bigger
);
261 int cond
= _selectedNotification
->getCondition();
265 _dynamicFieldCondition
->setCurrentIndex(_dynamicFieldCondition
->findText(NotifyPluginOptionsPage::conditionValues
.at(cond
)));
267 connect(_dynamicFieldCondition
, SIGNAL(currentIndexChanged(QString
)),
268 this, SLOT(on_changedIndex_rangeValue(QString
)));
270 addDynamicFieldWidget(objField
);
273 void NotifyPluginOptionsPage::addDynamicFieldWidget(UAVObjectField
*objField
)
276 qNotifyDebug() << "objField == NULL!";
279 // check if dynamic fileld already settled,
280 // so if its exists remove it and install new field
281 if (_dynamicFieldWidget
) {
282 _optionsPage
->dynamicValueLayout
->removeWidget(_dynamicFieldWidget
);
283 delete _dynamicFieldWidget
;
284 _dynamicFieldWidget
= NULL
;
287 QSizePolicy
sizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
288 sizePolicy
.setHorizontalStretch(0);
289 sizePolicy
.setVerticalStretch(0);
291 _dynamicFieldType
= objField
->getType();
292 switch (_dynamicFieldType
) {
293 case UAVObjectField::ENUM
:
295 _dynamicFieldWidget
= new QComboBox(_form
);
296 QStringList
enumValues(objField
->getOptions());
297 (dynamic_cast<QComboBox
*>(_dynamicFieldWidget
))->addItems(enumValues
);
302 Q_ASSERT(_dynamicFieldCondition
);
303 if (NotifyPluginOptionsPage::conditionValues
.indexOf(_dynamicFieldCondition
->currentText()) == NotifyPluginOptionsPage::inrange
) {
304 _dynamicFieldWidget
= new QLineEdit(_form
);
306 (static_cast<QLineEdit
*>(_dynamicFieldWidget
))->setInputMask("#99999.99 : #99999.99;");
307 (static_cast<QLineEdit
*>(_dynamicFieldWidget
))->setText("0000000000");
308 (static_cast<QLineEdit
*>(_dynamicFieldWidget
))->setCursorPosition(0);
310 _dynamicFieldWidget
= new QDoubleSpinBox(_form
);
311 (dynamic_cast<QDoubleSpinBox
*>(_dynamicFieldWidget
))->setRange(-99999.99, 99999.99);
316 enum { eDynamicFieldWidth
= 100 };
317 _dynamicFieldWidget
->setSizePolicy(sizePolicy
);
318 _dynamicFieldWidget
->setFixedWidth(eDynamicFieldWidth
);
319 _optionsPage
->dynamicValueLayout
->addWidget(_dynamicFieldWidget
);
322 void NotifyPluginOptionsPage::setDynamicFieldValue(NotificationItem
*notification
)
324 if (QDoubleSpinBox
* seValue
= dynamic_cast<QDoubleSpinBox
*>(_dynamicFieldWidget
)) {
325 seValue
->setValue(notification
->singleValue().toDouble());
327 if (QComboBox
* cbValue
= dynamic_cast<QComboBox
*>(_dynamicFieldWidget
)) {
328 int idx
= cbValue
->findText(notification
->singleValue().toString());
330 cbValue
->setCurrentIndex(idx
);
333 if (QLineEdit
* rangeValue
= dynamic_cast<QLineEdit
*>(_dynamicFieldWidget
)) {
334 QString str
= QString("%1%2").arg(notification
->singleValue().toDouble(), 5, 'f', 2, '0')
335 .arg(notification
->valueRange2(), 5, 'f', 2, '0');
336 rangeValue
->setText(str
);
338 qNotifyDebug() << "NotifyPluginOptionsPage::setDynamicValueField | unknown _fieldValue: " << _dynamicFieldWidget
;
344 void NotifyPluginOptionsPage::resetFieldType()
346 _dynamicFieldType
= -1;
349 void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem
*notification
)
351 Q_ASSERT(notification
);
352 notification
->setSoundCollectionPath(_optionsPage
->SoundDirectoryPathChooser
->path());
353 notification
->setCurrentLanguage(_optionsPage
->SoundCollectionList
->currentText());
354 notification
->setDataObject(_optionsPage
->UAVObject
->currentText());
355 notification
->setObjectField(_optionsPage
->UAVObjectField
->currentText());
356 notification
->setSound1(_optionsPage
->Sound1
->currentText());
357 notification
->setSound2(_optionsPage
->Sound2
->currentText());
358 notification
->setSound3(_optionsPage
->Sound3
->currentText());
359 notification
->setSayOrder(_sayOrder
->currentIndex());
360 notification
->setCondition(NotifyPluginOptionsPage::conditionValues
.indexOf(_dynamicFieldCondition
->currentText()));
361 if (QDoubleSpinBox
* spinValue
= dynamic_cast<QDoubleSpinBox
*>(_dynamicFieldWidget
)) {
362 notification
->setSingleValue(spinValue
->value());
364 if (QComboBox
* comboBoxValue
= dynamic_cast<QComboBox
*>(_dynamicFieldWidget
)) {
365 notification
->setSingleValue(comboBoxValue
->currentText());
367 if (QLineEdit
* rangeValue
= dynamic_cast<QLineEdit
*>(_dynamicFieldWidget
)) {
368 QString str
= rangeValue
->text();
369 QStringList range
= str
.split(':');
370 notification
->setSingleValue(range
.at(0).toDouble());
371 notification
->setValueRange2(range
.at(1).toDouble());
377 void NotifyPluginOptionsPage::updateConfigView(NotificationItem
*notification
)
379 Q_ASSERT(notification
);
380 disconnect(_optionsPage
->UAVObject
, SIGNAL(currentIndexChanged(QString
)),
381 this, SLOT(on_changedIndex_UAVObject(QString
)));
382 disconnect(_optionsPage
->UAVObjectField
, SIGNAL(currentIndexChanged(QString
)),
383 this, SLOT(on_changedIndex_UAVField(QString
)));
385 QString path
= notification
->getSoundCollectionPath();
386 if (path
.isEmpty()) {
387 path
= Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds");
390 _optionsPage
->SoundDirectoryPathChooser
->setPath(path
);
392 if (-1 != _optionsPage
->SoundCollectionList
->findText(notification
->getCurrentLanguage())) {
393 _optionsPage
->SoundCollectionList
->setCurrentIndex(_optionsPage
->SoundCollectionList
->findText(notification
->getCurrentLanguage()));
395 _optionsPage
->SoundCollectionList
->setCurrentIndex(_optionsPage
->SoundCollectionList
->findText("default"));
398 // Fills the combo boxes for the UAVObjects
399 QList
< QList
<UAVDataObject
*> > objList
= _objManager
.getDataObjects();
400 foreach(QList
<UAVDataObject
*> list
, objList
) {
401 foreach(UAVDataObject
* obj
, list
) {
402 _optionsPage
->UAVObject
->addItem(obj
->getName());
406 if (-1 != _optionsPage
->UAVObject
->findText(notification
->getDataObject())) {
407 _optionsPage
->UAVObject
->setCurrentIndex(_optionsPage
->UAVObject
->findText(notification
->getDataObject()));
410 _optionsPage
->UAVObjectField
->clear();
411 if (_currUAVObject
) {
412 QList
<UAVObjectField
*> fieldList
= _currUAVObject
->getFields();
413 foreach(UAVObjectField
* field
, fieldList
)
414 _optionsPage
->UAVObjectField
->addItem(field
->getName());
417 if (-1 != _optionsPage
->UAVObjectField
->findText(notification
->getObjectField())) {
418 _optionsPage
->UAVObjectField
->setCurrentIndex(_optionsPage
->UAVObjectField
->findText(notification
->getObjectField()));
421 if (-1 != _optionsPage
->Sound1
->findText(notification
->getSound1())) {
422 _optionsPage
->Sound1
->setCurrentIndex(_optionsPage
->Sound1
->findText(notification
->getSound1()));
424 // show item from default location
425 _optionsPage
->SoundCollectionList
->setCurrentIndex(_optionsPage
->SoundCollectionList
->findText("default"));
426 _optionsPage
->Sound1
->setCurrentIndex(_optionsPage
->Sound1
->findText(notification
->getSound1()));
429 if (-1 != _optionsPage
->Sound2
->findText(notification
->getSound2())) {
430 _optionsPage
->Sound2
->setCurrentIndex(_optionsPage
->Sound2
->findText(notification
->getSound2()));
432 // show item from default location
433 _optionsPage
->SoundCollectionList
->setCurrentIndex(_optionsPage
->SoundCollectionList
->findText("default"));
434 _optionsPage
->Sound2
->setCurrentIndex(_optionsPage
->Sound2
->findText(notification
->getSound2()));
437 if (-1 != _optionsPage
->Sound3
->findText(notification
->getSound3())) {
438 _optionsPage
->Sound3
->setCurrentIndex(_optionsPage
->Sound3
->findText(notification
->getSound3()));
440 // show item from default location
441 _optionsPage
->SoundCollectionList
->setCurrentIndex(_optionsPage
->SoundCollectionList
->findText("default"));
442 _optionsPage
->Sound3
->setCurrentIndex(_optionsPage
->Sound3
->findText(notification
->getSound3()));
444 int cond
= notification
->getCondition();
448 _dynamicFieldCondition
->setCurrentIndex(_dynamicFieldCondition
->findText(NotifyPluginOptionsPage::conditionValues
.at(cond
)));
450 _sayOrder
->setCurrentIndex(notification
->getSayOrder());
452 setDynamicFieldValue(notification
);
454 connect(_optionsPage
->UAVObject
, SIGNAL(currentIndexChanged(QString
)),
455 this, SLOT(on_changedIndex_UAVObject(QString
)));
456 connect(_optionsPage
->UAVObjectField
, SIGNAL(currentIndexChanged(QString
)),
457 this, SLOT(on_changedIndex_UAVField(QString
)));
460 void NotifyPluginOptionsPage::on_changedIndex_rangeValue(QString
/* rangeStr */)
462 Q_ASSERT(_dynamicFieldWidget
);
463 UAVObjectField
*field
= getObjectFieldFromSelected();
465 addDynamicFieldWidget(field
);
466 setDynamicFieldValue(_selectedNotification
);
469 void NotifyPluginOptionsPage::on_changedIndex_UAVField(QString field
)
472 Q_ASSERT(_currUAVObject
);
473 addDynamicField(_currUAVObject
->getField(field
));
476 void NotifyPluginOptionsPage::on_changedIndex_UAVObject(QString val
)
479 _currUAVObject
= dynamic_cast<UAVDataObject
*>(_objManager
.getObject(val
));
480 if (!_currUAVObject
) {
481 qNotifyDebug() << "on_UAVObject_indexChanged | no such UAVOBject";
484 QList
<UAVObjectField
*> fieldList
= _currUAVObject
->getFields();
485 disconnect(_optionsPage
->UAVObjectField
, SIGNAL(currentIndexChanged(QString
)), this, SLOT(on_changedIndex_UAVField(QString
)));
486 _optionsPage
->UAVObjectField
->clear();
487 foreach(UAVObjectField
* field
, fieldList
) {
488 _optionsPage
->UAVObjectField
->addItem(field
->getName());
490 connect(_optionsPage
->UAVObjectField
, SIGNAL(currentIndexChanged(QString
)), this, SLOT(on_changedIndex_UAVField(QString
)));
491 _selectedNotification
->setObjectField(fieldList
.at(0)->getName());
492 addDynamicField(fieldList
.at(0));
496 void NotifyPluginOptionsPage::on_changedIndex_soundLanguage(int index
)
498 _optionsPage
->SoundCollectionList
->setCurrentIndex(index
);
499 QString collectionPath
= _optionsPage
->SoundDirectoryPathChooser
->path()
500 + QDir::toNativeSeparators("/" + _optionsPage
->SoundCollectionList
->currentText());
502 QDir
dirPath(collectionPath
);
504 filters
<< "*.mp3" << "*.wav";
505 dirPath
.setNameFilters(filters
);
506 QStringList listSoundFiles
= dirPath
.entryList(filters
);
507 listSoundFiles
.replaceInStrings(QRegExp(".mp3|.wav"), "");
508 _optionsPage
->Sound1
->clear();
509 _optionsPage
->Sound2
->clear();
510 _optionsPage
->Sound3
->clear();
511 _optionsPage
->Sound1
->addItem("");
512 _optionsPage
->Sound1
->addItems(listSoundFiles
);
513 _optionsPage
->Sound2
->addItem("");
514 _optionsPage
->Sound2
->addItems(listSoundFiles
);
515 _optionsPage
->Sound3
->addItem("");
516 _optionsPage
->Sound3
->addItems(listSoundFiles
);
520 void NotifyPluginOptionsPage::on_changed_playButtonText(QMediaPlayer::State newstate
)
522 // Q_ASSERT(Phonon::ErrorState != newstate);
524 if (newstate
== QMediaPlayer::PausedState
|| newstate
== QMediaPlayer::StoppedState
) {
525 _optionsPage
->buttonPlayNotification
->setText("Play");
526 _optionsPage
->buttonPlayNotification
->setIcon(QPixmap(":/notify/images/play.png"));
528 if (newstate
== QMediaPlayer::PlayingState
) {
529 _optionsPage
->buttonPlayNotification
->setText("Stop");
530 _optionsPage
->buttonPlayNotification
->setIcon(QPixmap(":/notify/images/stop.png"));
535 void NotifyPluginOptionsPage::on_changedSelection_notifyTable(const QItemSelection
& selected
, const QItemSelection
& /* deselected */)
540 if (selected
.indexes().size()) {
542 setSelectedNotification(_privListNotifications
.at(selected
.indexes().at(0).row()));
543 UAVObjectField
*field
= getObjectFieldFromSelected();
544 addDynamicField(field
);
545 updateConfigView(_selectedNotification
);
548 _optionsPage
->buttonModify
->setEnabled(select
);
549 _optionsPage
->buttonDelete
->setEnabled(select
);
550 _optionsPage
->buttonPlayNotification
->setEnabled(select
);
553 void NotifyPluginOptionsPage::on_clicked_buttonSoundFolder(const QString
& path
)
556 QStringList listDirCollections
= dirPath
.entryList(QDir::AllDirs
| QDir::NoDotAndDotDot
);
558 _optionsPage
->SoundCollectionList
->clear();
559 _optionsPage
->SoundCollectionList
->addItems(listDirCollections
);
562 void NotifyPluginOptionsPage::on_clicked_buttonTestSoundNotification()
564 NotificationItem
*notification
= NULL
;
566 playlist
= new QMediaPlaylist
;
567 qNotifyDebug() << "on_buttonTestSoundNotification_clicked";
568 Q_ASSERT(-1 != _notifyRulesSelection
->currentIndex().row());
570 notification
= _privListNotifications
.at(_notifyRulesSelection
->currentIndex().row());
571 QStringList sequence
= notification
->toSoundList();
572 if (sequence
.isEmpty()) {
573 qNotifyDebug() << "message sequense is empty!";
576 foreach(QString item
, sequence
) {
577 qNotifyDebug() << item
;
578 playlist
->addMedia(QUrl::fromLocalFile(item
));
580 _testSound
->setPlaylist(playlist
);
584 void NotifyPluginOptionsPage::on_clicked_buttonAddNotification()
586 NotificationItem
*notification
= new NotificationItem
;
588 if (_optionsPage
->SoundDirectoryPathChooser
->path().isEmpty()) {
589 QPalette textPalette
= _optionsPage
->SoundDirectoryPathChooser
->palette();
590 textPalette
.setColor(QPalette::Normal
, QPalette::Text
, Qt::red
);
591 _optionsPage
->SoundDirectoryPathChooser
->setPalette(textPalette
);
592 _optionsPage
->SoundDirectoryPathChooser
->setPath("please select sound collection folder");
596 getOptionsPageValues(notification
);
598 if (((!_optionsPage
->Sound2
->currentText().isEmpty()) && (_sayOrder
->currentText() == "After second"))
599 || ((!_optionsPage
->Sound3
->currentText().isEmpty()) && (_sayOrder
->currentText() == "After third"))) {
603 notification
->setSayOrder(_sayOrder
->currentIndex());
606 _notifyRulesModel
->entryAdded(notification
);
607 _notifyRulesSelection
->setCurrentIndex(_notifyRulesModel
->index(_privListNotifications
.size() - 1, 0, QModelIndex()),
608 QItemSelectionModel::ClearAndSelect
| QItemSelectionModel::Rows
);
611 void NotifyPluginOptionsPage::on_clicked_buttonDeleteNotification()
613 _notifyRulesModel
->removeRow(_notifyRulesSelection
->currentIndex().row());
614 if (!_notifyRulesModel
->rowCount()
615 && (_notifyRulesSelection
->currentIndex().row() > 0
616 && _notifyRulesSelection
->currentIndex().row() < _notifyRulesModel
->rowCount())) {
617 _optionsPage
->buttonDelete
->setEnabled(false);
618 _optionsPage
->buttonModify
->setEnabled(false);
619 _optionsPage
->buttonPlayNotification
->setEnabled(false);
623 void NotifyPluginOptionsPage::on_clicked_buttonModifyNotification()
625 NotificationItem
*notification
= new NotificationItem
;
627 getOptionsPageValues(notification
);
628 notification
->setRetryValue(_privListNotifications
.at(_notifyRulesSelection
->currentIndex().row())->retryValue());
629 notification
->setLifetime(_privListNotifications
.at(_notifyRulesSelection
->currentIndex().row())->lifetime());
630 notification
->setMute(_privListNotifications
.at(_notifyRulesSelection
->currentIndex().row())->mute());
632 _privListNotifications
.replace(_notifyRulesSelection
->currentIndex().row(), notification
);
633 entryUpdated(_notifyRulesSelection
->currentIndex().row());
636 void NotifyPluginOptionsPage::on_FinishedPlaying()
641 void NotifyPluginOptionsPage::on_toggled_checkEnableSound(bool state
)
644 // bool state1 = 1 ^ state;
646 // QList<Phonon::Path> listOutputs = _testSound->outputPaths();
647 // Phonon::AudioOutput *audioOutput = (Phonon::AudioOutput *)listOutputs.last().sink();
648 // _testSound->setMuted(state1);