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

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

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

View File

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

View File

@ -40,11 +40,6 @@ using namespace Core;
QString getSound##number() const { return _sound##number; } \ QString getSound##number() const { return _sound##number; } \
void setSound##number(QString text) { _sound##number = text; } \ void setSound##number(QString text) { _sound##number = text; } \
// QString getSound2() const { return _sound2; }
// void setSound2(QString text) { _sound2 = text; }
// QString getSound3() const { return _sound3; }
// void setSound3(QString text) { _sound3 = text; }
class NotificationItem : public QObject class NotificationItem : public QObject
{ {
@ -97,14 +92,35 @@ public:
void saveState(QSettings* settings) const; void saveState(QSettings* settings) const;
void restoreState(QSettings* settings); void restoreState(QSettings* settings);
QString parseNotifyMessage(); QString parseNotifyMessage();
QTimer* timer; QTimer* getTimer() const { return _timer; }
QTimer* expireTimer; void startTimer(int value);
bool isNowPlaying; // void stopTimer();
void disposeTimer();
QTimer* getExpireTimer() const { return _expireTimer; }
void startExpireTimer();
void stopExpireTimer();
void disposeExpireTimer();
bool isNowPlaying;
bool firstStart; bool firstStart;
private: private:
void checkSoundFilesExisting();
private:
QTimer* _timer;
//! time from putting notification in queue till moment when notification became out-of-date
//! NOTE: each notification has it lifetime, this time setups individually for each notification
//! according to its priority
QTimer* _expireTimer;
QStringList _messageSequence; QStringList _messageSequence;

View File

@ -25,38 +25,38 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "NotificationItem.h" #include "notificationitem.h"
#include "notifylogging.h"
#include <QtCore/QDataStream> #include <QtCore/QDataStream>
#include <QFile> #include <QFile>
#include "utils/pathutils.h" #include "utils/pathutils.h"
NotificationItem::NotificationItem(QObject *parent) : NotificationItem::NotificationItem(QObject *parent)
QObject(parent), : QObject(parent)
isNowPlaying(0), , isNowPlaying(0)
firstStart(1), , firstStart(true)
_soundCollectionPath(""), , _soundCollectionPath("")
_currentLanguage("default"), , _currentLanguage("default")
_dataObject(""), , _dataObject("")
_objectField(""), , _objectField("")
_dataValue("Equal to"), , _dataValue("Equal to")
_sound1(""), , _sound1("")
_sound2(""), , _sound2("")
_sound3(""), , _sound3("")
_sayOrder("Never"), , _sayOrder("Never")
_spinBoxValue(0), , _spinBoxValue(0)
_repeatString("Repeat Instantly"), , _repeatString("Repeat Instantly")
_repeatTimeout(true), , _repeatTimeout(true)
_expireTimeout(15) , _expireTimeout(15)
{ {
timer = NULL; _timer = NULL;
expireTimer = NULL; _expireTimer = NULL;
} }
void NotificationItem::copyTo(NotificationItem* that) const void NotificationItem::copyTo(NotificationItem* that) const
{ {
that->isNowPlaying = isNowPlaying; that->isNowPlaying = isNowPlaying;
that->firstStart = firstStart; that->firstStart = firstStart;
that->_soundCollectionPath = _soundCollectionPath; that->_soundCollectionPath = _soundCollectionPath;
@ -110,6 +110,53 @@ void NotificationItem::restoreState(QSettings* settings)
} }
void NotificationItem::startTimer(int value) {
if (!_timer) {
_timer = new QTimer(this);
_timer->setInterval(value);
}
if (!_timer->isActive())
_timer->start();
}
void NotificationItem::stopTimer() {
if (_timer) {
if (_timer->isActive())
_timer->stop();
}
}
void NotificationItem::disposeTimer() {
if (_timer) {
_timer->stop();
delete _timer;
_timer = NULL;
}
}
void NotificationItem::startExpireTimer() {
if (!_expireTimer)
{
_expireTimer = new QTimer(this);
}
_expireTimer->start(_expireTimeout * 1000);
}
void NotificationItem::stopExpireTimer() {
if (_expireTimer) {
if (_expireTimer)
_expireTimer->stop();
}
}
void NotificationItem::disposeExpireTimer() {
if (_expireTimer) {
_expireTimer->stop();
delete _expireTimer;
_expireTimer = NULL;
}
}
QString NotificationItem::parseNotifyMessage() QString NotificationItem::parseNotifyMessage()
{ {
// tips: // tips:
@ -123,28 +170,10 @@ QString NotificationItem::parseNotifyMessage()
// generate queue of sound files to play // generate queue of sound files to play
_messageSequence.clear(); _messageSequence.clear();
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"))) checkSoundFilesExisting();
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"));
if("" != getSound2()) if(!_messageSequence.size()) {
{ qNotifyDebug() << "no any files in message queue";
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"));
}
if("" != getSound3())
{
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"));
} }
switch(str1.at(0).toAscii()) switch(str1.at(0).toAscii())
@ -241,3 +270,32 @@ QString NotificationItem::parseNotifyMessage()
} }
return str; return str;
} }
void NotificationItem::checkSoundFilesExisting() {
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound1()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound1()+".wav"));
if(!getSound2().size())
{
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/" + getCurrentLanguage()+"/"+getSound2()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath() + "/default/"+getSound2()+".wav"));
}
if(!getSound3().size())
{
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+ "/" + getCurrentLanguage()+"/"+getSound3()+".wav"));
else
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav")))
_messageSequence.append(QDir::toNativeSeparators(getSoundCollectionPath()+"/default/"+getSound3()+".wav"));
}
}

