1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-27 16:54:15 +01:00

Notify plugin, please test this and make sure it works on Linux and Mac.

The idea is you select a UABObject to watch and when it reaches a certain level it will play sounds of your choice.

Can some one people do a code review and make sure it is ok? Testing would be very useful as well.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@795 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
dankers 2010-06-17 11:59:53 +00:00 committed by dankers
parent 8bddb604a1
commit a267d6d9d0
15 changed files with 2112 additions and 0 deletions

View File

@ -0,0 +1,21 @@
TEMPLATE = lib
TARGET = NotifyPlugin
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(notifyplugin_dependencies.pri)
QT += phonon
HEADERS += notifyplugin.h \
notifypluginoptionspage.h \
notifypluginconfiguration.h
SOURCES += notifyplugin.cpp \
notifypluginoptionspage.cpp \
notifypluginconfiguration.cpp
OTHER_FILES += notifyplugin.pluginspec
FORMS += \
notifypluginoptionspage.ui

View File

@ -0,0 +1,343 @@
<?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,166 @@
/**
******************************************************************************
*
* @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 <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>();
// 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)

View File

@ -0,0 +1,74 @@
/**
******************************************************************************
*
* @file donothingplugin.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
* @{
*
*****************************************************************************/
/*
* 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 SOUNDNOTIFYPLUGIN_H
#define SOUNDNOTIFYPLUGIN_H
#include <extensionsystem/iplugin.h>
#include "notifypluginoptionspage.h"
#include <QSettings>
class SoundNotifyPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
SoundNotifyPlugin();
~SoundNotifyPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
QList<NotifyPluginConfiguration*> getListNotifications() { return lstNotifications; }
void setListNotifications(QList<NotifyPluginConfiguration*>& list_notify) { lstNotifications=list_notify; }
bool getEnableSound() const { return enableSound; }
void setEnableSound(bool value) {enableSound = value; }
private:
bool enableSound;
QList< QList<Phonon::MediaSource>* > lstMediaSource;
QStringList mediaSource;
QMap<QString, Phonon::MediaObject*> mapMediaObjects;
QSettings* settings;
QList<UAVDataObject*> lstNotifiedUAVObjects;
QList<NotifyPluginConfiguration*> lstNotifications;
QString m_field;
NotifyPluginConfiguration *notify;
NotifyPluginOptionsPage *mop;
private slots:
void connectNotifications();
void playNotification(UAVObject *object);
};
#endif // SOUNDNOTIFYPLUGIN_H

View File

@ -0,0 +1,11 @@
<plugin name="NotifyPlugin" version="0.0.1" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright>
<license>The GNU Public License (GPL) Version 3</license>
<description>Sound Notify Plugin</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="0.0.1"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1 @@
include(../../plugins/uavobjects/uavobjects.pri)

View File

@ -0,0 +1,143 @@
/**
******************************************************************************
*
* @file NotifyPluginConfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Airspeed Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3
* @defgroup Airspeed
* @{
*
*****************************************************************************/
/*
* 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 "notifypluginconfiguration.h"
#include <QtCore/QDataStream>
#include <QFile>
NotifyPluginConfiguration::NotifyPluginConfiguration(QObject *parent) :
soundCollectionPath(""),
currentLanguage("default"),
dataObject(""),
objectField(""),
value("Equal to"),
sound1(""),
sound2(""),
sayOrder("Never"),
spinBoxValue(0)
{
}
void NotifyPluginConfiguration::saveState(QSettings* settings) const
{
settings->setValue("SoundCollectionPath", getSoundCollectionPath());
settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage());
settings->setValue(QLatin1String("ObjectField"), getObjectField());
settings->setValue(QLatin1String("DataObject"), getDataObject());
settings->setValue(QLatin1String("Value"), getValue());
settings->setValue(QLatin1String("ValueSpinBox"), getSpinBoxValue());
settings->setValue(QLatin1String("Sound1"), getSound1());
settings->setValue(QLatin1String("Sound2"), getSound2());
settings->setValue(QLatin1String("SayOrder"), getSayOrder());
}
void NotifyPluginConfiguration::restoreState(QSettings* settings)
{
//settings = Core::ICore::instance()->settings();
setSoundCollectionPath(settings->value(QLatin1String("SoundCollectionPath"), tr("")).toString());
setCurrentLanguage(settings->value(QLatin1String("CurrentLanguage"), tr("")).toString());
setDataObject(settings->value(QLatin1String("DataObject"), tr("")).toString());
setObjectField(settings->value(QLatin1String("ObjectField"), tr("")).toString());
setValue(settings->value(QLatin1String("Value"), tr("")).toString());
setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString());
setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString());
setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString());
setSpinBoxValue(settings->value(QLatin1String("ValueSpinBox"), tr("")).toDouble());
}
QString NotifyPluginConfiguration::parseNotifyMessage()
{
// tips:
// check of *.wav files exist needed for playing phonon queues;
// if phonon player don't find next file in queue, it buzz
QString str,str1;
str1= getSayOrder();
str = QString("%L1 ").arg(getSpinBoxValue());
int position = 0xFF;
// generate queue of sound files to play
notifyMessageList.clear();
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound1()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound1()+".wav");
else
if(QFile::exists(getSoundCollectionPath()+"\\default\\"+getSound2()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\default\\"+getSound1()+".wav");
if(getSound2()!="")
{
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound2()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound2()+".wav");
else
if(QFile::exists(getSoundCollectionPath()+"\\"+"\\default\\"+"\\"+getSound2()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\default\\"+getSound2()+".wav");
}
switch(str1.at(0).toAscii())
{
case 'N'://NEVER:
str = getSound1()+" "+getSound2();
position = 0xFF;
break;
case 'B'://BEFORE:
str = QString("%L1 ").arg(getSpinBoxValue())+getSound1()+" "+getSound2();
position = 0;
break;
case 'A'://AFTER1:
switch(str1.at(6).toAscii())
{
case 'f':
str = getSound1()+QString(" %L1 ").arg(getSpinBoxValue())+getSound2();
position = 1;
break;
case 's':
str = getSound1()+" "+getSound2()+QString(" %L1").arg(getSpinBoxValue());
position = 2;
break;
}
break;
}
if(position!=0xFF)
{
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+QString("%L1 ").arg(getSpinBoxValue())+".wav"))
notifyMessageList.insert(position,getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+QString("%L1 ").arg(getSpinBoxValue())+".wav");
else
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+QString("%L1 ").arg(getSpinBoxValue())+".wav"))
notifyMessageList.insert(position,getSoundCollectionPath()+"\\default\\"+QString("%L1 ").arg(getSpinBoxValue())+".wav");
}
//str.replace(QString(".wav | .mp3"), QString(""));
return str;
}

View File

@ -0,0 +1,96 @@
/**
******************************************************************************
*
* @file NotifyPluginConfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Airspeed Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3
* @defgroup Airspeed
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef NOTIFYPLUGINCONFIGURATION_H
#define NOTIFYPLUGINCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
#include "qsettings.h"
#include <qstringlist.h>
using namespace Core;
class NotifyPluginConfiguration : public QObject
{
Q_OBJECT
public:
explicit NotifyPluginConfiguration(QObject *parent = 0);
QString getSound1() const { return sound1; }
void setSound1(QString text) {sound1 = text; }
QString getSound2() const { return sound2; }
void setSound2(QString text) {sound2 = text; }
QString getValue() const { return value; }
void setValue(QString text) {value = text; }
QString getSayOrder() const { return sayOrder; }
void setSayOrder(QString text) {sayOrder = text; }
double getSpinBoxValue() const { return spinBoxValue; }
void setSpinBoxValue(double value) {spinBoxValue = value; }
QString getDataObject() const { return dataObject; }
void setDataObject(QString text) {dataObject = text; }
QString getObjectField() const { return objectField; }
void setObjectField(QString text) { objectField = text; }
QString getSoundCollectionPath() const { return soundCollectionPath; }
void setSoundCollectionPath(QString text) { soundCollectionPath = text; }
QString getCurrentLanguage() const { return currentLanguage; }
void setCurrentLanguage(QString text) { currentLanguage = text; }
QStringList getNotifyMessageList() const { return notifyMessageList; }
void setNotifyMessageList(QStringList text) { notifyMessageList = text; }
void saveState(QSettings* settings) const;
void restoreState(QSettings* settings);
QString parseNotifyMessage();
private:
QStringList notifyMessageList;
QString soundCollectionPath;
QString currentLanguage;
QString dataObject;
QString objectField;
QString value;
QString sound1;
QString sound2;
QString sayOrder;
double spinBoxValue;
};
#endif // NOTIFYPLUGINCONFIGURATION_H

View File

@ -0,0 +1,61 @@
/**
******************************************************************************
*
* @file notifypluginfactory.cpp
* @author David "Buzz" Carlson Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup airspeed
* @{
*
*****************************************************************************/
/*
* 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 "notifypluginfactory.h"
//#include "notifypluginwidget.h"
#include "notifyplugin.h"
#include "notifypluginconfiguration.h"
#include "notifypluginoptionspage.h"
#include <coreplugin/iuavgadget.h>
NotifyPluginFactory::NotifyPluginFactory(QObject *parent) :
IUAVGadgetFactory(QString("Notify Plugin"),
tr("Notify Plugin"),
parent)
{
}
NotifyPluginFactory::~NotifyPluginFactory()
{
}
Core::IUAVGadget* NotifyPluginFactory::createGadget(QWidget *parent)
{
// NotifyPluginWidget* gadgetWidget = new NotifyPluginWidget(parent);
return (Core::IUAVGadget*)0;//new NotifyPlugin(QString("NotifyPlugin"), gadgetWidget, parent);
}
IUAVGadgetConfiguration *NotifyPluginFactory::createConfiguration(const QByteArray &state)
{
return new NotifyPluginConfiguration(QString("Notify Plugin"), state);
}
IOptionsPage *NotifyPluginFactory::createOptionsPage(IUAVGadgetConfiguration *config)
{
return new NotifyPluginOptionsPage(qobject_cast<NotifyPluginConfiguration*>(config));
}

View File

@ -0,0 +1,53 @@
/**
******************************************************************************
*
* @file notifypluginfactory.h
* @author David "Buzz" Carlson Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup airspeed
* @{
*
*****************************************************************************/
/*
* 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 NOTIFYPLUGINFACTORY_H
#define NOTIFYPLUGINFACTORY_H
#include <coreplugin/iuavgadgetfactory.h>
namespace Core {
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class NotifyPluginFactory : public IUAVGadgetFactory
{
Q_OBJECT
public:
NotifyPluginFactory(QObject *parent = 0);
~NotifyPluginFactory();
Core::IUAVGadget *createGadget(QWidget *parent);
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
};
#endif // NOTIFYPLUGINFACTORY_H

View File

@ -0,0 +1,56 @@
/**
******************************************************************************
*
* @file NotifyPlugingadget.h
* @author David "Buzz" Carlson 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 NOTIFYPLUGINGADGET_H
#define NOTIFYPLUGINGADGET_H
#include <coreplugin/iuavgadget.h>
//#include "NotifyPlugingadgetwidget.h"
class IUAVGadget;
class QWidget;
class QString;
//class NotifyPluginGadgetWidget;
using namespace Core;
class NotifyPluginGadget : public Core::IUAVGadget
{
Q_OBJECT
public:
NotifyPluginGadget(QString classId, NotifyPluginGadgetWidget *widget, QWidget *parent = 0);
~NotifyPluginGadget();
// QWidget *widget() { return m_widget; }
void loadConfiguration(IUAVGadgetConfiguration* config);
private:
// NotifyPluginGadgetWidget *m_widget;
};
#endif // NOTIFYPLUGINGADGET_H

View File

@ -0,0 +1,497 @@
/**
******************************************************************************
*
* @file notifypluginoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Sound Notify Plugin options page
* @see The GNU Public License (GPL) Version 3
* @defgroup Airspeed
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "notifypluginoptionspage.h"
#include <coreplugin/icore.h>
#include "notifypluginconfiguration.h"
#include "ui_notifypluginoptionspage.h"
#include "extensionsystem/pluginmanager.h"
#include <QFileDialog>
#include <QtAlgorithms>
#include <QStringList>
#include <QtCore/QSettings>
#include <QTableWidget>
#include <QPalette>
#include <QBuffer>
#include "notifyplugin.h"
NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotifyPluginConfiguration *config,*/ QObject *parent) :
IOptionsPage(parent),
owner((SoundNotifyPlugin*)parent),
currentCollectionPath(""),
privListNotifications(((SoundNotifyPlugin*)parent)->getListNotifications())
{
}
//creates options page widget (uses the UI file)
QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
{
options_page = new Ui::NotifyPluginOptionsPage();
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
options_page->setupUi(optionsPageWidget);
options_page->chkEnableSound->setChecked(owner->getEnableSound());
options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory"));
options_page->tableNotifications->setRowCount(0);
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>();
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) {
options_page->UAVObject->addItem(obj->getName());
}
}
connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&)));
connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int)));
connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked()));
connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked()));
connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked()));
connect(options_page->buttonTestSound1, SIGNAL(clicked()), this, SLOT(on_buttonTestSound1_clicked()));
connect(options_page->buttonTestSound2, SIGNAL(clicked()), this, SLOT(on_buttonTestSound2_clicked()));
connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked()));
connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool)));
connect(options_page->tableNotifications, SIGNAL(itemSelectionChanged()), this, SLOT(on_tableNotification_changeSelection()));
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)));
updateConfigView(notify);
foreach(NotifyPluginConfiguration* notification,privListNotifications)
{
options_page->tableNotifications->setRowCount(options_page->tableNotifications->rowCount()+1);
options_page->tableNotifications->setItem (options_page->tableNotifications->rowCount()-1,0,
new QTableWidgetItem(notification->parseNotifyMessage()));
}
options_page->buttonModify->setEnabled(false);
options_page->buttonDelete->setEnabled(false);
sound1 = Phonon::createPlayer(Phonon::NotificationCategory);
sound2 = Phonon::createPlayer(Phonon::NotificationCategory);
notifySound = Phonon::createPlayer(Phonon::NotificationCategory);
// audioOutput = new Phonon::AudioOutput(Phonon::NotificationCategory, this);
// Phonon::createPath(sound1, audioOutput);
// Phonon::createPath(sound2, audioOutput);
// Phonon::createPath(notifySound, audioOutput);
connect(sound1,SIGNAL(stateChanged(Phonon::State,Phonon::State)),SLOT(changeButtonText(Phonon::State,Phonon::State)));
connect(sound2,SIGNAL(stateChanged(Phonon::State,Phonon::State)),SLOT(changeButtonText(Phonon::State,Phonon::State)));
connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)),SLOT(changeButtonText(Phonon::State,Phonon::State)));
return optionsPageWidget;
}
void NotifyPluginOptionsPage::getOptionsPageValues()
{
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());
}
////////////////////////////////////////////
// Called when the user presses apply or OK.
//
// Saves the current values
//
////////////////////////////////////////////
void NotifyPluginOptionsPage::apply()
{
settings->beginGroup(QLatin1String("NotifyPlugin"));
getOptionsPageValues();
settings->beginWriteArray("Current");
settings->setArrayIndex(0);
notify->saveState(settings);
settings->endArray();
//settings->remove("listNotifies");
settings->beginGroup("listNotifies");
settings->remove("");
settings->endGroup();
settings->beginWriteArray("listNotifies");
for (int i = 0; i < options_page->tableNotifications->rowCount(); i++) {
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();
}
void NotifyPluginOptionsPage::finish()
{
delete options_page;
}
//////////////////////////////////////////////////////////////////////////////
// Fills in the <Field> combo box when value is changed in the
// <Object> combo box
//////////////////////////////////////////////////////////////////////////////
void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) {
options_page->UAVObjectField->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->UAVObjectField->addItem(field->getName());
}
}
// locate collection folder on disk
void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path)
{
disconnect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int)));
QDir dirPath(path);
listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
options_page->SoundCollectionList->clear();
options_page->SoundCollectionList->addItems(listDirCollections);
connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int)));
}
void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index)
{
options_page->SoundCollectionList->setCurrentIndex(index);
currentCollectionPath = options_page->SoundDirectoryPathChooser->path() +"\\"+options_page->SoundCollectionList->currentText();
QDir dirPath(currentCollectionPath);
QStringList filters;
filters << "*.mp3" << "*.wav";
dirPath.setNameFilters(filters);
listSoundFiles = dirPath.entryList(filters);
listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), "");
options_page->Sound1->clear();
options_page->Sound2->clear();
options_page->Sound1->addItems(listSoundFiles);
options_page->Sound2->addItems(listSoundFiles);
options_page->Sound2->addItem("");
}
void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate)
{
if(sender()==sound1)
{
if(newstate == Phonon::PausedState)
options_page->buttonTestSound1->setText("Play");
else
if(newstate == Phonon::PlayingState)
options_page->buttonTestSound1->setText("Stop");
}
else
{
if(sender()==sound2)
{
if(newstate == Phonon::PausedState)
options_page->buttonTestSound2->setText("Play");
else
if(newstate == Phonon::PlayingState)
options_page->buttonTestSound2->setText("Stop");
}
else
{
if(sender()==notifySound)
{
if(newstate == Phonon::PausedState)
options_page->buttonPlayNotification->setText("Play");
else
if(newstate == Phonon::PlayingState)
options_page->buttonPlayNotification->setText("Stop");
}
}
}
}
void NotifyPluginOptionsPage::on_buttonTestSound1_clicked()
{
if(options_page->Sound1->currentText()=="") return;
QFile file;
QString currPath = options_page->SoundDirectoryPathChooser->path()+"\\"+
options_page->SoundCollectionList->currentText()+"\\"+options_page->Sound1->currentText()+".wav";
//currPath.replace(QString("\\"), QString("/"));
// file.setFileName(currPath);
// file.open(QIODevice::ReadOnly);
// QDataStream in(&file); // read the data serialized from the file
// QByteArray buf;
// in >> buf;
sound1->setCurrentSource(Phonon::MediaSource(currPath));
sound1->play();
}
void NotifyPluginOptionsPage::on_buttonTestSound2_clicked()
{
if(options_page->Sound2->currentText()=="") return;
QFile file;
QString currPath = options_page->SoundDirectoryPathChooser->path()+"\\"+
options_page->SoundCollectionList->currentText()+"\\"+options_page->Sound2->currentText()+".wav";
//currPath.replace(QString("\\"), QString("/"));
sound2->setCurrentSource(Phonon::MediaSource(currPath));
sound2->play();
}
void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked()
{
QList <Phonon::MediaSource> messageNotify;
//getOptionsPageValues();
notify = privListNotifications.at(options_page->tableNotifications->currentRow());
notify->parseNotifyMessage();
QStringList stringList = notify->getNotifyMessageList();
foreach(QString item, stringList)
messageNotify.append(Phonon::MediaSource(item));
notifySound->clear();
notifySound->setQueue(messageNotify);
notifySound->play();
}
void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state)
{
bool state1 = 1^state;
{
QList<Phonon::Path> listOutputs = sound1->outputPaths();
Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink();
audioOutput->setMuted(state1);
}
{
QList<Phonon::Path> listOutputs = sound2->outputPaths();
Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink();
audioOutput->setMuted(state1);
}
{
QList<Phonon::Path> listOutputs = notifySound->outputPaths();
Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink();
audioOutput->setMuted(state1);
}
}
void NotifyPluginOptionsPage::updateConfigView(NotifyPluginConfiguration* notification)
{
options_page->SoundDirectoryPathChooser->setPath(notification->getSoundCollectionPath());
if(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())!=-1){
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage()));
}
else
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
if(options_page->UAVObject->findText(notification->getDataObject())!=-1){
options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject()));
}
// 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()*/) );
if (obj != NULL ) {
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->UAVObjectField->addItem(field->getName());
}
}
if(options_page->UAVObjectField->findText(notification->getObjectField())!=-1){
options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField()));
}
if(options_page->Sound1->findText(notification->getSound1())!=-1){
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1()));
}
else
{
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1()));
// don't show item if it wasn't find in stored location
//options_page->Sound1->setCurrentIndex(-1);
}
if(options_page->Sound2->findText(notification->getSound2())!=-1){
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2()));
}
else
{
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2()));
// don't show item if it wasn't find in stored location
//options_page->Sound2->setCurrentIndex(-1);
}
if(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){
options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder()));
}
options_page->ValueSpinBox->setValue(notification->getSpinBoxValue());
}
void NotifyPluginOptionsPage::on_tableNotification_changeSelection()
{
QTableWidgetItem * item = options_page->tableNotifications->currentItem();
//qDebug()
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());
}
void NotifyPluginOptionsPage::on_buttonAddNotification_clicked()
{
if(options_page->SoundDirectoryPathChooser->path()=="")
{
QPalette textPalette=options_page->SoundDirectoryPathChooser->palette();
textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red);
options_page->SoundDirectoryPathChooser->setPalette(textPalette);
options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder");
return;
}
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());
if(options_page->Sound1->currentText()!="")
notify->setSound1(options_page->Sound1->currentText());
notify->setSound2(options_page->Sound2->currentText());
if((options_page->Sound2->currentText()=="")&&(options_page->SayOrder->currentText()=="After second"))
return;
else
notify->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()));
privListNotifications.append(notify);
notify = new NotifyPluginConfiguration;
}
void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked()
{
QTableWidgetItem * item = options_page->tableNotifications->currentItem();
int row = item->row();
privListNotifications.removeAt(row);
// if(!privListNotifications.size())
// notify = new NotifyPluginConfiguration;
options_page->tableNotifications->removeRow(row);
if(!options_page->tableNotifications->rowCount())
{
options_page->buttonDelete->setEnabled(false);
options_page->buttonModify->setEnabled(false);
}
}
void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked()
{
QTableWidgetItem * item = options_page->tableNotifications->currentItem();
if(!item) return;
notify = privListNotifications.at(item->row());
getOptionsPageValues();
item->setText(notify->parseNotifyMessage());
}

