From 3af398d7f9d62f5c78a350afe5d1f8e69f1eea41 Mon Sep 17 00:00:00 2001 From: Nickolay Date: Thu, 15 Sep 2011 00:38:18 +0300 Subject: [PATCH 1/9] initial changes --- ground/ground.pro.user.2.1pre1 | 311 ++++++++++++++++++ .../internals/projections/lks94projection.h | 2 +- .../src/plugins/notify/NotificationItem.h | 154 +++++++++ .../src/plugins/notify/notify.pro | 4 +- .../src/plugins/notify/notifyitemdelegate.cpp | 225 +++++++------ .../src/plugins/notify/notifyitemdelegate.h | 28 +- .../src/plugins/notify/notifyplugin.cpp | 137 ++++---- .../src/plugins/notify/notifyplugin.h | 34 +- .../notify/notifypluginconfiguration.cpp | 118 ++++--- .../notify/notifypluginconfiguration.h | 122 ------- .../notify/notifypluginoptionspage.cpp | 210 +++++------- .../plugins/notify/notifypluginoptionspage.h | 21 +- .../plugins/notify/notifypluginoptionspage.ui | 18 +- .../src/plugins/notify/notifytablemodel.cpp | 47 +-- .../src/plugins/notify/notifytablemodel.h | 24 +- openpilotgcs.bat | 3 + 16 files changed, 865 insertions(+), 593 deletions(-) create mode 100644 ground/ground.pro.user.2.1pre1 create mode 100644 ground/openpilotgcs/src/plugins/notify/NotificationItem.h delete mode 100644 ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.h create mode 100644 openpilotgcs.bat diff --git a/ground/ground.pro.user.2.1pre1 b/ground/ground.pro.user.2.1pre1 new file mode 100644 index 000000000..0a2acf277 --- /dev/null +++ b/ground/ground.pro.user.2.1pre1 @@ -0,0 +1,311 @@ + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + System + + + + ProjectExplorer.Project.Target.0 + + Desktop + Qt4ProjectManager.Target.DesktopTarget + 0 + 0 + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + Qt in PATH Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + D:/!Work/OpenSource/OpenPilot/op/OpenPilot/ground-build + 2 + 2 + true + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + Qt in PATH Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + D:/!Work/OpenSource/OpenPilot/op/OpenPilot/ground-build + 2 + 2 + true + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + 4.6.2 Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + D:/!Work/OpenSource/OpenPilot/op/OpenPilot/ground-build + 13 + 2 + true + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + 4.6.2 Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + D:/!Work/OpenSource/OpenPilot/op/OpenPilot/ground-build + 13 + 2 + true + + 4 + + bin + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/bin/bin.pro + false + false + + false + false + + + + translations + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/share/openpilotgcs/translations/translations.pro + false + false + + false + false + + + + uavobjgenerator + Qt4ProjectManager.Qt4RunConfiguration + 2 + + uavobjgenerator/uavobjgenerator.pro + false + false + + false + false + + + + app + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/src/app/app.pro + false + false + + false + false + + + + berkeley + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/src/libs/libqxt/src/berkeley/berkeley.pro + false + false + + false + false + + + + designer + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/src/libs/libqxt/src/designer/designer.pro + false + false + + false + false + + + + gui + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/src/libs/libqxt/src/gui/gui.pro + false + false + + false + false + + + + network + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/src/libs/libqxt/src/network/network.pro + false + false + + false + false + + + + sql + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/src/libs/libqxt/src/sql/sql.pro + false + false + + false + false + + + + web + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/src/libs/libqxt/src/web/web.pro + false + false + + false + false + + + + zeroconf + Qt4ProjectManager.Qt4RunConfiguration + 2 + + openpilotgcs/src/libs/libqxt/src/zeroconf/zeroconf.pro + false + false + + false + false + + + 11 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 4 + + diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h index 4eee20aaa..dc895f04c 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h @@ -28,7 +28,7 @@ #define LKS94PROJECTION_H #include #include "cmath" -#include "../pureprojection.h" +#include "D:\!Work\OpenSource\OpenPilot\OpenPilot\ground\openpilotgcs\src\libs\opmapcontrol\src\internals\pureprojection.h" namespace projections { diff --git a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h new file mode 100644 index 000000000..c09e64982 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h @@ -0,0 +1,154 @@ +/** + ****************************************************************************** + * + * @file NotificationItem.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Notify Plugin configuration header + * @see The GNU Public License (GPL) Version 3 + * @defgroup notifyplugin + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef NOTIFICATION_ITEM_H +#define NOTIFICATION_ITEM_H + +#include +#include "qsettings.h" +#include +#include + +using namespace Core; + +#define DECLARE_SOUND(number) \ + QString getSound##number() const { return _sound##number; } \ + void setSound##number(QString text) { _sound##number = text; } \ + +// QString getSound2() const { return _sound2; } +// void setSound2(QString text) { _sound2 = text; } + +// QString getSound3() const { return _sound3; } +// void setSound3(QString text) { _sound3 = text; } + +class NotificationItem : public QObject +{ + Q_OBJECT +public: + explicit NotificationItem(QObject *parent = 0); + + void copyTo(NotificationItem*) const; + + DECLARE_SOUND(1) + DECLARE_SOUND(2) + DECLARE_SOUND(3) + + QString getValue() const { return _dataValue; } + void setValue(QString text) { _dataValue = text; } + + QString getSayOrder() const { return _sayOrder; } + void setSayOrder(QString text) { _sayOrder = text; } + + double getSpinBoxValue() const { return _spinBoxValue; } + void setSpinBoxValue(double value) { _spinBoxValue = value; } + + + QString getDataObject() const { return _dataObject; } + void setDataObject(QString text) { _dataObject = text; } + + QString getObjectField() const { return _objectField; } + void setObjectField(QString text) { _objectField = text; } + + QString getSoundCollectionPath() const { return _soundCollectionPath; } + void setSoundCollectionPath(QString path) { _soundCollectionPath = path; } + + QString getCurrentLanguage() const { return _currentLanguage; } + void setCurrentLanguage(QString text) { _currentLanguage = text; } + + QStringList getMessageSequence() const { return _messageSequence; } + void setMessageSequence(QStringList sequence) { _messageSequence = sequence; } + + QString getRepeatFlag() const { return _repeatString; } + void setRepeatFlag(QString value) { _repeatString = value; } + + bool getRepeatTimeout() const { return _repeatTimeout; } + void setRepeatTimeout(bool value) { _repeatTimeout = value; } + + int getExpireTimeout() const { return _expireTimeout; } + void setExpireTimeout(int value) { _expireTimeout = value; } + + bool getEnableFlag() const { return _enableFlag; } + void setEnableFlag(bool value) { _enableFlag = value; } + + void saveState(QSettings* settings) const; + void restoreState(QSettings* settings); + QString parseNotifyMessage(); + + QTimer* timer; + QTimer* expireTimer; + bool isNowPlaying; // + bool firstStart; + +private: + + QStringList _messageSequence; + + //! path to folder with sound files + QString _soundCollectionPath; + + //! language in what notifications will be spelled + QString _currentLanguage; + + //! one UAV object per one notification + QString _dataObject; + + //! one field value change can be assigned to one notification + QString _objectField; + + //! poled UAV field value + QString _dataValue; + + //! possible sounds(at least one required to play notification) + QString _sound1; + QString _sound2; + QString _sound3; + + //! order in what sounds 1-3 will be played + QString _sayOrder; + + double _spinBoxValue; + + QString _repeatString; + + //! time when next notification must be fired + bool _repeatTimeout; + + //! how often or what periodicaly notification should be played + int _repeatTimerValue; + + //! time after event occured till notification became invalid + //! and will be removed from list + int _expireTimeout; + + //! enables/disables playing of current notification + bool _enableFlag; +}; + +Q_DECLARE_METATYPE(NotificationItem*) + +#endif // NotificationItem_H diff --git a/ground/openpilotgcs/src/plugins/notify/notify.pro b/ground/openpilotgcs/src/plugins/notify/notify.pro index 9ebebfa22..e70392a6a 100644 --- a/ground/openpilotgcs/src/plugins/notify/notify.pro +++ b/ground/openpilotgcs/src/plugins/notify/notify.pro @@ -10,9 +10,9 @@ QT += phonon HEADERS += notifyplugin.h \ notifypluginoptionspage.h \ - notifypluginconfiguration.h \ notifyitemdelegate.h \ - notifytablemodel.h + notifytablemodel.h \ + NotificationItem.h SOURCES += notifyplugin.cpp \ notifypluginoptionspage.cpp \ diff --git a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp index 7a2fc2ef4..d6e5161fc 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp @@ -25,136 +25,135 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "notifyitemdelegate.h" #include +#include "notifyitemdelegate.h" +#include "notifytablemodel.h" - NotifyItemDelegate::NotifyItemDelegate(QStringList items,QObject *parent) - : QItemDelegate(parent), - m_parent(parent), - m_items(items) { +NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent) + : QItemDelegate(parent) + , _parent(parent) + , _items(items) +{ - } +} - QWidget *NotifyItemDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &, - const QModelIndex &index) const - { - if (index.column() == 1) { - QComboBox* editor = new QComboBox(parent); - editor->clear(); - editor->addItems(m_items); - //repeatEditor->setCurrentIndex(0); - //repeatEditor->setItemDelegate(new RepeatCounterDelegate()); - - //connect(repeatEditor,SIGNAL(activated (const QString& )),this,SLOT(selectRow(const QString& ))); - //QTableWidgetItem* item = qobject_cast(parent); - //((QTableWidgetItem*)parent)->setSelected(true); -// connect(editor, SIGNAL(editingFinished()), -// this, SLOT(commitAndCloseEditor())); - return editor; - } else - { - if(index.column() == 2) - { - QSpinBox* editor = new QSpinBox(parent); - connect(editor, SIGNAL(editingFinished()), - this, SLOT(commitAndCloseEditor())); - return editor; - } - - } - QLineEdit *editor = new QLineEdit(parent); -// connect(editor, SIGNAL(editingFinished()), -// this, SLOT(commitAndCloseEditor())); - return editor; - } - - void NotifyItemDelegate::commitAndCloseEditor() - { - QLineEdit *editor = qobject_cast(sender()); - if (editor) - { - emit commitData(editor); - emit closeEditor(editor); - - } else { - QComboBox* editor = qobject_cast(sender()); - if (editor) - { - emit commitData(editor); - emit closeEditor(editor); - } else { - QSpinBox* editor = qobject_cast(sender()); - if (editor) - { - emit commitData(editor); - emit closeEditor(editor); - } - } - } - } - - void NotifyItemDelegate::setEditorData(QWidget *editor, - const QModelIndex &index) const - { - QLineEdit *edit = qobject_cast(editor); - if (edit) { - edit->setText(index.model()->data(index, Qt::EditRole).toString()); - } else { - QComboBox * repeatEditor = qobject_cast(editor); - if (repeatEditor) - repeatEditor->setCurrentIndex(repeatEditor->findText(index.model()->data(index, Qt::EditRole).toString())); - else { - QSpinBox * expireEditor = qobject_cast(editor); - if (expireEditor) - expireEditor->setValue(index.model()->data(index, Qt::EditRole).toInt()); - } - } - } - - void NotifyItemDelegate::setModelData(QWidget *editor, - QAbstractItemModel *model, const QModelIndex &index) const - { - QLineEdit *edit = qobject_cast(editor); - if (edit) { - model->setData(index, edit->text()); - } else { - QComboBox * repeatEditor = qobject_cast(editor); - if (repeatEditor) { - model->setData(index, repeatEditor->currentText()); - - } else { - QSpinBox * expireEditor = qobject_cast(editor); - if (expireEditor) { - //expireEditor->interpretText(); - model->setData(index, expireEditor->value(), Qt::EditRole); +QWidget *NotifyItemDelegate::createEditor(QWidget* parent, + const QStyleOptionViewItem& /*none*/, + const QModelIndex& index) const +{ + if(eREPEAT_VALUE == index.column()) { + QComboBox* editor = new QComboBox(parent); + editor->clear(); + editor->addItems(_items); + return editor; + } else { + if(eEXPIRE_TIME == index.column()) { + QSpinBox* editor = new QSpinBox(parent); + connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); + return editor; + } else { + if(eENABLE_NOTIFICATION == index.column()) { + QCheckBox* editor = new QCheckBox(parent); + connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); + return editor; } - } - } - } + } + } + QLineEdit *editor = new QLineEdit(parent); + return editor; +} +void NotifyItemDelegate::commitAndCloseEditor() +{ + QLineEdit* editor = qobject_cast(sender()); + if (editor) { + emit commitData(editor); + emit closeEditor(editor); + } else { + QComboBox* editor = qobject_cast(sender()); + if (editor) + { + emit commitData(editor); + emit closeEditor(editor); + } else { + QSpinBox* editor = qobject_cast(sender()); + if (editor) + { + emit commitData(editor); + emit closeEditor(editor); + } else { + QCheckBox* editor = qobject_cast(sender()); + if (editor) + { + emit commitData(editor); + emit closeEditor(editor); + } + } + } + } +} + +void NotifyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + QLineEdit* edit = qobject_cast(editor); + if(edit) { + edit->setText(index.model()->data(index, Qt::EditRole).toString()); + } else { + QComboBox* repeatEditor = qobject_cast(editor); + if(repeatEditor) + repeatEditor->setCurrentIndex(repeatEditor->findText(index.model()->data(index, Qt::EditRole).toString())); + else { + QSpinBox* expireEditor = qobject_cast(editor); + if(expireEditor) + expireEditor->setValue(index.model()->data(index, Qt::EditRole).toInt()); + else { + QCheckBox* enablePlayEditor = qobject_cast(editor); + if (enablePlayEditor) + enablePlayEditor->setChecked(index.model()->data(index, Qt::EditRole).toBool()); + } + } + } +} + +void NotifyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + QLineEdit *edit = qobject_cast(editor); + if(edit) { + model->setData(index, edit->text()); + } else { + QComboBox * repeatEditor = qobject_cast(editor); + if(repeatEditor) { + model->setData(index, repeatEditor->currentText()); + } else { + QSpinBox * expireEditor = qobject_cast(editor); + if(expireEditor) { + model->setData(index, expireEditor->value(), Qt::EditRole); + } else { + QCheckBox* enablePlayEditor = qobject_cast(editor); + if (enablePlayEditor) { + model->setData(index, enablePlayEditor->isChecked(), Qt::EditRole); + } + } + } + } +} void NotifyItemDelegate::selectRow(const QString & text) { - //QList list = ((QTableWidget*)(sender()->parent()))->findItems(text,Qt::MatchExactly); QComboBox* combo = qobject_cast(sender()); QTableWidget* table = new QTableWidget; table = (QTableWidget*)(combo->parent()); - qDebug()<columnCount(); - qDebug()<rowCount(); - qDebug()<currentRow(); - //table->setCurrentIndex(1); - //table->findItems(text,Qt::MatchExactly); - //item->model()->index() - //item->setSelected(true); + + qDebug() << table->columnCount(); + qDebug() << table->rowCount(); + qDebug() << table->currentRow(); } -QSize NotifyItemDelegate::sizeHint ( const QStyleOptionViewItem & option, - const QModelIndex & index ) const +QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem & option, + const QModelIndex & index) const { QSize s = QItemDelegate::sizeHint(option, index); s.setHeight(10); - return s; } diff --git a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h index 40d6ced20..01fa0794d 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h @@ -31,21 +31,6 @@ #include #include -//class RepeatCounterDelegate : public QItemDelegate -//{ -// Q_OBJECT - -//public: -// RepeatCounterDelegate(QObject *parent = 0); -// QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, -// const QModelIndex &index) const; -// void setEditorData(QWidget *editor, const QModelIndex &index) const; -// void setModelData(QWidget *editor, QAbstractItemModel *model, -// const QModelIndex &index) const; - -//private slots: -// void commitAndCloseEditor(); -//}; class NotifyItemDelegate : public QItemDelegate { @@ -58,19 +43,16 @@ public: void setEditorData(QWidget *editor, const QModelIndex &index) const; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; -// bool editorEvent(QEvent * event, QAbstractItemModel * model, -// const QStyleOptionViewItem & option, const QModelIndex & index ); QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; -private: - QObject* m_parent; - QStringList m_items; - QComboBox* repeatEditor; - - private slots: void selectRow(const QString & text); void commitAndCloseEditor(); + +private: + QObject* _parent; + QStringList _items; + }; #endif // NOTIFYITEMDELEGATE_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp index 8735f8b60..c959925b4 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp @@ -26,7 +26,7 @@ */ #include "notifyplugin.h" -#include "notifypluginconfiguration.h" +#include "notificationitem.h" #include "notifypluginoptionspage.h" #include #include @@ -37,15 +37,29 @@ #include #include "qxttimer.h" +#include "backendcapabilities.h" static const QString VERSION = "1.0.0"; //#define DEBUG_NOTIFIES +#ifdef DEBUG_NOTIFIES +QDebug qNotifyDebug() +#endif +#ifndef DEBUG_NOTIFIES +QNoDebug qNotifyDebug() +#endif +{ +#ifdef DEBUG_NOTIFIES + return qDebug(); +#endif + return QNoDebug(); +} + SoundNotifyPlugin::SoundNotifyPlugin() { - phonon.mo = NULL; - configured = false; + phonon.mo = NULL; + configured = false; // Do nothing } @@ -121,7 +135,7 @@ void SoundNotifyPlugin::readConfig( QSettings* settings, UAVConfigInfo *configIn int size = settings->beginReadArray("listNotifies"); for (int i = 0; i < size; ++i) { settings->setArrayIndex(i); - NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; + NotificationItem* notification = new NotificationItem; notification->restoreState(settings); lstNotifications.append(notification); } @@ -145,7 +159,7 @@ void SoundNotifyPlugin::readConfig_0_0_0(){ int size = settings->beginReadArray("listNotifies"); for (int i = 0; i < size; ++i) { settings->setArrayIndex(i); - NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; + NotificationItem* notification = new NotificationItem; notification->restoreState(settings); lstNotifications.append(notification); } @@ -185,7 +199,7 @@ void SoundNotifyPlugin::onAutopilotDisconnect() void SoundNotifyPlugin::resetNotification(void) { //first, reject empty args and unknown fields. - foreach(NotifyPluginConfiguration* notify,lstNotifications) { + foreach(NotificationItem* notify,lstNotifications) { if(notify->timer) { disconnect(notify->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); @@ -207,7 +221,7 @@ void SoundNotifyPlugin::resetNotification(void) update list of notifies; will be perform on OK or APPLY press of option page */ -void SoundNotifyPlugin::updateNotificationList(QList list) +void SoundNotifyPlugin::updateNotificationList(QList list) { removedNotifies.clear(); resetNotification(); @@ -224,10 +238,10 @@ void SoundNotifyPlugin::connectNotifications() if (obj != NULL) disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(appendNotification(UAVObject*))); } - if(phonon.mo != NULL) { - delete phonon.mo; - phonon.mo = NULL; - } + if(phonon.mo != NULL) { + delete phonon.mo; + phonon.mo = NULL; + } if(!enableSound) return; @@ -240,25 +254,10 @@ void SoundNotifyPlugin::connectNotifications() removedNotifies.clear(); //first, reject empty args and unknown fields. - foreach(NotifyPluginConfiguration* notify,lstNotifications) { + foreach(NotificationItem* notify, lstNotifications) { notify->firstStart=true; notify->isNowPlaying=false; -// if(notify->timer) -// { -// disconnect(notify->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); -// notify->timer->stop(); -// delete notify->timer; -// notify->timer = NULL; -// } -// if(notify->expireTimer) -// { -// disconnect(notify->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler())); -// notify->expireTimer->stop(); -// delete notify->expireTimer; -// notify->expireTimer = NULL; -// } - UAVDataObject* obj = dynamic_cast( objManager->getObject(notify->getDataObject()) ); if (obj != NULL ) { if(!lstNotifiedUAVObjects.contains(obj)) { @@ -269,27 +268,25 @@ void SoundNotifyPlugin::connectNotifications() std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl; } - if(lstNotifications.isEmpty()) return; - // set notification message to current event - phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory); - phonon.mo->clearQueue(); - phonon.firstPlay = true; -#ifdef DEBUG_NOTIFIES - QList audioOutputDevices = - Phonon::BackendCapabilities::availableAudioOutputDevices(); - foreach(Phonon::AudioOutputDevice dev, audioOutputDevices) { - qDebug() << "Notify: Audio Output device: " << dev.name() << " - " << dev.description(); - } -#endif - connect(phonon.mo,SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(stateChanged(Phonon::State,Phonon::State))); + if(lstNotifications.isEmpty()) return; + // set notification message to current event + phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory); + phonon.mo->clearQueue(); + phonon.firstPlay = true; + QList audioOutputDevices = + Phonon::BackendCapabilities::availableAudioOutputDevices(); + foreach(Phonon::AudioOutputDevice dev, audioOutputDevices) { + qNotifyDebug() << "Notify: Audio Output device: " << dev.name() << " - " << dev.description(); + } + connect(phonon.mo, SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this, SLOT(stateChanged(Phonon::State,Phonon::State))); } void SoundNotifyPlugin::appendNotification(UAVObject *object) { disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); - foreach(NotifyPluginConfiguration* notification, lstNotifications) { + foreach(NotificationItem* notification, lstNotifications) { if(object->getName()!=notification->getDataObject()) continue; @@ -306,7 +303,7 @@ void SoundNotifyPlugin::appendNotification(UAVObject *object) } -void SoundNotifyPlugin::checkNotificationRule(NotifyPluginConfiguration* notification, UAVObject* object) +void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UAVObject* object) { bool condition=false; double threshold; @@ -350,7 +347,7 @@ void SoundNotifyPlugin::checkNotificationRule(NotifyPluginConfiguration* notific #endif // if audio is busy, start expiration timer //ms = (notification->getExpiredTimeout()[in sec])*1000 - //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotifyPluginConfiguration*)), qVariantFromValue(notification)); + //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); pendingNotifications.append(notification); if(!notification->expireTimer) { @@ -363,21 +360,22 @@ void SoundNotifyPlugin::checkNotificationRule(NotifyPluginConfiguration* notific } } -bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification) +bool SoundNotifyPlugin::playNotification(NotificationItem* notification) { // Check: race condition, if phonon.mo got deleted don't go further if (phonon.mo == NULL) return false; + if(!notification->getEnableFlag()) return true; + #ifdef DEBUG_NOTIFIES qDebug() << "Phonon State: " << phonon.mo->state(); #endif - if((phonon.mo->state()==Phonon::PausedState) || - (phonon.mo->state()==Phonon::StoppedState) || - phonon.firstPlay) + if((phonon.mo->state()==Phonon::PausedState) + || (phonon.mo->state()==Phonon::StoppedState) + || phonon.firstPlay) { // don't fire expire timer - //notification->expire = false; nowPlayingConfiguration = notification; if(notification->expireTimer) notification->expireTimer->stop(); @@ -385,7 +383,6 @@ bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification if(notification->getRepeatFlag()=="Repeat Once") { removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification))); - //if(!notification->firstStart) return true; } else { if(notification->getRepeatFlag()!="Repeat Instantly") @@ -407,24 +404,21 @@ bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification } if(!notification->timer->isActive()) notification->timer->start(); - - //QxtTimer::singleShot(timer_value, this, SLOT(repeatTimerHandler(NotifyPluginConfiguration*)), qVariantFromValue(notification)); } } notification->firstStart=false; - phonon.mo->clear(); + phonon.mo->clear(); QString str = notification->parseNotifyMessage(); -#ifdef DEBUG_NOTIFIES - qDebug() << "play notification - " << str; -#endif - foreach(QString item, notification->getNotifyMessageList()) { - Phonon::MediaSource *ms = new Phonon::MediaSource(item); - ms->setAutoDelete(true); - phonon.mo->enqueue(*ms); - } + qNotifyDebug() << "play notification - " << str; + + foreach(QString item, notification->getMessageSequence()) { + Phonon::MediaSource *ms = new Phonon::MediaSource(item); + ms->setAutoDelete(true); + phonon.mo->enqueue(*ms); + } phonon.mo->play(); - phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before - // the state is not "Loading" anymore. + phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before + // the state is not "Loading" anymore. } else return false; // if audio is busy @@ -432,20 +426,9 @@ bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification return true; } -//void SoundNotifyPlugin::repeatTimerHandler(NotifyPluginConfiguration* notification) -//{ -// qDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage(); - -// ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); -// UAVObjectManager *objManager = pm->getObject(); -// UAVObject* object = objManager->getObject(notification->getDataObject()); -// if(object) -// checkNotificationRule(notification,object); -//} - void SoundNotifyPlugin::repeatTimerHandler() { - NotifyPluginConfiguration* notification = static_cast(sender()->parent()); + NotificationItem* notification = static_cast(sender()->parent()); #ifdef DEBUG_NOTIFIES qDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage(); #endif @@ -459,7 +442,7 @@ void SoundNotifyPlugin::repeatTimerHandler() void SoundNotifyPlugin::expireTimerHandler() { // fire expire timer - NotifyPluginConfiguration* notification = static_cast(sender()->parent()); + NotificationItem* notification = static_cast(sender()->parent()); notification->expireTimer->stop(); if(!pendingNotifications.isEmpty()) @@ -494,7 +477,7 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst nowPlayingConfiguration=NULL; if(!pendingNotifications.isEmpty()) { - NotifyPluginConfiguration* notification = pendingNotifications.takeFirst(); + NotificationItem* notification = pendingNotifications.takeFirst(); #ifdef DEBUG_NOTIFIES qDebug() << "play audioFree - " << notification->parseNotifyMessage(); #endif diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h index 0d0eb50d8..afd68fecc 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h @@ -32,7 +32,7 @@ #include "uavtalk/telemetrymanager.h" #include "uavobjectmanager.h" #include "uavobject.h" -#include "notifypluginconfiguration.h" +#include "notificationitem.h" #include #include @@ -44,10 +44,12 @@ class NotifyPluginOptionsPage; typedef struct { Phonon::MediaObject* mo; - NotifyPluginConfiguration* notify; - bool firstPlay; + NotificationItem* notify; + bool firstPlay; } PhononObject, *pPhononObject; + + class SoundNotifyPlugin : public Core::IConfigurablePlugin { Q_OBJECT @@ -62,48 +64,42 @@ public: void shutdown(); - QList getListNotifications() { return lstNotifications; } - //void setListNotifications(QList& list_notify) { } - NotifyPluginConfiguration* getCurrentNotification(){ return ¤tNotification;} + QList getListNotifications() { return lstNotifications; } + NotificationItem* getCurrentNotification(){ return ¤tNotification;} bool getEnableSound() const { return enableSound; } void setEnableSound(bool value) {enableSound = value; } - - private: bool configured; // just for migration,delete later bool enableSound; QList< QList* > lstMediaSource; QStringList mediaSource; - //QMap mapMediaObjects; QMultiMap mapMediaObjects; - QSettings* settings; QList lstNotifiedUAVObjects; + QList lstNotifications; + QList pendingNotifications; + QList removedNotifies; - QList lstNotifications; - QList pendingNotifications; - QList removedNotifies; - - NotifyPluginConfiguration currentNotification; - NotifyPluginConfiguration* nowPlayingConfiguration; + NotificationItem currentNotification; + NotificationItem* nowPlayingConfiguration; QString m_field; PhononObject phonon; NotifyPluginOptionsPage *mop; TelemetryManager* telMngr; - bool playNotification(NotifyPluginConfiguration* notification); - void checkNotificationRule(NotifyPluginConfiguration* notification, UAVObject* object); + bool playNotification(NotificationItem* notification); + void checkNotificationRule(NotificationItem* notification, UAVObject* object); void readConfig_0_0_0(); private slots: void onTelemetryManagerAdded(QObject* obj); void onAutopilotDisconnect(); void connectNotifications(); - void updateNotificationList(QList list); + void updateNotificationList(QList list); void resetNotification(void); void appendNotification(UAVObject *object); void repeatTimerHandler(void); diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.cpp index 94b88421e..8d5cb25e3 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.cpp @@ -1,7 +1,7 @@ /** ****************************************************************************** * - * @file notifyPluginConfiguration.cpp + * @file NotificationItem.cpp * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @brief Notify Plugin configuration * @see The GNU Public License (GPL) Version 3 @@ -25,60 +25,60 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "notifypluginconfiguration.h" +#include "NotificationItem.h" #include #include #include "utils/pathutils.h" -NotifyPluginConfiguration::NotifyPluginConfiguration(QObject *parent) : +NotificationItem::NotificationItem(QObject *parent) : QObject(parent), isNowPlaying(0), firstStart(1), - soundCollectionPath(""), - currentLanguage("default"), - dataObject(""), - objectField(""), - value("Equal to"), - sound1(""), - sound2(""), - sound3(""), - sayOrder("Never"), - spinBoxValue(0), - repeatString("Repeat Instantly"), - repeatTimeout(true), - expireTimeout(15) + _soundCollectionPath(""), + _currentLanguage("default"), + _dataObject(""), + _objectField(""), + _dataValue("Equal to"), + _sound1(""), + _sound2(""), + _sound3(""), + _sayOrder("Never"), + _spinBoxValue(0), + _repeatString("Repeat Instantly"), + _repeatTimeout(true), + _expireTimeout(15) { timer = NULL; expireTimer = NULL; } -void NotifyPluginConfiguration::copyTo(NotifyPluginConfiguration* that) const +void NotificationItem::copyTo(NotificationItem* that) const { that->isNowPlaying = isNowPlaying; that->firstStart = firstStart; - that->soundCollectionPath = soundCollectionPath; - that->currentLanguage = currentLanguage; - that->soundCollectionPath = soundCollectionPath; - that->dataObject = dataObject; - that->objectField = objectField; - that->value = value; - that->sound1 = sound1; - that->sound2 = sound2; - that->sound3 = sound3; - that->sayOrder = sayOrder; - that->spinBoxValue = spinBoxValue; - that->repeatString = repeatString; - that->repeatTimeout = repeatTimeout; - that->expireTimeout = expireTimeout; + that->_soundCollectionPath = _soundCollectionPath; + that->_currentLanguage = _currentLanguage; + that->_soundCollectionPath = _soundCollectionPath; + that->_dataObject = _dataObject; + that->_objectField = _objectField; + that->_dataValue = _dataValue; + that->_sound1 = _sound1; + that->_sound2 = _sound2; + that->_sound3 = _sound3; + that->_sayOrder = _sayOrder; + that->_spinBoxValue = _spinBoxValue; + that->_repeatString = _repeatString; + that->_repeatTimeout = _repeatTimeout; + that->_expireTimeout = _expireTimeout; } -void NotifyPluginConfiguration::saveState(QSettings* settings) const +void NotificationItem::saveState(QSettings* settings) const { - settings->setValue("SoundCollectionPath", Utils::PathUtils().RemoveDataPath(getSoundCollectionPath())); + settings->setValue("SoundCollectionPath", Utils::PathUtils().RemoveDataPath(getSoundCollectionPath())); settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage()); settings->setValue(QLatin1String("ObjectField"), getObjectField()); settings->setValue(QLatin1String("DataObject"), getDataObject()); @@ -92,7 +92,7 @@ void NotifyPluginConfiguration::saveState(QSettings* settings) const settings->setValue(QLatin1String("ExpireTimeout"), getExpireTimeout()); } -void NotifyPluginConfiguration::restoreState(QSettings* settings) +void NotificationItem::restoreState(QSettings* settings) { //settings = Core::ICore::instance()->settings(); setSoundCollectionPath(Utils::PathUtils().InsertDataPath(settings->value(QLatin1String("SoundCollectionPath"), tr("")).toString())); @@ -110,7 +110,7 @@ void NotifyPluginConfiguration::restoreState(QSettings* settings) } -QString NotifyPluginConfiguration::parseNotifyMessage() +QString NotificationItem::parseNotifyMessage() { // tips: // check of *.wav files exist needed for playing phonon queues; @@ -121,30 +121,30 @@ QString NotifyPluginConfiguration::parseNotifyMessage() str = QString("%L1 ").arg(getSpinBoxValue()); int position = 0xFF; // generate queue of sound files to play - notifyMessageList.clear(); + _messageSequence.clear(); - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"))) - notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")); + if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"))) + _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")); else - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"))) - notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")); + if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"))) + _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")); - if(getSound2()!="") + if("" != getSound2()) { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"))) - notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")); + if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"))) + _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")); else - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"))) - notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")); + if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"))) + _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")); } - if(getSound3()!="") + if("" != getSound3()) { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"))) - notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")); + if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"))) + _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")); else - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"))) - notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")); + if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"))) + _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")); } switch(str1.at(0).toAscii()) @@ -178,7 +178,7 @@ QString NotifyPluginConfiguration::parseNotifyMessage() break; } - if(position!=0xFF) + if(position != 0xFF) { QStringList numberParts = QString("%1").arg(getSpinBoxValue()).trimmed().split("."); QStringList numberFiles; @@ -212,9 +212,9 @@ QString NotifyPluginConfiguration::parseNotifyMessage() } } - if(numberParts.size()>1) { + if(1 < numberParts.size()) { numberFiles.append("point"); - if((numberParts.at(1).size()==1) /*|| (numberParts.at(1).toInt()<20)*/) + if((numberParts.at(1).size()==1)) numberFiles.append(numberParts.at(1)); else { if(numberParts.at(1).left(1)=="0") @@ -226,20 +226,18 @@ QString NotifyPluginConfiguration::parseNotifyMessage() } foreach(QString fileName,numberFiles) { fileName+=".wav"; - QString filePath = QDir::toNativeSeparators(getSoundCollectionPath()+"/"+ getCurrentLanguage()+"/"+fileName); + QString filePath = QDir::toNativeSeparators(getSoundCollectionPath()+"/"+ getCurrentLanguage()+"/"+fileName); if(QFile::exists(filePath)) - notifyMessageList.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+ "/"+getCurrentLanguage()+"/"+fileName)); + _messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+ "/"+getCurrentLanguage()+"/"+fileName)); else { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName))) - notifyMessageList.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName)); + if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName))) + _messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName)); else { - notifyMessageList.clear(); + _messageSequence.clear(); break; // if no some of *.wav files, then don't play number! } } } } - - //str.replace(QString(".wav | .mp3"), QString("")); return str; } diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.h b/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.h deleted file mode 100644 index ad13a82a0..000000000 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.h +++ /dev/null @@ -1,122 +0,0 @@ -/** - ****************************************************************************** - * - * @file notifypluginconfiguration.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Notify Plugin configuration header - * @see The GNU Public License (GPL) Version 3 - * @defgroup notifyplugin - * @{ - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef NOTIFYPLUGINCONFIGURATION_H -#define NOTIFYPLUGINCONFIGURATION_H -#include -#include "qsettings.h" -#include -#include - -using namespace Core; - -class NotifyPluginConfiguration : public QObject -{ - Q_OBJECT -public: - explicit NotifyPluginConfiguration(QObject *parent = 0); - - QTimer* timer; - QTimer* expireTimer; - bool isNowPlaying; // - bool firstStart; - - void copyTo(NotifyPluginConfiguration*) const; - - QString getSound1() const { return sound1; } - void setSound1(QString text) {sound1 = text; } - - QString getSound2() const { return sound2; } - void setSound2(QString text) {sound2 = text; } - - QString getSound3() const { return sound3; } - void setSound3(QString text) {sound3 = text; } - - QString getValue() const { return value; } - void setValue(QString text) {value = text; } - - QString getSayOrder() const { return sayOrder; } - void setSayOrder(QString text) {sayOrder = text; } - - double getSpinBoxValue() const { return spinBoxValue; } - void setSpinBoxValue(double value) {spinBoxValue = value; } - - - QString getDataObject() const { return dataObject; } - void setDataObject(QString text) {dataObject = text; } - - QString getObjectField() const { return objectField; } - void setObjectField(QString text) { objectField = text; } - - QString getSoundCollectionPath() const { return soundCollectionPath; } - void setSoundCollectionPath(QString text) { soundCollectionPath = text; } - - QString getCurrentLanguage() const { return currentLanguage; } - void setCurrentLanguage(QString text) { currentLanguage = text; } - - QStringList getNotifyMessageList() const { return notifyMessageList; } - void setNotifyMessageList(QStringList text) { notifyMessageList = text; } - - QString getRepeatFlag() const { return repeatString; } - void setRepeatFlag(QString value) { repeatString = value; } - - bool getRepeatTimeout() const { return repeatTimeout; } - void setRepeatTimeout(bool value) { repeatTimeout = value; } - - int getExpireTimeout() const { return expireTimeout; } - void setExpireTimeout(int value) { expireTimeout = value; } - - - - void saveState(QSettings* settings) const; - void restoreState(QSettings* settings); - QString parseNotifyMessage(); - -private: - QStringList notifyMessageList; - QString soundCollectionPath; - QString currentLanguage; - QString dataObject; - QString objectField; - - QString value; - QString sound1; - QString sound2; - QString sound3; - QString sayOrder; - double spinBoxValue; - QString repeatString; - bool repeatTimeout; - int repeatTimerValue; - int expireTimeout; - -}; - -Q_DECLARE_METATYPE(NotifyPluginConfiguration*) - -#endif // NOTIFYPLUGINCONFIGURATION_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index 5dee5678a..48d8f9132 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -27,7 +27,7 @@ #include "notifypluginoptionspage.h" #include -#include "notifypluginconfiguration.h" +#include "notificationitem.h" #include "ui_notifypluginoptionspage.h" #include "extensionsystem/pluginmanager.h" #include "utils/pathutils.h" @@ -44,7 +44,7 @@ #include "notifyitemdelegate.h" #include "notifytablemodel.h" -NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotifyPluginConfiguration *config,*/ QObject *parent) : +NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) : IOptionsPage(parent), owner((SoundNotifyPlugin*)parent), currentCollectionPath(""), @@ -95,36 +95,29 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); -// connect(options_page->buttonTestSound1, SIGNAL(clicked()), this, SLOT(on_buttonTestSound1_clicked())); -// connect(options_page->buttonTestSound2, SIGNAL(clicked()), this, SLOT(on_buttonTestSound2_clicked())); connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); - connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); - connect(this, SIGNAL(updateNotifications(QList)), - owner, SLOT(updateNotificationList(QList))); + connect(this, SIGNAL(updateNotifications(QList)), + owner, SLOT(updateNotificationList(QList))); connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); //emit resetNotification(); + privListNotifications.clear(); - privListNotifications.clear(); - - for (int i = 0; i < owner->getListNotifications().size(); ++i) { - NotifyPluginConfiguration* notification = new NotifyPluginConfiguration(); - owner->getListNotifications().at(i)->copyTo(notification); - privListNotifications.append(notification); + for (int i = 0; i < owner->getListNotifications().size(); ++i) { + NotificationItem* notification = new NotificationItem(); + owner->getListNotifications().at(i)->copyTo(notification); + privListNotifications.append(notification); } - updateConfigView(owner->getCurrentNotification()); + updateConfigView(owner->getCurrentNotification()); - options_page->chkEnableSound->setChecked(owner->getEnableSound()); + options_page->chkEnableSound->setChecked(owner->getEnableSound()); - QStringList headerStrings; - headerStrings << "Name" << "Repeats" << "Lifetime,sec"; - - notifyRulesModel = new NotifyTableModel(&privListNotifications,headerStrings); + notifyRulesModel = new NotifyTableModel(&privListNotifications); options_page->notifyRulesView->setModel(notifyRulesModel); options_page->notifyRulesView->resizeRowsToContents(); notifyRulesSelection = new QItemSelectionModel(notifyRulesModel); @@ -135,50 +128,28 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) connect(this, SIGNAL(entryAdded(int)), notifyRulesModel, SLOT(entryAdded(int))); + options_page->notifyRulesView->setSelectionModel(notifyRulesSelection); options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); - options_page->notifyRulesView->setColumnWidth(0,200); - options_page->notifyRulesView->setColumnWidth(1,150); - options_page->notifyRulesView->setColumnWidth(2,100); + options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); + options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); + options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); + options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); options_page->buttonModify->setEnabled(false); options_page->buttonDelete->setEnabled(false); options_page->buttonPlayNotification->setEnabled(false); -// sound1 = Phonon::createPlayer(Phonon::NotificationCategory); -// sound2 = Phonon::createPlayer(Phonon::NotificationCategory); notifySound = Phonon::createPlayer(Phonon::NotificationCategory); -// audioOutput = new Phonon::AudioOutput(Phonon::NotificationCategory, this); -// Phonon::createPath(sound1, audioOutput); -// Phonon::createPath(sound2, audioOutput); -// Phonon::createPath(notifySound, audioOutput); - -// connect(sound1,SIGNAL(stateChanged(Phonon::State,Phonon::State)),SLOT(changeButtonText(Phonon::State,Phonon::State))); -// connect(sound2,SIGNAL(stateChanged(Phonon::State,Phonon::State)),SLOT(changeButtonText(Phonon::State,Phonon::State))); connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), this,SLOT(changeButtonText(Phonon::State,Phonon::State))); + connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); return optionsPageWidget; } -void NotifyPluginOptionsPage::showPersistentComboBox( const QModelIndex & parent, int start, int end ) -{ -// for (int i=start; itableNotifications->openPersistentEditor(options_page->tableNotifications->item(i,1)); -// } -} - -void NotifyPluginOptionsPage::showPersistentComboBox2( const QModelIndex & topLeft, const QModelIndex & bottomRight ) -{ - //for (QModelIndex i=topLeft; itableNotifications->openPersistentEditor(options_page->tableNotifications->item(options_page->tableNotifications->currentRow(),1)); - } -} - - -void NotifyPluginOptionsPage::getOptionsPageValues(NotifyPluginConfiguration* notification) +void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) { notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); @@ -191,26 +162,16 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotifyPluginConfiguration* no notification->setValue(options_page->Value->currentText()); notification->setSpinBoxValue(options_page->ValueSpinBox->value()); -// if(notifyRulesSelection->currentIndex().row()>-1) -// { -// //qDebug() << "delegate value:" << options_page->tableNotifications->item(options_page->tableNotifications->currentRow(),1)->data(Qt::EditRole); -// notification->setRepeatFlag(notifyRulesModel->data(notifyRulesSelection->currentIndex(),Qt::DisplayRole).toString()); -// } } -//////////////////////////////////////////// -// Called when the user presses apply or OK. -// -// Saves the current values -// -//////////////////////////////////////////// +/*! +* Called when the user presses apply or OK. +* Saves the current values +*/ void NotifyPluginOptionsPage::apply() { - - getOptionsPageValues(owner->getCurrentNotification()); - + getOptionsPageValues(owner->getCurrentNotification()); owner->setEnableSound(options_page->chkEnableSound->isChecked()); - //owner->setListNotifications(privListNotifications); emit updateNotifications(privListNotifications); } @@ -218,25 +179,22 @@ void NotifyPluginOptionsPage::finish() { disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - if(notifySound) - { + if (notifySound) { notifySound->stop(); notifySound->clear(); } - - delete options_page; + if (options_page) + delete options_page; } - - ////////////////////////////////////////////////////////////////////////////// // Fills in the combo box when value is changed in the // combo box ////////////////////////////////////////////////////////////////////////////// void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) { options_page->UAVObjectField->clear(); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager* objManager = pm->getObject(); UAVDataObject* obj = dynamic_cast( objManager->getObject(val) ); QList fieldList = obj->getFields(); foreach (UAVObjectField* field, fieldList) { @@ -258,8 +216,8 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) { options_page->SoundCollectionList->setCurrentIndex(index); - currentCollectionPath = options_page->SoundDirectoryPathChooser->path() + - QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText()); + currentCollectionPath = options_page->SoundDirectoryPathChooser->path() + + QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText()); QDir dirPath(currentCollectionPath); QStringList filters; @@ -280,30 +238,38 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate) { - if(newstate == Phonon::PausedState || newstate == Phonon::StoppedState){ + Q_ASSERT(Phonon::ErrorState != newstate); + + if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { options_page->buttonPlayNotification->setText("Play"); options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); - } - else - if(newstate == Phonon::PlayingState) { - options_page->buttonPlayNotification->setText("Stop"); - options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); + } else { + if (newstate == Phonon::PlayingState) { + options_page->buttonPlayNotification->setText("Stop"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); + } } } +void NotifyPluginOptionsPage::onFinishedPlaying() +{ + notifySound->clear(); +} void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() { - // QList messageNotify; - NotifyPluginConfiguration *notification; + NotificationItem* notification = NULL; - if(notifyRulesSelection->currentIndex().row()==-1) return; - - notifySound->clearQueue(); + if (-1 == notifyRulesSelection->currentIndex().row()) + return; + notifySound->clearQueue(); notification = privListNotifications.at(notifyRulesSelection->currentIndex().row()); notification->parseNotifyMessage(); - foreach(QString item, notification->getNotifyMessageList()) - notifySound->enqueue(Phonon::MediaSource(item)); + QStringList sequence = notification->getMessageSequence(); + Q_ASSERT(!!sequence.size()); + foreach(QString item, sequence) + notifySound->enqueue(Phonon::MediaSource(item)); + notifySound->play(); } @@ -316,25 +282,24 @@ void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state) audioOutput->setMuted(state1); } -void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notification) +void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) { QString path = notification->getSoundCollectionPath(); - if(path=="") - { + if (path == "") { //QDir dir = QDir::currentPath(); //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; - path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); + path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); } + options_page->SoundDirectoryPathChooser->setPath(path); - if(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())!=-1){ + if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){ options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); - } - else + } else { options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + } - - if(options_page->UAVObject->findText(notification->getDataObject())!=-1){ + if (options_page->UAVObject->findText(notification->getDataObject())!=-1){ options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); } @@ -349,15 +314,13 @@ void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notifi } } - if(options_page->UAVObjectField->findText(notification->getObjectField())!=-1){ + if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) { options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); } - if(options_page->Sound1->findText(notification->getSound1())!=-1){ + if (-1 != options_page->Sound1->findText(notification->getSound1())) { options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); - } - else - { + } else { // show item from default location options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); @@ -366,10 +329,9 @@ void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notifi //options_page->Sound1->setCurrentIndex(-1); } - if(options_page->Sound2->findText(notification->getSound2())!=-1) { + if (-1 != options_page->Sound2->findText(notification->getSound2())) { options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); - } - else { + } else { // show item from default location options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); @@ -378,33 +340,33 @@ void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notifi //options_page->Sound2->setCurrentIndex(-1); } - if(options_page->Sound3->findText(notification->getSound3())!=-1) { + if (-1 != options_page->Sound3->findText(notification->getSound3())) { options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); - } - else { + } else { // show item from default location options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); } - if(options_page->Value->findText(notification->getValue())!=-1) { + if (-1 != options_page->Value->findText(notification->getValue())) { options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue())); } - if(options_page->SayOrder->findText(notification->getSayOrder())!=-1) { + if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) { options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder())); } + options_page->ValueSpinBox->setValue(notification->getSpinBoxValue()); } void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ) { - bool select = true; + bool select = false; notifySound->stop(); - if(selected.indexes().size()) + if (selected.indexes().size()) { + select = true; updateConfigView(privListNotifications.at(selected.indexes().at(0).row())); - else - select = false; + } options_page->buttonModify->setEnabled(select); options_page->buttonDelete->setEnabled(select); @@ -412,13 +374,11 @@ void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemS } - void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() { - NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; + NotificationItem* notification = new NotificationItem; - if(options_page->SoundDirectoryPathChooser->path()=="") - { + if (options_page->SoundDirectoryPathChooser->path()=="") { QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); options_page->SoundDirectoryPathChooser->setPalette(textPalette); @@ -433,20 +393,20 @@ void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() notification->setValue(options_page->Value->currentText()); notification->setSpinBoxValue(options_page->ValueSpinBox->value()); - if(options_page->Sound1->currentText()!="") + if (options_page->Sound1->currentText().size() > 0) notification->setSound1(options_page->Sound1->currentText()); notification->setSound2(options_page->Sound2->currentText()); notification->setSound3(options_page->Sound3->currentText()); - if(((options_page->Sound2->currentText()=="")&&(options_page->SayOrder->currentText()=="After second")) - || ((options_page->Sound3->currentText()=="")&&(options_page->SayOrder->currentText()=="After third"))) + if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second")) + || ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) { return; - else + } else { notification->setSayOrder(options_page->SayOrder->currentText()); - + } privListNotifications.append(notification); - emit entryAdded(privListNotifications.size()-1); + emit entryAdded(privListNotifications.size() - 1); notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } @@ -455,7 +415,9 @@ void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() { notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row()); - if(!notifyRulesModel->rowCount() && (notifyRulesSelection->currentIndex().row() > 0 && notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount())) + if (!notifyRulesModel->rowCount() + && (notifyRulesSelection->currentIndex().row() > 0 + && notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) ) { options_page->buttonDelete->setEnabled(false); options_page->buttonModify->setEnabled(false); @@ -466,7 +428,7 @@ void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked() { - NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; + NotificationItem* notification = new NotificationItem; getOptionsPageValues(notification); notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag()); privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification); diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h index 9d159e2a4..31da8373f 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h @@ -45,7 +45,7 @@ class NotifyTableModel; -class NotifyPluginConfiguration; +class NotificationItem; class SoundNotifyPlugin; namespace Ui { @@ -59,7 +59,7 @@ class NotifyPluginOptionsPage : public IOptionsPage { Q_OBJECT public: - explicit NotifyPluginOptionsPage(/*NotifyPluginConfiguration *config, */QObject *parent = 0); + explicit NotifyPluginOptionsPage(/*NotificationItem *config, */QObject *parent = 0); QString id() const { return QLatin1String("settings"); } QString trName() const { return tr("settings"); } @@ -73,8 +73,8 @@ public: void finish(); void restoreFromSettings(); - void updateConfigView(NotifyPluginConfiguration* notification); - void getOptionsPageValues(NotifyPluginConfiguration* notification); + void updateConfigView(NotificationItem* notification); + void getOptionsPageValues(NotificationItem* notification); private: UAVObjectManager *objManager; @@ -90,24 +90,18 @@ private: QStringList delegateItems; NotifyTableModel* notifyRulesModel; QItemSelectionModel *notifyRulesSelection; - QList privListNotifications; + QList privListNotifications; Ui::NotifyPluginOptionsPage *options_page; - //NotifyPluginConfiguration *notify; signals: - void updateNotifications(QList list); + void updateNotifications(QList list); void resetNotification(void); void entryUpdated(int index); void entryAdded(int position); private slots: - void showPersistentComboBox( const QModelIndex & parent, int start, int end ); - void showPersistentComboBox2 ( const QModelIndex & topLeft, const QModelIndex & bottomRight ); - -// void on_buttonTestSound1_clicked(); -// void on_buttonTestSound2_clicked(); void on_buttonTestSoundNotification_clicked(); void on_buttonAddNotification_clicked(); @@ -119,6 +113,9 @@ private slots: void on_UAVObject_indexChanged(QString val); void changeButtonText(Phonon::State newstate, Phonon::State oldstate); void on_chkEnableSound_toggled(bool state); + + void onFinishedPlaying(void); + }; #endif // NOTIFYPLUGINOPTIONSPAGE_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui index b3f48432a..4645bd14a 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui @@ -24,7 +24,7 @@ 10 10 - 501 + 551 81 @@ -36,7 +36,7 @@ 10 20 - 481 + 531 51 @@ -89,7 +89,7 @@ p, li { white-space: pre-wrap; } 10 220 - 501 + 551 211 @@ -101,7 +101,7 @@ p, li { white-space: pre-wrap; } 10 180 - 481 + 531 26 @@ -203,7 +203,7 @@ p, li { white-space: pre-wrap; } 10 20 - 481 + 531 151 @@ -226,7 +226,7 @@ p, li { white-space: pre-wrap; } 10 100 - 501 + 551 31 @@ -272,7 +272,7 @@ p, li { white-space: pre-wrap; } 7 130 - 501 + 551 20 @@ -285,7 +285,7 @@ p, li { white-space: pre-wrap; } 10 180 - 501 + 551 31 @@ -390,7 +390,7 @@ p, li { white-space: pre-wrap; } 10 150 - 501 + 551 31 diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp index 6f0584d70..6e503cbd8 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp @@ -26,17 +26,30 @@ */ #include "notifytablemodel.h" +#include + +NotifyTableModel::NotifyTableModel(QList* parentList, QObject* parent) + : QAbstractTableModel(parent) +{ + _headerStrings << "Name" << "Repeats" << "Lifetime,sec" << "Enable"; + _list.reset(parentList); +} + bool NotifyTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { - if(index.column()==1) + if(eREPEAT_VALUE == index.column()) _list->at(index.row())->setRepeatFlag(value.toString()); - else - if(index.column()==2) + else { + if(eEXPIRE_TIME == index.column()) _list->at(index.row())->setExpireTimeout(value.toInt()); - + else { + if(eENABLE_NOTIFICATION == index.column()) + _list->at(index.row())->setEnableFlag(value.toBool()); + } + } emit dataChanged(index, index); return true; } @@ -45,9 +58,10 @@ bool NotifyTableModel::setData(const QModelIndex &index, QVariant NotifyTableModel::data(const QModelIndex &index, int role) const { - - if (!index.isValid()) + if (!index.isValid()) { + qWarning() << "NotifyTableModel::data - index.isValid()"; return QVariant(); + } if (index.row() >= _list->size()) return QVariant(); @@ -56,15 +70,18 @@ QVariant NotifyTableModel::data(const QModelIndex &index, int role) const { switch(index.column()) { - case 0: + case eMESSAGE_NAME: return _list->at(index.row())->parseNotifyMessage(); - case 1: + case eREPEAT_VALUE: return _list->at(index.row())->getRepeatFlag(); - case 2: + case eEXPIRE_TIME: return _list->at(index.row())->getExpireTimeout(); + case eENABLE_NOTIFICATION: + return _list->at(index.row())->getEnableFlag(); + default: return QVariant(); } @@ -72,12 +89,8 @@ QVariant NotifyTableModel::data(const QModelIndex &index, int role) const else { if (Qt::SizeHintRole == role){ - //QVariant size = data(index, Qt::SizeHintRole); return QVariant(10); } - // if(role == Qt::DecorationRole) - // if (index.column() == 0) - // return defectsIcons[defectList->at(index.row()).id-1]; } return QVariant(); } @@ -88,7 +101,7 @@ QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation, return QVariant(); if (orientation == Qt::Horizontal) - return headerStrings.at(section); + return _headerStrings.at(section); else if(orientation == Qt::Vertical) return QString("%1").arg(section); @@ -100,12 +113,6 @@ bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex &ind { Q_UNUSED(index); beginInsertRows(QModelIndex(), position, position+rows-1); - -// for (int row=0; row < rows; ++row) { -// _list->append(position); -// } - - endInsertRows(); return true; } diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h index 65aa82a86..978605fbe 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h @@ -31,26 +31,28 @@ #include #include -#include "notifypluginconfiguration.h" +#include "notificationitem.h" + +enum ColumnNames { eMESSAGE_NAME, eREPEAT_VALUE, eEXPIRE_TIME, eENABLE_NOTIFICATION }; class NotifyTableModel : public QAbstractTableModel { Q_OBJECT - public: - NotifyTableModel(QList *parentList, const QStringList& parentHeaderList, QObject *parent = 0) - : QAbstractTableModel(parent), - _list(parentList), - headerStrings(parentHeaderList) - { } - int rowCount(const QModelIndex &parent = QModelIndex()) const + enum {eColumnCount = 4 }; + +public: + + NotifyTableModel(QList* parentList, QObject* parent = 0); + + int rowCount(const QModelIndex& parent = QModelIndex()) const { return _list->count(); } int columnCount(const QModelIndex &/*parent*/) const { - return 3; + return eColumnCount; } Qt::ItemFlags flags(const QModelIndex &index) const @@ -71,8 +73,8 @@ private slots: void entryUpdated(int offset); void entryAdded(int position); private: - QList *_list; - QStringList headerStrings; + QScopedPointer > _list; + QStringList _headerStrings; }; diff --git a/openpilotgcs.bat b/openpilotgcs.bat new file mode 100644 index 000000000..a656aa85b --- /dev/null +++ b/openpilotgcs.bat @@ -0,0 +1,3 @@ +cd D:\Qt\4.7.3\bin\ + +call D:\!Work\OpenSource\OpenPilot\OpenPilot\build\ground\openpilotgcs\bin\openpilotgcs.exe \ No newline at end of file From e14e0a763b409d83b69bec98ddfef0e44f9225fc Mon Sep 17 00:00:00 2001 From: Nickolay Date: Thu, 15 Sep 2011 01:35:19 +0300 Subject: [PATCH 2/9] - temporary remove assert in finished callback; --- .../openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index 48d8f9132..686c59c3b 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -238,7 +238,7 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate) { - Q_ASSERT(Phonon::ErrorState != newstate); + //Q_ASSERT(Phonon::ErrorState != newstate); if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { options_page->buttonPlayNotification->setText("Play"); From c16e386e6375538b5be59f637ef65f0c408cfa05 Mon Sep 17 00:00:00 2001 From: Nickolay Date: Fri, 16 Sep 2011 02:24:35 +0300 Subject: [PATCH 3/9] +reordering of table items - experimenting with D&D --- ...configuration.cpp => notificationitem.cpp} | 0 .../src/plugins/notify/notify.pro | 6 +- .../src/plugins/notify/notifyplugin.h | 35 +++--- .../notify/notifypluginoptionspage.cpp | 111 ++++++++++-------- .../plugins/notify/notifypluginoptionspage.h | 22 ++-- .../src/plugins/notify/notifytablemodel.cpp | 30 ++--- .../src/plugins/notify/notifytablemodel.h | 9 +- 7 files changed, 120 insertions(+), 93 deletions(-) rename ground/openpilotgcs/src/plugins/notify/{notifypluginconfiguration.cpp => notificationitem.cpp} (100%) diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.cpp b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp similarity index 100% rename from ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.cpp rename to ground/openpilotgcs/src/plugins/notify/notificationitem.cpp diff --git a/ground/openpilotgcs/src/plugins/notify/notify.pro b/ground/openpilotgcs/src/plugins/notify/notify.pro index e70392a6a..b8eeb35fd 100644 --- a/ground/openpilotgcs/src/plugins/notify/notify.pro +++ b/ground/openpilotgcs/src/plugins/notify/notify.pro @@ -12,13 +12,13 @@ HEADERS += notifyplugin.h \ notifypluginoptionspage.h \ notifyitemdelegate.h \ notifytablemodel.h \ - NotificationItem.h + notificationitem.h SOURCES += notifyplugin.cpp \ notifypluginoptionspage.cpp \ - notifypluginconfiguration.cpp \ notifyitemdelegate.cpp \ - notifytablemodel.cpp + notifytablemodel.cpp \ + notificationitem.cpp OTHER_FILES += NotifyPlugin.pluginspec diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h index afd68fecc..c1e0ce620 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h @@ -71,6 +71,26 @@ public: void setEnableSound(bool value) {enableSound = value; } private: + SoundNotifyPlugin(const SoundNotifyPlugin& rhs); + SoundNotifyPlugin& operator= (const SoundNotifyPlugin& rhs); + + bool playNotification(NotificationItem* notification); + void checkNotificationRule(NotificationItem* notification, UAVObject* object); + void readConfig_0_0_0(); + +private slots: + void onTelemetryManagerAdded(QObject* obj); + void onAutopilotDisconnect(); + void connectNotifications(); + void updateNotificationList(QList list); + void resetNotification(void); + void appendNotification(UAVObject *object); + void repeatTimerHandler(void); + void expireTimerHandler(void); + void stateChanged(Phonon::State newstate, Phonon::State oldstate); + +private: + bool configured; // just for migration,delete later bool enableSound; QList< QList* > lstMediaSource; @@ -90,21 +110,6 @@ private: PhononObject phonon; NotifyPluginOptionsPage *mop; TelemetryManager* telMngr; - - bool playNotification(NotificationItem* notification); - void checkNotificationRule(NotificationItem* notification, UAVObject* object); - void readConfig_0_0_0(); - -private slots: - void onTelemetryManagerAdded(QObject* obj); - void onAutopilotDisconnect(); - void connectNotifications(); - void updateNotificationList(QList list); - void resetNotification(void); - void appendNotification(UAVObject *object); - void repeatTimerHandler(void); - void expireTimerHandler(void); - void stateChanged(Phonon::State newstate, Phonon::State oldstate); }; #endif // SOUNDNOTIFYPLUGIN_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index 686c59c3b..cee9a4027 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -44,24 +44,26 @@ #include "notifyitemdelegate.h" #include "notifytablemodel.h" -NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) : - IOptionsPage(parent), - owner((SoundNotifyPlugin*)parent), - currentCollectionPath(""), - privListNotifications(((SoundNotifyPlugin*)parent)->getListNotifications()) +NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) + : IOptionsPage(parent) + , objManager(*ExtensionSystem::PluginManager::instance()->getObject()) + , owner(qobject_cast(parent)) + , currentCollectionPath("") + , privListNotifications((qobject_cast(parent))->getListNotifications()) { - } +NotifyPluginOptionsPage::~NotifyPluginOptionsPage() +{ +} //creates options page widget (uses the UI file) QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) { - - options_page = new Ui::NotifyPluginOptionsPage(); - //main widget - QWidget *optionsPageWidget = new QWidget; - //main layout + options_page.reset(new Ui::NotifyPluginOptionsPage()); + //main widget + QWidget *optionsPageWidget = new QWidget; + //main layout options_page->setupUi(optionsPageWidget); delegateItems.clear(); @@ -73,17 +75,11 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) << "Repeat 30 seconds" << "Repeat 1 minute"; - options_page->chkEnableSound->setChecked(owner->getEnableSound()); options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); - - - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - objManager = pm->getObject(); - // Fills the combo boxes for the UAVObjects - QList< QList > objList = objManager->getDataObjects(); + QList< QList > objList = objManager.getDataObjects(); foreach (QList list, objList) { foreach (UAVDataObject* obj, list) { options_page->UAVObject->addItem(obj->getName()); @@ -92,13 +88,8 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); - connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); - connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); - connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); - connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); - connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); - connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); + connect(this, SIGNAL(updateNotifications(QList)), owner, SLOT(updateNotificationList(QList))); connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); @@ -115,20 +106,52 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) updateConfigView(owner->getCurrentNotification()); + initButtons(); + initRulesTableModel(); + initRulesTableView(); + initPhononPlayer(); + + return optionsPageWidget; +} + +void NotifyPluginOptionsPage::initButtons() +{ options_page->chkEnableSound->setChecked(owner->getEnableSound()); + connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); - notifyRulesModel = new NotifyTableModel(&privListNotifications); - options_page->notifyRulesView->setModel(notifyRulesModel); + options_page->buttonModify->setEnabled(false); + options_page->buttonDelete->setEnabled(false); + options_page->buttonPlayNotification->setEnabled(false); + connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); + connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); + connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); + connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); +} + +void NotifyPluginOptionsPage::initPhononPlayer() +{ + notifySound = Phonon::createPlayer(Phonon::NotificationCategory); + connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(changeButtonText(Phonon::State,Phonon::State))); + connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); +} + +void NotifyPluginOptionsPage::initRulesTableModel() +{ + notifyRulesModel.reset(new NotifyTableModel(&privListNotifications)); + notifyRulesSelection = new QItemSelectionModel(notifyRulesModel.data()); + connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), + this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); + connect(this, SIGNAL(entryUpdated(int)), + notifyRulesModel.data(), SLOT(entryUpdated(int))); + connect(this, SIGNAL(entryAdded(int)), + notifyRulesModel.data(), SLOT(entryAdded(int))); +} + +void NotifyPluginOptionsPage::initRulesTableView() +{ + options_page->notifyRulesView->setModel(notifyRulesModel.data()); options_page->notifyRulesView->resizeRowsToContents(); - notifyRulesSelection = new QItemSelectionModel(notifyRulesModel); - connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), - this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); - connect(this, SIGNAL(entryUpdated(int)), - notifyRulesModel, SLOT(entryUpdated(int))); - connect(this, SIGNAL(entryAdded(int)), - notifyRulesModel, SLOT(entryAdded(int))); - - options_page->notifyRulesView->setSelectionModel(notifyRulesSelection); options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); @@ -136,17 +159,9 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); - - options_page->buttonModify->setEnabled(false); - options_page->buttonDelete->setEnabled(false); - options_page->buttonPlayNotification->setEnabled(false); - - notifySound = Phonon::createPlayer(Phonon::NotificationCategory); - connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); - - return optionsPageWidget; + options_page->notifyRulesView->setDragEnabled(true); + options_page->notifyRulesView->setAcceptDrops(true); + options_page->notifyRulesView->setDropIndicatorShown(true); } void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) @@ -183,8 +198,6 @@ void NotifyPluginOptionsPage::finish() notifySound->stop(); notifySound->clear(); } - if (options_page) - delete options_page; } ////////////////////////////////////////////////////////////////////////////// @@ -306,7 +319,7 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) // Now load the object field values: options_page->UAVObjectField->clear(); QString uavDataObject = notification->getDataObject(); - UAVDataObject* obj = dynamic_cast( objManager->getObject(uavDataObject/*objList.at(0).at(0)->getName()*/) ); + UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); if (obj != NULL ) { QList fieldList = obj->getFields(); foreach (UAVObjectField* field, fieldList) { diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h index 31da8373f..521cf9874 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h @@ -42,16 +42,13 @@ #include #include #include +#include "ui_notifypluginoptionspage.h" +//#include "notifytablemodel.h" class NotifyTableModel; - class NotificationItem; class SoundNotifyPlugin; -namespace Ui { - class NotifyPluginOptionsPage; -} - using namespace Core; @@ -60,7 +57,7 @@ class NotifyPluginOptionsPage : public IOptionsPage Q_OBJECT public: explicit NotifyPluginOptionsPage(/*NotificationItem *config, */QObject *parent = 0); - + ~NotifyPluginOptionsPage(); QString id() const { return QLatin1String("settings"); } QString trName() const { return tr("settings"); } QString category() const { return QLatin1String("Notify Plugin");} @@ -77,7 +74,14 @@ public: void getOptionsPageValues(NotificationItem* notification); private: - UAVObjectManager *objManager; + //Q_DISABLE_COPY(NotifyPluginOptionsPage) + void initButtons(); + void initPhononPlayer(); + void initRulesTableModel(); + void initRulesTableView(); + +private: + UAVObjectManager& objManager; SoundNotifyPlugin* owner; QStringList listDirCollections; QStringList listSoundFiles; @@ -88,11 +92,11 @@ private: Phonon::MediaObject *notifySound; Phonon::AudioOutput *audioOutput; QStringList delegateItems; - NotifyTableModel* notifyRulesModel; + QScopedPointer notifyRulesModel; QItemSelectionModel *notifyRulesSelection; QList privListNotifications; - Ui::NotifyPluginOptionsPage *options_page; + QScopedPointer options_page; signals: void updateNotifications(QList list); diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp index 6e503cbd8..f3c89b5b7 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp @@ -109,26 +109,26 @@ QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation, return QVariant(); } -bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex &index) +bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& index) { - Q_UNUSED(index); - beginInsertRows(QModelIndex(), position, position+rows-1); - endInsertRows(); - return true; + Q_UNUSED(index); + beginInsertRows(QModelIndex(), position, position+rows-1); + endInsertRows(); + return true; } - bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex &index) - { - Q_UNUSED(index); - beginRemoveRows(QModelIndex(), position, position+rows-1); +bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex& index) +{ + Q_UNUSED(index); + beginRemoveRows(QModelIndex(), position, position+rows-1); - for (int row=0; row < rows; ++row) { - _list->removeAt(position); - } + for (int row=0; row < rows; ++row) { + _list->removeAt(position); + } - endRemoveRows(); - return true; - } + endRemoveRows(); + return true; +} void NotifyTableModel::entryUpdated(int offset) { diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h index 978605fbe..affae25da 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h @@ -58,11 +58,16 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const { if (!index.isValid()) - return Qt::ItemIsEnabled; + return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; } + Qt::DropActions supportedDropActions() const + { + return Qt::MoveAction; + } + bool setData(const QModelIndex &index, const QVariant &value, int role); QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; From 56e71cd82ec0fbe0040d8dce03ee8097f70f8d37 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Sep 2011 18:39:20 +0300 Subject: [PATCH 4/9] +removed public members in notificationitem; +cosmetic changes; +fixed indentation; --- .../internals/projections/lks94projection.h | 2 +- .../src/plugins/notify/NotificationItem.h | 156 +++--- .../src/plugins/notify/notificationitem.cpp | 420 ++++++++------- .../src/plugins/notify/notify.pro | 8 +- .../src/plugins/notify/notifyitemdelegate.cpp | 202 ++++---- .../src/plugins/notify/notifylogging.cpp | 42 ++ .../src/plugins/notify/notifylogging.h | 42 ++ .../src/plugins/notify/notifyplugin.cpp | 488 ++++++++---------- .../src/plugins/notify/notifyplugin.h | 1 - .../notify/notifypluginoptionspage.cpp | 469 +++++++++-------- .../notify/notifypluginoptionspage.cpp.orig | 465 +++++++++++++++++ .../plugins/notify/notifypluginoptionspage.h | 2 +- .../src/plugins/notify/notifytablemodel.cpp | 114 ++-- 13 files changed, 1493 insertions(+), 918 deletions(-) create mode 100644 ground/openpilotgcs/src/plugins/notify/notifylogging.cpp create mode 100644 ground/openpilotgcs/src/plugins/notify/notifylogging.h create mode 100644 ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp.orig diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h index dc895f04c..efbe9c394 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h @@ -28,7 +28,7 @@ #define LKS94PROJECTION_H #include #include "cmath" -#include "D:\!Work\OpenSource\OpenPilot\OpenPilot\ground\openpilotgcs\src\libs\opmapcontrol\src\internals\pureprojection.h" +#include "D:\!Work\OpenPilot\OpenPilot\ground\openpilotgcs\src\libs\opmapcontrol\src\internals\pureprojection.h" namespace projections { diff --git a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h index c09e64982..ad7250060 100644 --- a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h +++ b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h @@ -40,113 +40,129 @@ using namespace Core; QString getSound##number() const { return _sound##number; } \ void setSound##number(QString text) { _sound##number = text; } \ -// QString getSound2() const { return _sound2; } -// void setSound2(QString text) { _sound2 = text; } - -// QString getSound3() const { return _sound3; } -// void setSound3(QString text) { _sound3 = text; } class NotificationItem : public QObject { - Q_OBJECT + Q_OBJECT public: - explicit NotificationItem(QObject *parent = 0); + explicit NotificationItem(QObject *parent = 0); - void copyTo(NotificationItem*) const; + void copyTo(NotificationItem*) const; - DECLARE_SOUND(1) - DECLARE_SOUND(2) - DECLARE_SOUND(3) + DECLARE_SOUND(1) + DECLARE_SOUND(2) + DECLARE_SOUND(3) - QString getValue() const { return _dataValue; } - void setValue(QString text) { _dataValue = text; } + QString getValue() const { return _dataValue; } + void setValue(QString text) { _dataValue = text; } - QString getSayOrder() const { return _sayOrder; } - void setSayOrder(QString text) { _sayOrder = text; } + QString getSayOrder() const { return _sayOrder; } + void setSayOrder(QString text) { _sayOrder = text; } - double getSpinBoxValue() const { return _spinBoxValue; } - void setSpinBoxValue(double value) { _spinBoxValue = value; } + double getSpinBoxValue() const { return _spinBoxValue; } + void setSpinBoxValue(double value) { _spinBoxValue = value; } - QString getDataObject() const { return _dataObject; } - void setDataObject(QString text) { _dataObject = text; } + QString getDataObject() const { return _dataObject; } + void setDataObject(QString text) { _dataObject = text; } - QString getObjectField() const { return _objectField; } - void setObjectField(QString text) { _objectField = text; } + QString getObjectField() const { return _objectField; } + void setObjectField(QString text) { _objectField = text; } - QString getSoundCollectionPath() const { return _soundCollectionPath; } - void setSoundCollectionPath(QString path) { _soundCollectionPath = path; } + QString getSoundCollectionPath() const { return _soundCollectionPath; } + void setSoundCollectionPath(QString path) { _soundCollectionPath = path; } - QString getCurrentLanguage() const { return _currentLanguage; } - void setCurrentLanguage(QString text) { _currentLanguage = text; } + QString getCurrentLanguage() const { return _currentLanguage; } + void setCurrentLanguage(QString text) { _currentLanguage = text; } - QStringList getMessageSequence() const { return _messageSequence; } - void setMessageSequence(QStringList sequence) { _messageSequence = sequence; } + QStringList getMessageSequence() const { return _messageSequence; } + void setMessageSequence(QStringList sequence) { _messageSequence = sequence; } - QString getRepeatFlag() const { return _repeatString; } - void setRepeatFlag(QString value) { _repeatString = value; } + QString getRepeatFlag() const { return _repeatString; } + void setRepeatFlag(QString value) { _repeatString = value; } - bool getRepeatTimeout() const { return _repeatTimeout; } - void setRepeatTimeout(bool value) { _repeatTimeout = value; } + bool getRepeatTimeout() const { return _repeatTimeout; } + void setRepeatTimeout(bool value) { _repeatTimeout = value; } - int getExpireTimeout() const { return _expireTimeout; } - void setExpireTimeout(int value) { _expireTimeout = value; } + int getExpireTimeout() const { return _expireTimeout; } + void setExpireTimeout(int value) { _expireTimeout = value; } - bool getEnableFlag() const { return _enableFlag; } - void setEnableFlag(bool value) { _enableFlag = value; } + bool getEnableFlag() const { return _enableFlag; } + void setEnableFlag(bool value) { _enableFlag = value; } - void saveState(QSettings* settings) const; - void restoreState(QSettings* settings); - QString parseNotifyMessage(); + void saveState(QSettings* settings) const; + void restoreState(QSettings* settings); - QTimer* timer; - QTimer* expireTimer; - bool isNowPlaying; // - bool firstStart; + QString parseNotifyMessage(); + + QTimer* getTimer() const { return _timer; } + void startTimer(int value); + void stopTimer(); + void disposeTimer(); + + QTimer* getExpireTimer() const { return _expireTimer; } + void startExpireTimer(); + void stopExpireTimer(); + + void disposeExpireTimer(); + + bool isNowPlaying; + bool firstStart; private: + void checkSoundFilesExisting(); - QStringList _messageSequence; +private: + QTimer* _timer; - //! path to folder with sound files - QString _soundCollectionPath; + //! time from putting notification in queue till moment when notification became out-of-date + //! NOTE: each notification has it lifetime, this time setups individually for each notification + //! according to its priority + QTimer* _expireTimer; - //! language in what notifications will be spelled - QString _currentLanguage; - //! one UAV object per one notification - QString _dataObject; - //! one field value change can be assigned to one notification - QString _objectField; + QStringList _messageSequence; - //! poled UAV field value - QString _dataValue; + //! path to folder with sound files + QString _soundCollectionPath; - //! possible sounds(at least one required to play notification) - QString _sound1; - QString _sound2; - QString _sound3; + //! language in what notifications will be spelled + QString _currentLanguage; - //! order in what sounds 1-3 will be played - QString _sayOrder; + //! one UAV object per one notification + QString _dataObject; - double _spinBoxValue; + //! one field value change can be assigned to one notification + QString _objectField; - QString _repeatString; + //! poled UAV field value + QString _dataValue; - //! time when next notification must be fired - bool _repeatTimeout; + //! possible sounds(at least one required to play notification) + QString _sound1; + QString _sound2; + QString _sound3; - //! how often or what periodicaly notification should be played - int _repeatTimerValue; + //! order in what sounds 1-3 will be played + QString _sayOrder; - //! time after event occured till notification became invalid - //! and will be removed from list - int _expireTimeout; + double _spinBoxValue; - //! enables/disables playing of current notification - bool _enableFlag; + QString _repeatString; + + //! time when next notification must be fired + bool _repeatTimeout; + + //! how often or what periodicaly notification should be played + int _repeatTimerValue; + + //! time after event occured till notification became invalid + //! and will be removed from list + int _expireTimeout; + + //! enables/disables playing of current notification + bool _enableFlag; }; Q_DECLARE_METATYPE(NotificationItem*) diff --git a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp index 8d5cb25e3..69f085620 100644 --- a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp @@ -25,219 +25,277 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "NotificationItem.h" +#include "notificationitem.h" +#include "notifylogging.h" #include #include #include "utils/pathutils.h" -NotificationItem::NotificationItem(QObject *parent) : - QObject(parent), - isNowPlaying(0), - firstStart(1), - _soundCollectionPath(""), - _currentLanguage("default"), - _dataObject(""), - _objectField(""), - _dataValue("Equal to"), - _sound1(""), - _sound2(""), - _sound3(""), - _sayOrder("Never"), - _spinBoxValue(0), - _repeatString("Repeat Instantly"), - _repeatTimeout(true), - _expireTimeout(15) +NotificationItem::NotificationItem(QObject *parent) + : QObject(parent) + , isNowPlaying(0) + , firstStart(true) + , _soundCollectionPath("") + , _currentLanguage("default") + , _dataObject("") + , _objectField("") + , _dataValue("Equal to") + , _sound1("") + , _sound2("") + , _sound3("") + , _sayOrder("Never") + , _spinBoxValue(0) + , _repeatString("Repeat Instantly") + , _repeatTimeout(true) + , _expireTimeout(15) { - timer = NULL; - expireTimer = NULL; + _timer = NULL; + _expireTimer = NULL; } void NotificationItem::copyTo(NotificationItem* that) const { - - that->isNowPlaying = isNowPlaying; - that->firstStart = firstStart; - that->_soundCollectionPath = _soundCollectionPath; - that->_currentLanguage = _currentLanguage; - that->_soundCollectionPath = _soundCollectionPath; - that->_dataObject = _dataObject; - that->_objectField = _objectField; - that->_dataValue = _dataValue; - that->_sound1 = _sound1; - that->_sound2 = _sound2; - that->_sound3 = _sound3; - that->_sayOrder = _sayOrder; - that->_spinBoxValue = _spinBoxValue; - that->_repeatString = _repeatString; - that->_repeatTimeout = _repeatTimeout; - that->_expireTimeout = _expireTimeout; + that->isNowPlaying = isNowPlaying; + that->firstStart = firstStart; + that->_soundCollectionPath = _soundCollectionPath; + that->_currentLanguage = _currentLanguage; + that->_soundCollectionPath = _soundCollectionPath; + that->_dataObject = _dataObject; + that->_objectField = _objectField; + that->_dataValue = _dataValue; + that->_sound1 = _sound1; + that->_sound2 = _sound2; + that->_sound3 = _sound3; + that->_sayOrder = _sayOrder; + that->_spinBoxValue = _spinBoxValue; + that->_repeatString = _repeatString; + that->_repeatTimeout = _repeatTimeout; + that->_expireTimeout = _expireTimeout; } void NotificationItem::saveState(QSettings* settings) const { - settings->setValue("SoundCollectionPath", Utils::PathUtils().RemoveDataPath(getSoundCollectionPath())); - settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage()); - settings->setValue(QLatin1String("ObjectField"), getObjectField()); - settings->setValue(QLatin1String("DataObject"), getDataObject()); - settings->setValue(QLatin1String("Value"), getValue()); - settings->setValue(QLatin1String("ValueSpinBox"), getSpinBoxValue()); - settings->setValue(QLatin1String("Sound1"), getSound1()); - settings->setValue(QLatin1String("Sound2"), getSound2()); - settings->setValue(QLatin1String("Sound3"), getSound3()); - settings->setValue(QLatin1String("SayOrder"), getSayOrder()); - settings->setValue(QLatin1String("Repeat"), getRepeatFlag()); - settings->setValue(QLatin1String("ExpireTimeout"), getExpireTimeout()); + settings->setValue("SoundCollectionPath", Utils::PathUtils().RemoveDataPath(getSoundCollectionPath())); + settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage()); + settings->setValue(QLatin1String("ObjectField"), getObjectField()); + settings->setValue(QLatin1String("DataObject"), getDataObject()); + settings->setValue(QLatin1String("Value"), getValue()); + settings->setValue(QLatin1String("ValueSpinBox"), getSpinBoxValue()); + settings->setValue(QLatin1String("Sound1"), getSound1()); + settings->setValue(QLatin1String("Sound2"), getSound2()); + settings->setValue(QLatin1String("Sound3"), getSound3()); + settings->setValue(QLatin1String("SayOrder"), getSayOrder()); + settings->setValue(QLatin1String("Repeat"), getRepeatFlag()); + settings->setValue(QLatin1String("ExpireTimeout"), getExpireTimeout()); } void NotificationItem::restoreState(QSettings* settings) { - //settings = Core::ICore::instance()->settings(); - setSoundCollectionPath(Utils::PathUtils().InsertDataPath(settings->value(QLatin1String("SoundCollectionPath"), tr("")).toString())); - setCurrentLanguage(settings->value(QLatin1String("CurrentLanguage"), tr("")).toString()); - setDataObject(settings->value(QLatin1String("DataObject"), tr("")).toString()); - setObjectField(settings->value(QLatin1String("ObjectField"), tr("")).toString()); - setValue(settings->value(QLatin1String("Value"), tr("")).toString()); - setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString()); - setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString()); - setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString()); - setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString()); - setSpinBoxValue(settings->value(QLatin1String("ValueSpinBox"), tr("")).toDouble()); - setRepeatFlag(settings->value(QLatin1String("Repeat"), tr("")).toString()); - setExpireTimeout(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt()); + //settings = Core::ICore::instance()->settings(); + setSoundCollectionPath(Utils::PathUtils().InsertDataPath(settings->value(QLatin1String("SoundCollectionPath"), tr("")).toString())); + setCurrentLanguage(settings->value(QLatin1String("CurrentLanguage"), tr("")).toString()); + setDataObject(settings->value(QLatin1String("DataObject"), tr("")).toString()); + setObjectField(settings->value(QLatin1String("ObjectField"), tr("")).toString()); + setValue(settings->value(QLatin1String("Value"), tr("")).toString()); + setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString()); + setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString()); + setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString()); + setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString()); + setSpinBoxValue(settings->value(QLatin1String("ValueSpinBox"), tr("")).toDouble()); + setRepeatFlag(settings->value(QLatin1String("Repeat"), tr("")).toString()); + setExpireTimeout(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt()); } +void NotificationItem::startTimer(int value) { + if (!_timer) { + _timer = new QTimer(this); + _timer->setInterval(value); + } + if (!_timer->isActive()) + _timer->start(); +} + +void NotificationItem::stopTimer() { + if (_timer) { + if (_timer->isActive()) + _timer->stop(); + } +} + +void NotificationItem::disposeTimer() { + if (_timer) { + _timer->stop(); + delete _timer; + _timer = NULL; + } +} + +void NotificationItem::startExpireTimer() { + if (!_expireTimer) + { + _expireTimer = new QTimer(this); + } + _expireTimer->start(_expireTimeout * 1000); +} + +void NotificationItem::stopExpireTimer() { + if (_expireTimer) { + if (_expireTimer) + _expireTimer->stop(); + } +} + +void NotificationItem::disposeExpireTimer() { + if (_expireTimer) { + _expireTimer->stop(); + delete _expireTimer; + _expireTimer = NULL; + } +} + QString NotificationItem::parseNotifyMessage() { - // tips: - // check of *.wav files exist needed for playing phonon queues; - // if phonon player don't find next file in queue, it buzz + // tips: + // check of *.wav files exist needed for playing phonon queues; + // if phonon player don't find next file in queue, it buzz - QString str,str1; - str1= getSayOrder(); - str = QString("%L1 ").arg(getSpinBoxValue()); - int position = 0xFF; - // generate queue of sound files to play - _messageSequence.clear(); + QString str,str1; + str1= getSayOrder(); + str = QString("%L1 ").arg(getSpinBoxValue()); + int position = 0xFF; + // generate queue of sound files to play + _messageSequence.clear(); - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")); - else - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")); + checkSoundFilesExisting(); - if("" != getSound2()) - { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")); - else - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")); - } + if(!_messageSequence.size()) { + qNotifyDebug() << "no any files in message queue"; + } - if("" != getSound3()) - { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")); - else - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")); - } + switch(str1.at(0).toAscii()) + { + case 'N'://NEVER: + str = getSound1()+" "+getSound2()+" "+getSound3(); + position = 0xFF; + break; - switch(str1.at(0).toAscii()) - { - case 'N'://NEVER: - str = getSound1()+" "+getSound2()+" "+getSound3(); - position = 0xFF; - break; + case 'B'://BEFORE: + str = QString("%L1 ").arg(getSpinBoxValue())+getSound1()+" "+getSound2()+" "+getSound3(); + position = 0; + break; - case 'B'://BEFORE: - str = QString("%L1 ").arg(getSpinBoxValue())+getSound1()+" "+getSound2()+" "+getSound3(); - position = 0; - break; + case 'A'://AFTER: + switch(str1.at(6).toAscii()) + { + case 'f': + str = getSound1()+QString(" %L1 ").arg(getSpinBoxValue())+getSound2()+" "+getSound3(); + position = 1; + break; + case 's': + str = getSound1()+" "+getSound2()+QString(" %L1").arg(getSpinBoxValue())+" "+getSound3(); + position = 2; + break; + case 't': + str = getSound1()+" "+getSound2()+" "+getSound3()+QString(" %L1").arg(getSpinBoxValue()); + position = 3; + break; + } + break; + } - case 'A'://AFTER: - switch(str1.at(6).toAscii()) - { - case 'f': - str = getSound1()+QString(" %L1 ").arg(getSpinBoxValue())+getSound2()+" "+getSound3(); - position = 1; - break; - case 's': - str = getSound1()+" "+getSound2()+QString(" %L1").arg(getSpinBoxValue())+" "+getSound3(); - position = 2; - break; - case 't': - str = getSound1()+" "+getSound2()+" "+getSound3()+QString(" %L1").arg(getSpinBoxValue()); - position = 3; - break; - } - break; - } + if(position != 0xFF) + { + QStringList numberParts = QString("%1").arg(getSpinBoxValue()).trimmed().split("."); + QStringList numberFiles; - if(position != 0xFF) - { - QStringList numberParts = QString("%1").arg(getSpinBoxValue()).trimmed().split("."); - QStringList numberFiles; + if((numberParts.at(0).size()==1) || (numberParts.at(0).toInt()<20)) + { + //if(numberParts.at(0)!="0") + numberFiles.append(numberParts.at(0)); + } else { + int i=0; + if(numberParts.at(0).right(2).toInt()<20 && numberParts.at(0).right(2).toInt()!=0) { + if(numberParts.at(0).right(2).toInt()<10) + numberFiles.append(numberParts.at(0).right(1)); + else + numberFiles.append(numberParts.at(0).right(2)); + i=2; + } + for(;i #include "notifyitemdelegate.h" #include "notifytablemodel.h" - +#include "notifylogging.h" NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent) - : QItemDelegate(parent) - , _parent(parent) - , _items(items) + : QItemDelegate(parent) + , _parent(parent) + , _items(items) { } -QWidget *NotifyItemDelegate::createEditor(QWidget* parent, - const QStyleOptionViewItem& /*none*/, - const QModelIndex& index) const +QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*none*/, + const QModelIndex& index) const { - if(eREPEAT_VALUE == index.column()) { - QComboBox* editor = new QComboBox(parent); - editor->clear(); - editor->addItems(_items); - return editor; - } else { - if(eEXPIRE_TIME == index.column()) { - QSpinBox* editor = new QSpinBox(parent); - connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); - return editor; - } else { - if(eENABLE_NOTIFICATION == index.column()) { - QCheckBox* editor = new QCheckBox(parent); - connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); - return editor; - } - } - } - QLineEdit *editor = new QLineEdit(parent); - return editor; + if (eREPEAT_VALUE == index.column()) { + QComboBox* editor = new QComboBox(parent); + editor->clear(); + editor->addItems(_items); + return editor; + } else { + if (eEXPIRE_TIME == index.column()) { + QSpinBox* editor = new QSpinBox(parent); + connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); + return editor; + } else { + if (eENABLE_NOTIFICATION == index.column()) { + QCheckBox* editor = new QCheckBox(parent); + connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); + return editor; + } + } + } + QLineEdit *editor = new QLineEdit(parent); + return editor; } void NotifyItemDelegate::commitAndCloseEditor() { - QLineEdit* editor = qobject_cast(sender()); - if (editor) { - emit commitData(editor); - emit closeEditor(editor); - } else { - QComboBox* editor = qobject_cast(sender()); - if (editor) - { - emit commitData(editor); - emit closeEditor(editor); - } else { - QSpinBox* editor = qobject_cast(sender()); - if (editor) - { - emit commitData(editor); - emit closeEditor(editor); - } else { - QCheckBox* editor = qobject_cast(sender()); - if (editor) - { - emit commitData(editor); - emit closeEditor(editor); - } - } - } - } + QLineEdit* editor = qobject_cast(sender()); + if (editor) { + emit commitData(editor); + emit closeEditor(editor); + } else { + QComboBox* editor = qobject_cast(sender()); + if (editor) + { + emit commitData(editor); + emit closeEditor(editor); + } else { + QSpinBox* editor = qobject_cast(sender()); + if (editor) + { + emit commitData(editor); + emit closeEditor(editor); + } else { + QCheckBox* editor = qobject_cast(sender()); + if (editor) + { + emit commitData(editor); + emit closeEditor(editor); + } + } + } + } } void NotifyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { - QLineEdit* edit = qobject_cast(editor); - if(edit) { - edit->setText(index.model()->data(index, Qt::EditRole).toString()); - } else { - QComboBox* repeatEditor = qobject_cast(editor); - if(repeatEditor) - repeatEditor->setCurrentIndex(repeatEditor->findText(index.model()->data(index, Qt::EditRole).toString())); - else { - QSpinBox* expireEditor = qobject_cast(editor); - if(expireEditor) - expireEditor->setValue(index.model()->data(index, Qt::EditRole).toInt()); - else { - QCheckBox* enablePlayEditor = qobject_cast(editor); - if (enablePlayEditor) - enablePlayEditor->setChecked(index.model()->data(index, Qt::EditRole).toBool()); - } - } - } + QLineEdit* edit = qobject_cast(editor); + if (edit) { + edit->setText(index.model()->data(index, Qt::EditRole).toString()); + } else { + QComboBox* repeatEditor = qobject_cast(editor); + if (repeatEditor) + repeatEditor->setCurrentIndex(repeatEditor->findText(index.model()->data(index, Qt::EditRole).toString())); + else { + QSpinBox* expireEditor = qobject_cast(editor); + if (expireEditor) + expireEditor->setValue(index.model()->data(index, Qt::EditRole).toInt()); + else { + QCheckBox* enablePlayEditor = qobject_cast(editor); + if (enablePlayEditor) + enablePlayEditor->setChecked(index.model()->data(index, Qt::EditRole).toBool()); + } + } + } } void NotifyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { - QLineEdit *edit = qobject_cast(editor); - if(edit) { - model->setData(index, edit->text()); - } else { - QComboBox * repeatEditor = qobject_cast(editor); - if(repeatEditor) { - model->setData(index, repeatEditor->currentText()); - } else { - QSpinBox * expireEditor = qobject_cast(editor); - if(expireEditor) { - model->setData(index, expireEditor->value(), Qt::EditRole); - } else { - QCheckBox* enablePlayEditor = qobject_cast(editor); - if (enablePlayEditor) { - model->setData(index, enablePlayEditor->isChecked(), Qt::EditRole); - } - } - } - } + QLineEdit *edit = qobject_cast(editor); + if (edit) { + model->setData(index, edit->text()); + } else { + QComboBox * repeatEditor = qobject_cast(editor); + if (repeatEditor) { + model->setData(index, repeatEditor->currentText()); + } else { + QSpinBox * expireEditor = qobject_cast(editor); + if (expireEditor) { + model->setData(index, expireEditor->value(), Qt::EditRole); + } else { + QCheckBox* enablePlayEditor = qobject_cast(editor); + if (enablePlayEditor) { + model->setData(index, enablePlayEditor->isChecked(), Qt::EditRole); + } + } + } + } } -void NotifyItemDelegate::selectRow(const QString & text) +void NotifyItemDelegate::selectRow(const QString& text) { - QComboBox* combo = qobject_cast(sender()); - QTableWidget* table = new QTableWidget; - table = (QTableWidget*)(combo->parent()); + QComboBox* combo = qobject_cast(sender()); + QTableWidget* table = new QTableWidget; + table = (QTableWidget*)(combo->parent()); - qDebug() << table->columnCount(); - qDebug() << table->rowCount(); - qDebug() << table->currentRow(); + qNotifyDebug() << table->columnCount(); + qNotifyDebug() << table->rowCount(); + qNotifyDebug() << table->currentRow(); } -QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem & option, - const QModelIndex & index) const +QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { - QSize s = QItemDelegate::sizeHint(option, index); - s.setHeight(10); - return s; + QSize s = QItemDelegate::sizeHint(option, index); + s.setHeight(10); + return s; } diff --git a/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp b/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp new file mode 100644 index 000000000..616b2ada5 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp @@ -0,0 +1,42 @@ +/** + ****************************************************************************** + * + * @file notifylogging.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Uses to logging only inside notify plugin, + * can be convinient turned on/off + * @see The GNU Public License (GPL) Version 3 + * @defgroup notifyplugin + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "notifylogging.h" + +#ifdef DEBUG_NOTIFIES +QDebug qNotifyDebug() +#endif +#ifndef DEBUG_NOTIFIES +QNoDebug qNotifyDebug() +#endif +{ +#ifdef DEBUG_NOTIFIES + return qDebug(); +#endif + return QNoDebug(); +} diff --git a/ground/openpilotgcs/src/plugins/notify/notifylogging.h b/ground/openpilotgcs/src/plugins/notify/notifylogging.h new file mode 100644 index 000000000..bf02b86df --- /dev/null +++ b/ground/openpilotgcs/src/plugins/notify/notifylogging.h @@ -0,0 +1,42 @@ +/** + ****************************************************************************** + * + * @file notifylogging.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Uses to logging only inside notify plugin, + * can be convinient turned on/off + * @see The GNU Public License (GPL) Version 3 + * @defgroup notifyplugin + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef NOTIFYLOGGING_H +#define NOTIFYLOGGING_H + +#include "QDebug.h" + +#ifdef DEBUG_NOTIFIES +QDebug qNotifyDebug(); +#endif +#ifndef DEBUG_NOTIFIES +QNoDebug qNotifyDebug(); +#endif + + +#endif // NOTIFYLOGGING_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp index c959925b4..9eef49dec 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp @@ -28,6 +28,7 @@ #include "notifyplugin.h" #include "notificationitem.h" #include "notifypluginoptionspage.h" +#include "notifylogging.h" #include #include #include @@ -43,18 +44,6 @@ static const QString VERSION = "1.0.0"; //#define DEBUG_NOTIFIES -#ifdef DEBUG_NOTIFIES -QDebug qNotifyDebug() -#endif -#ifndef DEBUG_NOTIFIES -QNoDebug qNotifyDebug() -#endif -{ -#ifdef DEBUG_NOTIFIES - return qDebug(); -#endif - return QNoDebug(); -} SoundNotifyPlugin::SoundNotifyPlugin() { @@ -84,15 +73,15 @@ bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg) void SoundNotifyPlugin::extensionsInitialized() { - Core::ICore::instance()->readSettings(this); - if ( !configured ){ - readConfig_0_0_0(); - } + Core::ICore::instance()->readSettings(this); + if ( !configured ){ + readConfig_0_0_0(); + } - ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); - connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*))); - removedNotifies.clear(); - connectNotifications(); + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*))); + removedNotifies.clear(); + connectNotifications(); } void SoundNotifyPlugin::saveConfig( QSettings* settings, UAVConfigInfo *configInfo){ @@ -147,39 +136,39 @@ void SoundNotifyPlugin::readConfig( QSettings* settings, UAVConfigInfo *configIn void SoundNotifyPlugin::readConfig_0_0_0(){ - settings = Core::ICore::instance()->settings(); - settings->beginGroup(QLatin1String("NotifyPlugin")); + settings = Core::ICore::instance()->settings(); + settings->beginGroup(QLatin1String("NotifyPlugin")); - settings->beginReadArray("Current"); - settings->setArrayIndex(0); - currentNotification.restoreState(settings); - settings->endArray(); + settings->beginReadArray("Current"); + settings->setArrayIndex(0); + currentNotification.restoreState(settings); + settings->endArray(); - // read list of notifications from settings - int size = settings->beginReadArray("listNotifies"); - for (int i = 0; i < size; ++i) { - settings->setArrayIndex(i); - NotificationItem* notification = new NotificationItem; - notification->restoreState(settings); - lstNotifications.append(notification); - } - settings->endArray(); - setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool()); - settings->endGroup(); - - ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); - connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*))); - removedNotifies.clear(); - connectNotifications(); - - configured = true; - } + // read list of notifications from settings + int size = settings->beginReadArray("listNotifies"); + for (int i = 0; i < size; ++i) { + settings->setArrayIndex(i); + NotificationItem* notification = new NotificationItem; + notification->restoreState(settings); + lstNotifications.append(notification); + } + settings->endArray(); + setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool()); + settings->endGroup(); + + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*))); + removedNotifies.clear(); + connectNotifications(); + + configured = true; +} void SoundNotifyPlugin::onTelemetryManagerAdded(QObject* obj) { - telMngr = qobject_cast(obj); - if(telMngr) - connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); + telMngr = qobject_cast(obj); + if (telMngr) + connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); } void SoundNotifyPlugin::shutdown() @@ -189,86 +178,76 @@ void SoundNotifyPlugin::shutdown() void SoundNotifyPlugin::onAutopilotDisconnect() { - connectNotifications(); + connectNotifications(); } /*! - clear any notify timers from previous flight; - reset will be perform on start of option page + clear any notify timers from previous flight; + reset will be perform on start of option page */ void SoundNotifyPlugin::resetNotification(void) { - //first, reject empty args and unknown fields. - foreach(NotificationItem* notify,lstNotifications) { - if(notify->timer) - { - disconnect(notify->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); - notify->timer->stop(); - delete notify->timer; - notify->timer = NULL; - } - if(notify->expireTimer) - { - disconnect(notify->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler())); - notify->expireTimer->stop(); - delete notify->expireTimer; - notify->expireTimer = NULL; - } - } + //first, reject empty args and unknown fields. + foreach(NotificationItem* ntf, lstNotifications) { + ntf->disposeTimer(); + disconnect(ntf->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); + ntf->disposeExpireTimer(); + disconnect(ntf->getExpireTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); + } } /*! - update list of notifies; - will be perform on OK or APPLY press of option page + update list of notifies; + will be perform on OK or APPLY press of option page */ void SoundNotifyPlugin::updateNotificationList(QList list) { - removedNotifies.clear(); - resetNotification(); - lstNotifications.clear(); - lstNotifications=list; - connectNotifications(); + removedNotifies.clear(); + resetNotification(); + lstNotifications.clear(); + lstNotifications=list; + connectNotifications(); - Core::ICore::instance()->saveSettings(this); + Core::ICore::instance()->saveSettings(this); } void SoundNotifyPlugin::connectNotifications() { - foreach(UAVDataObject* obj,lstNotifiedUAVObjects) { - if (obj != NULL) - disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(appendNotification(UAVObject*))); - } - if(phonon.mo != NULL) { - delete phonon.mo; - phonon.mo = NULL; - } + foreach(UAVDataObject* obj,lstNotifiedUAVObjects) { + if (obj != NULL) + disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(appendNotification(UAVObject*))); + } + if (phonon.mo != NULL) { + delete phonon.mo; + phonon.mo = NULL; + } - if(!enableSound) return; + if (!enableSound) return; - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objManager = pm->getObject(); - lstNotifiedUAVObjects.clear(); - pendingNotifications.clear(); - lstNotifications.append(removedNotifies); - removedNotifies.clear(); + lstNotifiedUAVObjects.clear(); + pendingNotifications.clear(); + lstNotifications.append(removedNotifies); + removedNotifies.clear(); - //first, reject empty args and unknown fields. - foreach(NotificationItem* notify, lstNotifications) { - notify->firstStart=true; - notify->isNowPlaying=false; + //first, reject empty args and unknown fields. + foreach(NotificationItem* notify, lstNotifications) { + notify->firstStart=true; + notify->isNowPlaying=false; - UAVDataObject* obj = dynamic_cast( objManager->getObject(notify->getDataObject()) ); - if (obj != NULL ) { - if(!lstNotifiedUAVObjects.contains(obj)) { - lstNotifiedUAVObjects.append(obj); - connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); - } - } else - std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl; - } + UAVDataObject* obj = dynamic_cast( objManager->getObject(notify->getDataObject()) ); + if (obj != NULL ) { + if (!lstNotifiedUAVObjects.contains(obj)) { + lstNotifiedUAVObjects.append(obj); + connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); + } + } else + std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl; + } - if(lstNotifications.isEmpty()) return; + if (lstNotifications.isEmpty()) return; // set notification message to current event phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory); phonon.mo->clearQueue(); @@ -284,80 +263,73 @@ void SoundNotifyPlugin::connectNotifications() void SoundNotifyPlugin::appendNotification(UAVObject *object) { - disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); + disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); - foreach(NotificationItem* notification, lstNotifications) { - if(object->getName()!=notification->getDataObject()) - continue; + foreach(NotificationItem* ntf, lstNotifications) { + if (object->getName() != ntf->getDataObject()) + continue; - if(nowPlayingConfiguration == notification) - continue; + if (nowPlayingConfiguration == ntf) + continue; - if(notification->getRepeatFlag()!= "Repeat Instantly" && - notification->getRepeatFlag()!= "Repeat Once" && !notification->firstStart) - continue; + if (ntf->getRepeatFlag()!= "Repeat Instantly" && + ntf->getRepeatFlag()!= "Repeat Once" && !ntf->firstStart) + continue; - checkNotificationRule(notification,object); - } - connect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); + checkNotificationRule(ntf,object); + } + connect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); } void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UAVObject* object) { - bool condition=false; - double threshold; - QString direction; - QString fieldName; - threshold = notification->getSpinBoxValue(); - direction = notification->getValue(); - fieldName = notification->getObjectField(); - UAVObjectField* field = object->getField(fieldName); - if (field->getName()!="") { - double value = field->getDouble(); + bool condition=false; + double threshold; + QString direction; + QString fieldName; + threshold = notification->getSpinBoxValue(); + direction = notification->getValue(); + fieldName = notification->getObjectField(); + UAVObjectField* field = object->getField(fieldName); + if (field->getName()!="") { + double value = field->getDouble(); - switch(direction[0].toAscii()) - { - case 'E': - if(value==threshold) - condition = true; - break; - case 'G': - if(value>threshold) - condition = true; - break; - case 'L': - if(valuethreshold) + condition = true; + break; + case 'L': + if (valuetimer) - if(notification->timer->isActive()) - notification->timer->stop(); -#ifdef DEBUG_NOTIFIES - qDebug() << "add to pending list - " << notification->parseNotifyMessage(); -#endif - // if audio is busy, start expiration timer - //ms = (notification->getExpiredTimeout()[in sec])*1000 - //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); - pendingNotifications.append(notification); - if(!notification->expireTimer) - { - notification->expireTimer = new QTimer(notification); - connect(notification->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler())); - } - notification->expireTimer->start(notification->getExpireTimeout()*1000); - } - } - } + if (condition) + { + if (!playNotification(notification)) + { + if (!pendingNotifications.contains(notification)) + { + notification->stopTimer(); + + qNotifyDebug() << "add to pending list - " << notification->parseNotifyMessage(); + // if audio is busy, start expiration timer + //ms = (notification->getExpiredTimeout()[in sec])*1000 + //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); + pendingNotifications.append(notification); + notification->startExpireTimer(); + connect(notification->getExpireTimer(), SIGNAL(timeout()), this, SLOT(expireTimerHandler())); + } + } + } } bool SoundNotifyPlugin::playNotification(NotificationItem* notification) @@ -366,132 +338,112 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification) if (phonon.mo == NULL) return false; - if(!notification->getEnableFlag()) return true; + if (!notification->getEnableFlag()) return true; -#ifdef DEBUG_NOTIFIES - qDebug() << "Phonon State: " << phonon.mo->state(); -#endif - if((phonon.mo->state()==Phonon::PausedState) - || (phonon.mo->state()==Phonon::StoppedState) - || phonon.firstPlay) - { - // don't fire expire timer - nowPlayingConfiguration = notification; - if(notification->expireTimer) - notification->expireTimer->stop(); + qNotifyDebug() << "Phonon State: " << phonon.mo->state(); + if ((phonon.mo->state()==Phonon::PausedState) + || (phonon.mo->state()==Phonon::StoppedState) + || phonon.firstPlay) + { + // don't fire expire timer + nowPlayingConfiguration = notification; + notification->stopExpireTimer(); - if(notification->getRepeatFlag()=="Repeat Once") - { - removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification))); - } - else { - if(notification->getRepeatFlag()!="Repeat Instantly") - { - QRegExp rxlen("(\\d+)"); - QString value; - int timer_value; - int pos = rxlen.indexIn(notification->getRepeatFlag()); - if (pos > -1) { - value = rxlen.cap(1); // "189" - timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage - } + if (notification->getRepeatFlag()=="Repeat Once") { + removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification))); + } else { + if (notification->getRepeatFlag()!="Repeat Instantly") + { + QRegExp rxlen("(\\d+)"); + QString value; + int timer_value; + int pos = rxlen.indexIn(notification->getRepeatFlag()); + if (pos > -1) { + value = rxlen.cap(1); // "189" + timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage + } - if(!notification->timer) - { - notification->timer = new QTimer(notification); - notification->timer->setInterval(timer_value); - connect(notification->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); - } - if(!notification->timer->isActive()) - notification->timer->start(); - } - } - notification->firstStart=false; - phonon.mo->clear(); - QString str = notification->parseNotifyMessage(); - qNotifyDebug() << "play notification - " << str; + notification->startTimer(timer_value); + connect(notification->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); + } + } + notification->firstStart=false; + phonon.mo->clear(); + QString str = notification->parseNotifyMessage(); + qNotifyDebug() << "play notification - " << str; + foreach (QString item, notification->getMessageSequence()) { + Phonon::MediaSource *ms = new Phonon::MediaSource(item); + ms->setAutoDelete(true); + phonon.mo->enqueue(*ms); + } + phonon.mo->play(); + phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before + // the state is not "Loading" anymore. + } + else + return false; // if audio is busy - foreach(QString item, notification->getMessageSequence()) { - Phonon::MediaSource *ms = new Phonon::MediaSource(item); - ms->setAutoDelete(true); - phonon.mo->enqueue(*ms); - } - phonon.mo->play(); - phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before - // the state is not "Loading" anymore. - } - else - return false; // if audio is busy - - return true; + return true; } void SoundNotifyPlugin::repeatTimerHandler() { NotificationItem* notification = static_cast(sender()->parent()); -#ifdef DEBUG_NOTIFIES - qDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage(); -#endif - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + + qNotifyDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage(); + + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject(); UAVObject* object = objManager->getObject(notification->getDataObject()); - if(object) + if (object) checkNotificationRule(notification,object); } void SoundNotifyPlugin::expireTimerHandler() { - // fire expire timer - NotificationItem* notification = static_cast(sender()->parent()); - notification->expireTimer->stop(); + // fire expire timer + NotificationItem* notification = static_cast(sender()->parent()); + notification->stopExpireTimer(); - if(!pendingNotifications.isEmpty()) - { -#ifdef DEBUG_NOTIFIES - qDebug() << "expireTimerHandler - " << notification->parseNotifyMessage(); -#endif - pendingNotifications.removeOne(notification); - } + if (!pendingNotifications.isEmpty()) { + qNotifyDebug() << "expireTimerHandler - " << notification->parseNotifyMessage(); + pendingNotifications.removeOne(notification); + } } void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldstate) { Q_UNUSED(oldstate) -#ifdef DEBUG_NOTIFIES - qDebug() << "File length (ms): " << phonon.mo->totalTime(); - qDebug() << "New State: " << newstate; -#endif + qNotifyDebug() << "File length (ms): " << phonon.mo->totalTime(); + qNotifyDebug() << "New State: " << newstate; #ifndef Q_OS_WIN - // This is a hack to force Linux to wait until the end of the - // wav file before moving to the next in the queue. - // I wish I did not have to go through a #define, but I did not - // manage to make this work on both platforms any other way! - if (phonon.mo->totalTime()>0) - phonon.mo->setTransitionTime(phonon.mo->totalTime()); + // This is a hack to force Linux to wait until the end of the + // wav file before moving to the next in the queue. + // I wish I did not have to go through a #define, but I did not + // manage to make this work on both platforms any other way! + if (phonon.mo->totalTime()>0) + phonon.mo->setTransitionTime(phonon.mo->totalTime()); #endif - if((newstate == Phonon::PausedState) || - (newstate == Phonon::StoppedState)) - { - nowPlayingConfiguration=NULL; - if(!pendingNotifications.isEmpty()) - { - NotificationItem* notification = pendingNotifications.takeFirst(); -#ifdef DEBUG_NOTIFIES - qDebug() << "play audioFree - " << notification->parseNotifyMessage(); -#endif - playNotification(notification); - } - } else if (newstate == Phonon::ErrorState) - { - if(phonon.mo->errorType()==0) { - qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType(); - phonon.mo->clearQueue(); - } - } -// if(newstate == Phonon::BufferingState) -// qDebug() << "Phonon::BufferingState!!!"; + if ((newstate == Phonon::PausedState) || + (newstate == Phonon::StoppedState)) + { + nowPlayingConfiguration=NULL; + if (!pendingNotifications.isEmpty()) + { + NotificationItem* notification = pendingNotifications.takeFirst(); + qNotifyDebug() << "play audioFree - " << notification->parseNotifyMessage(); + playNotification(notification); + } + } else { + if (newstate == Phonon::ErrorState) { + if (phonon.mo->errorType()==0) { + qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType(); + phonon.mo->clearQueue(); + } + } + } } Q_EXPORT_PLUGIN(SoundNotifyPlugin) diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h index c1e0ce620..1d9475469 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h @@ -49,7 +49,6 @@ typedef struct { } PhononObject, *pPhononObject; - class SoundNotifyPlugin : public Core::IConfigurablePlugin { Q_OBJECT diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index cee9a4027..caad0efff 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -64,68 +64,67 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) //main widget QWidget *optionsPageWidget = new QWidget; //main layout - options_page->setupUi(optionsPageWidget); + options_page->setupUi(optionsPageWidget); - delegateItems.clear(); - listSoundFiles.clear(); + delegateItems.clear(); + listSoundFiles.clear(); - delegateItems << "Repeat Once" - << "Repeat Instantly" - << "Repeat 10 seconds" - << "Repeat 30 seconds" - << "Repeat 1 minute"; + delegateItems << "Repeat Once" + << "Repeat Instantly" + << "Repeat 10 seconds" + << "Repeat 30 seconds" + << "Repeat 1 minute"; - options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); - options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); + options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); + options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); - // Fills the combo boxes for the UAVObjects - QList< QList > objList = objManager.getDataObjects(); - foreach (QList list, objList) { - foreach (UAVDataObject* obj, list) { - options_page->UAVObject->addItem(obj->getName()); - } - } + // Fills the combo boxes for the UAVObjects + QList< QList > objList = objManager.getDataObjects(); + foreach (QList list, objList) { + foreach (UAVDataObject* obj, list) { + options_page->UAVObject->addItem(obj->getName()); + } + } - connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); - connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); - connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); + connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); + connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); + connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); - connect(this, SIGNAL(updateNotifications(QList)), - owner, SLOT(updateNotificationList(QList))); - connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); + connect(this, SIGNAL(updateNotifications(QList)), + owner, SLOT(updateNotificationList(QList))); + //connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); - //emit resetNotification(); - privListNotifications.clear(); + privListNotifications.clear(); - for (int i = 0; i < owner->getListNotifications().size(); ++i) { - NotificationItem* notification = new NotificationItem(); - owner->getListNotifications().at(i)->copyTo(notification); - privListNotifications.append(notification); - } + for (int i = 0; i < owner->getListNotifications().size(); ++i) { + NotificationItem* notification = new NotificationItem(); + owner->getListNotifications().at(i)->copyTo(notification); + privListNotifications.append(notification); + } - updateConfigView(owner->getCurrentNotification()); + updateConfigView(owner->getCurrentNotification()); - initButtons(); - initRulesTableModel(); - initRulesTableView(); - initPhononPlayer(); + initButtons(); + initRulesTableModel(); + initRulesTableView(); + initPhononPlayer(); - return optionsPageWidget; + return optionsPageWidget; } void NotifyPluginOptionsPage::initButtons() { - options_page->chkEnableSound->setChecked(owner->getEnableSound()); - connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); + options_page->chkEnableSound->setChecked(owner->getEnableSound()); + connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); - options_page->buttonModify->setEnabled(false); - options_page->buttonDelete->setEnabled(false); - options_page->buttonPlayNotification->setEnabled(false); - connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); - connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); - connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); - connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); + options_page->buttonModify->setEnabled(false); + options_page->buttonDelete->setEnabled(false); + options_page->buttonPlayNotification->setEnabled(false); + connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); + connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); + connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); + connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); } void NotifyPluginOptionsPage::initPhononPlayer() @@ -150,32 +149,32 @@ void NotifyPluginOptionsPage::initRulesTableModel() void NotifyPluginOptionsPage::initRulesTableView() { - options_page->notifyRulesView->setModel(notifyRulesModel.data()); - options_page->notifyRulesView->resizeRowsToContents(); - options_page->notifyRulesView->setSelectionModel(notifyRulesSelection); - options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); + options_page->notifyRulesView->setModel(notifyRulesModel.data()); + options_page->notifyRulesView->resizeRowsToContents(); + options_page->notifyRulesView->setSelectionModel(notifyRulesSelection); + options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); - options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); - options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); - options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); - options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); - options_page->notifyRulesView->setDragEnabled(true); - options_page->notifyRulesView->setAcceptDrops(true); - options_page->notifyRulesView->setDropIndicatorShown(true); + options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); + options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); + options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); + options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); + options_page->notifyRulesView->setDragEnabled(true); + options_page->notifyRulesView->setAcceptDrops(true); + options_page->notifyRulesView->setDropIndicatorShown(true); } void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) { - notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); - notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); - notification->setDataObject(options_page->UAVObject->currentText()); - notification->setObjectField(options_page->UAVObjectField->currentText()); - notification->setSound1(options_page->Sound1->currentText()); - notification->setSound2(options_page->Sound2->currentText()); - notification->setSound3(options_page->Sound3->currentText()); - notification->setSayOrder(options_page->SayOrder->currentText()); - notification->setValue(options_page->Value->currentText()); - notification->setSpinBoxValue(options_page->ValueSpinBox->value()); + notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); + notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); + notification->setDataObject(options_page->UAVObject->currentText()); + notification->setObjectField(options_page->UAVObjectField->currentText()); + notification->setSound1(options_page->Sound1->currentText()); + notification->setSound2(options_page->Sound2->currentText()); + notification->setSound3(options_page->Sound3->currentText()); + notification->setSayOrder(options_page->SayOrder->currentText()); + notification->setValue(options_page->Value->currentText()); + notification->setSpinBoxValue(options_page->ValueSpinBox->value()); } @@ -185,19 +184,19 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio */ void NotifyPluginOptionsPage::apply() { - getOptionsPageValues(owner->getCurrentNotification()); - owner->setEnableSound(options_page->chkEnableSound->isChecked()); - emit updateNotifications(privListNotifications); + getOptionsPageValues(owner->getCurrentNotification()); + owner->setEnableSound(options_page->chkEnableSound->isChecked()); + emit updateNotifications(privListNotifications); } void NotifyPluginOptionsPage::finish() { - disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - if (notifySound) { - notifySound->stop(); - notifySound->clear(); - } + disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(changeButtonText(Phonon::State,Phonon::State))); + if (notifySound) { + notifySound->stop(); + notifySound->clear(); + } } ////////////////////////////////////////////////////////////////////////////// @@ -205,247 +204,247 @@ void NotifyPluginOptionsPage::finish() // combo box ////////////////////////////////////////////////////////////////////////////// void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) { - options_page->UAVObjectField->clear(); - ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager* objManager = pm->getObject(); + options_page->UAVObjectField->clear(); + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager* objManager = pm->getObject(); UAVDataObject* obj = dynamic_cast( objManager->getObject(val) ); QList fieldList = obj->getFields(); foreach (UAVObjectField* field, fieldList) { - options_page->UAVObjectField->addItem(field->getName()); + options_page->UAVObjectField->addItem(field->getName()); } } // locate collection folder on disk void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path) { - QDir dirPath(path); - listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); - options_page->SoundCollectionList->clear(); - options_page->SoundCollectionList->addItems(listDirCollections); + QDir dirPath(path); + listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + options_page->SoundCollectionList->clear(); + options_page->SoundCollectionList->addItems(listDirCollections); } void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) { - options_page->SoundCollectionList->setCurrentIndex(index); + options_page->SoundCollectionList->setCurrentIndex(index); currentCollectionPath = options_page->SoundDirectoryPathChooser->path() + QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText()); - QDir dirPath(currentCollectionPath); - QStringList filters; - filters << "*.mp3" << "*.wav"; - dirPath.setNameFilters(filters); - listSoundFiles = dirPath.entryList(filters); - listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), ""); - options_page->Sound1->clear(); - options_page->Sound2->clear(); - options_page->Sound3->clear(); - options_page->Sound1->addItems(listSoundFiles); - options_page->Sound2->addItem(""); - options_page->Sound2->addItems(listSoundFiles); - options_page->Sound3->addItem(""); - options_page->Sound3->addItems(listSoundFiles); + QDir dirPath(currentCollectionPath); + QStringList filters; + filters << "*.mp3" << "*.wav"; + dirPath.setNameFilters(filters); + listSoundFiles = dirPath.entryList(filters); + listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), ""); + options_page->Sound1->clear(); + options_page->Sound2->clear(); + options_page->Sound3->clear(); + options_page->Sound1->addItems(listSoundFiles); + options_page->Sound2->addItem(""); + options_page->Sound2->addItems(listSoundFiles); + options_page->Sound3->addItem(""); + options_page->Sound3->addItems(listSoundFiles); } void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate) { - //Q_ASSERT(Phonon::ErrorState != newstate); + //Q_ASSERT(Phonon::ErrorState != newstate); - if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { - options_page->buttonPlayNotification->setText("Play"); - options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); - } else { - if (newstate == Phonon::PlayingState) { - options_page->buttonPlayNotification->setText("Stop"); - options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); - } - } + if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { + options_page->buttonPlayNotification->setText("Play"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); + } else { + if (newstate == Phonon::PlayingState) { + options_page->buttonPlayNotification->setText("Stop"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); + } + } } void NotifyPluginOptionsPage::onFinishedPlaying() { - notifySound->clear(); + notifySound->clear(); } void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() { - NotificationItem* notification = NULL; + NotificationItem* notification = NULL; - if (-1 == notifyRulesSelection->currentIndex().row()) - return; - notifySound->clearQueue(); - notification = privListNotifications.at(notifyRulesSelection->currentIndex().row()); - notification->parseNotifyMessage(); - QStringList sequence = notification->getMessageSequence(); - Q_ASSERT(!!sequence.size()); - foreach(QString item, sequence) - notifySound->enqueue(Phonon::MediaSource(item)); + if (-1 == notifyRulesSelection->currentIndex().row()) + return; + notifySound->clearQueue(); + notification = privListNotifications.at(notifyRulesSelection->currentIndex().row()); + notification->parseNotifyMessage(); + QStringList sequence = notification->getMessageSequence(); + Q_ASSERT(!!sequence.size()); + foreach(QString item, sequence) + notifySound->enqueue(Phonon::MediaSource(item)); - notifySound->play(); + notifySound->play(); } void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state) { - bool state1 = 1^state; + bool state1 = 1^state; - QList listOutputs = notifySound->outputPaths(); - Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink(); - audioOutput->setMuted(state1); + QList listOutputs = notifySound->outputPaths(); + Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink(); + audioOutput->setMuted(state1); } void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) { - QString path = notification->getSoundCollectionPath(); - if (path == "") { - //QDir dir = QDir::currentPath(); - //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; - path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); - } + QString path = notification->getSoundCollectionPath(); + if (path == "") { + //QDir dir = QDir::currentPath(); + //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; + path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); + } - options_page->SoundDirectoryPathChooser->setPath(path); + options_page->SoundDirectoryPathChooser->setPath(path); - if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){ - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); - } else { - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - } + if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){ + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); + } else { + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + } - if (options_page->UAVObject->findText(notification->getDataObject())!=-1){ - options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); - } + if (options_page->UAVObject->findText(notification->getDataObject())!=-1){ + options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); + } - // Now load the object field values: - options_page->UAVObjectField->clear(); - QString uavDataObject = notification->getDataObject(); - UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); - if (obj != NULL ) { - QList fieldList = obj->getFields(); - foreach (UAVObjectField* field, fieldList) { - options_page->UAVObjectField->addItem(field->getName()); - } - } + // Now load the object field values: + options_page->UAVObjectField->clear(); + QString uavDataObject = notification->getDataObject(); + UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); + if (obj != NULL ) { + QList fieldList = obj->getFields(); + foreach (UAVObjectField* field, fieldList) { + options_page->UAVObjectField->addItem(field->getName()); + } + } - if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) { - options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); - } + if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) { + options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); + } - if (-1 != options_page->Sound1->findText(notification->getSound1())) { - options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); - } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + if (-1 != options_page->Sound1->findText(notification->getSound1())) { + options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + } else { + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); - // don't show item if it wasn't find in stored location - //options_page->Sound1->setCurrentIndex(-1); - } + // don't show item if it wasn't find in stored location + //options_page->Sound1->setCurrentIndex(-1); + } - if (-1 != options_page->Sound2->findText(notification->getSound2())) { - options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); - } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + if (-1 != options_page->Sound2->findText(notification->getSound2())) { + options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + } else { + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); - // don't show item if it wasn't find in stored location - //options_page->Sound2->setCurrentIndex(-1); - } + // don't show item if it wasn't find in stored location + //options_page->Sound2->setCurrentIndex(-1); + } - if (-1 != options_page->Sound3->findText(notification->getSound3())) { - options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); - } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); - } + if (-1 != options_page->Sound3->findText(notification->getSound3())) { + options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + } else { + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + } - if (-1 != options_page->Value->findText(notification->getValue())) { - options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue())); - } + if (-1 != options_page->Value->findText(notification->getValue())) { + options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue())); + } - if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) { - options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder())); - } + if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) { + options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder())); + } - options_page->ValueSpinBox->setValue(notification->getSpinBoxValue()); + options_page->ValueSpinBox->setValue(notification->getSpinBoxValue()); } void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ) { - bool select = false; - notifySound->stop(); - if (selected.indexes().size()) { - select = true; - updateConfigView(privListNotifications.at(selected.indexes().at(0).row())); - } + bool select = false; + notifySound->stop(); + if (selected.indexes().size()) { + select = true; + updateConfigView(privListNotifications.at(selected.indexes().at(0).row())); + } - options_page->buttonModify->setEnabled(select); - options_page->buttonDelete->setEnabled(select); - options_page->buttonPlayNotification->setEnabled(select); + options_page->buttonModify->setEnabled(select); + options_page->buttonDelete->setEnabled(select); + options_page->buttonPlayNotification->setEnabled(select); } void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() { - NotificationItem* notification = new NotificationItem; + NotificationItem* notification = new NotificationItem; - if (options_page->SoundDirectoryPathChooser->path()=="") { - QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); - textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); - options_page->SoundDirectoryPathChooser->setPalette(textPalette); - options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder"); - return; - } + if (options_page->SoundDirectoryPathChooser->path()=="") { + QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); + textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); + options_page->SoundDirectoryPathChooser->setPalette(textPalette); + options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder"); + return; + } - notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); - notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); - notification->setDataObject(options_page->UAVObject->currentText()); - notification->setObjectField(options_page->UAVObjectField->currentText()); - notification->setValue(options_page->Value->currentText()); - notification->setSpinBoxValue(options_page->ValueSpinBox->value()); + notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); + notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); + notification->setDataObject(options_page->UAVObject->currentText()); + notification->setObjectField(options_page->UAVObjectField->currentText()); + notification->setValue(options_page->Value->currentText()); + notification->setSpinBoxValue(options_page->ValueSpinBox->value()); - if (options_page->Sound1->currentText().size() > 0) - notification->setSound1(options_page->Sound1->currentText()); + if (options_page->Sound1->currentText().size() > 0) + notification->setSound1(options_page->Sound1->currentText()); - notification->setSound2(options_page->Sound2->currentText()); - notification->setSound3(options_page->Sound3->currentText()); + notification->setSound2(options_page->Sound2->currentText()); + notification->setSound3(options_page->Sound3->currentText()); - if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second")) - || ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) { - return; - } else { - notification->setSayOrder(options_page->SayOrder->currentText()); - } - privListNotifications.append(notification); - emit entryAdded(privListNotifications.size() - 1); - notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), - QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); +if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second")) + || ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) { + return; + } else { + notification->setSayOrder(options_page->SayOrder->currentText()); + } + privListNotifications.append(notification); + emit entryAdded(privListNotifications.size() - 1); + notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() { - notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row()); - if (!notifyRulesModel->rowCount() - && (notifyRulesSelection->currentIndex().row() > 0 - && notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) ) - { - options_page->buttonDelete->setEnabled(false); - options_page->buttonModify->setEnabled(false); - options_page->buttonPlayNotification->setEnabled(false); - } + notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row()); + if (!notifyRulesModel->rowCount() + && (notifyRulesSelection->currentIndex().row() > 0 + && notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) ) + { + options_page->buttonDelete->setEnabled(false); + options_page->buttonModify->setEnabled(false); + options_page->buttonPlayNotification->setEnabled(false); + } } void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked() { - NotificationItem* notification = new NotificationItem; - getOptionsPageValues(notification); - notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag()); - privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification); - entryUpdated(notifyRulesSelection->currentIndex().row()); + NotificationItem* notification = new NotificationItem; + getOptionsPageValues(notification); + notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag()); + privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification); + entryUpdated(notifyRulesSelection->currentIndex().row()); } diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp.orig b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp.orig new file mode 100644 index 000000000..b91317c9f --- /dev/null +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp.orig @@ -0,0 +1,465 @@ +/** + ****************************************************************************** + * + * @file notifypluginoptionspage.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Notify Plugin options page + * @see The GNU Public License (GPL) Version 3 + * @defgroup notifyplugin + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "notifypluginoptionspage.h" +#include +#include "notificationitem.h" +#include "ui_notifypluginoptionspage.h" +#include "extensionsystem/pluginmanager.h" +#include "utils/pathutils.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "notifyplugin.h" +#include "notifyitemdelegate.h" +#include "notifytablemodel.h" + +NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) + : IOptionsPage(parent) + , objManager(*ExtensionSystem::PluginManager::instance()->getObject()) + , owner(qobject_cast(parent)) + , currentCollectionPath("") + , privListNotifications((qobject_cast(parent))->getListNotifications()) +{ +} + +NotifyPluginOptionsPage::~NotifyPluginOptionsPage() +{ +} + +//creates options page widget (uses the UI file) +QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) +{ + options_page.reset(new Ui::NotifyPluginOptionsPage()); + //main widget + QWidget *optionsPageWidget = new QWidget; + //main layout + options_page->setupUi(optionsPageWidget); + + delegateItems.clear(); + listSoundFiles.clear(); + + delegateItems << "Repeat Once" + << "Repeat Instantly" + << "Repeat 10 seconds" + << "Repeat 30 seconds" + << "Repeat 1 minute"; + + options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); + options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); + + // Fills the combo boxes for the UAVObjects + QList< QList > objList = objManager.getDataObjects(); + foreach (QList list, objList) { + foreach (UAVDataObject* obj, list) { + options_page->UAVObject->addItem(obj->getName()); + } + } + + connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); + connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); + connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); + + connect(this, SIGNAL(updateNotifications(QList)), + owner, SLOT(updateNotificationList(QList))); + connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); + + //emit resetNotification(); + + privListNotifications.clear(); + + for (int i = 0; i < owner->getListNotifications().size(); ++i) { + NotificationItem* notification = new NotificationItem(); + owner->getListNotifications().at(i)->copyTo(notification); + privListNotifications.append(notification); + } + + updateConfigView(owner->getCurrentNotification()); + + initButtons(); + initRulesTableModel(); + initRulesTableView(); + initPhononPlayer(); + + return optionsPageWidget; +} + +void NotifyPluginOptionsPage::initButtons() +{ + options_page->chkEnableSound->setChecked(owner->getEnableSound()); + connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); + + options_page->buttonModify->setEnabled(false); + options_page->buttonDelete->setEnabled(false); + options_page->buttonPlayNotification->setEnabled(false); + connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); + connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); + connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); + connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); +} + +void NotifyPluginOptionsPage::initPhononPlayer() +{ + notifySound = Phonon::createPlayer(Phonon::NotificationCategory); + connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(changeButtonText(Phonon::State,Phonon::State))); + connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); +} + +void NotifyPluginOptionsPage::initRulesTableModel() +{ + notifyRulesModel.reset(new NotifyTableModel(&privListNotifications)); + notifyRulesSelection = new QItemSelectionModel(notifyRulesModel.data()); + connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), + this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); + connect(this, SIGNAL(entryUpdated(int)), + notifyRulesModel.data(), SLOT(entryUpdated(int))); + connect(this, SIGNAL(entryAdded(int)), + notifyRulesModel.data(), SLOT(entryAdded(int))); +} + +void NotifyPluginOptionsPage::initRulesTableView() +{ + options_page->notifyRulesView->setModel(notifyRulesModel.data()); + options_page->notifyRulesView->resizeRowsToContents(); + options_page->notifyRulesView->setSelectionModel(notifyRulesSelection); + options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); + + options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); + options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); + options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); + options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); + options_page->notifyRulesView->setDragEnabled(true); + options_page->notifyRulesView->setAcceptDrops(true); + options_page->notifyRulesView->setDropIndicatorShown(true); +} + +void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) +{ + notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); + notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); + notification->setDataObject(options_page->UAVObject->currentText()); + notification->setObjectField(options_page->UAVObjectField->currentText()); + notification->setSound1(options_page->Sound1->currentText()); + notification->setSound2(options_page->Sound2->currentText()); + notification->setSound3(options_page->Sound3->currentText()); + notification->setSayOrder(options_page->SayOrder->currentText()); + notification->setValue(options_page->Value->currentText()); + notification->setSpinBoxValue(options_page->ValueSpinBox->value()); + +} + +/*! +* Called when the user presses apply or OK. +* Saves the current values +*/ +void NotifyPluginOptionsPage::apply() +{ + getOptionsPageValues(owner->getCurrentNotification()); + owner->setEnableSound(options_page->chkEnableSound->isChecked()); + emit updateNotifications(privListNotifications); +} + +void NotifyPluginOptionsPage::finish() +{ + disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(changeButtonText(Phonon::State,Phonon::State))); + if (notifySound) { + notifySound->stop(); + notifySound->clear(); + } +} + +////////////////////////////////////////////////////////////////////////////// +// Fills in the combo box when value is changed in the +// combo box +////////////////////////////////////////////////////////////////////////////// +void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) { + options_page->UAVObjectField->clear(); + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager* objManager = pm->getObject(); + UAVDataObject* obj = dynamic_cast( objManager->getObject(val) ); + QList fieldList = obj->getFields(); + foreach (UAVObjectField* field, fieldList) { + options_page->UAVObjectField->addItem(field->getName()); + } +} + +// locate collection folder on disk +void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path) +{ + QDir dirPath(path); + listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + options_page->SoundCollectionList->clear(); + options_page->SoundCollectionList->addItems(listDirCollections); +} + + +void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) +{ + options_page->SoundCollectionList->setCurrentIndex(index); + + currentCollectionPath = options_page->SoundDirectoryPathChooser->path() + + QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText()); + + QDir dirPath(currentCollectionPath); + QStringList filters; + filters << "*.mp3" << "*.wav"; + dirPath.setNameFilters(filters); + listSoundFiles = dirPath.entryList(filters); + listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), ""); + + options_page->Sound1->clear(); + options_page->Sound2->clear(); + options_page->Sound3->clear(); + options_page->Sound1->addItems(listSoundFiles); + options_page->Sound2->addItem(""); + options_page->Sound2->addItems(listSoundFiles); + options_page->Sound3->addItem(""); + options_page->Sound3->addItems(listSoundFiles); + +} + +void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate) +{ + //Q_ASSERT(Phonon::ErrorState != newstate); + + if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { + options_page->buttonPlayNotification->setText("Play"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); + } else { + if (newstate == Phonon::PlayingState) { + options_page->buttonPlayNotification->setText("Stop"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); + } + } +} + +void NotifyPluginOptionsPage::onFinishedPlaying() +{ + notifySound->clear(); +} + +void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() +{ + NotificationItem* notification = NULL; + + if (-1 == notifyRulesSelection->currentIndex().row()) + return; + notifySound->clearQueue(); + notification = privListNotifications.at(notifyRulesSelection->currentIndex().row()); + notification->parseNotifyMessage(); + QStringList sequence = notification->getMessageSequence(); + Q_ASSERT(!!sequence.size()); + foreach(QString item, sequence) + notifySound->enqueue(Phonon::MediaSource(item)); + + notifySound->play(); +} + +void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state) +{ + bool state1 = 1^state; + + QList listOutputs = notifySound->outputPaths(); + Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink(); + audioOutput->setMuted(state1); +} + +void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) +{ + QString path = notification->getSoundCollectionPath(); + if (path == "") { + //QDir dir = QDir::currentPath(); + //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; + path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); + } + + options_page->SoundDirectoryPathChooser->setPath(path); + + if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){ + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); + } else { + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + } + + if (options_page->UAVObject->findText(notification->getDataObject())!=-1){ + options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); + } + +<<<<<<< Updated upstream + // Now load the object field values: + options_page->UAVObjectField->clear(); + QString uavDataObject = notification->getDataObject(); + UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); + if (obj != NULL ) { + QList fieldList = obj->getFields(); + foreach (UAVObjectField* field, fieldList) { + options_page->UAVObjectField->addItem(field->getName()); + } + } +======= + // Now load the object field values: + options_page->UAVObjectField->clear(); + QString uavDataObject = notification->getDataObject(); + UAVDataObject* obj = dynamic_cast( objManager->getObject(uavDataObject/*objList.at(0).at(0)->getName()*/) ); + if (obj != NULL ) { + QList fieldList = obj->getFields(); + foreach (UAVObjectField* field, fieldList) { + options_page->UAVObjectField->addItem(field->getName()); + } + } +>>>>>>> Stashed changes + + if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) { + options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); + } + + if (-1 != options_page->Sound1->findText(notification->getSound1())) { + options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + } else { + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + + // don't show item if it wasn't find in stored location + //options_page->Sound1->setCurrentIndex(-1); + } + + if (-1 != options_page->Sound2->findText(notification->getSound2())) { + options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + } else { + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + + // don't show item if it wasn't find in stored location + //options_page->Sound2->setCurrentIndex(-1); + } + + if (-1 != options_page->Sound3->findText(notification->getSound3())) { + options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + } else { + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + } + + if (-1 != options_page->Value->findText(notification->getValue())) { + options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue())); + } + + if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) { + options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder())); + } + + options_page->ValueSpinBox->setValue(notification->getSpinBoxValue()); +} + +void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ) +{ + bool select = false; + notifySound->stop(); + if (selected.indexes().size()) { + select = true; + updateConfigView(privListNotifications.at(selected.indexes().at(0).row())); + } + + options_page->buttonModify->setEnabled(select); + options_page->buttonDelete->setEnabled(select); + options_page->buttonPlayNotification->setEnabled(select); +} + + +void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() +{ + NotificationItem* notification = new NotificationItem; + + if (options_page->SoundDirectoryPathChooser->path()=="") { + QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); + textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); + options_page->SoundDirectoryPathChooser->setPalette(textPalette); + options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder"); + return; + } + + notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); + notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); + notification->setDataObject(options_page->UAVObject->currentText()); + notification->setObjectField(options_page->UAVObjectField->currentText()); + notification->setValue(options_page->Value->currentText()); + notification->setSpinBoxValue(options_page->ValueSpinBox->value()); + + if (options_page->Sound1->currentText().size() > 0) + notification->setSound1(options_page->Sound1->currentText()); + + notification->setSound2(options_page->Sound2->currentText()); + notification->setSound3(options_page->Sound3->currentText()); + + if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second")) + || ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) { + return; + } else { + notification->setSayOrder(options_page->SayOrder->currentText()); + } + privListNotifications.append(notification); + emit entryAdded(privListNotifications.size() - 1); + notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); +} + + +void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() +{ + notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row()); + if (!notifyRulesModel->rowCount() + && (notifyRulesSelection->currentIndex().row() > 0 + && notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) ) + { + options_page->buttonDelete->setEnabled(false); + options_page->buttonModify->setEnabled(false); + options_page->buttonPlayNotification->setEnabled(false); + } + +} + +void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked() +{ + NotificationItem* notification = new NotificationItem; + getOptionsPageValues(notification); + notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag()); + privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification); + entryUpdated(notifyRulesSelection->currentIndex().row()); + +} + diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h index 521cf9874..acb9f18e7 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h @@ -100,7 +100,7 @@ private: signals: void updateNotifications(QList list); - void resetNotification(void); + //void resetNotification(void); void entryUpdated(int index); void entryAdded(int position); diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp index f3c89b5b7..7c564a6df 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp @@ -31,82 +31,82 @@ NotifyTableModel::NotifyTableModel(QList* parentList, QObject* parent) : QAbstractTableModel(parent) { - _headerStrings << "Name" << "Repeats" << "Lifetime,sec" << "Enable"; - _list.reset(parentList); + _headerStrings << "Name" << "Repeats" << "Lifetime,sec" << "Enable"; + _list.reset(parentList); } bool NotifyTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (index.isValid() && role == Qt::EditRole) { - if(eREPEAT_VALUE == index.column()) - _list->at(index.row())->setRepeatFlag(value.toString()); - else { - if(eEXPIRE_TIME == index.column()) - _list->at(index.row())->setExpireTimeout(value.toInt()); - else { - if(eENABLE_NOTIFICATION == index.column()) - _list->at(index.row())->setEnableFlag(value.toBool()); - } - } - emit dataChanged(index, index); - return true; - } - return false; + if (index.isValid() && role == Qt::EditRole) { + if(eREPEAT_VALUE == index.column()) + _list->at(index.row())->setRepeatFlag(value.toString()); + else { + if(eEXPIRE_TIME == index.column()) + _list->at(index.row())->setExpireTimeout(value.toInt()); + else { + if(eENABLE_NOTIFICATION == index.column()) + _list->at(index.row())->setEnableFlag(value.toBool()); + } + } + emit dataChanged(index, index); + return true; + } + return false; } QVariant NotifyTableModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) { - qWarning() << "NotifyTableModel::data - index.isValid()"; - return QVariant(); - } + if (!index.isValid()) { + qWarning() << "NotifyTableModel::data - index.isValid()"; + return QVariant(); + } - if (index.row() >= _list->size()) - return QVariant(); + if (index.row() >= _list->size()) + return QVariant(); - if (role == Qt::DisplayRole || role == Qt::EditRole) - { - switch(index.column()) - { - case eMESSAGE_NAME: - return _list->at(index.row())->parseNotifyMessage(); + if (role == Qt::DisplayRole || role == Qt::EditRole) + { + switch(index.column()) + { + case eMESSAGE_NAME: + return _list->at(index.row())->parseNotifyMessage(); - case eREPEAT_VALUE: - return _list->at(index.row())->getRepeatFlag(); + case eREPEAT_VALUE: + return _list->at(index.row())->getRepeatFlag(); - case eEXPIRE_TIME: - return _list->at(index.row())->getExpireTimeout(); + case eEXPIRE_TIME: + return _list->at(index.row())->getExpireTimeout(); - case eENABLE_NOTIFICATION: - return _list->at(index.row())->getEnableFlag(); + case eENABLE_NOTIFICATION: + return _list->at(index.row())->getEnableFlag(); - default: - return QVariant(); - } - } - else - { - if (Qt::SizeHintRole == role){ - return QVariant(10); - } - } - return QVariant(); + default: + return QVariant(); + } + } + else + { + if (Qt::SizeHintRole == role){ + return QVariant(10); + } + } + return QVariant(); } QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (role != Qt::DisplayRole) - return QVariant(); + if (role != Qt::DisplayRole) + return QVariant(); - if (orientation == Qt::Horizontal) - return _headerStrings.at(section); - else - if(orientation == Qt::Vertical) - return QString("%1").arg(section); + if (orientation == Qt::Horizontal) + return _headerStrings.at(section); + else + if(orientation == Qt::Vertical) + return QString("%1").arg(section); - return QVariant(); + return QVariant(); } bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& index) @@ -132,11 +132,11 @@ bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex& ind void NotifyTableModel::entryUpdated(int offset) { - QModelIndex idx = index(offset, 0); - emit dataChanged(idx, idx); + QModelIndex idx = index(offset, 0); + emit dataChanged(idx, idx); } void NotifyTableModel::entryAdded(int position) { - insertRows(position, 1,QModelIndex()); + insertRows(position, 1,QModelIndex()); } From 1665ae8299645c94d7cb6d7081b624e8dafd65b0 Mon Sep 17 00:00:00 2001 From: Nickolay Date: Mon, 19 Sep 2011 00:26:49 +0300 Subject: [PATCH 5/9] +reordering add some changes; --- .../internals/projections/lks94projection.h | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h deleted file mode 100644 index efbe9c394..000000000 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h +++ /dev/null @@ -1,72 +0,0 @@ -/** -****************************************************************************** -* -* @file lks94projection.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. -* @brief -* @see The GNU Public License (GPL) Version 3 -* @defgroup OPMapWidget -* @{ -* -*****************************************************************************/ -/* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -* for more details. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#ifndef LKS94PROJECTION_H -#define LKS94PROJECTION_H -#include -#include "cmath" -#include "D:\!Work\OpenPilot\OpenPilot\ground\openpilotgcs\src\libs\opmapcontrol\src\internals\pureprojection.h" - - -namespace projections { -class LKS94Projection:public internals::PureProjection -{ -public: - LKS94Projection(); - double GetTileMatrixResolution(int const& zoom); - virtual QString Type(){return "LKS94Projection";} - virtual Size TileSize() const; - virtual double Axis() const; - virtual double Flattening() const; - virtual core::Point FromLatLngToPixel(double lat, double lng, int const& zoom); - virtual internals::PointLatLng FromPixelToLatLng(int const& x, int const& y, int const& zoom); - virtual double GetGroundResolution(int const& zoom, double const& latitude); - virtual Size GetTileMatrixMinXY(int const& zoom); - virtual Size GetTileMatrixMaxXY(int const& zoom); - -private: - const double MinLatitude; - const double MaxLatitude; - const double MinLongitude; - const double MaxLongitude; - const double orignX; - const double orignY; - Size tileSize; - QVector DTM10(const QVector & lonlat); - QVector MTD10(QVector & pnt); - QVector DTM00(QVector & lonlat); - QVector DTM01(QVector & lonlat); - QVector MTD01(QVector & pnt); - QVector MTD11(QVector & p); - double Clip(double const& n, double const& minValue, double const& maxValue); -}; - -} -#endif // LKS94PROJECTION_H - - - - From 1af42e1b32d9d95845f62aa724e4fc0248f4bb7b Mon Sep 17 00:00:00 2001 From: Nickolay Date: Mon, 19 Sep 2011 00:30:57 +0300 Subject: [PATCH 6/9] + notify table reordering some changes --- .../src/plugins/notify/NotificationItem.h | 30 ++- .../src/plugins/notify/notificationitem.cpp | 50 ++++- .../src/plugins/notify/notifyitemdelegate.cpp | 10 +- .../src/plugins/notify/notifyitemdelegate.h | 4 +- .../src/plugins/notify/notifylogging.cpp | 13 +- .../src/plugins/notify/notifylogging.h | 8 +- .../src/plugins/notify/notifyplugin.cpp | 88 ++++----- .../notify/notifypluginoptionspage.cpp | 83 ++++----- .../plugins/notify/notifypluginoptionspage.h | 19 +- .../src/plugins/notify/notifytablemodel.cpp | 175 ++++++++++++++++-- .../src/plugins/notify/notifytablemodel.h | 23 ++- 11 files changed, 350 insertions(+), 153 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h index ad7250060..da40d2afb 100644 --- a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h +++ b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h @@ -78,21 +78,22 @@ public: QStringList getMessageSequence() const { return _messageSequence; } void setMessageSequence(QStringList sequence) { _messageSequence = sequence; } - QString getRepeatFlag() const { return _repeatString; } - void setRepeatFlag(QString value) { _repeatString = value; } + QString retryString() const { return _repeatString; } + void setRetryString(QString value) { _repeatString = value; } - bool getRepeatTimeout() const { return _repeatTimeout; } - void setRepeatTimeout(bool value) { _repeatTimeout = value; } + int lifetime() const { return _expireTimeout; } + void setLifetime(int value) { _expireTimeout = value; } - int getExpireTimeout() const { return _expireTimeout; } - void setExpireTimeout(int value) { _expireTimeout = value; } - - bool getEnableFlag() const { return _enableFlag; } - void setEnableFlag(bool value) { _enableFlag = value; } + bool mute() const { return _mute; } + void setMute(bool value) { _mute = value; } void saveState(QSettings* settings) const; void restoreState(QSettings* settings); + + void seriaize(QDataStream& stream); + void deseriaize(QDataStream& stream); + QString parseNotifyMessage(); QTimer* getTimer() const { return _timer; } @@ -120,8 +121,6 @@ private: //! according to its priority QTimer* _expireTimer; - - QStringList _messageSequence; //! path to folder with sound files @@ -149,20 +148,15 @@ private: double _spinBoxValue; - QString _repeatString; - - //! time when next notification must be fired - bool _repeatTimeout; - //! how often or what periodicaly notification should be played - int _repeatTimerValue; + QString _repeatString; //! time after event occured till notification became invalid //! and will be removed from list int _expireTimeout; //! enables/disables playing of current notification - bool _enableFlag; + bool _mute; }; Q_DECLARE_METATYPE(NotificationItem*) diff --git a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp index 69f085620..889b84261 100644 --- a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp @@ -47,8 +47,8 @@ NotificationItem::NotificationItem(QObject *parent) , _sayOrder("Never") , _spinBoxValue(0) , _repeatString("Repeat Instantly") - , _repeatTimeout(true) , _expireTimeout(15) + , _mute(false) { _timer = NULL; @@ -71,8 +71,9 @@ void NotificationItem::copyTo(NotificationItem* that) const that->_sayOrder = _sayOrder; that->_spinBoxValue = _spinBoxValue; that->_repeatString = _repeatString; - that->_repeatTimeout = _repeatTimeout; that->_expireTimeout = _expireTimeout; + that->_mute = _mute; + } @@ -88,8 +89,10 @@ void NotificationItem::saveState(QSettings* settings) const settings->setValue(QLatin1String("Sound2"), getSound2()); settings->setValue(QLatin1String("Sound3"), getSound3()); settings->setValue(QLatin1String("SayOrder"), getSayOrder()); - settings->setValue(QLatin1String("Repeat"), getRepeatFlag()); - settings->setValue(QLatin1String("ExpireTimeout"), getExpireTimeout()); + settings->setValue(QLatin1String("Repeat"), retryString()); + settings->setValue(QLatin1String("ExpireTimeout"), lifetime()); + settings->setValue(QLatin1String("Mute"), mute()); + } void NotificationItem::restoreState(QSettings* settings) @@ -105,10 +108,45 @@ void NotificationItem::restoreState(QSettings* settings) setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString()); setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString()); setSpinBoxValue(settings->value(QLatin1String("ValueSpinBox"), tr("")).toDouble()); - setRepeatFlag(settings->value(QLatin1String("Repeat"), tr("")).toString()); - setExpireTimeout(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt()); + setRetryString(settings->value(QLatin1String("Repeat"), tr("")).toString()); + setLifetime(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt()); + setMute(settings->value(QLatin1String("Mute"), tr("")).toInt()); + } +void NotificationItem::seriaize(QDataStream& stream) +{ + stream << this->_soundCollectionPath; + stream << this->_currentLanguage; + stream << this->_dataObject; + stream << this->_objectField; + stream << this->_dataValue; + stream << this->_sound1; + stream << this->_sound2; + stream << this->_sound3; + stream << this->_sayOrder; + stream << this->_spinBoxValue; + stream << this->_repeatString; + stream << this->_expireTimeout; + stream << this->_mute; +} + +void NotificationItem::deseriaize(QDataStream& stream) +{ + stream >> this->_soundCollectionPath; + stream >> this->_currentLanguage; + stream >> this->_dataObject; + stream >> this->_objectField; + stream >> this->_dataValue; + stream >> this->_sound1; + stream >> this->_sound2; + stream >> this->_sound3; + stream >> this->_sayOrder; + stream >> this->_spinBoxValue; + stream >> this->_repeatString; + stream >> this->_expireTimeout; + stream >> this->_mute; +} void NotificationItem::startTimer(int value) { if (!_timer) { diff --git a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp index f5f243e43..d418f0d26 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp @@ -30,11 +30,15 @@ #include "notifytablemodel.h" #include "notifylogging.h" -NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent) +NotifyItemDelegate::NotifyItemDelegate(QObject* parent) : QItemDelegate(parent) , _parent(parent) - , _items(items) { + _titles << "Repeat Once" + << "Repeat Instantly" + << "Repeat 10 seconds" + << "Repeat 30 seconds" + << "Repeat 1 minute"; } @@ -44,7 +48,7 @@ QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionVie if (eREPEAT_VALUE == index.column()) { QComboBox* editor = new QComboBox(parent); editor->clear(); - editor->addItems(_items); + editor->addItems(_titles); return editor; } else { if (eEXPIRE_TIME == index.column()) { diff --git a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h index 01fa0794d..494e61c17 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h @@ -37,7 +37,7 @@ class NotifyItemDelegate : public QItemDelegate Q_OBJECT public: - NotifyItemDelegate(QStringList items, QObject *parent = 0); + NotifyItemDelegate(QObject *parent = 0); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const; @@ -51,7 +51,7 @@ private slots: private: QObject* _parent; - QStringList _items; + QStringList _titles; }; diff --git a/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp b/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp index 616b2ada5..0a29cc6e6 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp @@ -28,15 +28,16 @@ #include "notifylogging.h" -#ifdef DEBUG_NOTIFIES +#ifdef DEBUG_NOTIFIES_ENABLE QDebug qNotifyDebug() -#endif -#ifndef DEBUG_NOTIFIES -QNoDebug qNotifyDebug() -#endif { -#ifdef DEBUG_NOTIFIES return qDebug(); +} #endif + +#ifndef DEBUG_NOTIFIES_ENABLE +QNoDebug qNotifyDebug() +{ return QNoDebug(); } +#endif diff --git a/ground/openpilotgcs/src/plugins/notify/notifylogging.h b/ground/openpilotgcs/src/plugins/notify/notifylogging.h index bf02b86df..ea7ea331c 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifylogging.h +++ b/ground/openpilotgcs/src/plugins/notify/notifylogging.h @@ -31,12 +31,16 @@ #include "QDebug.h" -#ifdef DEBUG_NOTIFIES +#define DEBUG_NOTIFIES_ENABLE + +#ifdef DEBUG_NOTIFIES_ENABLE QDebug qNotifyDebug(); #endif -#ifndef DEBUG_NOTIFIES + +#ifndef DEBUG_NOTIFIES_ENABLE QNoDebug qNotifyDebug(); #endif +#define qNotifyDebug_if(test) if(test) qNotifyDebug() #endif // NOTIFYLOGGING_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp index 9eef49dec..e7878c3da 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp @@ -272,8 +272,8 @@ void SoundNotifyPlugin::appendNotification(UAVObject *object) if (nowPlayingConfiguration == ntf) continue; - if (ntf->getRepeatFlag()!= "Repeat Instantly" && - ntf->getRepeatFlag()!= "Repeat Once" && !ntf->firstStart) + if (ntf->retryString() != "Repeat Instantly" && + ntf->retryString() != "Repeat Once" && !ntf->firstStart) continue; checkNotificationRule(ntf,object); @@ -288,46 +288,47 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA double threshold; QString direction; QString fieldName; + threshold = notification->getSpinBoxValue(); direction = notification->getValue(); fieldName = notification->getObjectField(); UAVObjectField* field = object->getField(fieldName); - if (field->getName()!="") { - double value = field->getDouble(); - switch(direction[0].toAscii()) - { - case 'E': - if (value==threshold) - condition = true; - break; - case 'G': - if (value>threshold) - condition = true; - break; - case 'L': - if (valuegetName() == "") + return; + + double value = field->getDouble(); + switch(direction[0].toAscii()) + { + case 'E': + condition = (value == threshold); + break; + + case 'G': + condition = (value > threshold); + break; + + case 'L': + condition = (value < threshold); + break; } - if (condition) - { - if (!playNotification(notification)) - { - if (!pendingNotifications.contains(notification)) - { - notification->stopTimer(); + if (!condition) + return; - qNotifyDebug() << "add to pending list - " << notification->parseNotifyMessage(); - // if audio is busy, start expiration timer - //ms = (notification->getExpiredTimeout()[in sec])*1000 - //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); - pendingNotifications.append(notification); - notification->startExpireTimer(); - connect(notification->getExpireTimer(), SIGNAL(timeout()), this, SLOT(expireTimerHandler())); - } + if (!playNotification(notification)) + { + if (!pendingNotifications.contains(notification)) + { + notification->stopTimer(); + + qNotifyDebug() << "add to pending list - " << notification->parseNotifyMessage(); + // if audio is busy, start expiration timer + //ms = (notification->getExpiredTimeout()[in sec])*1000 + //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); + pendingNotifications.append(notification); + notification->startExpireTimer(); + connect(notification->getExpireTimer(), SIGNAL(timeout()), this, SLOT(expireTimerHandler())); } } } @@ -338,26 +339,26 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification) if (phonon.mo == NULL) return false; - if (!notification->getEnableFlag()) return true; + if (!notification->mute()) + return true; qNotifyDebug() << "Phonon State: " << phonon.mo->state(); if ((phonon.mo->state()==Phonon::PausedState) - || (phonon.mo->state()==Phonon::StoppedState) - || phonon.firstPlay) + || (phonon.mo->state()==Phonon::StoppedState) + || phonon.firstPlay) { // don't fire expire timer nowPlayingConfiguration = notification; notification->stopExpireTimer(); - if (notification->getRepeatFlag()=="Repeat Once") { + if (notification->retryString() == "Repeat Once") { removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification))); } else { - if (notification->getRepeatFlag()!="Repeat Instantly") - { + if (notification->retryString() != "Repeat Instantly") { QRegExp rxlen("(\\d+)"); QString value; int timer_value; - int pos = rxlen.indexIn(notification->getRepeatFlag()); + int pos = rxlen.indexIn(notification->retryString()); if (pos > -1) { value = rxlen.cap(1); // "189" timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage @@ -379,10 +380,9 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification) phonon.mo->play(); phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before // the state is not "Loading" anymore. - } - else + } else { return false; // if audio is busy - + } return true; } diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index caad0efff..a1122f078 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -43,13 +43,13 @@ #include "notifyplugin.h" #include "notifyitemdelegate.h" #include "notifytablemodel.h" +#include "notifylogging.h" NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) : IOptionsPage(parent) , objManager(*ExtensionSystem::PluginManager::instance()->getObject()) , owner(qobject_cast(parent)) , currentCollectionPath("") - , privListNotifications((qobject_cast(parent))->getListNotifications()) { } @@ -66,15 +66,8 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) //main layout options_page->setupUi(optionsPageWidget); - delegateItems.clear(); listSoundFiles.clear(); - delegateItems << "Repeat Once" - << "Repeat Instantly" - << "Repeat 10 seconds" - << "Repeat 30 seconds" - << "Repeat 1 minute"; - options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); @@ -95,19 +88,13 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) //connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); - privListNotifications.clear(); - - for (int i = 0; i < owner->getListNotifications().size(); ++i) { - NotificationItem* notification = new NotificationItem(); - owner->getListNotifications().at(i)->copyTo(notification); - privListNotifications.append(notification); - } +// privListNotifications = ((qobject_cast(parent))->getListNotifications()); + privListNotifications = owner->getListNotifications(); updateConfigView(owner->getCurrentNotification()); + initRulesTable(); initButtons(); - initRulesTableModel(); - initRulesTableView(); initPhononPlayer(); return optionsPageWidget; @@ -129,31 +116,32 @@ void NotifyPluginOptionsPage::initButtons() void NotifyPluginOptionsPage::initPhononPlayer() { - notifySound = Phonon::createPlayer(Phonon::NotificationCategory); - connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), + notifySound.reset(Phonon::createPlayer(Phonon::NotificationCategory)); + connect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); + connect(notifySound.data(), SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); } -void NotifyPluginOptionsPage::initRulesTableModel() +void NotifyPluginOptionsPage::initRulesTable() { - notifyRulesModel.reset(new NotifyTableModel(&privListNotifications)); - notifyRulesSelection = new QItemSelectionModel(notifyRulesModel.data()); - connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), + qNotifyDebug_if(_notifyRulesModel.isNull()) << "_notifyRulesModel.isNull())"; + qNotifyDebug_if(!_notifyRulesSelection) << "_notifyRulesSelection.isNull())"; + //QItemSelectionModel* selection = _notifyRulesSelection.take(); + _notifyRulesModel.reset(new NotifyTableModel(privListNotifications)); + _notifyRulesSelection = new QItemSelectionModel(_notifyRulesModel.data()); + + connect(_notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); connect(this, SIGNAL(entryUpdated(int)), - notifyRulesModel.data(), SLOT(entryUpdated(int))); + _notifyRulesModel.data(), SLOT(entryUpdated(int))); connect(this, SIGNAL(entryAdded(int)), - notifyRulesModel.data(), SLOT(entryAdded(int))); -} + _notifyRulesModel.data(), SLOT(entryAdded(int))); + + options_page->notifyRulesView->setModel(_notifyRulesModel.data()); + options_page->notifyRulesView->setSelectionModel(_notifyRulesSelection); + options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(this)); -void NotifyPluginOptionsPage::initRulesTableView() -{ - options_page->notifyRulesView->setModel(notifyRulesModel.data()); options_page->notifyRulesView->resizeRowsToContents(); - options_page->notifyRulesView->setSelectionModel(notifyRulesSelection); - options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); - options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); @@ -161,6 +149,9 @@ void NotifyPluginOptionsPage::initRulesTableView() options_page->notifyRulesView->setDragEnabled(true); options_page->notifyRulesView->setAcceptDrops(true); options_page->notifyRulesView->setDropIndicatorShown(true); + options_page->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove); + + } void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) @@ -175,7 +166,6 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio notification->setSayOrder(options_page->SayOrder->currentText()); notification->setValue(options_page->Value->currentText()); notification->setSpinBoxValue(options_page->ValueSpinBox->value()); - } /*! @@ -191,7 +181,7 @@ void NotifyPluginOptionsPage::apply() void NotifyPluginOptionsPage::finish() { - disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), + disconnect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), this,SLOT(changeButtonText(Phonon::State,Phonon::State))); if (notifySound) { notifySound->stop(); @@ -272,10 +262,10 @@ void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() { NotificationItem* notification = NULL; - if (-1 == notifyRulesSelection->currentIndex().row()) + if (-1 == _notifyRulesSelection->currentIndex().row()) return; notifySound->clearQueue(); - notification = privListNotifications.at(notifyRulesSelection->currentIndex().row()); + notification = privListNotifications.at(_notifyRulesSelection->currentIndex().row()); notification->parseNotifyMessage(); QStringList sequence = notification->getMessageSequence(); Q_ASSERT(!!sequence.size()); @@ -419,17 +409,17 @@ if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder-> } privListNotifications.append(notification); emit entryAdded(privListNotifications.size() - 1); - notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), + _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() { - notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row()); - if (!notifyRulesModel->rowCount() - && (notifyRulesSelection->currentIndex().row() > 0 - && notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) ) + _notifyRulesModel->removeRow(_notifyRulesSelection->currentIndex().row()); + if (!_notifyRulesModel->rowCount() + && (_notifyRulesSelection->currentIndex().row() > 0 + && _notifyRulesSelection->currentIndex().row() < _notifyRulesModel->rowCount()) ) { options_page->buttonDelete->setEnabled(false); options_page->buttonModify->setEnabled(false); @@ -442,9 +432,12 @@ void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked() { NotificationItem* notification = new NotificationItem; getOptionsPageValues(notification); - notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag()); - privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification); - entryUpdated(notifyRulesSelection->currentIndex().row()); + notification->setRetryString(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryString()); + notification->setLifetime(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->lifetime()); + notification->setMute(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->mute()); + + privListNotifications.replace(_notifyRulesSelection->currentIndex().row(),notification); + entryUpdated(_notifyRulesSelection->currentIndex().row()); } diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h index acb9f18e7..9e49e89ec 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h @@ -42,13 +42,15 @@ #include #include #include -#include "ui_notifypluginoptionspage.h" //#include "notifytablemodel.h" class NotifyTableModel; class NotificationItem; class SoundNotifyPlugin; +namespace Ui { + class NotifyPluginOptionsPage; +}; using namespace Core; @@ -74,11 +76,11 @@ public: void getOptionsPageValues(NotificationItem* notification); private: - //Q_DISABLE_COPY(NotifyPluginOptionsPage) + Q_DISABLE_COPY(NotifyPluginOptionsPage) + void initButtons(); void initPhononPlayer(); - void initRulesTableModel(); - void initRulesTableView(); + void initRulesTable(); private: UAVObjectManager& objManager; @@ -86,14 +88,13 @@ private: QStringList listDirCollections; QStringList listSoundFiles; QString currentCollectionPath; - int sizeNotifyList; Phonon::MediaObject *sound1; Phonon::MediaObject *sound2; - Phonon::MediaObject *notifySound; + QScopedPointer notifySound; Phonon::AudioOutput *audioOutput; - QStringList delegateItems; - QScopedPointer notifyRulesModel; - QItemSelectionModel *notifyRulesSelection; + + QScopedPointer _notifyRulesModel; + QItemSelectionModel* _notifyRulesSelection; QList privListNotifications; QScopedPointer options_page; diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp index 7c564a6df..0c2337437 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp @@ -26,28 +26,41 @@ */ #include "notifytablemodel.h" +#include "notifylogging.h" #include +#include -NotifyTableModel::NotifyTableModel(QList* parentList, QObject* parent) +static int _dragStartRow = -1; +static int _dragNumRows = -1; +const char* mime_type_notify_table = "openpilot/notify_plugin_table"; + +NotifyTableModel::NotifyTableModel(QList& parentList, QObject* parent) : QAbstractTableModel(parent) + , _list(parentList) { - _headerStrings << "Name" << "Repeats" << "Lifetime,sec" << "Enable"; - _list.reset(parentList); + _headerStrings << "Name" << "Repeats" << "Lifetime,sec" << "Mute"; + connect(this, SIGNAL(dragRows(int, int)), this, SLOT(dropRows(int, int))); } bool NotifyTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { + if (index.isValid() && role == Qt::DisplayRole) { + if(eMESSAGE_NAME == index.column()) { + emit dataChanged(index, index); + return true; + } + } if (index.isValid() && role == Qt::EditRole) { if(eREPEAT_VALUE == index.column()) - _list->at(index.row())->setRepeatFlag(value.toString()); + _list.at(index.row())->setRetryString(value.toString()); else { if(eEXPIRE_TIME == index.column()) - _list->at(index.row())->setExpireTimeout(value.toInt()); + _list.at(index.row())->setLifetime(value.toInt()); else { if(eENABLE_NOTIFICATION == index.column()) - _list->at(index.row())->setEnableFlag(value.toBool()); + _list.at(index.row())->setMute(value.toBool()); } } emit dataChanged(index, index); @@ -63,7 +76,7 @@ QVariant NotifyTableModel::data(const QModelIndex &index, int role) const return QVariant(); } - if (index.row() >= _list->size()) + if (index.row() >= _list.size()) return QVariant(); if (role == Qt::DisplayRole || role == Qt::EditRole) @@ -71,16 +84,16 @@ QVariant NotifyTableModel::data(const QModelIndex &index, int role) const switch(index.column()) { case eMESSAGE_NAME: - return _list->at(index.row())->parseNotifyMessage(); + return _list.at(index.row())->parseNotifyMessage(); case eREPEAT_VALUE: - return _list->at(index.row())->getRepeatFlag(); + return _list.at(index.row())->retryString(); case eEXPIRE_TIME: - return _list->at(index.row())->getExpireTimeout(); + return _list.at(index.row())->lifetime(); case eENABLE_NOTIFICATION: - return _list->at(index.row())->getEnableFlag(); + return _list.at(index.row())->mute(); default: return QVariant(); @@ -112,7 +125,16 @@ QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation, bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& index) { Q_UNUSED(index); - beginInsertRows(QModelIndex(), position, position+rows-1); + + if((-1 == position) || (-1 == rows) ) + return false; + + beginInsertRows(QModelIndex(), position, position + rows - 1); + + for (int row = 0; row < rows; ++row) { + _list.insert(position, new NotificationItem()); + } + endInsertRows(); return true; } @@ -120,10 +142,14 @@ bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& ind bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex& index) { Q_UNUSED(index); - beginRemoveRows(QModelIndex(), position, position+rows-1); - for (int row=0; row < rows; ++row) { - _list->removeAt(position); + if((-1 == position) || (-1 == rows) ) + return false; + + beginRemoveRows(QModelIndex(), position, position + rows - 1); + + for (int row = 0; row < rows; ++row) { + _list.removeAt(position); } endRemoveRows(); @@ -140,3 +166,122 @@ void NotifyTableModel::entryAdded(int position) { insertRows(position, 1,QModelIndex()); } + + +bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row, + int column, const QModelIndex& parent) +{ + if (action == Qt::IgnoreAction) + return true; + + if (!data->hasFormat(mime_type_notify_table)) + return false; + + int beginRow = -1; + + if (row != -1) + beginRow = row; + else { + if (parent.isValid()) + beginRow = parent.row(); + else + beginRow = rowCount(QModelIndex()); + } + + if(-1 == beginRow) + return false; + + QByteArray encodedData = data->data(mime_type_notify_table); + QDataStream stream(&encodedData, QIODevice::ReadOnly); + int rows = beginRow; + while(!stream.atEnd()) { + qint32 ptr; + stream >> ptr; + NotificationItem* item = reinterpret_cast(ptr); + int dragged = _list.indexOf(item); + if(-1 == dragged || rows >= _list.size() || dragged == rows) { + qNotifyDebug() << "no such item"; + return false; + } + removeRows(rows, 1, QModelIndex()); + insertRows(rows, 1, QModelIndex()); + _list.replace(dragged, item); + // _list.swap(dragged, rows); + ++rows; + }; + + QModelIndex idxTopLeft = index(beginRow, 0, QModelIndex()); + QModelIndex idxBotRight = index(beginRow, columnCount(QModelIndex()), QModelIndex()); + emit dataChanged(idxTopLeft, idxBotRight); + //QStringList newItems; + + //removeRows(_dragStartRow, _dragNumRows, QModelIndex()); + //insertRows(beginRow, rows, QModelIndex()); +// int rows = beginRow; +// while (!stream.atEnd()) { +// _list.at(index.row())->deserialize(stream); +// ++rows; +// } + +// while(rows) { +// int column = 0; +// foreach (const QString& text, newItems) { +// QModelIndex idx = index(beginRow, column, QModelIndex()); +// if(!column) +// setData(const_cast(idx), text, Qt::DisplayRole); +// else +// setData(const_cast(idx), text, Qt::EditRole); +// ++column; +// } +// ++beginRow; +// --rows; +// } + return true; +} + +QMimeData* NotifyTableModel::mimeData(const QModelIndexList& indexes) const +{ + QMimeData* mimeData = new QMimeData(); + QByteArray encodedData; + + QDataStream stream(&encodedData, QIODevice::WriteOnly); + int rows = 0; + foreach (const QModelIndex& index, indexes) { + if(!index.column()) { + qint32 item = reinterpret_cast(_list.at(index.row())); + stream << item; + } + ++rows; + } + +// int numRows = 0; +// foreach (const QModelIndex& index, indexes) { +// if (index.isValid() && index.column()) { +// _list.at(index.row())->serialize(stream); +//// if(!index.column()) { +//// numRows++; +//// QString name = data(index, Qt::DisplayRole).toString(); +//// stream << name; +//// } else { +//// QString text = data(index, Qt::EditRole).toString(); +//// stream << text; +//// } +// } +// } + + mimeData->setData(mime_type_notify_table, encodedData); + + //emit dragRows(indexes.at(0).row(), rows); + dropRows(indexes.at(0).row(), rows); + //_dragStartRow = indexes.at(0).row(); + //_dragNumRows = 1/*numRows*/; + + return mimeData; +} + +void NotifyTableModel::dropRows(int position, int count) const +{ + for (int row = 0; row < count; ++row) { + _list.removeAt(position); + } +} diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h index affae25da..f58cc0599 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h @@ -43,11 +43,11 @@ class NotifyTableModel : public QAbstractTableModel public: - NotifyTableModel(QList* parentList, QObject* parent = 0); + NotifyTableModel(QList& parentList, QObject* parent = 0); int rowCount(const QModelIndex& parent = QModelIndex()) const { - return _list->count(); + return _list.count(); } int columnCount(const QModelIndex &/*parent*/) const @@ -68,17 +68,34 @@ public: return Qt::MoveAction; } + QStringList mimeTypes() const + { + QStringList types; + types << "application/vnd.text.list"; + return types; + } + + bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, + int column, const QModelIndex& parent); + QMimeData* mimeData(const QModelIndexList &indexes) const; + + bool setData(const QModelIndex &index, const QVariant &value, int role); QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; bool insertRows(int position, int rows, const QModelIndex &index); bool removeRows(int position, int rows, const QModelIndex &index); +signals: + void dragRows(int position, int count); + private slots: void entryUpdated(int offset); void entryAdded(int position); + void dropRows(int position, int count) const; + private: - QScopedPointer > _list; + mutable QList& _list; QStringList _headerStrings; }; From 82ec3199d73f0d743d117fc028243dfd038b2ae5 Mon Sep 17 00:00:00 2001 From: Nickolay Date: Thu, 29 Sep 2011 20:26:46 +0300 Subject: [PATCH 7/9] +dynamic field UI; --- .../src/plugins/notify/NotificationItem.h | 30 +- .../src/plugins/notify/notificationitem.cpp | 259 +++--- .../src/plugins/notify/notifyplugin.cpp | 9 +- .../notify/notifypluginoptionspage.cpp | 406 ++++++--- .../notify/notifypluginoptionspage.cpp.orig | 443 +++++----- .../plugins/notify/notifypluginoptionspage.h | 59 +- .../plugins/notify/notifypluginoptionspage.ui | 787 +++++++----------- .../src/plugins/notify/notifytablemodel.cpp | 8 +- .../src/plugins/notify/notifytablemodel.h | 3 +- 9 files changed, 1094 insertions(+), 910 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h index da40d2afb..20de7a4f8 100644 --- a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h +++ b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h @@ -40,11 +40,15 @@ using namespace Core; QString getSound##number() const { return _sound##number; } \ void setSound##number(QString text) { _sound##number = text; } \ +class UAVDataObject; +class UAVObjectField; class NotificationItem : public QObject { Q_OBJECT public: + enum { eDefaultTimeout = 15 }; // in sec + explicit NotificationItem(QObject *parent = 0); void copyTo(NotificationItem*) const; @@ -53,15 +57,17 @@ public: DECLARE_SOUND(2) DECLARE_SOUND(3) - QString getValue() const { return _dataValue; } - void setValue(QString text) { _dataValue = text; } + QString range() const { return _rangeLimit; } + void setRange(QString text) { _rangeLimit = text; } QString getSayOrder() const { return _sayOrder; } void setSayOrder(QString text) { _sayOrder = text; } - double getSpinBoxValue() const { return _spinBoxValue; } - void setSpinBoxValue(double value) { _spinBoxValue = value; } + double singleValue() const { return _singleValue; } + void setSingleValue(double value) { _singleValue = value; } + double valueRange2() const { return _valueRange2; } + void setValueRange2(double value) { _valueRange2 = value; } QString getDataObject() const { return _dataObject; } void setDataObject(QString text) { _dataObject = text; } @@ -91,6 +97,9 @@ public: void restoreState(QSettings* settings); + UAVDataObject* getUAVObject(void); + UAVObjectField* getUAVObjectField(void); + void seriaize(QDataStream& stream); void deseriaize(QDataStream& stream); @@ -111,7 +120,7 @@ public: bool firstStart; private: - void checkSoundFilesExisting(); + void checkSoundFilesExisting(bool& missed1, bool& missed2, bool& missed3); private: QTimer* _timer; @@ -135,8 +144,8 @@ private: //! one field value change can be assigned to one notification QString _objectField; - //! poled UAV field value - QString _dataValue; + //! fire condition for UAV field value (lower, greater, in range) + QString _rangeLimit; //! possible sounds(at least one required to play notification) QString _sound1; @@ -146,7 +155,12 @@ private: //! order in what sounds 1-3 will be played QString _sayOrder; - double _spinBoxValue; + //! one-side range, value maybe lower or greater + double _singleValue; + + //! both-side range, value should be inside the range + //double _valueRange1; + double _valueRange2; //! how often or what periodicaly notification should be played QString _repeatString; diff --git a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp index 889b84261..d6c803b68 100644 --- a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp @@ -25,11 +25,19 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "notificationitem.h" -#include "notifylogging.h" +//Qt headers #include #include + +// GCS headers +#include "extensionsystem/pluginmanager.h" #include "utils/pathutils.h" +#include "uavobjectmanager.h" +#include "uavobject.h" + +// Notify plugin headers +#include "notificationitem.h" +#include "notifylogging.h" NotificationItem::NotificationItem(QObject *parent) @@ -40,14 +48,15 @@ NotificationItem::NotificationItem(QObject *parent) , _currentLanguage("default") , _dataObject("") , _objectField("") - , _dataValue("Equal to") + , _rangeLimit("Equal to") , _sound1("") , _sound2("") , _sound3("") , _sayOrder("Never") - , _spinBoxValue(0) + , _singleValue(0) + , _valueRange2(0) , _repeatString("Repeat Instantly") - , _expireTimeout(15) + , _expireTimeout(eDefaultTimeout) , _mute(false) { @@ -64,12 +73,13 @@ void NotificationItem::copyTo(NotificationItem* that) const that->_soundCollectionPath = _soundCollectionPath; that->_dataObject = _dataObject; that->_objectField = _objectField; - that->_dataValue = _dataValue; + that->_rangeLimit = _rangeLimit; that->_sound1 = _sound1; that->_sound2 = _sound2; that->_sound3 = _sound3; that->_sayOrder = _sayOrder; - that->_spinBoxValue = _spinBoxValue; + that->_singleValue = _singleValue; + that->_valueRange2 = _valueRange2; that->_repeatString = _repeatString; that->_expireTimeout = _expireTimeout; that->_mute = _mute; @@ -83,8 +93,9 @@ void NotificationItem::saveState(QSettings* settings) const settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage()); settings->setValue(QLatin1String("ObjectField"), getObjectField()); settings->setValue(QLatin1String("DataObject"), getDataObject()); - settings->setValue(QLatin1String("Value"), getValue()); - settings->setValue(QLatin1String("ValueSpinBox"), getSpinBoxValue()); + settings->setValue(QLatin1String("RangeLimit"), range()); + settings->setValue(QLatin1String("Value1"), singleValue()); + settings->setValue(QLatin1String("Value2"), valueRange2()); settings->setValue(QLatin1String("Sound1"), getSound1()); settings->setValue(QLatin1String("Sound2"), getSound2()); settings->setValue(QLatin1String("Sound3"), getSound3()); @@ -102,12 +113,13 @@ 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()); - setValue(settings->value(QLatin1String("Value"), tr("")).toString()); + setRange(settings->value(QLatin1String("RangeLimit"), tr("")).toString()); setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString()); setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString()); setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString()); setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString()); - setSpinBoxValue(settings->value(QLatin1String("ValueSpinBox"), tr("")).toDouble()); + setSingleValue(settings->value(QLatin1String("Value1"), tr("")).toDouble()); + setValueRange2(settings->value(QLatin1String("Value2"), tr("")).toDouble()); setRetryString(settings->value(QLatin1String("Repeat"), tr("")).toString()); setLifetime(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt()); setMute(settings->value(QLatin1String("Mute"), tr("")).toInt()); @@ -120,12 +132,13 @@ void NotificationItem::seriaize(QDataStream& stream) stream << this->_currentLanguage; stream << this->_dataObject; stream << this->_objectField; - stream << this->_dataValue; + stream << this->_rangeLimit; stream << this->_sound1; stream << this->_sound2; stream << this->_sound3; stream << this->_sayOrder; - stream << this->_spinBoxValue; + stream << this->_singleValue; + stream << this->_valueRange2; stream << this->_repeatString; stream << this->_expireTimeout; stream << this->_mute; @@ -137,12 +150,13 @@ void NotificationItem::deseriaize(QDataStream& stream) stream >> this->_currentLanguage; stream >> this->_dataObject; stream >> this->_objectField; - stream >> this->_dataValue; + stream >> this->_rangeLimit; stream >> this->_sound1; stream >> this->_sound2; stream >> this->_sound3; stream >> this->_sayOrder; - stream >> this->_spinBoxValue; + stream >> this->_singleValue; + stream >> this->_valueRange2; stream >> this->_repeatString; stream >> this->_expireTimeout; stream >> this->_mute; @@ -195,145 +209,192 @@ void NotificationItem::disposeExpireTimer() { } } +#define missed "missed sound" +#define CHECK_ADD_SOUND(n) ((!_missedSound##n) ? getSound##n() : (missed#n)) +#define CHECK_REPLACE_SOUND(n) ((!_missedSound##n) ? str.replace(missed#n, getSound##n()) : (missed#n)) + QString NotificationItem::parseNotifyMessage() { // tips: // check of *.wav files exist needed for playing phonon queues; // if phonon player don't find next file in queue, it buzz - QString str,str1; - str1= getSayOrder(); - str = QString("%L1 ").arg(getSpinBoxValue()); - int position = 0xFF; + QString str; + QString value; + QString sayOrder = getSayOrder(); + UAVObjectField* field = getUAVObjectField(); + if (UAVObjectField::ENUM == field->getType()) { + Q_ASSERT(singleValue() < field->getOptions().size()); + value = QString("%L1").arg(field->getOptions().at(singleValue())); + } else { + value = QString("%L1").arg(singleValue()); + } + + int position = -1; // default don't play value wav file + // generate queue of sound files to play _messageSequence.clear(); - checkSoundFilesExisting(); + bool _missedSound1 = false; + bool _missedSound2 = false; + bool _missedSound3 = false; + + checkSoundFilesExisting(_missedSound1, _missedSound2, _missedSound3); + str = CHECK_ADD_SOUND(1)+" "+CHECK_ADD_SOUND(2)+" "+CHECK_ADD_SOUND(3); if(!_messageSequence.size()) { qNotifyDebug() << "no any files in message queue"; } - switch(str1.at(0).toAscii()) + sayOrder = sayOrder.trimmed(); + switch(sayOrder.at(0).toUpper().toAscii()) { - case 'N'://NEVER: - str = getSound1()+" "+getSound2()+" "+getSound3(); - position = 0xFF; - break; - - case 'B'://BEFORE: - str = QString("%L1 ").arg(getSpinBoxValue())+getSound1()+" "+getSound2()+" "+getSound3(); - position = 0; - break; + case 'B'://BEFORE: + CHECK_REPLACE_SOUND(1); + CHECK_REPLACE_SOUND(2); + CHECK_REPLACE_SOUND(3); + str.prepend(value + " "); + position = 0; + break; case 'A'://AFTER: - switch(str1.at(6).toAscii()) + switch(sayOrder.at(6).toLower().toAscii()) { case 'f': - str = getSound1()+QString(" %L1 ").arg(getSpinBoxValue())+getSound2()+" "+getSound3(); + str = CHECK_ADD_SOUND(1)+" "+value+" "+CHECK_ADD_SOUND(2)+" "+CHECK_ADD_SOUND(3); position = 1; break; + case 's': - str = getSound1()+" "+getSound2()+QString(" %L1").arg(getSpinBoxValue())+" "+getSound3(); + str = CHECK_ADD_SOUND(1)+" "+CHECK_ADD_SOUND(2)+" "+value+" "+CHECK_ADD_SOUND(3); position = 2; break; + case 't': - str = getSound1()+" "+getSound2()+" "+getSound3()+QString(" %L1").arg(getSpinBoxValue()); + CHECK_REPLACE_SOUND(1); + CHECK_REPLACE_SOUND(2); + CHECK_REPLACE_SOUND(3); + str.append(" "+value); position = 3; break; } break; + + default: + CHECK_REPLACE_SOUND(1); + CHECK_REPLACE_SOUND(2); + CHECK_REPLACE_SOUND(3); + break; } - if(position != 0xFF) - { - QStringList numberParts = QString("%1").arg(getSpinBoxValue()).trimmed().split("."); - QStringList numberFiles; + if(-1 == position) { + qNotifyDebug() << "NotificationItem::parseNotifyMessage() | value position undefined"; + return str; + } - if((numberParts.at(0).size()==1) || (numberParts.at(0).toInt()<20)) - { - //if(numberParts.at(0)!="0") - numberFiles.append(numberParts.at(0)); - } else { - int i=0; - if(numberParts.at(0).right(2).toInt()<20 && numberParts.at(0).right(2).toInt()!=0) { - if(numberParts.at(0).right(2).toInt()<10) - numberFiles.append(numberParts.at(0).right(1)); - else - numberFiles.append(numberParts.at(0).right(2)); - i=2; - } - for(;igetType()) return str; - if(1 < numberParts.size()) { - numberFiles.append("point"); - if((numberParts.at(1).size()==1)) - numberFiles.append(numberParts.at(1)); - else { - if(numberParts.at(1).left(1)=="0") - numberFiles.append(numberParts.at(1).left(1)); - else - numberFiles.append(numberParts.at(1).left(1)+'0'); - numberFiles.append(numberParts.at(1).right(1)); - } + QStringList numberParts = value.trimmed().split("."); + QStringList digitWavs; + + 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)); + } else { + int i=0; + // [2] store two lowest digits of number + int num = numberParts.at(0).right(2).toInt(); + if (num < 20 && num != 0) { + // store eighter number in range [0...10) or in range [10...20) + digitWavs.append(numberParts.at(0).right(1 + num/11)); + i=2; + } + // [3] prepend 100 and 1000 digits of number + for (;i number < 1 + digitWavs.append(numberParts.at(1)); + } else { + // append fractional part of number + QString left = numberParts.at(1).left(1); + (left == "0") ? digitWavs.append(left) : digitWavs.append(left + '0'); + digitWavs.append(numberParts.at(1).right(1)); + } + } + foreach(QString fileName, digitWavs) { + fileName+=".wav"; + QString filePath = QDir::toNativeSeparators(getSoundCollectionPath()+"/"+ getCurrentLanguage()+"/"+fileName); + if(QFile::exists(filePath)) + _messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+ "/"+getCurrentLanguage()+"/"+fileName)); + else { + if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName))) + _messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName)); + else { + _messageSequence.clear(); + break; // if no some of *.wav files, then don't play number! } + } } return str; } +UAVObjectField* NotificationItem::getUAVObjectField() { + return getUAVObject()->getField(getObjectField()); +} -void NotificationItem::checkSoundFilesExisting() { +UAVDataObject* NotificationItem::getUAVObject() { + return dynamic_cast((ExtensionSystem::PluginManager::instance()->getObject())->getObject(getDataObject())); +} + + +void NotificationItem::checkSoundFilesExisting(bool& missed1, bool& missed2, bool& missed3) +{ if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"))) _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")); - else + else { if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"))) _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")); + else + missed1 = true; + } - - if(!getSound2().size()) - { + if(getSound2().size()) { if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"))) _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")); - else + else { if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"))) _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")); + else + missed2 = true; + } } - if(!getSound3().size()) - { + if(getSound3().size()) { if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"))) _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")); - else + else { if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"))) _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")); + else + missed3 = true; + } } } diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp index e7878c3da..fa55cfc42 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp @@ -289,8 +289,8 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA QString direction; QString fieldName; - threshold = notification->getSpinBoxValue(); - direction = notification->getValue(); + threshold = notification->singleValue(); + direction = notification->range(); fieldName = notification->getObjectField(); UAVObjectField* field = object->getField(fieldName); @@ -311,6 +311,11 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA case 'L': condition = (value < threshold); break; + + case 'R': + condition = (value > threshold) && (value < notification->valueRange2()); + break; + } if (!condition) diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index a1122f078..305e5e13e 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -39,30 +39,58 @@ #include #include #include +#include +#include #include "notifyplugin.h" #include "notifyitemdelegate.h" #include "notifytablemodel.h" #include "notifylogging.h" + +static const char* cStrBefore1st = "Before first"; +static const char* cStrBefore2nd = "Before second"; +static const char* cStrAfter2nd = "After second"; + +static const char* cStrEqualTo = "Equal to"; +static const char* cStrLargeThan = "Large than"; +static const char* cStrLowerThan = "Lower than"; +static const char* cStrInRange = "In range"; + + +//----------------------------------------------------------------------------- NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) : IOptionsPage(parent) , objManager(*ExtensionSystem::PluginManager::instance()->getObject()) , owner(qobject_cast(parent)) , currentCollectionPath("") + , _valueRange(NULL) + , _sayOrder(NULL) + , _fieldValue(NULL) + , _fieldType(-1) + , _form(NULL) { } +//----------------------------------------------------------------------------- NotifyPluginOptionsPage::~NotifyPluginOptionsPage() { } //creates options page widget (uses the UI file) + +//----------------------------------------------------------------------------- QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) { options_page.reset(new Ui::NotifyPluginOptionsPage()); //main widget - QWidget *optionsPageWidget = new QWidget; + QWidget* optionsPageWidget = new QWidget; + //if(!_fieldValue.isNull()) + _fieldValue = NULL; + _valueRange = NULL; + _fieldType = -1; + //save ref to form, needed for binding dynamic fields in future + _form = optionsPageWidget; //main layout options_page->setupUi(optionsPageWidget); @@ -71,35 +99,161 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); - // Fills the combo boxes for the UAVObjects - QList< QList > objList = objManager.getDataObjects(); - foreach (QList list, objList) { - foreach (UAVDataObject* obj, list) { - options_page->UAVObject->addItem(obj->getName()); - } - } - connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); - connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); + + connect(this, SIGNAL(updateNotifications(QList)), owner, SLOT(updateNotificationList(QList))); //connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); - -// privListNotifications = ((qobject_cast(parent))->getListNotifications()); privListNotifications = owner->getListNotifications(); - updateConfigView(owner->getCurrentNotification()); + // [1] + addDynamicValueLayout(); + _selectedNotification = owner->getCurrentNotification(); + // [2] + updateConfigView(_selectedNotification); initRulesTable(); initButtons(); initPhononPlayer(); +// _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(0, 0, QModelIndex()), +// QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + return optionsPageWidget; } +//----------------------------------------------------------------------------- +void NotifyPluginOptionsPage::apply() +{ + getOptionsPageValues(owner->getCurrentNotification()); + owner->setEnableSound(options_page->chkEnableSound->isChecked()); + emit updateNotifications(privListNotifications); +} + +void NotifyPluginOptionsPage::finish() +{ + + disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); + + disconnect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(changeButtonText(Phonon::State,Phonon::State))); + if (notifySound) { + notifySound->stop(); + notifySound->clear(); + } +} + +//----------------------------------------------------------------------------- +void NotifyPluginOptionsPage::addDynamicValueLayout() +{ + NotificationItem* curr = owner->getCurrentNotification(); + Q_ASSERT(curr); + options_page->dynamicValueLayout->addWidget(new QLabel("Say order ", _form)); + + _sayOrder = new QComboBox(_form); + options_page->dynamicValueLayout->addWidget(_sayOrder); + QStringList sayOrderValues; + sayOrderValues << cStrBefore1st << cStrBefore2nd << cStrAfter2nd; + _sayOrder->addItems(sayOrderValues); + + options_page->dynamicValueLayout->addWidget(new QLabel("Value is ", _form)); + + UAVDataObject* obj = dynamic_cast(objManager.getObject(curr->getDataObject())); + UAVObjectField* field = obj->getField(curr->getObjectField()); + Q_ASSERT(obj); + Q_ASSERT(field); + _valueRange = new QComboBox(_form); + options_page->dynamicValueLayout->addWidget(_valueRange); + + addDynamicField(field); +} + +//----------------------------------------------------------------------------- +void NotifyPluginOptionsPage::resetValueRange() +{ + _fieldValue = new QLineEdit(_form); + (static_cast(_fieldValue))->setInputMask("999.99 - 999.99;"); + (static_cast(_fieldValue))->setText("0000000000"); + (static_cast(_fieldValue))->setCursorPosition(0); +} + +//----------------------------------------------------------------------------- +void NotifyPluginOptionsPage::on_rangeValue_indexChanged(QString rangeStr) +{ + Q_ASSERT(_fieldValue); + if(rangeStr == cStrInRange) { + Q_ASSERT(_fieldValue); + options_page->dynamicValueLayout->removeWidget(_fieldValue); + resetValueRange(); + options_page->dynamicValueLayout->addWidget(_fieldValue); + + // _fieldType = -1; + // addDynamicField(field); + } +} + +//----------------------------------------------------------------------------- +void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField) +{ + //qDebugNotify_if(!objField || !parent) << "null input params"; + Q_ASSERT(objField); + if(objField->getType() == _fieldType) { + if(QComboBox* fieldValue = dynamic_cast(_fieldValue)) { + fieldValue->clear(); + QStringList enumValues(objField->getOptions()); + fieldValue->addItems(enumValues); + } + return; + } + // check if dynamic fileld already settled, + // so if its exists remove it and install new field + if(_fieldValue) + options_page->dynamicValueLayout->removeWidget(_fieldValue); + + disconnect(_valueRange, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_rangeValue_indexChanged(QString))); + + _valueRange->clear(); + QStringList rangeValues; + if(UAVObjectField::ENUM == objField->getType()) { + rangeValues << cStrEqualTo << cStrInRange; + _valueRange->addItems(rangeValues); + } + else { + rangeValues << cStrEqualTo << cStrLargeThan << cStrLowerThan << cStrInRange; + _valueRange->addItems(rangeValues); + connect(_valueRange, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_rangeValue_indexChanged(QString))); + } + + + _fieldType = objField->getType(); + switch(_fieldType) + { + case UAVObjectField::ENUM: + { + _fieldValue = new QComboBox(_form); + QStringList enumValues(objField->getOptions()); + (dynamic_cast(_fieldValue))->addItems(enumValues); + } + break; + + default: + if(_valueRange->currentText() == cStrInRange) { + resetValueRange(); + } else { + _fieldValue = new QSpinBox(_form); + } + break; + }; + options_page->dynamicValueLayout->addWidget(_fieldValue); +} + +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::initButtons() { options_page->chkEnableSound->setChecked(owner->getEnableSound()); @@ -114,6 +268,7 @@ void NotifyPluginOptionsPage::initButtons() connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); } +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::initPhononPlayer() { notifySound.reset(Phonon::createPlayer(Phonon::NotificationCategory)); @@ -122,6 +277,8 @@ void NotifyPluginOptionsPage::initPhononPlayer() connect(notifySound.data(), SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); } + +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::initRulesTable() { qNotifyDebug_if(_notifyRulesModel.isNull()) << "_notifyRulesModel.isNull())"; @@ -134,8 +291,8 @@ void NotifyPluginOptionsPage::initRulesTable() this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); connect(this, SIGNAL(entryUpdated(int)), _notifyRulesModel.data(), SLOT(entryUpdated(int))); - connect(this, SIGNAL(entryAdded(int)), - _notifyRulesModel.data(), SLOT(entryAdded(int))); +// connect(this, SIGNAL(entryAdded(int)), +// _notifyRulesModel.data(), SLOT(entryAdded(int))); options_page->notifyRulesView->setModel(_notifyRulesModel.data()); options_page->notifyRulesView->setSelectionModel(_notifyRulesSelection); @@ -150,12 +307,12 @@ void NotifyPluginOptionsPage::initRulesTable() options_page->notifyRulesView->setAcceptDrops(true); options_page->notifyRulesView->setDropIndicatorShown(true); options_page->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove); - - } +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) { + Q_ASSERT(notification); notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); notification->setDataObject(options_page->UAVObject->currentText()); @@ -163,48 +320,51 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio notification->setSound1(options_page->Sound1->currentText()); notification->setSound2(options_page->Sound2->currentText()); notification->setSound3(options_page->Sound3->currentText()); - notification->setSayOrder(options_page->SayOrder->currentText()); - notification->setValue(options_page->Value->currentText()); - notification->setSpinBoxValue(options_page->ValueSpinBox->value()); -} - -/*! -* Called when the user presses apply or OK. -* Saves the current values -*/ -void NotifyPluginOptionsPage::apply() -{ - getOptionsPageValues(owner->getCurrentNotification()); - owner->setEnableSound(options_page->chkEnableSound->isChecked()); - emit updateNotifications(privListNotifications); -} - -void NotifyPluginOptionsPage::finish() -{ - disconnect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - if (notifySound) { - notifySound->stop(); - notifySound->clear(); + notification->setSayOrder(_sayOrder->currentText()); + notification->setRange(_valueRange->currentText()); + if(QSpinBox* spinValue = dynamic_cast(_fieldValue)) + notification->setSingleValue(spinValue->value()); + else { + if(QComboBox* comboBoxValue = dynamic_cast(_fieldValue)) + notification->setSingleValue(comboBoxValue->currentIndex()); + else { + if(QLineEdit* rangeValue = dynamic_cast(_fieldValue)) { + QString str = rangeValue->text(); + QStringList range = str.split('-'); + notification->setSingleValue(range.at(0).toDouble()); + notification->setValueRange2(range.at(1).toDouble()); + } + } } } + +//----------------------------------------------------------------------------- +void NotifyPluginOptionsPage::onUAVField_indexChanged(QString field) { + _fieldType = -1; + UAVDataObject* obj = dynamic_cast( objManager.getObject(options_page->UAVObject->currentText())); + addDynamicField(obj->getField(field)); + +} + ////////////////////////////////////////////////////////////////////////////// // Fills in the combo box when value is changed in the // combo box ////////////////////////////////////////////////////////////////////////////// void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) { - options_page->UAVObjectField->clear(); - ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager* objManager = pm->getObject(); - UAVDataObject* obj = dynamic_cast( objManager->getObject(val) ); + _fieldType = -1; + UAVDataObject* obj = dynamic_cast( objManager.getObject(val) ); QList fieldList = obj->getFields(); + disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); + options_page->UAVObjectField->clear(); foreach (UAVObjectField* field, fieldList) { options_page->UAVObjectField->addItem(field->getName()); } + connect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); + addDynamicField(fieldList.at(0)); } -// locate collection folder on disk +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path) { QDir dirPath(path); @@ -213,7 +373,7 @@ void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path) options_page->SoundCollectionList->addItems(listDirCollections); } - +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) { options_page->SoundCollectionList->setCurrentIndex(index); @@ -238,6 +398,7 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) } +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate) { //Q_ASSERT(Phonon::ErrorState != newstate); @@ -253,25 +414,29 @@ void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon:: } } +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::onFinishedPlaying() { notifySound->clear(); } +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() { NotificationItem* notification = NULL; if (-1 == _notifyRulesSelection->currentIndex().row()) - return; + return; notifySound->clearQueue(); notification = privListNotifications.at(_notifyRulesSelection->currentIndex().row()); notification->parseNotifyMessage(); QStringList sequence = notification->getMessageSequence(); Q_ASSERT(!!sequence.size()); - foreach(QString item, sequence) - notifySound->enqueue(Phonon::MediaSource(item)); - + qNotifyDebug() << "on_buttonTestSoundNotification_clicked"; + foreach(QString item, sequence) { + qNotifyDebug() << item; + notifySound->enqueue(Phonon::MediaSource(item)); + } notifySound->play(); } @@ -284,90 +449,132 @@ void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state) audioOutput->setMuted(state1); } +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) { + Q_ASSERT(notification); + disconnect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_UAVObject_indexChanged(QString))); + disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), + this, SLOT(onUAVField_indexChanged(QString))); + QString path = notification->getSoundCollectionPath(); if (path == "") { - //QDir dir = QDir::currentPath(); - //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; - path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); + //QDir dir = QDir::currentPath(); + //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; + path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); } options_page->SoundDirectoryPathChooser->setPath(path); if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){ - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); } else { - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + } + + + // Fills the combo boxes for the UAVObjects + QList< QList > objList = objManager.getDataObjects(); + foreach (QList list, objList) { + foreach (UAVDataObject* obj, list) { + options_page->UAVObject->addItem(obj->getName()); + } } if (options_page->UAVObject->findText(notification->getDataObject())!=-1){ - options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); + options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); } - // Now load the object field values: options_page->UAVObjectField->clear(); QString uavDataObject = notification->getDataObject(); UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); if (obj != NULL ) { - QList fieldList = obj->getFields(); - foreach (UAVObjectField* field, fieldList) { - options_page->UAVObjectField->addItem(field->getName()); - } + QList fieldList = obj->getFields(); + foreach (UAVObjectField* field, fieldList) { + options_page->UAVObjectField->addItem(field->getName()); + } } if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) { - options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); + options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); } if (-1 != options_page->Sound1->findText(notification->getSound1())) { - options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); - - // don't show item if it wasn't find in stored location - //options_page->Sound1->setCurrentIndex(-1); + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); } if (-1 != options_page->Sound2->findText(notification->getSound2())) { - options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); - - // don't show item if it wasn't find in stored location - //options_page->Sound2->setCurrentIndex(-1); + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); } if (-1 != options_page->Sound3->findText(notification->getSound3())) { - options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); } - if (-1 != options_page->Value->findText(notification->getValue())) { - options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue())); + if (-1 != _valueRange->findText(notification->range())) { + _valueRange->setCurrentIndex(_valueRange->findText(notification->range())); } - if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) { - options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder())); + if (-1 != _sayOrder->findText(notification->getSayOrder())) { + _sayOrder->setCurrentIndex(_sayOrder->findText(notification->getSayOrder())); } - options_page->ValueSpinBox->setValue(notification->getSpinBoxValue()); + setDynamicValueField(notification); + + connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_UAVObject_indexChanged(QString))); + connect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), + this, SLOT(onUAVField_indexChanged(QString))); + } +//----------------------------------------------------------------------------- +void NotifyPluginOptionsPage::setDynamicValueField(NotificationItem* notification) +{ + if(QSpinBox* spinValue = dynamic_cast(_fieldValue)) + spinValue->setValue(notification->singleValue()); + else { + if(QComboBox* comboBoxValue = dynamic_cast(_fieldValue)) + comboBoxValue->setCurrentIndex(notification->singleValue()); + else { + if(QLineEdit* rangeValue = dynamic_cast(_fieldValue)) { + resetValueRange(); + rangeValue->setText(QString("%1%2").arg(notification->singleValue()) + .arg(notification->valueRange2())); + } else { + qNotifyDebug() << "NotifyPluginOptionsPage::setDynamicValueField | unknown _fieldValue: " << _fieldValue; + } + + } + } +} + +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ) { bool select = false; notifySound->stop(); if (selected.indexes().size()) { - select = true; - updateConfigView(privListNotifications.at(selected.indexes().at(0).row())); + select = true; + _selectedNotification = privListNotifications.at(selected.indexes().at(0).row()); + updateConfigView(_selectedNotification); + UAVDataObject* obj = dynamic_cast( objManager.getObject(options_page->UAVObject->currentText())); + UAVObjectField* field = obj->getField(options_page->UAVObjectField->currentText()); + addDynamicField(field); + setDynamicValueField(_selectedNotification); } options_page->buttonModify->setEnabled(select); @@ -375,7 +582,7 @@ void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemS options_page->buttonPlayNotification->setEnabled(select); } - +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() { NotificationItem* notification = new NotificationItem; @@ -392,34 +599,36 @@ void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); notification->setDataObject(options_page->UAVObject->currentText()); notification->setObjectField(options_page->UAVObjectField->currentText()); - notification->setValue(options_page->Value->currentText()); - notification->setSpinBoxValue(options_page->ValueSpinBox->value()); + notification->setRange(_valueRange->currentText()); + + if(QSpinBox* spinValue = dynamic_cast(_fieldValue)) + notification->setSingleValue(spinValue->value()); if (options_page->Sound1->currentText().size() > 0) - notification->setSound1(options_page->Sound1->currentText()); + notification->setSound1(options_page->Sound1->currentText()); notification->setSound2(options_page->Sound2->currentText()); notification->setSound3(options_page->Sound3->currentText()); -if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second")) - || ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) { + if ( ((!options_page->Sound2->currentText().size()) && (_sayOrder->currentText()=="After second")) + || ((!options_page->Sound3->currentText().size()) && (_sayOrder->currentText()=="After third")) ) { return; } else { - notification->setSayOrder(options_page->SayOrder->currentText()); + notification->setSayOrder(_sayOrder->currentText()); } - privListNotifications.append(notification); - emit entryAdded(privListNotifications.size() - 1); + + _notifyRulesModel->entryAdded(notification); _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } - +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() { _notifyRulesModel->removeRow(_notifyRulesSelection->currentIndex().row()); if (!_notifyRulesModel->rowCount() && (_notifyRulesSelection->currentIndex().row() > 0 - && _notifyRulesSelection->currentIndex().row() < _notifyRulesModel->rowCount()) ) + && _notifyRulesSelection->currentIndex().row() < _notifyRulesModel->rowCount()) ) { options_page->buttonDelete->setEnabled(false); options_page->buttonModify->setEnabled(false); @@ -428,6 +637,7 @@ void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() } +//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked() { NotificationItem* notification = new NotificationItem; diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp.orig b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp.orig index b91317c9f..2ff775e31 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp.orig +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp.orig @@ -43,13 +43,13 @@ #include "notifyplugin.h" #include "notifyitemdelegate.h" #include "notifytablemodel.h" +#include "notifylogging.h" NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) : IOptionsPage(parent) , objManager(*ExtensionSystem::PluginManager::instance()->getObject()) , owner(qobject_cast(parent)) , currentCollectionPath("") - , privListNotifications((qobject_cast(parent))->getListNotifications()) { } @@ -64,22 +64,53 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) //main widget QWidget *optionsPageWidget = new QWidget; //main layout + options_page->setupUi(optionsPageWidget); + + listSoundFiles.clear(); + + options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); + options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); + + // Fills the combo boxes for the UAVObjects + QList< QList > objList = objManager.getDataObjects(); + foreach (QList list, objList) { + foreach (UAVDataObject* obj, list) { + options_page->UAVObject->addItem(obj->getName()); + } + } + +<<<<<<< Updated upstream + connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); + connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); + connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); +======= + options_page = new Ui::NotifyPluginOptionsPage(); + //main widget + QWidget *optionsPageWidget = new QWidget; + //main layout options_page->setupUi(optionsPageWidget); delegateItems.clear(); listSoundFiles.clear(); + options_page->horizontalLayout_3->addWidget(new QPushButton("testtt")); delegateItems << "Repeat Once" << "Repeat Instantly" << "Repeat 10 seconds" << "Repeat 30 seconds" << "Repeat 1 minute"; + options_page->chkEnableSound->setChecked(owner->getEnableSound()); options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); + + + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + objManager = pm->getObject(); + // Fills the combo boxes for the UAVObjects - QList< QList > objList = objManager.getDataObjects(); + QList< QList > objList = objManager->getDataObjects(); foreach (QList list, objList) { foreach (UAVDataObject* obj, list) { options_page->UAVObject->addItem(obj->getName()); @@ -88,95 +119,122 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); - connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); + connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); + connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); + connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); +// connect(options_page->buttonTestSound1, SIGNAL(clicked()), this, SLOT(on_buttonTestSound1_clicked())); +// connect(options_page->buttonTestSound2, SIGNAL(clicked()), this, SLOT(on_buttonTestSound2_clicked())); + connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); + connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); - connect(this, SIGNAL(updateNotifications(QList)), - owner, SLOT(updateNotificationList(QList))); + + connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); + connect(this, SIGNAL(updateNotifications(QList)), + owner, SLOT(updateNotificationList(QList))); connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); //emit resetNotification(); - privListNotifications.clear(); - for (int i = 0; i < owner->getListNotifications().size(); ++i) { - NotificationItem* notification = new NotificationItem(); - owner->getListNotifications().at(i)->copyTo(notification); - privListNotifications.append(notification); + privListNotifications.clear(); + + for (int i = 0; i < owner->getListNotifications().size(); ++i) { + NotifyPluginConfiguration* notification = new NotifyPluginConfiguration(); + owner->getListNotifications().at(i)->copyTo(notification); + privListNotifications.append(notification); } - updateConfigView(owner->getCurrentNotification()); + updateConfigView(owner->getCurrentNotification()); - initButtons(); - initRulesTableModel(); - initRulesTableView(); - initPhononPlayer(); + options_page->chkEnableSound->setChecked(owner->getEnableSound()); - return optionsPageWidget; + QStringList headerStrings; + headerStrings << "Name" << "Repeats" << "Lifetime,sec"; +>>>>>>> Stashed changes + + connect(this, SIGNAL(updateNotifications(QList)), + owner, SLOT(updateNotificationList(QList))); + //connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); + + +// privListNotifications = ((qobject_cast(parent))->getListNotifications()); + privListNotifications = owner->getListNotifications(); + + updateConfigView(owner->getCurrentNotification()); + + initRulesTable(); + initButtons(); + initPhononPlayer(); + + return optionsPageWidget; } void NotifyPluginOptionsPage::initButtons() { - options_page->chkEnableSound->setChecked(owner->getEnableSound()); - connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); + options_page->chkEnableSound->setChecked(owner->getEnableSound()); + connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); - options_page->buttonModify->setEnabled(false); - options_page->buttonDelete->setEnabled(false); - options_page->buttonPlayNotification->setEnabled(false); - connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); - connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); - connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); - connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); + options_page->buttonModify->setEnabled(false); + options_page->buttonDelete->setEnabled(false); + options_page->buttonPlayNotification->setEnabled(false); + connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); + connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); + connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); + connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); } void NotifyPluginOptionsPage::initPhononPlayer() { - notifySound = Phonon::createPlayer(Phonon::NotificationCategory); - connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), + notifySound.reset(Phonon::createPlayer(Phonon::NotificationCategory)); + connect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); + connect(notifySound.data(), SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); } -void NotifyPluginOptionsPage::initRulesTableModel() +void NotifyPluginOptionsPage::initRulesTable() { - notifyRulesModel.reset(new NotifyTableModel(&privListNotifications)); - notifyRulesSelection = new QItemSelectionModel(notifyRulesModel.data()); - connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), + qNotifyDebug_if(_notifyRulesModel.isNull()) << "_notifyRulesModel.isNull())"; + qNotifyDebug_if(!_notifyRulesSelection) << "_notifyRulesSelection.isNull())"; + //QItemSelectionModel* selection = _notifyRulesSelection.take(); + _notifyRulesModel.reset(new NotifyTableModel(privListNotifications)); + _notifyRulesSelection = new QItemSelectionModel(_notifyRulesModel.data()); + + connect(_notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); connect(this, SIGNAL(entryUpdated(int)), - notifyRulesModel.data(), SLOT(entryUpdated(int))); + _notifyRulesModel.data(), SLOT(entryUpdated(int))); connect(this, SIGNAL(entryAdded(int)), - notifyRulesModel.data(), SLOT(entryAdded(int))); -} + _notifyRulesModel.data(), SLOT(entryAdded(int))); + + options_page->notifyRulesView->setModel(_notifyRulesModel.data()); + options_page->notifyRulesView->setSelectionModel(_notifyRulesSelection); + options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(this)); + + options_page->notifyRulesView->resizeRowsToContents(); + options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); + options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); + options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); + options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); + options_page->notifyRulesView->setDragEnabled(true); + options_page->notifyRulesView->setAcceptDrops(true); + options_page->notifyRulesView->setDropIndicatorShown(true); + options_page->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove); -void NotifyPluginOptionsPage::initRulesTableView() -{ - options_page->notifyRulesView->setModel(notifyRulesModel.data()); - options_page->notifyRulesView->resizeRowsToContents(); - options_page->notifyRulesView->setSelectionModel(notifyRulesSelection); - options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); - options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); - options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); - options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); - options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); - options_page->notifyRulesView->setDragEnabled(true); - options_page->notifyRulesView->setAcceptDrops(true); - options_page->notifyRulesView->setDropIndicatorShown(true); } void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) { - notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); - notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); - notification->setDataObject(options_page->UAVObject->currentText()); - notification->setObjectField(options_page->UAVObjectField->currentText()); - notification->setSound1(options_page->Sound1->currentText()); - notification->setSound2(options_page->Sound2->currentText()); - notification->setSound3(options_page->Sound3->currentText()); - notification->setSayOrder(options_page->SayOrder->currentText()); - notification->setValue(options_page->Value->currentText()); - notification->setSpinBoxValue(options_page->ValueSpinBox->value()); - + notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); + notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); + notification->setDataObject(options_page->UAVObject->currentText()); + notification->setObjectField(options_page->UAVObjectField->currentText()); + notification->setSound1(options_page->Sound1->currentText()); + notification->setSound2(options_page->Sound2->currentText()); + notification->setSound3(options_page->Sound3->currentText()); + notification->setSayOrder(options_page->SayOrder->currentText()); + notification->setValue(options_page->Value->currentText()); + notification->setSpinBoxValue(options_page->ValueSpinBox->value()); } /*! @@ -185,19 +243,19 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio */ void NotifyPluginOptionsPage::apply() { - getOptionsPageValues(owner->getCurrentNotification()); - owner->setEnableSound(options_page->chkEnableSound->isChecked()); - emit updateNotifications(privListNotifications); + getOptionsPageValues(owner->getCurrentNotification()); + owner->setEnableSound(options_page->chkEnableSound->isChecked()); + emit updateNotifications(privListNotifications); } void NotifyPluginOptionsPage::finish() { - disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - if (notifySound) { - notifySound->stop(); - notifySound->clear(); - } + disconnect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(changeButtonText(Phonon::State,Phonon::State))); + if (notifySound) { + notifySound->stop(); + notifySound->clear(); + } } ////////////////////////////////////////////////////////////////////////////// @@ -205,23 +263,23 @@ void NotifyPluginOptionsPage::finish() // combo box ////////////////////////////////////////////////////////////////////////////// void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) { - options_page->UAVObjectField->clear(); - ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager* objManager = pm->getObject(); + options_page->UAVObjectField->clear(); + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager* objManager = pm->getObject(); UAVDataObject* obj = dynamic_cast( objManager->getObject(val) ); QList fieldList = obj->getFields(); foreach (UAVObjectField* field, fieldList) { - options_page->UAVObjectField->addItem(field->getName()); + options_page->UAVObjectField->addItem(field->getName()); } } // locate collection folder on disk void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path) { - QDir dirPath(path); - listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); - options_page->SoundCollectionList->clear(); - options_page->SoundCollectionList->addItems(listDirCollections); + QDir dirPath(path); + listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + options_page->SoundCollectionList->clear(); + options_page->SoundCollectionList->addItems(listDirCollections); } @@ -230,7 +288,7 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) options_page->SoundCollectionList->setCurrentIndex(index); currentCollectionPath = options_page->SoundDirectoryPathChooser->path() - + QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText()); + + QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText()); QDir dirPath(currentCollectionPath); QStringList filters; @@ -238,7 +296,6 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) dirPath.setNameFilters(filters); listSoundFiles = dirPath.entryList(filters); listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), ""); - options_page->Sound1->clear(); options_page->Sound2->clear(); options_page->Sound3->clear(); @@ -252,135 +309,122 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate) { - //Q_ASSERT(Phonon::ErrorState != newstate); + //Q_ASSERT(Phonon::ErrorState != newstate); - if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { - options_page->buttonPlayNotification->setText("Play"); - options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); - } else { - if (newstate == Phonon::PlayingState) { - options_page->buttonPlayNotification->setText("Stop"); - options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); - } - } + if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { + options_page->buttonPlayNotification->setText("Play"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); + } else { + if (newstate == Phonon::PlayingState) { + options_page->buttonPlayNotification->setText("Stop"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); + } + } } void NotifyPluginOptionsPage::onFinishedPlaying() { - notifySound->clear(); + notifySound->clear(); } void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() { - NotificationItem* notification = NULL; + NotificationItem* notification = NULL; - if (-1 == notifyRulesSelection->currentIndex().row()) - return; - notifySound->clearQueue(); - notification = privListNotifications.at(notifyRulesSelection->currentIndex().row()); - notification->parseNotifyMessage(); - QStringList sequence = notification->getMessageSequence(); - Q_ASSERT(!!sequence.size()); - foreach(QString item, sequence) - notifySound->enqueue(Phonon::MediaSource(item)); + if (-1 == _notifyRulesSelection->currentIndex().row()) + return; + notifySound->clearQueue(); + notification = privListNotifications.at(_notifyRulesSelection->currentIndex().row()); + notification->parseNotifyMessage(); + QStringList sequence = notification->getMessageSequence(); + Q_ASSERT(!!sequence.size()); + foreach(QString item, sequence) + notifySound->enqueue(Phonon::MediaSource(item)); - notifySound->play(); + notifySound->play(); } void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state) { - bool state1 = 1^state; + bool state1 = 1^state; - QList listOutputs = notifySound->outputPaths(); - Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink(); - audioOutput->setMuted(state1); + QList listOutputs = notifySound->outputPaths(); + Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink(); + audioOutput->setMuted(state1); } void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) { QString path = notification->getSoundCollectionPath(); if (path == "") { - //QDir dir = QDir::currentPath(); - //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; - path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); + //QDir dir = QDir::currentPath(); + //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; + path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); } options_page->SoundDirectoryPathChooser->setPath(path); if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){ - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); } else { - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); } if (options_page->UAVObject->findText(notification->getDataObject())!=-1){ - options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); + options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); } -<<<<<<< Updated upstream - // Now load the object field values: - options_page->UAVObjectField->clear(); - QString uavDataObject = notification->getDataObject(); - UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); - if (obj != NULL ) { - QList fieldList = obj->getFields(); - foreach (UAVObjectField* field, fieldList) { - options_page->UAVObjectField->addItem(field->getName()); - } - } -======= // Now load the object field values: options_page->UAVObjectField->clear(); QString uavDataObject = notification->getDataObject(); - UAVDataObject* obj = dynamic_cast( objManager->getObject(uavDataObject/*objList.at(0).at(0)->getName()*/) ); + UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); if (obj != NULL ) { - QList fieldList = obj->getFields(); - foreach (UAVObjectField* field, fieldList) { - options_page->UAVObjectField->addItem(field->getName()); - } + QList fieldList = obj->getFields(); + foreach (UAVObjectField* field, fieldList) { + options_page->UAVObjectField->addItem(field->getName()); + } } ->>>>>>> Stashed changes if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) { - options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); + options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); } if (-1 != options_page->Sound1->findText(notification->getSound1())) { - options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); - // don't show item if it wasn't find in stored location - //options_page->Sound1->setCurrentIndex(-1); + // don't show item if it wasn't find in stored location + //options_page->Sound1->setCurrentIndex(-1); } if (-1 != options_page->Sound2->findText(notification->getSound2())) { - options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); - // don't show item if it wasn't find in stored location - //options_page->Sound2->setCurrentIndex(-1); + // don't show item if it wasn't find in stored location + //options_page->Sound2->setCurrentIndex(-1); } if (-1 != options_page->Sound3->findText(notification->getSound3())) { - options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); } else { - // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + // show item from default location + options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); } if (-1 != options_page->Value->findText(notification->getValue())) { - options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue())); + options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue())); } if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) { - options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder())); + options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder())); } options_page->ValueSpinBox->setValue(notification->getSpinBoxValue()); @@ -388,78 +432,81 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ) { - bool select = false; - notifySound->stop(); - if (selected.indexes().size()) { - select = true; - updateConfigView(privListNotifications.at(selected.indexes().at(0).row())); - } + bool select = false; + notifySound->stop(); + if (selected.indexes().size()) { + select = true; + updateConfigView(privListNotifications.at(selected.indexes().at(0).row())); + } - options_page->buttonModify->setEnabled(select); - options_page->buttonDelete->setEnabled(select); - options_page->buttonPlayNotification->setEnabled(select); + options_page->buttonModify->setEnabled(select); + options_page->buttonDelete->setEnabled(select); + options_page->buttonPlayNotification->setEnabled(select); } void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() { - NotificationItem* notification = new NotificationItem; + NotificationItem* notification = new NotificationItem; - if (options_page->SoundDirectoryPathChooser->path()=="") { - QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); - textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); - options_page->SoundDirectoryPathChooser->setPalette(textPalette); - options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder"); - return; - } + if (options_page->SoundDirectoryPathChooser->path()=="") { + QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); + textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); + options_page->SoundDirectoryPathChooser->setPalette(textPalette); + options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder"); + return; + } - notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); - notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); - notification->setDataObject(options_page->UAVObject->currentText()); - notification->setObjectField(options_page->UAVObjectField->currentText()); - notification->setValue(options_page->Value->currentText()); - notification->setSpinBoxValue(options_page->ValueSpinBox->value()); + notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); + notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); + notification->setDataObject(options_page->UAVObject->currentText()); + notification->setObjectField(options_page->UAVObjectField->currentText()); + notification->setValue(options_page->Value->currentText()); + notification->setSpinBoxValue(options_page->ValueSpinBox->value()); - if (options_page->Sound1->currentText().size() > 0) - notification->setSound1(options_page->Sound1->currentText()); + if (options_page->Sound1->currentText().size() > 0) + notification->setSound1(options_page->Sound1->currentText()); - notification->setSound2(options_page->Sound2->currentText()); - notification->setSound3(options_page->Sound3->currentText()); + notification->setSound2(options_page->Sound2->currentText()); + notification->setSound3(options_page->Sound3->currentText()); - if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second")) - || ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) { - return; - } else { - notification->setSayOrder(options_page->SayOrder->currentText()); - } - privListNotifications.append(notification); - emit entryAdded(privListNotifications.size() - 1); - notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), - QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); +if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second")) + || ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) { + return; + } else { + notification->setSayOrder(options_page->SayOrder->currentText()); + } + privListNotifications.append(notification); + emit entryAdded(privListNotifications.size() - 1); + _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() { - notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row()); - if (!notifyRulesModel->rowCount() - && (notifyRulesSelection->currentIndex().row() > 0 - && notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) ) - { - options_page->buttonDelete->setEnabled(false); - options_page->buttonModify->setEnabled(false); - options_page->buttonPlayNotification->setEnabled(false); - } + _notifyRulesModel->removeRow(_notifyRulesSelection->currentIndex().row()); + if (!_notifyRulesModel->rowCount() + && (_notifyRulesSelection->currentIndex().row() > 0 + && _notifyRulesSelection->currentIndex().row() < _notifyRulesModel->rowCount()) ) + { + options_page->buttonDelete->setEnabled(false); + options_page->buttonModify->setEnabled(false); + options_page->buttonPlayNotification->setEnabled(false); + } } void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked() { - NotificationItem* notification = new NotificationItem; - getOptionsPageValues(notification); - notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag()); - privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification); - entryUpdated(notifyRulesSelection->currentIndex().row()); + NotificationItem* notification = new NotificationItem; + getOptionsPageValues(notification); + notification->setRetryString(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryString()); + notification->setLifetime(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->lifetime()); + notification->setMute(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->mute()); + + privListNotifications.replace(_notifyRulesSelection->currentIndex().row(),notification); + entryUpdated(_notifyRulesSelection->currentIndex().row()); } diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h index 9e49e89ec..f4a29ae41 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h @@ -42,7 +42,8 @@ #include #include #include -//#include "notifytablemodel.h" +#include +#include class NotifyTableModel; class NotificationItem; @@ -65,8 +66,6 @@ public: QString category() const { return QLatin1String("Notify Plugin");} QString trCategory() const { return tr("Notify Plugin");} - - QWidget *createPage(QWidget *parent); void apply(); void finish(); @@ -75,13 +74,39 @@ public: void updateConfigView(NotificationItem* notification); void getOptionsPageValues(NotificationItem* notification); +signals: + void updateNotifications(QList list); + //void resetNotification(void); + void entryUpdated(int index); + private: Q_DISABLE_COPY(NotifyPluginOptionsPage) + void resetValueRange(); + void setDynamicValueField(NotificationItem* notification); + void addDynamicField(UAVObjectField* objField); + void addDynamicValueLayout(); void initButtons(); void initPhononPlayer(); void initRulesTable(); +private slots: + void on_buttonTestSoundNotification_clicked(); + + void on_buttonAddNotification_clicked(); + void on_buttonDeleteNotification_clicked(); + void on_buttonModifyNotification_clicked(); + void on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ); + void on_soundLanguage_indexChanged(int index); + void on_buttonSoundFolder_clicked(const QString& path); + void on_UAVObject_indexChanged(QString val); + void onUAVField_indexChanged(QString val); + void changeButtonText(Phonon::State newstate, Phonon::State oldstate); + void on_chkEnableSound_toggled(bool state); + void on_rangeValue_indexChanged(QString); + + void onFinishedPlaying(void); + private: UAVObjectManager& objManager; SoundNotifyPlugin* owner; @@ -99,28 +124,12 @@ private: QScopedPointer options_page; -signals: - void updateNotifications(QList list); - //void resetNotification(void); - void entryUpdated(int index); - void entryAdded(int position); - - -private slots: - void on_buttonTestSoundNotification_clicked(); - - void on_buttonAddNotification_clicked(); - void on_buttonDeleteNotification_clicked(); - void on_buttonModifyNotification_clicked(); - void on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ); - void on_soundLanguage_indexChanged(int index); - void on_buttonSoundFolder_clicked(const QString& path); - void on_UAVObject_indexChanged(QString val); - void changeButtonText(Phonon::State newstate, Phonon::State oldstate); - void on_chkEnableSound_toggled(bool state); - - void onFinishedPlaying(void); - + QComboBox* _valueRange; + QComboBox* _sayOrder; + QWidget* _fieldValue; + int _fieldType; + QWidget* _form; + NotificationItem* _selectedNotification; }; #endif // NOTIFYPLUGINOPTIONSPAGE_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui index 4645bd14a..23d05c2a0 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui @@ -6,7 +6,7 @@ 0 0 - 589 + 570 453 @@ -19,531 +19,364 @@ Form - - - - 10 - 10 - 551 - 81 - + + + QLayout::SetMinimumSize - - Sound Collection - - - - - 10 - 20 - 531 - 51 - - - - - 6 + + + + QLayout::SetFixedSize - - - - Language + + + + + 0 + 0 + - - - - - - true + + Sound Collection - - - 75 - 23 - - - - - - - - - 147 - 0 - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + + + + + true + + + + 75 + 23 + + + + + 550 + 16777215 + + + + + + + + + 0 + 0 + + + + Language + + + + + + + + 147 + 0 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Select the sound collection</span></p></body></html> + + + + + + + + + + + + + + + + + DataObject + + + + + + + + 0 + 0 + + + + + + + + ObjectField + + + + + + + + 0 + 0 + - - - - - - 10 - 220 - 551 - 211 - - - - Sound Notifications - - - - - 10 - 180 - 531 - 26 - - - + + + + + Qt::Horizontal + + + + + + + + - + + + + 0 + 0 + + - Enable Sounds + Sound1: - - - Qt::Horizontal + + + + 0 + 0 + - + - 138 - 20 + 110 + 0 - - - - - - Play - - - - :/notify/images/play.png:/notify/images/play.png - - - - - - - Qt::Horizontal - - + - 40 - 20 + 16777215 + 16777215 - + - - - Qt::Horizontal + + + + 0 + 0 + - + + Sound2: + + + + + + + + 0 + 0 + + + - 40 - 20 + 110 + 0 - - - - - - Add - - - - :/notify/images/add.png:/notify/images/add.png + + + 16777215 + 16777215 + - - - Modify + + + + 0 + 0 + - - - :/notify/images/modify.png:/notify/images/modify.png + + Sound3: - - - Delete + + + + 0 + 0 + - - - :/utils/images/removesubmitfield.png:/utils/images/removesubmitfield.png + + + 110 + 0 + + + + + 16777215 + 16777215 + - - - - - 10 - 20 - 531 - 151 - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - 22 - - - 22 - - - - - - - 10 - 100 - 551 - 31 - - - - - - - DataObject - - - - - - - - 0 - 0 - - - - - - - - ObjectField - - - - - - - - 0 - 0 - - - - - - - - - - 7 - 130 - 551 - 20 - - - - Qt::Horizontal - - - - - - 10 - 180 - 551 - 31 - - - - - - - - 0 - 0 - - - - Sound1: - - - - - - - - 0 - 0 - - - - - 110 - 0 - - - - - 16777215 - 16777215 - - - - - - - - Sound2: - - - - - - - - 0 - 0 - - - - - 110 - 0 - - - - - 16777215 - 16777215 - - - - - - - - Sound3: - - - - - - - - 0 - 0 - - - - - 110 - 0 - - - - - 16777215 - 16777215 - - - - - - - - - - 10 - 150 - 551 - 31 - - - - - - - true - - - - 0 - 0 - - - - - 40 - 0 - - - - Value is - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 110 - 16777215 - - + + + + + + + + Sound Notifications + + - - Equal to - + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + 22 + + + 22 + + - - Greater than - + + + + + Enable Sounds + + + + + + + Qt::Horizontal + + + + 138 + 20 + + + + + + + + Play + + + + :/notify/images/play.png:/notify/images/play.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add + + + + :/notify/images/add.png:/notify/images/add.png + + + + + + + Modify + + + + :/notify/images/modify.png:/notify/images/modify.png + + + + + + + Delete + + + + :/utils/images/removesubmitfield.png:/utils/images/removesubmitfield.png + + + + - - - Less than - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 170 - 16777215 - - - - 2 - - - 9999.899999999999636 - - - 1.000000000000000 - - - - - - - - 0 - 0 - - - - Say Order - - - - - - - - 0 - 0 - - - - - 110 - 16777215 - - - - Select if the value of the object should be spoken and if so, either before the configured sound or after it. - - - - Never - - - - - Before first - - - - - After first - - - - - After second - - - - - After third - - - - - - + + + + diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp index 0c2337437..138af106b 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp @@ -162,9 +162,13 @@ void NotifyTableModel::entryUpdated(int offset) emit dataChanged(idx, idx); } -void NotifyTableModel::entryAdded(int position) +void NotifyTableModel::entryAdded(NotificationItem* item) { - insertRows(position, 1,QModelIndex()); + insertRows(rowCount(), 1, QModelIndex()); + NotificationItem* tmp = _list.at(rowCount() - 1); + _list.replace(rowCount() - 1, item); + delete tmp; + entryUpdated(rowCount() - 1); } diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h index f58cc0599..3168a848f 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h @@ -86,12 +86,13 @@ public: bool insertRows(int position, int rows, const QModelIndex &index); bool removeRows(int position, int rows, const QModelIndex &index); + void entryAdded(NotificationItem* item); + signals: void dragRows(int position, int count); private slots: void entryUpdated(int offset); - void entryAdded(int position); void dropRows(int position, int count) const; private: From 6a5589ef5101bef3d7e37a37aad32925adea66e4 Mon Sep 17 00:00:00 2001 From: Nickolay Date: Tue, 4 Oct 2011 01:59:37 +0300 Subject: [PATCH 8/9] +multiple selection with D&D completed; +support of enum and range for value completed; --- .../src/plugins/notify/NotificationItem.h | 35 +- .../src/plugins/notify/notificationitem.cpp | 299 +++++----- .../src/plugins/notify/notifyitemdelegate.cpp | 15 +- .../src/plugins/notify/notifyitemdelegate.h | 24 +- .../src/plugins/notify/notifyplugin.cpp | 62 +- .../src/plugins/notify/notifyplugin.h | 88 +-- .../notify/notifypluginoptionspage.cpp | 539 +++++++++--------- .../plugins/notify/notifypluginoptionspage.h | 136 +++-- .../plugins/notify/notifypluginoptionspage.ui | 2 +- .../src/plugins/notify/notifytablemodel.cpp | 102 ++-- .../src/plugins/notify/notifytablemodel.h | 80 ++- 11 files changed, 699 insertions(+), 683 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h index 20de7a4f8..1898f1a55 100644 --- a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h +++ b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h @@ -103,7 +103,31 @@ public: void seriaize(QDataStream& stream); void deseriaize(QDataStream& stream); - QString parseNotifyMessage(); + /** + * Convert notification item fields in single string, + * to show in table for example + * + * @return string which describe notification + */ + QString toString(); + + /** + * Generate list of sound files needed to play notification + * + * @return success - reference to non-empty _messageSequence; + * error - if one of sounds doesn't exist returns + * reference to empty _messageSequence; + */ + QStringList& toSoundList(); + + /** + * Returns sound caption name, needed to create string representation of notification. + * + * @return success - string == , if sound file exists + * error - string == [missind], if sound file doesn't exist + */ + QString getSoundCaption(QString fileName); + QTimer* getTimer() const { return _timer; } void startTimer(int value); @@ -119,10 +143,14 @@ public: bool isNowPlaying; bool firstStart; -private: - void checkSoundFilesExisting(bool& missed1, bool& missed2, bool& missed3); + static QStringList sayOrderValues; + static QStringList retryValues; private: + QString checkSoundExists(QString fileName); + +private: + QTimer* _timer; //! time from putting notification in queue till moment when notification became out-of-date @@ -130,6 +158,7 @@ private: //! according to its priority QTimer* _expireTimer; + //! list of wav files from which notification consists QStringList _messageSequence; //! path to folder with sound files diff --git a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp index d6c803b68..1b0e634a6 100644 --- a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp @@ -40,10 +40,28 @@ #include "notifylogging.h" +static const QString cStrNever("Never"); +static const QString cStrBefore1st("Before first"); +static const QString cStrBefore2nd("Before second"); +static const QString cStrAfter2nd("After second"); + +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"); +static const QString cStrRetry1min("Repeat 1 minute"); + + +QStringList NotificationItem::sayOrderValues; +QStringList NotificationItem::retryValues; + + NotificationItem::NotificationItem(QObject *parent) : QObject(parent) , isNowPlaying(0) , firstStart(true) + , _timer(NULL) + , _expireTimer(NULL) , _soundCollectionPath("") , _currentLanguage("default") , _dataObject("") @@ -52,16 +70,23 @@ NotificationItem::NotificationItem(QObject *parent) , _sound1("") , _sound2("") , _sound3("") - , _sayOrder("Never") + , _sayOrder(cStrNever) , _singleValue(0) , _valueRange2(0) - , _repeatString("Repeat Instantly") + , _repeatString(cStrRetryInstantly) , _expireTimeout(eDefaultTimeout) , _mute(false) - { - _timer = NULL; - _expireTimer = NULL; + NotificationItem::sayOrderValues.append(cStrBefore1st); + NotificationItem::sayOrderValues.append(cStrBefore2nd); + NotificationItem::sayOrderValues.append(cStrAfter2nd); + + NotificationItem::retryValues.append(cStrRetryOnce); + NotificationItem::retryValues.append(cStrRetryInstantly); + NotificationItem::retryValues.append(cStrRetry10sec); + NotificationItem::retryValues.append(cStrRetry30sec); + NotificationItem::retryValues.append(cStrRetry1min); + } void NotificationItem::copyTo(NotificationItem* that) const @@ -103,7 +128,6 @@ void NotificationItem::saveState(QSettings* settings) const settings->setValue(QLatin1String("Repeat"), retryString()); settings->setValue(QLatin1String("ExpireTimeout"), lifetime()); settings->setValue(QLatin1String("Mute"), mute()); - } void NotificationItem::restoreState(QSettings* settings) @@ -123,7 +147,6 @@ void NotificationItem::restoreState(QSettings* settings) setRetryString(settings->value(QLatin1String("Repeat"), tr("")).toString()); setLifetime(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt()); setMute(settings->value(QLatin1String("Mute"), tr("")).toInt()); - } void NotificationItem::seriaize(QDataStream& stream) @@ -162,7 +185,8 @@ void NotificationItem::deseriaize(QDataStream& stream) stream >> this->_mute; } -void NotificationItem::startTimer(int value) { +void NotificationItem::startTimer(int value) +{ if (!_timer) { _timer = new QTimer(this); _timer->setInterval(value); @@ -171,14 +195,16 @@ void NotificationItem::startTimer(int value) { _timer->start(); } -void NotificationItem::stopTimer() { +void NotificationItem::stopTimer() +{ if (_timer) { if (_timer->isActive()) _timer->stop(); } } -void NotificationItem::disposeTimer() { +void NotificationItem::disposeTimer() +{ if (_timer) { _timer->stop(); delete _timer; @@ -186,22 +212,24 @@ void NotificationItem::disposeTimer() { } } -void NotificationItem::startExpireTimer() { - if (!_expireTimer) - { +void NotificationItem::startExpireTimer() +{ + if (!_expireTimer) { _expireTimer = new QTimer(this); } _expireTimer->start(_expireTimeout * 1000); } -void NotificationItem::stopExpireTimer() { +void NotificationItem::stopExpireTimer() +{ if (_expireTimer) { if (_expireTimer) _expireTimer->stop(); } } -void NotificationItem::disposeExpireTimer() { +void NotificationItem::disposeExpireTimer() +{ if (_expireTimer) { _expireTimer->stop(); delete _expireTimer; @@ -209,91 +237,33 @@ void NotificationItem::disposeExpireTimer() { } } -#define missed "missed sound" -#define CHECK_ADD_SOUND(n) ((!_missedSound##n) ? getSound##n() : (missed#n)) -#define CHECK_REPLACE_SOUND(n) ((!_missedSound##n) ? str.replace(missed#n, getSound##n()) : (missed#n)) - -QString NotificationItem::parseNotifyMessage() +int getValuePosition(QString sayOrder) { - // tips: - // check of *.wav files exist needed for playing phonon queues; - // if phonon player don't find next file in queue, it buzz + return NotificationItem::sayOrderValues.indexOf(sayOrder); +} - QString str; - QString value; - QString sayOrder = getSayOrder(); - UAVObjectField* field = getUAVObjectField(); - if (UAVObjectField::ENUM == field->getType()) { - Q_ASSERT(singleValue() < field->getOptions().size()); - value = QString("%L1").arg(field->getOptions().at(singleValue())); - } else { - value = QString("%L1").arg(singleValue()); +QString NotificationItem::checkSoundExists(QString fileName) +{ + QString name(fileName + ".wav"); + QString filePath = QDir::toNativeSeparators(getSoundCollectionPath() + "/" + + getCurrentLanguage() + "/" + + name); + if(QFile::exists(filePath)) + return filePath; + else { + filePath = QDir::toNativeSeparators(getSoundCollectionPath() + + "/default/" + + name); + if(!QFile::exists(filePath)) + filePath.clear(); } + return filePath; +} - int position = -1; // default don't play value wav file - - // generate queue of sound files to play - _messageSequence.clear(); - - bool _missedSound1 = false; - bool _missedSound2 = false; - bool _missedSound3 = false; - - checkSoundFilesExisting(_missedSound1, _missedSound2, _missedSound3); - str = CHECK_ADD_SOUND(1)+" "+CHECK_ADD_SOUND(2)+" "+CHECK_ADD_SOUND(3); - - if(!_messageSequence.size()) { - qNotifyDebug() << "no any files in message queue"; - } - - sayOrder = sayOrder.trimmed(); - switch(sayOrder.at(0).toUpper().toAscii()) - { - case 'B'://BEFORE: - CHECK_REPLACE_SOUND(1); - CHECK_REPLACE_SOUND(2); - CHECK_REPLACE_SOUND(3); - str.prepend(value + " "); - position = 0; - break; - - case 'A'://AFTER: - switch(sayOrder.at(6).toLower().toAscii()) - { - case 'f': - str = CHECK_ADD_SOUND(1)+" "+value+" "+CHECK_ADD_SOUND(2)+" "+CHECK_ADD_SOUND(3); - position = 1; - break; - - case 's': - str = CHECK_ADD_SOUND(1)+" "+CHECK_ADD_SOUND(2)+" "+value+" "+CHECK_ADD_SOUND(3); - position = 2; - break; - - case 't': - CHECK_REPLACE_SOUND(1); - CHECK_REPLACE_SOUND(2); - CHECK_REPLACE_SOUND(3); - str.append(" "+value); - position = 3; - break; - } - break; - - default: - CHECK_REPLACE_SOUND(1); - CHECK_REPLACE_SOUND(2); - CHECK_REPLACE_SOUND(3); - break; - } - - if(-1 == position) { - qNotifyDebug() << "NotificationItem::parseNotifyMessage() | value position undefined"; - return str; - } - - if (UAVObjectField::ENUM == field->getType()) return str; - +QStringList valueToSoundList(QString value) +{ + // replace point chr if exists + value = value.replace(',', '.'); QStringList numberParts = value.trimmed().split("."); QStringList digitWavs; @@ -338,23 +308,100 @@ QString NotificationItem::parseNotifyMessage() digitWavs.append(numberParts.at(1).right(1)); } } - foreach(QString fileName, digitWavs) { - fileName+=".wav"; - QString filePath = QDir::toNativeSeparators(getSoundCollectionPath()+"/"+ getCurrentLanguage()+"/"+fileName); - if(QFile::exists(filePath)) - _messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+ "/"+getCurrentLanguage()+"/"+fileName)); - else { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName))) - _messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName)); - else { - _messageSequence.clear(); - break; // if no some of *.wav files, then don't play number! - } + return digitWavs; +} + +QString NotificationItem::toString() +{ + QString str; + QString value; + UAVObjectField* field = getUAVObjectField(); + if (UAVObjectField::ENUM == field->getType()) { + Q_ASSERT(singleValue() < field->getOptions().size()); + value = field->getOptions().at(singleValue()); + } else { + value = QString("%L1").arg(singleValue()); + } + + int pos = getValuePosition(getSayOrder().trimmed()); + QStringList lst; + lst.append(getSoundCaption(getSound1())); + lst.append(getSoundCaption(getSound2())); + lst.append(getSoundCaption(getSound3())); + QStringList valueSounds = valueToSoundList(value); + bool missed = false; + foreach(QString sound, valueSounds) { + if(checkSoundExists(sound).isEmpty()) { + missed = true; + break; } } + + // if not "Never" case + if(-1 != pos) { + if(missed) + lst.insert(pos, "[missed]" + value); + else + lst.insert(pos, value); + } + str = lst.join(" "); return str; } +QStringList& NotificationItem::toSoundList() +{ + // tips: + // check of *.wav files exist needed for playing phonon queues; + // if phonon player don't find next file in queue, it buzz + + QString value; + UAVObjectField* field = getUAVObjectField(); + if (UAVObjectField::ENUM == field->getType()) { + Q_ASSERT(singleValue() < field->getOptions().size()); + value = field->getOptions().at(singleValue()); + } else { + value = QString("%L1").arg(singleValue()); + } + + // generate queue of sound files to play + _messageSequence.clear(); + int pos = getValuePosition(getSayOrder().trimmed()); + QStringList lst; + if(!getSound1().isEmpty()) + lst.append(getSound1()); + if(!getSound2().isEmpty()) + lst.append(getSound2()); + if(!getSound3().isEmpty()) + lst.append(getSound3()); + + // if not "Never" case + if(-1 != pos) { + QStringList valueSounds = valueToSoundList(value); + foreach(QString sound, valueSounds) + lst.insert(pos++, sound); + } + + foreach(QString sound, lst) { + QString path = checkSoundExists(sound); + if (!path.isEmpty()) { + _messageSequence.append(path); + } else { + _messageSequence.clear(); + break; + } + } + return _messageSequence; +} + +QString NotificationItem::getSoundCaption(QString fileName) +{ + if(fileName.isEmpty()) return QString(); + if(checkSoundExists(fileName).isEmpty()) { + return QString("[missed]") + fileName; + } + return fileName; +} + UAVObjectField* NotificationItem::getUAVObjectField() { return getUAVObject()->getField(getObjectField()); } @@ -362,39 +409,3 @@ UAVObjectField* NotificationItem::getUAVObjectField() { UAVDataObject* NotificationItem::getUAVObject() { return dynamic_cast((ExtensionSystem::PluginManager::instance()->getObject())->getObject(getDataObject())); } - - -void NotificationItem::checkSoundFilesExisting(bool& missed1, bool& missed2, bool& missed3) -{ - - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")); - else { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")); - else - missed1 = true; - } - - if(getSound2().size()) { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")); - else { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")); - else - missed2 = true; - } - } - - if(getSound3().size()) { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")); - else { - if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"))) - _messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")); - else - missed3 = true; - } - } -} diff --git a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp index d418f0d26..da7177b35 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.cpp @@ -29,34 +29,29 @@ #include "notifyitemdelegate.h" #include "notifytablemodel.h" #include "notifylogging.h" +#include "notificationitem.h" NotifyItemDelegate::NotifyItemDelegate(QObject* parent) : QItemDelegate(parent) , _parent(parent) { - _titles << "Repeat Once" - << "Repeat Instantly" - << "Repeat 10 seconds" - << "Repeat 30 seconds" - << "Repeat 1 minute"; - } QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*none*/, const QModelIndex& index) const { - if (eREPEAT_VALUE == index.column()) { + if (eRepeatValue == index.column()) { QComboBox* editor = new QComboBox(parent); editor->clear(); - editor->addItems(_titles); + editor->addItems(NotificationItem::retryValues); return editor; } else { - if (eEXPIRE_TIME == index.column()) { + if (eExpireTimer == index.column()) { QSpinBox* editor = new QSpinBox(parent); connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return editor; } else { - if (eENABLE_NOTIFICATION == index.column()) { + if (eTurnOn == index.column()) { QCheckBox* editor = new QCheckBox(parent); connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return editor; diff --git a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h index 494e61c17..ace6d4976 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyitemdelegate.h @@ -34,25 +34,23 @@ class NotifyItemDelegate : public QItemDelegate { - Q_OBJECT + Q_OBJECT public: - NotifyItemDelegate(QObject *parent = 0); - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, - const QModelIndex &index) const; - void setEditorData(QWidget *editor, const QModelIndex &index) const; - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const; - QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; + NotifyItemDelegate(QObject *parent = 0); + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, + const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; private slots: - void selectRow(const QString & text); - void commitAndCloseEditor(); + void selectRow(const QString & text); + void commitAndCloseEditor(); private: - QObject* _parent; - QStringList _titles; - + QObject* _parent; }; #endif // NOTIFYITEMDELEGATE_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp index fa55cfc42..88cb23621 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp @@ -49,7 +49,6 @@ SoundNotifyPlugin::SoundNotifyPlugin() { phonon.mo = NULL; configured = false; - // Do nothing } SoundNotifyPlugin::~SoundNotifyPlugin() @@ -57,7 +56,6 @@ SoundNotifyPlugin::~SoundNotifyPlugin() Core::ICore::instance()->saveSettings(this); if (phonon.mo != NULL) delete phonon.mo; - // Do nothing } bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg) @@ -99,8 +97,8 @@ void SoundNotifyPlugin::saveConfig( QSettings* settings, UAVConfigInfo *configIn settings->beginWriteArray("listNotifies"); for (int i = 0; i < lstNotifications.size(); i++) { - settings->setArrayIndex(i); - lstNotifications.at(i)->saveState(settings); + settings->setArrayIndex(i); + lstNotifications.at(i)->saveState(settings); } settings->endArray(); settings->setValue(QLatin1String("EnableSound"), enableSound); @@ -147,10 +145,10 @@ void SoundNotifyPlugin::readConfig_0_0_0(){ // read list of notifications from settings int size = settings->beginReadArray("listNotifies"); for (int i = 0; i < size; ++i) { - settings->setArrayIndex(i); - NotificationItem* notification = new NotificationItem; - notification->restoreState(settings); - lstNotifications.append(notification); + settings->setArrayIndex(i); + NotificationItem* notification = new NotificationItem; + notification->restoreState(settings); + lstNotifications.append(notification); } settings->endArray(); setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool()); @@ -237,14 +235,17 @@ void SoundNotifyPlugin::connectNotifications() notify->firstStart=true; notify->isNowPlaying=false; + if(notify->mute()) continue; + UAVDataObject* obj = dynamic_cast( objManager->getObject(notify->getDataObject()) ); if (obj != NULL ) { if (!lstNotifiedUAVObjects.contains(obj)) { - lstNotifiedUAVObjects.append(obj); - connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); + lstNotifiedUAVObjects.append(obj); + connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); } - } else - std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl; + } else { + qNotifyDebug() << "Error: Object is unknown (" << notify->getDataObject() << ")."; + } } if (lstNotifications.isEmpty()) return; @@ -294,7 +295,7 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA fieldName = notification->getObjectField(); UAVObjectField* field = object->getField(fieldName); - if (field->getName() == "") + if (field->getName().isEmpty()) return; double value = field->getDouble(); @@ -321,13 +322,11 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA if (!condition) return; - if (!playNotification(notification)) - { - if (!pendingNotifications.contains(notification)) - { + if (!playNotification(notification)) { + if (!pendingNotifications.contains(notification)) { notification->stopTimer(); - qNotifyDebug() << "add to pending list - " << notification->parseNotifyMessage(); + qNotifyDebug() << "add to pending list - " << notification->toString(); // if audio is busy, start expiration timer //ms = (notification->getExpiredTimeout()[in sec])*1000 //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); @@ -344,8 +343,8 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification) if (phonon.mo == NULL) return false; - if (!notification->mute()) - return true; + if (notification->mute()) + return false; qNotifyDebug() << "Phonon State: " << phonon.mo->state(); if ((phonon.mo->state()==Phonon::PausedState) @@ -375,9 +374,8 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification) } notification->firstStart=false; phonon.mo->clear(); - QString str = notification->parseNotifyMessage(); - qNotifyDebug() << "play notification - " << str; - foreach (QString item, notification->getMessageSequence()) { + qNotifyDebug() << "play notification - " << notification->toString(); + foreach (QString item, notification->toSoundList()) { Phonon::MediaSource *ms = new Phonon::MediaSource(item); ms->setAutoDelete(true); phonon.mo->enqueue(*ms); @@ -393,15 +391,15 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification) void SoundNotifyPlugin::repeatTimerHandler() { - NotificationItem* notification = static_cast(sender()->parent()); + NotificationItem* notification = static_cast(sender()->parent()); - qNotifyDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage(); + qNotifyDebug() << "repeatTimerHandler - " << notification->toString(); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - UAVObject* object = objManager->getObject(notification->getDataObject()); - if (object) - checkNotificationRule(notification,object); + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objManager = pm->getObject(); + UAVObject* object = objManager->getObject(notification->getDataObject()); + if (object) + checkNotificationRule(notification,object); } void SoundNotifyPlugin::expireTimerHandler() @@ -411,7 +409,7 @@ void SoundNotifyPlugin::expireTimerHandler() notification->stopExpireTimer(); if (!pendingNotifications.isEmpty()) { - qNotifyDebug() << "expireTimerHandler - " << notification->parseNotifyMessage(); + qNotifyDebug() << "expireTimerHandler - " << notification->toString(); pendingNotifications.removeOne(notification); } } @@ -438,7 +436,7 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst if (!pendingNotifications.isEmpty()) { NotificationItem* notification = pendingNotifications.takeFirst(); - qNotifyDebug() << "play audioFree - " << notification->parseNotifyMessage(); + qNotifyDebug() << "play audioFree - " << notification->toString(); playNotification(notification); } } else { diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h index 1d9475469..0b7a31f3b 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h @@ -50,65 +50,65 @@ typedef struct { class SoundNotifyPlugin : public Core::IConfigurablePlugin -{ - Q_OBJECT -public: - SoundNotifyPlugin(); - ~SoundNotifyPlugin(); +{ + Q_OBJECT +public: + SoundNotifyPlugin(); + ~SoundNotifyPlugin(); - void extensionsInitialized(); - bool initialize(const QStringList & arguments, QString * errorString); - void readConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo); - void saveConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo); - void shutdown(); + void extensionsInitialized(); + bool initialize(const QStringList & arguments, QString * errorString); + void readConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo); + void saveConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo); + void shutdown(); - QList getListNotifications() { return lstNotifications; } - NotificationItem* getCurrentNotification(){ return ¤tNotification;} + QList getListNotifications() { return lstNotifications; } + NotificationItem* getCurrentNotification(){ return ¤tNotification;} - bool getEnableSound() const { return enableSound; } - void setEnableSound(bool value) {enableSound = value; } + bool getEnableSound() const { return enableSound; } + void setEnableSound(bool value) {enableSound = value; } private: - SoundNotifyPlugin(const SoundNotifyPlugin& rhs); - SoundNotifyPlugin& operator= (const SoundNotifyPlugin& rhs); + Q_DISABLE_COPY(SoundNotifyPlugin) - bool playNotification(NotificationItem* notification); - void checkNotificationRule(NotificationItem* notification, UAVObject* object); - void readConfig_0_0_0(); + bool playNotification(NotificationItem* notification); + void checkNotificationRule(NotificationItem* notification, UAVObject* object); + void readConfig_0_0_0(); private slots: - void onTelemetryManagerAdded(QObject* obj); - void onAutopilotDisconnect(); - void connectNotifications(); - void updateNotificationList(QList list); - void resetNotification(void); - void appendNotification(UAVObject *object); - void repeatTimerHandler(void); - void expireTimerHandler(void); - void stateChanged(Phonon::State newstate, Phonon::State oldstate); + + void onTelemetryManagerAdded(QObject* obj); + void onAutopilotDisconnect(); + void connectNotifications(); + void updateNotificationList(QList list); + void resetNotification(void); + void appendNotification(UAVObject *object); + void repeatTimerHandler(void); + void expireTimerHandler(void); + void stateChanged(Phonon::State newstate, Phonon::State oldstate); private: - bool configured; // just for migration,delete later - bool enableSound; - QList< QList* > lstMediaSource; - QStringList mediaSource; - QMultiMap mapMediaObjects; - QSettings* settings; + bool configured; // just for migration,delete later + bool enableSound; + QList< QList* > lstMediaSource; + QStringList mediaSource; + QMultiMap mapMediaObjects; + QSettings* settings; - QList lstNotifiedUAVObjects; - QList lstNotifications; - QList pendingNotifications; - QList removedNotifies; + QList lstNotifiedUAVObjects; + QList lstNotifications; + QList pendingNotifications; + QList removedNotifies; - NotificationItem currentNotification; - NotificationItem* nowPlayingConfiguration; + NotificationItem currentNotification; + NotificationItem* nowPlayingConfiguration; - QString m_field; - PhononObject phonon; - NotifyPluginOptionsPage *mop; - TelemetryManager* telMngr; + QString m_field; + PhononObject phonon; + NotifyPluginOptionsPage *mop; + TelemetryManager* telMngr; }; #endif // SOUNDNOTIFYPLUGIN_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index 305e5e13e..fdf0f5cc9 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -47,72 +47,61 @@ #include "notifytablemodel.h" #include "notifylogging.h" - -static const char* cStrBefore1st = "Before first"; -static const char* cStrBefore2nd = "Before second"; -static const char* cStrAfter2nd = "After second"; - static const char* cStrEqualTo = "Equal to"; static const char* cStrLargeThan = "Large than"; static const char* cStrLowerThan = "Lower than"; static const char* cStrInRange = "In range"; -//----------------------------------------------------------------------------- -NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) +NotifyPluginOptionsPage::NotifyPluginOptionsPage(QObject *parent) : IOptionsPage(parent) - , objManager(*ExtensionSystem::PluginManager::instance()->getObject()) - , owner(qobject_cast(parent)) - , currentCollectionPath("") + , _objManager(*ExtensionSystem::PluginManager::instance()->getObject()) + , _owner(qobject_cast(parent)) + , _currentCollectionPath("") , _valueRange(NULL) , _sayOrder(NULL) , _fieldValue(NULL) , _fieldType(-1) , _form(NULL) -{ -} + , _selectedNotification(NULL) +{} -//----------------------------------------------------------------------------- NotifyPluginOptionsPage::~NotifyPluginOptionsPage() -{ -} +{} -//creates options page widget (uses the UI file) - -//----------------------------------------------------------------------------- QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) { - options_page.reset(new Ui::NotifyPluginOptionsPage()); + _optionsPage.reset(new Ui::NotifyPluginOptionsPage()); //main widget QWidget* optionsPageWidget = new QWidget; - //if(!_fieldValue.isNull()) _fieldValue = NULL; _valueRange = NULL; - _fieldType = -1; + resetFieldType(); //save ref to form, needed for binding dynamic fields in future _form = optionsPageWidget; //main layout - options_page->setupUi(optionsPageWidget); + _optionsPage->setupUi(optionsPageWidget); - listSoundFiles.clear(); - - options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); - options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); - - connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); - connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); + _listSoundFiles.clear(); + _optionsPage->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); + _optionsPage->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); + connect(_optionsPage->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), + this, SLOT(on_buttonSoundFolder_clicked(const QString&))); + connect(_optionsPage->SoundCollectionList, SIGNAL(currentIndexChanged (int)), + this, SLOT(on_soundLanguage_indexChanged(int))); connect(this, SIGNAL(updateNotifications(QList)), - owner, SLOT(updateNotificationList(QList))); + _owner, SLOT(updateNotificationList(QList))); //connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); - privListNotifications = owner->getListNotifications(); + _privListNotifications = _owner->getListNotifications(); + // [1] + _selectedNotification = _owner->getCurrentNotification(); addDynamicValueLayout(); - _selectedNotification = owner->getCurrentNotification(); // [2] updateConfigView(_selectedNotification); @@ -120,117 +109,119 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) initButtons(); initPhononPlayer(); -// _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(0, 0, QModelIndex()), -// QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(0, 0, QModelIndex()), + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); return optionsPageWidget; } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::apply() { - getOptionsPageValues(owner->getCurrentNotification()); - owner->setEnableSound(options_page->chkEnableSound->isChecked()); - emit updateNotifications(privListNotifications); + getOptionsPageValues(_owner->getCurrentNotification()); + _owner->setEnableSound(_optionsPage->chkEnableSound->isChecked()); + emit updateNotifications(_privListNotifications); } void NotifyPluginOptionsPage::finish() { + disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_UAVField_indexChanged(QString))); - disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); - - disconnect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - if (notifySound) { - notifySound->stop(); - notifySound->clear(); + disconnect(_notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(on_changeButtonText(Phonon::State,Phonon::State))); + if (_notifySound) { + _notifySound->stop(); + _notifySound->clear(); } } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::addDynamicValueLayout() { - NotificationItem* curr = owner->getCurrentNotification(); + NotificationItem* curr = _owner->getCurrentNotification(); Q_ASSERT(curr); - options_page->dynamicValueLayout->addWidget(new QLabel("Say order ", _form)); + _optionsPage->dynamicValueLayout->addWidget(new QLabel("Say order ", _form)); _sayOrder = new QComboBox(_form); - options_page->dynamicValueLayout->addWidget(_sayOrder); - QStringList sayOrderValues; - sayOrderValues << cStrBefore1st << cStrBefore2nd << cStrAfter2nd; - _sayOrder->addItems(sayOrderValues); + _optionsPage->dynamicValueLayout->addWidget(_sayOrder); + _sayOrder->addItems(NotificationItem::sayOrderValues); - options_page->dynamicValueLayout->addWidget(new QLabel("Value is ", _form)); + _optionsPage->dynamicValueLayout->addWidget(new QLabel("Value is ", _form)); - UAVDataObject* obj = dynamic_cast(objManager.getObject(curr->getDataObject())); + UAVDataObject* obj = dynamic_cast(_objManager.getObject(curr->getDataObject())); UAVObjectField* field = obj->getField(curr->getObjectField()); Q_ASSERT(obj); Q_ASSERT(field); _valueRange = new QComboBox(_form); - options_page->dynamicValueLayout->addWidget(_valueRange); + _optionsPage->dynamicValueLayout->addWidget(_valueRange); addDynamicField(field); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::resetValueRange() { - _fieldValue = new QLineEdit(_form); (static_cast(_fieldValue))->setInputMask("999.99 - 999.99;"); (static_cast(_fieldValue))->setText("0000000000"); (static_cast(_fieldValue))->setCursorPosition(0); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_rangeValue_indexChanged(QString rangeStr) { Q_ASSERT(_fieldValue); - if(rangeStr == cStrInRange) { - Q_ASSERT(_fieldValue); - options_page->dynamicValueLayout->removeWidget(_fieldValue); - resetValueRange(); - options_page->dynamicValueLayout->addWidget(_fieldValue); - - // _fieldType = -1; - // addDynamicField(field); - } + UAVObjectField* field = getObjectFieldFromPage(); + Q_ASSERT(!!field); + setDynamicValueWidget(field); + setDynamicValueField(_selectedNotification); +} + +void NotifyPluginOptionsPage::resetFieldType() +{ + _fieldType = -1; } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField) { - //qDebugNotify_if(!objField || !parent) << "null input params"; + //qDebugNotify_ if (!objField || !parent) << "null input params"; Q_ASSERT(objField); - if(objField->getType() == _fieldType) { - if(QComboBox* fieldValue = dynamic_cast(_fieldValue)) { + if (objField->getType() == _fieldType) { + if (QComboBox* fieldValue = dynamic_cast(_fieldValue)) { fieldValue->clear(); QStringList enumValues(objField->getOptions()); fieldValue->addItems(enumValues); } return; } - // check if dynamic fileld already settled, - // so if its exists remove it and install new field - if(_fieldValue) - options_page->dynamicValueLayout->removeWidget(_fieldValue); disconnect(_valueRange, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_rangeValue_indexChanged(QString))); _valueRange->clear(); QStringList rangeValues; - if(UAVObjectField::ENUM == objField->getType()) { + if (UAVObjectField::ENUM == objField->getType()) { rangeValues << cStrEqualTo << cStrInRange; _valueRange->addItems(rangeValues); - } - else { + _valueRange->setCurrentIndex(rangeValues.indexOf(_selectedNotification->range())); + + } else { rangeValues << cStrEqualTo << cStrLargeThan << cStrLowerThan << cStrInRange; _valueRange->addItems(rangeValues); connect(_valueRange, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_rangeValue_indexChanged(QString))); } + setDynamicValueWidget(objField); +} +void NotifyPluginOptionsPage::setDynamicValueWidget(UAVObjectField* objField) +{ + Q_ASSERT(_valueRange); + + // check if dynamic fileld already settled, + // so if its exists remove it and install new field + if (_fieldValue) { + _optionsPage->dynamicValueLayout->removeWidget(_fieldValue); + delete _fieldValue; + _fieldValue = NULL; + } _fieldType = objField->getType(); switch(_fieldType) { @@ -243,92 +234,90 @@ void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField) break; default: - if(_valueRange->currentText() == cStrInRange) { + if (_valueRange->currentText() == cStrInRange) { + _fieldValue = new QLineEdit(_form); resetValueRange(); } else { _fieldValue = new QSpinBox(_form); } break; }; - options_page->dynamicValueLayout->addWidget(_fieldValue); + _optionsPage->dynamicValueLayout->addWidget(_fieldValue); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::initButtons() { - options_page->chkEnableSound->setChecked(owner->getEnableSound()); - connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); + _optionsPage->chkEnableSound->setChecked(_owner->getEnableSound()); + connect(_optionsPage->chkEnableSound, SIGNAL(toggled(bool)), + this, SLOT(on_checkEnableSound_toggled(bool))); - options_page->buttonModify->setEnabled(false); - options_page->buttonDelete->setEnabled(false); - options_page->buttonPlayNotification->setEnabled(false); - connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); - connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); - connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); - connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); + _optionsPage->buttonModify->setEnabled(false); + _optionsPage->buttonDelete->setEnabled(false); + _optionsPage->buttonPlayNotification->setEnabled(false); + connect(_optionsPage->buttonAdd, SIGNAL(pressed()), + this, SLOT(on_button_AddNotification_clicked())); + connect(_optionsPage->buttonDelete, SIGNAL(pressed()), + this, SLOT(on_button_DeleteNotification_clicked())); + connect(_optionsPage->buttonModify, SIGNAL(pressed()), + this, SLOT(on_button_ModifyNotification_clicked())); + connect(_optionsPage->buttonPlayNotification, SIGNAL(clicked()), + this, SLOT(on_button_TestSoundNotification_clicked())); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::initPhononPlayer() { - notifySound.reset(Phonon::createPlayer(Phonon::NotificationCategory)); - connect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - connect(notifySound.data(), SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); + _notifySound.reset(Phonon::createPlayer(Phonon::NotificationCategory)); + connect(_notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(on_changeButtonText(Phonon::State,Phonon::State))); + connect(_notifySound.data(), SIGNAL(finished(void)), this, SLOT(on_FinishedPlaying(void))); } - -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::initRulesTable() { qNotifyDebug_if(_notifyRulesModel.isNull()) << "_notifyRulesModel.isNull())"; qNotifyDebug_if(!_notifyRulesSelection) << "_notifyRulesSelection.isNull())"; - //QItemSelectionModel* selection = _notifyRulesSelection.take(); - _notifyRulesModel.reset(new NotifyTableModel(privListNotifications)); + _notifyRulesModel.reset(new NotifyTableModel(_privListNotifications)); _notifyRulesSelection = new QItemSelectionModel(_notifyRulesModel.data()); connect(_notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), - this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); + this, SLOT(on_table_changeSelection( const QItemSelection & , const QItemSelection & ))); connect(this, SIGNAL(entryUpdated(int)), - _notifyRulesModel.data(), SLOT(entryUpdated(int))); -// connect(this, SIGNAL(entryAdded(int)), -// _notifyRulesModel.data(), SLOT(entryAdded(int))); + _notifyRulesModel.data(), SLOT(entryUpdated(int))); - options_page->notifyRulesView->setModel(_notifyRulesModel.data()); - options_page->notifyRulesView->setSelectionModel(_notifyRulesSelection); - options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(this)); + _optionsPage->notifyRulesView->setModel(_notifyRulesModel.data()); + _optionsPage->notifyRulesView->setSelectionModel(_notifyRulesSelection); + _optionsPage->notifyRulesView->setItemDelegate(new NotifyItemDelegate(this)); - options_page->notifyRulesView->resizeRowsToContents(); - options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); - options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); - options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); - options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); - options_page->notifyRulesView->setDragEnabled(true); - options_page->notifyRulesView->setAcceptDrops(true); - options_page->notifyRulesView->setDropIndicatorShown(true); - options_page->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove); + _optionsPage->notifyRulesView->resizeRowsToContents(); + _optionsPage->notifyRulesView->setColumnWidth(eMessageName,200); + _optionsPage->notifyRulesView->setColumnWidth(eRepeatValue,120); + _optionsPage->notifyRulesView->setColumnWidth(eExpireTimer,100); + _optionsPage->notifyRulesView->setColumnWidth(eTurnOn,60); + _optionsPage->notifyRulesView->setDragEnabled(true); + _optionsPage->notifyRulesView->setAcceptDrops(true); + _optionsPage->notifyRulesView->setDropIndicatorShown(true); + _optionsPage->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) { Q_ASSERT(notification); - notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); - notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); - notification->setDataObject(options_page->UAVObject->currentText()); - notification->setObjectField(options_page->UAVObjectField->currentText()); - notification->setSound1(options_page->Sound1->currentText()); - notification->setSound2(options_page->Sound2->currentText()); - notification->setSound3(options_page->Sound3->currentText()); + notification->setSoundCollectionPath(_optionsPage->SoundDirectoryPathChooser->path()); + notification->setCurrentLanguage(_optionsPage->SoundCollectionList->currentText()); + notification->setDataObject(_optionsPage->UAVObject->currentText()); + notification->setObjectField(_optionsPage->UAVObjectField->currentText()); + notification->setSound1(_optionsPage->Sound1->currentText()); + notification->setSound2(_optionsPage->Sound2->currentText()); + notification->setSound3(_optionsPage->Sound3->currentText()); notification->setSayOrder(_sayOrder->currentText()); notification->setRange(_valueRange->currentText()); - if(QSpinBox* spinValue = dynamic_cast(_fieldValue)) + if (QSpinBox* spinValue = dynamic_cast(_fieldValue)) notification->setSingleValue(spinValue->value()); else { - if(QComboBox* comboBoxValue = dynamic_cast(_fieldValue)) + if (QComboBox* comboBoxValue = dynamic_cast(_fieldValue)) notification->setSingleValue(comboBoxValue->currentIndex()); else { - if(QLineEdit* rangeValue = dynamic_cast(_fieldValue)) { + if (QLineEdit* rangeValue = dynamic_cast(_fieldValue)) { QString str = rangeValue->text(); QStringList range = str.split('-'); notification->setSingleValue(range.at(0).toDouble()); @@ -338,190 +327,175 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio } } - -//----------------------------------------------------------------------------- -void NotifyPluginOptionsPage::onUAVField_indexChanged(QString field) { - _fieldType = -1; - UAVDataObject* obj = dynamic_cast( objManager.getObject(options_page->UAVObject->currentText())); +void NotifyPluginOptionsPage::on_UAVField_indexChanged(QString field) +{ + resetFieldType(); + UAVDataObject* obj = dynamic_cast( _objManager.getObject(_optionsPage->UAVObject->currentText())); addDynamicField(obj->getField(field)); } -////////////////////////////////////////////////////////////////////////////// -// Fills in the combo box when value is changed in the -// combo box -////////////////////////////////////////////////////////////////////////////// -void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) { - _fieldType = -1; - UAVDataObject* obj = dynamic_cast( objManager.getObject(val) ); +void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) +{ + resetFieldType(); + UAVDataObject* obj = dynamic_cast( _objManager.getObject(val) ); QList fieldList = obj->getFields(); - disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); - options_page->UAVObjectField->clear(); + disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVField_indexChanged(QString))); + _optionsPage->UAVObjectField->clear(); foreach (UAVObjectField* field, fieldList) { - options_page->UAVObjectField->addItem(field->getName()); + _optionsPage->UAVObjectField->addItem(field->getName()); } - connect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); + connect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVField_indexChanged(QString))); addDynamicField(fieldList.at(0)); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path) { QDir dirPath(path); - listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); - options_page->SoundCollectionList->clear(); - options_page->SoundCollectionList->addItems(listDirCollections); + _listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + _optionsPage->SoundCollectionList->clear(); + _optionsPage->SoundCollectionList->addItems(_listDirCollections); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) { - options_page->SoundCollectionList->setCurrentIndex(index); + _optionsPage->SoundCollectionList->setCurrentIndex(index); + _currentCollectionPath = _optionsPage->SoundDirectoryPathChooser->path() + + QDir::toNativeSeparators("/" + _optionsPage->SoundCollectionList->currentText()); - currentCollectionPath = options_page->SoundDirectoryPathChooser->path() - + QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText()); - - QDir dirPath(currentCollectionPath); + QDir dirPath(_currentCollectionPath); QStringList filters; filters << "*.mp3" << "*.wav"; dirPath.setNameFilters(filters); - listSoundFiles = dirPath.entryList(filters); - listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), ""); - options_page->Sound1->clear(); - options_page->Sound2->clear(); - options_page->Sound3->clear(); - options_page->Sound1->addItems(listSoundFiles); - options_page->Sound2->addItem(""); - options_page->Sound2->addItems(listSoundFiles); - options_page->Sound3->addItem(""); - options_page->Sound3->addItems(listSoundFiles); - + _listSoundFiles = dirPath.entryList(filters); + _listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), ""); + _optionsPage->Sound1->clear(); + _optionsPage->Sound2->clear(); + _optionsPage->Sound3->clear(); + _optionsPage->Sound1->addItems(_listSoundFiles); + _optionsPage->Sound2->addItem(""); + _optionsPage->Sound2->addItems(_listSoundFiles); + _optionsPage->Sound3->addItem(""); + _optionsPage->Sound3->addItems(_listSoundFiles); } -//----------------------------------------------------------------------------- -void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate) +void NotifyPluginOptionsPage::on_changeButtonText(Phonon::State newstate, Phonon::State oldstate) { //Q_ASSERT(Phonon::ErrorState != newstate); if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { - options_page->buttonPlayNotification->setText("Play"); - options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); + _optionsPage->buttonPlayNotification->setText("Play"); + _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); } else { if (newstate == Phonon::PlayingState) { - options_page->buttonPlayNotification->setText("Stop"); - options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); + _optionsPage->buttonPlayNotification->setText("Stop"); + _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); } } } -//----------------------------------------------------------------------------- -void NotifyPluginOptionsPage::onFinishedPlaying() +void NotifyPluginOptionsPage::on_FinishedPlaying() { - notifySound->clear(); + _notifySound->clear(); } -//----------------------------------------------------------------------------- -void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() +void NotifyPluginOptionsPage::on_button_TestSoundNotification_clicked() { NotificationItem* notification = NULL; - - if (-1 == _notifyRulesSelection->currentIndex().row()) - return; - notifySound->clearQueue(); - notification = privListNotifications.at(_notifyRulesSelection->currentIndex().row()); - notification->parseNotifyMessage(); - QStringList sequence = notification->getMessageSequence(); - Q_ASSERT(!!sequence.size()); qNotifyDebug() << "on_buttonTestSoundNotification_clicked"; + Q_ASSERT(-1 != _notifyRulesSelection->currentIndex().row()); + _notifySound->clearQueue(); + notification = _privListNotifications.at(_notifyRulesSelection->currentIndex().row()); + QStringList sequence = notification->toSoundList(); + if (sequence.isEmpty()) { + qNotifyDebug() << "message sequense is empty!"; + return; + } foreach(QString item, sequence) { qNotifyDebug() << item; - notifySound->enqueue(Phonon::MediaSource(item)); + _notifySound->enqueue(Phonon::MediaSource(item)); } - notifySound->play(); + _notifySound->play(); } -void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state) +void NotifyPluginOptionsPage::on_checkEnableSound_toggled(bool state) { bool state1 = 1^state; - QList listOutputs = notifySound->outputPaths(); + QList listOutputs = _notifySound->outputPaths(); Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink(); audioOutput->setMuted(state1); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) { Q_ASSERT(notification); - disconnect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), + disconnect(_optionsPage->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); - disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), - this, SLOT(onUAVField_indexChanged(QString))); + disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_UAVField_indexChanged(QString))); QString path = notification->getSoundCollectionPath(); - if (path == "") { - //QDir dir = QDir::currentPath(); - //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; + if (path.isEmpty()) { path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds"); } - options_page->SoundDirectoryPathChooser->setPath(path); + _optionsPage->SoundDirectoryPathChooser->setPath(path); - if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){ - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); + if (-1 != _optionsPage->SoundCollectionList->findText(notification->getCurrentLanguage())) { + _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText(notification->getCurrentLanguage())); } else { - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); + _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default")); } - // Fills the combo boxes for the UAVObjects - QList< QList > objList = objManager.getDataObjects(); + QList< QList > objList = _objManager.getDataObjects(); foreach (QList list, objList) { foreach (UAVDataObject* obj, list) { - options_page->UAVObject->addItem(obj->getName()); + _optionsPage->UAVObject->addItem(obj->getName()); } } - if (options_page->UAVObject->findText(notification->getDataObject())!=-1){ - options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); + if (-1 != _optionsPage->UAVObject->findText(notification->getDataObject())) { + _optionsPage->UAVObject->setCurrentIndex(_optionsPage->UAVObject->findText(notification->getDataObject())); } - options_page->UAVObjectField->clear(); + _optionsPage->UAVObjectField->clear(); QString uavDataObject = notification->getDataObject(); - UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); + UAVDataObject* obj = dynamic_cast(_objManager.getObject(uavDataObject)); if (obj != NULL ) { QList fieldList = obj->getFields(); foreach (UAVObjectField* field, fieldList) { - options_page->UAVObjectField->addItem(field->getName()); + _optionsPage->UAVObjectField->addItem(field->getName()); } } - if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) { - options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); + if (-1 != _optionsPage->UAVObjectField->findText(notification->getObjectField())) { + _optionsPage->UAVObjectField->setCurrentIndex(_optionsPage->UAVObjectField->findText(notification->getObjectField())); } - if (-1 != options_page->Sound1->findText(notification->getSound1())) { - options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + if (-1 != _optionsPage->Sound1->findText(notification->getSound1())) { + _optionsPage->Sound1->setCurrentIndex(_optionsPage->Sound1->findText(notification->getSound1())); } else { // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); + _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default")); + _optionsPage->Sound1->setCurrentIndex(_optionsPage->Sound1->findText(notification->getSound1())); } - if (-1 != options_page->Sound2->findText(notification->getSound2())) { - options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + if (-1 != _optionsPage->Sound2->findText(notification->getSound2())) { + _optionsPage->Sound2->setCurrentIndex(_optionsPage->Sound2->findText(notification->getSound2())); } else { // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); + _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default")); + _optionsPage->Sound2->setCurrentIndex(_optionsPage->Sound2->findText(notification->getSound2())); } - if (-1 != options_page->Sound3->findText(notification->getSound3())) { - options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + if (-1 != _optionsPage->Sound3->findText(notification->getSound3())) { + _optionsPage->Sound3->setCurrentIndex(_optionsPage->Sound3->findText(notification->getSound3())); } else { // show item from default location - options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); - options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); + _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default")); + _optionsPage->Sound3->setCurrentIndex(_optionsPage->Sound3->findText(notification->getSound3())); } if (-1 != _valueRange->findText(notification->range())) { @@ -534,120 +508,123 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) setDynamicValueField(notification); - connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), + connect(_optionsPage->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); - connect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), - this, SLOT(onUAVField_indexChanged(QString))); + connect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_UAVField_indexChanged(QString))); } -//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::setDynamicValueField(NotificationItem* notification) { - if(QSpinBox* spinValue = dynamic_cast(_fieldValue)) + if (QSpinBox* spinValue = dynamic_cast(_fieldValue)) spinValue->setValue(notification->singleValue()); else { - if(QComboBox* comboBoxValue = dynamic_cast(_fieldValue)) + if (QComboBox* comboBoxValue = dynamic_cast(_fieldValue)) comboBoxValue->setCurrentIndex(notification->singleValue()); else { - if(QLineEdit* rangeValue = dynamic_cast(_fieldValue)) { - resetValueRange(); - rangeValue->setText(QString("%1%2").arg(notification->singleValue()) - .arg(notification->valueRange2())); + if (QLineEdit* rangeValue = dynamic_cast(_fieldValue)) { + //resetValueRange(); + QString str = QString("%1%2").arg(notification->singleValue(), 5, 'f', 2, '0') + .arg(notification->valueRange2(), 5, 'f', 2, '0'); + rangeValue->setText(str); } else { qNotifyDebug() << "NotifyPluginOptionsPage::setDynamicValueField | unknown _fieldValue: " << _fieldValue; } - } } } -//----------------------------------------------------------------------------- -void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ) +UAVObjectField* NotifyPluginOptionsPage::getObjectFieldFromPage() { - bool select = false; - notifySound->stop(); - if (selected.indexes().size()) { - select = true; - _selectedNotification = privListNotifications.at(selected.indexes().at(0).row()); - updateConfigView(_selectedNotification); - UAVDataObject* obj = dynamic_cast( objManager.getObject(options_page->UAVObject->currentText())); - UAVObjectField* field = obj->getField(options_page->UAVObjectField->currentText()); - addDynamicField(field); - setDynamicValueField(_selectedNotification); - } - - options_page->buttonModify->setEnabled(select); - options_page->buttonDelete->setEnabled(select); - options_page->buttonPlayNotification->setEnabled(select); + UAVDataObject* obj = dynamic_cast( _objManager.getObject(_optionsPage->UAVObject->currentText())); + return obj->getField(_optionsPage->UAVObjectField->currentText()); } -//----------------------------------------------------------------------------- -void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() + +UAVObjectField* NotifyPluginOptionsPage::getObjectFieldFromSelected() +{ + UAVDataObject* obj = dynamic_cast(_objManager.getObject(_selectedNotification->getDataObject())); + return obj->getField(_selectedNotification->getObjectField()); +} + +void NotifyPluginOptionsPage::on_table_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ) +{ + bool select = false; + _notifySound->stop(); + if (selected.indexes().size()) { + select = true; + _selectedNotification = _privListNotifications.at(selected.indexes().at(0).row()); + UAVObjectField* field = getObjectFieldFromSelected(); + addDynamicField(field); + updateConfigView(_selectedNotification); + } + + _optionsPage->buttonModify->setEnabled(select); + _optionsPage->buttonDelete->setEnabled(select); + _optionsPage->buttonPlayNotification->setEnabled(select); +} + +void NotifyPluginOptionsPage::on_button_AddNotification_clicked() { NotificationItem* notification = new NotificationItem; - if (options_page->SoundDirectoryPathChooser->path()=="") { - QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); - textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); - options_page->SoundDirectoryPathChooser->setPalette(textPalette); - options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder"); - return; + if (_optionsPage->SoundDirectoryPathChooser->path().isEmpty()) { + QPalette textPalette=_optionsPage->SoundDirectoryPathChooser->palette(); + textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); + _optionsPage->SoundDirectoryPathChooser->setPalette(textPalette); + _optionsPage->SoundDirectoryPathChooser->setPath("please select sound collection folder"); + return; } - notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); - notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); - notification->setDataObject(options_page->UAVObject->currentText()); - notification->setObjectField(options_page->UAVObjectField->currentText()); + notification->setSoundCollectionPath(_optionsPage->SoundDirectoryPathChooser->path()); + notification->setCurrentLanguage(_optionsPage->SoundCollectionList->currentText()); + notification->setDataObject(_optionsPage->UAVObject->currentText()); + notification->setObjectField(_optionsPage->UAVObjectField->currentText()); notification->setRange(_valueRange->currentText()); - if(QSpinBox* spinValue = dynamic_cast(_fieldValue)) + if (QSpinBox* spinValue = dynamic_cast(_fieldValue)) notification->setSingleValue(spinValue->value()); - if (options_page->Sound1->currentText().size() > 0) - notification->setSound1(options_page->Sound1->currentText()); + if (_optionsPage->Sound1->currentText().size() > 0) + notification->setSound1(_optionsPage->Sound1->currentText()); - notification->setSound2(options_page->Sound2->currentText()); - notification->setSound3(options_page->Sound3->currentText()); + notification->setSound2(_optionsPage->Sound2->currentText()); + notification->setSound3(_optionsPage->Sound3->currentText()); - if ( ((!options_page->Sound2->currentText().size()) && (_sayOrder->currentText()=="After second")) - || ((!options_page->Sound3->currentText().size()) && (_sayOrder->currentText()=="After third")) ) { + if ( ((!_optionsPage->Sound2->currentText().size()) && (_sayOrder->currentText()=="After second")) + || ((!_optionsPage->Sound3->currentText().size()) && (_sayOrder->currentText()=="After third")) ) { return; } else { notification->setSayOrder(_sayOrder->currentText()); } _notifyRulesModel->entryAdded(notification); - _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()), + _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(_privListNotifications.size()-1,0,QModelIndex()), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } -//----------------------------------------------------------------------------- -void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() +void NotifyPluginOptionsPage::on_button_DeleteNotification_clicked() { _notifyRulesModel->removeRow(_notifyRulesSelection->currentIndex().row()); if (!_notifyRulesModel->rowCount() && (_notifyRulesSelection->currentIndex().row() > 0 && _notifyRulesSelection->currentIndex().row() < _notifyRulesModel->rowCount()) ) { - options_page->buttonDelete->setEnabled(false); - options_page->buttonModify->setEnabled(false); - options_page->buttonPlayNotification->setEnabled(false); + _optionsPage->buttonDelete->setEnabled(false); + _optionsPage->buttonModify->setEnabled(false); + _optionsPage->buttonPlayNotification->setEnabled(false); } - } -//----------------------------------------------------------------------------- -void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked() +void NotifyPluginOptionsPage::on_button_ModifyNotification_clicked() { NotificationItem* notification = new NotificationItem; getOptionsPageValues(notification); - notification->setRetryString(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryString()); - notification->setLifetime(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->lifetime()); - notification->setMute(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->mute()); + notification->setRetryString(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryString()); + notification->setLifetime(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->lifetime()); + notification->setMute(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->mute()); - privListNotifications.replace(_notifyRulesSelection->currentIndex().row(),notification); + _privListNotifications.replace(_notifyRulesSelection->currentIndex().row(),notification); entryUpdated(_notifyRulesSelection->currentIndex().row()); - } - diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h index f4a29ae41..3f36f3f4d 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h @@ -57,78 +57,130 @@ using namespace Core; class NotifyPluginOptionsPage : public IOptionsPage { - Q_OBJECT + Q_OBJECT + public: - explicit NotifyPluginOptionsPage(/*NotificationItem *config, */QObject *parent = 0); - ~NotifyPluginOptionsPage(); - QString id() const { return QLatin1String("settings"); } - QString trName() const { return tr("settings"); } - QString category() const { return QLatin1String("Notify Plugin");} - QString trCategory() const { return tr("Notify Plugin");} + + explicit NotifyPluginOptionsPage(QObject *parent = 0); + ~NotifyPluginOptionsPage(); + QString id() const { return QLatin1String("settings"); } + QString trName() const { return tr("settings"); } + QString category() const { return QLatin1String("Notify Plugin");} + QString trCategory() const { return tr("Notify Plugin");} QWidget *createPage(QWidget *parent); void apply(); - void finish(); - void restoreFromSettings(); + void finish(); + void restoreFromSettings(); - void updateConfigView(NotificationItem* notification); - void getOptionsPageValues(NotificationItem* notification); + void updateConfigView(NotificationItem* notification); + void getOptionsPageValues(NotificationItem* notification); + UAVObjectField* getObjectFieldFromPage(); + UAVObjectField* getObjectFieldFromSelected(); signals: void updateNotifications(QList list); - //void resetNotification(void); void entryUpdated(int index); +private slots: + void on_button_TestSoundNotification_clicked(); + void on_button_AddNotification_clicked(); + void on_button_DeleteNotification_clicked(); + void on_button_ModifyNotification_clicked(); + + /** + * We can use continuous selection, to select simultaneously + * multiple rows to move them(using drag & drop) inside table ranges. + */ + void on_table_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ); + + void on_soundLanguage_indexChanged(int index); + void on_buttonSoundFolder_clicked(const QString& path); + void on_UAVObject_indexChanged(QString val); + void on_UAVField_indexChanged(QString val); + void on_changeButtonText(Phonon::State newstate, Phonon::State oldstate); + void on_checkEnableSound_toggled(bool state); + + /** + * Important when we change to or from "In range" value + * For enums UI layout stayed the same, but for numeric values + * we need to change UI to show edit line, + * to have possibility assign range limits for value. + */ + void on_rangeValue_indexChanged(QString); + + void on_FinishedPlaying(void); + + private: Q_DISABLE_COPY(NotifyPluginOptionsPage) void resetValueRange(); + void resetFieldType(); + void setDynamicValueField(NotificationItem* notification); void addDynamicField(UAVObjectField* objField); void addDynamicValueLayout(); + void setDynamicValueWidget(UAVObjectField* objField); + void initButtons(); void initPhononPlayer(); void initRulesTable(); -private slots: - void on_buttonTestSoundNotification_clicked(); - - void on_buttonAddNotification_clicked(); - void on_buttonDeleteNotification_clicked(); - void on_buttonModifyNotification_clicked(); - void on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ); - void on_soundLanguage_indexChanged(int index); - void on_buttonSoundFolder_clicked(const QString& path); - void on_UAVObject_indexChanged(QString val); - void onUAVField_indexChanged(QString val); - void changeButtonText(Phonon::State newstate, Phonon::State oldstate); - void on_chkEnableSound_toggled(bool state); - void on_rangeValue_indexChanged(QString); - - void onFinishedPlaying(void); - private: - UAVObjectManager& objManager; - SoundNotifyPlugin* owner; - QStringList listDirCollections; - QStringList listSoundFiles; - QString currentCollectionPath; - Phonon::MediaObject *sound1; - Phonon::MediaObject *sound2; - QScopedPointer notifySound; - Phonon::AudioOutput *audioOutput; - QScopedPointer _notifyRulesModel; - QItemSelectionModel* _notifyRulesSelection; - QList privListNotifications; + UAVObjectManager& _objManager; + SoundNotifyPlugin* _owner; + QStringList _listDirCollections; + QStringList _listSoundFiles; + QString _currentCollectionPath; + Phonon::MediaObject* _sound1; + Phonon::MediaObject* _sound2; + QScopedPointer _notifySound; + Phonon::AudioOutput* _audioOutput; - QScopedPointer options_page; + QScopedPointer _notifyRulesModel; + QItemSelectionModel* _notifyRulesSelection; + /** + * Local copy of notification list, which owned by notify plugin. + * Notification list readed once on application loaded, during + * notify plugin startup, then on open options page. + * This copy is simple assignment, but due to implicitly sharing + * we don't have additional cost for that, copy will created + * only after modification of private notify list. + */ + QList _privListNotifications; + + QScopedPointer _optionsPage; + + //! widget to convinient selection of condition for field value (equal, lower, greater) QComboBox* _valueRange; + + //! widget to convinient selection of order in which sounds will be played QComboBox* _sayOrder; + + //! widget to represent edit widget for UAVObjectfield, + //! can be spinbox - for numerics, combobox - enums, or + //! lineedit - for range limits QWidget* _fieldValue; + + //! type of UAVObjectField - numeric or ENUM + //! this variable needs to correctly set dynamic UI elemen _fieldValue + //! NOTE: ocassionaly it should be invalidated (= -1) to reset _fieldValue int _fieldType; + + //! actualy reference to optionsPageWidget, + //! we MUST hold it beyond the scope of createPage func + //! to have possibility change dynamic parts of options page layout in future QWidget* _form; + + //! needs to correctly update UI during transitions from "In Range" to other + //! _valueRange entries and back direction as well + QString _prevRangeValue; + + //! Currently selected notification, all controls filled accroding to it. + //! On options page startup, always points to first row. NotificationItem* _selectedNotification; }; diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui index 23d05c2a0..94560ff1a 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.ui @@ -266,7 +266,7 @@ p, li { white-space: pre-wrap; } - QAbstractItemView::SingleSelection + QAbstractItemView::ContiguousSelection QAbstractItemView::SelectRows diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp index 138af106b..b1fd1c737 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp @@ -30,8 +30,6 @@ #include #include -static int _dragStartRow = -1; -static int _dragNumRows = -1; const char* mime_type_notify_table = "openpilot/notify_plugin_table"; NotifyTableModel::NotifyTableModel(QList& parentList, QObject* parent) @@ -47,19 +45,19 @@ bool NotifyTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::DisplayRole) { - if(eMESSAGE_NAME == index.column()) { + if(eMessageName == index.column()) { emit dataChanged(index, index); return true; } } if (index.isValid() && role == Qt::EditRole) { - if(eREPEAT_VALUE == index.column()) + if(eRepeatValue == index.column()) _list.at(index.row())->setRetryString(value.toString()); else { - if(eEXPIRE_TIME == index.column()) + if(eExpireTimer == index.column()) _list.at(index.row())->setLifetime(value.toInt()); else { - if(eENABLE_NOTIFICATION == index.column()) + if(eTurnOn == index.column()) _list.at(index.row())->setMute(value.toBool()); } } @@ -83,16 +81,16 @@ QVariant NotifyTableModel::data(const QModelIndex &index, int role) const { switch(index.column()) { - case eMESSAGE_NAME: - return _list.at(index.row())->parseNotifyMessage(); + case eMessageName: + return _list.at(index.row())->toString(); - case eREPEAT_VALUE: + case eRepeatValue: return _list.at(index.row())->retryString(); - case eEXPIRE_TIME: + case eExpireTimer: return _list.at(index.row())->lifetime(); - case eENABLE_NOTIFICATION: + case eTurnOn: return _list.at(index.row())->mute(); default: @@ -126,13 +124,13 @@ bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& ind { Q_UNUSED(index); - if((-1 == position) || (-1 == rows) ) + if (-1 == position || -1 == rows) return false; beginInsertRows(QModelIndex(), position, position + rows - 1); - for (int row = 0; row < rows; ++row) { - _list.insert(position, new NotificationItem()); + for (int i = 0; i < rows; ++i) { + _list.insert(position + i, new NotificationItem()); } endInsertRows(); @@ -171,6 +169,17 @@ void NotifyTableModel::entryAdded(NotificationItem* item) entryUpdated(rowCount() - 1); } +Qt::DropActions NotifyTableModel::supportedDropActions() const +{ + return Qt::MoveAction; +} + +QStringList NotifyTableModel::mimeTypes() const +{ + QStringList types; + types << mime_type_notify_table; + return types; +} bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex& parent) @@ -198,48 +207,31 @@ bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction acti QByteArray encodedData = data->data(mime_type_notify_table); QDataStream stream(&encodedData, QIODevice::ReadOnly); int rows = beginRow; + // read next item from input MIME and drop into the table line by line while(!stream.atEnd()) { qint32 ptr; stream >> ptr; NotificationItem* item = reinterpret_cast(ptr); int dragged = _list.indexOf(item); + // we can drag item from top rows to bottom (DOWN_DIRECTION), + // or from bottom rows to top rows (UP_DIRECTION) + enum { UP_DIRECTION, DOWN_DIRECTION }; + int direction = (dragged < rows) ? DOWN_DIRECTION : (dragged += 1, UP_DIRECTION); + Q_ASSERT(insertRows(rows + direction, 1, QModelIndex())); if(-1 == dragged || rows >= _list.size() || dragged == rows) { qNotifyDebug() << "no such item"; + return false; } - removeRows(rows, 1, QModelIndex()); - insertRows(rows, 1, QModelIndex()); - _list.replace(dragged, item); - // _list.swap(dragged, rows); - ++rows; + _list.replace(rows + direction, item); + Q_ASSERT(removeRows(dragged, 1, QModelIndex())); + if(direction == UP_DIRECTION) + ++rows; }; QModelIndex idxTopLeft = index(beginRow, 0, QModelIndex()); QModelIndex idxBotRight = index(beginRow, columnCount(QModelIndex()), QModelIndex()); emit dataChanged(idxTopLeft, idxBotRight); - //QStringList newItems; - - //removeRows(_dragStartRow, _dragNumRows, QModelIndex()); - //insertRows(beginRow, rows, QModelIndex()); -// int rows = beginRow; -// while (!stream.atEnd()) { -// _list.at(index.row())->deserialize(stream); -// ++rows; -// } - -// while(rows) { -// int column = 0; -// foreach (const QString& text, newItems) { -// QModelIndex idx = index(beginRow, column, QModelIndex()); -// if(!column) -// setData(const_cast(idx), text, Qt::DisplayRole); -// else -// setData(const_cast(idx), text, Qt::EditRole); -// ++column; -// } -// ++beginRow; -// --rows; -// } return true; } @@ -251,35 +243,13 @@ QMimeData* NotifyTableModel::mimeData(const QModelIndexList& indexes) const QDataStream stream(&encodedData, QIODevice::WriteOnly); int rows = 0; foreach (const QModelIndex& index, indexes) { - if(!index.column()) { + if (!index.column()) { qint32 item = reinterpret_cast(_list.at(index.row())); stream << item; + ++rows; } - ++rows; } - -// int numRows = 0; -// foreach (const QModelIndex& index, indexes) { -// if (index.isValid() && index.column()) { -// _list.at(index.row())->serialize(stream); -//// if(!index.column()) { -//// numRows++; -//// QString name = data(index, Qt::DisplayRole).toString(); -//// stream << name; -//// } else { -//// QString text = data(index, Qt::EditRole).toString(); -//// stream << text; -//// } -// } -// } - mimeData->setData(mime_type_notify_table, encodedData); - - //emit dragRows(indexes.at(0).row(), rows); - dropRows(indexes.at(0).row(), rows); - //_dragStartRow = indexes.at(0).row(); - //_dragNumRows = 1/*numRows*/; - return mimeData; } diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h index 3168a848f..28eb8cc68 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h @@ -33,72 +33,58 @@ #include #include "notificationitem.h" -enum ColumnNames { eMESSAGE_NAME, eREPEAT_VALUE, eEXPIRE_TIME, eENABLE_NOTIFICATION }; +enum ColumnNames { eMessageName, eRepeatValue, eExpireTimer, eTurnOn }; class NotifyTableModel : public QAbstractTableModel { - Q_OBJECT + Q_OBJECT - enum {eColumnCount = 4 }; + enum {eColumnCount = 4 }; public: - NotifyTableModel(QList& parentList, QObject* parent = 0); - - int rowCount(const QModelIndex& parent = QModelIndex()) const - { - return _list.count(); - } - - int columnCount(const QModelIndex &/*parent*/) const - { - return eColumnCount; - } - - Qt::ItemFlags flags(const QModelIndex &index) const - { - if (!index.isValid()) - return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; - - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; - } - - Qt::DropActions supportedDropActions() const + NotifyTableModel(QList& parentList, QObject* parent = 0); + int rowCount(const QModelIndex& parent = QModelIndex()) const { - return Qt::MoveAction; + return _list.count(); } - QStringList mimeTypes() const - { - QStringList types; - types << "application/vnd.text.list"; - return types; - } + int columnCount(const QModelIndex &/*parent*/) const + { + return eColumnCount; + } - bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, - int column, const QModelIndex& parent); - QMimeData* mimeData(const QModelIndexList &indexes) const; + Qt::ItemFlags flags(const QModelIndex &index) const + { + if (!index.isValid()) + return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; + + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; + } + QStringList mimeTypes() const; + Qt::DropActions supportedDropActions() const; + bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, + int column, const QModelIndex& parent); + QMimeData* mimeData(const QModelIndexList &indexes) const; - bool setData(const QModelIndex &index, const QVariant &value, int role); - QVariant data(const QModelIndex &index, int role) const; - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - bool insertRows(int position, int rows, const QModelIndex &index); - bool removeRows(int position, int rows, const QModelIndex &index); - - void entryAdded(NotificationItem* item); + bool setData(const QModelIndex &index, const QVariant &value, int role); + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + bool insertRows(int position, int rows, const QModelIndex &index); + bool removeRows(int position, int rows, const QModelIndex &index); + void entryAdded(NotificationItem* item); signals: - void dragRows(int position, int count); + void dragRows(int position, int count); private slots: - void entryUpdated(int offset); - void dropRows(int position, int count) const; + void entryUpdated(int offset); + void dropRows(int position, int count) const; private: - mutable QList& _list; - QStringList _headerStrings; + mutable QList& _list; + QStringList _headerStrings; }; - #endif // NOTIFYTABLEMODEL_H From 20757c2efd40484c107d6b5d892c51721a32da80 Mon Sep 17 00:00:00 2001 From: Nickolay Date: Wed, 12 Oct 2011 08:36:05 +0300 Subject: [PATCH 9/9] +complete all features; +testing in progress; --- .../src/plugins/notify/NotificationItem.h | 11 +- .../src/plugins/notify/notificationitem.cpp | 55 +- .../src/plugins/notify/notifylogging.cpp | 2 +- .../src/plugins/notify/notifyplugin.cpp | 440 ++++++------ .../src/plugins/notify/notifyplugin.h | 22 +- .../notify/notifypluginoptionspage.cpp | 627 +++++++++--------- .../plugins/notify/notifypluginoptionspage.h | 99 ++- .../src/plugins/notify/notifytablemodel.cpp | 27 +- 8 files changed, 687 insertions(+), 596 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h index 1898f1a55..d4929a1e5 100644 --- a/ground/openpilotgcs/src/plugins/notify/NotificationItem.h +++ b/ground/openpilotgcs/src/plugins/notify/NotificationItem.h @@ -63,8 +63,8 @@ public: QString getSayOrder() const { return _sayOrder; } void setSayOrder(QString text) { _sayOrder = text; } - double singleValue() const { return _singleValue; } - void setSingleValue(double value) { _singleValue = value; } + QVariant singleValue() const { return _singleValue; } + void setSingleValue(QVariant value) { _singleValue = value; } double valueRange2() const { return _valueRange2; } void setValueRange2(double value) { _valueRange2 = value; } @@ -131,6 +131,7 @@ public: QTimer* getTimer() const { return _timer; } void startTimer(int value); + void restartTimer(); void stopTimer(); void disposeTimer(); @@ -141,7 +142,7 @@ public: void disposeExpireTimer(); bool isNowPlaying; - bool firstStart; + bool _isPlayed; static QStringList sayOrderValues; static QStringList retryValues; @@ -184,8 +185,8 @@ private: //! order in what sounds 1-3 will be played QString _sayOrder; - //! one-side range, value maybe lower or greater - double _singleValue; + //! one-side range, value(numeric or ENUM type) maybe lower, greater or in range + QVariant _singleValue; //! both-side range, value should be inside the range //double _valueRange1; diff --git a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp index 1b0e634a6..ec86aabcd 100644 --- a/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp @@ -59,7 +59,7 @@ QStringList NotificationItem::retryValues; NotificationItem::NotificationItem(QObject *parent) : QObject(parent) , isNowPlaying(0) - , firstStart(true) + , _isPlayed(false) , _timer(NULL) , _expireTimer(NULL) , _soundCollectionPath("") @@ -77,10 +77,12 @@ NotificationItem::NotificationItem(QObject *parent) , _expireTimeout(eDefaultTimeout) , _mute(false) { + NotificationItem::sayOrderValues.clear(); NotificationItem::sayOrderValues.append(cStrBefore1st); NotificationItem::sayOrderValues.append(cStrBefore2nd); NotificationItem::sayOrderValues.append(cStrAfter2nd); + NotificationItem::retryValues.clear(); NotificationItem::retryValues.append(cStrRetryOnce); NotificationItem::retryValues.append(cStrRetryInstantly); NotificationItem::retryValues.append(cStrRetry10sec); @@ -92,7 +94,7 @@ NotificationItem::NotificationItem(QObject *parent) void NotificationItem::copyTo(NotificationItem* that) const { that->isNowPlaying = isNowPlaying; - that->firstStart = firstStart; + that->_isPlayed = _isPlayed; that->_soundCollectionPath = _soundCollectionPath; that->_currentLanguage = _currentLanguage; that->_soundCollectionPath = _soundCollectionPath; @@ -142,7 +144,8 @@ void NotificationItem::restoreState(QSettings* settings) setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString()); setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString()); setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString()); - setSingleValue(settings->value(QLatin1String("Value1"), tr("")).toDouble()); + QVariant value = settings->value(QLatin1String("Value1"), tr("")); + setSingleValue(value); setValueRange2(settings->value(QLatin1String("Value2"), tr("")).toDouble()); setRetryString(settings->value(QLatin1String("Repeat"), tr("")).toString()); setLifetime(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt()); @@ -185,16 +188,26 @@ void NotificationItem::deseriaize(QDataStream& stream) stream >> this->_mute; } -void NotificationItem::startTimer(int value) +void NotificationItem::startTimer(int msec) { if (!_timer) { _timer = new QTimer(this); - _timer->setInterval(value); + _timer->setInterval(msec); } if (!_timer->isActive()) _timer->start(); } + +void NotificationItem::restartTimer() +{ + if (!_timer) { + if (!_timer->isActive()) + _timer->start(); + } +} + + void NotificationItem::stopTimer() { if (_timer) { @@ -311,17 +324,26 @@ QStringList valueToSoundList(QString value) return digitWavs; } +QString stringFromValue(QVariant value, UAVObjectField* field) +{ + Q_ASSERT(field); + Q_ASSERT(!value.isNull()); + QString str; + if (UAVObjectField::ENUM == field->getType()) { + if(!field->getOptions().contains(value.toString())) + return QString(); + str = value.toString(); + } else { + str = QString("%L1").arg(value.toDouble()); + } + return str; +} + QString NotificationItem::toString() { QString str; - QString value; UAVObjectField* field = getUAVObjectField(); - if (UAVObjectField::ENUM == field->getType()) { - Q_ASSERT(singleValue() < field->getOptions().size()); - value = field->getOptions().at(singleValue()); - } else { - value = QString("%L1").arg(singleValue()); - } + QString value = stringFromValue(singleValue(), field); int pos = getValuePosition(getSayOrder().trimmed()); QStringList lst; @@ -353,15 +375,8 @@ QStringList& NotificationItem::toSoundList() // tips: // check of *.wav files exist needed for playing phonon queues; // if phonon player don't find next file in queue, it buzz - - QString value; UAVObjectField* field = getUAVObjectField(); - if (UAVObjectField::ENUM == field->getType()) { - Q_ASSERT(singleValue() < field->getOptions().size()); - value = field->getOptions().at(singleValue()); - } else { - value = QString("%L1").arg(singleValue()); - } + QString value = stringFromValue(singleValue(), field); // generate queue of sound files to play _messageSequence.clear(); diff --git a/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp b/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp index 0a29cc6e6..3cb11d111 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifylogging.cpp @@ -31,7 +31,7 @@ #ifdef DEBUG_NOTIFIES_ENABLE QDebug qNotifyDebug() { - return qDebug(); + return qDebug() << "[NOTIFY_PLG]"; } #endif diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp index 88cb23621..5ac05776a 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.cpp @@ -48,7 +48,6 @@ static const QString VERSION = "1.0.0"; SoundNotifyPlugin::SoundNotifyPlugin() { phonon.mo = NULL; - configured = false; } SoundNotifyPlugin::~SoundNotifyPlugin() @@ -72,13 +71,10 @@ bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg) void SoundNotifyPlugin::extensionsInitialized() { Core::ICore::instance()->readSettings(this); - if ( !configured ){ - readConfig_0_0_0(); - } ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*))); - removedNotifies.clear(); + _toRemoveNotifications.clear(); connectNotifications(); } @@ -96,46 +92,19 @@ void SoundNotifyPlugin::saveConfig( QSettings* settings, UAVConfigInfo *configIn settings->endGroup(); settings->beginWriteArray("listNotifies"); - for (int i = 0; i < lstNotifications.size(); i++) { + for (int i = 0; i < _notificationList.size(); i++) { settings->setArrayIndex(i); - lstNotifications.at(i)->saveState(settings); + _notificationList.at(i)->saveState(settings); } settings->endArray(); settings->setValue(QLatin1String("EnableSound"), enableSound); } -void SoundNotifyPlugin::readConfig( QSettings* settings, UAVConfigInfo *configInfo){ - - if ( configInfo->version() == UAVConfigVersion() ){ - // Just for migration to the new format. - configured = false; - return; - } - - settings->beginReadArray("Current"); - settings->setArrayIndex(0); - currentNotification.restoreState(settings); - settings->endArray(); - - // read list of notifications from settings - int size = settings->beginReadArray("listNotifies"); - for (int i = 0; i < size; ++i) { - settings->setArrayIndex(i); - NotificationItem* notification = new NotificationItem; - notification->restoreState(settings); - lstNotifications.append(notification); - } - settings->endArray(); - setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool()); - - configured = true; -} - -void SoundNotifyPlugin::readConfig_0_0_0(){ - - settings = Core::ICore::instance()->settings(); - settings->beginGroup(QLatin1String("NotifyPlugin")); +void SoundNotifyPlugin::readConfig( QSettings* settings, UAVConfigInfo *configInfo) +{ + // Just for migration to the new format. + //Q_ASSERT(configInfo->version() == UAVConfigVersion()); settings->beginReadArray("Current"); settings->setArrayIndex(0); @@ -148,18 +117,10 @@ void SoundNotifyPlugin::readConfig_0_0_0(){ settings->setArrayIndex(i); NotificationItem* notification = new NotificationItem; notification->restoreState(settings); - lstNotifications.append(notification); + _notificationList.append(notification); } settings->endArray(); setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool()); - settings->endGroup(); - - ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); - connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*))); - removedNotifies.clear(); - connectNotifications(); - - configured = true; } void SoundNotifyPlugin::onTelemetryManagerAdded(QObject* obj) @@ -186,11 +147,11 @@ void SoundNotifyPlugin::onAutopilotDisconnect() void SoundNotifyPlugin::resetNotification(void) { //first, reject empty args and unknown fields. - foreach(NotificationItem* ntf, lstNotifications) { + foreach(NotificationItem* ntf, _notificationList) { ntf->disposeTimer(); - disconnect(ntf->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); + disconnect(ntf->getTimer(), SIGNAL(timeout()), this, SLOT(on_timerRepeated_Notification())); ntf->disposeExpireTimer(); - disconnect(ntf->getExpireTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); + disconnect(ntf->getExpireTimer(), SIGNAL(timeout()), this, SLOT(on_timerRepeated_Notification())); } } @@ -200,10 +161,10 @@ void SoundNotifyPlugin::resetNotification(void) */ void SoundNotifyPlugin::updateNotificationList(QList list) { - removedNotifies.clear(); + _toRemoveNotifications.clear(); resetNotification(); - lstNotifications.clear(); - lstNotifications=list; + _notificationList.clear(); + _notificationList=list; connectNotifications(); Core::ICore::instance()->saveSettings(this); @@ -213,7 +174,7 @@ void SoundNotifyPlugin::connectNotifications() { foreach(UAVDataObject* obj,lstNotifiedUAVObjects) { if (obj != NULL) - disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(appendNotification(UAVObject*))); + disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(on_arrived_Notification(UAVObject*))); } if (phonon.mo != NULL) { delete phonon.mo; @@ -226,29 +187,33 @@ void SoundNotifyPlugin::connectNotifications() UAVObjectManager *objManager = pm->getObject(); lstNotifiedUAVObjects.clear(); - pendingNotifications.clear(); - lstNotifications.append(removedNotifies); - removedNotifies.clear(); + _pendingNotifications.clear(); + _notificationList.append(_toRemoveNotifications); + _toRemoveNotifications.clear(); //first, reject empty args and unknown fields. - foreach(NotificationItem* notify, lstNotifications) { - notify->firstStart=true; + foreach(NotificationItem* notify, _notificationList) { + notify->_isPlayed = false; notify->isNowPlaying=false; if(notify->mute()) continue; + // check is all sounds presented for notification, + // if not - we must not subscribe to it at all + if(notify->toSoundList().isEmpty()) continue; UAVDataObject* obj = dynamic_cast( objManager->getObject(notify->getDataObject()) ); if (obj != NULL ) { if (!lstNotifiedUAVObjects.contains(obj)) { lstNotifiedUAVObjects.append(obj); - connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); + + connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(on_arrived_Notification(UAVObject*))); } } else { qNotifyDebug() << "Error: Object is unknown (" << notify->getDataObject() << ")."; } } - if (lstNotifications.isEmpty()) return; + if (_notificationList.isEmpty()) return; // set notification message to current event phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory); phonon.mo->clearQueue(); @@ -262,138 +227,66 @@ void SoundNotifyPlugin::connectNotifications() this, SLOT(stateChanged(Phonon::State,Phonon::State))); } -void SoundNotifyPlugin::appendNotification(UAVObject *object) +void SoundNotifyPlugin::on_arrived_Notification(UAVObject *object) { - disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); - - foreach(NotificationItem* ntf, lstNotifications) { + foreach(NotificationItem* ntf, _notificationList) { if (object->getName() != ntf->getDataObject()) continue; - if (nowPlayingConfiguration == ntf) + + // skip duplicate notifications + if (_nowPlayingNotification == ntf) continue; + // skip periodical notifications + // this condition accepts: + // 1. Periodical notifications played firstly; + // NOTE: At first time it will be played, then it played only by timer, + // when conditions became false firstStart flag has been cleared and + // 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" && - ntf->retryString() != "Repeat Once" && !ntf->firstStart) + ntf->retryString() != "Repeat Once" && ntf->_isPlayed) continue; - checkNotificationRule(ntf,object); + qNotifyDebug() << QString("new notification: | %1 | %2 | val1: %3 | val2: %4") + .arg(ntf->getDataObject()) + .arg(ntf->getObjectField()) + .arg(ntf->singleValue().toString()) + .arg(ntf->valueRange2()); + + QString fieldName = ntf->getObjectField(); + UAVObjectField* field = object->getField(fieldName); + + qNotifyDebug() << QString("UAV object: %1 | value: %2") + .arg(object->getName()) + .arg(field->getValue().toString()); + + checkNotificationRule(ntf, object); } - connect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); + connect(object, SIGNAL(objectUpdated(UAVObject*)), + this, SLOT(on_arrived_Notification(UAVObject*)), Qt::UniqueConnection); } -void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UAVObject* object) -{ - bool condition=false; - double threshold; - QString direction; - QString fieldName; - - threshold = notification->singleValue(); - direction = notification->range(); - fieldName = notification->getObjectField(); - UAVObjectField* field = object->getField(fieldName); - - if (field->getName().isEmpty()) - return; - - double value = field->getDouble(); - switch(direction[0].toAscii()) - { - case 'E': - condition = (value == threshold); - break; - - case 'G': - condition = (value > threshold); - break; - - case 'L': - condition = (value < threshold); - break; - - case 'R': - condition = (value > threshold) && (value < notification->valueRange2()); - break; - - } - - if (!condition) - return; - - if (!playNotification(notification)) { - if (!pendingNotifications.contains(notification)) { - notification->stopTimer(); - - qNotifyDebug() << "add to pending list - " << notification->toString(); - // if audio is busy, start expiration timer - //ms = (notification->getExpiredTimeout()[in sec])*1000 - //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); - pendingNotifications.append(notification); - notification->startExpireTimer(); - connect(notification->getExpireTimer(), SIGNAL(timeout()), this, SLOT(expireTimerHandler())); - } - } -} - -bool SoundNotifyPlugin::playNotification(NotificationItem* notification) -{ - // Check: race condition, if phonon.mo got deleted don't go further - if (phonon.mo == NULL) - return false; - - if (notification->mute()) - return false; - - qNotifyDebug() << "Phonon State: " << phonon.mo->state(); - if ((phonon.mo->state()==Phonon::PausedState) - || (phonon.mo->state()==Phonon::StoppedState) - || phonon.firstPlay) - { - // don't fire expire timer - nowPlayingConfiguration = notification; - notification->stopExpireTimer(); - - if (notification->retryString() == "Repeat Once") { - removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification))); - } else { - if (notification->retryString() != "Repeat Instantly") { - QRegExp rxlen("(\\d+)"); - QString value; - int timer_value; - int pos = rxlen.indexIn(notification->retryString()); - if (pos > -1) { - value = rxlen.cap(1); // "189" - timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage - } - - notification->startTimer(timer_value); - connect(notification->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); - } - } - notification->firstStart=false; - phonon.mo->clear(); - qNotifyDebug() << "play notification - " << notification->toString(); - foreach (QString item, notification->toSoundList()) { - Phonon::MediaSource *ms = new Phonon::MediaSource(item); - ms->setAutoDelete(true); - phonon.mo->enqueue(*ms); - } - phonon.mo->play(); - phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before - // the state is not "Loading" anymore. - } else { - return false; // if audio is busy - } - return true; -} - -void SoundNotifyPlugin::repeatTimerHandler() +void SoundNotifyPlugin::on_timerRepeated_Notification() { NotificationItem* notification = static_cast(sender()->parent()); + if (!notification) + return; + // skip duplicate notifications + // WARNING: generally we shoudn't ever trap here + // this means, that timer fires to early and notification overlap itself + if (_nowPlayingNotification == notification) { + qNotifyDebug() << "WARN: on_timerRepeated - notification was skipped!"; + notification->restartTimer(); + return; + } - qNotifyDebug() << "repeatTimerHandler - " << notification->toString(); + qNotifyDebug() << QString("repeatTimer: %1% | %2 | %3").arg(notification->getDataObject()) + .arg(notification->getObjectField()) + .arg(notification->toString()); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject(); @@ -402,15 +295,23 @@ void SoundNotifyPlugin::repeatTimerHandler() checkNotificationRule(notification,object); } -void SoundNotifyPlugin::expireTimerHandler() + +void SoundNotifyPlugin::on_expiredTimer_Notification() { // fire expire timer NotificationItem* notification = static_cast(sender()->parent()); + if(!notification) + return; notification->stopExpireTimer(); - if (!pendingNotifications.isEmpty()) { - qNotifyDebug() << "expireTimerHandler - " << notification->toString(); - pendingNotifications.removeOne(notification); + volatile QMutexLocker lock(&_mutex); + + if (!_pendingNotifications.isEmpty()) { + qNotifyDebug() << QString("expireTimer: %1% | %2 | %3").arg(notification->getDataObject()) + .arg(notification->getObjectField()) + .arg(notification->toString()); + + _pendingNotifications.removeOne(notification); } } @@ -418,8 +319,7 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst { Q_UNUSED(oldstate) - qNotifyDebug() << "File length (ms): " << phonon.mo->totalTime(); - qNotifyDebug() << "New State: " << newstate; + //qNotifyDebug() << "File length (ms): " << phonon.mo->totalTime(); #ifndef Q_OS_WIN // This is a hack to force Linux to wait until the end of the @@ -432,11 +332,18 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst if ((newstate == Phonon::PausedState) || (newstate == Phonon::StoppedState)) { - nowPlayingConfiguration=NULL; - if (!pendingNotifications.isEmpty()) + qNotifyDebug() << "New State: " << QVariant(newstate).toString(); + + volatile QMutexLocker lock(&_mutex); + // assignment to NULL needed to detect that palying is finished + // it's useful in repeat timer handler, where we can detect + // that notification has not overlap with itself + _nowPlayingNotification = NULL; + + if (!_pendingNotifications.isEmpty()) { - NotificationItem* notification = pendingNotifications.takeFirst(); - qNotifyDebug() << "play audioFree - " << notification->toString(); + NotificationItem* notification = _pendingNotifications.takeFirst(); + qNotifyDebug_if(notification) << "play audioFree - " << notification->toString(); playNotification(notification); } } else { @@ -449,4 +356,163 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst } } +bool checkRange(QString fieldValue, QString enumValue, QStringList values, char direction) +{ + + bool ret = false; + switch(direction) + { + case 'E': + ret = !QString::compare(enumValue, fieldValue, Qt::CaseInsensitive) ? true : false; + break; + + default: + ret = true; + break; + }; + return ret; +} + +bool checkRange(double fieldValue, double min, double max, char direction) +{ + bool ret = false; + Q_ASSERT(min < max); + switch(direction) + { + case 'E': + ret = (fieldValue == min); + break; + + case 'G': + ret = (fieldValue > min); + break; + + case 'L': + ret = (fieldValue < min); + break; + + default: + ret = (fieldValue > min) && (fieldValue < max); + break; + }; + + return ret; +} + +void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UAVObject* object) +{ + bool condition=false; + + if (notification->mute()) + return; + + QString direction = notification->range(); + QString fieldName = notification->getObjectField(); + UAVObjectField* field = object->getField(fieldName); + + if (field->getName().isEmpty()) + return; + + QVariant value = field->getValue(); + if(UAVObjectField::ENUM == field->getType()) { + condition = checkRange(value.toString(), + notification->singleValue().toString(), + field->getOptions(), + direction[0].toAscii()); + } else { + condition = checkRange(value.toDouble(), + notification->singleValue().toDouble(), + notification->valueRange2(), + direction[0].toAscii()); + } + + notification->_isPlayed = condition; + // if condition has been changed, and already in false state + // we should reset _isPlayed flag and stop repeat timer + if (!notification->_isPlayed) { + notification->stopTimer(); + return; + } + + volatile QMutexLocker lock(&_mutex); + + if (!playNotification(notification)) { + if (!_pendingNotifications.contains(notification) + && (_nowPlayingNotification != notification)) { + notification->stopTimer(); + + qNotifyDebug() << "add to pending list - " << notification->toString(); + // if audio is busy, start expiration timer + //ms = (notification->getExpiredTimeout()[in sec])*1000 + //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); + _pendingNotifications.append(notification); + notification->startExpireTimer(); + connect(notification->getExpireTimer(), SIGNAL(timeout()), + this, SLOT(on_expiredTimer_Notification()), Qt::UniqueConnection); + } + } +} + +bool SoundNotifyPlugin::playNotification(NotificationItem* notification) +{ + if(!notification) + return false; + + // Check: race condition, if phonon.mo got deleted don't go further + if (phonon.mo == NULL) + return false; + + //qNotifyDebug() << "Phonon State: " << phonon.mo->state(); + + if ((phonon.mo->state()==Phonon::PausedState) + || (phonon.mo->state()==Phonon::StoppedState) + || phonon.firstPlay) + { + _nowPlayingNotification = notification; + notification->stopExpireTimer(); + + if (notification->retryString() == "Repeat Once") { + _toRemoveNotifications.append(_notificationList.takeAt(_notificationList.indexOf(notification))); + } else { + if (notification->retryString() != "Repeat Instantly") { + QRegExp rxlen("(\\d+)"); + QString value; + int timer_value; + int pos = rxlen.indexIn(notification->retryString()); + if (pos > -1) { + value = rxlen.cap(1); // "189" + + // needs to correct repeat timer value, + // acording to message play duration, + // we don't measure duration of each message, + // simply take average duration + enum { eAverageDurationSec = 8 }; + + enum { eSecToMsec = 1000 }; + + timer_value = (value.toInt() + eAverageDurationSec) * eSecToMsec; + } + + notification->startTimer(timer_value); + connect(notification->getTimer(), SIGNAL(timeout()), + this, SLOT(on_timerRepeated_Notification()), Qt::UniqueConnection); + } + } + phonon.mo->clear(); + qNotifyDebug() << "play: " << notification->toString(); + foreach (QString item, notification->toSoundList()) { + Phonon::MediaSource *ms = new Phonon::MediaSource(item); + ms->setAutoDelete(true); + phonon.mo->enqueue(*ms); + } + phonon.mo->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; + + } + + return false; +} + Q_EXPORT_PLUGIN(SoundNotifyPlugin) diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h index 0b7a31f3b..6a142ff03 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h @@ -63,7 +63,7 @@ public: void shutdown(); - QList getListNotifications() { return lstNotifications; } + QList getListNotifications() { return _notificationList; } NotificationItem* getCurrentNotification(){ return ¤tNotification;} bool getEnableSound() const { return enableSound; } @@ -83,14 +83,12 @@ private slots: void connectNotifications(); void updateNotificationList(QList list); void resetNotification(void); - void appendNotification(UAVObject *object); - void repeatTimerHandler(void); - void expireTimerHandler(void); + void on_arrived_Notification(UAVObject *object); + void on_timerRepeated_Notification(void); + void on_expiredTimer_Notification(void); void stateChanged(Phonon::State newstate, Phonon::State oldstate); private: - - bool configured; // just for migration,delete later bool enableSound; QList< QList* > lstMediaSource; QStringList mediaSource; @@ -98,17 +96,17 @@ private: QSettings* settings; QList lstNotifiedUAVObjects; - QList lstNotifications; - QList pendingNotifications; - QList removedNotifies; + QList _notificationList; + QList _pendingNotifications; + QList _toRemoveNotifications; NotificationItem currentNotification; - NotificationItem* nowPlayingConfiguration; + NotificationItem* _nowPlayingNotification; - QString m_field; PhononObject phonon; - NotifyPluginOptionsPage *mop; + NotifyPluginOptionsPage* mop; TelemetryManager* telMngr; + QMutex _mutex; }; #endif // SOUNDNOTIFYPLUGIN_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index fdf0f5cc9..49b274e38 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -57,11 +57,10 @@ NotifyPluginOptionsPage::NotifyPluginOptionsPage(QObject *parent) : IOptionsPage(parent) , _objManager(*ExtensionSystem::PluginManager::instance()->getObject()) , _owner(qobject_cast(parent)) - , _currentCollectionPath("") - , _valueRange(NULL) + , _dynamicFieldLimit(NULL) + , _dynamicFieldWidget(NULL) + , _dynamicFieldType(-1) , _sayOrder(NULL) - , _fieldValue(NULL) - , _fieldType(-1) , _form(NULL) , _selectedNotification(NULL) {} @@ -74,23 +73,21 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) _optionsPage.reset(new Ui::NotifyPluginOptionsPage()); //main widget QWidget* optionsPageWidget = new QWidget; - _fieldValue = NULL; - _valueRange = NULL; + _dynamicFieldWidget = NULL; + _dynamicFieldLimit = NULL; resetFieldType(); //save ref to form, needed for binding dynamic fields in future _form = optionsPageWidget; //main layout _optionsPage->setupUi(optionsPageWidget); - _listSoundFiles.clear(); - _optionsPage->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); _optionsPage->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); connect(_optionsPage->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), - this, SLOT(on_buttonSoundFolder_clicked(const QString&))); + this, SLOT(on_clicked_buttonSoundFolder(const QString&))); connect(_optionsPage->SoundCollectionList, SIGNAL(currentIndexChanged (int)), - this, SLOT(on_soundLanguage_indexChanged(int))); + this, SLOT(on_changedIndex_soundLanguage(int))); connect(this, SIGNAL(updateNotifications(QList)), _owner, SLOT(updateNotificationList(QList))); @@ -100,8 +97,8 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) // [1] - _selectedNotification = _owner->getCurrentNotification(); - addDynamicValueLayout(); + setSelectedNotification(_owner->getCurrentNotification()); + addDynamicFieldLayout(); // [2] updateConfigView(_selectedNotification); @@ -109,7 +106,8 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) initButtons(); initPhononPlayer(); - _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(0, 0, QModelIndex()), + int curr_row = _privListNotifications.indexOf(_selectedNotification); + _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(curr_row, 0, QModelIndex()), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); return optionsPageWidget; @@ -125,151 +123,41 @@ void NotifyPluginOptionsPage::apply() void NotifyPluginOptionsPage::finish() { disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), - this, SLOT(on_UAVField_indexChanged(QString))); + this, SLOT(on_changedIndex_UAVField(QString))); - disconnect(_notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(on_changeButtonText(Phonon::State,Phonon::State))); - if (_notifySound) { - _notifySound->stop(); - _notifySound->clear(); + disconnect(_testSound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(on_changed_playButtonText(Phonon::State,Phonon::State))); + if (_testSound) { + _testSound->stop(); + _testSound->clear(); } } -void NotifyPluginOptionsPage::addDynamicValueLayout() -{ - NotificationItem* curr = _owner->getCurrentNotification(); - Q_ASSERT(curr); - _optionsPage->dynamicValueLayout->addWidget(new QLabel("Say order ", _form)); - - _sayOrder = new QComboBox(_form); - _optionsPage->dynamicValueLayout->addWidget(_sayOrder); - _sayOrder->addItems(NotificationItem::sayOrderValues); - - _optionsPage->dynamicValueLayout->addWidget(new QLabel("Value is ", _form)); - - UAVDataObject* obj = dynamic_cast(_objManager.getObject(curr->getDataObject())); - UAVObjectField* field = obj->getField(curr->getObjectField()); - Q_ASSERT(obj); - Q_ASSERT(field); - _valueRange = new QComboBox(_form); - _optionsPage->dynamicValueLayout->addWidget(_valueRange); - - addDynamicField(field); -} - -void NotifyPluginOptionsPage::resetValueRange() -{ - (static_cast(_fieldValue))->setInputMask("999.99 - 999.99;"); - (static_cast(_fieldValue))->setText("0000000000"); - (static_cast(_fieldValue))->setCursorPosition(0); -} - -void NotifyPluginOptionsPage::on_rangeValue_indexChanged(QString rangeStr) -{ - Q_ASSERT(_fieldValue); - UAVObjectField* field = getObjectFieldFromPage(); - Q_ASSERT(!!field); - setDynamicValueWidget(field); - setDynamicValueField(_selectedNotification); -} - -void NotifyPluginOptionsPage::resetFieldType() -{ - _fieldType = -1; -} - -void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField) -{ - //qDebugNotify_ if (!objField || !parent) << "null input params"; - Q_ASSERT(objField); - if (objField->getType() == _fieldType) { - if (QComboBox* fieldValue = dynamic_cast(_fieldValue)) { - fieldValue->clear(); - QStringList enumValues(objField->getOptions()); - fieldValue->addItems(enumValues); - } - return; - } - - disconnect(_valueRange, SIGNAL(currentIndexChanged(QString)), - this, SLOT(on_rangeValue_indexChanged(QString))); - - _valueRange->clear(); - QStringList rangeValues; - if (UAVObjectField::ENUM == objField->getType()) { - rangeValues << cStrEqualTo << cStrInRange; - _valueRange->addItems(rangeValues); - _valueRange->setCurrentIndex(rangeValues.indexOf(_selectedNotification->range())); - - } else { - rangeValues << cStrEqualTo << cStrLargeThan << cStrLowerThan << cStrInRange; - _valueRange->addItems(rangeValues); - connect(_valueRange, SIGNAL(currentIndexChanged(QString)), - this, SLOT(on_rangeValue_indexChanged(QString))); - } - - setDynamicValueWidget(objField); -} - -void NotifyPluginOptionsPage::setDynamicValueWidget(UAVObjectField* objField) -{ - Q_ASSERT(_valueRange); - - // check if dynamic fileld already settled, - // so if its exists remove it and install new field - if (_fieldValue) { - _optionsPage->dynamicValueLayout->removeWidget(_fieldValue); - delete _fieldValue; - _fieldValue = NULL; - } - _fieldType = objField->getType(); - switch(_fieldType) - { - case UAVObjectField::ENUM: - { - _fieldValue = new QComboBox(_form); - QStringList enumValues(objField->getOptions()); - (dynamic_cast(_fieldValue))->addItems(enumValues); - } - break; - - default: - if (_valueRange->currentText() == cStrInRange) { - _fieldValue = new QLineEdit(_form); - resetValueRange(); - } else { - _fieldValue = new QSpinBox(_form); - } - break; - }; - _optionsPage->dynamicValueLayout->addWidget(_fieldValue); -} - void NotifyPluginOptionsPage::initButtons() { _optionsPage->chkEnableSound->setChecked(_owner->getEnableSound()); connect(_optionsPage->chkEnableSound, SIGNAL(toggled(bool)), - this, SLOT(on_checkEnableSound_toggled(bool))); + this, SLOT(on_toggled_checkEnableSound(bool))); _optionsPage->buttonModify->setEnabled(false); _optionsPage->buttonDelete->setEnabled(false); _optionsPage->buttonPlayNotification->setEnabled(false); connect(_optionsPage->buttonAdd, SIGNAL(pressed()), - this, SLOT(on_button_AddNotification_clicked())); + this, SLOT(on_clicked_buttonAddNotification())); connect(_optionsPage->buttonDelete, SIGNAL(pressed()), - this, SLOT(on_button_DeleteNotification_clicked())); + this, SLOT(on_clicked_buttonDeleteNotification())); connect(_optionsPage->buttonModify, SIGNAL(pressed()), - this, SLOT(on_button_ModifyNotification_clicked())); + this, SLOT(on_clicked_buttonModifyNotification())); connect(_optionsPage->buttonPlayNotification, SIGNAL(clicked()), - this, SLOT(on_button_TestSoundNotification_clicked())); + this, SLOT(on_clicked_buttonTestSoundNotification())); } void NotifyPluginOptionsPage::initPhononPlayer() { - _notifySound.reset(Phonon::createPlayer(Phonon::NotificationCategory)); - connect(_notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(on_changeButtonText(Phonon::State,Phonon::State))); - connect(_notifySound.data(), SIGNAL(finished(void)), this, SLOT(on_FinishedPlaying(void))); + _testSound.reset(Phonon::createPlayer(Phonon::NotificationCategory)); + connect(_testSound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(on_changed_playButtonText(Phonon::State,Phonon::State))); + connect(_testSound.data(), SIGNAL(finished(void)), this, SLOT(on_FinishedPlaying(void))); } void NotifyPluginOptionsPage::initRulesTable() @@ -280,7 +168,7 @@ void NotifyPluginOptionsPage::initRulesTable() _notifyRulesSelection = new QItemSelectionModel(_notifyRulesModel.data()); connect(_notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), - this, SLOT(on_table_changeSelection( const QItemSelection & , const QItemSelection & ))); + this, SLOT(on_changedSelection_notifyTable( const QItemSelection & , const QItemSelection & ))); connect(this, SIGNAL(entryUpdated(int)), _notifyRulesModel.data(), SLOT(entryUpdated(int))); @@ -299,6 +187,159 @@ void NotifyPluginOptionsPage::initRulesTable() _optionsPage->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove); } +UAVObjectField* NotifyPluginOptionsPage::getObjectFieldFromSelected() +{ + return (_currUAVObject) ? _currUAVObject->getField(_selectedNotification->getObjectField()) : NULL; +} + +void NotifyPluginOptionsPage::setSelectedNotification(NotificationItem* ntf) +{ + _selectedNotification = ntf; + _currUAVObject = dynamic_cast(_objManager.getObject(_selectedNotification->getDataObject())); + if(!_currUAVObject) { + qNotifyDebug() << "no such UAVObject: " << _selectedNotification->getDataObject(); + } +} + +void NotifyPluginOptionsPage::addDynamicFieldLayout() +{ + // there is no need to check (objField == NULL), + // thus it doesn't use in this field directly + + QSizePolicy labelSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + labelSizePolicy.setHorizontalStretch(0); + labelSizePolicy.setVerticalStretch(0); +// labelSizePolicy.setHeightForWidth(UAVObject->sizePolicy().hasHeightForWidth()); + + + QLabel* labelSayOrder = new QLabel("Say order ", _form); + labelSayOrder->setSizePolicy(labelSizePolicy); + + _optionsPage->dynamicValueLayout->addWidget(labelSayOrder); + _sayOrder = new QComboBox(_form); + _optionsPage->dynamicValueLayout->addWidget(_sayOrder); + _sayOrder->addItems(NotificationItem::sayOrderValues); + + QLabel* labelValueIs = new QLabel("Value is ", _form); + labelValueIs->setSizePolicy(labelSizePolicy); + _optionsPage->dynamicValueLayout->addWidget(labelValueIs); + + _dynamicFieldLimit = new QComboBox(_form); + _optionsPage->dynamicValueLayout->addWidget(_dynamicFieldLimit); + UAVObjectField* field = getObjectFieldFromSelected(); + addDynamicField(field); +} + +void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField) +{ + if(!objField) { + qNotifyDebug() << "addDynamicField | input objField == NULL"; + return; + } + if (objField->getType() == _dynamicFieldType) { + if (QComboBox* fieldValue = dynamic_cast(_dynamicFieldWidget)) { + fieldValue->clear(); + QStringList enumValues(objField->getOptions()); + fieldValue->addItems(enumValues); + } + return; + } + + disconnect(_dynamicFieldLimit, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_changedIndex_rangeValue(QString))); + + _dynamicFieldLimit->clear(); + QStringList rangeValues; + if (UAVObjectField::ENUM == objField->getType()) { + rangeValues << cStrEqualTo << cStrInRange; + _dynamicFieldLimit->addItems(rangeValues); + _dynamicFieldLimit->setCurrentIndex(rangeValues.indexOf(_selectedNotification->range())); + + } else { + rangeValues << cStrEqualTo << cStrLargeThan << cStrLowerThan << cStrInRange; + _dynamicFieldLimit->addItems(rangeValues); + connect(_dynamicFieldLimit, SIGNAL(currentIndexChanged(QString)), + this, SLOT(on_changedIndex_rangeValue(QString))); + } + + addDynamicFieldWidget(objField); +} + +void NotifyPluginOptionsPage::addDynamicFieldWidget(UAVObjectField* objField) +{ + if(!objField) { + qNotifyDebug() << "objField == NULL!"; + return; + } + // check if dynamic fileld already settled, + // so if its exists remove it and install new field + if (_dynamicFieldWidget) { + _optionsPage->dynamicValueLayout->removeWidget(_dynamicFieldWidget); + delete _dynamicFieldWidget; + _dynamicFieldWidget = NULL; + } + + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + + _dynamicFieldType = objField->getType(); + switch(_dynamicFieldType) + { + case UAVObjectField::ENUM: + { + _dynamicFieldWidget = new QComboBox(_form); + QStringList enumValues(objField->getOptions()); + (dynamic_cast(_dynamicFieldWidget))->addItems(enumValues); + } + break; + + default: + Q_ASSERT(_dynamicFieldLimit); + if (_dynamicFieldLimit->currentText() == cStrInRange) { + _dynamicFieldWidget = new QLineEdit(_form); + + (static_cast(_dynamicFieldWidget))->setInputMask("999.99 - 999.99;"); + (static_cast(_dynamicFieldWidget))->setText("0000000000"); + (static_cast(_dynamicFieldWidget))->setCursorPosition(0); + } else { + _dynamicFieldWidget = new QDoubleSpinBox(_form); + (dynamic_cast(_dynamicFieldWidget))->setRange(000.00, 999.99); + } + break; + }; + enum { eDynamicFieldWidth = 100 }; + _dynamicFieldWidget->setSizePolicy(sizePolicy); + _dynamicFieldWidget->setFixedWidth(eDynamicFieldWidth); + _optionsPage->dynamicValueLayout->addWidget(_dynamicFieldWidget); +} + +void NotifyPluginOptionsPage::setDynamicFieldValue(NotificationItem* notification) +{ + if (QDoubleSpinBox* seValue = dynamic_cast(_dynamicFieldWidget)) + seValue->setValue(notification->singleValue().toDouble()); + else { + if (QComboBox* cbValue = dynamic_cast(_dynamicFieldWidget)) { + int idx = cbValue->findText(notification->singleValue().toString()); + if(-1 != idx) + cbValue->setCurrentIndex(idx); + } else { + if (QLineEdit* rangeValue = dynamic_cast(_dynamicFieldWidget)) { + QString str = QString("%1%2").arg(notification->singleValue().toDouble(), 5, 'f', 2, '0') + .arg(notification->valueRange2(), 5, 'f', 2, '0'); + rangeValue->setText(str); + } else { + qNotifyDebug() << "NotifyPluginOptionsPage::setDynamicValueField | unknown _fieldValue: " << _dynamicFieldWidget; + } + } + } +} + +void NotifyPluginOptionsPage::resetFieldType() +{ + _dynamicFieldType = -1; +} + void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) { Q_ASSERT(notification); @@ -310,14 +351,14 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio notification->setSound2(_optionsPage->Sound2->currentText()); notification->setSound3(_optionsPage->Sound3->currentText()); notification->setSayOrder(_sayOrder->currentText()); - notification->setRange(_valueRange->currentText()); - if (QSpinBox* spinValue = dynamic_cast(_fieldValue)) + notification->setRange(_dynamicFieldLimit->currentText()); + if (QDoubleSpinBox* spinValue = dynamic_cast(_dynamicFieldWidget)) notification->setSingleValue(spinValue->value()); else { - if (QComboBox* comboBoxValue = dynamic_cast(_fieldValue)) - notification->setSingleValue(comboBoxValue->currentIndex()); + if (QComboBox* comboBoxValue = dynamic_cast(_dynamicFieldWidget)) + notification->setSingleValue(comboBoxValue->currentText()); else { - if (QLineEdit* rangeValue = dynamic_cast(_fieldValue)) { + if (QLineEdit* rangeValue = dynamic_cast(_dynamicFieldWidget)) { QString str = rangeValue->text(); QStringList range = str.split('-'); notification->setSingleValue(range.at(0).toDouble()); @@ -327,113 +368,13 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio } } -void NotifyPluginOptionsPage::on_UAVField_indexChanged(QString field) -{ - resetFieldType(); - UAVDataObject* obj = dynamic_cast( _objManager.getObject(_optionsPage->UAVObject->currentText())); - addDynamicField(obj->getField(field)); - -} - -void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) -{ - resetFieldType(); - UAVDataObject* obj = dynamic_cast( _objManager.getObject(val) ); - QList fieldList = obj->getFields(); - disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVField_indexChanged(QString))); - _optionsPage->UAVObjectField->clear(); - foreach (UAVObjectField* field, fieldList) { - _optionsPage->UAVObjectField->addItem(field->getName()); - } - connect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVField_indexChanged(QString))); - addDynamicField(fieldList.at(0)); -} - -void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path) -{ - QDir dirPath(path); - _listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); - _optionsPage->SoundCollectionList->clear(); - _optionsPage->SoundCollectionList->addItems(_listDirCollections); -} - -void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) -{ - _optionsPage->SoundCollectionList->setCurrentIndex(index); - _currentCollectionPath = _optionsPage->SoundDirectoryPathChooser->path() - + QDir::toNativeSeparators("/" + _optionsPage->SoundCollectionList->currentText()); - - QDir dirPath(_currentCollectionPath); - QStringList filters; - filters << "*.mp3" << "*.wav"; - dirPath.setNameFilters(filters); - _listSoundFiles = dirPath.entryList(filters); - _listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), ""); - _optionsPage->Sound1->clear(); - _optionsPage->Sound2->clear(); - _optionsPage->Sound3->clear(); - _optionsPage->Sound1->addItems(_listSoundFiles); - _optionsPage->Sound2->addItem(""); - _optionsPage->Sound2->addItems(_listSoundFiles); - _optionsPage->Sound3->addItem(""); - _optionsPage->Sound3->addItems(_listSoundFiles); -} - -void NotifyPluginOptionsPage::on_changeButtonText(Phonon::State newstate, Phonon::State oldstate) -{ - //Q_ASSERT(Phonon::ErrorState != newstate); - - if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { - _optionsPage->buttonPlayNotification->setText("Play"); - _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); - } else { - if (newstate == Phonon::PlayingState) { - _optionsPage->buttonPlayNotification->setText("Stop"); - _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); - } - } -} - -void NotifyPluginOptionsPage::on_FinishedPlaying() -{ - _notifySound->clear(); -} - -void NotifyPluginOptionsPage::on_button_TestSoundNotification_clicked() -{ - NotificationItem* notification = NULL; - qNotifyDebug() << "on_buttonTestSoundNotification_clicked"; - Q_ASSERT(-1 != _notifyRulesSelection->currentIndex().row()); - _notifySound->clearQueue(); - notification = _privListNotifications.at(_notifyRulesSelection->currentIndex().row()); - QStringList sequence = notification->toSoundList(); - if (sequence.isEmpty()) { - qNotifyDebug() << "message sequense is empty!"; - return; - } - foreach(QString item, sequence) { - qNotifyDebug() << item; - _notifySound->enqueue(Phonon::MediaSource(item)); - } - _notifySound->play(); -} - -void NotifyPluginOptionsPage::on_checkEnableSound_toggled(bool state) -{ - bool state1 = 1^state; - - QList listOutputs = _notifySound->outputPaths(); - Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink(); - audioOutput->setMuted(state1); -} - void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) { Q_ASSERT(notification); disconnect(_optionsPage->UAVObject, SIGNAL(currentIndexChanged(QString)), - this, SLOT(on_UAVObject_indexChanged(QString))); + this, SLOT(on_changedIndex_UAVObject(QString))); disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), - this, SLOT(on_UAVField_indexChanged(QString))); + this, SLOT(on_changedIndex_UAVField(QString))); QString path = notification->getSoundCollectionPath(); if (path.isEmpty()) { @@ -461,13 +402,10 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) } _optionsPage->UAVObjectField->clear(); - QString uavDataObject = notification->getDataObject(); - UAVDataObject* obj = dynamic_cast(_objManager.getObject(uavDataObject)); - if (obj != NULL ) { - QList fieldList = obj->getFields(); - foreach (UAVObjectField* field, fieldList) { + if(_currUAVObject) { + QList fieldList = _currUAVObject->getFields(); + foreach (UAVObjectField* field, fieldList) _optionsPage->UAVObjectField->addItem(field->getName()); - } } if (-1 != _optionsPage->UAVObjectField->findText(notification->getObjectField())) { @@ -498,63 +436,105 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) _optionsPage->Sound3->setCurrentIndex(_optionsPage->Sound3->findText(notification->getSound3())); } - if (-1 != _valueRange->findText(notification->range())) { - _valueRange->setCurrentIndex(_valueRange->findText(notification->range())); + if (-1 != _dynamicFieldLimit->findText(notification->range())) { + _dynamicFieldLimit->setCurrentIndex(_dynamicFieldLimit->findText(notification->range())); } if (-1 != _sayOrder->findText(notification->getSayOrder())) { _sayOrder->setCurrentIndex(_sayOrder->findText(notification->getSayOrder())); } - setDynamicValueField(notification); + setDynamicFieldValue(notification); connect(_optionsPage->UAVObject, SIGNAL(currentIndexChanged(QString)), - this, SLOT(on_UAVObject_indexChanged(QString))); + this, SLOT(on_changedIndex_UAVObject(QString))); connect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), - this, SLOT(on_UAVField_indexChanged(QString))); + this, SLOT(on_changedIndex_UAVField(QString))); } -void NotifyPluginOptionsPage::setDynamicValueField(NotificationItem* notification) +void NotifyPluginOptionsPage::on_changedIndex_rangeValue(QString rangeStr) { - if (QSpinBox* spinValue = dynamic_cast(_fieldValue)) - spinValue->setValue(notification->singleValue()); - else { - if (QComboBox* comboBoxValue = dynamic_cast(_fieldValue)) - comboBoxValue->setCurrentIndex(notification->singleValue()); - else { - if (QLineEdit* rangeValue = dynamic_cast(_fieldValue)) { - //resetValueRange(); - QString str = QString("%1%2").arg(notification->singleValue(), 5, 'f', 2, '0') - .arg(notification->valueRange2(), 5, 'f', 2, '0'); - rangeValue->setText(str); - } else { - qNotifyDebug() << "NotifyPluginOptionsPage::setDynamicValueField | unknown _fieldValue: " << _fieldValue; - } + Q_ASSERT(_dynamicFieldWidget); + UAVObjectField* field = getObjectFieldFromSelected(); + Q_ASSERT(!!field); + addDynamicFieldWidget(field); + setDynamicFieldValue(_selectedNotification); +} + +void NotifyPluginOptionsPage::on_changedIndex_UAVField(QString field) +{ + resetFieldType(); + Q_ASSERT(_currUAVObject); + addDynamicField(_currUAVObject->getField(field)); + +} + +void NotifyPluginOptionsPage::on_changedIndex_UAVObject(QString val) +{ + resetFieldType(); + _currUAVObject = dynamic_cast( _objManager.getObject(val) ); + if(!_currUAVObject) { + qNotifyDebug() << "on_UAVObject_indexChanged | no such UAVOBject"; + return; + } + QList fieldList = _currUAVObject->getFields(); + disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_changedIndex_UAVField(QString))); + _optionsPage->UAVObjectField->clear(); + foreach (UAVObjectField* field, fieldList) { + _optionsPage->UAVObjectField->addItem(field->getName()); + } + connect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_changedIndex_UAVField(QString))); + _selectedNotification->setObjectField(fieldList.at(0)->getName()); + addDynamicField(fieldList.at(0)); +} + + +void NotifyPluginOptionsPage::on_changedIndex_soundLanguage(int index) +{ + _optionsPage->SoundCollectionList->setCurrentIndex(index); + QString collectionPath = _optionsPage->SoundDirectoryPathChooser->path() + + QDir::toNativeSeparators("/" + _optionsPage->SoundCollectionList->currentText()); + + QDir dirPath(collectionPath); + QStringList filters; + filters << "*.mp3" << "*.wav"; + dirPath.setNameFilters(filters); + QStringList listSoundFiles = dirPath.entryList(filters); + listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), ""); + _optionsPage->Sound1->clear(); + _optionsPage->Sound2->clear(); + _optionsPage->Sound3->clear(); + _optionsPage->Sound1->addItems(listSoundFiles); + _optionsPage->Sound2->addItem(""); + _optionsPage->Sound2->addItems(listSoundFiles); + _optionsPage->Sound3->addItem(""); + _optionsPage->Sound3->addItems(listSoundFiles); +} + + +void NotifyPluginOptionsPage::on_changed_playButtonText(Phonon::State newstate, Phonon::State oldstate) +{ + //Q_ASSERT(Phonon::ErrorState != newstate); + + if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) { + _optionsPage->buttonPlayNotification->setText("Play"); + _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); + } else { + if (newstate == Phonon::PlayingState) { + _optionsPage->buttonPlayNotification->setText("Stop"); + _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); } } } -UAVObjectField* NotifyPluginOptionsPage::getObjectFieldFromPage() -{ - UAVDataObject* obj = dynamic_cast( _objManager.getObject(_optionsPage->UAVObject->currentText())); - return obj->getField(_optionsPage->UAVObjectField->currentText()); -} - - -UAVObjectField* NotifyPluginOptionsPage::getObjectFieldFromSelected() -{ - UAVDataObject* obj = dynamic_cast(_objManager.getObject(_selectedNotification->getDataObject())); - return obj->getField(_selectedNotification->getObjectField()); -} - -void NotifyPluginOptionsPage::on_table_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ) +void NotifyPluginOptionsPage::on_changedSelection_notifyTable(const QItemSelection & selected, const QItemSelection & deselected ) { bool select = false; - _notifySound->stop(); + _testSound->stop(); if (selected.indexes().size()) { select = true; - _selectedNotification = _privListNotifications.at(selected.indexes().at(0).row()); + setSelectedNotification(_privListNotifications.at(selected.indexes().at(0).row())); UAVObjectField* field = getObjectFieldFromSelected(); addDynamicField(field); updateConfigView(_selectedNotification); @@ -565,7 +545,34 @@ void NotifyPluginOptionsPage::on_table_changeSelection( const QItemSelection & s _optionsPage->buttonPlayNotification->setEnabled(select); } -void NotifyPluginOptionsPage::on_button_AddNotification_clicked() +void NotifyPluginOptionsPage::on_clicked_buttonSoundFolder(const QString& path) +{ + QDir dirPath(path); + QStringList listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + _optionsPage->SoundCollectionList->clear(); + _optionsPage->SoundCollectionList->addItems(listDirCollections); +} + +void NotifyPluginOptionsPage::on_clicked_buttonTestSoundNotification() +{ + NotificationItem* notification = NULL; + qNotifyDebug() << "on_buttonTestSoundNotification_clicked"; + Q_ASSERT(-1 != _notifyRulesSelection->currentIndex().row()); + _testSound->clearQueue(); + notification = _privListNotifications.at(_notifyRulesSelection->currentIndex().row()); + QStringList sequence = notification->toSoundList(); + if (sequence.isEmpty()) { + qNotifyDebug() << "message sequense is empty!"; + return; + } + foreach(QString item, sequence) { + qNotifyDebug() << item; + _testSound->enqueue(Phonon::MediaSource(item)); + } + _testSound->play(); +} + +void NotifyPluginOptionsPage::on_clicked_buttonAddNotification() { NotificationItem* notification = new NotificationItem; @@ -574,27 +581,15 @@ void NotifyPluginOptionsPage::on_button_AddNotification_clicked() textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); _optionsPage->SoundDirectoryPathChooser->setPalette(textPalette); _optionsPage->SoundDirectoryPathChooser->setPath("please select sound collection folder"); + delete notification; return; } + getOptionsPageValues(notification); - notification->setSoundCollectionPath(_optionsPage->SoundDirectoryPathChooser->path()); - notification->setCurrentLanguage(_optionsPage->SoundCollectionList->currentText()); - notification->setDataObject(_optionsPage->UAVObject->currentText()); - notification->setObjectField(_optionsPage->UAVObjectField->currentText()); - notification->setRange(_valueRange->currentText()); - - if (QSpinBox* spinValue = dynamic_cast(_fieldValue)) - notification->setSingleValue(spinValue->value()); - - if (_optionsPage->Sound1->currentText().size() > 0) - notification->setSound1(_optionsPage->Sound1->currentText()); - - notification->setSound2(_optionsPage->Sound2->currentText()); - notification->setSound3(_optionsPage->Sound3->currentText()); - - if ( ((!_optionsPage->Sound2->currentText().size()) && (_sayOrder->currentText()=="After second")) - || ((!_optionsPage->Sound3->currentText().size()) && (_sayOrder->currentText()=="After third")) ) { - return; + if ( ((!_optionsPage->Sound2->currentText().isEmpty()) && (_sayOrder->currentText()=="After second")) + || ((!_optionsPage->Sound3->currentText().isEmpty()) && (_sayOrder->currentText()=="After third")) ) { + delete notification; + return; } else { notification->setSayOrder(_sayOrder->currentText()); } @@ -604,7 +599,7 @@ void NotifyPluginOptionsPage::on_button_AddNotification_clicked() QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } -void NotifyPluginOptionsPage::on_button_DeleteNotification_clicked() +void NotifyPluginOptionsPage::on_clicked_buttonDeleteNotification() { _notifyRulesModel->removeRow(_notifyRulesSelection->currentIndex().row()); if (!_notifyRulesModel->rowCount() @@ -617,7 +612,7 @@ void NotifyPluginOptionsPage::on_button_DeleteNotification_clicked() } } -void NotifyPluginOptionsPage::on_button_ModifyNotification_clicked() +void NotifyPluginOptionsPage::on_clicked_buttonModifyNotification() { NotificationItem* notification = new NotificationItem; getOptionsPageValues(notification); @@ -628,3 +623,17 @@ void NotifyPluginOptionsPage::on_button_ModifyNotification_clicked() _privListNotifications.replace(_notifyRulesSelection->currentIndex().row(),notification); entryUpdated(_notifyRulesSelection->currentIndex().row()); } + +void NotifyPluginOptionsPage::on_FinishedPlaying() +{ + _testSound->clear(); +} + +void NotifyPluginOptionsPage::on_toggled_checkEnableSound(bool state) +{ + bool state1 = 1^state; + + QList listOutputs = _testSound->outputPaths(); + Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink(); + audioOutput->setMuted(state1); +} diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h index 3f36f3f4d..b270e72a0 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h @@ -73,33 +73,28 @@ public: void finish(); void restoreFromSettings(); - void updateConfigView(NotificationItem* notification); - void getOptionsPageValues(NotificationItem* notification); - UAVObjectField* getObjectFieldFromPage(); - UAVObjectField* getObjectFieldFromSelected(); - signals: void updateNotifications(QList list); void entryUpdated(int index); private slots: - void on_button_TestSoundNotification_clicked(); - void on_button_AddNotification_clicked(); - void on_button_DeleteNotification_clicked(); - void on_button_ModifyNotification_clicked(); + void on_clicked_buttonTestSoundNotification(); + void on_clicked_buttonAddNotification(); + void on_clicked_buttonDeleteNotification(); + void on_clicked_buttonModifyNotification(); /** * We can use continuous selection, to select simultaneously * multiple rows to move them(using drag & drop) inside table ranges. */ - void on_table_changeSelection( const QItemSelection & selected, const QItemSelection & deselected ); + void on_changedSelection_notifyTable( const QItemSelection & selected, const QItemSelection & deselected ); - void on_soundLanguage_indexChanged(int index); - void on_buttonSoundFolder_clicked(const QString& path); - void on_UAVObject_indexChanged(QString val); - void on_UAVField_indexChanged(QString val); - void on_changeButtonText(Phonon::State newstate, Phonon::State oldstate); - void on_checkEnableSound_toggled(bool state); + void on_changedIndex_soundLanguage(int index); + void on_clicked_buttonSoundFolder(const QString& path); + void on_changedIndex_UAVObject(QString val); + void on_changedIndex_UAVField(QString val); + void on_changed_playButtonText(Phonon::State newstate, Phonon::State oldstate); + void on_toggled_checkEnableSound(bool state); /** * Important when we change to or from "In range" value @@ -107,7 +102,7 @@ private slots: * we need to change UI to show edit line, * to have possibility assign range limits for value. */ - void on_rangeValue_indexChanged(QString); + void on_changedIndex_rangeValue(QString); void on_FinishedPlaying(void); @@ -115,29 +110,31 @@ private slots: private: Q_DISABLE_COPY(NotifyPluginOptionsPage) - void resetValueRange(); - void resetFieldType(); - - void setDynamicValueField(NotificationItem* notification); - void addDynamicField(UAVObjectField* objField); - void addDynamicValueLayout(); - void setDynamicValueWidget(UAVObjectField* objField); - void initButtons(); void initPhononPlayer(); void initRulesTable(); + void setSelectedNotification(NotificationItem* ntf); + void resetValueRange(); + void resetFieldType(); + + void updateConfigView(NotificationItem* notification); + void getOptionsPageValues(NotificationItem* notification); + UAVObjectField* getObjectFieldFromPage(); + UAVObjectField* getObjectFieldFromSelected(); + + void addDynamicFieldLayout(); + void addDynamicField(UAVObjectField* objField); + void addDynamicFieldWidget(UAVObjectField* objField); + void setDynamicFieldValue(NotificationItem* notification); + private: UAVObjectManager& _objManager; SoundNotifyPlugin* _owner; - QStringList _listDirCollections; - QStringList _listSoundFiles; - QString _currentCollectionPath; - Phonon::MediaObject* _sound1; - Phonon::MediaObject* _sound2; - QScopedPointer _notifySound; - Phonon::AudioOutput* _audioOutput; + + //! Media object uses to test sound playing + QScopedPointer _testSound; QScopedPointer _notifyRulesModel; QItemSelectionModel* _notifyRulesSelection; @@ -154,34 +151,36 @@ private: QScopedPointer _optionsPage; - //! widget to convinient selection of condition for field value (equal, lower, greater) - QComboBox* _valueRange; + //! Widget to convinient selection of condition for field value (equal, lower, greater) + QComboBox* _dynamicFieldLimit; - //! widget to convinient selection of order in which sounds will be played + //! Represents edit widget for dynamic UAVObjectfield, + //! can be spinbox - for numerics, combobox - enums, or + //! lineedit - for numerics with range constraints + QWidget* _dynamicFieldWidget; + + //! Type of UAVObjectField - numeric or ENUM, + //! this variable needs to correctly set appropriate dynamic UI element (_dynamicFieldWidget) + //! NOTE: ocassionaly it should be invalidated (= -1) to reset _dynamicFieldWidget + int _dynamicFieldType; + + //! Widget to convinient selection of position of + //! between sounds[1..3] QComboBox* _sayOrder; - //! widget to represent edit widget for UAVObjectfield, - //! can be spinbox - for numerics, combobox - enums, or - //! lineedit - for range limits - QWidget* _fieldValue; - - //! type of UAVObjectField - numeric or ENUM - //! this variable needs to correctly set dynamic UI elemen _fieldValue - //! NOTE: ocassionaly it should be invalidated (= -1) to reset _fieldValue - int _fieldType; - - //! actualy reference to optionsPageWidget, + //! Actualy reference to optionsPageWidget, //! we MUST hold it beyond the scope of createPage func //! to have possibility change dynamic parts of options page layout in future QWidget* _form; - //! needs to correctly update UI during transitions from "In Range" to other - //! _valueRange entries and back direction as well - QString _prevRangeValue; - //! Currently selected notification, all controls filled accroding to it. //! On options page startup, always points to first row. NotificationItem* _selectedNotification; + + //! Retrieved from UAVObjectManager by name from _selectedNotification, + //! if UAVObjectManager doesn't have such object, this field will be NULL + UAVDataObject* _currUAVObject; + }; #endif // NOTIFYPLUGINOPTIONSPAGE_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp index b1fd1c737..ed4eb0e56 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp @@ -45,19 +45,19 @@ bool NotifyTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::DisplayRole) { - if(eMessageName == index.column()) { + if (eMessageName == index.column()) { emit dataChanged(index, index); return true; } } if (index.isValid() && role == Qt::EditRole) { - if(eRepeatValue == index.column()) + if (eRepeatValue == index.column()) _list.at(index.row())->setRetryString(value.toString()); else { - if(eExpireTimer == index.column()) + if (eExpireTimer == index.column()) _list.at(index.row())->setLifetime(value.toInt()); else { - if(eTurnOn == index.column()) + if (eTurnOn == index.column()) _list.at(index.row())->setMute(value.toBool()); } } @@ -114,7 +114,7 @@ QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation, if (orientation == Qt::Horizontal) return _headerStrings.at(section); else - if(orientation == Qt::Vertical) + if (orientation == Qt::Vertical) return QString("%1").arg(section); return QVariant(); @@ -141,7 +141,7 @@ bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex& ind { Q_UNUSED(index); - if((-1 == position) || (-1 == rows) ) + if ((-1 == position) || (-1 == rows) ) return false; beginRemoveRows(QModelIndex(), position, position + rows - 1); @@ -201,7 +201,7 @@ bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction acti beginRow = rowCount(QModelIndex()); } - if(-1 == beginRow) + if (-1 == beginRow) return false; QByteArray encodedData = data->data(mime_type_notify_table); @@ -217,15 +217,18 @@ bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction acti // or from bottom rows to top rows (UP_DIRECTION) enum { UP_DIRECTION, DOWN_DIRECTION }; int direction = (dragged < rows) ? DOWN_DIRECTION : (dragged += 1, UP_DIRECTION); - Q_ASSERT(insertRows(rows + direction, 1, QModelIndex())); - if(-1 == dragged || rows >= _list.size() || dragged == rows) { + // check drop bounds + if (dragged < 0 || ((dragged + 1) >= _list.size() && direction == DOWN_DIRECTION) || dragged == rows) { qNotifyDebug() << "no such item"; - - return false; + continue; } + // addiional check in case dropping of multiple rows + if(rows + direction > _list.size()) continue; + + Q_ASSERT(insertRows(rows + direction, 1, QModelIndex())); _list.replace(rows + direction, item); Q_ASSERT(removeRows(dragged, 1, QModelIndex())); - if(direction == UP_DIRECTION) + if (direction == UP_DIRECTION) ++rows; };