1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

+removed public members in notificationitem; +cosmetic changes; +fixed indentation;

This commit is contained in:
unknown 2011-09-16 18:39:20 +03:00
parent c16e386e63
commit 56e71cd82e
13 changed files with 1493 additions and 918 deletions

View File

@ -28,7 +28,7 @@
#define LKS94PROJECTION_H
#include <QVector>
#include "cmath"
#include "D:\!Work\OpenSource\OpenPilot\OpenPilot\ground\openpilotgcs\src\libs\opmapcontrol\src\internals\pureprojection.h"
#include "D:\!Work\OpenPilot\OpenPilot\ground\openpilotgcs\src\libs\opmapcontrol\src\internals\pureprojection.h"
namespace projections {

View File

@ -40,113 +40,129 @@ using namespace Core;
QString getSound##number() const { return _sound##number; } \
void setSound##number(QString text) { _sound##number = text; } \
// QString getSound2() const { return _sound2; }
// void setSound2(QString text) { _sound2 = text; }
// QString getSound3() const { return _sound3; }
// void setSound3(QString text) { _sound3 = text; }
class NotificationItem : public QObject
{
Q_OBJECT
Q_OBJECT
public:
explicit NotificationItem(QObject *parent = 0);
explicit NotificationItem(QObject *parent = 0);
void copyTo(NotificationItem*) const;
void copyTo(NotificationItem*) const;
DECLARE_SOUND(1)
DECLARE_SOUND(2)
DECLARE_SOUND(3)
DECLARE_SOUND(1)
DECLARE_SOUND(2)
DECLARE_SOUND(3)
QString getValue() const { return _dataValue; }
void setValue(QString text) { _dataValue = text; }
QString getValue() const { return _dataValue; }
void setValue(QString text) { _dataValue = text; }
QString getSayOrder() const { return _sayOrder; }
void setSayOrder(QString text) { _sayOrder = text; }
QString getSayOrder() const { return _sayOrder; }
void setSayOrder(QString text) { _sayOrder = text; }
double getSpinBoxValue() const { return _spinBoxValue; }
void setSpinBoxValue(double value) { _spinBoxValue = value; }
double getSpinBoxValue() const { return _spinBoxValue; }
void setSpinBoxValue(double value) { _spinBoxValue = value; }
QString getDataObject() const { return _dataObject; }
void setDataObject(QString text) { _dataObject = text; }
QString getDataObject() const { return _dataObject; }
void setDataObject(QString text) { _dataObject = text; }
QString getObjectField() const { return _objectField; }
void setObjectField(QString text) { _objectField = text; }
QString getObjectField() const { return _objectField; }
void setObjectField(QString text) { _objectField = text; }
QString getSoundCollectionPath() const { return _soundCollectionPath; }
void setSoundCollectionPath(QString path) { _soundCollectionPath = path; }
QString getSoundCollectionPath() const { return _soundCollectionPath; }
void setSoundCollectionPath(QString path) { _soundCollectionPath = path; }
QString getCurrentLanguage() const { return _currentLanguage; }
void setCurrentLanguage(QString text) { _currentLanguage = text; }
QString getCurrentLanguage() const { return _currentLanguage; }
void setCurrentLanguage(QString text) { _currentLanguage = text; }
QStringList getMessageSequence() const { return _messageSequence; }
void setMessageSequence(QStringList sequence) { _messageSequence = sequence; }
QStringList getMessageSequence() const { return _messageSequence; }
void setMessageSequence(QStringList sequence) { _messageSequence = sequence; }
QString getRepeatFlag() const { return _repeatString; }
void setRepeatFlag(QString value) { _repeatString = value; }
QString getRepeatFlag() const { return _repeatString; }
void setRepeatFlag(QString value) { _repeatString = value; }
bool getRepeatTimeout() const { return _repeatTimeout; }
void setRepeatTimeout(bool value) { _repeatTimeout = value; }
bool getRepeatTimeout() const { return _repeatTimeout; }
void setRepeatTimeout(bool value) { _repeatTimeout = value; }
int getExpireTimeout() const { return _expireTimeout; }
void setExpireTimeout(int value) { _expireTimeout = value; }
int getExpireTimeout() const { return _expireTimeout; }
void setExpireTimeout(int value) { _expireTimeout = value; }
bool getEnableFlag() const { return _enableFlag; }
void setEnableFlag(bool value) { _enableFlag = value; }
bool getEnableFlag() const { return _enableFlag; }
void setEnableFlag(bool value) { _enableFlag = value; }
void saveState(QSettings* settings) const;
void restoreState(QSettings* settings);
QString parseNotifyMessage();
void saveState(QSettings* settings) const;
void restoreState(QSettings* settings);
QTimer* timer;
QTimer* expireTimer;
bool isNowPlaying; //
bool firstStart;
QString parseNotifyMessage();
QTimer* getTimer() const { return _timer; }
void startTimer(int value);
void stopTimer();
void disposeTimer();
QTimer* getExpireTimer() const { return _expireTimer; }
void startExpireTimer();
void stopExpireTimer();
void disposeExpireTimer();
bool isNowPlaying;
bool firstStart;
private:
void checkSoundFilesExisting();
QStringList _messageSequence;
private:
QTimer* _timer;
//! path to folder with sound files
QString _soundCollectionPath;
//! time from putting notification in queue till moment when notification became out-of-date
//! NOTE: each notification has it lifetime, this time setups individually for each notification
//! according to its priority
QTimer* _expireTimer;
//! language in what notifications will be spelled
QString _currentLanguage;
//! one UAV object per one notification
QString _dataObject;
//! one field value change can be assigned to one notification
QString _objectField;
QStringList _messageSequence;
//! poled UAV field value
QString _dataValue;
//! path to folder with sound files
QString _soundCollectionPath;
//! possible sounds(at least one required to play notification)
QString _sound1;
QString _sound2;
QString _sound3;
//! language in what notifications will be spelled
QString _currentLanguage;
//! order in what sounds 1-3 will be played
QString _sayOrder;
//! one UAV object per one notification
QString _dataObject;
double _spinBoxValue;
//! one field value change can be assigned to one notification
QString _objectField;
QString _repeatString;
//! poled UAV field value
QString _dataValue;
//! time when next notification must be fired
bool _repeatTimeout;
//! possible sounds(at least one required to play notification)
QString _sound1;
QString _sound2;
QString _sound3;
//! how often or what periodicaly notification should be played
int _repeatTimerValue;
//! order in what sounds 1-3 will be played
QString _sayOrder;
//! time after event occured till notification became invalid
//! and will be removed from list
int _expireTimeout;
double _spinBoxValue;
//! enables/disables playing of current notification
bool _enableFlag;
QString _repeatString;
//! time when next notification must be fired
bool _repeatTimeout;
//! how often or what periodicaly notification should be played
int _repeatTimerValue;
//! time after event occured till notification became invalid
//! and will be removed from list
int _expireTimeout;
//! enables/disables playing of current notification
bool _enableFlag;
};
Q_DECLARE_METATYPE(NotificationItem*)

View File

@ -25,219 +25,277 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "NotificationItem.h"
#include "notificationitem.h"
#include "notifylogging.h"
#include <QtCore/QDataStream>
#include <QFile>
#include "utils/pathutils.h"
NotificationItem::NotificationItem(QObject *parent) :
QObject(parent),
isNowPlaying(0),
firstStart(1),
_soundCollectionPath(""),
_currentLanguage("default"),
_dataObject(""),
_objectField(""),
_dataValue("Equal to"),
_sound1(""),
_sound2(""),
_sound3(""),
_sayOrder("Never"),
_spinBoxValue(0),
_repeatString("Repeat Instantly"),
_repeatTimeout(true),
_expireTimeout(15)
NotificationItem::NotificationItem(QObject *parent)
: QObject(parent)
, isNowPlaying(0)
, firstStart(true)
, _soundCollectionPath("")
, _currentLanguage("default")
, _dataObject("")
, _objectField("")
, _dataValue("Equal to")
, _sound1("")
, _sound2("")
, _sound3("")
, _sayOrder("Never")
, _spinBoxValue(0)
, _repeatString("Repeat Instantly")
, _repeatTimeout(true)
, _expireTimeout(15)
{
timer = NULL;
expireTimer = NULL;
_timer = NULL;
_expireTimer = NULL;
}
void NotificationItem::copyTo(NotificationItem* that) const
{
that->isNowPlaying = isNowPlaying;
that->firstStart = firstStart;
that->_soundCollectionPath = _soundCollectionPath;
that->_currentLanguage = _currentLanguage;
that->_soundCollectionPath = _soundCollectionPath;
that->_dataObject = _dataObject;
that->_objectField = _objectField;
that->_dataValue = _dataValue;
that->_sound1 = _sound1;
that->_sound2 = _sound2;
that->_sound3 = _sound3;
that->_sayOrder = _sayOrder;
that->_spinBoxValue = _spinBoxValue;
that->_repeatString = _repeatString;
that->_repeatTimeout = _repeatTimeout;
that->_expireTimeout = _expireTimeout;
that->isNowPlaying = isNowPlaying;
that->firstStart = firstStart;
that->_soundCollectionPath = _soundCollectionPath;
that->_currentLanguage = _currentLanguage;
that->_soundCollectionPath = _soundCollectionPath;
that->_dataObject = _dataObject;
that->_objectField = _objectField;
that->_dataValue = _dataValue;
that->_sound1 = _sound1;
that->_sound2 = _sound2;
that->_sound3 = _sound3;
that->_sayOrder = _sayOrder;
that->_spinBoxValue = _spinBoxValue;
that->_repeatString = _repeatString;
that->_repeatTimeout = _repeatTimeout;
that->_expireTimeout = _expireTimeout;
}
void NotificationItem::saveState(QSettings* settings) const
{
settings->setValue("SoundCollectionPath", Utils::PathUtils().RemoveDataPath(getSoundCollectionPath()));
settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage());
settings->setValue(QLatin1String("ObjectField"), getObjectField());
settings->setValue(QLatin1String("DataObject"), getDataObject());
settings->setValue(QLatin1String("Value"), getValue());
settings->setValue(QLatin1String("ValueSpinBox"), getSpinBoxValue());
settings->setValue(QLatin1String("Sound1"), getSound1());
settings->setValue(QLatin1String("Sound2"), getSound2());
settings->setValue(QLatin1String("Sound3"), getSound3());
settings->setValue(QLatin1String("SayOrder"), getSayOrder());
settings->setValue(QLatin1String("Repeat"), getRepeatFlag());
settings->setValue(QLatin1String("ExpireTimeout"), getExpireTimeout());
settings->setValue("SoundCollectionPath", Utils::PathUtils().RemoveDataPath(getSoundCollectionPath()));
settings->setValue(QLatin1String("CurrentLanguage"), getCurrentLanguage());
settings->setValue(QLatin1String("ObjectField"), getObjectField());
settings->setValue(QLatin1String("DataObject"), getDataObject());
settings->setValue(QLatin1String("Value"), getValue());
settings->setValue(QLatin1String("ValueSpinBox"), getSpinBoxValue());
settings->setValue(QLatin1String("Sound1"), getSound1());
settings->setValue(QLatin1String("Sound2"), getSound2());
settings->setValue(QLatin1String("Sound3"), getSound3());
settings->setValue(QLatin1String("SayOrder"), getSayOrder());
settings->setValue(QLatin1String("Repeat"), getRepeatFlag());
settings->setValue(QLatin1String("ExpireTimeout"), getExpireTimeout());
}
void NotificationItem::restoreState(QSettings* settings)
{
//settings = Core::ICore::instance()->settings();
setSoundCollectionPath(Utils::PathUtils().InsertDataPath(settings->value(QLatin1String("SoundCollectionPath"), tr("")).toString()));
setCurrentLanguage(settings->value(QLatin1String("CurrentLanguage"), tr("")).toString());
setDataObject(settings->value(QLatin1String("DataObject"), tr("")).toString());
setObjectField(settings->value(QLatin1String("ObjectField"), tr("")).toString());
setValue(settings->value(QLatin1String("Value"), tr("")).toString());
setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString());
setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString());
setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString());
setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString());
setSpinBoxValue(settings->value(QLatin1String("ValueSpinBox"), tr("")).toDouble());
setRepeatFlag(settings->value(QLatin1String("Repeat"), tr("")).toString());
setExpireTimeout(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt());
//settings = Core::ICore::instance()->settings();
setSoundCollectionPath(Utils::PathUtils().InsertDataPath(settings->value(QLatin1String("SoundCollectionPath"), tr("")).toString()));
setCurrentLanguage(settings->value(QLatin1String("CurrentLanguage"), tr("")).toString());
setDataObject(settings->value(QLatin1String("DataObject"), tr("")).toString());
setObjectField(settings->value(QLatin1String("ObjectField"), tr("")).toString());
setValue(settings->value(QLatin1String("Value"), tr("")).toString());
setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString());
setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString());
setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString());
setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString());
setSpinBoxValue(settings->value(QLatin1String("ValueSpinBox"), tr("")).toDouble());
setRepeatFlag(settings->value(QLatin1String("Repeat"), tr("")).toString());
setExpireTimeout(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt());
}
void NotificationItem::startTimer(int value) {
if (!_timer) {
_timer = new QTimer(this);
_timer->setInterval(value);
}
if (!_timer->isActive())
_timer->start();
}
void NotificationItem::stopTimer() {
if (_timer) {
if (_timer->isActive())
_timer->stop();
}
}
void NotificationItem::disposeTimer() {
if (_timer) {
_timer->stop();
delete _timer;
_timer = NULL;
}
}
void NotificationItem::startExpireTimer() {
if (!_expireTimer)
{
_expireTimer = new QTimer(this);
}
_expireTimer->start(_expireTimeout * 1000);
}
void NotificationItem::stopExpireTimer() {
if (_expireTimer) {
if (_expireTimer)
_expireTimer->stop();
}
}
void NotificationItem::disposeExpireTimer() {
if (_expireTimer) {
_expireTimer->stop();
delete _expireTimer;
_expireTimer = NULL;
}
}
QString NotificationItem::parseNotifyMessage()
{
// tips:
// check of *.wav files exist needed for playing phonon queues;
// if phonon player don't find next file in queue, it buzz
// tips:
// check of *.wav files exist needed for playing phonon queues;
// if phonon player don't find next file in queue, it buzz
QString str,str1;
str1= getSayOrder();
str = QString("%L1 ").arg(getSpinBoxValue());
int position = 0xFF;
// generate queue of sound files to play
_messageSequence.clear();
QString str,str1;
str1= getSayOrder();
str = QString("%L1 ").arg(getSpinBoxValue());
int position = 0xFF;
// generate queue of sound files to play
_messageSequence.clear();
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"));
checkSoundFilesExisting();
if("" != getSound2())
{
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"));
}
if(!_messageSequence.size()) {
qNotifyDebug() << "no any files in message queue";
}
if("" != getSound3())
{
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"));
}
switch(str1.at(0).toAscii())
{
case 'N'://NEVER:
str = getSound1()+" "+getSound2()+" "+getSound3();
position = 0xFF;
break;
switch(str1.at(0).toAscii())
{
case 'N'://NEVER:
str = getSound1()+" "+getSound2()+" "+getSound3();
position = 0xFF;
break;
case 'B'://BEFORE:
str = QString("%L1 ").arg(getSpinBoxValue())+getSound1()+" "+getSound2()+" "+getSound3();
position = 0;
break;
case 'B'://BEFORE:
str = QString("%L1 ").arg(getSpinBoxValue())+getSound1()+" "+getSound2()+" "+getSound3();
position = 0;
break;
case 'A'://AFTER:
switch(str1.at(6).toAscii())
{
case 'f':
str = getSound1()+QString(" %L1 ").arg(getSpinBoxValue())+getSound2()+" "+getSound3();
position = 1;
break;
case 's':
str = getSound1()+" "+getSound2()+QString(" %L1").arg(getSpinBoxValue())+" "+getSound3();
position = 2;
break;
case 't':
str = getSound1()+" "+getSound2()+" "+getSound3()+QString(" %L1").arg(getSpinBoxValue());
position = 3;
break;
}
break;
}
case 'A'://AFTER:
switch(str1.at(6).toAscii())
{
case 'f':
str = getSound1()+QString(" %L1 ").arg(getSpinBoxValue())+getSound2()+" "+getSound3();
position = 1;
break;
case 's':
str = getSound1()+" "+getSound2()+QString(" %L1").arg(getSpinBoxValue())+" "+getSound3();
position = 2;
break;
case 't':
str = getSound1()+" "+getSound2()+" "+getSound3()+QString(" %L1").arg(getSpinBoxValue());
position = 3;
break;
}
break;
}
if(position != 0xFF)
{
QStringList numberParts = QString("%1").arg(getSpinBoxValue()).trimmed().split(".");
QStringList numberFiles;
if(position != 0xFF)
{
QStringList numberParts = QString("%1").arg(getSpinBoxValue()).trimmed().split(".");
QStringList numberFiles;
if((numberParts.at(0).size()==1) || (numberParts.at(0).toInt()<20))
{
//if(numberParts.at(0)!="0")
numberFiles.append(numberParts.at(0));
} else {
int i=0;
if(numberParts.at(0).right(2).toInt()<20 && numberParts.at(0).right(2).toInt()!=0) {
if(numberParts.at(0).right(2).toInt()<10)
numberFiles.append(numberParts.at(0).right(1));
else
numberFiles.append(numberParts.at(0).right(2));
i=2;
}
for(;i<numberParts.at(0).size();i++)
{
numberFiles.prepend(numberParts.at(0).at(numberParts.at(0).size()-i-1));
if(numberFiles.first()==QString("0")) {
numberFiles.removeFirst();
continue;
}
if(i==1)
numberFiles.replace(0,numberFiles.first()+'0');
if(i==2)
numberFiles.insert(1,"100");
if(i==3)
numberFiles.insert(1,"1000");
}
}
if((numberParts.at(0).size()==1) || (numberParts.at(0).toInt()<20))
{
//if(numberParts.at(0)!="0")
numberFiles.append(numberParts.at(0));
} else {
int i=0;
if(numberParts.at(0).right(2).toInt()<20 && numberParts.at(0).right(2).toInt()!=0) {
if(numberParts.at(0).right(2).toInt()<10)
numberFiles.append(numberParts.at(0).right(1));
else
numberFiles.append(numberParts.at(0).right(2));
i=2;
}
for(;i<numberParts.at(0).size();i++)
{
numberFiles.prepend(numberParts.at(0).at(numberParts.at(0).size()-i-1));
if(numberFiles.first()==QString("0")) {
numberFiles.removeFirst();
continue;
}
if(i==1)
numberFiles.replace(0,numberFiles.first()+'0');
if(i==2)
numberFiles.insert(1,"100");
if(i==3)
numberFiles.insert(1,"1000");
}
}
if(1 < numberParts.size()) {
numberFiles.append("point");
if((numberParts.at(1).size()==1))
numberFiles.append(numberParts.at(1));
else {
if(numberParts.at(1).left(1)=="0")
numberFiles.append(numberParts.at(1).left(1));
else
numberFiles.append(numberParts.at(1).left(1)+'0');
numberFiles.append(numberParts.at(1).right(1));
}
}
foreach(QString fileName,numberFiles) {
fileName+=".wav";
QString filePath = QDir::toNativeSeparators(getSoundCollectionPath()+"/"+ getCurrentLanguage()+"/"+fileName);
if(QFile::exists(filePath))
_messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+ "/"+getCurrentLanguage()+"/"+fileName));
else {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName)))
_messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName));
else {
_messageSequence.clear();
break; // if no some of *.wav files, then don't play number!
}
}
}
}
return str;
if(1 < numberParts.size()) {
numberFiles.append("point");
if((numberParts.at(1).size()==1))
numberFiles.append(numberParts.at(1));
else {
if(numberParts.at(1).left(1)=="0")
numberFiles.append(numberParts.at(1).left(1));
else
numberFiles.append(numberParts.at(1).left(1)+'0');
numberFiles.append(numberParts.at(1).right(1));
}
}
foreach(QString fileName,numberFiles) {
fileName+=".wav";
QString filePath = QDir::toNativeSeparators(getSoundCollectionPath()+"/"+ getCurrentLanguage()+"/"+fileName);
if(QFile::exists(filePath))
_messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+ "/"+getCurrentLanguage()+"/"+fileName));
else {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName)))
_messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName));
else {
_messageSequence.clear();
break; // if no some of *.wav files, then don't play number!
}
}
}
}
return str;
}
void NotificationItem::checkSoundFilesExisting() {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"));
if(!getSound2().size())
{
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"));
}
if(!getSound3().size())
{
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"));
}
}

