-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pianobar-QT.cpp
115 lines (76 loc) · 2.93 KB
/
Pianobar-QT.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
#include "Pianobar-QT.h"
#include "Pianobar_QT_MainWindow.h"
Pianobar_QT::Pianobar_QT(QWidget* parent) : QWidget(parent)
{
QGridLayout* layout = new QGridLayout(this);
QLabel* title = new QLabel("Welcome to PianobarQT", this);
QFont titleFont;
titleFont.setPointSize(20);
titleFont.setUnderline(true);
titleFont.setBold(true);
title->setFont(titleFont);
layout->addWidget(title, 0, 0, 1, 2);
QLabel* userNameLabel = new QLabel("Username", this);
layout->addWidget(userNameLabel, 1, 0);
userName = new QLineEdit(this);
layout->addWidget(userName, 1, 1);
QLabel* passwordLabel = new QLabel("Password", this);
layout->addWidget(passwordLabel, 2, 0);
passwordField = new QLineEdit(this);
passwordField->setEchoMode(QLineEdit::Password);
layout->addWidget(passwordField, 2, 1);
ok = new QPushButton("Ok", this);
QPushButton* cancel = new QPushButton("Cancel", this);
QHBoxLayout* hbox = new QHBoxLayout();
hbox->addWidget(ok, 1, Qt::AlignRight);
hbox->addWidget(cancel, 1, Qt::AlignRight);
layout->addLayout(hbox, 3, 1);
setLayout(layout);
connect(cancel, SIGNAL(clicked(bool)), SLOT(cancelPressed()));
connect(ok, SIGNAL(clicked(bool)), SLOT(logIn()));
connect(passwordField, SIGNAL(returnPressed()), SLOT(logIn()));
}
void Pianobar_QT::logIn(){
QString username = userName->text();
QString password = passwordField->text();
if(username.isEmpty() || password.isEmpty()){
if(username.isEmpty()){
userName->setStyleSheet("background: red");
}else{
userName->setStyleSheet("background: white");
}
if(password.isEmpty()){
passwordField->setStyleSheet("background: red");
}else{
passwordField->setStyleSheet("background: white");
}
return;
}
piano.PianoInitialize(&ph, &wh);
//TODO While the program is logging in, show some sort of indicator
// to make sure the user doesn't think the program is stuck
//Copy the data to avoid overwriting... dam you memory
char* user = strdup(username.toAscii().data());
char* pass = strdup(password.toAscii().data());
if(!piano.PianoLogin(&ph, &wh, user, pass)){
//TODO: Tell the user in a nicer way that the login failed
userName->setStyleSheet("background: red");
passwordField->setStyleSheet("background: red");
return;
}
//free(user);
//free(pass);
Pianobar_QT_MainWindow* mainWindow = new Pianobar_QT_MainWindow(username);
mainWindow->setHandlers(ph, wh);
mainWindow->show();
this->close();
//Make sure that there are no double logins
ok->disconnect(SIGNAL(clicked(bool)));
passwordField->disconnect(SIGNAL(returnPressed()));
}
void Pianobar_QT::cancelPressed()
{
//We are out of here
exit(0);
}
#include "Pianobar-QT.moc"