mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
Notify plugin did not work at all on Linux due to hardcoded backslashes in the path. Now using Qt "native separators" to become multiplatform.
One standing issue: the 1st second of the sound only is played... git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2288 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
94721bf4cc
commit
398ae4f90a
@ -38,7 +38,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "qxttimer.h"
|
#include "qxttimer.h"
|
||||||
|
|
||||||
//#define DEBUG_NOTIFIES
|
#define DEBUG_NOTIFIES
|
||||||
|
|
||||||
SoundNotifyPlugin::SoundNotifyPlugin()
|
SoundNotifyPlugin::SoundNotifyPlugin()
|
||||||
{
|
{
|
||||||
@ -193,10 +193,18 @@ void SoundNotifyPlugin::connectNotifications()
|
|||||||
|
|
||||||
if(lstNotifications.isEmpty()) return;
|
if(lstNotifications.isEmpty()) return;
|
||||||
// set notification message to current event
|
// set notification message to current event
|
||||||
phonon.mo = new Phonon::MediaObject;
|
//phonon.mo = new Phonon::MediaObject;
|
||||||
phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory);
|
phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory);
|
||||||
phonon.ms = new QList<Phonon::MediaSource>;
|
phonon.ms = new QList<Phonon::MediaSource>;
|
||||||
phonon.mo->clear();
|
phonon.mo->clear();
|
||||||
|
phonon.firstPlay = true;
|
||||||
|
#ifdef DEBUG_NOTIFIES
|
||||||
|
QList<Phonon::AudioOutputDevice> audioOutputDevices =
|
||||||
|
Phonon::BackendCapabilities::availableAudioOutputDevices();
|
||||||
|
foreach(Phonon::AudioOutputDevice dev, audioOutputDevices) {
|
||||||
|
qDebug() << "Notify: Audio Output device: " << dev.name() << " - " << dev.description();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
connect(phonon.mo,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
|
connect(phonon.mo,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
|
||||||
this,SLOT(stateChanged(Phonon::State,Phonon::State)));
|
this,SLOT(stateChanged(Phonon::State,Phonon::State)));
|
||||||
}
|
}
|
||||||
@ -281,8 +289,12 @@ void SoundNotifyPlugin::checkNotificationRule(NotifyPluginConfiguration* notific
|
|||||||
|
|
||||||
bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification)
|
bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_NOTIFIES
|
||||||
|
qDebug() << "Phonon State: " << phonon.mo->state();
|
||||||
|
#endif
|
||||||
if((phonon.mo->state()==Phonon::PausedState) ||
|
if((phonon.mo->state()==Phonon::PausedState) ||
|
||||||
(phonon.mo->state()==Phonon::StoppedState))
|
(phonon.mo->state()==Phonon::StoppedState) ||
|
||||||
|
phonon.firstPlay)
|
||||||
{
|
{
|
||||||
// don't fire expire timer
|
// don't fire expire timer
|
||||||
//notification->expire = false;
|
//notification->expire = false;
|
||||||
@ -330,6 +342,8 @@ bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification
|
|||||||
phonon.ms->append(Phonon::MediaSource(item));
|
phonon.ms->append(Phonon::MediaSource(item));
|
||||||
phonon.mo->setQueue(*phonon.ms);
|
phonon.mo->setQueue(*phonon.ms);
|
||||||
phonon.mo->play();
|
phonon.mo->play();
|
||||||
|
phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before
|
||||||
|
// the state is not "Loading" anymore.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false; // if audio is busy
|
return false; // if audio is busy
|
||||||
@ -379,6 +393,10 @@ void SoundNotifyPlugin::expireTimerHandler()
|
|||||||
void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldstate)
|
void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldstate)
|
||||||
{
|
{
|
||||||
Q_UNUSED(oldstate)
|
Q_UNUSED(oldstate)
|
||||||
|
|
||||||
|
#ifdef DEBUG_NOTIFIES
|
||||||
|
qDebug() << "File length (ms): " << phonon.mo->totalTime();
|
||||||
|
#endif
|
||||||
if((newstate == Phonon::PausedState) ||
|
if((newstate == Phonon::PausedState) ||
|
||||||
(newstate == Phonon::StoppedState))
|
(newstate == Phonon::StoppedState))
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@ typedef struct {
|
|||||||
Phonon::MediaObject* mo;
|
Phonon::MediaObject* mo;
|
||||||
QList<Phonon::MediaSource>* ms;
|
QList<Phonon::MediaSource>* ms;
|
||||||
NotifyPluginConfiguration* notify;
|
NotifyPluginConfiguration* notify;
|
||||||
|
bool firstPlay;
|
||||||
} PhononObject, *pPhononObject;
|
} PhononObject, *pPhononObject;
|
||||||
|
|
||||||
class SoundNotifyPlugin : public ExtensionSystem::IPlugin
|
class SoundNotifyPlugin : public ExtensionSystem::IPlugin
|
||||||
|
@ -101,28 +101,28 @@ QString NotifyPluginConfiguration::parseNotifyMessage()
|
|||||||
// generate queue of sound files to play
|
// generate queue of sound files to play
|
||||||
notifyMessageList.clear();
|
notifyMessageList.clear();
|
||||||
|
|
||||||
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound1()+".wav"))
|
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ getCurrentLanguage()+"/"+getSound1()+".wav")))
|
||||||
notifyMessageList.append(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound1()+".wav");
|
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + getCurrentLanguage()+"/"+getSound1()+".wav"));
|
||||||
else
|
else
|
||||||
if(QFile::exists(getSoundCollectionPath()+"\\default\\"+getSound2()+".wav"))
|
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "default/"+getSound2()+".wav")))
|
||||||
notifyMessageList.append(getSoundCollectionPath()+"\\default\\"+getSound1()+".wav");
|
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + "default/"+getSound1()+".wav"));
|
||||||
|
|
||||||
if(getSound2()!="")
|
if(getSound2()!="")
|
||||||
{
|
{
|
||||||
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound2()+".wav"))
|
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + getCurrentLanguage()+"/"+getSound2()+".wav")))
|
||||||
notifyMessageList.append(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound2()+".wav");
|
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + getCurrentLanguage()+"/"+getSound2()+".wav"));
|
||||||
else
|
else
|
||||||
if(QFile::exists(getSoundCollectionPath()+"\\"+"\\default\\"+"\\"+getSound2()+".wav"))
|
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "default/"+getSound2()+".wav")))
|
||||||
notifyMessageList.append(getSoundCollectionPath()+"\\default\\"+getSound2()+".wav");
|
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + "default/"+getSound2()+".wav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getSound3()!="")
|
if(getSound3()!="")
|
||||||
{
|
{
|
||||||
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound3()+".wav"))
|
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+getCurrentLanguage()+"/"+getSound3()+".wav")))
|
||||||
notifyMessageList.append(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound3()+".wav");
|
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath()+getCurrentLanguage()+"/"+getSound3()+".wav"));
|
||||||
else
|
else
|
||||||
if(QFile::exists(getSoundCollectionPath()+"\\"+"\\default\\"+"\\"+getSound3()+".wav"))
|
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"default/"+getSound3()+".wav")))
|
||||||
notifyMessageList.append(getSoundCollectionPath()+"\\default\\"+getSound3()+".wav");
|
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath()+"default/"+getSound3()+".wav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(str1.at(0).toAscii())
|
switch(str1.at(0).toAscii())
|
||||||
@ -204,12 +204,12 @@ QString NotifyPluginConfiguration::parseNotifyMessage()
|
|||||||
}
|
}
|
||||||
foreach(QString fileName,numberFiles) {
|
foreach(QString fileName,numberFiles) {
|
||||||
fileName+=".wav";
|
fileName+=".wav";
|
||||||
QString filePath = getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+fileName;
|
QString filePath = getSoundCollectionPath()+ QDir::toNativeSeparators(getCurrentLanguage()+"/"+fileName);
|
||||||
if(QFile::exists(filePath))
|
if(QFile::exists(filePath))
|
||||||
notifyMessageList.insert(position++,getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+fileName);
|
notifyMessageList.insert(position++,getSoundCollectionPath()+ QDir::toNativeSeparators(getCurrentLanguage()+"/"+fileName));
|
||||||
else {
|
else {
|
||||||
if(QFile::exists(getSoundCollectionPath()+"\\default\\"+fileName))
|
if(QFile::exists(getSoundCollectionPath()+QDir::toNativeSeparators("default/"+fileName)))
|
||||||
notifyMessageList.insert(position++,getSoundCollectionPath()+"\\default\\"+fileName);
|
notifyMessageList.insert(position++,getSoundCollectionPath()+QDir::toNativeSeparators("default/"+fileName));
|
||||||
else {
|
else {
|
||||||
notifyMessageList.clear();
|
notifyMessageList.clear();
|
||||||
break; // if no some of *.wav files, then don't play number!
|
break; // if no some of *.wav files, then don't play number!
|
||||||
|
@ -287,7 +287,8 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int index)
|
|||||||
{
|
{
|
||||||
options_page->SoundCollectionList->setCurrentIndex(index);
|
options_page->SoundCollectionList->setCurrentIndex(index);
|
||||||
|
|
||||||
currentCollectionPath = options_page->SoundDirectoryPathChooser->path() +"\\"+options_page->SoundCollectionList->currentText();
|
currentCollectionPath = options_page->SoundDirectoryPathChooser->path() +
|
||||||
|
QDir::toNativeSeparators("/" + options_page->SoundCollectionList->currentText());
|
||||||
|
|
||||||
QDir dirPath(currentCollectionPath);
|
QDir dirPath(currentCollectionPath);
|
||||||
QStringList filters;
|
QStringList filters;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user