1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

+multiple selection with D&D completed; +support of enum and range for value completed;

This commit is contained in:
Nickolay 2011-10-04 01:59:37 +03:00
parent 82ec3199d7
commit 6a5589ef51
11 changed files with 699 additions and 683 deletions

View File

@ -103,7 +103,31 @@ public:
void seriaize(QDataStream& stream); void seriaize(QDataStream& stream);
void deseriaize(QDataStream& stream); void deseriaize(QDataStream& stream);
QString parseNotifyMessage(); /**
* Convert notification item fields in single string,
* to show in table for example
*
* @return string which describe notification
*/
QString toString();
/**
* Generate list of sound files needed to play notification
*
* @return success - reference to non-empty _messageSequence;
* error - if one of sounds doesn't exist returns
* reference to empty _messageSequence;
*/
QStringList& toSoundList();
/**
* Returns sound caption name, needed to create string representation of notification.
*
* @return success - string == <sound filename>, if sound file exists
* error - string == [missind]<sound filename>, if sound file doesn't exist
*/
QString getSoundCaption(QString fileName);
QTimer* getTimer() const { return _timer; } QTimer* getTimer() const { return _timer; }
void startTimer(int value); void startTimer(int value);
@ -119,10 +143,14 @@ public:
bool isNowPlaying; bool isNowPlaying;
bool firstStart; bool firstStart;
private: static QStringList sayOrderValues;
void checkSoundFilesExisting(bool& missed1, bool& missed2, bool& missed3); static QStringList retryValues;
private: private:
QString checkSoundExists(QString fileName);
private:
QTimer* _timer; QTimer* _timer;
//! time from putting notification in queue till moment when notification became out-of-date //! time from putting notification in queue till moment when notification became out-of-date
@ -130,6 +158,7 @@ private:
//! according to its priority //! according to its priority
QTimer* _expireTimer; QTimer* _expireTimer;
//! list of wav files from which notification consists
QStringList _messageSequence; QStringList _messageSequence;
//! path to folder with sound files //! path to folder with sound files

View File

