forked from sandsmark/Spokify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.cpp
105 lines (90 loc) · 2.97 KB
/
login.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
/*
* This file is part of Spokify.
* Copyright (C) 2010 Rafael Fernández López <[email protected]>
*
* Spokify 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 3 of the License, or
* (at your option) any later version.
*
* Spokify 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 Spokify. If not, see <http://www.gnu.org/licenses/>.
*/
#include "login.h"
#include "mainwindow.h"
#include <QtGui/QLabel>
#include <QtGui/QCheckBox>
#include <QtGui/QFormLayout>
#include <KLocale>
#include <KLineEdit>
#include <kwallet.h>
Login::Login(MainWindow *mainWindow)
: KDialog(mainWindow)
, m_username(new KLineEdit(this))
, m_password(new KLineEdit(this))
, m_remember(new QCheckBox(i18n("Remember me"), this))
, m_mainWindow(mainWindow)
{
setWindowTitle(i18n("Login"));
setButtons(KDialog::Ok | KDialog::Cancel);
m_password->setEchoMode(KLineEdit::Password);
m_remember->setCheckState(Qt::Checked);
QWidget *main = new QWidget(this);
QFormLayout *layout = new QFormLayout;
layout->addRow(i18n("Username"), m_username);
layout->addRow(i18n("Password"), m_password);
layout->addWidget(m_remember);
QLabel *note = new QLabel(i18n("Note that for logging in you need a Premium Account"), main);
note->setWordWrap(true);
layout->addWidget(note);
main->setLayout(layout);
connect(this, SIGNAL(okClicked()), SLOT(loginSlot()));
setMainWidget(main);
m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), winId());
if (m_wallet) {
if (!m_wallet->hasFolder("spokify")) {
m_wallet->createFolder("spokify");
}
m_wallet->setFolder("spokify");
}
}
Login::~Login()
{
}
void Login::accept()
{
if (m_wallet && m_remember->checkState() == Qt::Checked) {
QMap<QString, QString> authInfo;
authInfo["username"] = m_username->text();
authInfo["password"] = m_password->text();
m_wallet->writeMap("spokify", authInfo);
m_wallet->sync();
}
KDialog::accept();
}
void Login::showEvent(QShowEvent *event)
{
if (m_wallet) {
QMap<QString, QString> authInfo;
m_wallet->readMap("spokify", authInfo);
m_username->setText(authInfo["username"]);
m_password->setText(authInfo["password"]);
}
KDialog::showEvent(event);
}
void Login::loginSlot()
{
//BEGIN: Spotify login
sp_session_login(m_mainWindow->session(), m_username->text().toLatin1(),
m_password->text().toLatin1(), true
#if SPOTIFY_API_VERSION >= 11
, NULL
#endif
);
//END: Spotify login
}