Skip to content

Commit

Permalink
Sound options: don't immediately save changes when sound system gets …
Browse files Browse the repository at this point in the history
…autodetected; fix kvirc#2667
  • Loading branch information
ctrlaltca committed Jul 26, 2024
1 parent 13a6fc3 commit efb0107
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
9 changes: 8 additions & 1 deletion src/modules/options/OptionsWidget_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,15 @@ void OptionsWidget_soundGeneral::soundAutoDetect()

g_pApp->setOverrideCursor(Qt::WaitCursor);

m->ctrl("detectSoundSystem", nullptr);
soundFillBox();
QString szSoundSystem;
if(m->ctrl("detectSoundSystem", &szSoundSystem) && !KviQString::equalCI(szSoundSystem, "null"))
{
int idx = m_pSoundSystemBox->findText(szSoundSystem);
if(idx > -1) {
m_pSoundSystemBox->setCurrentIndex(idx);
}
}

g_pApp->restoreOverrideCursor();
}
Expand Down
10 changes: 8 additions & 2 deletions src/modules/setup/libkvisetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ KVIMODULEEXPORTFUNC void setup_finish()

// detect the most appropriate sound system
KviModule * m = g_pModuleManager->getModule("snd");
if(m)
m->ctrl("detectSoundSystem", nullptr);
if(m) {
QString szSoundSystem;
if (m->ctrl("detectSoundSystem", &szSoundSystem) &&
!KviQString::equalCI(szSoundSystem, "null"))
{
KVI_OPTION_STRING(KviOption_stringSoundSystem) = szSoundSystem;
}
}
}
}

Expand Down
52 changes: 31 additions & 21 deletions src/modules/snd/libkvisnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,36 @@ bool KviSoundPlayer::event(QEvent * e)
return QObject::event(e);
}

void KviSoundPlayer::detectSoundSystem()
bool KviSoundPlayer::detectSoundSystem(QString & szSoundSystem)
{
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
KVI_OPTION_STRING(KviOption_stringSoundSystem) = "winmm";
#else
szSoundSystem = "winmm";
return true;
#endif
#ifdef COMPILE_QTMULTIMEDIA_SUPPORT
szSoundSystem = "qt";
return true;
#endif
#ifdef COMPILE_ESD_SUPPORT
esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO;
int esd_fd = esd_play_stream(format, 8012, nullptr, "kvirc");
if(esd_fd >= 0)
{
KVI_OPTION_STRING(KviOption_stringSoundSystem) = "esd";
return;
szSoundSystem = "esd";
return true;
}
#endif
#ifdef COMPILE_OSS_SUPPORT
#ifdef COMPILE_AUDIOFILE_SUPPORT
KVI_OPTION_STRING(KviOption_stringSoundSystem) = "oss+audiofile";
return;
szSoundSystem = "oss+audiofile";
return true;
#endif
KVI_OPTION_STRING(KviOption_stringSoundSystem) = "oss";
szSoundSystem = "oss";
return true;
#endif

#ifdef COMPILE_QTMULTIMEDIA_SUPPORT
KVI_OPTION_STRING(KviOption_stringSoundSystem) = "qt";
#endif
return;
#endif
szSoundSystem = "null";
return false;
}

#ifdef COMPILE_PHONON_SUPPORT
Expand Down Expand Up @@ -395,16 +398,19 @@ bool KviSoundPlayer::play(const QString & szFileName)
if(!e)
{
if(
(!KVI_OPTION_STRING(KviOption_stringSoundSystem).isEmpty()) && (!KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringSoundSystem), "unknown")))
(!KVI_OPTION_STRING(KviOption_stringSoundSystem).isEmpty()) &&
(!KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringSoundSystem), "unknown")) &&
(!KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringSoundSystem), "null")))
{
qDebug(
"Sound system '%s' is not valid, you may want to re-configure it in the options dialog...",
KVI_OPTION_STRING(KviOption_stringSoundSystem).toUtf8().data());
return false; // detection already attempted (and failed?)
}

detectSoundSystem();
e = m_pSoundSystemDict->find(KVI_OPTION_STRING(KviOption_stringSoundSystem));
QString szSoundSystem;
detectSoundSystem(szSoundSystem);
e = m_pSoundSystemDict->find(szSoundSystem);
if(!e)
return false;
}
Expand Down Expand Up @@ -718,14 +724,16 @@ static bool snd_kvs_cmd_play(KviKvsModuleCommandCall * c)

static bool snd_kvs_cmd_autodetect(KviKvsModuleCommandCall * c)
{
g_pSoundPlayer->detectSoundSystem();
if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringSoundSystem), "null"))
QString szSoundSystem;
g_pSoundPlayer->detectSoundSystem(szSoundSystem);
if(KviQString::equalCI(szSoundSystem, "null"))
{
c->window()->outputNoFmt(KVI_OUT_SYSTEMERROR, __tr2qs("Sorry, I can't find a sound system to use on this machine"));
}
else
{
c->window()->output(KVI_OUT_SYSTEMMESSAGE, __tr2qs("Sound system detected to: %s"), KVI_OPTION_STRING(KviOption_stringSoundSystem).toUtf8().data());
KVI_OPTION_STRING(KviOption_stringSoundSystem) = szSoundSystem;
c->window()->output(KVI_OUT_SYSTEMMESSAGE, __tr2qs("Sound system detected to: %s"), szSoundSystem.toUtf8().data());
}
return true;
}
Expand Down Expand Up @@ -831,8 +839,10 @@ static bool snd_module_ctrl(KviModule *, const char * operation, void * param)
}
if(kvi_strEqualCI(operation, "detectSoundSystem"))
{
g_pSoundPlayer->detectSoundSystem();
return true;
QString * pszSoundSystem = (QString *)param;
if(pszSoundSystem)
return g_pSoundPlayer->detectSoundSystem(*pszSoundSystem);
return false;
}
if(kvi_strEqualCI(operation, "play"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/modules/snd/libkvisnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class KviSoundPlayer : public QObject

public:
bool play(const QString & szFileName);
void detectSoundSystem();
bool detectSoundSystem(QString & szSoundSystem);
bool havePlayingSounds();
void getAvailableSoundSystems(QStringList * l);
bool isMuted()
Expand Down

0 comments on commit efb0107

Please sign in to comment.