diff --git a/ground/src/plugins/notify/NotifyPlugin.pluginspec b/ground/src/plugins/notify/NotifyPlugin.pluginspec index 3c4032de7..f19845a4f 100644 --- a/ground/src/plugins/notify/NotifyPlugin.pluginspec +++ b/ground/src/plugins/notify/NotifyPlugin.pluginspec @@ -1,4 +1,4 @@ - + The OpenPilot Project (C) 2010 Daniel Godin The GNU Public License (GPL) Version 3 diff --git a/ground/src/plugins/notify/images/add.png b/ground/src/plugins/notify/images/add.png new file mode 100644 index 000000000..93257c816 Binary files /dev/null and b/ground/src/plugins/notify/images/add.png differ diff --git a/ground/src/plugins/notify/images/delete.png b/ground/src/plugins/notify/images/delete.png new file mode 100644 index 000000000..d91a52dc0 Binary files /dev/null and b/ground/src/plugins/notify/images/delete.png differ diff --git a/ground/src/plugins/notify/images/modify.png b/ground/src/plugins/notify/images/modify.png new file mode 100644 index 000000000..5f841381e Binary files /dev/null and b/ground/src/plugins/notify/images/modify.png differ diff --git a/ground/src/plugins/notify/images/play.png b/ground/src/plugins/notify/images/play.png new file mode 100644 index 000000000..d7089dca5 Binary files /dev/null and b/ground/src/plugins/notify/images/play.png differ diff --git a/ground/src/plugins/notify/images/play2.png b/ground/src/plugins/notify/images/play2.png new file mode 100644 index 000000000..581bf054d Binary files /dev/null and b/ground/src/plugins/notify/images/play2.png differ diff --git a/ground/src/plugins/notify/images/stop.png b/ground/src/plugins/notify/images/stop.png new file mode 100644 index 000000000..e985587d6 Binary files /dev/null and b/ground/src/plugins/notify/images/stop.png differ diff --git a/ground/src/plugins/notify/notify.pro b/ground/src/plugins/notify/notify.pro index a78172bcc..dfcc21fa0 100644 --- a/ground/src/plugins/notify/notify.pro +++ b/ground/src/plugins/notify/notify.pro @@ -10,12 +10,17 @@ QT += phonon HEADERS += notifyplugin.h \ notifypluginoptionspage.h \ - notifypluginconfiguration.h + notifypluginconfiguration.h \ + notifyitemdelegate.h SOURCES += notifyplugin.cpp \ notifypluginoptionspage.cpp \ - notifypluginconfiguration.cpp + notifypluginconfiguration.cpp \ + notifyitemdelegate.cpp OTHER_FILES += NotifyPlugin.pluginspec FORMS += \ notifypluginoptionspage.ui + +RESOURCES += \ + res.qrc diff --git a/ground/src/plugins/notify/notifygadgetoptionspage.ui b/ground/src/plugins/notify/notifygadgetoptionspage.ui deleted file mode 100644 index f9869fc24..000000000 --- a/ground/src/plugins/notify/notifygadgetoptionspage.ui +++ /dev/null @@ -1,343 +0,0 @@ - - - NotifyGadgetOptionsPage - - - - 0 - 0 - 376 - 400 - - - - - 0 - 0 - - - - Form - - - - - 10 - 190 - 351 - 171 - - - - Current Notifications - - - - - 10 - 20 - 331 - 111 - - - - <!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:'Segoe UI'; font-size:9pt; 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;">Lists the notifactions already configured. Clicking on an item enables it to be modified. </p></body></html> - - - false - - - false - - - - - - 9 - 140 - 331 - 25 - - - - - - - Enable Sounds - - - - - - - Qt::Horizontal - - - - 138 - 20 - - - - - - - - Delete - - - - - - - - - - 10 - 10 - 358 - 177 - - - - - - - - - Sound Collection: - - - - - - - - 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> - - - - - - - Qt::Horizontal - - - - 28 - 20 - - - - - - - - <!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;">Locate the base directory of the Sound Collections</span></p></body></html> - - - Locate... - - - - - - - - - Qt::Horizontal - - - - - - - - - Object: - - - - - - - - 0 - 0 - - - - - - - - Field: - - - - - - - - 0 - 0 - - - - - - - - Value is: - - - - - - - - 0 - 0 - - - - - Equal to - - - - - Greater than - - - - - Less than - - - - - - - - - - - Sound 1: - - - - - - - - 0 - 0 - - - - - - - - Test - - - - - - - Sound 2: - - - - - - - - 0 - 0 - - - - - - - - Test - - - - - - - Say Value: - - - - - - - Select if the value of the object should be spoken and if so, either before the configured sound or after it. - - - - Never - - - - - Before Snd 1 - - - - - After Snd 1 - - - - - After Snd 2 - - - - - - - - Modify - - - - - - - Add - - - - - - - - - - - diff --git a/ground/src/plugins/notify/notifyitemdelegate.cpp b/ground/src/plugins/notify/notifyitemdelegate.cpp new file mode 100644 index 000000000..86ec6e60c --- /dev/null +++ b/ground/src/plugins/notify/notifyitemdelegate.cpp @@ -0,0 +1,206 @@ +/** + ****************************************************************************** + * + * @file notifyitemdelegate.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief + * @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 "notifyitemdelegate.h" +#include + +//RepeatCounterDelegate::RepeatCounterDelegate(QObject *parent) +// : QItemDelegate(parent) {} + +// QWidget* RepeatCounterDelegate::createEditor(QWidget *parent, +// const QStyleOptionViewItem &, +// const QModelIndex &index) const +// { +// if (index.row() == 2) { +// QSpinBox *editor = new QSpinBox(parent); +// editor->setMinimum(0); +// editor->setMaximum(100); +// return editor; +// } + +// QLabel *editor = new QLabel(parent); + +// connect(editor, SIGNAL(editingFinished()), +// this, SLOT(commitAndCloseEditor())); +// return editor; +// } + +// void RepeatCounterDelegate::commitAndCloseEditor() +// { +// QLabel* editor = qobject_cast(sender()); +// emit commitData(editor); +// emit closeEditor(editor); +// } + +// void RepeatCounterDelegate::setEditorData(QWidget *editor, +// const QModelIndex &index) const +// { +// QLabel* edit = qobject_cast(editor); +// if (edit) { +// edit->setText(index.model()->data(index, Qt::EditRole).toString()); +// } else { +// QSpinBox* spinBox = static_cast(editor); +// if (spinBox) +// { +// int value = index.model()->data(index, Qt::EditRole).toInt(); +// spinBox->setValue(value); + +// //repeatEditor->setCurrentIndex(repeatEditor->findText(index.model()->data(index, Qt::EditRole).toString())); +//// repeatEditor->setDate(QDate::fromString( +//// index.model()->data(index, Qt::EditRole).toString(), +//// "d/M/yyyy")); +// } +// } +// } + +// void RepeatCounterDelegate::setModelData(QWidget *editor, +// QAbstractItemModel *model, const QModelIndex &index) const +// { +// QLabel* edit = qobject_cast(editor); +// if (edit) { +// model->setData(index, edit->text()); +// } else { +// QSpinBox* spinBox = static_cast(editor); +// if (spinBox) { +// spinBox->interpretText(); +// int value = spinBox->value(); +// model->setData(index, value, Qt::EditRole); +// } +// } +// } + +////////////////////////////////////////////////////////////////////////// + + NotifyItemDelegate::NotifyItemDelegate(QStringList items,QObject *parent) + : QItemDelegate(parent), + m_parent(parent), + m_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; + } + 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); + } + } + } + + 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())); +// QTableWidgetItem* item = ((QTableWidget*)m_parent)->item(index.row(),1); +// item->setSelected(true); + } + } + + 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()); +// emit commitData(repeatEditor); +// emit closeEditor(repeatEditor); + } + } + } + +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); +} + +// bool NotifyItemDelegate::editorEvent(QEvent * event, QAbstractItemModel * model, +// const QStyleOptionViewItem & option, const QModelIndex & index ) +// { +// if(event->type()==QEvent::EnabledChange) +// { +// QTableWidgetItem* item = ((QTableWidget*)parent())->item(index.row(),index.column()); +// item->setSelected(true); +// } +// return false; +// } diff --git a/ground/src/plugins/notify/notifyitemdelegate.h b/ground/src/plugins/notify/notifyitemdelegate.h new file mode 100644 index 000000000..99ee545e4 --- /dev/null +++ b/ground/src/plugins/notify/notifyitemdelegate.h @@ -0,0 +1,74 @@ +/** + ****************************************************************************** + * + * @file notifyitemdelegate.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief + * @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 NOTIFYITEMDELEGATE_H +#define NOTIFYITEMDELEGATE_H + +#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 +{ + Q_OBJECT + +public: + NotifyItemDelegate(QStringList items, 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; +// bool editorEvent(QEvent * event, QAbstractItemModel * model, +// const QStyleOptionViewItem & option, const QModelIndex & index ); +private: + QObject* m_parent; + QStringList m_items; + QComboBox* repeatEditor; + + +private slots: + void selectRow(const QString & text); + void commitAndCloseEditor(); +}; + +#endif // NOTIFYITEMDELEGATE_H diff --git a/ground/src/plugins/notify/notifyplugin.cpp b/ground/src/plugins/notify/notifyplugin.cpp index 6d1c100b8..5ba5eadd5 100644 --- a/ground/src/plugins/notify/notifyplugin.cpp +++ b/ground/src/plugins/notify/notifyplugin.cpp @@ -1,172 +1,198 @@ -/** - ****************************************************************************** - * - * @file donothingplugin.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. - * @brief - * @see The GNU Public License (GPL) Version 3 - * @defgroup donothingplugin - * @{ - * - *****************************************************************************/ -/* - * 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 "notifyplugin.h" -#include "notifypluginconfiguration.h" -#include "notifypluginoptionspage.h" -#include -#include -#include -#include -#include -#include - - -SoundNotifyPlugin::SoundNotifyPlugin() -{ - // Do nothing -} - -SoundNotifyPlugin::~SoundNotifyPlugin() -{ - // Do nothing -} - -bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg) -{ - Q_UNUSED(args); - Q_UNUSED(errMsg); - - mop = new NotifyPluginOptionsPage(this); - addAutoReleasedObject(mop); - - return true; -} - -void SoundNotifyPlugin::extensionsInitialized() -{ - settings = Core::ICore::instance()->settings(); - settings->beginGroup(QLatin1String("NotifyPlugin")); - - // read list of notifications from settings - int size = settings->beginReadArray("listNotifies"); - for (int i = 0; i < size; ++i) { - settings->setArrayIndex(i); - notify = new NotifyPluginConfiguration; - notify->restoreState(settings); - lstNotifications.append(notify); - } - settings->endArray(); - setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool()); - settings->endGroup(); - - connectNotifications(); -} - -void SoundNotifyPlugin::shutdown() -{ - // Do nothing -} - - -void SoundNotifyPlugin::connectNotifications() -{ - foreach(UAVDataObject* obj,lstNotifiedUAVObjects) { - if (obj != NULL) - disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(playNotification(UAVObject*))); - } - if(!enableSound) return; - - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - - QList deleteList = mapMediaObjects.values(); - if(!deleteList.isEmpty()) - foreach(Phonon::MediaObject* mediaObj,deleteList) - delete mediaObj; - - // Check validity of arguments first, reject empty args and unknown fields. - foreach(NotifyPluginConfiguration* notify,lstNotifications) { - UAVDataObject* obj = dynamic_cast( objManager->getObject(notify->getDataObject()) ); - if (obj != NULL ) { - std::cout << "Connected Object (" << notify->getDataObject().toStdString() << ")." << std::endl; - connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(playNotification(UAVObject*))); - lstNotifiedUAVObjects.append(obj); - notify->parseNotifyMessage(); - mediaSource = notify->getNotifyMessageList(); - lstMediaSource.append(new QList); - foreach(QString item, mediaSource) - lstMediaSource.last()->append(Phonon::MediaSource(item)); - - // set notification message to current event - mapMediaObjects[obj->getName()] = new Phonon::MediaObject; - mapMediaObjects[obj->getName()] = Phonon::createPlayer(Phonon::NotificationCategory); - mapMediaObjects[obj->getName()]->setQueue(*lstMediaSource.last()); - } else { - std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl; - } - } -} - -void SoundNotifyPlugin::playNotification(UAVObject *object) -{ - UAVObjectField* field; - double threshold; - QString direction; - bool play = false; - - foreach(NotifyPluginConfiguration* notify, lstNotifications) { - if(object->getName()==notify->getDataObject()) { - QString fld = notify->getObjectField(); - field = object->getField(fld); - threshold = notify->getSpinBoxValue(); - direction = notify->getValue(); - } - } - - if (field) { - switch(direction[0].toAscii()) - { - case 'E': - if(field->getDouble()==threshold) - play = true; - break; - case 'G': - if(field->getDouble()>threshold) - play = true; - break; - case 'L': - if(field->getDouble()getName()]->state()==Phonon::PausedState) || - (mapMediaObjects[object->getName()]->state()==Phonon::StoppedState)) - { - mapMediaObjects[object->getName()]->clear(); - mapMediaObjects[object->getName()]->setQueue(*lstMediaSource.last()); - mapMediaObjects[object->getName()]->play(); - } - } - } -} - -Q_EXPORT_PLUGIN(SoundNotifyPlugin) +/** + ****************************************************************************** + * + * @file notifyplugin.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief + * @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 "notifyplugin.h" +#include "notifypluginconfiguration.h" +#include "notifypluginoptionspage.h" +#include +#include +#include +#include +#include +#include + + +SoundNotifyPlugin::SoundNotifyPlugin() +{ + // Do nothing +} + +SoundNotifyPlugin::~SoundNotifyPlugin() +{ + // Do nothing +} + +bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg) +{ + Q_UNUSED(args); + Q_UNUSED(errMsg); + + mop = new NotifyPluginOptionsPage(this); + addAutoReleasedObject(mop); + + return true; +} + +void SoundNotifyPlugin::extensionsInitialized() +{ + settings = Core::ICore::instance()->settings(); + settings->beginGroup(QLatin1String("NotifyPlugin")); + + // read list of notifications from settings + int size = settings->beginReadArray("listNotifies"); + for (int i = 0; i < size; ++i) { + settings->setArrayIndex(i); + NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; + notification->restoreState(settings); + lstNotifications.append(notification); + } + settings->endArray(); + setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool()); + settings->endGroup(); + + connectNotifications(); +} + +void SoundNotifyPlugin::shutdown() +{ + // Do nothing +} + + +void SoundNotifyPlugin::connectNotifications() +{ + foreach(UAVDataObject* obj,lstNotifiedUAVObjects) { + if (obj != NULL) + disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(playNotification(UAVObject*))); + } + if(!enableSound) return; + + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objManager = pm->getObject(); + + lstNotifiedUAVObjects.clear(); + +// QList deleteList = mapMediaObjects.values(); +// if(!deleteList.isEmpty()) +// foreach(Phonon::MediaObject* mediaObj,deleteList) +// delete mediaObj; + + // Check validity of arguments first, reject empty args and unknown fields. + foreach(NotifyPluginConfiguration* notify,lstNotifications) { + 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(playNotification(UAVObject*))); + } + //lstMediaSource.append(new QList); + + QMap::const_iterator iter = mapMediaObjects.find(obj->getName()); + if(iter==mapMediaObjects.end()) { + // set notification message to current event + mapMediaObjects[obj->getName()].mo = new Phonon::MediaObject; + mapMediaObjects[obj->getName()].mo = Phonon::createPlayer(Phonon::NotificationCategory); + mapMediaObjects[obj->getName()].ms = new QList; + mapMediaObjects[obj->getName()].mo->clear(); + } + +// notify->parseNotifyMessage(); +// foreach(QString item, notify->getNotifyMessageList()) +// { +// mapMediaObjects[obj->getName()].ms->clear(); +// mapMediaObjects[obj->getName()].ms->append(Phonon::MediaSource(item)); +// } + + //mapMediaObjects[obj->getName()].ms = lstMediaSource.last(); + } else { + std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl; + } + } +} + +void SoundNotifyPlugin::playNotification(UAVObject *object) +{ + UAVObjectField* field; + double threshold; + QString direction; + QString fieldName; + bool play = false; + NotifyPluginConfiguration* notification; + + foreach(notification, lstNotifications) { + if(object->getName()==notification->getDataObject()) { + fieldName = notification->getObjectField(); + field = object->getField(fieldName); + threshold = notification->getSpinBoxValue(); + direction = notification->getValue(); + } + + if (field) { + double value = field->getDouble(); + //qDebug() << fieldName << " - value - " << value; + + switch(direction[0].toAscii()) + { + case 'E': + if(value==threshold) + play = true; + break; + case 'G': + if(value>threshold) + play = true; + break; + case 'L': + if(valuegetName()].mo->state()==Phonon::PausedState) || + (mapMediaObjects[object->getName()].mo->state()==Phonon::StoppedState)) + { + qDebug() << fieldName << " - value - " << value; + mapMediaObjects[object->getName()].mo->clear(); + mapMediaObjects[object->getName()].ms->clear(); + notification->parseNotifyMessage(); + foreach(QString item, notification->getNotifyMessageList()) + mapMediaObjects[object->getName()].ms->append(Phonon::MediaSource(item)); + mapMediaObjects[object->getName()].mo->setQueue(*mapMediaObjects[object->getName()].ms); + mapMediaObjects[object->getName()].mo->play(); + if(notification->getRepeatFlag()=="Once") + lstNotifications.removeOne(notification); + break; + } + } + } + } +} + +Q_EXPORT_PLUGIN(SoundNotifyPlugin) diff --git a/ground/src/plugins/notify/notifyplugin.h b/ground/src/plugins/notify/notifyplugin.h index 12733538b..579b4b0bd 100644 --- a/ground/src/plugins/notify/notifyplugin.h +++ b/ground/src/plugins/notify/notifyplugin.h @@ -1,12 +1,11 @@ /** ****************************************************************************** * - * @file donothingplugin.h + * @file notifyplugin.h * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * @brief * @see The GNU Public License (GPL) Version 3 - * @defgroup donothingplugin + * @defgroup notifyplugin * @{ * *****************************************************************************/ @@ -37,6 +36,11 @@ class NotifyPluginOptionsPage; class NotifyPluginConfiguration; +typedef struct { + Phonon::MediaObject* mo; + QList* ms; +} PhononObject, *pPhononObject; + class SoundNotifyPlugin : public ExtensionSystem::IPlugin { Q_OBJECT @@ -60,7 +64,9 @@ private: bool enableSound; QList< QList* > lstMediaSource; QStringList mediaSource; - QMap mapMediaObjects; + //QMap mapMediaObjects; + QMap mapMediaObjects; + QSettings* settings; QList lstNotifiedUAVObjects; @@ -68,7 +74,7 @@ private: QList lstNotifications; QString m_field; - NotifyPluginConfiguration *notify; + NotifyPluginOptionsPage *mop; private slots: diff --git a/ground/src/plugins/notify/notifypluginconfiguration.cpp b/ground/src/plugins/notify/notifypluginconfiguration.cpp index b30316c00..589f3acc4 100644 --- a/ground/src/plugins/notify/notifypluginconfiguration.cpp +++ b/ground/src/plugins/notify/notifypluginconfiguration.cpp @@ -1,11 +1,11 @@ /** ****************************************************************************** * - * @file NotifyPluginConfiguration.cpp + * @file notifyPluginConfiguration.cpp * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Airspeed Plugin Gadget configuration + * @brief Notify Plugin configuration * @see The GNU Public License (GPL) Version 3 - * @defgroup Airspeed + * @defgroup notifyplugin * @{ * *****************************************************************************/ @@ -39,7 +39,8 @@ NotifyPluginConfiguration::NotifyPluginConfiguration(QObject *parent) : sound1(""), sound2(""), sayOrder("Never"), - spinBoxValue(0) + spinBoxValue(0), + repeatString("Continue") { } @@ -56,7 +57,7 @@ void NotifyPluginConfiguration::saveState(QSettings* settings) const settings->setValue(QLatin1String("Sound1"), getSound1()); settings->setValue(QLatin1String("Sound2"), getSound2()); settings->setValue(QLatin1String("SayOrder"), getSayOrder()); - + settings->setValue(QLatin1String("Repeat"), getRepeatFlag()); } void NotifyPluginConfiguration::restoreState(QSettings* settings) @@ -71,6 +72,7 @@ void NotifyPluginConfiguration::restoreState(QSettings* settings) setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString()); setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString()); setSpinBoxValue(settings->value(QLatin1String("ValueSpinBox"), tr("")).toDouble()); + setRepeatFlag(settings->value(QLatin1String("Repeat"), tr("")).toString()); } @@ -136,11 +138,11 @@ QString NotifyPluginConfiguration::parseNotifyMessage() if((numberParts.at(0).size()==1) || (numberParts.at(0).toInt()<20)) { - if(numberParts.at(0)!="0") + //if(numberParts.at(0)!="0") numberFiles.append(numberParts.at(0)); } else { int i=0; - if(numberParts.at(0).right(2).toInt()<20) { + 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 @@ -165,10 +167,13 @@ QString NotifyPluginConfiguration::parseNotifyMessage() if(numberParts.size()>1) { numberFiles.append("point"); - if((numberParts.at(1).size()==1) || (numberParts.at(1).toInt()<20)) + if((numberParts.at(1).size()==1) /*|| (numberParts.at(1).toInt()<20)*/) numberFiles.append(numberParts.at(1)); else { - numberFiles.append(numberParts.at(1).left(1)+'0'); + 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)); } } diff --git a/ground/src/plugins/notify/notifypluginconfiguration.h b/ground/src/plugins/notify/notifypluginconfiguration.h index 1d26f1398..96bf40b9f 100644 --- a/ground/src/plugins/notify/notifypluginconfiguration.h +++ b/ground/src/plugins/notify/notifypluginconfiguration.h @@ -1,11 +1,11 @@ /** ****************************************************************************** * - * @file NotifyPluginConfiguration.h + * @file notifypluginconfiguration.h * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Airspeed Plugin Gadget configuration + * @brief Notify Plugin configuration header * @see The GNU Public License (GPL) Version 3 - * @defgroup Airspeed + * @defgroup notifyplugin * @{ * *****************************************************************************/ @@ -71,6 +71,8 @@ public: QStringList getNotifyMessageList() const { return notifyMessageList; } void setNotifyMessageList(QStringList text) { notifyMessageList = text; } + QString getRepeatFlag() const { return repeatString; } + void setRepeatFlag(QString value) { repeatString = value; } void saveState(QSettings* settings) const; void restoreState(QSettings* settings); @@ -88,6 +90,7 @@ private: QString sound2; QString sayOrder; double spinBoxValue; + QString repeatString; }; diff --git a/ground/src/plugins/notify/notifypluginfactory.cpp b/ground/src/plugins/notify/notifypluginfactory.cpp index 92fe082c6..4459cbd1c 100644 --- a/ground/src/plugins/notify/notifypluginfactory.cpp +++ b/ground/src/plugins/notify/notifypluginfactory.cpp @@ -2,10 +2,10 @@ ****************************************************************************** * * @file notifypluginfactory.cpp - * @author David "Buzz" Carlson Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @brief * @see The GNU Public License (GPL) Version 3 - * @defgroup airspeed + * @defgroup notifyplugin * @{ * *****************************************************************************/ diff --git a/ground/src/plugins/notify/notifypluginfactory.h b/ground/src/plugins/notify/notifypluginfactory.h index 6948132f1..18e681cdd 100644 --- a/ground/src/plugins/notify/notifypluginfactory.h +++ b/ground/src/plugins/notify/notifypluginfactory.h @@ -2,10 +2,10 @@ ****************************************************************************** * * @file notifypluginfactory.h - * @author David "Buzz" Carlson Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @brief * @see The GNU Public License (GPL) Version 3 - * @defgroup airspeed + * @defgroup notifyplugin * @{ * *****************************************************************************/ diff --git a/ground/src/plugins/notify/notifyplugingadget.h b/ground/src/plugins/notify/notifyplugingadget.h index b3e2a872b..6edfa950d 100644 --- a/ground/src/plugins/notify/notifyplugingadget.h +++ b/ground/src/plugins/notify/notifyplugingadget.h @@ -1,11 +1,11 @@ /** ****************************************************************************** * - * @file NotifyPlugingadget.h - * @author David "Buzz" Carlson Copyright (C) 2010. + * @file notifyplugingadget.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @brief * @see The GNU Public License (GPL) Version 3 - * @defgroup NotifyPlugin + * @defgroup notifyplugin * @{ * *****************************************************************************/ diff --git a/ground/src/plugins/notify/notifypluginoptionspage.cpp b/ground/src/plugins/notify/notifypluginoptionspage.cpp index ff2fcdee1..78c668008 100644 --- a/ground/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/src/plugins/notify/notifypluginoptionspage.cpp @@ -3,9 +3,9 @@ * * @file notifypluginoptionspage.cpp * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Sound Notify Plugin options page + * @brief Notify Plugin options page * @see The GNU Public License (GPL) Version 3 - * @defgroup Airspeed + * @defgroup notifyplugin * @{ * *****************************************************************************/ @@ -40,7 +40,7 @@ #include #include "notifyplugin.h" - +#include "notifyitemdelegate.h" NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotifyPluginConfiguration *config,*/ QObject *parent) : IOptionsPage(parent), @@ -61,37 +61,34 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) QWidget *optionsPageWidget = new QWidget; //main layout options_page->setupUi(optionsPageWidget); + delegateItems.clear(); + delegateItems << "Continue" << "Once"; options_page->chkEnableSound->setChecked(owner->getEnableSound()); options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); +// connect(options_page->tableNotifications->model(),SIGNAL(rowsInserted ( const QModelIndex & , int , int )),this, +// SLOT(showPersistentComboBox ( const QModelIndex & , int , int ))); +// connect(options_page->tableNotifications->model(),SIGNAL(dataChanged ( const QModelIndex & , const QModelIndex & )),this, +// SLOT(showPersistentComboBox2( const QModelIndex & , const QModelIndex & ))); + + options_page->tableNotifications->setRowCount(0); + options_page->tableNotifications->setItemDelegate(new NotifyItemDelegate(delegateItems,options_page->tableNotifications)); + + QStringList labels; + labels << "Name" << "Repeats"; + options_page->tableNotifications->setHorizontalHeaderLabels(labels); privListNotifications.clear(); listSoundFiles.clear(); settings = Core::ICore::instance()->settings(); settings->beginGroup(QLatin1String("NotifyPlugin")); - int size = settings->beginReadArray("listNotifies"); - for (int i = 0; i < size; ++i) { - settings->setArrayIndex(i); - notify = new NotifyPluginConfiguration; - notify->restoreState(settings); - privListNotifications.append(notify); - } - settings->endArray(); - - settings->beginReadArray("Current"); - settings->setArrayIndex(0); - notify = new NotifyPluginConfiguration; - notify->restoreState(settings); - settings->endArray(); - options_page->chkEnableSound->setChecked(settings->value(QLatin1String("EnableSound"),0).toBool()); - settings->endGroup(); - - // Fills the combo boxes for the UAVObjects ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); objManager = pm->getObject(); + + // Fills the combo boxes for the UAVObjects QList< QList > objList = objManager->getDataObjects(); foreach (QList list, objList) { foreach (UAVDataObject* obj, list) { @@ -112,9 +109,23 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); connect(this, SIGNAL(updateNotifications()), owner, SLOT(connectNotifications())); - //connect(options_page->chkEnableSound, SIGNAL(stateChanged(int)), this, SLOT(enableSound(int))); + int size = settings->beginReadArray("listNotifies"); + for (int i = 0; i < size; ++i) { + settings->setArrayIndex(i); + NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; + notification->restoreState(settings); + privListNotifications.append(notification); + } + settings->endArray(); - updateConfigView(notify); + settings->beginReadArray("Current"); + settings->setArrayIndex(0); + NotifyPluginConfiguration notification; + notification.restoreState(settings); + updateConfigView(¬ification); + settings->endArray(); + options_page->chkEnableSound->setChecked(settings->value(QLatin1String("EnableSound"),0).toBool()); + settings->endGroup(); foreach(NotifyPluginConfiguration* notification,privListNotifications) { @@ -122,7 +133,13 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) options_page->tableNotifications->setItem (options_page->tableNotifications->rowCount()-1,0, new QTableWidgetItem(notification->parseNotifyMessage())); + QString str = notification->getRepeatFlag(); + options_page->tableNotifications->setItem (options_page->tableNotifications->rowCount()-1,1, + new QTableWidgetItem(str)); + + } + options_page->buttonModify->setEnabled(false); options_page->buttonDelete->setEnabled(false); options_page->buttonPlayNotification->setEnabled(false); @@ -143,17 +160,38 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) return optionsPageWidget; } -void NotifyPluginOptionsPage::getOptionsPageValues() +void NotifyPluginOptionsPage::showPersistentComboBox( const QModelIndex & parent, int start, int end ) { - notify->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); - notify->setCurrentLanguage(options_page->SoundCollectionList->currentText()); - notify->setDataObject(options_page->UAVObject->currentText()); - notify->setObjectField(options_page->UAVObjectField->currentText()); - notify->setSound1(options_page->Sound1->currentText()); - notify->setSound2(options_page->Sound2->currentText()); - notify->setSayOrder(options_page->SayOrder->currentText()); - notify->setValue(options_page->Value->currentText()); - notify->setSpinBoxValue(options_page->ValueSpinBox->value()); +// 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) +{ + 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->setSayOrder(options_page->SayOrder->currentText()); + notification->setValue(options_page->Value->currentText()); + notification->setSpinBoxValue(options_page->ValueSpinBox->value()); + if(options_page->tableNotifications->currentRow()>-1) + { + qDebug() << "delegate value:" << options_page->tableNotifications->item(options_page->tableNotifications->currentRow(),1)->data(Qt::EditRole); + notification->setRepeatFlag(options_page->tableNotifications->item(options_page->tableNotifications->currentRow(),1)->data(Qt::EditRole).toString()); + } } //////////////////////////////////////////// @@ -164,13 +202,15 @@ void NotifyPluginOptionsPage::getOptionsPageValues() //////////////////////////////////////////// void NotifyPluginOptionsPage::apply() { + NotifyPluginConfiguration notification; + settings->beginGroup(QLatin1String("NotifyPlugin")); - getOptionsPageValues(); + getOptionsPageValues(¬ification); settings->beginWriteArray("Current"); settings->setArrayIndex(0); - notify->saveState(settings); + notification.saveState(settings); settings->endArray(); //settings->remove("listNotifies"); @@ -184,13 +224,13 @@ void NotifyPluginOptionsPage::apply() settings->setArrayIndex(i); privListNotifications.at(i)->saveState(settings); } - owner->setListNotifications(privListNotifications); settings->endArray(); - owner->setEnableSound(options_page->chkEnableSound->isChecked()); settings->setValue(QLatin1String("EnableSound"), options_page->chkEnableSound->isChecked()); settings->endGroup(); - //emit updateNotifications(); + owner->setEnableSound(options_page->chkEnableSound->isChecked()); + owner->setListNotifications(privListNotifications); + emit updateNotifications(); } void NotifyPluginOptionsPage::finish() @@ -252,31 +292,43 @@ void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon:: { if(sender()==sound1) { - if(newstate == Phonon::PausedState) + if(newstate == Phonon::PausedState) { options_page->buttonTestSound1->setText("Play"); + options_page->buttonTestSound1->setIcon(QPixmap(":/notify/images/play.png")); + } else - if(newstate == Phonon::PlayingState) + if(newstate == Phonon::PlayingState) { options_page->buttonTestSound1->setText("Stop"); + options_page->buttonTestSound1->setIcon(QPixmap(":/notify/images/stop.png")); + } } else { if(sender()==sound2) { - if(newstate == Phonon::PausedState) + if(newstate == Phonon::PausedState) { options_page->buttonTestSound2->setText("Play"); + options_page->buttonTestSound2->setIcon(QPixmap(":/notify/images/play.png")); + } else - if(newstate == Phonon::PlayingState) + if(newstate == Phonon::PlayingState) { options_page->buttonTestSound2->setText("Stop"); + options_page->buttonTestSound2->setIcon(QPixmap(":/notify/images/stop.png")); + } } else { if(sender()==notifySound) { - if(newstate == Phonon::PausedState) + if(newstate == Phonon::PausedState){ options_page->buttonPlayNotification->setText("Play"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); + } else - if(newstate == Phonon::PlayingState) + if(newstate == Phonon::PlayingState) { options_page->buttonPlayNotification->setText("Stop"); + options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); + } } } } @@ -318,11 +370,12 @@ void NotifyPluginOptionsPage::on_buttonTestSound2_clicked() void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked() { QList messageNotify; + NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; //getOptionsPageValues(); if(options_page->tableNotifications->currentRow()==-1) return; - notify = privListNotifications.at(options_page->tableNotifications->currentRow()); - notify->parseNotifyMessage(); - QStringList stringList = notify->getNotifyMessageList(); + notification = privListNotifications.at(options_page->tableNotifications->currentRow()); + notification->parseNotifyMessage(); + QStringList stringList = notification->getNotifyMessageList(); foreach(QString item, stringList) messageNotify.append(Phonon::MediaSource(item)); notifySound->clear(); @@ -352,8 +405,14 @@ void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state) void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notification) { - - options_page->SoundDirectoryPathChooser->setPath(notification->getSoundCollectionPath()); + QString path = notification->getSoundCollectionPath(); + if(path=="") + { + //QDir dir = QDir::currentPath(); + //path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds"; + path = "../share/sounds"; + } + options_page->SoundDirectoryPathChooser->setPath(path); if(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())!=-1){ options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); @@ -368,7 +427,8 @@ void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notifi // Now load the object field values: options_page->UAVObjectField->clear(); - UAVDataObject* obj = dynamic_cast( objManager->getObject(notification->getDataObject()/*objList.at(0).at(0)->getName()*/) ); + 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) { @@ -393,7 +453,7 @@ void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notifi //options_page->Sound1->setCurrentIndex(-1); } - if(options_page->Sound2->findText(notification->getSound2())!=-1){ + if(options_page->Sound2->findText(notification->getSound2())!=-1) { options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); } else @@ -405,11 +465,12 @@ void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notifi // don't show item if it wasn't find in stored location //options_page->Sound2->setCurrentIndex(-1); } - if(options_page->Value->findText(notification->getValue())!=-1){ + + if(options_page->Value->findText(notification->getValue())!=-1) { options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue())); } - if(options_page->SayOrder->findText(notification->getSayOrder())!=-1){ + if(options_page->SayOrder->findText(notification->getSayOrder())!=-1) { options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder())); } options_page->ValueSpinBox->setValue(notification->getSpinBoxValue()); @@ -417,12 +478,10 @@ void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notifi void NotifyPluginOptionsPage::on_tableNotification_changeSelection() { - QTableWidgetItem * item = options_page->tableNotifications->currentItem(); - //qDebug() + QTableWidgetItem * item = options_page->tableNotifications->item(options_page->tableNotifications->currentRow(),0); + if(!item) return; -// if(notify) -// delete notify; - //notify = ); + updateConfigView(privListNotifications.at(item->row())); options_page->buttonModify->setEnabled(item->isSelected()); options_page->buttonDelete->setEnabled(item->isSelected()); @@ -431,6 +490,8 @@ void NotifyPluginOptionsPage::on_tableNotification_changeSelection() void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() { + NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; + if(options_page->SoundDirectoryPathChooser->path()=="") { QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); @@ -440,31 +501,31 @@ void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() return; } - notify->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); - notify->setCurrentLanguage(options_page->SoundCollectionList->currentText()); - notify->setDataObject(options_page->UAVObject->currentText()); - notify->setObjectField(options_page->UAVObjectField->currentText()); - notify->setValue(options_page->Value->currentText()); - notify->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()!="") - notify->setSound1(options_page->Sound1->currentText()); + notification->setSound1(options_page->Sound1->currentText()); - notify->setSound2(options_page->Sound2->currentText()); + notification->setSound2(options_page->Sound2->currentText()); if((options_page->Sound2->currentText()=="")&&(options_page->SayOrder->currentText()=="After second")) return; else - notify->setSayOrder(options_page->SayOrder->currentText()); + notification->setSayOrder(options_page->SayOrder->currentText()); int row = options_page->tableNotifications->rowCount(); options_page->tableNotifications->setRowCount(row+1); row = options_page->tableNotifications->rowCount(); - options_page->tableNotifications->setItem (row-1,0, - new QTableWidgetItem(notify->parseNotifyMessage())); + options_page->tableNotifications->setItem (row-1,0,new QTableWidgetItem(notification->parseNotifyMessage())); + options_page->tableNotifications->setItem (row-1,1,new QTableWidgetItem(delegateItems.first())); + //options_page->tableNotifications->openPersistentEditor(options_page->tableNotifications->item(row-1,1)); - privListNotifications.append(notify); - notify = new NotifyPluginConfiguration; + privListNotifications.append(notification); } @@ -495,10 +556,14 @@ void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked() void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked() { - QTableWidgetItem * item = options_page->tableNotifications->currentItem(); + NotifyPluginConfiguration* notification = new NotifyPluginConfiguration; + //NotifyPluginConfiguration notification; + + QTableWidgetItem * item = options_page->tableNotifications->item(options_page->tableNotifications->currentRow(),0); if(!item) return; - notify = privListNotifications.at(item->row()); - getOptionsPageValues(); - item->setText(notify->parseNotifyMessage()); + //notify = privListNotifications.at(item->row()); // ??? + getOptionsPageValues(notification); + privListNotifications.replace(item->row(),notification); + item->setText(notification->parseNotifyMessage()); } diff --git a/ground/src/plugins/notify/notifypluginoptionspage.h b/ground/src/plugins/notify/notifypluginoptionspage.h index 63ceeb4b2..3d9f98ea2 100644 --- a/ground/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/src/plugins/notify/notifypluginoptionspage.h @@ -3,9 +3,9 @@ * * @file notifypluginoptionspage.h * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Airspeed Plugin Gadget options page + * @brief Notify Plugin options page header * @see The GNU Public License (GPL) Version 3 - * @defgroup SoundNotify + * @defgroup notify * @{ * *****************************************************************************/ @@ -68,7 +68,7 @@ public: void restoreFromSettings(); void updateConfigView(NotifyPluginConfiguration* notification); - void getOptionsPageValues(); + void getOptionsPageValues(NotifyPluginConfiguration* notification); private: UAVObjectManager *objManager; @@ -82,16 +82,20 @@ private: Phonon::MediaObject *sound2; Phonon::MediaObject *notifySound; Phonon::AudioOutput *audioOutput; + QStringList delegateItems; QList privListNotifications; Ui::NotifyPluginOptionsPage *options_page; - NotifyPluginConfiguration *notify; + //NotifyPluginConfiguration *notify; signals: void updateNotifications(); 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(); diff --git a/ground/src/plugins/notify/notifypluginoptionspage.ui b/ground/src/plugins/notify/notifypluginoptionspage.ui index 5f2a193c4..188569ccf 100644 --- a/ground/src/plugins/notify/notifypluginoptionspage.ui +++ b/ground/src/plugins/notify/notifypluginoptionspage.ui @@ -44,6 +44,10 @@ Play + + + :/notify/images/play.png:/notify/images/play.png + @@ -162,6 +166,10 @@ Play + + + :/notify/images/play.png:/notify/images/play.png + @@ -288,22 +296,22 @@ p, li { white-space: pre-wrap; } - QAbstractItemView::NoEditTriggers + QAbstractItemView::DoubleClicked QAbstractItemView::SelectRows - 1 + 2 - false + true - 300 + 200 - 200 + 100 true @@ -315,6 +323,7 @@ p, li { white-space: pre-wrap; } true + @@ -322,7 +331,7 @@ p, li { white-space: pre-wrap; } 10 180 481 - 25 + 26 @@ -351,6 +360,10 @@ p, li { white-space: pre-wrap; } Play + + + :/notify/images/play.png:/notify/images/play.png + @@ -384,6 +397,10 @@ p, li { white-space: pre-wrap; } Add + + + :/notify/images/add.png:/notify/images/add.png + @@ -391,6 +408,10 @@ p, li { white-space: pre-wrap; } Modify + + + :/notify/images/modify.png:/notify/images/modify.png + @@ -398,6 +419,10 @@ p, li { white-space: pre-wrap; } Delete + + + :/utils/images/removesubmitfield.png:/utils/images/removesubmitfield.png + @@ -471,7 +496,10 @@ p, li { white-space: pre-wrap; } 1 - + + + + addNewNotification() diff --git a/ground/src/plugins/notify/res.qrc b/ground/src/plugins/notify/res.qrc new file mode 100644 index 000000000..63579df21 --- /dev/null +++ b/ground/src/plugins/notify/res.qrc @@ -0,0 +1,10 @@ + + + images/modify.png + images/play.png + images/play2.png + images/add.png + images/delete.png + images/stop.png + +