diff --git a/src/dlgprefshoutcast.cpp b/src/dlgprefshoutcast.cpp index 9ff22bdf3ad..cbdb800ce63 100644 --- a/src/dlgprefshoutcast.cpp +++ b/src/dlgprefshoutcast.cpp @@ -22,7 +22,7 @@ #include "defs_urls.h" #include "dlgprefshoutcast.h" #include "shoutcast/defs_shoutcast.h" -#include "controlobjectthread.h" +#include "controlobjectslave.h" const char* kDefaultMetadataFormat = "$artist - $title"; @@ -31,12 +31,14 @@ DlgPrefShoutcast::DlgPrefShoutcast(QWidget *parent, ConfigObject *_ m_pConfig(_config) { setupUi(this); - m_pUpdateShoutcastFromPrefs = new ControlObjectThread( - SHOUTCAST_PREF_KEY, "update_from_prefs"); + m_pUpdateShoutcastFromPrefs = new ControlObjectSlave( + SHOUTCAST_PREF_KEY, "update_from_prefs", this); + m_pShoutcastEnabled = new ControlObjectSlave( + SHOUTCAST_PREF_KEY, "enabled", this); // Enable live broadcasting checkbox - enableLiveBroadcasting->setChecked((bool)m_pConfig->getValueString( - ConfigKey(SHOUTCAST_PREF_KEY,"enabled")).toInt()); + enableLiveBroadcasting->setChecked( + m_pShoutcastEnabled->toBool()); //Server type combobox comboBoxServerType->addItem(tr("Icecast 2"), SHOUTCAST_SERVER_ICECAST2); @@ -181,7 +183,6 @@ DlgPrefShoutcast::DlgPrefShoutcast(QWidget *parent, ConfigObject *_ } DlgPrefShoutcast::~DlgPrefShoutcast() { - delete m_pUpdateShoutcastFromPrefs; } void DlgPrefShoutcast::slotResetToDefaults() { @@ -212,31 +213,49 @@ void DlgPrefShoutcast::slotResetToDefaults() { } void DlgPrefShoutcast::slotUpdate() { - enableLiveBroadcasting->setChecked((bool)m_pConfig->getValueString( - ConfigKey(SHOUTCAST_PREF_KEY,"enabled")).toInt()); + enableLiveBroadcasting->setChecked(m_pShoutcastEnabled->toBool()); } void DlgPrefShoutcast::slotApply() { - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "enabled"), ConfigValue(enableLiveBroadcasting->isChecked())); + m_pShoutcastEnabled->set(enableLiveBroadcasting->isChecked()); // Combo boxes, make sure to load their data not their display strings. - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "servertype"), ConfigValue(comboBoxServerType->itemData(comboBoxServerType->currentIndex()).toString())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "bitrate"), ConfigValue(comboBoxEncodingBitrate->itemData(comboBoxEncodingBitrate->currentIndex()).toString())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "format"), ConfigValue(comboBoxEncodingFormat->itemData(comboBoxEncodingFormat->currentIndex()).toString())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "channels"), ConfigValue(comboBoxEncodingChannels->itemData(comboBoxEncodingChannels->currentIndex()).toString())); - - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "mountpoint"), ConfigValue(mountpoint->text())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "host"), ConfigValue(host->text())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "port"), ConfigValue(port->text())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "login"), ConfigValue(login->text())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "password"), ConfigValue(password->text())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_name"), ConfigValue(stream_name->text())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_website"),ConfigValue(stream_website->text())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_desc"), ConfigValue(stream_desc->toPlainText())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_genre"), ConfigValue(stream_genre->text())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_public"), ConfigValue(stream_public->isChecked())); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "ogg_dynamicupdate"), ConfigValue(ogg_dynamicupdate->isChecked())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "servertype"), + ConfigValue(comboBoxServerType->itemData( + comboBoxServerType->currentIndex()).toString())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "bitrate"), + ConfigValue(comboBoxEncodingBitrate->itemData( + comboBoxEncodingBitrate->currentIndex()).toString())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "format"), + ConfigValue(comboBoxEncodingFormat->itemData( + comboBoxEncodingFormat->currentIndex()).toString())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "channels"), + ConfigValue(comboBoxEncodingChannels->itemData( + comboBoxEncodingChannels->currentIndex()).toString())); + + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "mountpoint"), + ConfigValue(mountpoint->text())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "host"), + ConfigValue(host->text())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "port"), + ConfigValue(port->text())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "login"), + ConfigValue(login->text())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "password"), + ConfigValue(password->text())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_name"), + ConfigValue(stream_name->text())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_website"), + ConfigValue(stream_website->text())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_desc"), + ConfigValue(stream_desc->toPlainText())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_genre"), + ConfigValue(stream_genre->text())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "stream_public"), + ConfigValue(stream_public->isChecked())); + m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "ogg_dynamicupdate"), + ConfigValue(ogg_dynamicupdate->isChecked())); QString charset = ""; if (enableUtf8Metadata->isChecked()) { @@ -259,5 +278,5 @@ void DlgPrefShoutcast::slotApply() m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "metadata_format"), ConfigValue(metadata_format->text())); //Tell the EngineShoutcast object to update with these values by toggling this control object. - m_pUpdateShoutcastFromPrefs->slotSet(1.0); + m_pUpdateShoutcastFromPrefs->set(1.0); } diff --git a/src/dlgprefshoutcast.h b/src/dlgprefshoutcast.h index cc7a1118ebd..4fad3416f2a 100644 --- a/src/dlgprefshoutcast.h +++ b/src/dlgprefshoutcast.h @@ -32,7 +32,7 @@ *@author John Sully */ -class ControlObjectThread; +class ControlObjectSlave; class DlgPrefShoutcast : public DlgPreferencePage, public Ui::DlgPrefShoutcastDlg { Q_OBJECT @@ -52,7 +52,8 @@ class DlgPrefShoutcast : public DlgPreferencePage, public Ui::DlgPrefShoutcastDl private: ConfigObject* m_pConfig; // If set to 1, EngineShoutcast will update it's settings. - ControlObjectThread* m_pUpdateShoutcastFromPrefs; + ControlObjectSlave* m_pUpdateShoutcastFromPrefs; + ControlObjectSlave* m_pShoutcastEnabled; }; #endif diff --git a/src/engine/sidechain/engineshoutcast.cpp b/src/engine/sidechain/engineshoutcast.cpp index a7f62ac9bfe..9a563dd8525 100644 --- a/src/engine/sidechain/engineshoutcast.cpp +++ b/src/engine/sidechain/engineshoutcast.cpp @@ -74,6 +74,9 @@ EngineShoutcast::EngineShoutcast(ConfigObject* _config) m_pShoutcastStatus->set(NETWORKSTREAMWORKER_STATE_DISCONNECTED); m_pShoutcastNeedUpdateFromPrefs = new ControlObject( ConfigKey(SHOUTCAST_PREF_KEY,"update_from_prefs")); + const bool persist = true; + m_pShoutcastEnabled = new ControlObject( + ConfigKey(SHOUTCAST_PREF_KEY,"enabled"),true, false, persist); setState(NETWORKSTREAMWORKER_STATE_INIT); @@ -416,7 +419,7 @@ bool EngineShoutcast::processConnect() { shout_close(m_pShout); } setState(NETWORKSTREAMWORKER_STATE_ERROR); - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY,"enabled"),ConfigValue("0")); + m_pShoutcastEnabled->set(0); m_pShoutcastStatus->set(NETWORKSTREAMWORKER_STATE_DISCONNECTED); return false; } @@ -444,8 +447,8 @@ bool EngineShoutcast::processConnect() { return true; } setState(NETWORKSTREAMWORKER_STATE_ERROR); - //otherwise disable shoutcast in preferences - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY,"enabled"),ConfigValue("0")); + // otherwise disable shoutcast in preferences + m_pShoutcastEnabled->set(0); if (m_pShout) { shout_close(m_pShout); //errorDialog(tr("Mixxx could not connect to the server"), tr("Please check your connection to the Internet and verify that your username and password are correct.")); @@ -746,8 +749,7 @@ void EngineShoutcast::run() { m_readSema.acquire(); // Check to see if Shoutcast is enabled, and pass the samples off to be // broadcast if necessary. - bool prefEnabled = (m_pConfig->getValueString( - ConfigKey(SHOUTCAST_PREF_KEY, "enabled")).toInt() == 1); + bool prefEnabled = m_pShoutcastEnabled->toBool(); if (m_bThreadQuit || !prefEnabled) { m_threadWaiting = false; processDisconnect(); diff --git a/src/engine/sidechain/engineshoutcast.h b/src/engine/sidechain/engineshoutcast.h index 2fe01729889..ffad534a631 100644 --- a/src/engine/sidechain/engineshoutcast.h +++ b/src/engine/sidechain/engineshoutcast.h @@ -108,6 +108,7 @@ class EngineShoutcast : ConfigObject* m_pConfig; Encoder *m_encoder; ControlObject* m_pShoutcastNeedUpdateFromPrefs; + ControlObject* m_pShoutcastEnabled; ControlObjectSlave* m_pMasterSamplerate; ControlObject* m_pShoutcastStatus; // static metadata according to prefereneces diff --git a/src/shoutcast/shoutcastmanager.cpp b/src/shoutcast/shoutcastmanager.cpp index ceb7226464d..8c957c00aa7 100644 --- a/src/shoutcast/shoutcastmanager.cpp +++ b/src/shoutcast/shoutcastmanager.cpp @@ -16,20 +16,18 @@ ShoutcastManager::ShoutcastManager(ConfigObject* pConfig, new EngineShoutcast(pConfig)); pNetworkStream->addWorker(m_pShoutcast); } + m_pShoutcastEnabled = new ControlObjectSlave( + SHOUTCAST_PREF_KEY, "enabled", this); } ShoutcastManager::~ShoutcastManager() { // Disable shoutcast so when Mixxx starts again it will not connect. - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "enabled"), 0); + m_pShoutcastEnabled->set(0); } void ShoutcastManager::setEnabled(bool value) { - m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY, "enabled"), - ConfigValue(value)); - - /** - * Should this be started somewhere else? - */ + m_pShoutcastEnabled->set(value); + // Should this be started somewhere else? if (value == true) { m_pShoutcast->serverConnect(); } else { @@ -38,6 +36,5 @@ void ShoutcastManager::setEnabled(bool value) { } bool ShoutcastManager::isEnabled() { - return m_pConfig->getValueString( - ConfigKey(SHOUTCAST_PREF_KEY, "enabled")).toInt() == 1; + return m_pShoutcastEnabled->toBool(); } diff --git a/src/shoutcast/shoutcastmanager.h b/src/shoutcast/shoutcastmanager.h index c1d30a5078d..d2fd0dad0a5 100644 --- a/src/shoutcast/shoutcastmanager.h +++ b/src/shoutcast/shoutcastmanager.h @@ -29,6 +29,7 @@ class ShoutcastManager : public QObject { private: ConfigObject* m_pConfig; QSharedPointer m_pShoutcast; + ControlObjectSlave* m_pShoutcastEnabled; };