1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

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

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

View File

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

View File

@ -40,11 +40,6 @@ using namespace Core;
QString getSound##number() const { return _sound##number; } \
void setSound##number(QString text) { _sound##number = text; } \
// QString getSound2() const { return _sound2; }
// void setSound2(QString text) { _sound2 = text; }
// QString getSound3() const { return _sound3; }
// void setSound3(QString text) { _sound3 = text; }
class NotificationItem : public QObject
{
@ -97,14 +92,35 @@ public:
void saveState(QSettings* settings) const;
void restoreState(QSettings* settings);
QString parseNotifyMessage();
QTimer* timer;
QTimer* expireTimer;
bool isNowPlaying; //
QTimer* getTimer() const { return _timer; }
void startTimer(int value);
void stopTimer();
void disposeTimer();
QTimer* getExpireTimer() const { return _expireTimer; }
void startExpireTimer();
void stopExpireTimer();
void disposeExpireTimer();
bool isNowPlaying;
bool firstStart;
private:
void checkSoundFilesExisting();
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;

View File

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

View File

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

View File

@ -28,7 +28,7 @@
#include <QtGui>
#include "notifyitemdelegate.h"
#include "notifytablemodel.h"
#include "notifylogging.h"
NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent)
: QItemDelegate(parent)
@ -38,8 +38,7 @@ NotifyItemDelegate::NotifyItemDelegate(QStringList items, QObject* parent)
}
QWidget *NotifyItemDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem& /*none*/,
QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*none*/,
const QModelIndex& index) const
{
if (eREPEAT_VALUE == index.column()) {
@ -145,13 +144,12 @@ void NotifyItemDelegate::selectRow(const QString & text)
QTableWidget* table = new QTableWidget;
table = (QTableWidget*)(combo->parent());
qDebug() << table->columnCount();
qDebug() << table->rowCount();
qDebug() << table->currentRow();
qNotifyDebug() << table->columnCount();
qNotifyDebug() << table->rowCount();
qNotifyDebug() << table->currentRow();
}
QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem & option,
const QModelIndex & index) const
QSize NotifyItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QSize s = QItemDelegate::sizeHint(option, index);
s.setHeight(10);

View File

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

View File

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

View File