View File

@ -12,13 +12,15 @@ HEADERS += notifyplugin.h \
notifypluginoptionspage.h \
notifyitemdelegate.h \
notifytablemodel.h \
notificationitem.h
notificationitem.h \
notifylogging.h
SOURCES += notifyplugin.cpp \
notifypluginoptionspage.cpp \
notifyitemdelegate.cpp \
notifytablemodel.cpp \
notificationitem.cpp
notificationitem.cpp \
notifylogging.cpp
OTHER_FILES += NotifyPlugin.pluginspec
@ -27,3 +29,5 @@ FORMS += \
RESOURCES += \
res.qrc

View File

@ -28,132 +28,130 @@
#include <QtGui>
#include "notifyitemdelegate.h"
#include "notifytablemodel.h"
#include "notifylogging.h"
NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent)
: QItemDelegate(parent)
, _parent(parent)
, _items(items)
: QItemDelegate(parent)
, _parent(parent)
, _items(items)
{
}
QWidget *NotifyItemDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem& /*none*/,
const QModelIndex& index) const
QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*none*/,
const QModelIndex& index) const
{
if(eREPEAT_VALUE == index.column()) {
QComboBox* editor = new QComboBox(parent);
editor->clear();
editor->addItems(_items);
return editor;
} else {
if(eEXPIRE_TIME == index.column()) {
QSpinBox* editor = new QSpinBox(parent);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
return editor;
} else {
if(eENABLE_NOTIFICATION == index.column()) {
QCheckBox* editor = new QCheckBox(parent);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
return editor;
}
}
}
QLineEdit *editor = new QLineEdit(parent);
return editor;
if (eREPEAT_VALUE == index.column()) {
QComboBox* editor = new QComboBox(parent);
editor->clear();
editor->addItems(_items);
return editor;
} else {
if (eEXPIRE_TIME == index.column()) {
QSpinBox* editor = new QSpinBox(parent);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
return editor;
} else {
if (eENABLE_NOTIFICATION == index.column()) {
QCheckBox* editor = new QCheckBox(parent);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
return editor;
}
}
}
QLineEdit *editor = new QLineEdit(parent);
return editor;
}
void NotifyItemDelegate::commitAndCloseEditor()
{
QLineEdit* editor = qobject_cast<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);
} else {
QSpinBox* editor = qobject_cast<QSpinBox*>(sender());
if (editor)
{
emit commitData(editor);
emit closeEditor(editor);
} else {
QCheckBox* editor = qobject_cast<QCheckBox*>(sender());
if (editor)
{
emit commitData(editor);
emit closeEditor(editor);
}
}
}
}
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);
} else {
QSpinBox* editor = qobject_cast<QSpinBox*>(sender());
if (editor)
{
emit commitData(editor);
emit closeEditor(editor);
} else {
QCheckBox* editor = qobject_cast<QCheckBox*>(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()));
else {
QSpinBox* expireEditor = qobject_cast<QSpinBox *>(editor);
if(expireEditor)
expireEditor->setValue(index.model()->data(index, Qt::EditRole).toInt());
else {
QCheckBox* enablePlayEditor = qobject_cast<QCheckBox *>(editor);
if (enablePlayEditor)
enablePlayEditor->setChecked(index.model()->data(index, Qt::EditRole).toBool());
}
}
}
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()));
else {
QSpinBox* expireEditor = qobject_cast<QSpinBox *>(editor);
if (expireEditor)
expireEditor->setValue(index.model()->data(index, Qt::EditRole).toInt());
else {
QCheckBox* enablePlayEditor = qobject_cast<QCheckBox *>(editor);
if (enablePlayEditor)
enablePlayEditor->setChecked(index.model()->data(index, Qt::EditRole).toBool());
}
}
}
}
void NotifyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
if(edit) {
model->setData(index, edit->text());
} else {
QComboBox * repeatEditor = qobject_cast<QComboBox *>(editor);
if(repeatEditor) {
model->setData(index, repeatEditor->currentText());
} else {
QSpinBox * expireEditor = qobject_cast<QSpinBox *>(editor);
if(expireEditor) {
model->setData(index, expireEditor->value(), Qt::EditRole);
} else {
QCheckBox* enablePlayEditor = qobject_cast<QCheckBox*>(editor);
if (enablePlayEditor) {
model->setData(index, enablePlayEditor->isChecked(), Qt::EditRole);
}
}
}
}
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());
} else {
QSpinBox * expireEditor = qobject_cast<QSpinBox *>(editor);
if (expireEditor) {
model->setData(index, expireEditor->value(), Qt::EditRole);
} else {
QCheckBox* enablePlayEditor = qobject_cast<QCheckBox*>(editor);
if (enablePlayEditor) {
model->setData(index, enablePlayEditor->isChecked(), Qt::EditRole);
}
}
}
}
}
void NotifyItemDelegate::selectRow(const QString & text)
void NotifyItemDelegate::selectRow(const QString& text)
{
QComboBox* combo = qobject_cast<QComboBox*>(sender());
QTableWidget* table = new QTableWidget;
table = (QTableWidget*)(combo->parent());
QComboBox* combo = qobject_cast<QComboBox*>(sender());
QTableWidget* table = new QTableWidget;
table = (QTableWidget*)(combo->parent());
qDebug() << table->columnCount();
qDebug() << table->rowCount();
qDebug() << table->currentRow();
qNotifyDebug() << table->columnCount();
qNotifyDebug() << table->rowCount();
qNotifyDebug() << table->currentRow();
}
QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem & option,
const QModelIndex & index) const
QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QSize s = QItemDelegate::sizeHint(option, index);
s.setHeight(10);
return s;
QSize s = QItemDelegate::sizeHint(option, index);
s.setHeight(10);
return s;
}

