-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
142 lines (114 loc) · 3.45 KB
/
mainwindow.cpp
File metadata and controls
142 lines (114 loc) · 3.45 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ui_musicwindow.h"
#include <string.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
init();
Label_logOk = new QLabel(this);
Label_logOk->setHidden(true);
Label_logOk->setText("YOU ARE NOW LOGGED IN");
ui->loginItemsLayout->addWidget(Label_logOk);
Label_logWrong = new QLabel(this);
Label_logWrong->setHidden(true);
Label_logWrong->setText("Wrong username or password. Try again!");
ui->loginItemsLayout->addWidget(Label_logWrong);
Label_signOk = new QLabel(this);
Label_signOk->setHidden(true);
Label_signOk->setText("SIGN UP COMPLETE");
ui->loginItemsLayout->addWidget(Label_signOk);
musWind = new MusicWindow(nullptr, sd);
}
void MainWindow::init(){
int port = 3005;
if((sd=socket(AF_INET, SOCK_STREAM,0))==-1)
{
perror("[CLIENT] socket() error.\n");
}
/* gunoaie */
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_port = htons(port);
if(::connect(sd, (struct sockaddr *)&server, sizeof(sockaddr)) == -1){
perror("[CLIENT] connect() error.\n");
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
printf("AICI SUNTEM!");
char user_name[50], password[50];
memset(user_name, 0, sizeof(user_name));
memset(password, 0, sizeof(user_name));
strcpy(user_name, ui->user->text().toStdString().c_str());
strcpy(password, ui->pass->text().toStdString().c_str());
// write(this->sd, "LOG", 256);
write(this->sd, &user_name, 50);
write(this->sd, &password, 50);
char message[256];
memset(message, 0, 256);
read(this->sd, message, 256);
printf("%s\n", message);
fflush(stdout);
if(strcmp(message,"YES")==0)
logonSuccessful();
else
logonUnSuccesful();
}
/*
void MainWindow::on_signup_clicked(){
char user_name[50], password[50];
memset(user_name, 0, sizeof(user_name));
memset(password, 0, sizeof(user_name));
strcpy(user_name, ui->user->text().toStdString().c_str());
strcpy(password, ui->pass->text().toStdString().c_str());
write(this->sd, "SIGN", 256);
write(this->sd, user_name, 50);
write(this->sd, password, 50);
char message[256];
memset(message, 0, 256);
read(this->sd, message, 256);
printf("%s\n", message);
fflush(stdout);
if(strcmp(message,"YES")==0)
signUpSuccessful();
}*/
/*
void MainWindow::signUpSuccessful(){
Label_signOk->show();
Label_signOk->setHidden(false);
this->update();
musWind->show();
this->hide();
QMessageBox popup;
popup.setText("Wrong username or password!");
popup.setStandardButtons(QMessageBox::Ok);
popup.setDefaultButton(QMessageBox::Ok);
popup.exec();
musWind->show();
}*/
void MainWindow::logonSuccessful()
{
Label_logOk->show();
Label_logOk->setHidden(false);
this->update();
musWind->show();
this->hide();
}
void MainWindow::logonUnSuccesful(){
ui->loginGroup->hide();
QMessageBox popup;
popup.setText("Wrong username or password!");
popup.setStandardButtons(QMessageBox::Ok);
popup.setDefaultButton(QMessageBox::Ok);
popup.exec();
ui->user->clear();
ui->pass->clear();
ui->loginGroup->show();
}