1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +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:
edouard 2010-12-26 18:55:28 +00:00 committed by edouard
parent 94721bf4cc
commit 398ae4f90a
4 changed files with 43 additions and 23 deletions

View File

@ -38,7 +38,7 @@
#include <iostream>
#include "qxttimer.h"
//#define DEBUG_NOTIFIES
#define DEBUG_NOTIFIES
SoundNotifyPlugin::SoundNotifyPlugin()
{
@ -193,10 +193,18 @@ void SoundNotifyPlugin::connectNotifications()
if(lstNotifications.isEmpty()) return;
// set notification message to current event
phonon.mo = new Phonon::MediaObject;
phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory);
phonon.ms = new QList<Phonon::MediaSource>;
phonon.mo->clear();
//phonon.mo = new Phonon::MediaObject;
phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory);
phonon.ms = new QList<Phonon::MediaSource>;
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)),
this,SLOT(stateChanged(Phonon::State,Phonon::State)));
}
@ -281,8 +289,12 @@ void SoundNotifyPlugin::checkNotificationRule(NotifyPluginConfiguration* notific
bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification)
{
#ifdef DEBUG_NOTIFIES
qDebug() << "Phonon State: " << phonon.mo->state();
#endif
if((phonon.mo->state()==Phonon::PausedState) ||
(phonon.mo->state()==Phonon::StoppedState))
(phonon.mo->state()==Phonon::StoppedState) ||
phonon.firstPlay)
{
// don't fire expire timer
//notification->expire = false;
@ -330,6 +342,8 @@ bool SoundNotifyPlugin::playNotification(NotifyPluginConfiguration* notification
phonon.ms->append(Phonon::MediaSource(item));
phonon.mo->setQueue(*phonon.ms);
phonon.mo->play();
phonon.firstPlay = false; // On Linux, you sometimes have to nudge Phonon to play 1 time before
// the state is not "Loading" anymore.
}
else
return false; // if audio is busy
@ -379,6 +393,10 @@ void SoundNotifyPlugin::expireTimerHandler()
void SoundNotifyPlugin::stateChanged(Phonon::State newstate, Phonon::State oldstate)
{
Q_UNUSED(oldstate)
#ifdef DEBUG_NOTIFIES
qDebug() << "File length (ms): " << phonon.mo->totalTime();
#endif
if((newstate == Phonon::PausedState) ||
(newstate == Phonon::StoppedState))
{

View File

@ -42,6 +42,7 @@ typedef struct {
Phonon::MediaObject* mo;
QList<Phonon::MediaSource>* ms;
NotifyPluginConfiguration* notify;
bool firstPlay;
} PhononObject, *pPhononObject;
class SoundNotifyPlugin : public ExtensionSystem::IPlugin

View File

@ -101,28 +101,28 @@ QString NotifyPluginConfiguration::parseNotifyMessage()
// generate queue of sound files to play
notifyMessageList.clear();
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound1()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound1()+".wav");
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+ getCurrentLanguage()+"/"+getSound1()+".wav")))
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + getCurrentLanguage()+"/"+getSound1()+".wav"));
else
if(QFile::exists(getSoundCollectionPath()+"\\default\\"+getSound2()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\default\\"+getSound1()+".wav");
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "default/"+getSound2()+".wav")))
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + "default/"+getSound1()+".wav"));
if(getSound2()!="")
{
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound2()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound2()+".wav");
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + getCurrentLanguage()+"/"+getSound2()+".wav")))
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + getCurrentLanguage()+"/"+getSound2()+".wav"));
else
if(QFile::exists(getSoundCollectionPath()+"\\"+"\\default\\"+"\\"+getSound2()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\default\\"+getSound2()+".wav");
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath() + "default/"+getSound2()+".wav")))
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath() + "default/"+getSound2()+".wav"));
}
if(getSound3()!="")
{
if(QFile::exists(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound3()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+getSound3()+".wav");
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+getCurrentLanguage()+"/"+getSound3()+".wav")))
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath()+getCurrentLanguage()+"/"+getSound3()+".wav"));
else
if(QFile::exists(getSoundCollectionPath()+"\\"+"\\default\\"+"\\"+getSound3()+".wav"))
notifyMessageList.append(getSoundCollectionPath()+"\\default\\"+getSound3()+".wav");
if(QFile::exists(QDir::toNativeSeparators(getSoundCollectionPath()+"default/"+getSound3()+".wav")))
notifyMessageList.append(QDir::toNativeSeparators(getSoundCollectionPath()+"default/"+getSound3()+".wav"));
}
switch(str1.at(0).toAscii())
@ -204,12 +204,12 @@ QString NotifyPluginConfiguration::parseNotifyMessage()
}
foreach(QString fileName,numberFiles) {
fileName+=".wav";
QString filePath = getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+fileName;
QString filePath = getSoundCollectionPath()+ QDir::toNativeSeparators(getCurrentLanguage()+"/"+fileName);
if(QFile::exists(filePath))
notifyMessageList.insert(position++,getSoundCollectionPath()+"\\"+getCurrentLanguage()+"\\"+fileName);
notifyMessageList.insert(position++,getSoundCollectionPath()+ QDir::toNativeSeparators(getCurrentLanguage()+"/"+fileName));
else {
if(QFile::exists(getSoundCollectionPath()+"\\default\\"+fileName))
notifyMessageList.insert(position++,getSoundCollectionPath()+"\\default\\"+fileName);
if(QFile::exists(getSoundCollectionPath()+QDir::toNativeSeparators("default/"+fileName)))
notifyMessageList.insert(position++,getSoundCollectionPath()+QDir::toNativeSeparators("default/"+fileName));
else {
notifyMessageList.clear();
break; // if no some of *.wav files, then don't play number!

View File

@ -287,7 +287,8 @@ void NotifyPluginOptionsPage::on_soundLanguage_indexChanged(int 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);
QStringList filters;