View File

@ -0,0 +1,110 @@
/**
******************************************************************************
*
* @file notifypluginoptionspage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Airspeed Plugin Gadget options page
* @see The GNU Public License (GPL) Version 3
* @defgroup SoundNotify
* @{
*
*****************************************************************************/
/*
* 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 NOTIFYPLUGINOPTIONSPAGE_H
#define NOTIFYPLUGINOPTIONSPAGE_H
#include "coreplugin/dialogs/ioptionspage.h"
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavobject.h"
#include "QString"
#include <QStringList>
#include <QDebug>
#include <QtCore/QSettings>
#include <phonon>
class NotifyPluginConfiguration;
class SoundNotifyPlugin;
namespace Ui {
class NotifyPluginOptionsPage;
}
using namespace Core;
class NotifyPluginOptionsPage : public IOptionsPage
{
Q_OBJECT
public:
explicit NotifyPluginOptionsPage(/*NotifyPluginConfiguration *config, */QObject *parent = 0);
QString id() const { return QLatin1String("settings"); }
QString trName() const { return tr("settings"); }
QString category() const { return QLatin1String("Notify Plugin");}
QString trCategory() const { return tr("Notify Plugin");}
QWidget *createPage(QWidget *parent);
void apply();
void finish();
void restoreFromSettings();
void updateConfigView(NotifyPluginConfiguration* notification);
void getOptionsPageValues();
private:
UAVObjectManager *objManager;
SoundNotifyPlugin* owner;
QSettings* settings;
QStringList listDirCollections;
QStringList listSoundFiles;
QString currentCollectionPath;
int sizeNotifyList;
Phonon::MediaObject *sound1;
Phonon::MediaObject *sound2;
Phonon::MediaObject *notifySound;
Phonon::AudioOutput *audioOutput;
QList<NotifyPluginConfiguration*> privListNotifications;
Ui::NotifyPluginOptionsPage *options_page;
NotifyPluginConfiguration *notify;
signals:
void updateNotifications();
private slots:
void on_buttonTestSound1_clicked();
void on_buttonTestSound2_clicked();
void on_buttonTestSoundNotification_clicked();
void on_buttonAddNotification_clicked();
void on_buttonDeleteNotification_clicked();
void on_buttonModifyNotification_clicked();
void on_tableNotification_changeSelection();
void on_soundLanguage_indexChanged(int index);
void on_buttonSoundFolder_clicked(const QString& path);
void on_UAVObject_indexChanged(QString val);
void changeButtonText(Phonon::State newstate, Phonon::State oldstate);
void on_chkEnableSound_toggled(bool state);
};
#endif // NOTIFYPLUGINOPTIONSPAGE_H