@ -28,6 +28,7 @@
#include "notifyplugin.h"
#include "notificationitem.h"
#include "notifypluginoptionspage.h"
#include "notifylogging.h"
#include <coreplugin/icore.h>
#include <QDebug>
#include <QtPlugin>
@ -43,18 +44,6 @@ static const QString VERSION = "1.0.0";
//#define DEBUG_NOTIFIES
#ifdef DEBUG_NOTIFIES
QDebug qNotifyDebug()
#endif
#ifndef DEBUG_NOTIFIES
QNoDebug qNotifyDebug()
#endif
{
#ifdef DEBUG_NOTIFIES
return qDebug();
#endif
return QNoDebug();
}
SoundNotifyPlugin::SoundNotifyPlugin()
{
@ -199,21 +188,11 @@ void SoundNotifyPlugin::onAutopilotDisconnect()
void SoundNotifyPlugin::resetNotification(void)
{
//first, reject empty args and unknown fields.
foreach(NotificationItem* notify,lstNotifications) {
if(notify->timer)
{
disconnect(notify->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
notify->timer->stop();
delete notify->timer;
notify->timer = NULL;
}
if(notify->expireTimer)
{
disconnect(notify->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
notify->expireTimer->stop();
delete notify->expireTimer;
notify->expireTimer = NULL;
}
foreach(NotificationItem* ntf, lstNotifications) {
ntf->disposeTimer();
disconnect(ntf->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
ntf->disposeExpireTimer();
disconnect(ntf->getExpireTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
}
}
@ -286,18 +265,18 @@ void SoundNotifyPlugin::appendNotification(UAVObject *object)
{
disconnect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
foreach(NotificationItem* notification, lstNotifications) {
if(object->getName()!=notification->getDataObject())
foreach(NotificationItem* ntf, lstNotifications) {
if (object->getName() != ntf->getDataObject())
continue;
if(nowPlayingConfiguration == notification)
if (nowPlayingConfiguration == ntf)
continue;
if(notification->getRepeatFlag()!= "Repeat Instantly" &&
notification->getRepeatFlag()!= "Repeat Once" && !notification->firstStart)
if (ntf->getRepeatFlag()!= "Repeat Instantly" &&
ntf->getRepeatFlag()!= "Repeat Once" && !ntf->firstStart)
continue;
checkNotificationRule(notification,object);
checkNotificationRule(ntf,object);
}
connect(object, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(appendNotification(UAVObject*)));
}
@ -339,22 +318,15 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA
{
if (!pendingNotifications.contains(notification))
{
if(notification->timer)
if(notification->timer->isActive())
notification->timer->stop();
#ifdef DEBUG_NOTIFIES
qDebug() << "add to pending list - " << notification->parseNotifyMessage();
#endif
notification->stopTimer();
qNotifyDebug() << "add to pending list - " << notification->parseNotifyMessage();
// if audio is busy, start expiration timer
//ms = (notification->getExpiredTimeout()[in sec])*1000
//QxtTimer::singleShot(notification->getExpireTimeout()*1000, this, SLOT(expirationTimerHandler(NotificationItem*)), qVariantFromValue(notification));
pendingNotifications.append(notification);
if(!notification->expireTimer)
{
notification->expireTimer = new QTimer(notification);
connect(notification->expireTimer, SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
}
notification->expireTimer->start(notification->getExpireTimeout()*1000);
notification->startExpireTimer();
connect(notification->getExpireTimer(), SIGNAL(timeout()), this, SLOT(expireTimerHandler()));
}
}
}
@ -368,23 +340,18 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
if (!notification->getEnableFlag()) return true;
#ifdef DEBUG_NOTIFIES
qDebug() << "Phonon State: " << phonon.mo->state();
#endif
qNotifyDebug() << "Phonon State: " << phonon.mo->state();
if ((phonon.mo->state()==Phonon::PausedState)
|| (phonon.mo->state()==Phonon::StoppedState)
|| phonon.firstPlay)
{
// don't fire expire timer
nowPlayingConfiguration = notification;
if(notification->expireTimer)
notification->expireTimer->stop();
notification->stopExpireTimer();
if(notification->getRepeatFlag()=="Repeat Once")
{
if (notification->getRepeatFlag()=="Repeat Once") {
removedNotifies.append(lstNotifications.takeAt(lstNotifications.indexOf(notification)));
}
else {
} else {
if (notification->getRepeatFlag()!="Repeat Instantly")
{
QRegExp rxlen("(\\d+)");
@ -396,21 +363,14 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
timer_value = (value.toInt()+8)*1000; //ms*1000 + average duration of meassage
}
if(!notification->timer)
{
notification->timer = new QTimer(notification);
notification->timer->setInterval(timer_value);
connect(notification->timer, SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
}
if(!notification->timer->isActive())
notification->timer->start();
notification->startTimer(timer_value);
connect(notification->getTimer(), SIGNAL(timeout()), this, SLOT(repeatTimerHandler()));
}
}
notification->firstStart=false;
phonon.mo->clear();
QString str = notification->parseNotifyMessage();
qNotifyDebug() << "play notification - " << str;
foreach (QString item, notification->getMessageSequence()) {
Phonon::MediaSource *ms = new Phonon::MediaSource(item);
ms->setAutoDelete(true);
@ -429,9 +389,9 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
void SoundNotifyPlugin::repeatTimerHandler()
{
NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent());
#ifdef DEBUG_NOTIFIES
qDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage();
#endif
qNotifyDebug() << "repeatTimerHandler - " << notification->parseNotifyMessage();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVObject* object = objManager->getObject(notification->getDataObject());
@ -443,13 +403,10 @@ void SoundNotifyPlugin::expireTimerHandler()
{
// fire expire timer
NotificationItem* notification = static_cast<NotificationItem*>(sender()->parent());
notification->expireTimer->stop();
notification->stopExpireTimer();
if(!pendingNotifications.isEmpty())
{
#ifdef DEBUG_NOTIFIES
qDebug() << "expireTimerHandler - " << notification->parseNotifyMessage();
#endif
if (!pendingNotifications.isEmpty()) {
qNotifyDebug() << "expireTimerHandler - " << notification->parseNotifyMessage();
pendingNotifications.removeOne(notification);
}
}
@ -458,10 +415,8 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
{
Q_UNUSED(oldstate)
#ifdef DEBUG_NOTIFIES
qDebug() << "File length (ms): " << phonon.mo->totalTime();
qDebug() << "New State: " << newstate;
#endif
qNotifyDebug() << "File length (ms): " << phonon.mo->totalTime();
qNotifyDebug() << "New State: " << newstate;
#ifndef Q_OS_WIN
// This is a hack to force Linux to wait until the end of the
@ -478,20 +433,17 @@ void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldst
if (!pendingNotifications.isEmpty())
{
NotificationItem* notification = pendingNotifications.takeFirst();
#ifdef DEBUG_NOTIFIES
qDebug() << "play audioFree - " << notification->parseNotifyMessage();
#endif
qNotifyDebug() << "play audioFree - " << notification->parseNotifyMessage();
playNotification(notification);
}
} else if (newstate == Phonon::ErrorState)
{
} else {
if (newstate == Phonon::ErrorState) {
if (phonon.mo->errorType()==0) {
qDebug() << "Phonon::ErrorState: ErrorType = " << phonon.mo->errorType();
phonon.mo->clearQueue();
}
}
// if(newstate == Phonon::BufferingState)
// qDebug() << "Phonon::BufferingState!!!";
}
}
Q_EXPORT_PLUGIN(SoundNotifyPlugin)

View File

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

View File

@ -92,9 +92,8 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
connect(this, SIGNAL(updateNotifications(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();

View File

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

View File

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