View File

@ -0,0 +1,42 @@
/**
******************************************************************************
*
* @file notifylogging.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uses to logging only inside notify plugin,
* can be convinient turned on/off
* @see The GNU Public License (GPL) Version 3
* @defgroup notifyplugin
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "notifylogging.h"
#ifdef DEBUG_NOTIFIES
QDebug qNotifyDebug()
#endif
#ifndef DEBUG_NOTIFIES
QNoDebug qNotifyDebug()
#endif
{
#ifdef DEBUG_NOTIFIES
return qDebug();
#endif
return QNoDebug();
}

View File

@ -0,0 +1,42 @@
/**
******************************************************************************
*
* @file notifylogging.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Uses to logging only inside notify plugin,
* can be convinient turned on/off
* @see The GNU Public License (GPL) Version 3
* @defgroup notifyplugin
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef NOTIFYLOGGING_H
#define NOTIFYLOGGING_H
#include "QDebug.h"
#ifdef DEBUG_NOTIFIES
QDebug qNotifyDebug();
#endif
#ifndef DEBUG_NOTIFIES
QNoDebug qNotifyDebug();
#endif
#endif // NOTIFYLOGGING_H

View File

@ -28,6 +28,7 @@
#include "notifyplugin.h"
#include "notificationitem.h"
#include "notifypluginoptionspage.h"
#include "notifylogging.h"
#include <coreplugin/icore.h>
#include <QDebug>
#include <QtPlugin>
@ -43,18 +44,6 @@ static const QString VERSION = "1.0.0";
//#define DEBUG_NOTIFIES
#ifdef DEBUG_NOTIFIES
QDebug qNotifyDebug()
#endif
#ifndef DEBUG_NOTIFIES
QNoDebug qNotifyDebug()
#endif
{
#ifdef DEBUG_NOTIFIES
return qDebug();
#endif
return QNoDebug();
}
SoundNotifyPlugin::SoundNotifyPlugin()
{
@ -84,15 +73,15 @@ bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg)
void SoundNotifyPlugin::extensionsInitialized()
{
Core::ICore::instance()->readSettings(this);
if ( !configured ){
readConfig_0_0_0();
}
Core::ICore::instance()->readSettings(this);
if ( !configured ){
readConfig_0_0_0();
}
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*)));
removedNotifies.clear();
connectNotifications();
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*)));
removedNotifies.clear();
connectNotifications();
}
void SoundNotifyPlugin::saveConfig( QSettings* settings, UAVConfigInfo *configInfo){
@ -147,39 +136,39 @@ void SoundNotifyPlugin::readConfig( QSettings* settings, UAVConfigInfo *configIn
void SoundNotifyPlugin::readConfig_0_0_0(){
settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("NotifyPlugin"));
settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("NotifyPlugin"));
settings->beginReadArray("Current");
settings->setArrayIndex(0);
currentNotification.restoreState(settings);
settings->endArray();
settings->beginReadArray("Current");
settings->setArrayIndex(0);
currentNotification.restoreState(settings);
settings->endArray();
// read list of notifications from settings
int size = settings->beginReadArray("listNotifies");
for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i);
NotificationItem* notification = new NotificationItem;
notification->restoreState(settings);
lstNotifications.append(notification);
}
settings->endArray();
setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool());
settings->endGroup();
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*)));
removedNotifies.clear();
connectNotifications();
configured = true;
}
// read list of notifications from settings
int size = settings->beginReadArray("listNotifies");
for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i);
NotificationItem* notification = new NotificationItem;
notification->restoreState(settings);
lstNotifications.append(notification);
}
settings->endArray();
setEnableSound(settings->value(QLatin1String("EnableSound"),0).toBool());
settings->endGroup();
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
connect(pm, SIGNAL(objectAdded(QObject*)), this, SLOT(onTelemetryManagerAdded(QObject*)));
removedNotifies.clear();
connectNotifications();
configured = true;
}
void SoundNotifyPlugin::onTelemetryManagerAdded(QObject* obj)
{
telMngr = qobject_cast<TelemetryManager *>(obj);
if(telMngr)
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
telMngr = qobject_cast<TelemetryManager *>(obj);
if (telMngr)
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
}
void SoundNotifyPlugin::shutdown()
@ -189,86 +178,76 @@ void SoundNotifyPlugin::shutdown()
void SoundNotifyPlugin::onAutopilotDisconnect()
{
connectNotifications();
connectNotifications();
}
/*!
clear any notify timers from previous flight;
reset will be perform on start of option page
clear any notify timers from previous flight;
reset will be perform on start of option page
*/
void SoundNotifyPlugin::resetNotification(void)
{
//first, reject empty args and unknown fields.
foreach(NotificationItem* notify,lstNotifications) {
if(notify->timer)
{
disconnect(notify->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
notify->timer->stop();
delete notify->timer;
notify->timer = NULL;
}
if(notify->expireTimer)
{
disconnect(notify->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
notify->expireTimer->stop();
delete notify->expireTimer;
notify->expireTimer = NULL;
}
}
//first, reject empty args and unknown fields.
foreach(NotificationItem* ntf, lstNotifications) {
ntf->disposeTimer();
disconnect(ntf->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
ntf->disposeExpireTimer();
disconnect(ntf->getExpireTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
}
}
/*!
update list of notifies;
will be perform on OK or APPLY press of option page
update list of notifies;
will be perform on OK or APPLY press of option page
*/
void SoundNotifyPlugin::updateNotificationList(QList<NotificationItem*> list)
{
removedNotifies.clear();
resetNotification();
lstNotifications.clear();
lstNotifications=list;
connectNotifications();
removedNotifies.clear();
resetNotification();
lstNotifications.clear();
lstNotifications=list;
connectNotifications();
Core::ICore::instance()->saveSettings(this);
Core::ICore::instance()->saveSettings(this);
}
void SoundNotifyPlugin::connectNotifications()
{
foreach(UAVDataObject* obj,lstNotifiedUAVObjects) {
if (obj != NULL)
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(appendNotification(UAVObject*)));
}
if(phonon.mo != NULL) {
delete phonon.mo;
phonon.mo = NULL;
}
foreach(UAVDataObject* obj,lstNotifiedUAVObjects) {
if (obj != NULL)
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(appendNotification(UAVObject*)));
}
if (phonon.mo != NULL) {
delete phonon.mo;
phonon.mo = NULL;
}
if(!enableSound) return;
if (!enableSound) return;
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
lstNotifiedUAVObjects.clear();
pendingNotifications.clear();
lstNotifications.append(removedNotifies);
removedNotifies.clear();
lstNotifiedUAVObjects.clear();
pendingNotifications.clear();
lstNotifications.append(removedNotifies);
removedNotifies.clear();
//first, reject empty args and unknown fields.
foreach(NotificationItem* notify, lstNotifications) {
notify->firstStart=true;
notify->isNowPlaying=false;
//first, reject empty args and unknown fields.
foreach(NotificationItem* notify, lstNotifications) {
notify->firstStart=true;
notify->isNowPlaying=false;
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(notify->getDataObject()) );
if (obj != NULL ) {
if(!lstNotifiedUAVObjects.contains(obj)) {
lstNotifiedUAVObjects.append(obj);
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
}
} else
std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl;
}
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(notify->getDataObject()) );
if (obj != NULL ) {
if (!lstNotifiedUAVObjects.contains(obj)) {
lstNotifiedUAVObjects.append(obj);
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
}
} else
std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl;
}
if(lstNotifications.isEmpty()) return;
if (lstNotifications.isEmpty()) return;
// set notification message to current event
phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory);
phonon.mo->clearQueue();
@ -284,80 +263,73 @@ void SoundNotifyPlugin::connectNotifications()
void SoundNotifyPlugin::appendNotification(UAVObject *object)
{
disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
foreach(NotificationItem* notification, lstNotifications) {
if(object->getName()!=notification->getDataObject())
continue;
foreach(NotificationItem* ntf, lstNotifications) {
if (object->getName() != ntf->getDataObject())
continue;
if(nowPlayingConfiguration == notification)
continue;
if (nowPlayingConfiguration == ntf)
continue;
if(notification->getRepeatFlag()!= "Repeat Instantly" &&
notification->getRepeatFlag()!= "Repeat Once" && !notification->firstStart)
continue;
if (ntf->getRepeatFlag()!= "Repeat Instantly" &&
ntf->getRepeatFlag()!= "Repeat Once" && !ntf->firstStart)
continue;
checkNotificationRule(notification,object);
}
connect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
checkNotificationRule(ntf,object);
}
connect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
}
void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UAVObject* object)
{
bool condition=false;
double threshold;
QString direction;
QString fieldName;
threshold = notification->getSpinBoxValue();
direction = notification->getValue();
fieldName = notification->getObjectField();
UAVObjectField* field = object->getField(fieldName);
if (field->getName()!="") {
double value = field->getDouble();
bool condition=false;
double threshold;
QString direction;
QString fieldName;
threshold = notification->getSpinBoxValue();
direction = notification->getValue();
fieldName = notification->getObjectField();
UAVObjectField* field = object->getField(fieldName);
if (field->getName()!="") {
double value = field->getDouble();
switch(direction[0].toAscii())
{
case 'E':
if(value==threshold)
condition = true;
break;
case 'G':
if(value>threshold)
condition = true;
break;
case 'L':
if(value<threshold)
condition = true;
break;
}
}
switch(direction[0].toAscii())
{
case 'E':
if (value==threshold)
condition = true;
break;
case 'G':
if (value>threshold)
condition = true;
break;
case 'L':
if (value<threshold)
condition = true;
break;
}
}
if(condition)
{
if(!playNotification(notification))
{
if(!pendingNotifications.contains(notification))
{
if(notification->timer)
if(notification->timer->isActive())
notification->timer->stop();
#ifdef DEBUG_NOTIFIES
qDebug() << "add to pending list - " << notification->parseNotifyMessage();
#endif
// if audio is busy, start expiration timer
//ms = (notification->getExpiredTimeout()[in sec])*1000
//QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification));
pendingNotifications.append(notification);
if(!notification->expireTimer)
{
notification->expireTimer = new QTimer(notification);
connect(notification->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
}
notification->expireTimer->start(notification->getExpireTimeout()*1000);
}
}
}
if (condition)
{
if (!playNotification(notification))
{
if (!pendingNotifications.contains(notification))
{
notification->stopTimer();
qNotifyDebug() << "add to pending list - " << notification->parseNotifyMessage();
// if audio is busy, start expiration timer
//ms = (notification->getExpiredTimeout()[in sec])*1000
//QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification));
pendingNotifications.append(notification);
notification->startExpireTimer();
connect(notification->getExpireTimer(), SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
}
}
}
}
bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
@ -366,132 +338,112 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
if (phonon.mo == NULL)
return false;
if(!notification->getEnableFlag()) return true;
if (!notification->getEnableFlag()) return true;
#ifdef DEBUG_NOTIFIES
qDebug() << "Phonon State: " << phonon.mo->state();
#endif
if((phonon.mo->state()==Phonon::PausedState)
|| (phonon.mo->state()==Phonon::StoppedState)
|| phonon.firstPlay)
{
// don't fire expire timer
nowPlayingConfiguration = notification;
if(notification->expireTimer)
notification->expireTimer->stop();
qNotifyDebug() << "Phonon State: " << phonon.mo->state();
if ((phonon.mo->state()==Phonon::PausedState)
|| (phonon.mo->state()==Phonon::StoppedState)
|| phonon.firstPlay)
{
// don't fire expire timer
nowPlayingConfiguration = notification;
notification->stopExpireTimer();
if(notification->getRepeatFlag()=="Repeat Once")
{
removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification)));
}
else {
if(notification->getRepeatFlag()!="Repeat Instantly")
{
QRegExp rxlen("(\\d+)");
QString value;
int timer_value;
int pos = rxlen.indexIn(notification->getRepeatFlag());
if (pos > -1) {
value = rxlen.cap(1); // "189"
timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage
}
if (notification->getRepeatFlag()=="Repeat Once") {
removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification)));
} else {
if (notification->getRepeatFlag()!="Repeat Instantly")
{
QRegExp rxlen("(\\d+)");
QString value;
int timer_value;
int pos = rxlen.indexIn(notification->getRepeatFlag());
if (pos > -1) {
value = rxlen.cap(1); // "189"
timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage
}
if(!notification->timer)
{
notification->timer = new QTimer(notification);
notification->timer->setInterval(timer_value);
connect(notification->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
}
if(!notification->timer->isActive())
notification->timer->start();
}
}
notification->firstStart=false;
phonon.mo->clear();
QString str = notification->parseNotifyMessage();
qNotifyDebug() << "play notification - " << str;
notification->startTimer(timer_value);
connect(notification->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
}
}
notification->firstStart=false;
phonon.mo->clear();
QString str = notification->parseNotifyMessage();
qNotifyDebug() << "play notification - " << str;
foreach (QString item, notification->getMessageSequence()) {
Phonon::MediaSource *ms = new Phonon::MediaSource(item);
ms->setAutoDelete(true);
phonon.mo->enqueue(*ms);
}
phonon.mo->play();
phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before
// the state is not "Loading" anymore.
}
else
return false; // if audio is busy
foreach(QString item, notification->getMessageSequence()) {
Phonon::MediaSource *ms = new Phonon::MediaSource(item);
ms->setAutoDelete(true);
phonon.mo->enqueue(*ms);
}
phonon.mo->play();
phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before
// the state is not "Loading" anymore.
}
else
return false; // if audio is busy
return true;
return true;
}
void SoundNotifyPlugin::repeatTimerHandler()
{
NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent());
#ifdef DEBUG_NOTIFIES
qDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage();
#endif
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
qNotifyDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVObject* object = objManager->getObject(notification->getDataObject());
if(object)
if (object)
checkNotificationRule(notification,object);
}
void SoundNotifyPlugin::expireTimerHandler()
{
// fire expire timer
NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent());
notification->expireTimer->stop();
// fire expire timer
NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent());
notification->stopExpireTimer();
if(!pendingNotifications.isEmpty())
{
#ifdef DEBUG_NOTIFIES
qDebug() << "expireTimerHandler - " << notification->parseNotifyMessage();
#endif
pendingNotifications.removeOne(notification);
}
if (!pendingNotifications.isEmpty()) {
qNotifyDebug() << "expireTimerHandler - " << notification->parseNotifyMessage();
pendingNotifications.removeOne(notification);
}
}
void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldstate)
{
Q_UNUSED(oldstate)
#ifdef DEBUG_NOTIFIES
qDebug() << "File length (ms): " << phonon.mo->totalTime();
qDebug() << "New State: " << newstate;
#endif
qNotifyDebug() << "File length (ms): " << phonon.mo->totalTime();
qNotifyDebug() << "New State: " << newstate;
#ifndef Q_OS_WIN
// This is a hack to force Linux to wait until the end of the
// wav file before moving to the next in the queue.
// I wish I did not have to go through a #define, but I did not
// manage to make this work on both platforms any other way!
if (phonon.mo->totalTime()>0)
phonon.mo->setTransitionTime(phonon.mo->totalTime());
// This is a hack to force Linux to wait until the end of the
// wav file before moving to the next in the queue.
// I wish I did not have to go through a #define, but I did not
// manage to make this work on both platforms any other way!
if (phonon.mo->totalTime()>0)
phonon.mo->setTransitionTime(phonon.mo->totalTime());
#endif
if((newstate == Phonon::PausedState) ||
(newstate == Phonon::StoppedState))
{
nowPlayingConfiguration=NULL;
if(!pendingNotifications.isEmpty())
{
NotificationItem* notification = pendingNotifications.takeFirst();
#ifdef DEBUG_NOTIFIES
qDebug() << "play audioFree - " << notification->parseNotifyMessage();
#endif
playNotification(notification);
}
} else if (newstate == Phonon::ErrorState)
{
if(phonon.mo->errorType()==0) {
qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType();
phonon.mo->clearQueue();
}
}
// if(newstate == Phonon::BufferingState)
// qDebug() << "Phonon::BufferingState!!!";
if ((newstate == Phonon::PausedState) ||
(newstate == Phonon::StoppedState))
{
nowPlayingConfiguration=NULL;
if (!pendingNotifications.isEmpty())
{
NotificationItem* notification = pendingNotifications.takeFirst();
qNotifyDebug() << "play audioFree - " << notification->parseNotifyMessage();
playNotification(notification);
}
} else {
if (newstate == Phonon::ErrorState) {
if (phonon.mo->errorType()==0) {
qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType();
phonon.mo->clearQueue();
}
}
}
}
Q_EXPORT_PLUGIN(SoundNotifyPlugin)

