1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Latest update from Daniel for the Notify Plugin

Please help test it, all sound files are in SVN as well.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@975 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
dankers 2010-07-01 13:23:15 +00:00 committed by dankers
parent 6f06d0a69a
commit 6f6a8e50ee
22 changed files with 717 additions and 628 deletions

View File

@ -1,4 +1,4 @@
<plugin name="NotifyPlugin" version="0.0.1" compatVersion="1.0.0">
<plugin name="NotifyPlugin" version="1.0.0" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 Daniel Godin</copyright>
<license>The GNU Public License (GPL) Version 3</license>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 832 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -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

View File

@ -1,343 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NotifyGadgetOptionsPage</class>
<widget class="QWidget" name="NotifyGadgetOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>400</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<width>351</width>
<height>171</height>
</rect>
</property>
<property name="title">
<string>Current Notifications</string>
</property>
<widget class="QTableView" name="CurrentActions">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>331</width>
<height>111</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Segoe UI'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Lists the notifactions already configured. Clicking on an item enables it to be modified. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>9</x>
<y>140</y>
<width>331</width>
<height>25</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Enable Sounds</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>138</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>358</width>
<height>177</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Sound Collection: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox">
<property name="minimumSize">
<size>
<width>147</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;Select the sound collection&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>28</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="loadFile">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;Locate the base directory of the Sound Collections&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Locate...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Object:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="uavObject1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Field:</string>
</property>
</widget>
</item>
<item row="0" column="3" colspan="3">
<widget class="QComboBox" name="objectField1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Value is:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="4">
<widget class="QComboBox" name="Value">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Equal to</string>
</property>
</item>
<item>
<property name="text">
<string>Greater than</string>
</property>
</item>
<item>
<property name="text">
<string>Less than</string>
</property>
</item>
</widget>
</item>
<item row="1" column="5">
<widget class="QDoubleSpinBox" name="doubleSpinBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Sound 1:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QComboBox" name="Sound">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="4" colspan="2">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Sound 2:</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QComboBox" name="Sound_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="4" colspan="2">
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Say Value: </string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBox_2">
<property name="toolTip">
<string>Select if the value of the object should be spoken and if so, either before the configured sound or after it.</string>
</property>
<item>
<property name="text">
<string>Never</string>
</property>
</item>
<item>
<property name="text">
<string>Before Snd 1</string>
</property>
</item>
<item>
<property name="text">
<string>After Snd 1</string>
</property>
</item>
<item>
<property name="text">
<string>After Snd 2</string>
</property>
</item>
</widget>
</item>
<item row="4" column="2" colspan="2">
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Modify</string>
</property>
</widget>
</item>
<item row="4" column="4" colspan="2">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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 <QtGui>
//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<QLabel*>(sender());
// emit commitData(editor);
// emit closeEditor(editor);
// }
// void RepeatCounterDelegate::setEditorData(QWidget *editor,
// const QModelIndex &index) const
// {
// QLabel* edit = qobject_cast<QLabel*>(editor);
// if (edit) {
// edit->setText(index.model()->data(index, Qt::EditRole).toString());
// } else {
// QSpinBox* spinBox = static_cast<QSpinBox*>(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<QLabel*>(editor);
// if (edit) {
// model->setData(index, edit->text());
// } else {
// QSpinBox* spinBox = static_cast<QSpinBox*>(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<QTableWidgetItem *>(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<QLineEdit *>(sender());
if (editor)
{
emit commitData(editor);
emit closeEditor(editor);
}
else
{
QComboBox* editor = qobject_cast<QComboBox*>(sender());
if (editor)
{
emit commitData(editor);
emit closeEditor(editor);
}
}
}
void NotifyItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
if (edit) {
edit->setText(index.model()->data(index, Qt::EditRole).toString());
} else {
QComboBox * repeatEditor = qobject_cast<QComboBox *>(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<QLineEdit *>(editor);
if (edit) {
model->setData(index, edit->text());
} else {
QComboBox * repeatEditor = qobject_cast<QComboBox *>(editor);
if (repeatEditor) {
model->setData(index, repeatEditor->currentText());
// emit commitData(repeatEditor);
// emit closeEditor(repeatEditor);
}
}
}
void NotifyItemDelegate::selectRow(const QString & text)
{
//QList<QTableWidgetItem *> list = ((QTableWidget*)(sender()->parent()))->findItems(text,Qt::MatchExactly);
QComboBox* combo = qobject_cast<QComboBox*>(sender());
QTableWidget* table = new QTableWidget;
table = (QTableWidget*)(combo->parent());
qDebug()<<table->columnCount();
qDebug()<<table->rowCount();
qDebug()<<table->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;
// }

View File

@ -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 <QItemDelegate>
#include <QComboBox>
//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

View File

@ -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 <coreplugin/icore.h>
#include <QDebug>
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
#include <iostream>
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<UAVObjectManager>();
QList<Phonon::MediaObject*> 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<UAVDataObject*>( 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<Phonon::MediaSource>);
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()<threshold)
play = true;
break;
}
if(play)
{
if((mapMediaObjects[object->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 <coreplugin/icore.h>
#include <QDebug>
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
#include <iostream>
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<UAVObjectManager>();
lstNotifiedUAVObjects.clear();
// QList<Phonon::MediaObject*> 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<UAVDataObject*>( 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<Phonon::MediaSource>);
QMap<QString, PhononObject>::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<Phonon::MediaSource>;
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(value<threshold)
play = true;
break;
}
if(play)
{
play = false;
if((mapMediaObjects[object->getName()].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)

View File

@ -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<Phonon::MediaSource>* ms;
} PhononObject, *pPhononObject;
class SoundNotifyPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
@ -60,7 +64,9 @@ private:
bool enableSound;
QList< QList<Phonon::MediaSource>* > lstMediaSource;
QStringList mediaSource;
QMap<QString, Phonon::MediaObject*> mapMediaObjects;
//QMap<QString, Phonon::MediaObject*> mapMediaObjects;
QMap<QString, PhononObject> mapMediaObjects;
QSettings* settings;
QList<UAVDataObject*> lstNotifiedUAVObjects;
@ -68,7 +74,7 @@ private:
QList<NotifyPluginConfiguration*> lstNotifications;
QString m_field;
NotifyPluginConfiguration *notify;
NotifyPluginOptionsPage *mop;
private slots:

View File

@ -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));
}
}