@ -40,10 +40,28 @@
#include "notifylogging.h" #include "notifylogging.h"
static const QString cStrNever("Never");
static const QString cStrBefore1st("Before first");
static const QString cStrBefore2nd("Before second");
static const QString cStrAfter2nd("After second");
static const QString cStrRetryOnce("Repeat Once");
static const QString cStrRetryInstantly("Repeat Instantly");
static const QString cStrRetry10sec("Repeat 10 seconds");
static const QString cStrRetry30sec("Repeat 30 seconds");
static const QString cStrRetry1min("Repeat 1 minute");
QStringList NotificationItem::sayOrderValues;
QStringList NotificationItem::retryValues;
NotificationItem::NotificationItem(QObject *parent) NotificationItem::NotificationItem(QObject *parent)
: QObject(parent) : QObject(parent)
, isNowPlaying(0) , isNowPlaying(0)
, firstStart(true) , firstStart(true)
, _timer(NULL)
, _expireTimer(NULL)
, _soundCollectionPath("") , _soundCollectionPath("")
, _currentLanguage("default") , _currentLanguage("default")
, _dataObject("") , _dataObject("")
@ -52,16 +70,23 @@ NotificationItem::NotificationItem(QObject *parent)
, _sound1("") , _sound1("")
, _sound2("") , _sound2("")
, _sound3("") , _sound3("")
, _sayOrder("Never") , _sayOrder(cStrNever)
, _singleValue(0) , _singleValue(0)
, _valueRange2(0) , _valueRange2(0)
, _repeatString("Repeat Instantly") , _repeatString(cStrRetryInstantly)
, _expireTimeout(eDefaultTimeout) , _expireTimeout(eDefaultTimeout)
, _mute(false) , _mute(false)
{ {
_timer = NULL; NotificationItem::sayOrderValues.append(cStrBefore1st);
_expireTimer = NULL; NotificationItem::sayOrderValues.append(cStrBefore2nd);
NotificationItem::sayOrderValues.append(cStrAfter2nd);
NotificationItem::retryValues.append(cStrRetryOnce);
NotificationItem::retryValues.append(cStrRetryInstantly);
NotificationItem::retryValues.append(cStrRetry10sec);
NotificationItem::retryValues.append(cStrRetry30sec);
NotificationItem::retryValues.append(cStrRetry1min);
} }
void NotificationItem::copyTo(NotificationItem* that) const void NotificationItem::copyTo(NotificationItem* that) const
@ -103,7 +128,6 @@ void NotificationItem::saveState(QSettings* settings) const
settings->setValue(QLatin1String("Repeat"), retryString()); settings->setValue(QLatin1String("Repeat"), retryString());
settings->setValue(QLatin1String("ExpireTimeout"), lifetime()); settings->setValue(QLatin1String("ExpireTimeout"), lifetime());
settings->setValue(QLatin1String("Mute"), mute()); settings->setValue(QLatin1String("Mute"), mute());
} }
void NotificationItem::restoreState(QSettings* settings) void NotificationItem::restoreState(QSettings* settings)
@ -123,7 +147,6 @@ void NotificationItem::restoreState(QSettings* settings)
setRetryString(settings->value(QLatin1String("Repeat"), tr("")).toString()); setRetryString(settings->value(QLatin1String("Repeat"), tr("")).toString());
setLifetime(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt()); setLifetime(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt());
setMute(settings->value(QLatin1String("Mute"), tr("")).toInt()); setMute(settings->value(QLatin1String("Mute"), tr("")).toInt());
} }
void NotificationItem::seriaize(QDataStream& stream) void NotificationItem::seriaize(QDataStream& stream)
@ -162,7 +185,8 @@ void NotificationItem::deseriaize(QDataStream& stream)
stream >> this->_mute; stream >> this->_mute;
} }
void NotificationItem::startTimer(int value) { void NotificationItem::startTimer(int value)
{
if (!_timer) { if (!_timer) {
_timer = new QTimer(this); _timer = new QTimer(this);
_timer->setInterval(value); _timer->setInterval(value);
@ -171,14 +195,16 @@ void NotificationItem::startTimer(int value) {
_timer->start(); _timer->start();
} }
void NotificationItem::stopTimer() { void NotificationItem::stopTimer()
{
if (_timer) { if (_timer) {
if (_timer->isActive()) if (_timer->isActive())
_timer->stop(); _timer->stop();
} }
} }
void NotificationItem::disposeTimer() { void NotificationItem::disposeTimer()
{
if (_timer) { if (_timer) {
_timer->stop(); _timer->stop();
delete _timer; delete _timer;
@ -186,22 +212,24 @@ void NotificationItem::disposeTimer() {
} }
} }
void NotificationItem::startExpireTimer() { void NotificationItem::startExpireTimer()
if (!_expireTimer) {
{ if (!_expireTimer) {
_expireTimer = new QTimer(this); _expireTimer = new QTimer(this);
} }
_expireTimer->start(_expireTimeout * 1000); _expireTimer->start(_expireTimeout * 1000);
} }
void NotificationItem::stopExpireTimer() { void NotificationItem::stopExpireTimer()
{
if (_expireTimer) { if (_expireTimer) {
if (_expireTimer) if (_expireTimer)
_expireTimer->stop(); _expireTimer->stop();
} }
} }
void NotificationItem::disposeExpireTimer() { void NotificationItem::disposeExpireTimer()
{
if (_expireTimer) { if (_expireTimer) {
_expireTimer->stop(); _expireTimer->stop();
delete _expireTimer; delete _expireTimer;
@ -209,91 +237,33 @@ void NotificationItem::disposeExpireTimer() {
} }
} }
#define missed "missed sound" int getValuePosition(QString sayOrder)
#define CHECK_ADD_SOUND(n) ((!_missedSound##n) ? getSound##n() : (missed#n))
#define CHECK_REPLACE_SOUND(n) ((!_missedSound##n) ? str.replace(missed#n, getSound##n()) : (missed#n))
QString NotificationItem::parseNotifyMessage()
{ {
// tips: return NotificationItem::sayOrderValues.indexOf(sayOrder);
// check of *.wav files exist needed for playing phonon queues; }
// if phonon player don't find next file in queue, it buzz
QString str; QString NotificationItem::checkSoundExists(QString fileName)
QString value; {
QString sayOrder = getSayOrder(); QString name(fileName + ".wav");
UAVObjectField* field = getUAVObjectField(); QString filePath = QDir::toNativeSeparators(getSoundCollectionPath() + "/" +
if (UAVObjectField::ENUM == field->getType()) { getCurrentLanguage() + "/" +
Q_ASSERT(singleValue() < field->getOptions().size()); name);
value = QString("%L1").arg(field->getOptions().at(singleValue())); if(QFile::exists(filePath))
} else { return filePath;
value = QString("%L1").arg(singleValue()); else {
filePath = QDir::toNativeSeparators(getSoundCollectionPath() +
"/default/" +
name);
if(!QFile::exists(filePath))
filePath.clear();
} }
return filePath;
}
int position = -1; // default don't play value wav file QStringList valueToSoundList(QString value)
{
// generate queue of sound files to play // replace point chr if exists
_messageSequence.clear(); value = value.replace(',', '.');
bool _missedSound1 = false;
bool _missedSound2 = false;
bool _missedSound3 = false;
checkSoundFilesExisting(_missedSound1, _missedSound2, _missedSound3);
str = CHECK_ADD_SOUND(1)+" "+CHECK_ADD_SOUND(2)+" "+CHECK_ADD_SOUND(3);
if(!_messageSequence.size()) {
qNotifyDebug() << "no any files in message queue";
}
sayOrder = sayOrder.trimmed();
switch(sayOrder.at(0).toUpper().toAscii())
{
case 'B'://BEFORE:
CHECK_REPLACE_SOUND(1);
CHECK_REPLACE_SOUND(2);
CHECK_REPLACE_SOUND(3);
str.prepend(value + " ");
position = 0;
break;
case 'A'://AFTER:
switch(sayOrder.at(6).toLower().toAscii())
{
case 'f':
str = CHECK_ADD_SOUND(1)+" "+value+" "+CHECK_ADD_SOUND(2)+" "+CHECK_ADD_SOUND(3);
position = 1;
break;
case 's':
str = CHECK_ADD_SOUND(1)+" "+CHECK_ADD_SOUND(2)+" "+value+" "+CHECK_ADD_SOUND(3);
position = 2;
break;
case 't':
CHECK_REPLACE_SOUND(1);
CHECK_REPLACE_SOUND(2);
CHECK_REPLACE_SOUND(3);
str.append(" "+value);
position = 3;
break;
}
break;
default:
CHECK_REPLACE_SOUND(1);
CHECK_REPLACE_SOUND(2);
CHECK_REPLACE_SOUND(3);
break;
}
if(-1 == position) {
qNotifyDebug() << "NotificationItem::parseNotifyMessage() | value position undefined";
return str;
}
if (UAVObjectField::ENUM == field->getType()) return str;
QStringList numberParts = value.trimmed().split("."); QStringList numberParts = value.trimmed().split(".");
QStringList digitWavs; QStringList digitWavs;
@ -338,23 +308,100 @@ QString NotificationItem::parseNotifyMessage()
digitWavs.append(numberParts.at(1).right(1)); digitWavs.append(numberParts.at(1).right(1));
} }
} }
foreach(QString fileName, digitWavs) { return digitWavs;
fileName+=".wav"; }
QString filePath = QDir::toNativeSeparators(getSoundCollectionPath()+"/"+ getCurrentLanguage()+"/"+fileName);
if(QFile::exists(filePath)) QString NotificationItem::toString()
_messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+ "/"+getCurrentLanguage()+"/"+fileName)); {
else { QString str;
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName))) QString value;
_messageSequence.insert(position++,QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+fileName)); UAVObjectField* field = getUAVObjectField();
else { if (UAVObjectField::ENUM == field->getType()) {
_messageSequence.clear(); Q_ASSERT(singleValue() < field->getOptions().size());
break; // if no some of *.wav files, then don't play number! value = field->getOptions().at(singleValue());
} } else {
value = QString("%L1").arg(singleValue());
}
int pos = getValuePosition(getSayOrder().trimmed());
QStringList lst;
lst.append(getSoundCaption(getSound1()));
lst.append(getSoundCaption(getSound2()));
lst.append(getSoundCaption(getSound3()));
QStringList valueSounds = valueToSoundList(value);
bool missed = false;
foreach(QString sound, valueSounds) {
if(checkSoundExists(sound).isEmpty()) {
missed = true;
break;
} }
} }
// if not "Never" case
if(-1 != pos) {
if(missed)
lst.insert(pos, "[missed]" + value);
else
lst.insert(pos, value);
}
str = lst.join(" ");
return str; return str;
} }
QStringList& NotificationItem::toSoundList()
{
// tips:
// check of *.wav files exist needed for playing phonon queues;
// if phonon player don't find next file in queue, it buzz
QString value;
UAVObjectField* field = getUAVObjectField();
if (UAVObjectField::ENUM == field->getType()) {
Q_ASSERT(singleValue() < field->getOptions().size());
value = field->getOptions().at(singleValue());
} else {
value = QString("%L1").arg(singleValue());
}
// generate queue of sound files to play
_messageSequence.clear();
int pos = getValuePosition(getSayOrder().trimmed());
QStringList lst;
if(!getSound1().isEmpty())
lst.append(getSound1());
if(!getSound2().isEmpty())
lst.append(getSound2());
if(!getSound3().isEmpty())
lst.append(getSound3());
// if not "Never" case
if(-1 != pos) {
QStringList valueSounds = valueToSoundList(value);
foreach(QString sound, valueSounds)
lst.insert(pos++, sound);
}
foreach(QString sound, lst) {
QString path = checkSoundExists(sound);
if (!path.isEmpty()) {
_messageSequence.append(path);
} else {
_messageSequence.clear();
break;
}
}
return _messageSequence;
}
QString NotificationItem::getSoundCaption(QString fileName)
{
if(fileName.isEmpty()) return QString();
if(checkSoundExists(fileName).isEmpty()) {
return QString("[missed]") + fileName;
}
return fileName;
}
UAVObjectField* NotificationItem::getUAVObjectField() { UAVObjectField* NotificationItem::getUAVObjectField() {
return getUAVObject()->getField(getObjectField()); return getUAVObject()->getField(getObjectField());
} }
@ -362,39 +409,3 @@ UAVObjectField* NotificationItem::getUAVObjectField() {
UAVDataObject* NotificationItem::getUAVObject() { UAVDataObject* NotificationItem::getUAVObject() {
return dynamic_cast<UAVDataObject*>((ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>())->getObject(getDataObject())); return dynamic_cast<UAVDataObject*>((ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>())->getObject(getDataObject()));
} }
void NotificationItem::checkSoundFilesExisting(bool& missed1, bool& missed2, bool& missed3)
{
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"));
else {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"));
else
missed1 = true;
}
if(getSound2().size()) {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"));
else {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"));
else
missed2 = true;
}
}
if(getSound3().size()) {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"));
else {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"));
else
missed3 = true;
}
}
}

View File

@ -29,34 +29,29 @@
#include "notifyitemdelegate.h" #include "notifyitemdelegate.h"
#include "notifytablemodel.h" #include "notifytablemodel.h"
#include "notifylogging.h" #include "notifylogging.h"
#include "notificationitem.h"
NotifyItemDelegate::NotifyItemDelegate(QObject* parent) NotifyItemDelegate::NotifyItemDelegate(QObject* parent)
: QItemDelegate(parent) : QItemDelegate(parent)
, _parent(parent) , _parent(parent)
{ {
_titles << "Repeat Once"
<< "Repeat Instantly"
<< "Repeat 10 seconds"
<< "Repeat 30 seconds"
<< "Repeat 1 minute";
} }
QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*none*/, QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*none*/,
const QModelIndex& index) const const QModelIndex& index) const
{ {
if (eREPEAT_VALUE == index.column()) { if (eRepeatValue == index.column()) {
QComboBox* editor = new QComboBox(parent); QComboBox* editor = new QComboBox(parent);
editor->clear(); editor->clear();
editor->addItems(_titles); editor->addItems(NotificationItem::retryValues);
return editor; return editor;
} else { } else {
if (eEXPIRE_TIME == index.column()) { if (eExpireTimer == 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 (eTurnOn == 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;

View File

@ -34,25 +34,23 @@
class NotifyItemDelegate : public QItemDelegate class NotifyItemDelegate : public QItemDelegate
{ {
Q_OBJECT Q_OBJECT
public: public:
NotifyItemDelegate(QObject *parent = 0); NotifyItemDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
const QModelIndex &index) const; const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const; const QModelIndex &index) const;
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
private slots: private slots:
void selectRow(const QString & text); void selectRow(const QString & text);
void commitAndCloseEditor(); void commitAndCloseEditor();
private: private:
QObject* _parent; QObject* _parent;
QStringList _titles;
}; };
#endif // NOTIFYITEMDELEGATE_H #endif // NOTIFYITEMDELEGATE_H

View File

@ -49,7 +49,6 @@ SoundNotifyPlugin::SoundNotifyPlugin()
{ {
phonon.mo = NULL; phonon.mo = NULL;
configured = false; configured = false;
// Do nothing
} }
SoundNotifyPlugin::~SoundNotifyPlugin() SoundNotifyPlugin::~SoundNotifyPlugin()
@ -57,7 +56,6 @@ SoundNotifyPlugin::~SoundNotifyPlugin()
Core::ICore::instance()->saveSettings(this); Core::ICore::instance()->saveSettings(this);
if (phonon.mo != NULL) if (phonon.mo != NULL)
delete phonon.mo; delete phonon.mo;
// Do nothing
} }
bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg) bool SoundNotifyPlugin::initialize(const QStringList& args, QString *errMsg)
@ -99,8 +97,8 @@ void SoundNotifyPlugin::saveConfig( QSettings* settings, UAVConfigInfo *configIn
settings->beginWriteArray("listNotifies"); settings->beginWriteArray("listNotifies");
for (int i = 0; i < lstNotifications.size(); i++) { for (int i = 0; i < lstNotifications.size(); i++) {
settings->setArrayIndex(i); settings->setArrayIndex(i);
lstNotifications.at(i)->saveState(settings); lstNotifications.at(i)->saveState(settings);
} }
settings->endArray(); settings->endArray();
settings->setValue(QLatin1String("EnableSound"), enableSound); settings->setValue(QLatin1String("EnableSound"), enableSound);
@ -147,10 +145,10 @@ void SoundNotifyPlugin::readConfig_0_0_0(){
// 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());
@ -237,14 +235,17 @@ void SoundNotifyPlugin::connectNotifications()
notify->firstStart=true; notify->firstStart=true;
notify->isNowPlaying=false; notify->isNowPlaying=false;
if(notify->mute()) continue;
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; qNotifyDebug() << "Error: Object is unknown (" << notify->getDataObject() << ").";
}
} }
if (lstNotifications.isEmpty()) return; if (lstNotifications.isEmpty()) return;
@ -294,7 +295,7 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA
fieldName = notification->getObjectField(); fieldName = notification->getObjectField();
UAVObjectField* field = object->getField(fieldName); UAVObjectField* field = object->getField(fieldName);
if (field->getName() == "") if (field->getName().isEmpty())
return; return;
double value = field->getDouble(); double value = field->getDouble();
@ -321,13 +322,11 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA
if (!condition) if (!condition)
return; return;
if (!playNotification(notification)) if (!playNotification(notification)) {
{ if (!pendingNotifications.contains(notification)) {
if (!pendingNotifications.contains(notification))
{
notification->stopTimer(); notification->stopTimer();
qNotifyDebug() << "add to pending list - " << notification->parseNotifyMessage(); qNotifyDebug() << "add to pending list - " << notification->toString();
// if audio is busy, start expiration timer // if audio is busy, start expiration timer
//ms = (notification->getExpiredTimeout()[in sec])*1000 //ms = (notification->getExpiredTimeout()[in sec])*1000
//QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification)); //QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification));
@ -344,8 +343,8 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
if (phonon.mo == NULL) if (phonon.mo == NULL)
return false; return false;
if (!notification->mute()) if (notification->mute())
return true; return false;
qNotifyDebug() << "Phonon State: " << phonon.mo->state(); qNotifyDebug() << "Phonon State: " << phonon.mo->state();
if ((phonon.mo->state()==Phonon::PausedState) if ((phonon.mo->state()==Phonon::PausedState)
@ -375,9 +374,8 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
} }
notification->firstStart=false; notification->firstStart=false;
phonon.mo->clear(); phonon.mo->clear();
QString str = notification->parseNotifyMessage(); qNotifyDebug() << "play notification - " << notification->toString();
qNotifyDebug() << "play notification - " << str; foreach (QString item, notification->toSoundList()) {
foreach (QString item, notification->getMessageSequence()) {
Phonon::MediaSource *ms = new Phonon::MediaSource(item); Phonon::MediaSource *ms = new Phonon::MediaSource(item);
ms->setAutoDelete(true); ms->setAutoDelete(true);
phonon.mo->enqueue(*ms); phonon.mo->enqueue(*ms);
@ -393,15 +391,15 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
void SoundNotifyPlugin::repeatTimerHandler() void SoundNotifyPlugin::repeatTimerHandler()
{ {
NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent()); NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent());
qNotifyDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage(); qNotifyDebug() << "repeatTimerHandler - " << notification->toString();
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()
@ -411,7 +409,7 @@ void SoundNotifyPlugin::expireTimerHandler()
notification->stopExpireTimer(); notification->stopExpireTimer();
if (!pendingNotifications.isEmpty()) { if (!pendingNotifications.isEmpty()) {
qNotifyDebug() << "expireTimerHandler - " << notification->parseNotifyMessage(); qNotifyDebug() << "expireTimerHandler - " << notification->toString();
pendingNotifications.removeOne(notification); pendingNotifications.removeOne(notification);
} }
} }
@ -438,7 +436,7 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
if (!pendingNotifications.isEmpty()) if (!pendingNotifications.isEmpty())
{ {
NotificationItem* notification = pendingNotifications.takeFirst(); NotificationItem* notification = pendingNotifications.takeFirst();
qNotifyDebug() << "play audioFree - " << notification->parseNotifyMessage(); qNotifyDebug() << "play audioFree - " << notification->toString();
playNotification(notification); playNotification(notification);
} }
} else { } else {

View File

@ -50,65 +50,65 @@ typedef struct {
class SoundNotifyPlugin : public Core::IConfigurablePlugin class SoundNotifyPlugin : public Core::IConfigurablePlugin
{ {
Q_OBJECT Q_OBJECT
public: public:
SoundNotifyPlugin(); SoundNotifyPlugin();
~SoundNotifyPlugin(); ~SoundNotifyPlugin();
void extensionsInitialized(); void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString); bool initialize(const QStringList & arguments, QString * errorString);
void readConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo); void readConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo);
void saveConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo); void saveConfig( QSettings* qSettings, Core::UAVConfigInfo *configInfo);
void shutdown(); void shutdown();
QList<NotificationItem*> getListNotifications() { return lstNotifications; } QList<NotificationItem*> getListNotifications() { return lstNotifications; }
NotificationItem* getCurrentNotification(){ return &currentNotification;} NotificationItem* getCurrentNotification(){ return &currentNotification;}
bool getEnableSound() const { return enableSound; } bool getEnableSound() const { return enableSound; }
void setEnableSound(bool value) {enableSound = value; } void setEnableSound(bool value) {enableSound = value; }
private: private:
SoundNotifyPlugin(const SoundNotifyPlugin& rhs); Q_DISABLE_COPY(SoundNotifyPlugin)
SoundNotifyPlugin& operator= (const SoundNotifyPlugin& rhs);
bool playNotification(NotificationItem* notification); bool playNotification(NotificationItem* notification);
void checkNotificationRule(NotificationItem* notification, UAVObject* object); void checkNotificationRule(NotificationItem* notification, UAVObject* object);
void readConfig_0_0_0(); void readConfig_0_0_0();
private slots: private slots:
void onTelemetryManagerAdded(QObject* obj);
void onAutopilotDisconnect(); void onTelemetryManagerAdded(QObject* obj);
void connectNotifications(); void onAutopilotDisconnect();
void updateNotificationList(QList<NotificationItem*> list); void connectNotifications();
void resetNotification(void); void updateNotificationList(QList<NotificationItem*> list);
void appendNotification(UAVObject *object); void resetNotification(void);
void repeatTimerHandler(void); void appendNotification(UAVObject *object);
void expireTimerHandler(void); void repeatTimerHandler(void);
void stateChanged(Phonon::State newstate, Phonon::State oldstate); void expireTimerHandler(void);
void stateChanged(Phonon::State newstate, Phonon::State oldstate);
private: private:
bool configured; // just for migration,delete later bool configured; // just for migration,delete later
bool enableSound; bool enableSound;
QList< QList<Phonon::MediaSource>* > lstMediaSource; QList< QList<Phonon::MediaSource>* > lstMediaSource;
QStringList mediaSource; QStringList mediaSource;
QMultiMap<QString, PhononObject> mapMediaObjects; QMultiMap<QString, PhononObject> mapMediaObjects;
QSettings* settings; QSettings* settings;
QList<UAVDataObject*> lstNotifiedUAVObjects; QList<UAVDataObject*> lstNotifiedUAVObjects;
QList<NotificationItem*> lstNotifications; QList<NotificationItem*> lstNotifications;
QList<NotificationItem*> pendingNotifications; QList<NotificationItem*> pendingNotifications;
QList<NotificationItem*> removedNotifies; QList<NotificationItem*> removedNotifies;
NotificationItem currentNotification; NotificationItem currentNotification;
NotificationItem* nowPlayingConfiguration; NotificationItem* nowPlayingConfiguration;
QString m_field; QString m_field;
PhononObject phonon; PhononObject phonon;
NotifyPluginOptionsPage *mop; NotifyPluginOptionsPage *mop;
TelemetryManager* telMngr; TelemetryManager* telMngr;
}; };
#endif // SOUNDNOTIFYPLUGIN_H #endif // SOUNDNOTIFYPLUGIN_H

View File

@ -47,72 +47,61 @@
#include "notifytablemodel.h" #include "notifytablemodel.h"
#include "notifylogging.h" #include "notifylogging.h"
static const char* cStrBefore1st = "Before first";
static const char* cStrBefore2nd = "Before second";
static const char* cStrAfter2nd = "After second";
static const char* cStrEqualTo = "Equal to"; static const char* cStrEqualTo = "Equal to";
static const char* cStrLargeThan = "Large than"; static const char* cStrLargeThan = "Large than";
static const char* cStrLowerThan = "Lower than"; static const char* cStrLowerThan = "Lower than";
static const char* cStrInRange = "In range"; static const char* cStrInRange = "In range";
//----------------------------------------------------------------------------- NotifyPluginOptionsPage::NotifyPluginOptionsPage(QObject *parent)
NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent)
: IOptionsPage(parent) : IOptionsPage(parent)
, objManager(*ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>()) , _objManager(*ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>())
, owner(qobject_cast<SoundNotifyPlugin*>(parent)) , _owner(qobject_cast<SoundNotifyPlugin*>(parent))
, currentCollectionPath("") , _currentCollectionPath("")
, _valueRange(NULL) , _valueRange(NULL)
, _sayOrder(NULL) , _sayOrder(NULL)
, _fieldValue(NULL) , _fieldValue(NULL)
, _fieldType(-1) , _fieldType(-1)
, _form(NULL) , _form(NULL)
{ , _selectedNotification(NULL)
} {}
//-----------------------------------------------------------------------------
NotifyPluginOptionsPage::~NotifyPluginOptionsPage() NotifyPluginOptionsPage::~NotifyPluginOptionsPage()
{ {}
}
//creates options page widget (uses the UI file)
//-----------------------------------------------------------------------------
QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
{ {
options_page.reset(new Ui::NotifyPluginOptionsPage()); _optionsPage.reset(new Ui::NotifyPluginOptionsPage());
//main widget //main widget
QWidget* optionsPageWidget = new QWidget; QWidget* optionsPageWidget = new QWidget;
//if(!_fieldValue.isNull())
_fieldValue = NULL; _fieldValue = NULL;
_valueRange = NULL; _valueRange = NULL;
_fieldType = -1; resetFieldType();
//save ref to form, needed for binding dynamic fields in future //save ref to form, needed for binding dynamic fields in future
_form = optionsPageWidget; _form = optionsPageWidget;
//main layout //main layout
options_page->setupUi(optionsPageWidget); _optionsPage->setupUi(optionsPageWidget);
listSoundFiles.clear(); _listSoundFiles.clear();
options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory"));
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)));
_optionsPage->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
_optionsPage->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory"));
connect(_optionsPage->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)),
this, SLOT(on_buttonSoundFolder_clicked(const QString&)));
connect(_optionsPage->SoundCollectionList, SIGNAL(currentIndexChanged (int)),
this, SLOT(on_soundLanguage_indexChanged(int)));
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()));
privListNotifications = owner->getListNotifications(); _privListNotifications = _owner->getListNotifications();
// [1] // [1]
_selectedNotification = _owner->getCurrentNotification();
addDynamicValueLayout(); addDynamicValueLayout();
_selectedNotification = owner->getCurrentNotification();
// [2] // [2]
updateConfigView(_selectedNotification); updateConfigView(_selectedNotification);
@ -120,117 +109,119 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
initButtons(); initButtons();
initPhononPlayer(); initPhononPlayer();
// _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(0, 0, QModelIndex()), _notifyRulesSelection->setCurrentIndex(_notifyRulesModel->index(0, 0, QModelIndex()),
// QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
return optionsPageWidget; return optionsPageWidget;
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::apply() void NotifyPluginOptionsPage::apply()
{ {
getOptionsPageValues(owner->getCurrentNotification()); getOptionsPageValues(_owner->getCurrentNotification());
owner->setEnableSound(options_page->chkEnableSound->isChecked()); _owner->setEnableSound(_optionsPage->chkEnableSound->isChecked());
emit updateNotifications(privListNotifications); emit updateNotifications(_privListNotifications);
} }
void NotifyPluginOptionsPage::finish() void NotifyPluginOptionsPage::finish()
{ {
disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_UAVField_indexChanged(QString)));
disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); disconnect(_notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(on_changeButtonText(Phonon::State,Phonon::State)));
disconnect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), if (_notifySound) {
this,SLOT(changeButtonText(Phonon::State,Phonon::State))); _notifySound->stop();
if (notifySound) { _notifySound->clear();
notifySound->stop();
notifySound->clear();
} }
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::addDynamicValueLayout() void NotifyPluginOptionsPage::addDynamicValueLayout()
{ {
NotificationItem* curr = owner->getCurrentNotification(); NotificationItem* curr = _owner->getCurrentNotification();
Q_ASSERT(curr); Q_ASSERT(curr);
options_page->dynamicValueLayout->addWidget(new QLabel("Say order ", _form)); _optionsPage->dynamicValueLayout->addWidget(new QLabel("Say order ", _form));
_sayOrder = new QComboBox(_form); _sayOrder = new QComboBox(_form);
options_page->dynamicValueLayout->addWidget(_sayOrder); _optionsPage->dynamicValueLayout->addWidget(_sayOrder);
QStringList sayOrderValues; _sayOrder->addItems(NotificationItem::sayOrderValues);
sayOrderValues << cStrBefore1st << cStrBefore2nd << cStrAfter2nd;
_sayOrder->addItems(sayOrderValues);
options_page->dynamicValueLayout->addWidget(new QLabel("Value is ", _form)); _optionsPage->dynamicValueLayout->addWidget(new QLabel("Value is ", _form));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager.getObject(curr->getDataObject())); UAVDataObject* obj = dynamic_cast<UAVDataObject*>(_objManager.getObject(curr->getDataObject()));
UAVObjectField* field = obj->getField(curr->getObjectField()); UAVObjectField* field = obj->getField(curr->getObjectField());
Q_ASSERT(obj); Q_ASSERT(obj);
Q_ASSERT(field); Q_ASSERT(field);
_valueRange = new QComboBox(_form); _valueRange = new QComboBox(_form);
options_page->dynamicValueLayout->addWidget(_valueRange); _optionsPage->dynamicValueLayout->addWidget(_valueRange);
addDynamicField(field); addDynamicField(field);
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::resetValueRange() void NotifyPluginOptionsPage::resetValueRange()
{ {
_fieldValue = new QLineEdit(_form);
(static_cast<QLineEdit*>(_fieldValue))->setInputMask("999.99 - 999.99;"); (static_cast<QLineEdit*>(_fieldValue))->setInputMask("999.99 - 999.99;");
(static_cast<QLineEdit*>(_fieldValue))->setText("0000000000"); (static_cast<QLineEdit*>(_fieldValue))->setText("0000000000");
(static_cast<QLineEdit*>(_fieldValue))->setCursorPosition(0); (static_cast<QLineEdit*>(_fieldValue))->setCursorPosition(0);
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::on_rangeValue_indexChanged(QString rangeStr) void NotifyPluginOptionsPage::on_rangeValue_indexChanged(QString rangeStr)
{ {
Q_ASSERT(_fieldValue); Q_ASSERT(_fieldValue);
if(rangeStr == cStrInRange) { UAVObjectField* field = getObjectFieldFromPage();
Q_ASSERT(_fieldValue); Q_ASSERT(!!field);
options_page->dynamicValueLayout->removeWidget(_fieldValue); setDynamicValueWidget(field);
resetValueRange(); setDynamicValueField(_selectedNotification);
options_page->dynamicValueLayout->addWidget(_fieldValue); }
// _fieldType = -1; void NotifyPluginOptionsPage::resetFieldType()
// addDynamicField(field); {
} _fieldType = -1;
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField) void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField)
{ {
//qDebugNotify_if(!objField || !parent) << "null input params"; //qDebugNotify_ if (!objField || !parent) << "null input params";
Q_ASSERT(objField); Q_ASSERT(objField);
if(objField->getType() == _fieldType) { if (objField->getType() == _fieldType) {
if(QComboBox* fieldValue = dynamic_cast<QComboBox*>(_fieldValue)) { if (QComboBox* fieldValue = dynamic_cast<QComboBox*>(_fieldValue)) {
fieldValue->clear(); fieldValue->clear();
QStringList enumValues(objField->getOptions()); QStringList enumValues(objField->getOptions());
fieldValue->addItems(enumValues); fieldValue->addItems(enumValues);
} }
return; return;
} }
// check if dynamic fileld already settled,
// so if its exists remove it and install new field
if(_fieldValue)
options_page->dynamicValueLayout->removeWidget(_fieldValue);
disconnect(_valueRange, SIGNAL(currentIndexChanged(QString)), disconnect(_valueRange, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_rangeValue_indexChanged(QString))); this, SLOT(on_rangeValue_indexChanged(QString)));
_valueRange->clear(); _valueRange->clear();
QStringList rangeValues; QStringList rangeValues;
if(UAVObjectField::ENUM == objField->getType()) { if (UAVObjectField::ENUM == objField->getType()) {
rangeValues << cStrEqualTo << cStrInRange; rangeValues << cStrEqualTo << cStrInRange;
_valueRange->addItems(rangeValues); _valueRange->addItems(rangeValues);
} _valueRange->setCurrentIndex(rangeValues.indexOf(_selectedNotification->range()));
else {
} else {
rangeValues << cStrEqualTo << cStrLargeThan << cStrLowerThan << cStrInRange; rangeValues << cStrEqualTo << cStrLargeThan << cStrLowerThan << cStrInRange;
_valueRange->addItems(rangeValues); _valueRange->addItems(rangeValues);
connect(_valueRange, SIGNAL(currentIndexChanged(QString)), connect(_valueRange, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_rangeValue_indexChanged(QString))); this, SLOT(on_rangeValue_indexChanged(QString)));
} }
setDynamicValueWidget(objField);
}
void NotifyPluginOptionsPage::setDynamicValueWidget(UAVObjectField* objField)
{
Q_ASSERT(_valueRange);
// check if dynamic fileld already settled,
// so if its exists remove it and install new field
if (_fieldValue) {
_optionsPage->dynamicValueLayout->removeWidget(_fieldValue);
delete _fieldValue;
_fieldValue = NULL;
}
_fieldType = objField->getType(); _fieldType = objField->getType();
switch(_fieldType) switch(_fieldType)
{ {
@ -243,92 +234,90 @@ void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField)
break; break;
default: default:
if(_valueRange->currentText() == cStrInRange) { if (_valueRange->currentText() == cStrInRange) {
_fieldValue = new QLineEdit(_form);
resetValueRange(); resetValueRange();
} else { } else {
_fieldValue = new QSpinBox(_form); _fieldValue = new QSpinBox(_form);
} }
break; break;
}; };
options_page->dynamicValueLayout->addWidget(_fieldValue); _optionsPage->dynamicValueLayout->addWidget(_fieldValue);
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::initButtons() void NotifyPluginOptionsPage::initButtons()
{ {
options_page->chkEnableSound->setChecked(owner->getEnableSound()); _optionsPage->chkEnableSound->setChecked(_owner->getEnableSound());
connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); connect(_optionsPage->chkEnableSound, SIGNAL(toggled(bool)),
this, SLOT(on_checkEnableSound_toggled(bool)));
options_page->buttonModify->setEnabled(false); _optionsPage->buttonModify->setEnabled(false);
options_page->buttonDelete->setEnabled(false); _optionsPage->buttonDelete->setEnabled(false);
options_page->buttonPlayNotification->setEnabled(false); _optionsPage->buttonPlayNotification->setEnabled(false);
connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); connect(_optionsPage->buttonAdd, SIGNAL(pressed()),
connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); this, SLOT(on_button_AddNotification_clicked()));
connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); connect(_optionsPage->buttonDelete, SIGNAL(pressed()),
connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); this, SLOT(on_button_DeleteNotification_clicked()));
connect(_optionsPage->buttonModify, SIGNAL(pressed()),
this, SLOT(on_button_ModifyNotification_clicked()));
connect(_optionsPage->buttonPlayNotification, SIGNAL(clicked()),
this, SLOT(on_button_TestSoundNotification_clicked()));
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::initPhononPlayer() void NotifyPluginOptionsPage::initPhononPlayer()
{ {
notifySound.reset(Phonon::createPlayer(Phonon::NotificationCategory)); _notifySound.reset(Phonon::createPlayer(Phonon::NotificationCategory));
connect(notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)), connect(_notifySound.data(),SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(changeButtonText(Phonon::State,Phonon::State))); this,SLOT(on_changeButtonText(Phonon::State,Phonon::State)));
connect(notifySound.data(), SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); connect(_notifySound.data(), SIGNAL(finished(void)), this, SLOT(on_FinishedPlaying(void)));
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::initRulesTable() void NotifyPluginOptionsPage::initRulesTable()
{ {
qNotifyDebug_if(_notifyRulesModel.isNull()) << "_notifyRulesModel.isNull())"; qNotifyDebug_if(_notifyRulesModel.isNull()) << "_notifyRulesModel.isNull())";
qNotifyDebug_if(!_notifyRulesSelection) << "_notifyRulesSelection.isNull())"; qNotifyDebug_if(!_notifyRulesSelection) << "_notifyRulesSelection.isNull())";
//QItemSelectionModel* selection = _notifyRulesSelection.take(); _notifyRulesModel.reset(new NotifyTableModel(_privListNotifications));
_notifyRulesModel.reset(new NotifyTableModel(privListNotifications));
_notifyRulesSelection = new QItemSelectionModel(_notifyRulesModel.data()); _notifyRulesSelection = new QItemSelectionModel(_notifyRulesModel.data());
connect(_notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), connect(_notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); this, SLOT(on_table_changeSelection( const QItemSelection & , const QItemSelection & )));
connect(this, SIGNAL(entryUpdated(int)), connect(this, SIGNAL(entryUpdated(int)),
_notifyRulesModel.data(), SLOT(entryUpdated(int))); _notifyRulesModel.data(), SLOT(entryUpdated(int)));
// connect(this, SIGNAL(entryAdded(int)),
// _notifyRulesModel.data(), SLOT(entryAdded(int)));
options_page->notifyRulesView->setModel(_notifyRulesModel.data()); _optionsPage->notifyRulesView->setModel(_notifyRulesModel.data());
options_page->notifyRulesView->setSelectionModel(_notifyRulesSelection); _optionsPage->notifyRulesView->setSelectionModel(_notifyRulesSelection);
options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(this)); _optionsPage->notifyRulesView->setItemDelegate(new NotifyItemDelegate(this));
options_page->notifyRulesView->resizeRowsToContents(); _optionsPage->notifyRulesView->resizeRowsToContents();
options_page->notifyRulesView->setColumnWidth(eMESSAGE_NAME,200); _optionsPage->notifyRulesView->setColumnWidth(eMessageName,200);
options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); _optionsPage->notifyRulesView->setColumnWidth(eRepeatValue,120);
options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); _optionsPage->notifyRulesView->setColumnWidth(eExpireTimer,100);
options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); _optionsPage->notifyRulesView->setColumnWidth(eTurnOn,60);
options_page->notifyRulesView->setDragEnabled(true); _optionsPage->notifyRulesView->setDragEnabled(true);
options_page->notifyRulesView->setAcceptDrops(true); _optionsPage->notifyRulesView->setAcceptDrops(true);
options_page->notifyRulesView->setDropIndicatorShown(true); _optionsPage->notifyRulesView->setDropIndicatorShown(true);
options_page->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove); _optionsPage->notifyRulesView->setDragDropMode(QAbstractItemView::InternalMove);
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification)
{ {
Q_ASSERT(notification); Q_ASSERT(notification);
notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); notification->setSoundCollectionPath(_optionsPage->SoundDirectoryPathChooser->path());
notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); notification->setCurrentLanguage(_optionsPage->SoundCollectionList->currentText());
notification->setDataObject(options_page->UAVObject->currentText()); notification->setDataObject(_optionsPage->UAVObject->currentText());
notification->setObjectField(options_page->UAVObjectField->currentText()); notification->setObjectField(_optionsPage->UAVObjectField->currentText());
notification->setSound1(options_page->Sound1->currentText()); notification->setSound1(_optionsPage->Sound1->currentText());
notification->setSound2(options_page->Sound2->currentText()); notification->setSound2(_optionsPage->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText()); notification->setSound3(_optionsPage->Sound3->currentText());
notification->setSayOrder(_sayOrder->currentText()); notification->setSayOrder(_sayOrder->currentText());
notification->setRange(_valueRange->currentText()); notification->setRange(_valueRange->currentText());
if(QSpinBox* spinValue = dynamic_cast<QSpinBox*>(_fieldValue)) if (QSpinBox* spinValue = dynamic_cast<QSpinBox*>(_fieldValue))
notification->setSingleValue(spinValue->value()); notification->setSingleValue(spinValue->value());
else { else {
if(QComboBox* comboBoxValue = dynamic_cast<QComboBox*>(_fieldValue)) if (QComboBox* comboBoxValue = dynamic_cast<QComboBox*>(_fieldValue))
notification->setSingleValue(comboBoxValue->currentIndex()); notification->setSingleValue(comboBoxValue->currentIndex());
else { else {
if(QLineEdit* rangeValue = dynamic_cast<QLineEdit*>(_fieldValue)) { if (QLineEdit* rangeValue = dynamic_cast<QLineEdit*>(_fieldValue)) {
QString str = rangeValue->text(); QString str = rangeValue->text();
QStringList range = str.split('-'); QStringList range = str.split('-');
notification->setSingleValue(range.at(0).toDouble()); notification->setSingleValue(range.at(0).toDouble());
@ -338,190 +327,175 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio
} }
} }
void NotifyPluginOptionsPage::on_UAVField_indexChanged(QString field)
//----------------------------------------------------------------------------- {
void NotifyPluginOptionsPage::onUAVField_indexChanged(QString field) { resetFieldType();
_fieldType = -1; UAVDataObject* obj = dynamic_cast<UAVDataObject*>( _objManager.getObject(_optionsPage->UAVObject->currentText()));
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager.getObject(options_page->UAVObject->currentText()));
addDynamicField(obj->getField(field)); addDynamicField(obj->getField(field));
} }
////////////////////////////////////////////////////////////////////////////// void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val)
// Fills in the <Field> combo box when value is changed in the {
// <Object> combo box resetFieldType();
////////////////////////////////////////////////////////////////////////////// UAVDataObject* obj = dynamic_cast<UAVDataObject*>( _objManager.getObject(val) );
void NotifyPluginOptionsPage::on_UAVObject_indexChanged(QString val) {
_fieldType = -1;
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager.getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields(); QList<UAVObjectField*> fieldList = obj->getFields();
disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVField_indexChanged(QString)));
options_page->UAVObjectField->clear(); _optionsPage->UAVObjectField->clear();
foreach (UAVObjectField* field, fieldList) { foreach (UAVObjectField* field, fieldList) {
options_page->UAVObjectField->addItem(field->getName()); _optionsPage->UAVObjectField->addItem(field->getName());
} }
connect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(onUAVField_indexChanged(QString))); connect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVField_indexChanged(QString)));
addDynamicField(fieldList.at(0)); addDynamicField(fieldList.at(0));
} }
//-----------------------------------------------------------------------------
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(); _optionsPage->SoundCollectionList->clear();
options_page->SoundCollectionList->addItems(listDirCollections); _optionsPage->SoundCollectionList->addItems(_listDirCollections);
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index) void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index)
{ {
options_page->SoundCollectionList->setCurrentIndex(index); _optionsPage->SoundCollectionList->setCurrentIndex(index);
_currentCollectionPath = _optionsPage->SoundDirectoryPathChooser->path()
+ QDir::toNativeSeparators("/" + _optionsPage->SoundCollectionList->currentText());
currentCollectionPath = options_page->SoundDirectoryPathChooser->path() QDir dirPath(_currentCollectionPath);
+ QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText());
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(); _optionsPage->Sound1->clear();
options_page->Sound2->clear(); _optionsPage->Sound2->clear();
options_page->Sound3->clear(); _optionsPage->Sound3->clear();
options_page->Sound1->addItems(listSoundFiles); _optionsPage->Sound1->addItems(_listSoundFiles);
options_page->Sound2->addItem(""); _optionsPage->Sound2->addItem("");
options_page->Sound2->addItems(listSoundFiles); _optionsPage->Sound2->addItems(_listSoundFiles);
options_page->Sound3->addItem(""); _optionsPage->Sound3->addItem("");
options_page->Sound3->addItems(listSoundFiles); _optionsPage->Sound3->addItems(_listSoundFiles);
} }
//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_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"); _optionsPage->buttonPlayNotification->setText("Play");
options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png")); _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/play.png"));
} else { } else {
if (newstate == Phonon::PlayingState) { if (newstate == Phonon::PlayingState) {
options_page->buttonPlayNotification->setText("Stop"); _optionsPage->buttonPlayNotification->setText("Stop");
options_page->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png")); _optionsPage->buttonPlayNotification->setIcon(QPixmap(":/notify/images/stop.png"));
} }
} }
} }
//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_FinishedPlaying()
void NotifyPluginOptionsPage::onFinishedPlaying()
{ {
notifySound->clear(); _notifySound->clear();
} }
//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_button_TestSoundNotification_clicked()
void NotifyPluginOptionsPage::on_buttonTestSoundNotification_clicked()
{ {
NotificationItem* notification = NULL; NotificationItem* notification = NULL;
if (-1 == _notifyRulesSelection->currentIndex().row())
return;
notifySound->clearQueue();
notification = privListNotifications.at(_notifyRulesSelection->currentIndex().row());
notification->parseNotifyMessage();
QStringList sequence = notification->getMessageSequence();
Q_ASSERT(!!sequence.size());
qNotifyDebug() << "on_buttonTestSoundNotification_clicked"; qNotifyDebug() << "on_buttonTestSoundNotification_clicked";
Q_ASSERT(-1 != _notifyRulesSelection->currentIndex().row());
_notifySound->clearQueue();
notification = _privListNotifications.at(_notifyRulesSelection->currentIndex().row());
QStringList sequence = notification->toSoundList();
if (sequence.isEmpty()) {
qNotifyDebug() << "message sequense is empty!";
return;
}
foreach(QString item, sequence) { foreach(QString item, sequence) {
qNotifyDebug() << item; qNotifyDebug() << item;
notifySound->enqueue(Phonon::MediaSource(item)); _notifySound->enqueue(Phonon::MediaSource(item));
} }
notifySound->play(); _notifySound->play();
} }
void NotifyPluginOptionsPage::on_chkEnableSound_toggled(bool state) void NotifyPluginOptionsPage::on_checkEnableSound_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)
{ {
Q_ASSERT(notification); Q_ASSERT(notification);
disconnect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), disconnect(_optionsPage->UAVObject, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_UAVObject_indexChanged(QString))); this, SLOT(on_UAVObject_indexChanged(QString)));
disconnect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), disconnect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)),
this, SLOT(onUAVField_indexChanged(QString))); this, SLOT(on_UAVField_indexChanged(QString)));
QString path = notification->getSoundCollectionPath(); QString path = notification->getSoundCollectionPath();
if (path == "") { if (path.isEmpty()) {
//QDir dir = QDir::currentPath();
//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); _optionsPage->SoundDirectoryPathChooser->setPath(path);
if (-1 != options_page->SoundCollectionList->findText(notification->getCurrentLanguage())){ if (-1 != _optionsPage->SoundCollectionList->findText(notification->getCurrentLanguage())) {
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText(notification->getCurrentLanguage())); _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText(notification->getCurrentLanguage()));
} else { } else {
options_page->SoundCollectionList->setCurrentIndex(options_page->SoundCollectionList->findText("default")); _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default"));
} }
// 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()); _optionsPage->UAVObject->addItem(obj->getName());
} }
} }
if (options_page->UAVObject->findText(notification->getDataObject())!=-1){ if (-1 != _optionsPage->UAVObject->findText(notification->getDataObject())) {
options_page->UAVObject->setCurrentIndex(options_page->UAVObject->findText(notification->getDataObject())); _optionsPage->UAVObject->setCurrentIndex(_optionsPage->UAVObject->findText(notification->getDataObject()));
} }
options_page->UAVObjectField->clear(); _optionsPage->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()); _optionsPage->UAVObjectField->addItem(field->getName());
} }
} }
if (-1 != options_page->UAVObjectField->findText(notification->getObjectField())) { if (-1 != _optionsPage->UAVObjectField->findText(notification->getObjectField())) {
options_page->UAVObjectField->setCurrentIndex(options_page->UAVObjectField->findText(notification->getObjectField())); _optionsPage->UAVObjectField->setCurrentIndex(_optionsPage->UAVObjectField->findText(notification->getObjectField()));
} }
if (-1 != options_page->Sound1->findText(notification->getSound1())) { if (-1 != _optionsPage->Sound1->findText(notification->getSound1())) {
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); _optionsPage->Sound1->setCurrentIndex(_optionsPage->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")); _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default"));
options_page->Sound1->setCurrentIndex(options_page->Sound1->findText(notification->getSound1())); _optionsPage->Sound1->setCurrentIndex(_optionsPage->Sound1->findText(notification->getSound1()));
} }
if (-1 != options_page->Sound2->findText(notification->getSound2())) { if (-1 != _optionsPage->Sound2->findText(notification->getSound2())) {
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); _optionsPage->Sound2->setCurrentIndex(_optionsPage->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")); _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default"));
options_page->Sound2->setCurrentIndex(options_page->Sound2->findText(notification->getSound2())); _optionsPage->Sound2->setCurrentIndex(_optionsPage->Sound2->findText(notification->getSound2()));
} }
if (-1 != options_page->Sound3->findText(notification->getSound3())) { if (-1 != _optionsPage->Sound3->findText(notification->getSound3())) {
options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); _optionsPage->Sound3->setCurrentIndex(_optionsPage->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")); _optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default"));
options_page->Sound3->setCurrentIndex(options_page->Sound3->findText(notification->getSound3())); _optionsPage->Sound3->setCurrentIndex(_optionsPage->Sound3->findText(notification->getSound3()));
} }
if (-1 != _valueRange->findText(notification->range())) { if (-1 != _valueRange->findText(notification->range())) {
@ -534,120 +508,123 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification)
setDynamicValueField(notification); setDynamicValueField(notification);
connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), connect(_optionsPage->UAVObject, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_UAVObject_indexChanged(QString))); this, SLOT(on_UAVObject_indexChanged(QString)));
connect(options_page->UAVObjectField, SIGNAL(currentIndexChanged(QString)), connect(_optionsPage->UAVObjectField, SIGNAL(currentIndexChanged(QString)),
this, SLOT(onUAVField_indexChanged(QString))); this, SLOT(on_UAVField_indexChanged(QString)));
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::setDynamicValueField(NotificationItem* notification) void NotifyPluginOptionsPage::setDynamicValueField(NotificationItem* notification)
{ {
if(QSpinBox* spinValue = dynamic_cast<QSpinBox*>(_fieldValue)) if (QSpinBox* spinValue = dynamic_cast<QSpinBox*>(_fieldValue))
spinValue->setValue(notification->singleValue()); spinValue->setValue(notification->singleValue());
else { else {
if(QComboBox* comboBoxValue = dynamic_cast<QComboBox*>(_fieldValue)) if (QComboBox* comboBoxValue = dynamic_cast<QComboBox*>(_fieldValue))
comboBoxValue->setCurrentIndex(notification->singleValue()); comboBoxValue->setCurrentIndex(notification->singleValue());
else { else {
if(QLineEdit* rangeValue = dynamic_cast<QLineEdit*>(_fieldValue)) { if (QLineEdit* rangeValue = dynamic_cast<QLineEdit*>(_fieldValue)) {
resetValueRange(); //resetValueRange();
rangeValue->setText(QString("%1%2").arg(notification->singleValue()) QString str = QString("%1%2").arg(notification->singleValue(), 5, 'f', 2, '0')
.arg(notification->valueRange2())); .arg(notification->valueRange2(), 5, 'f', 2, '0');
rangeValue->setText(str);
} else { } else {
qNotifyDebug() << "NotifyPluginOptionsPage::setDynamicValueField | unknown _fieldValue: " << _fieldValue; qNotifyDebug() << "NotifyPluginOptionsPage::setDynamicValueField | unknown _fieldValue: " << _fieldValue;
} }
} }
} }
} }
//----------------------------------------------------------------------------- UAVObjectField* NotifyPluginOptionsPage::getObjectFieldFromPage()
void NotifyPluginOptionsPage::on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected )
{ {
bool select = false; UAVDataObject* obj = dynamic_cast<UAVDataObject*>( _objManager.getObject(_optionsPage->UAVObject->currentText()));
notifySound->stop(); return obj->getField(_optionsPage->UAVObjectField->currentText());
if (selected.indexes().size()) {
select = true;
_selectedNotification = privListNotifications.at(selected.indexes().at(0).row());
updateConfigView(_selectedNotification);
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager.getObject(options_page->UAVObject->currentText()));
UAVObjectField* field = obj->getField(options_page->UAVObjectField->currentText());
addDynamicField(field);
setDynamicValueField(_selectedNotification);
}
options_page->buttonModify->setEnabled(select);
options_page->buttonDelete->setEnabled(select);
options_page->buttonPlayNotification->setEnabled(select);
} }
//-----------------------------------------------------------------------------
void NotifyPluginOptionsPage::on_buttonAddNotification_clicked() UAVObjectField* NotifyPluginOptionsPage::getObjectFieldFromSelected()
{
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(_objManager.getObject(_selectedNotification->getDataObject()));
return obj->getField(_selectedNotification->getObjectField());
}
void NotifyPluginOptionsPage::on_table_changeSelection( const QItemSelection & selected, const QItemSelection & deselected )
{
bool select = false;
_notifySound->stop();
if (selected.indexes().size()) {
select = true;
_selectedNotification = _privListNotifications.at(selected.indexes().at(0).row());
UAVObjectField* field = getObjectFieldFromSelected();
addDynamicField(field);
updateConfigView(_selectedNotification);
}
_optionsPage->buttonModify->setEnabled(select);
_optionsPage->buttonDelete->setEnabled(select);
_optionsPage->buttonPlayNotification->setEnabled(select);
}
void NotifyPluginOptionsPage::on_button_AddNotification_clicked()
{ {
NotificationItem* notification = new NotificationItem; NotificationItem* notification = new NotificationItem;
if (options_page->SoundDirectoryPathChooser->path()=="") { if (_optionsPage->SoundDirectoryPathChooser->path().isEmpty()) {
QPalette textPalette=options_page->SoundDirectoryPathChooser->palette(); QPalette textPalette=_optionsPage->SoundDirectoryPathChooser->palette();
textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red); textPalette.setColor(QPalette::Normal,QPalette::Text, Qt::red);
options_page->SoundDirectoryPathChooser->setPalette(textPalette); _optionsPage->SoundDirectoryPathChooser->setPalette(textPalette);
options_page->SoundDirectoryPathChooser->setPath("please select sound collection folder"); _optionsPage->SoundDirectoryPathChooser->setPath("please select sound collection folder");
return; return;
} }
notification->setSoundCollectionPath(options_page->SoundDirectoryPathChooser->path()); notification->setSoundCollectionPath(_optionsPage->SoundDirectoryPathChooser->path());
notification->setCurrentLanguage(options_page->SoundCollectionList->currentText()); notification->setCurrentLanguage(_optionsPage->SoundCollectionList->currentText());
notification->setDataObject(options_page->UAVObject->currentText()); notification->setDataObject(_optionsPage->UAVObject->currentText());
notification->setObjectField(options_page->UAVObjectField->currentText()); notification->setObjectField(_optionsPage->UAVObjectField->currentText());
notification->setRange(_valueRange->currentText()); notification->setRange(_valueRange->currentText());
if(QSpinBox* spinValue = dynamic_cast<QSpinBox*>(_fieldValue)) if (QSpinBox* spinValue = dynamic_cast<QSpinBox*>(_fieldValue))
notification->setSingleValue(spinValue->value()); notification->setSingleValue(spinValue->value());
if (options_page->Sound1->currentText().size() > 0) if (_optionsPage->Sound1->currentText().size() > 0)
notification->setSound1(options_page->Sound1->currentText()); notification->setSound1(_optionsPage->Sound1->currentText());
notification->setSound2(options_page->Sound2->currentText()); notification->setSound2(_optionsPage->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText()); notification->setSound3(_optionsPage->Sound3->currentText());
if ( ((!options_page->Sound2->currentText().size()) && (_sayOrder->currentText()=="After second")) if ( ((!_optionsPage->Sound2->currentText().size()) && (_sayOrder->currentText()=="After second"))
|| ((!options_page->Sound3->currentText().size()) && (_sayOrder->currentText()=="After third")) ) { || ((!_optionsPage->Sound3->currentText().size()) && (_sayOrder->currentText()=="After third")) ) {
return; return;
} else { } else {
notification->setSayOrder(_sayOrder->currentText()); notification->setSayOrder(_sayOrder->currentText());
} }
_notifyRulesModel->entryAdded(notification); _notifyRulesModel->entryAdded(notification);
_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_button_DeleteNotification_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); _optionsPage->buttonDelete->setEnabled(false);
options_page->buttonModify->setEnabled(false); _optionsPage->buttonModify->setEnabled(false);
options_page->buttonPlayNotification->setEnabled(false); _optionsPage->buttonPlayNotification->setEnabled(false);
} }
} }
//----------------------------------------------------------------------------- void NotifyPluginOptionsPage::on_button_ModifyNotification_clicked()
void NotifyPluginOptionsPage::on_buttonModifyNotification_clicked()
{ {
NotificationItem* notification = new NotificationItem; NotificationItem* notification = new NotificationItem;
getOptionsPageValues(notification); getOptionsPageValues(notification);
notification->setRetryString(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryString()); notification->setRetryString(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryString());
notification->setLifetime(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->lifetime()); notification->setLifetime(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->lifetime());
notification->setMute(privListNotifications.at(_notifyRulesSelection->currentIndex().row())->mute()); notification->setMute(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->mute());
privListNotifications.replace(_notifyRulesSelection->currentIndex().row(),notification); _privListNotifications.replace(_notifyRulesSelection->currentIndex().row(),notification);
entryUpdated(_notifyRulesSelection->currentIndex().row()); entryUpdated(_notifyRulesSelection->currentIndex().row());
} }