View File

@ -49,7 +49,6 @@ typedef struct {
} PhononObject, *pPhononObject;
class SoundNotifyPlugin : public Core::IConfigurablePlugin
{
Q_OBJECT

View File

@ -64,68 +64,67 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
options_page->setupUi(optionsPageWidget);
options_page->setupUi(optionsPageWidget);
delegateItems.clear();
listSoundFiles.clear();
delegateItems.clear();
listSoundFiles.clear();
delegateItems << "Repeat Once"
<< "Repeat Instantly"
<< "Repeat 10 seconds"
<< "Repeat 30 seconds"
<< "Repeat 1 minute";
delegateItems << "Repeat Once"
<< "Repeat Instantly"
<< "Repeat 10 seconds"
<< "Repeat 30 seconds"
<< "Repeat 1 minute";
options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory"));
options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory"));
// Fills the combo boxes for the UAVObjects
QList< QList<UAVDataObject*> > objList = objManager.getDataObjects();
foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) {
options_page->UAVObject->addItem(obj->getName());
}
}
// Fills the combo boxes for the UAVObjects
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->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString)));
connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&)));
connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int)));
connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString)));
connect(this, SIGNAL(updateNotifications(QList<NotificationItem*>)),
owner, SLOT(updateNotificationList(QList<NotificationItem*>)));
connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification()));
connect(this, SIGNAL(updateNotifications(QList<NotificationItem*>)),
owner, SLOT(updateNotificationList(QList<NotificationItem*>)));
//connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification()));
//emit resetNotification();
privListNotifications.clear();
privListNotifications.clear();
for (int i = 0; i < owner->getListNotifications().size(); ++i) {
NotificationItem* notification = new NotificationItem();
owner->getListNotifications().at(i)->copyTo(notification);
privListNotifications.append(notification);
}
for (int i = 0; i < owner->getListNotifications().size(); ++i) {
NotificationItem* notification = new NotificationItem();
owner->getListNotifications().at(i)->copyTo(notification);
privListNotifications.append(notification);
}
updateConfigView(owner->getCurrentNotification());
updateConfigView(owner->getCurrentNotification());
initButtons();
initRulesTableModel();
initRulesTableView();
initPhononPlayer();
initButtons();
initRulesTableModel();
initRulesTableView();
initPhononPlayer();
return optionsPageWidget;
return optionsPageWidget;
}
void NotifyPluginOptionsPage::initButtons()
{
options_page->chkEnableSound->setChecked(owner->getEnableSound());
connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool)));
options_page->chkEnableSound->setChecked(owner->getEnableSound());
connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool)));
options_page->buttonModify->setEnabled(false);
options_page->buttonDelete->setEnabled(false);
options_page->buttonPlayNotification->setEnabled(false);
connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked()));
connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked()));
connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked()));
connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked()));
options_page->buttonModify->setEnabled(false);
options_page->buttonDelete->setEnabled(false);
options_page->buttonPlayNotification->setEnabled(false);
connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked()));
connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked()));
connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked()));
connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked()));
}
void NotifyPluginOptionsPage::initPhononPlayer()
@ -150,32 +149,32 @@ void NotifyPluginOptionsPage::initRulesTableModel()
void NotifyPluginOptionsPage::initRulesTableView()
{
options_page->notifyRulesView->setModel(notifyRulesModel.data());
options_page->notifyRulesView->resizeRowsToContents();
options_page->notifyRulesView->setSelectionModel(notifyRulesSelection);
options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this));
options_page->notifyRulesView->setModel(notifyRulesModel.data());
options_page->notifyRulesView->resizeRowsToContents();
options_page->notifyRulesView->setSelectionModel(notifyRulesSelection);
options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this));
options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200);
options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120);
options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100);
options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60);
options_page->notifyRulesView->setDragEnabled(true);
options_page->notifyRulesView->setAcceptDrops(true);
options_page->notifyRulesView->setDropIndicatorShown(true);
options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200);
options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120);
options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100);
options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60);
options_page->notifyRulesView->setDragEnabled(true);
options_page->notifyRulesView->setAcceptDrops(true);
options_page->notifyRulesView->setDropIndicatorShown(true);
}
void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification)
{
notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path());
notification->setCurrentLanguage(options_page->SoundCollectionList->currentText());
notification->setDataObject(options_page->UAVObject->currentText());
notification->setObjectField(options_page->UAVObjectField->currentText());
notification->setSound1(options_page->Sound1->currentText());
notification->setSound2(options_page->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText());
notification->setSayOrder(options_page->SayOrder->currentText());
notification->setValue(options_page->Value->currentText());
notification->setSpinBoxValue(options_page->ValueSpinBox->value());
notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path());
notification->setCurrentLanguage(options_page->SoundCollectionList->currentText());
notification->setDataObject(options_page->UAVObject->currentText());
notification->setObjectField(options_page->UAVObjectField->currentText());
notification->setSound1(options_page->Sound1->currentText());
notification->setSound2(options_page->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText());
notification->setSayOrder(options_page->SayOrder->currentText());
notification->setValue(options_page->Value->currentText());
notification->setSpinBoxValue(options_page->ValueSpinBox->value());
}
@ -185,19 +184,19 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio
*/
void NotifyPluginOptionsPage::apply()
{
getOptionsPageValues(owner->getCurrentNotification());
owner->setEnableSound(options_page->chkEnableSound->isChecked());
emit updateNotifications(privListNotifications);
getOptionsPageValues(owner->getCurrentNotification());
owner->setEnableSound(options_page->chkEnableSound->isChecked());
emit updateNotifications(privListNotifications);
}
void NotifyPluginOptionsPage::finish()
{
disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(changeButtonText(Phonon::State,Phonon::State)));
if (notifySound) {
notifySound->stop();
notifySound->clear();
}
disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(changeButtonText(Phonon::State,Phonon::State)));
if (notifySound) {
notifySound->stop();
notifySound->clear();
}
}
//////////////////////////////////////////////////////////////////////////////
@ -205,247 +204,247 @@ void NotifyPluginOptionsPage::finish()
// <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>();
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());
options_page->UAVObjectField->addItem(field->getName());
}
}
// locate collection folder on disk
void NotifyPluginOptionsPage::on_buttonSoundFolder_clicked(const QString& path)
{
QDir dirPath(path);
listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
options_page->SoundCollectionList->clear();
options_page->SoundCollectionList->addItems(listDirCollections);
QDir dirPath(path);
listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
options_page->SoundCollectionList->clear();
options_page->SoundCollectionList->addItems(listDirCollections);
}
void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index)
{
options_page->SoundCollectionList->setCurrentIndex(index);
options_page->SoundCollectionList->setCurrentIndex(index);
currentCollectionPath = options_page->SoundDirectoryPathChooser->path()
+ QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText());
QDir dirPath(currentCollectionPath);
QStringList filters;
filters << "*.mp3" << "*.wav";
dirPath.setNameFilters(filters);
listSoundFiles = dirPath.entryList(filters);
listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), "");
options_page->Sound1->clear();
options_page->Sound2->clear();
options_page->Sound3->clear();
options_page->Sound1->addItems(listSoundFiles);
options_page->Sound2->addItem("");
options_page->Sound2->addItems(listSoundFiles);
options_page->Sound3->addItem("");
options_page->Sound3->addItems(listSoundFiles);
QDir dirPath(currentCollectionPath);
QStringList filters;
filters << "*.mp3" << "*.wav";
dirPath.setNameFilters(filters);
listSoundFiles = dirPath.entryList(filters);
listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), "");
options_page->Sound1->clear();
options_page->Sound2->clear();
options_page->Sound3->clear();
options_page->Sound1->addItems(listSoundFiles);
options_page->Sound2->addItem("");
options_page->Sound2->addItems(listSoundFiles);
options_page->Sound3->addItem("");
options_page->Sound3->addItems(listSoundFiles);
}
void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate)
{
//Q_ASSERT(Phonon::ErrorState != newstate);
//Q_ASSERT(Phonon::ErrorState != newstate);
if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) {
options_page->buttonPlayNotification->setText("Play");
options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png"));
} else {
if (newstate == Phonon::PlayingState) {
options_page->buttonPlayNotification->setText("Stop");
options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png"));
}
}
if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) {
options_page->buttonPlayNotification->setText("Play");
options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png"));
} else {
if (newstate == Phonon::PlayingState) {
options_page->buttonPlayNotification->setText("Stop");
options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png"));
}
}
}
void NotifyPluginOptionsPage::onFinishedPlaying()
{
notifySound->clear();
notifySound->clear();
}
void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked()
{
NotificationItem* notification = NULL;
NotificationItem* notification = NULL;
if (-1 == notifyRulesSelection->currentIndex().row())
return;
notifySound->clearQueue();
notification = privListNotifications.at(notifyRulesSelection->currentIndex().row());
notification->parseNotifyMessage();
QStringList sequence = notification->getMessageSequence();
Q_ASSERT(!!sequence.size());
foreach(QString item, sequence)
notifySound->enqueue(Phonon::MediaSource(item));
if (-1 == notifyRulesSelection->currentIndex().row())
return;
notifySound->clearQueue();
notification = privListNotifications.at(notifyRulesSelection->currentIndex().row());
notification->parseNotifyMessage();
QStringList sequence = notification->getMessageSequence();
Q_ASSERT(!!sequence.size());
foreach(QString item, sequence)
notifySound->enqueue(Phonon::MediaSource(item));
notifySound->play();
notifySound->play();
}
void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state)
{
bool state1 = 1^state;
bool state1 = 1^state;
QList<Phonon::Path> listOutputs = notifySound->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(NotificationItem* notification)
{
QString path = notification->getSoundCollectionPath();
if (path == "") {
//QDir dir = QDir::currentPath();
//path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds";
path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds");
}
QString path = notification->getSoundCollectionPath();
if (path == "") {
//QDir dir = QDir::currentPath();
//path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds";
path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds");
}
options_page->SoundDirectoryPathChooser->setPath(path);
options_page->SoundDirectoryPathChooser->setPath(path);
if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage()));
} else {
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
}
if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage()));
} else {
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
}
if (options_page->UAVObject->findText(notification->getDataObject())!=-1){
options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject()));
}
if (options_page->UAVObject->findText(notification->getDataObject())!=-1){
options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject()));
}
// Now load the object field values:
options_page->UAVObjectField->clear();
QString uavDataObject = notification->getDataObject();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager.getObject(uavDataObject));
if (obj != NULL ) {
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->UAVObjectField->addItem(field->getName());
}
}
// Now load the object field values:
options_page->UAVObjectField->clear();
QString uavDataObject = notification->getDataObject();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager.getObject(uavDataObject));
if (obj != NULL ) {
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->UAVObjectField->addItem(field->getName());
}
}
if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) {
options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField()));
}
if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) {
options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField()));
}
if (-1 != options_page->Sound1->findText(notification->getSound1())) {
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1()));
if (-1 != options_page->Sound1->findText(notification->getSound1())) {
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1()));
// don't show item if it wasn't find in stored location
//options_page->Sound1->setCurrentIndex(-1);
}
// don't show item if it wasn't find in stored location
//options_page->Sound1->setCurrentIndex(-1);
}
if (-1 != options_page->Sound2->findText(notification->getSound2())) {
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2()));
if (-1 != options_page->Sound2->findText(notification->getSound2())) {
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2()));
// don't show item if it wasn't find in stored location
//options_page->Sound2->setCurrentIndex(-1);
}
// don't show item if it wasn't find in stored location
//options_page->Sound2->setCurrentIndex(-1);
}
if (-1 != options_page->Sound3->findText(notification->getSound3())) {
options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3()));
}
if (-1 != options_page->Sound3->findText(notification->getSound3())) {
options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3()));
}
if (-1 != options_page->Value->findText(notification->getValue())) {
options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue()));
}
if (-1 != options_page->Value->findText(notification->getValue())) {
options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue()));
}
if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) {
options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder()));
}
if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) {
options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder()));
}
options_page->ValueSpinBox->setValue(notification->getSpinBoxValue());
options_page->ValueSpinBox->setValue(notification->getSpinBoxValue());
}
void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected )
{
bool select = false;
notifySound->stop();
if (selected.indexes().size()) {
select = true;
updateConfigView(privListNotifications.at(selected.indexes().at(0).row()));
}
bool select = false;
notifySound->stop();
if (selected.indexes().size()) {
select = true;
updateConfigView(privListNotifications.at(selected.indexes().at(0).row()));
}
options_page->buttonModify->setEnabled(select);
options_page->buttonDelete->setEnabled(select);
options_page->buttonPlayNotification->setEnabled(select);
options_page->buttonModify->setEnabled(select);
options_page->buttonDelete->setEnabled(select);
options_page->buttonPlayNotification->setEnabled(select);
}
void NotifyPluginOptionsPage::on_buttonAddNotification_clicked()
{
NotificationItem* notification = new NotificationItem;
NotificationItem* notification = new NotificationItem;
if (options_page->SoundDirectoryPathChooser->path()=="") {
QPalette textPalette=options_page->SoundDirectoryPathChooser->palette();
textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red);
options_page->SoundDirectoryPathChooser->setPalette(textPalette);
options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder");
return;
}
if (options_page->SoundDirectoryPathChooser->path()=="") {
QPalette textPalette=options_page->SoundDirectoryPathChooser->palette();
textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red);
options_page->SoundDirectoryPathChooser->setPalette(textPalette);
options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder");
return;
}
notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path());
notification->setCurrentLanguage(options_page->SoundCollectionList->currentText());
notification->setDataObject(options_page->UAVObject->currentText());
notification->setObjectField(options_page->UAVObjectField->currentText());
notification->setValue(options_page->Value->currentText());
notification->setSpinBoxValue(options_page->ValueSpinBox->value());
notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path());
notification->setCurrentLanguage(options_page->SoundCollectionList->currentText());
notification->setDataObject(options_page->UAVObject->currentText());
notification->setObjectField(options_page->UAVObjectField->currentText());
notification->setValue(options_page->Value->currentText());
notification->setSpinBoxValue(options_page->ValueSpinBox->value());
if (options_page->Sound1->currentText().size() > 0)
notification->setSound1(options_page->Sound1->currentText());
if (options_page->Sound1->currentText().size() > 0)
notification->setSound1(options_page->Sound1->currentText());
notification->setSound2(options_page->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText());
notification->setSound2(options_page->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText());
if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second"))
|| ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) {
return;
} else {
notification->setSayOrder(options_page->SayOrder->currentText());
}
privListNotifications.append(notification);
emit entryAdded(privListNotifications.size() - 1);
notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second"))
|| ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) {
return;
} else {
notification->setSayOrder(options_page->SayOrder->currentText());
}
privListNotifications.append(notification);
emit entryAdded(privListNotifications.size() - 1);
notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
}
void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked()
{
notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row());
if (!notifyRulesModel->rowCount()
&& (notifyRulesSelection->currentIndex().row() > 0
&& notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) )
{
options_page->buttonDelete->setEnabled(false);
options_page->buttonModify->setEnabled(false);
options_page->buttonPlayNotification->setEnabled(false);
}
notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row());
if (!notifyRulesModel->rowCount()
&& (notifyRulesSelection->currentIndex().row() > 0
&& notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) )
{
options_page->buttonDelete->setEnabled(false);
options_page->buttonModify->setEnabled(false);
options_page->buttonPlayNotification->setEnabled(false);
}
}
void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked()
{
NotificationItem* notification = new NotificationItem;
getOptionsPageValues(notification);
notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag());
privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification);
entryUpdated(notifyRulesSelection->currentIndex().row());
NotificationItem* notification = new NotificationItem;
getOptionsPageValues(notification);
notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag());
privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification);
entryUpdated(notifyRulesSelection->currentIndex().row());
}

