diff --git a/ground/src/plugins/notify/notifyplugin.cpp b/ground/src/plugins/notify/notifyplugin.cpp index c3b5e179f..88186eced 100644 --- a/ground/src/plugins/notify/notifyplugin.cpp +++ b/ground/src/plugins/notify/notifyplugin.cpp @@ -38,7 +38,7 @@ #include #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.mo->clear(); + //phonon.mo = new Phonon::MediaObject; + phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory); + phonon.ms = new QList; + phonon.mo->clear(); + phonon.firstPlay = true; +#ifdef DEBUG_NOTIFIES + QList 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)) { diff --git a/ground/src/plugins/notify/notifyplugin.h b/ground/src/plugins/notify/notifyplugin.h index 7dddd5241..bdaca596e 100644 --- a/ground/src/plugins/notify/notifyplugin.h +++ b/ground/src/plugins/notify/notifyplugin.h @@ -42,6 +42,7 @@ typedef struct { Phonon::MediaObject* mo; QList* ms; NotifyPluginConfiguration* notify; + bool firstPlay; } PhononObject, *pPhononObject; class SoundNotifyPlugin : public ExtensionSystem::IPlugin diff --git a/ground/src/plugins/notify/notifypluginconfiguration.cpp b/ground/src/plugins/notify/notifypluginconfiguration.cpp index 7721e688c..a123975ee 100644 --- a/ground/src/plugins/notify/notifypluginconfiguration.cpp +++ b/ground/src/plugins/notify/notifypluginconfiguration.cpp @@ -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! diff --git a/ground/src/plugins/notify/notifypluginoptionspage.cpp b/ground/src/plugins/notify/notifypluginoptionspage.cpp index bc316d78b..4bc93eb38 100644 --- a/ground/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/src/plugins/notify/notifypluginoptionspage.cpp @@ -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;