File: playbacksettings.cpp

package info (click to toggle)
cantata 3.4.0.ds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,428 kB
  • sloc: cpp: 109,584; perl: 1,366; xml: 722; python: 139; lex: 110; sh: 105; yacc: 78; makefile: 8
file content (199 lines) | stat: -rw-r--r-- 8,175 bytes parent folder | download
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
/*
 * Cantata
 *
 * Copyright (c) 2011-2022 Craig Drummond <craig.p.drummond@gmail.com>
 *
 * ----
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "playbacksettings.h"
#include "mpd-interface/mpdconnection.h"
#include "settings.h"
#include "support/icon.h"
#include "support/messagebox.h"
#include "support/utils.h"
#include "widgets/basicitemdelegate.h"
#include <QListWidget>

#define REMOVE(w)         \
	w->setVisible(false); \
	w->deleteLater();     \
	w = 0;

PlaybackSettings::PlaybackSettings(QWidget* p)
	: QWidget(p)
{
	setupUi(this);
	stopFadeDuration->setRange(MPDConnection::MinFade, MPDConnection::MaxFade);
	stopFadeDuration->setSingleStep(100);

	outputsView->setItemDelegate(new BasicItemDelegate(outputsView));
	replayGain->addItem(tr("None"), QVariant("off"));
	replayGain->addItem(tr("Track"), QVariant("track"));
	replayGain->addItem(tr("Album"), QVariant("album"));
	replayGain->addItem(tr("Auto"), QVariant("auto"));
	connect(MPDConnection::self(), SIGNAL(replayGain(const QString&)), this, SLOT(replayGainSetting(const QString&)));
	connect(MPDConnection::self(), SIGNAL(outputsUpdated(const QList<Output>&)), this, SLOT(updateOutputs(const QList<Output>&)));
	connect(MPDConnection::self(), SIGNAL(stateChanged(bool)), this, SLOT(mpdConnectionStateChanged(bool)));
	connect(this, SIGNAL(enableOutput(quint32, bool)), MPDConnection::self(), SLOT(enableOutput(quint32, bool)));
	connect(this, SIGNAL(outputs()), MPDConnection::self(), SLOT(outputs()));
	connect(this, SIGNAL(setReplayGain(const QString&)), MPDConnection::self(), SLOT(setReplayGain(const QString&)));
	connect(this, SIGNAL(setCrossFade(int)), MPDConnection::self(), SLOT(setCrossFade(int)));
	connect(this, SIGNAL(getReplayGain()), MPDConnection::self(), SLOT(getReplayGain()));
	connect(aboutReplayGain, SIGNAL(leftClickedUrl()), SLOT(showAboutReplayGain()));
	int iconSize = Icon::dlgIconSize();
	messageIcon->setFixedSize(iconSize, iconSize);
	mpdConnectionStateChanged(MPDConnection::self()->isConnected());
#if defined Q_OS_WIN || (defined Q_OS_MAC && !defined IOKIT_FOUND)
	REMOVE(inhibitSuspend)
#endif
	outputsView->setVisible(outputsView->count() > 1);
	outputsViewLabel->setVisible(outputsView->count() > 1);

#ifdef Q_OS_MAC
	expandingSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
#endif
	volumeStep->setToolTip(volumeStepLabel->toolTip());
}

void PlaybackSettings::load()
{
	stopOnExit->setChecked(Settings::self()->stopOnExit());
	stopFadeDuration->setValue(Settings::self()->stopFadeDuration());
	prevSeekDuration->setValue(Settings::self()->prevSeekDuration());
#if (defined Q_OS_LINUX && defined QT_QTDBUS_FOUND) || (defined Q_OS_MAC && defined IOKIT_FOUND)
	inhibitSuspend->setChecked(Settings::self()->inhibitSuspend());
#endif
	volumeStep->setValue(Settings::self()->volumeStep());

	crossfading->setValue(MPDStatus::self()->crossFade());
	if (MPDConnection::self()->isConnected()) {
		emit getReplayGain();
		emit outputs();
		applyReplayGain->setChecked(MPDConnection::self()->getDetails().applyReplayGain);
	}
}

void PlaybackSettings::save()
{
	Settings::self()->saveStopOnExit(stopOnExit->isChecked());
	Settings::self()->saveStopFadeDuration(stopFadeDuration->value());
	Settings::self()->savePrevSeekDuration(prevSeekDuration->value());
#if (defined Q_OS_LINUX && defined QT_QTDBUS_FOUND) || (defined Q_OS_MAC && defined IOKIT_FOUND)
	Settings::self()->saveInhibitSuspend(inhibitSuspend->isChecked());
#endif
	Settings::self()->saveVolumeStep(volumeStep->value());

	if (MPDConnection::self()->isConnected()) {
		int crossFade = crossfading->value();
		if (crossFade != MPDStatus::self()->crossFade()) {
			emit setCrossFade(crossFade);
		}
		QString rg = replayGain->itemData(replayGain->currentIndex()).toString();
		if (rgSetting != rg) {
			rgSetting = rg;
			emit setReplayGain(rg);
		}
		MPDConnectionDetails det = MPDConnection::self()->getDetails();
		if (det.applyReplayGain != applyReplayGain->isChecked()) {
			det.applyReplayGain = applyReplayGain->isChecked();
			Settings::self()->saveConnectionDetails(det);
		}
		if (outputsView->isVisible()) {
			for (int i = 0; i < outputsView->count(); ++i) {
				QListWidgetItem* item = outputsView->item(i);
				bool isEnabled = Qt::Checked == item->checkState();
				int id = item->data(Qt::UserRole).toInt();
				if (isEnabled && !enabledOutputs.contains(id)) {
					enabledOutputs.insert(id);
					emit enableOutput(id, isEnabled);
				}
				else if (!isEnabled && enabledOutputs.contains(id)) {
					enabledOutputs.remove(id);
					emit enableOutput(id, isEnabled);
				}
			}
		}
	}
}

void PlaybackSettings::replayGainSetting(const QString& rg)
{
	rgSetting = rg;
	replayGain->setCurrentIndex(0);

	for (int i = 0; i < replayGain->count(); ++i) {
		if (replayGain->itemData(i).toString() == rg) {
			replayGain->setCurrentIndex(i);
			break;
		}
	}
}

void PlaybackSettings::updateOutputs(const QList<Output>& outputs)
{
	outputsView->clear();
	enabledOutputs.clear();
	for (const Output& output : outputs) {
		if (!output.inCurrentPartition) continue;
		QListWidgetItem* item = new QListWidgetItem(output.name, outputsView);
		item->setCheckState(output.enabled ? Qt::Checked : Qt::Unchecked);
		item->setData(Qt::UserRole, output.id);
		if (output.enabled) {
			enabledOutputs.insert(output.id);
		}
	}
	outputsView->setVisible(outputsView->count() > 1);
	outputsViewLabel->setVisible(outputsView->count() > 1);
}

void PlaybackSettings::mpdConnectionStateChanged(bool c)
{
	bool rgSupported = c && MPDConnection::self()->replaygainSupported();
	outputsView->setEnabled(c);
	outputsViewLabel->setEnabled(c);
	crossfading->setEnabled(c);
	crossfadingLabel->setEnabled(c);
	replayGainLabel->setEnabled(rgSupported);
	replayGain->setEnabled(rgSupported);
	applyReplayGain->setChecked(MPDConnection::self()->getDetails().applyReplayGain);
	messageIcon->setPixmap(style()->standardIcon(c ? QStyle::SP_MessageBoxInformation : QStyle::SP_MessageBoxWarning).pixmap(messageIcon->minimumSize()));
	if (c) {
		messageLabel->setText(tr("<i>Connected to %1<br/>The entries below apply to the currently connected MPD collection.</i>")
		                              .arg(MPDConnection::self()->getDetails().description()));
	}
	else {
		messageLabel->setText(tr("<i>Not Connected!<br/>The entries below cannot be modified, as Cantata is not connected to MPD.</i>"));
		outputsView->clear();
	}
}

void PlaybackSettings::showAboutReplayGain()
{
	MessageBox::information(this, tr("Replay Gain is a proposed standard published in 2001 to normalize the perceived loudness of computer "
	                                 "audio formats such as MP3 and Ogg Vorbis. It works on a track/album basis, and is now supported in a "
	                                 "growing number of players."
	                                 "<br/><br/>The following ReplayGain settings may be used:<ul>"
	                                 "<li><i>None</i> - No ReplayGain is applied.</li>"
	                                 "<li><i>Track</i> - Volume will be adjusted using the track's ReplayGain tags.</li>"
	                                 "<li><i>Album</i> - Volume will be adjusted using the albums's ReplayGain tags.</li>"
	                                 "<li><i>Auto</i> - Volume will be adjusted using the track's ReplayGain tags if random play is activated, otherwise the album's tags will be used.</li>"
	                                 "</ul>"));
}

#include "moc_playbacksettings.cpp"