View File

@ -0,0 +1,473 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NotifyPluginOptionsPage</class>
<widget class="QWidget" name="NotifyPluginOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>589</width>
<height>453</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="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>140</y>
<width>501</width>
<height>71</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="2" colspan="7">
<widget class="QComboBox" name="Sound1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="13">
<widget class="QPushButton" name="buttonTestSound2">
<property name="text">
<string>Play</string>
</property>
</widget>
</item>
<item row="2" column="12">
<widget class="QComboBox" name="Sound2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="7" colspan="3">
<widget class="QDoubleSpinBox" name="ValueSpinBox">
<property name="singleStep">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2" colspan="5">
<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="2" column="1">
<widget class="QLabel" name="labelSound1">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sound1:</string>
</property>
</widget>
</item>
<item row="1" column="12" colspan="2">
<widget class="QComboBox" name="SayOrder">
<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 first</string>
</property>
</item>
<item>
<property name="text">
<string>After first</string>
</property>
</item>
<item>
<property name="text">
<string>After second</string>
</property>
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="labelValue">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Value is</string>
</property>
</widget>
</item>
<item row="1" column="11">
<widget class="QLabel" name="labelSayOrder">
<property name="text">
<string>Say Order</string>
</property>
</widget>
</item>
<item row="2" column="9">
<widget class="QPushButton" name="buttonTestSound1">
<property name="text">
<string>Play</string>
</property>
</widget>
</item>
<item row="1" column="10">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="11">
<widget class="QLabel" name="labelSound2">
<property name="text">
<string>Sound2:</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>501</width>
<height>81</height>
</rect>
</property>
<property name="title">
<string>Sound Collection</string>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>481</width>
<height>51</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="labelLanguage">
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="5">
<widget class="Utils::PathChooser" name="SoundDirectoryPathChooser" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>75</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item row="1" column="1" colspan="4">
<widget class="QComboBox" name="SoundCollectionList">
<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>
</layout>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>220</y>
<width>501</width>
<height>211</height>
</rect>
</property>
<property name="title">
<string>Sound Notifcations</string>
</property>
<widget class="QTableWidget" name="tableNotifications">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>481</width>
<height>151</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>600</width>
<height>16777215</height>
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="columnCount">
<number>1</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>300</number>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>200</number>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>20</number>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>true</bool>
</attribute>
<column/>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<width>481</width>
<height>25</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="chkEnableSound">
<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="buttonPlayNotification">
<property name="text">
<string>Play</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonAdd">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonModify">
<property name="text">
<string>Modify</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonDelete">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>501</width>
<height>31</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelDataOb">
<property name="text">
<string>DataObject</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="UAVObject">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelObjectField">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="UAVObjectField">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>7</x>
<y>130</y>
<width>481</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
<slots>
<slot>addNewNotification()</slot>
</slots>
</ui>

View File

@ -97,6 +97,13 @@ plugin_systemhealth.depends = plugin_coreplugin
plugin_systemhealth.depends = plugin_uavobjects
SUBDIRS += plugin_systemhealth
#Notify Gadget
plugin_notify.subdir = notify
plugin_notify.depends = plugin_coreplugin
plugin_notify.depends = plugin_uavobjects
SUBDIRS += plugin_notify
#Config Gadget
#plugin_config.subdir = config
#plugin_config.depends = plugin_coreplugin