View File

@ -0,0 +1,465 @@
/**
******************************************************************************
*
* @file notifypluginoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Notify Plugin options page
* @see The GNU Public License (GPL) Version 3
* @defgroup notifyplugin
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "notifypluginoptionspage.h"
#include <coreplugin/icore.h>
#include "notificationitem.h"
#include "ui_notifypluginoptionspage.h"
#include "extensionsystem/pluginmanager.h"
#include "utils/pathutils.h"
#include <QFileDialog>
#include <QtAlgorithms>
#include <QStringList>
#include <QtCore/QSettings>
#include <QTableWidget>
#include <QPalette>
#include <QBuffer>
#include "notifyplugin.h"
#include "notifyitemdelegate.h"
#include "notifytablemodel.h"
NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent)
: IOptionsPage(parent)
, objManager(*ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>())
, owner(qobject_cast<SoundNotifyPlugin*>(parent))
, currentCollectionPath("")
, privListNotifications((qobject_cast<SoundNotifyPlugin*>(parent))->getListNotifications())
{
}
NotifyPluginOptionsPage::~NotifyPluginOptionsPage()
{
}
//creates options page widget (uses the UI file)
QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
{
options_page.reset(new Ui::NotifyPluginOptionsPage());
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
options_page->setupUi(optionsPageWidget);
delegateItems.clear();
listSoundFiles.clear();
delegateItems << "Repeat Once"
<< "Repeat Instantly"
<< "Repeat 10 seconds"
<< "Repeat 30 seconds"
<< "Repeat 1 minute";
options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory"));
// Fills the combo boxes for the UAVObjects
QList< QList<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->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString)));
connect(this, SIGNAL(updateNotifications(QList<NotificationItem*>)),
owner, SLOT(updateNotificationList(QList<NotificationItem*>)));
connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification()));
//emit resetNotification();
privListNotifications.clear();
for (int i = 0; i < owner->getListNotifications().size(); ++i) {
NotificationItem* notification = new NotificationItem();
owner->getListNotifications().at(i)->copyTo(notification);
privListNotifications.append(notification);
}
updateConfigView(owner->getCurrentNotification());
initButtons();
initRulesTableModel();
initRulesTableView();
initPhononPlayer();
return optionsPageWidget;
}
void NotifyPluginOptionsPage::initButtons()
{
options_page->chkEnableSound->setChecked(owner->getEnableSound());
connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool)));
options_page->buttonModify->setEnabled(false);
options_page->buttonDelete->setEnabled(false);
options_page->buttonPlayNotification->setEnabled(false);
connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked()));
connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked()));
connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked()));
connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked()));
}
void NotifyPluginOptionsPage::initPhononPlayer()
{
notifySound = Phonon::createPlayer(Phonon::NotificationCategory);
connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(changeButtonText(Phonon::State,Phonon::State)));
connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void)));
}
void NotifyPluginOptionsPage::initRulesTableModel()
{
notifyRulesModel.reset(new NotifyTableModel(&privListNotifications));
notifyRulesSelection = new QItemSelectionModel(notifyRulesModel.data());
connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & )));
connect(this, SIGNAL(entryUpdated(int)),
notifyRulesModel.data(), SLOT(entryUpdated(int)));
connect(this, SIGNAL(entryAdded(int)),
notifyRulesModel.data(), SLOT(entryAdded(int)));
}
void NotifyPluginOptionsPage::initRulesTableView()
{
options_page->notifyRulesView->setModel(notifyRulesModel.data());
options_page->notifyRulesView->resizeRowsToContents();
options_page->notifyRulesView->setSelectionModel(notifyRulesSelection);
options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this));
options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200);
options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120);
options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100);
options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60);
options_page->notifyRulesView->setDragEnabled(true);
options_page->notifyRulesView->setAcceptDrops(true);
options_page->notifyRulesView->setDropIndicatorShown(true);
}
void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification)
{
notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path());
notification->setCurrentLanguage(options_page->SoundCollectionList->currentText());
notification->setDataObject(options_page->UAVObject->currentText());
notification->setObjectField(options_page->UAVObjectField->currentText());
notification->setSound1(options_page->Sound1->currentText());
notification->setSound2(options_page->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText());
notification->setSayOrder(options_page->SayOrder->currentText());
notification->setValue(options_page->Value->currentText());
notification->setSpinBoxValue(options_page->ValueSpinBox->value());
}
/*!
* Called when the user presses apply or OK.
* Saves the current values
*/
void NotifyPluginOptionsPage::apply()
{
getOptionsPageValues(owner->getCurrentNotification());
owner->setEnableSound(options_page->chkEnableSound->isChecked());
emit updateNotifications(privListNotifications);
}
void NotifyPluginOptionsPage::finish()
{
disconnect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(changeButtonText(Phonon::State,Phonon::State)));
if (notifySound) {
notifySound->stop();
notifySound->clear();
}
}
//////////////////////////////////////////////////////////////////////////////
// Fills in the <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)
{
QDir dirPath(path);
listDirCollections = dirPath.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
options_page->SoundCollectionList->clear();
options_page->SoundCollectionList->addItems(listDirCollections);
}
void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index)
{
options_page->SoundCollectionList->setCurrentIndex(index);
currentCollectionPath = options_page->SoundDirectoryPathChooser->path()
+ QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText());
QDir dirPath(currentCollectionPath);
QStringList filters;
filters << "*.mp3" << "*.wav";
dirPath.setNameFilters(filters);
listSoundFiles = dirPath.entryList(filters);
listSoundFiles.replaceInStrings(QRegExp(".mp3|.wav"), "");
options_page->Sound1->clear();
options_page->Sound2->clear();
options_page->Sound3->clear();
options_page->Sound1->addItems(listSoundFiles);
options_page->Sound2->addItem("");
options_page->Sound2->addItems(listSoundFiles);
options_page->Sound3->addItem("");
options_page->Sound3->addItems(listSoundFiles);
}
void NotifyPluginOptionsPage::changeButtonText(Phonon::State newstate, Phonon::State oldstate)
{
//Q_ASSERT(Phonon::ErrorState != newstate);
if (newstate == Phonon::PausedState || newstate == Phonon::StoppedState) {
options_page->buttonPlayNotification->setText("Play");
options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png"));
} else {
if (newstate == Phonon::PlayingState) {
options_page->buttonPlayNotification->setText("Stop");
options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png"));
}
}
}
void NotifyPluginOptionsPage::onFinishedPlaying()
{
notifySound->clear();
}
void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked()
{
NotificationItem* notification = NULL;
if (-1 == notifyRulesSelection->currentIndex().row())
return;
notifySound->clearQueue();
notification = privListNotifications.at(notifyRulesSelection->currentIndex().row());
notification->parseNotifyMessage();
QStringList sequence = notification->getMessageSequence();
Q_ASSERT(!!sequence.size());
foreach(QString item, sequence)
notifySound->enqueue(Phonon::MediaSource(item));
notifySound->play();
}
void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state)
{
bool state1 = 1^state;
QList<Phonon::Path> listOutputs = notifySound->outputPaths();
Phonon::AudioOutput * audioOutput = (Phonon::AudioOutput*)listOutputs.last().sink();
audioOutput->setMuted(state1);
}
void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification)
{
QString path = notification->getSoundCollectionPath();
if (path == "") {
//QDir dir = QDir::currentPath();
//path = QDir::currentPath().left(QDir::currentPath().indexOf("OpenPilot",0,Qt::CaseSensitive))+"../share/sounds";
path = Utils::PathUtils().InsertDataPath("%%DATAPATH%%sounds");
}
options_page->SoundDirectoryPathChooser->setPath(path);
if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage()));
} else {
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
}
if (options_page->UAVObject->findText(notification->getDataObject())!=-1){
options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject()));
}
<<<<<<< Updated upstream
// Now load the object field values:
options_page->UAVObjectField->clear();
QString uavDataObject = notification->getDataObject();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager.getObject(uavDataObject));
if (obj != NULL ) {
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->UAVObjectField->addItem(field->getName());
}
}
=======
// Now load the object field values:
options_page->UAVObjectField->clear();
QString uavDataObject = notification->getDataObject();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(uavDataObject/*objList.at(0).at(0)->getName()*/) );
if (obj != NULL ) {
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->UAVObjectField->addItem(field->getName());
}
}
>>>>>>> Stashed changes
if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) {
options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField()));
}
if (-1 != options_page->Sound1->findText(notification->getSound1())) {
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1()));
// don't show item if it wasn't find in stored location
//options_page->Sound1->setCurrentIndex(-1);
}
if (-1 != options_page->Sound2->findText(notification->getSound2())) {
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2()));
// don't show item if it wasn't find in stored location
//options_page->Sound2->setCurrentIndex(-1);
}
if (-1 != options_page->Sound3->findText(notification->getSound3())) {
options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3()));
} else {
// show item from default location
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default"));
options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3()));
}
if (-1 != options_page->Value->findText(notification->getValue())) {
options_page->Value->setCurrentIndex(options_page->Value->findText(notification->getValue()));
}
if (-1 != options_page->SayOrder->findText(notification->getSayOrder())) {
options_page->SayOrder->setCurrentIndex(options_page->SayOrder->findText(notification->getSayOrder()));
}
options_page->ValueSpinBox->setValue(notification->getSpinBoxValue());
}
void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected )
{
bool select = false;
notifySound->stop();
if (selected.indexes().size()) {
select = true;
updateConfigView(privListNotifications.at(selected.indexes().at(0).row()));
}
options_page->buttonModify->setEnabled(select);
options_page->buttonDelete->setEnabled(select);
options_page->buttonPlayNotification->setEnabled(select);
}
void NotifyPluginOptionsPage::on_buttonAddNotification_clicked()
{
NotificationItem* notification = new NotificationItem;
if (options_page->SoundDirectoryPathChooser->path()=="") {
QPalette textPalette=options_page->SoundDirectoryPathChooser->palette();
textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red);
options_page->SoundDirectoryPathChooser->setPalette(textPalette);
options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder");
return;
}
notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path());
notification->setCurrentLanguage(options_page->SoundCollectionList->currentText());
notification->setDataObject(options_page->UAVObject->currentText());
notification->setObjectField(options_page->UAVObjectField->currentText());
notification->setValue(options_page->Value->currentText());
notification->setSpinBoxValue(options_page->ValueSpinBox->value());
if (options_page->Sound1->currentText().size() > 0)
notification->setSound1(options_page->Sound1->currentText());
notification->setSound2(options_page->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText());
if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second"))
|| ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) {
return;
} else {
notification->setSayOrder(options_page->SayOrder->currentText());
}
privListNotifications.append(notification);
emit entryAdded(privListNotifications.size() - 1);
notifyRulesSelection->setCurrentIndex(notifyRulesModel->index(privListNotifications.size()-1,0,QModelIndex()),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
}
void NotifyPluginOptionsPage::on_buttonDeleteNotification_clicked()
{
notifyRulesModel->removeRow(notifyRulesSelection->currentIndex().row());
if (!notifyRulesModel->rowCount()
&& (notifyRulesSelection->currentIndex().row() > 0
&& notifyRulesSelection->currentIndex().row() < notifyRulesModel->rowCount()) )
{
options_page->buttonDelete->setEnabled(false);
options_page->buttonModify->setEnabled(false);
options_page->buttonPlayNotification->setEnabled(false);
}
}
void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked()
{
NotificationItem* notification = new NotificationItem;
getOptionsPageValues(notification);
notification->setRepeatFlag(privListNotifications.at(notifyRulesSelection->currentIndex().row())->getRepeatFlag());
privListNotifications.replace(notifyRulesSelection->currentIndex().row(),notification);
entryUpdated(notifyRulesSelection->currentIndex().row());
}