View File

@ -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;
};

View File

@ -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
* @{
*
*****************************************************************************/

View File

@ -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
* @{
*
*****************************************************************************/

View File

@ -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
* @{
*
*****************************************************************************/

View File

@ -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 <QBuffer>
#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<UAVObjectManager>();
// Fills the combo boxes for the UAVObjects
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> 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(&notification);
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; i<end+1; i++) {
// options_page->tableNotifications->openPersistentEditor(options_page->tableNotifications->item(i,1));
// }
}
void NotifyPluginOptionsPage::showPersistentComboBox2( const QModelIndex & topLeft, const QModelIndex & bottomRight )
{
//for (QModelIndex i=topLeft; i<bottomRight+1; i++)
{
options_page->tableNotifications->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(&notification);
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 <Phonon::MediaSource> 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<UAVDataObject*>( objManager->getObject(notification->getDataObject()/*objList.at(0).at(0)->getName()*/) );
QString uavDataObject = notification->getDataObject();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(uavDataObject/*objList.at(0).at(0)->getName()*/) );
if (obj != NULL ) {
QList<UAVObjectField*> 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());
}

View File

@ -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<NotifyPluginConfiguration*> 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();

View File

@ -44,6 +44,10 @@
<property name="text">
<string>Play</string>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/notify/images/play.png</normaloff>:/notify/images/play.png</iconset>
</property>
</widget>
</item>
<item row="2" column="12">
@ -162,6 +166,10 @@
<property name="text">
<string>Play</string>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/notify/images/play.png</normaloff>:/notify/images/play.png</iconset>
</property>
</widget>
</item>
<item row="1" column="10">
@ -288,22 +296,22 @@ p, li { white-space: pre-wrap; }
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::DoubleClicked</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="columnCount">
<number>1</number>
<number>2</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>300</number>
<number>200</number>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>200</number>
<number>100</number>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>true</bool>
@ -315,6 +323,7 @@ p, li { white-space: pre-wrap; }
<bool>true</bool>
</attribute>
<column/>
<column/>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
@ -322,7 +331,7 @@ p, li { white-space: pre-wrap; }
<x>10</x>
<y>180</y>
<width>481</width>
<height>25</height>
<height>26</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
@ -351,6 +360,10 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Play</string>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/notify/images/play.png</normaloff>:/notify/images/play.png</iconset>
</property>
</widget>
</item>
<item>
@ -384,6 +397,10 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Add</string>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/notify/images/add.png</normaloff>:/notify/images/add.png</iconset>
</property>
</widget>
</item>
<item>
@ -391,6 +408,10 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Modify</string>
</property>
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/notify/images/modify.png</normaloff>:/notify/images/modify.png</iconset>
</property>
</widget>
</item>
<item>
@ -398,6 +419,10 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Delete</string>
</property>
<property name="icon">
<iconset resource="../../libs/utils/utils.qrc">
<normaloff>:/utils/images/removesubmitfield.png</normaloff>:/utils/images/removesubmitfield.png</iconset>
</property>
</widget>
</item>
</layout>
@ -471,7 +496,10 @@ p, li { white-space: pre-wrap; }
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../../libs/utils/utils.qrc"/>
<include location="res.qrc"/>
</resources>
<connections/>
<slots>
<slot>addNewNotification()</slot>

View File

@ -0,0 +1,10 @@
<RCC>
<qresource prefix="/notify">
<file>images/modify.png</file>
<file>images/play.png</file>
<file>images/play2.png</file>
<file>images/add.png</file>
<file>images/delete.png</file>
<file>images/stop.png</file>
</qresource>
</RCC>