View File

@ -57,78 +57,130 @@ using namespace Core;
class NotifyPluginOptionsPage : public IOptionsPage class NotifyPluginOptionsPage : public IOptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit NotifyPluginOptionsPage(/*NotificationItem *config, */QObject *parent = 0);
~NotifyPluginOptionsPage(); explicit NotifyPluginOptionsPage(QObject *parent = 0);
QString id() const { return QLatin1String("settings"); } ~NotifyPluginOptionsPage();
QString trName() const { return tr("settings"); } QString id() const { return QLatin1String("settings"); }
QString category() const { return QLatin1String("Notify Plugin");} QString trName() const { return tr("settings"); }
QString trCategory() const { return tr("Notify Plugin");} QString category() const { return QLatin1String("Notify Plugin");}
QString trCategory() const { return tr("Notify Plugin");}
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void apply(); void apply();
void finish(); void finish();
void restoreFromSettings(); void restoreFromSettings();
void updateConfigView(NotificationItem* notification); void updateConfigView(NotificationItem* notification);
void getOptionsPageValues(NotificationItem* notification); void getOptionsPageValues(NotificationItem* notification);
UAVObjectField* getObjectFieldFromPage();
UAVObjectField* getObjectFieldFromSelected();
signals: signals:
void updateNotifications(QList<NotificationItem*> list); void updateNotifications(QList<NotificationItem*> list);
//void resetNotification(void);
void entryUpdated(int index); void entryUpdated(int index);
private slots:
void on_button_TestSoundNotification_clicked();
void on_button_AddNotification_clicked();
void on_button_DeleteNotification_clicked();
void on_button_ModifyNotification_clicked();
/**
* We can use continuous selection, to select simultaneously
* multiple rows to move them(using drag & drop) inside table ranges.
*/
void on_table_changeSelection( const QItemSelection & selected, const QItemSelection & deselected );
void on_soundLanguage_indexChanged(int index);
void on_buttonSoundFolder_clicked(const QString& path);
void on_UAVObject_indexChanged(QString val);
void on_UAVField_indexChanged(QString val);
void on_changeButtonText(Phonon::State newstate, Phonon::State oldstate);
void on_checkEnableSound_toggled(bool state);
/**
* Important when we change to or from "In range" value
* For enums UI layout stayed the same, but for numeric values
* we need to change UI to show edit line,
* to have possibility assign range limits for value.
*/
void on_rangeValue_indexChanged(QString);
void on_FinishedPlaying(void);
private: private:
Q_DISABLE_COPY(NotifyPluginOptionsPage) Q_DISABLE_COPY(NotifyPluginOptionsPage)
void resetValueRange(); void resetValueRange();
void resetFieldType();
void setDynamicValueField(NotificationItem* notification); void setDynamicValueField(NotificationItem* notification);
void addDynamicField(UAVObjectField* objField); void addDynamicField(UAVObjectField* objField);
void addDynamicValueLayout(); void addDynamicValueLayout();
void setDynamicValueWidget(UAVObjectField* objField);
void initButtons(); void initButtons();
void initPhononPlayer(); void initPhononPlayer();
void initRulesTable(); void initRulesTable();
private slots:
void on_buttonTestSoundNotification_clicked();
void on_buttonAddNotification_clicked();
void on_buttonDeleteNotification_clicked();
void on_buttonModifyNotification_clicked();
void on_tableNotification_changeSelection( const QItemSelection & selected, const QItemSelection & deselected );
void on_soundLanguage_indexChanged(int index);
void on_buttonSoundFolder_clicked(const QString& path);
void on_UAVObject_indexChanged(QString val);
void onUAVField_indexChanged(QString val);
void changeButtonText(Phonon::State newstate, Phonon::State oldstate);
void on_chkEnableSound_toggled(bool state);
void on_rangeValue_indexChanged(QString);
void onFinishedPlaying(void);
private: private:
UAVObjectManager& objManager;
SoundNotifyPlugin* owner;
QStringList listDirCollections;
QStringList listSoundFiles;
QString currentCollectionPath;
Phonon::MediaObject *sound1;
Phonon::MediaObject *sound2;
QScopedPointer<Phonon::MediaObject> notifySound;
Phonon::AudioOutput *audioOutput;
QScopedPointer<NotifyTableModel> _notifyRulesModel; UAVObjectManager& _objManager;
QItemSelectionModel* _notifyRulesSelection; SoundNotifyPlugin* _owner;
QList<NotificationItem*> privListNotifications; QStringList _listDirCollections;
QStringList _listSoundFiles;
QString _currentCollectionPath;
Phonon::MediaObject* _sound1;
Phonon::MediaObject* _sound2;
QScopedPointer<Phonon::MediaObject> _notifySound;
Phonon::AudioOutput* _audioOutput;
QScopedPointer<Ui::NotifyPluginOptionsPage> options_page; QScopedPointer<NotifyTableModel> _notifyRulesModel;
QItemSelectionModel* _notifyRulesSelection;
/**
* Local copy of notification list, which owned by notify plugin.
* Notification list readed once on application loaded, during
* notify plugin startup, then on open options page.
* This copy is simple assignment, but due to implicitly sharing
* we don't have additional cost for that, copy will created
* only after modification of private notify list.
*/
QList<NotificationItem*> _privListNotifications;
QScopedPointer<Ui::NotifyPluginOptionsPage> _optionsPage;
//! widget to convinient selection of condition for field value (equal, lower, greater)
QComboBox* _valueRange; QComboBox* _valueRange;
//! widget to convinient selection of order in which sounds will be played
QComboBox* _sayOrder; QComboBox* _sayOrder;
//! widget to represent edit widget for UAVObjectfield,
//! can be spinbox - for numerics, combobox - enums, or
//! lineedit - for range limits
QWidget* _fieldValue; QWidget* _fieldValue;
//! type of UAVObjectField - numeric or ENUM
//! this variable needs to correctly set dynamic UI elemen _fieldValue
//! NOTE: ocassionaly it should be invalidated (= -1) to reset _fieldValue
int _fieldType; int _fieldType;
//! actualy reference to optionsPageWidget,
//! we MUST hold it beyond the scope of createPage func
//! to have possibility change dynamic parts of options page layout in future
QWidget* _form; QWidget* _form;
//! needs to correctly update UI during transitions from "In Range" to other
//! _valueRange entries and back direction as well
QString _prevRangeValue;
//! Currently selected notification, all controls filled accroding to it.
//! On options page startup, always points to first row.
NotificationItem* _selectedNotification; NotificationItem* _selectedNotification;
}; };