View File

@ -100,7 +100,7 @@ private:
signals:
void updateNotifications(QList<NotificationItem*> list);
void resetNotification(void);
//void resetNotification(void);
void entryUpdated(int index);
void entryAdded(int position);

View File

@ -31,82 +31,82 @@
NotifyTableModel::NotifyTableModel(QList<NotificationItem*>* parentList, QObject* parent)
: QAbstractTableModel(parent)
{
_headerStrings << "Name" << "Repeats" << "Lifetime,sec" << "Enable";
_list.reset(parentList);
_headerStrings << "Name" << "Repeats" << "Lifetime,sec" << "Enable";
_list.reset(parentList);
}
bool NotifyTableModel::setData(const QModelIndex &index,
const QVariant &value, int role)
{
if (index.isValid() && role == Qt::EditRole) {
if(eREPEAT_VALUE == index.column())
_list->at(index.row())->setRepeatFlag(value.toString());
else {
if(eEXPIRE_TIME == index.column())
_list->at(index.row())->setExpireTimeout(value.toInt());
else {
if(eENABLE_NOTIFICATION == index.column())
_list->at(index.row())->setEnableFlag(value.toBool());
}
}
emit dataChanged(index, index);
return true;
}
return false;
if (index.isValid() && role == Qt::EditRole) {
if(eREPEAT_VALUE == index.column())
_list->at(index.row())->setRepeatFlag(value.toString());
else {
if(eEXPIRE_TIME == index.column())
_list->at(index.row())->setExpireTimeout(value.toInt());
else {
if(eENABLE_NOTIFICATION == index.column())
_list->at(index.row())->setEnableFlag(value.toBool());
}
}
emit dataChanged(index, index);
return true;
}
return false;
}
QVariant NotifyTableModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
qWarning() << "NotifyTableModel::data - index.isValid()";
return QVariant();
}
if (!index.isValid()) {
qWarning() << "NotifyTableModel::data - index.isValid()";
return QVariant();
}
if (index.row() >= _list->size())
return QVariant();
if (index.row() >= _list->size())
return QVariant();
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
switch(index.column())
{
case eMESSAGE_NAME:
return _list->at(index.row())->parseNotifyMessage();
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
switch(index.column())
{
case eMESSAGE_NAME:
return _list->at(index.row())->parseNotifyMessage();
case eREPEAT_VALUE:
return _list->at(index.row())->getRepeatFlag();
case eREPEAT_VALUE:
return _list->at(index.row())->getRepeatFlag();
case eEXPIRE_TIME:
return _list->at(index.row())->getExpireTimeout();
case eEXPIRE_TIME:
return _list->at(index.row())->getExpireTimeout();
case eENABLE_NOTIFICATION:
return _list->at(index.row())->getEnableFlag();
case eENABLE_NOTIFICATION:
return _list->at(index.row())->getEnableFlag();
default:
return QVariant();
}
}
else
{
if (Qt::SizeHintRole == role){
return QVariant(10);
}
}
return QVariant();
default:
return QVariant();
}
}
else
{
if (Qt::SizeHintRole == role){
return QVariant(10);
}
}
return QVariant();
}
QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
return _headerStrings.at(section);
else
if(orientation == Qt::Vertical)
return QString("%1").arg(section);
if (orientation == Qt::Horizontal)
return _headerStrings.at(section);
else
if(orientation == Qt::Vertical)
return QString("%1").arg(section);
return QVariant();
return QVariant();
}
bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& index)
@ -132,11 +132,11 @@ bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex& ind
void NotifyTableModel::entryUpdated(int offset)
{
QModelIndex idx = index(offset, 0);
emit dataChanged(idx, idx);
QModelIndex idx = index(offset, 0);
emit dataChanged(idx, idx);
}
void NotifyTableModel::entryAdded(int position)
{
insertRows(position, 1,QModelIndex());
insertRows(position, 1,QModelIndex());
}