summaryrefslogtreecommitdiffstats
path: root/src/dlgprefshoutcast.cpp
blob: c9946e8c249c91f10d321af870419865cf527daa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/***************************************************************************
                          dlgprefshoutcast.cpp  -  description
                             -------------------
    begin                : Thu Jun 19 2007
    copyright            : (C) 2008 by Wesley Stessens
                           (C) 2008 by Albert Santoni
                           (C) 2007 by John Sully
    email                :
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <QtDebug>

#include "defs_urls.h"
#include "dlgprefshoutcast.h"
#include "shoutcast/defs_shoutcast.h"
#include "controlobjectslave.h"

const char* kDefaultMetadataFormat = "$artist - $title";

DlgPrefShoutcast::DlgPrefShoutcast(QWidget *parent, ConfigObject<ConfigValue> *_config)
        : DlgPreferencePage(parent),
          m_pConfig(_config) {
    setupUi(this);

    m_pShoutcastEnabled = new ControlObjectSlave(
            SHOUTCAST_PREF_KEY, "enabled", this);
    m_pShoutcastEnabled->connectValueChanged(
            SLOT(shoutcastEnabledChanged(double)));


    // Enable live broadcasting checkbox
    enableLiveBroadcasting->setChecked(
            m_pShoutcastEnabled->toBool());

    //Server type combobox
    comboBoxServerType->addItem(tr("Icecast 2"), SHOUTCAST_SERVER_ICECAST2);
    comboBoxServerType->addItem(tr("Shoutcast 1"), SHOUTCAST_SERVER_SHOUTCAST);
    comboBoxServerType->addItem(tr("Icecast 1"), SHOUTCAST_SERVER_ICECAST1);

    int tmp_index = comboBoxServerType->findData(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"servertype")));
    if (tmp_index < 0) //Set default if invalid.
        tmp_index = 0;
    comboBoxServerType->setCurrentIndex(tmp_index);

    // Mountpoint
    mountpoint->setText(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"mountpoint")));

    // Host
    host->setText(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"host")));

    // Port
    QString tmp_string = m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"port"));
    if (tmp_string.isEmpty())
        tmp_string = QString(SHOUTCAST_DEFAULT_PORT);
    port->setText(tmp_string);

    // Login
    login->setText(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"login")));

    // Password
    password->setText(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"password")));

    // Stream name
    stream_name->setText(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"stream_name")));

    // Stream website
    tmp_string = m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"stream_website"));
    if (tmp_string.isEmpty())
        tmp_string = MIXXX_WEBSITE_URL;
    stream_website->setText(tmp_string);

    // Stream description
    tmp_string = m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"stream_desc"));
    if (tmp_string.isEmpty())
        tmp_string = tr("This stream is online for testing purposes!");
    stream_desc->setText(tmp_string);

    // Stream genre
    tmp_string = m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"stream_genre"));
    if (tmp_string.isEmpty())
        tmp_string = tr("Live Mix");
    stream_genre->setText(tmp_string);

    // Stream "public" checkbox
    stream_public->setChecked((bool)m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"stream_public")).toInt());

    // OGG "dynamicupdate" checkbox
    ogg_dynamicupdate->setChecked((bool)m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"ogg_dynamicupdate")).toInt());

    // Encoding bitrate combobox
    QString kbps_pattern = QString("%1 kbps");
    QList<int> valid_kpbs;
    valid_kpbs << SHOUTCAST_BITRATE_320KBPS
               << SHOUTCAST_BITRATE_256KBPS
               << SHOUTCAST_BITRATE_224KBPS
               << SHOUTCAST_BITRATE_192KBPS
               << SHOUTCAST_BITRATE_160KBPS
               << SHOUTCAST_BITRATE_128KBPS
               << SHOUTCAST_BITRATE_112KBPS
               << SHOUTCAST_BITRATE_96KBPS
               << SHOUTCAST_BITRATE_80KBPS
               << SHOUTCAST_BITRATE_64KBPS
               << SHOUTCAST_BITRATE_48KBPS
               << SHOUTCAST_BITRATE_32KBPS;
    foreach (int kbps, valid_kpbs) {
        comboBoxEncodingBitrate->addItem(
            kbps_pattern.arg(QString::number(kbps)), kbps);
    }

    tmp_index = comboBoxEncodingBitrate->findData(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY, "bitrate")).toInt());
    if (tmp_index < 0) {
        tmp_index = comboBoxEncodingBitrate->findData(SHOUTCAST_BITRATE_128KBPS);
    }
    comboBoxEncodingBitrate->setCurrentIndex(tmp_index < 0 ? 0 : tmp_index);

    // Encoding format combobox
    comboBoxEncodingFormat->addItem(tr("MP3"), SHOUTCAST_FORMAT_MP3);
    comboBoxEncodingFormat->addItem(tr("Ogg Vorbis"), SHOUTCAST_FORMAT_OV);
    tmp_index = comboBoxEncodingFormat->findData(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY, "format")));
    if (tmp_index < 0) {
        // Set default of MP3 if invalid.
        tmp_index = 0;
    }
    comboBoxEncodingFormat->setCurrentIndex(tmp_index);

    // Encoding channels combobox
    comboBoxEncodingChannels->addItem(tr("Stereo"), SHOUTCAST_CHANNELS_STEREO);
    tmp_index = comboBoxEncodingChannels->findData(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY, "channels")));
    if (tmp_index < 0) //Set default to stereo if invalid.
        tmp_index = 0;
    comboBoxEncodingChannels->setCurrentIndex(tmp_index);

    // "Enable UTF-8 metadata" checkbox
    // TODO(rryan): allow arbitrary codecs in the future?
    QString charset = m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY, "metadata_charset"));
    enableUtf8Metadata->setChecked(charset == "UTF-8");

    // "Enable custom metadata" checkbox
    enableCustomMetadata->setChecked((bool)m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"enable_metadata")).toInt());

    //Custom artist
    custom_artist->setText(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"custom_artist")));

    //Custom title
    custom_title->setText(m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"custom_title")));

    //Metadata format
    tmp_string = m_pConfig->getValueString(
        ConfigKey(SHOUTCAST_PREF_KEY,"metadata_format"));
    if (tmp_string.isEmpty())
        // No tr() here, see https://bugs.launchpad.net/mixxx/+bug/1419500
        tmp_string = kDefaultMetadataFormat;
    metadata_format->setText(tmp_string);

    slotApply();
}

DlgPrefShoutcast::~DlgPrefShoutcast() {
}

void DlgPrefShoutcast::slotResetToDefaults() {
    // Make sure to keep these values in sync with the constructor.
    enableLiveBroadcasting->setChecked(false);
    comboBoxServerType->setCurrentIndex(0);
    mountpoint->setText("");
    host->setText("");
    port->setText("8000");
    login->setText("");
    password->setText("");
    stream_name->setText("");
    stream_website->setText(MIXXX_WEBSITE_URL);
    stream_desc->setText(tr("This stream is online for testing purposes!"));
    stream_genre->setText(tr("Live Mix"));
    stream_public->setChecked(false);
    ogg_dynamicupdate->setChecked(false);
    comboBoxEncodingBitrate->setCurrentIndex(comboBoxEncodingBitrate->findData(
            SHOUTCAST_BITRATE_128KBPS));
    comboBoxEncodingFormat->setCurrentIndex(0);
    comboBoxEncodingChannels->setCurrentIndex(0);
    enableUtf8Metadata->setChecked(false);
    enableCustomMetadata->setChecked(false);
    // No tr() here, see https://bugs.launchpad.net/mixxx/+bug/1419500
    metadata_format->setText(kDefaultMetadataFormat);
    custom_artist->setText("");
    custom_title->setText("");
}

void DlgPrefShoutcast::slotUpdate() {
    enableLiveBroadcasting->setChecked(m_pShoutcastEnabled->toBool());

    // Don't let user modify information if
    // sending is enabled.
    if(m_pShoutcastEnabled->toBool()) {
        this->setEnabled(false);
    } else {
        this->setEnabled(true);
    }
}

void DlgPrefShoutcast::slotApply()
{
    m_pShoutcastEnabled->set(enableLiveBroadcasting->isChecked());

    // Don't let user modify information if
    // sending is enabled.
    if(m_pShoutcastEnabled->toBool()) {
        this->setEnabled(false);
    } else {
        this->setEnabled(true);
    }

    // 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()));

    mountpoint->setText(mountpoint->text().trimmed());
    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