View File

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

View File

@ -28,7 +28,7 @@
#include <QtGui> #include <QtGui>
#include "notifyitemdelegate.h" #include "notifyitemdelegate.h"
#include "notifytablemodel.h" #include "notifytablemodel.h"
#include "notifylogging.h"
NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent) NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent)
: QItemDelegate(parent) : QItemDelegate(parent)
@ -38,22 +38,21 @@ NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent)
} }
QWidget *NotifyItemDelegate::createEditor(QWidget* parent, QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*none*/,
const QStyleOptionViewItem& /*none*/,
const QModelIndex& index) const const QModelIndex& index) const
{ {
if(eREPEAT_VALUE == index.column()) { if (eREPEAT_VALUE == index.column()) {
QComboBox* editor = new QComboBox(parent); QComboBox* editor = new QComboBox(parent);
editor->clear(); editor->clear();
editor->addItems(_items); editor->addItems(_items);
return editor; return editor;
} else { } else {
if(eEXPIRE_TIME == index.column()) { if (eEXPIRE_TIME == index.column()) {
QSpinBox* editor = new QSpinBox(parent); QSpinBox* editor = new QSpinBox(parent);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
return editor; return editor;
} else { } else {
if(eENABLE_NOTIFICATION == index.column()) { if (eENABLE_NOTIFICATION == index.column()) {
QCheckBox* editor = new QCheckBox(parent); QCheckBox* editor = new QCheckBox(parent);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
return editor; return editor;
@ -97,15 +96,15 @@ void NotifyItemDelegate::commitAndCloseEditor()
void NotifyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const void NotifyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{ {
QLineEdit* edit = qobject_cast<QLineEdit*>(editor); QLineEdit* edit = qobject_cast<QLineEdit*>(editor);
if(edit) { if (edit) {
edit->setText(index.model()->data(index, Qt::EditRole).toString()); edit->setText(index.model()->data(index, Qt::EditRole).toString());
} else { } else {
QComboBox* repeatEditor = qobject_cast<QComboBox *>(editor); QComboBox* repeatEditor = qobject_cast<QComboBox *>(editor);
if(repeatEditor) if (repeatEditor)
repeatEditor->setCurrentIndex(repeatEditor->findText(index.model()->data(index, Qt::EditRole).toString())); repeatEditor->setCurrentIndex(repeatEditor->findText(index.model()->data(index, Qt::EditRole).toString()));
else { else {
QSpinBox* expireEditor = qobject_cast<QSpinBox *>(editor); QSpinBox* expireEditor = qobject_cast<QSpinBox *>(editor);
if(expireEditor) if (expireEditor)
expireEditor->setValue(index.model()->data(index, Qt::EditRole).toInt()); expireEditor->setValue(index.model()->data(index, Qt::EditRole).toInt());
else { else {
QCheckBox* enablePlayEditor = qobject_cast<QCheckBox *>(editor); QCheckBox* enablePlayEditor = qobject_cast<QCheckBox *>(editor);
@ -119,15 +118,15 @@ void NotifyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index
void NotifyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const void NotifyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{ {
QLineEdit *edit = qobject_cast<QLineEdit *>(editor); QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
if(edit) { if (edit) {
model->setData(index, edit->text()); model->setData(index, edit->text());
} else { } else {
QComboBox * repeatEditor = qobject_cast<QComboBox *>(editor); QComboBox * repeatEditor = qobject_cast<QComboBox *>(editor);
if(repeatEditor) { if (repeatEditor) {
model->setData(index, repeatEditor->currentText()); model->setData(index, repeatEditor->currentText());
} else { } else {
QSpinBox * expireEditor = qobject_cast<QSpinBox *>(editor); QSpinBox * expireEditor = qobject_cast<QSpinBox *>(editor);
if(expireEditor) { if (expireEditor) {
model->setData(index, expireEditor->value(), Qt::EditRole); model->setData(index, expireEditor->value(), Qt::EditRole);
} else { } else {
QCheckBox* enablePlayEditor = qobject_cast<QCheckBox*>(editor); QCheckBox* enablePlayEditor = qobject_cast<QCheckBox*>(editor);
@ -139,19 +138,18 @@ void NotifyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model
} }
} }
void NotifyItemDelegate::selectRow(const QString & text) void NotifyItemDelegate::selectRow(const QString& text)
{ {
QComboBox* combo = qobject_cast<QComboBox*>(sender()); QComboBox* combo = qobject_cast<QComboBox*>(sender());
QTableWidget* table = new QTableWidget; QTableWidget* table = new QTableWidget;
table = (QTableWidget*)(combo->parent()); table = (QTableWidget*)(combo->parent());
qDebug() << table->columnCount(); qNotifyDebug() << table->columnCount();
qDebug() << table->rowCount(); qNotifyDebug() << table->rowCount();
qDebug() << table->currentRow(); qNotifyDebug() << table->currentRow();
} }
QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem & option, QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
const QModelIndex & index) const
{ {
QSize s = QItemDelegate::sizeHint(option, index); QSize s = QItemDelegate::sizeHint(option, index);
s.setHeight(10); s.setHeight(10);

View File

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

View File

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

View File

@ -28,6 +28,7 @@
#include "notifyplugin.h" #include "notifyplugin.h"
#include "notificationitem.h" #include "notificationitem.h"
#include "notifypluginoptionspage.h" #include "notifypluginoptionspage.h"
#include "notifylogging.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <QDebug> #include <QDebug>
#include <QtPlugin> #include <QtPlugin>
@ -43,18 +44,6 @@ static const QString VERSION = "1.0.0";
//#define DEBUG_NOTIFIES //#define DEBUG_NOTIFIES
#ifdef DEBUG_NOTIFIES
QDebug qNotifyDebug()
#endif
#ifndef DEBUG_NOTIFIES
QNoDebug qNotifyDebug()
#endif
{
#ifdef DEBUG_NOTIFIES
return qDebug();
#endif
return QNoDebug();
}
SoundNotifyPlugin::SoundNotifyPlugin() SoundNotifyPlugin::SoundNotifyPlugin()
{ {
@ -173,12 +162,12 @@ void SoundNotifyPlugin::readConfig_0_0_0(){
connectNotifications(); connectNotifications();
configured = true; configured = true;
} }
void SoundNotifyPlugin::onTelemetryManagerAdded(QObject* obj) void SoundNotifyPlugin::onTelemetryManagerAdded(QObject* obj)
{ {
telMngr = qobject_cast<TelemetryManager *>(obj); telMngr = qobject_cast<TelemetryManager *>(obj);
if(telMngr) if (telMngr)
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
} }
@ -199,21 +188,11 @@ void SoundNotifyPlugin::onAutopilotDisconnect()
void SoundNotifyPlugin::resetNotification(void) void SoundNotifyPlugin::resetNotification(void)
{ {
//first, reject empty args and unknown fields. //first, reject empty args and unknown fields.
foreach(NotificationItem* notify,lstNotifications) { foreach(NotificationItem* ntf, lstNotifications) {
if(notify->timer) ntf->disposeTimer();
{ disconnect(ntf->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
disconnect(notify->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler())); ntf->disposeExpireTimer();
notify->timer->stop(); disconnect(ntf->getExpireTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
delete notify->timer;
notify->timer = NULL;
}
if(notify->expireTimer)
{
disconnect(notify->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
notify->expireTimer->stop();
delete notify->expireTimer;
notify->expireTimer = NULL;
}
} }
} }
@ -238,12 +217,12 @@ void SoundNotifyPlugin::connectNotifications()
if (obj != NULL) if (obj != NULL)
disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(appendNotification(UAVObject*))); disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(appendNotification(UAVObject*)));
} }
if(phonon.mo != NULL) { if (phonon.mo != NULL) {
delete phonon.mo; delete phonon.mo;
phonon.mo = NULL; phonon.mo = NULL;
} }
if(!enableSound) return; if (!enableSound) return;
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
@ -260,7 +239,7 @@ void SoundNotifyPlugin::connectNotifications()
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*)));
} }
@ -268,7 +247,7 @@ void SoundNotifyPlugin::connectNotifications()
std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl; std::cout << "Error: Object is unknown (" << notify->getDataObject().toStdString() << ")." << std::endl;
} }
if(lstNotifications.isEmpty()) return; if (lstNotifications.isEmpty()) return;
// set notification message to current event // set notification message to current event
phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory); phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory);
phonon.mo->clearQueue(); phonon.mo->clearQueue();
@ -286,18 +265,18 @@ void SoundNotifyPlugin::appendNotification(UAVObject *object)
{ {
disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
foreach(NotificationItem* notification, lstNotifications) { foreach(NotificationItem* ntf, lstNotifications) {
if(object->getName()!=notification->getDataObject()) if (object->getName() != ntf->getDataObject())
continue; continue;
if(nowPlayingConfiguration == notification) if (nowPlayingConfiguration == ntf)
continue; continue;
if(notification->getRepeatFlag()!= "Repeat Instantly" && if (ntf->getRepeatFlag()!= "Repeat Instantly" &&
notification->getRepeatFlag()!= "Repeat Once" && !notification->firstStart) ntf->getRepeatFlag()!= "Repeat Once" && !ntf->firstStart)
continue; continue;
checkNotificationRule(notification,object); checkNotificationRule(ntf,object);
} }
connect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*))); connect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
} }
@ -319,42 +298,35 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA
switch(direction[0].toAscii()) switch(direction[0].toAscii())
{ {
case 'E': case 'E':
if(value==threshold) if (value==threshold)
condition = true; condition = true;
break; break;
case 'G': case 'G':
if(value>threshold) if (value>threshold)
condition = true; condition = true;
break; break;
case 'L': case 'L':
if(value<threshold) if (value<threshold)
condition = true; condition = true;
break; break;
} }
} }
if(condition) if (condition)
{ {
if(!playNotification(notification)) if (!playNotification(notification))
{ {
if(!pendingNotifications.contains(notification)) if (!pendingNotifications.contains(notification))
{ {
if(notification->timer) notification->stopTimer();
if(notification->timer->isActive())
notification->timer->stop(); qNotifyDebug() << "add to pending list - " << notification->parseNotifyMessage();
#ifdef DEBUG_NOTIFIES
qDebug() << "add to pending list - " << notification->parseNotifyMessage();
#endif
// 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));
pendingNotifications.append(notification); pendingNotifications.append(notification);
if(!notification->expireTimer) notification->startExpireTimer();
{ connect(notification->getExpireTimer(), SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
notification->expireTimer = new QTimer(notification);
connect(notification->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
}
notification->expireTimer->start(notification->getExpireTimeout()*1000);
} }
} }
} }
@ -366,26 +338,21 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
if (phonon.mo == NULL) if (phonon.mo == NULL)
return false; return false;
if(!notification->getEnableFlag()) return true; if (!notification->getEnableFlag()) return true;
#ifdef DEBUG_NOTIFIES qNotifyDebug() << "Phonon State: " << phonon.mo->state();
qDebug() << "Phonon State: " << phonon.mo->state(); if ((phonon.mo->state()==Phonon::PausedState)
#endif
if((phonon.mo->state()==Phonon::PausedState)
|| (phonon.mo->state()==Phonon::StoppedState) || (phonon.mo->state()==Phonon::StoppedState)
|| phonon.firstPlay) || phonon.firstPlay)
{ {
// don't fire expire timer // don't fire expire timer
nowPlayingConfiguration = notification; nowPlayingConfiguration = notification;
if(notification->expireTimer) notification->stopExpireTimer();
notification->expireTimer->stop();
if(notification->getRepeatFlag()=="Repeat Once") if (notification->getRepeatFlag()=="Repeat Once") {
{
removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification))); removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification)));
} } else {
else { if (notification->getRepeatFlag()!="Repeat Instantly")
if(notification->getRepeatFlag()!="Repeat Instantly")
{ {
QRegExp rxlen("(\\d+)"); QRegExp rxlen("(\\d+)");
QString value; QString value;
@ -396,22 +363,15 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage
} }
if(!notification->timer) notification->startTimer(timer_value);
{ connect(notification->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
notification->timer = new QTimer(notification);
notification->timer->setInterval(timer_value);
connect(notification->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
}
if(!notification->timer->isActive())
notification->timer->start();
} }
} }
notification->firstStart=false; notification->firstStart=false;
phonon.mo->clear(); phonon.mo->clear();
QString str = notification->parseNotifyMessage(); QString str = notification->parseNotifyMessage();
qNotifyDebug() << "play notification - " << str; qNotifyDebug() << "play notification - " << str;
foreach (QString item, notification->getMessageSequence()) {
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);
@ -429,13 +389,13 @@ 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());
#ifdef DEBUG_NOTIFIES
qDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage(); qNotifyDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage();
#endif
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVObject* object = objManager->getObject(notification->getDataObject()); UAVObject* object = objManager->getObject(notification->getDataObject());
if(object) if (object)
checkNotificationRule(notification,object); checkNotificationRule(notification,object);
} }
@ -443,13 +403,10 @@ void SoundNotifyPlugin::expireTimerHandler()
{ {
// fire expire timer // fire expire timer
NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent()); NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent());
notification->expireTimer->stop(); notification->stopExpireTimer();
if(!pendingNotifications.isEmpty()) if (!pendingNotifications.isEmpty()) {
{ qNotifyDebug() << "expireTimerHandler - " << notification->parseNotifyMessage();
#ifdef DEBUG_NOTIFIES
qDebug() << "expireTimerHandler - " << notification->parseNotifyMessage();
#endif
pendingNotifications.removeOne(notification); pendingNotifications.removeOne(notification);
} }
} }
@ -458,10 +415,8 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
{ {
Q_UNUSED(oldstate) Q_UNUSED(oldstate)
#ifdef DEBUG_NOTIFIES qNotifyDebug() << "File length (ms): " << phonon.mo->totalTime();
qDebug() << "File length (ms): " << phonon.mo->totalTime(); qNotifyDebug() << "New State: " << newstate;
qDebug() << "New State: " << newstate;
#endif
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
// This is a hack to force Linux to wait until the end of the // This is a hack to force Linux to wait until the end of the
@ -471,27 +426,24 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
if (phonon.mo->totalTime()>0) if (phonon.mo->totalTime()>0)
phonon.mo->setTransitionTime(phonon.mo->totalTime()); phonon.mo->setTransitionTime(phonon.mo->totalTime());
#endif #endif
if((newstate == Phonon::PausedState) || if ((newstate == Phonon::PausedState) ||
(newstate == Phonon::StoppedState)) (newstate == Phonon::StoppedState))
{ {
nowPlayingConfiguration=NULL; nowPlayingConfiguration=NULL;
if(!pendingNotifications.isEmpty()) if (!pendingNotifications.isEmpty())
{ {
NotificationItem* notification = pendingNotifications.takeFirst(); NotificationItem* notification = pendingNotifications.takeFirst();
#ifdef DEBUG_NOTIFIES qNotifyDebug() << "play audioFree - " << notification->parseNotifyMessage();
qDebug() << "play audioFree - " << notification->parseNotifyMessage();
#endif
playNotification(notification); playNotification(notification);
} }
} else if (newstate == Phonon::ErrorState) } else {
{ if (newstate == Phonon::ErrorState) {
if(phonon.mo->errorType()==0) { if (phonon.mo->errorType()==0) {
qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType(); qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType();
phonon.mo->clearQueue(); phonon.mo->clearQueue();
} }
} }
// if(newstate == Phonon::BufferingState) }
// qDebug() << "Phonon::BufferingState!!!";
} }
Q_EXPORT_PLUGIN(SoundNotifyPlugin) Q_EXPORT_PLUGIN(SoundNotifyPlugin)

View File

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

View File

@ -92,9 +92,8 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
connect(this, SIGNAL(updateNotifications(QList<NotificationItem*>)), connect(this, SIGNAL(updateNotifications(QList<NotificationItem*>)),
owner, SLOT(updateNotificationList(QList<NotificationItem*>))); owner, SLOT(updateNotificationList(QList<NotificationItem*>)));
connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); //connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification()));
//emit resetNotification();
privListNotifications.clear(); privListNotifications.clear();
@ -412,7 +411,7 @@ void NotifyPluginOptionsPage::on_buttonAddNotification_clicked()
notification->setSound2(options_page->Sound2->currentText()); notification->setSound2(options_page->Sound2->currentText());
notification->setSound3(options_page->Sound3->currentText()); notification->setSound3(options_page->Sound3->currentText());
if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second")) if ( ((!options_page->Sound2->currentText().size()) && (options_page->SayOrder->currentText()=="After second"))
|| ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) { || ((!options_page->Sound3->currentText().size()) && (options_page->SayOrder->currentText()=="After third")) ) {
return; return;
} else { } else {

View File

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

View File

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