This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathscrobblingsettings.cpp
164 lines (148 loc) · 5.75 KB
/
scrobblingsettings.cpp
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
/*
* Cantata
*
* Copyright (c) 2011-2022 Craig Drummond <[email protected]>
*
* ----
*
* 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 "scrobblingsettings.h"
#include "scrobbler.h"
#include "support/buddylabel.h"
#include "support/lineedit.h"
#include <QPushButton>
#define REMOVE(w) \
w->setVisible(false); \
w->deleteLater(); \
w=0;
ScrobblingSettings::ScrobblingSettings(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
connect(loginButton, SIGNAL(clicked()), this, SLOT(save()));
connect(Scrobbler::self(), SIGNAL(authenticated(bool)), SLOT(showStatus(bool)));
connect(Scrobbler::self(), SIGNAL(error(QString)), SLOT(showError(QString)));
connect(user, SIGNAL(textChanged(QString)), SLOT(controlLoginButton()));
connect(pass, SIGNAL(textChanged(QString)), SLOT(controlLoginButton()));
// connect(enableScrobbling, SIGNAL(toggled(bool)), Scrobbler::self(), SLOT(setEnabled(bool)));
// connect(showLove, SIGNAL(toggled(bool)), Scrobbler::self(), SLOT(setLoveEnabled(bool)));
connect(Scrobbler::self(), SIGNAL(enabled(bool)), enableScrobbling, SLOT(setChecked(bool)));
connect(scrobbler, SIGNAL(currentIndexChanged(int)), this, SLOT(scrobblerChanged()));
loginButton->setEnabled(false);
QMap<QString, QString> scrobblers=Scrobbler::self()->availableScrobblers();
QStringList keys=scrobblers.keys();
keys.sort();
QString firstMpdClient;
for (const QString &k: keys) {
bool viaMpd=Scrobbler::viaMpd(scrobblers[k]);
if (viaMpd) {
scrobbler->addItem(tr("%1 (via MPD)", "scrobbler name (via MPD)").arg(k), k);
} else {
scrobbler->addItem(k);
}
if (viaMpd && firstMpdClient.isEmpty()) {
firstMpdClient=k;
}
}
if (scrobbler->count()>1) {
scrobblerName->setVisible(false);
} else {
scrobblerName->setText(scrobbler->itemText(0));
scrobbler->setVisible(false);
scrobblerLabel->setBuddy(nullptr);
}
scrobblerName->setVisible(scrobbler->count()<2);
if (firstMpdClient.isEmpty()) {
REMOVE(noteLabel)
} else {
noteLabel->setText(tr("If you use a scrobbler which is marked as '(via MPD)' (such as %1), "
"then you will need to have this already started and running. "
"Cantata can only 'Love' tracks via this, and cannot enable/disable scrobbling.").arg(firstMpdClient));
}
#ifdef Q_OS_MAC
expandingSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
#endif
}
void ScrobblingSettings::load()
{
showStatus(Scrobbler::self()->isAuthenticated());
user->setText(Scrobbler::self()->user().trimmed());
pass->setText(Scrobbler::self()->pass().trimmed());
QString s=Scrobbler::self()->activeScrobbler();
for (int i=0; i<scrobbler->count(); ++i) {
if (scrobbler->itemText(i)==s || scrobbler->itemData(i).toString()==s) {
scrobbler->setCurrentIndex(i);
break;
}
}
enableScrobbling->setChecked(Scrobbler::self()->isEnabled());
showLove->setChecked(Scrobbler::self()->isLoveEnabled());
controlLoginButton();
scrobblerChanged();
}
void ScrobblingSettings::save()
{
bool isLogin=sender()==loginButton;
messageWidget->close();
QString u=user->text().trimmed();
QString p=pass->text().trimmed();
QString sc=scrobbler->itemData(scrobbler->currentIndex()).toString();
if (sc.isEmpty()) {
loginStatusLabel->setText(tr("Authenticating..."));
sc=scrobbler->currentText();
}
Scrobbler::self()->setEnabled(enableScrobbling->isChecked());
Scrobbler::self()->setLoveEnabled(showLove->isChecked());
// We dont save password, so this /might/ be empty! Therefore, dont disconnect just
// because user clicked OK/Apply...
if (isLogin || sc!=Scrobbler::self()->activeScrobbler() || u!=Scrobbler::self()->user() ||
(!Scrobbler::self()->pass().isEmpty() && p!=Scrobbler::self()->pass())) {
Scrobbler::self()->setDetails(sc, u, pass->text().trimmed());
}
}
void ScrobblingSettings::showStatus(bool status)
{
loginStatusLabel->setText(status ? tr("Authenticated") : tr("Not Authenticated"));
if (status) {
messageWidget->close();
}
enableScrobbling->setEnabled(status);
}
void ScrobblingSettings::showError(const QString &msg)
{
messageWidget->setError(msg, true);
}
void ScrobblingSettings::controlLoginButton()
{
loginButton->setEnabled(user->isEnabled() && !user->text().trimmed().isEmpty() && !pass->text().trimmed().isEmpty());
}
void ScrobblingSettings::scrobblerChanged()
{
bool viaMpd=!scrobbler->itemData(scrobbler->currentIndex()).toString().isEmpty();
user->setEnabled(!viaMpd);
userLabel->setEnabled(!viaMpd);
pass->setEnabled(!viaMpd);
passLabel->setEnabled(!viaMpd);
loginStatusLabel->setEnabled(!viaMpd);
statusLabel->setEnabled(!viaMpd);
enableScrobbling->setEnabled(!viaMpd);
if (viaMpd) {
enableScrobbling->setChecked(false);
}
controlLoginButton();
}
#include "moc_scrobblingsettings.cpp"