-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
134 lines (93 loc) · 2.83 KB
/
mainwindow.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
#include <iostream>
#include <fstream>
#include <string>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDialog>
#include <Qt>
#include <QDesktopWidget>
#include <QApplication>
#include "mainwindow.h"
#include "newuserwindow.h"
#include "moviesearchwindow.h"
using namespace std;
MainWindow::MainWindow(NetFlix* b)
{
LoginButton = new QPushButton("&Login");
NewUserButton = new QPushButton("&New User");
QuitButton = new QPushButton("&Quit");
LoginLabel=new QLabel("<b>Welcome to CSCI 104- Flix</b>");
LoginLabel->setAlignment(Qt::AlignCenter);
ErrorLoginLabel=new QLabel("The username isn't valid");
ErrorLoginLabel->setAlignment(Qt::AlignCenter);
UserNameText = new QLineEdit;
QFormLayout* fLayout = new QFormLayout;
fLayout->addRow(LoginLabel);
fLayout->addRow(ErrorLoginLabel);
ErrorLoginLabel->hide();
fLayout->addRow("&Login:", UserNameText);
QHBoxLayout* botRow = new QHBoxLayout;
botRow->addWidget(LoginButton);
botRow->addWidget(NewUserButton);
botRow->addWidget(QuitButton);
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addLayout(fLayout);
mainLayout->addLayout(botRow);
//Initialize other window class
QNewUser_w=new NewUserWindow(this);
QNewUser_w->setNetflix(b);
QNewUser_w->setWindowFlags(Qt::Window);
QMovieSearch_w=new MovieSearchWindow(this,b);
QMovieSearch_w->setWindowFlags(Qt::Window);
//connect the three buttons: login,new_user and quit
//also connect the login button to the return key.
connect(UserNameText, SIGNAL(returnPressed()),
LoginButton,SIGNAL(clicked()));
connect(LoginButton, SIGNAL(clicked()),
this, SLOT(LoginClicked()));
connect(NewUserButton, SIGNAL(clicked()),
this, SLOT(NewUserClicked()));
connect(QuitButton, SIGNAL(clicked()),
this, SLOT(QuitClicked()));
this->netflix=b;
setLayout(mainLayout);
}
void MainWindow::LoginClicked()
{
string userName = UserNameText->text().toStdString();
if(netflix->user_exist(userName))
{
if(netflix->getCurrentUser()->currentMovie()!=NULL)
{
QMovieSearch_w->updateCurrentMovie();
QMovieSearch_w->FrontQueue();
}
this->hide();
QMovieSearch_w->adjustSize();
QMovieSearch_w->move(QApplication::desktop()->screen()->rect().center() - QMovieSearch_w->rect().center());
QMovieSearch_w->show();
}
else
{
ErrorLoginLabel->show();
}
if(userName != ""){
}
else {
UserNameText->setText(QString("Please enter username to login"));
}
}
void MainWindow::QuitClicked()
{
cout<<"Thanks for using the Netflix movie search app"<<endl;
cout << "Bye Bye!" << endl;
close();
}
void MainWindow::NewUserClicked()
{
this->hide();
QNewUser_w->adjustSize();
QNewUser_w->move(QApplication::desktop()->screen()->rect().center() - QNewUser_w->rect().center());
QNewUser_w->show();
}