View File

@ -266,7 +266,7 @@ p, li { white-space: pre-wrap; }
<item> <item>
<widget class="QTableView" name="notifyRulesView"> <widget class="QTableView" name="notifyRulesView">
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::ContiguousSelection</enum>
</property> </property>
<property name="selectionBehavior"> <property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum> <enum>QAbstractItemView::SelectRows</enum>

View File

@ -30,8 +30,6 @@
#include <qdebug.h> #include <qdebug.h>
#include <QMimeData> #include <QMimeData>
static int _dragStartRow = -1;
static int _dragNumRows = -1;
const char* mime_type_notify_table = "openpilot/notify_plugin_table"; const char* mime_type_notify_table = "openpilot/notify_plugin_table";
NotifyTableModel::NotifyTableModel(QList<NotificationItem*>& parentList, QObject* parent) NotifyTableModel::NotifyTableModel(QList<NotificationItem*>& parentList, QObject* parent)
@ -47,19 +45,19 @@ bool NotifyTableModel::setData(const QModelIndex &index,
const QVariant &value, int role) const QVariant &value, int role)
{ {
if (index.isValid() && role == Qt::DisplayRole) { if (index.isValid() && role == Qt::DisplayRole) {
if(eMESSAGE_NAME == index.column()) { if(eMessageName == index.column()) {
emit dataChanged(index, index); emit dataChanged(index, index);
return true; return true;
} }
} }
if (index.isValid() && role == Qt::EditRole) { if (index.isValid() && role == Qt::EditRole) {
if(eREPEAT_VALUE == index.column()) if(eRepeatValue == index.column())
_list.at(index.row())->setRetryString(value.toString()); _list.at(index.row())->setRetryString(value.toString());
else { else {
if(eEXPIRE_TIME == index.column()) if(eExpireTimer == index.column())
_list.at(index.row())->setLifetime(value.toInt()); _list.at(index.row())->setLifetime(value.toInt());
else { else {
if(eENABLE_NOTIFICATION == index.column()) if(eTurnOn == index.column())
_list.at(index.row())->setMute(value.toBool()); _list.at(index.row())->setMute(value.toBool());
} }
} }
@ -83,16 +81,16 @@ QVariant NotifyTableModel::data(const QModelIndex &index, int role) const
{ {
switch(index.column()) switch(index.column())
{ {
case eMESSAGE_NAME: case eMessageName:
return _list.at(index.row())->parseNotifyMessage(); return _list.at(index.row())->toString();
case eREPEAT_VALUE: case eRepeatValue:
return _list.at(index.row())->retryString(); return _list.at(index.row())->retryString();
case eEXPIRE_TIME: case eExpireTimer:
return _list.at(index.row())->lifetime(); return _list.at(index.row())->lifetime();
case eENABLE_NOTIFICATION: case eTurnOn:
return _list.at(index.row())->mute(); return _list.at(index.row())->mute();
default: default:
@ -126,13 +124,13 @@ bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& ind
{ {
Q_UNUSED(index); Q_UNUSED(index);
if((-1 == position) || (-1 == rows) ) if (-1 == position || -1 == rows)
return false; return false;
beginInsertRows(QModelIndex(), position, position + rows - 1); beginInsertRows(QModelIndex(), position, position + rows - 1);
for (int row = 0; row < rows; ++row) { for (int i = 0; i < rows; ++i) {
_list.insert(position, new NotificationItem()); _list.insert(position + i, new NotificationItem());
} }
endInsertRows(); endInsertRows();
@ -171,6 +169,17 @@ void NotifyTableModel::entryAdded(NotificationItem* item)
entryUpdated(rowCount() - 1); entryUpdated(rowCount() - 1);
} }
Qt::DropActions NotifyTableModel::supportedDropActions() const
{
return Qt::MoveAction;
}
QStringList NotifyTableModel::mimeTypes() const
{
QStringList types;
types << mime_type_notify_table;
return types;
}
bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row, bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row,
int column, const QModelIndex& parent) int column, const QModelIndex& parent)
@ -198,48 +207,31 @@ bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction acti
QByteArray encodedData = data->data(mime_type_notify_table); QByteArray encodedData = data->data(mime_type_notify_table);
QDataStream stream(&encodedData, QIODevice::ReadOnly); QDataStream stream(&encodedData, QIODevice::ReadOnly);
int rows = beginRow; int rows = beginRow;
// read next item from input MIME and drop into the table line by line
while(!stream.atEnd()) { while(!stream.atEnd()) {
qint32 ptr; qint32 ptr;
stream >> ptr; stream >> ptr;
NotificationItem* item = reinterpret_cast<NotificationItem*>(ptr); NotificationItem* item = reinterpret_cast<NotificationItem*>(ptr);
int dragged = _list.indexOf(item); int dragged = _list.indexOf(item);
// we can drag item from top rows to bottom (DOWN_DIRECTION),
// or from bottom rows to top rows (UP_DIRECTION)
enum { UP_DIRECTION, DOWN_DIRECTION };
int direction = (dragged < rows) ? DOWN_DIRECTION : (dragged += 1, UP_DIRECTION);
Q_ASSERT(insertRows(rows + direction, 1, QModelIndex()));
if(-1 == dragged || rows >= _list.size() || dragged == rows) { if(-1 == dragged || rows >= _list.size() || dragged == rows) {
qNotifyDebug() << "no such item"; qNotifyDebug() << "no such item";
return false; return false;
} }
removeRows(rows, 1, QModelIndex()); _list.replace(rows + direction, item);
insertRows(rows, 1, QModelIndex()); Q_ASSERT(removeRows(dragged, 1, QModelIndex()));
_list.replace(dragged, item); if(direction == UP_DIRECTION)
// _list.swap(dragged, rows); ++rows;
++rows;
}; };
QModelIndex idxTopLeft = index(beginRow, 0, QModelIndex()); QModelIndex idxTopLeft = index(beginRow, 0, QModelIndex());
QModelIndex idxBotRight = index(beginRow, columnCount(QModelIndex()), QModelIndex()); QModelIndex idxBotRight = index(beginRow, columnCount(QModelIndex()), QModelIndex());
emit dataChanged(idxTopLeft, idxBotRight); emit dataChanged(idxTopLeft, idxBotRight);
//QStringList newItems;
//removeRows(_dragStartRow, _dragNumRows, QModelIndex());
//insertRows(beginRow, rows, QModelIndex());
// int rows = beginRow;
// while (!stream.atEnd()) {
// _list.at(index.row())->deserialize(stream);
// ++rows;
// }
// while(rows) {
// int column = 0;
// foreach (const QString& text, newItems) {
// QModelIndex idx = index(beginRow, column, QModelIndex());
// if(!column)
// setData(const_cast<const QModelIndex&>(idx), text, Qt::DisplayRole);
// else
// setData(const_cast<const QModelIndex&>(idx), text, Qt::EditRole);
// ++column;
// }
// ++beginRow;
// --rows;
// }
return true; return true;
} }
@ -251,35 +243,13 @@ QMimeData* NotifyTableModel::mimeData(const QModelIndexList& indexes) const
QDataStream stream(&encodedData, QIODevice::WriteOnly); QDataStream stream(&encodedData, QIODevice::WriteOnly);
int rows = 0; int rows = 0;
foreach (const QModelIndex& index, indexes) { foreach (const QModelIndex& index, indexes) {
if(!index.column()) { if (!index.column()) {
qint32 item = reinterpret_cast<qint32>(_list.at(index.row())); qint32 item = reinterpret_cast<qint32>(_list.at(index.row()));
stream << item; stream << item;
++rows;
} }
++rows;
} }
// int numRows = 0;
// foreach (const QModelIndex& index, indexes) {
// if (index.isValid() && index.column()) {
// _list.at(index.row())->serialize(stream);
//// if(!index.column()) {
//// numRows++;
//// QString name = data(index, Qt::DisplayRole).toString();
//// stream << name;
//// } else {
//// QString text = data(index, Qt::EditRole).toString();
//// stream << text;
//// }
// }
// }
mimeData->setData(mime_type_notify_table, encodedData); mimeData->setData(mime_type_notify_table, encodedData);
//emit dragRows(indexes.at(0).row(), rows);
dropRows(indexes.at(0).row(), rows);
//_dragStartRow = indexes.at(0).row();
//_dragNumRows = 1/*numRows*/;
return mimeData; return mimeData;
} }

View File

@ -33,72 +33,58 @@
#include <QList> #include <QList>
#include "notificationitem.h" #include "notificationitem.h"
enum ColumnNames { eMESSAGE_NAME, eREPEAT_VALUE, eEXPIRE_TIME, eENABLE_NOTIFICATION }; enum ColumnNames { eMessageName, eRepeatValue, eExpireTimer, eTurnOn };
class NotifyTableModel : public QAbstractTableModel class NotifyTableModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT
enum {eColumnCount = 4 }; enum {eColumnCount = 4 };
public: public:
NotifyTableModel(QList<NotificationItem*>& parentList, QObject* parent = 0); NotifyTableModel(QList<NotificationItem*>& parentList, QObject* parent = 0);
int rowCount(const QModelIndex& parent = QModelIndex()) const
int rowCount(const QModelIndex& parent = QModelIndex()) const
{
return _list.count();
}
int columnCount(const QModelIndex &/*parent*/) const
{
return eColumnCount;
}
Qt::ItemFlags flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
}
Qt::DropActions supportedDropActions() const
{ {
return Qt::MoveAction; return _list.count();
} }
QStringList mimeTypes() const int columnCount(const QModelIndex &/*parent*/) const
{ {
QStringList types; return eColumnCount;
types << "application/vnd.text.list"; }
return types;
}
bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, Qt::ItemFlags flags(const QModelIndex &index) const
int column, const QModelIndex& parent); {
QMimeData* mimeData(const QModelIndexList &indexes) const; if (!index.isValid())
return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
}
QStringList mimeTypes() const;
Qt::DropActions supportedDropActions() const;
bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row,
int column, const QModelIndex& parent);
QMimeData* mimeData(const QModelIndexList &indexes) const;
bool setData(const QModelIndex &index, const QVariant &value, int role); bool setData(const QModelIndex &index, const QVariant &value, int role);
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;
bool insertRows(int position, int rows, const QModelIndex &index); bool insertRows(int position, int rows, const QModelIndex &index);
bool removeRows(int position, int rows, const QModelIndex &index); bool removeRows(int position, int rows, const QModelIndex &index);
void entryAdded(NotificationItem* item);
void entryAdded(NotificationItem* item);
signals: signals:
void dragRows(int position, int count); void dragRows(int position, int count);
private slots: private slots:
void entryUpdated(int offset); void entryUpdated(int offset);
void dropRows(int position, int count) const; void dropRows(int position, int count) const;
private: private:
mutable QList<NotificationItem*>& _list; mutable QList<NotificationItem*>& _list;
QStringList _headerStrings; QStringList _headerStrings;
}; };
#endif // NOTIFYTABLEMODEL_H #endif // NOTIFYTABLEMODEL_H