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 #define LKS94PROJECTION_H
#include <QVector> #include <QVector>
#include "cmath" #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 { namespace projections {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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