Skip to content

Commit

Permalink
turn [Shoutcast],"enable" into a ControlObject
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Sep 26, 2015
1 parent 29a4814 commit 4b4953b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 42 deletions.
71 changes: 45 additions & 26 deletions src/dlgprefshoutcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -31,12 +31,14 @@ DlgPrefShoutcast::DlgPrefShoutcast(QWidget *parent, ConfigObject<ConfigValue> *_
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);
Expand Down Expand Up @@ -181,7 +183,6 @@ DlgPrefShoutcast::DlgPrefShoutcast(QWidget *parent, ConfigObject<ConfigValue> *_
}

DlgPrefShoutcast::~DlgPrefShoutcast() {
delete m_pUpdateShoutcastFromPrefs;
}

void DlgPrefShoutcast::slotResetToDefaults() {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
}
5 changes: 3 additions & 2 deletions src/dlgprefshoutcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*@author John Sully
*/

class ControlObjectThread;
class ControlObjectSlave;

class DlgPrefShoutcast : public DlgPreferencePage, public Ui::DlgPrefShoutcastDlg {
Q_OBJECT
Expand All @@ -52,7 +52,8 @@ class DlgPrefShoutcast : public DlgPreferencePage, public Ui::DlgPrefShoutcastDl
private:
ConfigObject<ConfigValue>* m_pConfig;
// If set to 1, EngineShoutcast will update it's settings.
ControlObjectThread* m_pUpdateShoutcastFromPrefs;
ControlObjectSlave* m_pUpdateShoutcastFromPrefs;
ControlObjectSlave* m_pShoutcastEnabled;
};

#endif
12 changes: 7 additions & 5 deletions src/engine/sidechain/engineshoutcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ EngineShoutcast::EngineShoutcast(ConfigObject<ConfigValue>* _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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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."));
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/engine/sidechain/engineshoutcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class EngineShoutcast :
ConfigObject<ConfigValue>* m_pConfig;
Encoder *m_encoder;
ControlObject* m_pShoutcastNeedUpdateFromPrefs;
ControlObject* m_pShoutcastEnabled;
ControlObjectSlave* m_pMasterSamplerate;
ControlObject* m_pShoutcastStatus;
// static metadata according to prefereneces
Expand Down
15 changes: 6 additions & 9 deletions src/shoutcast/shoutcastmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ ShoutcastManager::ShoutcastManager(ConfigObject<ConfigValue>* 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 {
Expand All @@ -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();
}
1 change: 1 addition & 0 deletions src/shoutcast/shoutcastmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ShoutcastManager : public QObject {
private:
ConfigObject<ConfigValue>* m_pConfig;
QSharedPointer<EngineShoutcast> m_pShoutcast;
ControlObjectSlave* m_pShoutcastEnabled;
};


Expand Down

0 comments on commit 4b4953b

Please sign in to comment.