-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserdialog.cpp
254 lines (218 loc) · 7.77 KB
/
userdialog.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include "userdialog.h"
#include "ui_userdialog.h"
#include <QMessageBox>
#include "Validation.h"
#include <QStringListModel>
#include <algorithm>
UserDialog::UserDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::UserDialog)
{
ui->setupUi(this);
}
UserDialog::~UserDialog()
{
delete ui;
}
void UserDialog::setCtrl(Controller& c) {
this->ctrl = c;
}
void UserDialog::initGenreItems() {
std::vector<Film> allFilms = ctrl.getRepo().getFilms();
std::vector<std::string> allGenres;
for (auto f : allFilms) {
if(std::find(allGenres.begin(), allGenres.end(), f.getGenre()) != allGenres.end()) {
continue;
}
else {
ui->genreComboBox->addItem(QString::fromStdString(f.getGenre()));
allGenres.push_back(f.getGenre());
}
}
}
void UserDialog::on_exitBtn_clicked()
{
this->close();
}
void UserDialog::on_showBtn_clicked()
{
ui->listWidget->clearSelection();
ui->genreComboBox->setCurrentText("Select Genre");
ui->viewBtn->setVisible(false);
ui->addBtn->setVisible(false);
//Set top title
ui->crtInfo->setText("Watchlist");
//show content in list Widget
WatchList temporaryWatchlist;
ui->listWidget->clear();
if (newCustomer) {
temporaryWatchlist = this->newWatchList; //if user is new modify the new watchlist
}
else {
temporaryWatchlist = ctrl.getRepo().getUsers()[this->posUser].watchList; //get the user's watchlist
}
if (temporaryWatchlist.getFilms().size() != 0) {
std::vector<Film> allFilms = temporaryWatchlist.getFilms();
for (auto f : allFilms) {
ui->listWidget->addItem(QString::fromStdString(f.getTitle()) +
" | " + QString::fromStdString(f.getGenre()) + " | " + QString::number(f.getYear()));
}
}
else
QMessageBox::warning(this, "Watchlist", "Your Watchlist is empty!");
}
void UserDialog::on_watchedBtn_clicked()
{
if (this->newCustomer == false) {
//get position of film in List Widget
int posOfWatched = ui->listWidget->selectionModel()->currentIndex().row();
if (posOfWatched != -1) {
//delete film from List Widget
QListWidgetItem *it = ui->listWidget->takeItem(ui->listWidget->currentRow());
delete it;
WatchList temporaryWatchlist = ctrl.getRepo().getUsers()[this->posUser].watchList; //get the user's watchlist
Film f = temporaryWatchlist.getFilms()[posOfWatched];
//delete from watchlist of user
ctrl.deleteFilmFromWatchlist(this->userName, f.getTitle(), f.getYear());
}
else
QMessageBox::warning(this, "Watched", "No movie was selected!");
}
else {
//get position of film in List Widget
int posOfWatched = ui->listWidget->selectionModel()->currentIndex().row();
if (posOfWatched != -1) {
//delete film from List Widget
QListWidgetItem *it = ui->listWidget->takeItem(ui->listWidget->currentRow());
delete it;
//delete from watchlist of user
this->newWatchList.deleteFilm(this->newWatchList.getFilms()[posOfWatched]);
}
else
QMessageBox::warning(this, "Watched", "No movie was selected!");
}
}
void UserDialog::on_openCSV_Btn_clicked()
{
if (ui->fileTypeCombo->currentText() == "csv") {
ctrl.selectFileType(this->userName, "csv");
ctrl.selectFileType(this->userName, "html");
}
else {
QMessageBox::warning(this, "Open", "Please, select a filetype!");
}
}
void UserDialog::on_openHTML_Btn_clicked()
{
if (ui->fileTypeCombo->currentText() == "html") {
ctrl.selectFileType(this->userName, "html");
ctrl.openFileInApp();
}
else {
QMessageBox::warning(this, "Open", "Please, select a filetype!");
}
}
void UserDialog::on_yesRadio_clicked()
{
WatchList temporaryWatchlist;
int posOfWatched = ui->listWidget->selectionModel()->currentIndex().row();
if (newCustomer) {
temporaryWatchlist = this->newWatchList; //if user is new modify the new watchlist
}
else {
temporaryWatchlist = ctrl.getRepo().getUsers()[this->posUser].watchList; //get the user's watchlist
}
ctrl.incLikes(temporaryWatchlist.getFilms()[posOfWatched].getTitle(), temporaryWatchlist.getFilms()[posOfWatched].getYear());
}
void UserDialog::on_genreComboBox_currentTextChanged(const QString &arg1)
{
ui->listWidget->clearSelection();
ui->watchedBtn->setVisible(false);
ui->label->setVisible(false);
ui->yesRadio->setVisible(false);
ui->NoRadio->setVisible(false);
ui->listWidget->clear();
//Set top title
if (ui->genreComboBox->currentText() == "Select Genre")
ui->crtInfo->setText("");
else {
ui->crtInfo->setText(ui->genreComboBox->currentText());
std::string option = ui->genreComboBox->currentText().toStdString();
if (option == "all")
option = "";
std::vector<Film> foundFilms = ctrl.getFilmsGenre(option);
for (auto f : foundFilms) {
ui->listWidget->addItem(QString::fromStdString(f.getTitle()) +
" | " + QString::fromStdString(f.getGenre()) + " | " + QString::number(f.getYear()));
}
}
}
void UserDialog::on_fileTypeCombo_currentTextChanged(const QString &arg1)
{
if (ui->fileTypeCombo->currentText() != "Save Format")
ctrl.selectFileType(this->userName, ui->fileTypeCombo->currentText().toStdString());
}
void UserDialog::on_addBtn_clicked()
{
WatchList creatingWatchList = this->newWatchList;
int posOfWatched = ui->listWidget->selectionModel()->currentIndex().row();
if (posOfWatched != -1) {
std::string option = ui->genreComboBox->currentText().toStdString();
if (option == "all")
option = "";
std::vector<Film> foundFilms = ctrl.getFilmsGenre(option);
if (this->newCustomer == false) {
ctrl.addFilmToWatchlist(this->userName, foundFilms[posOfWatched]); //add the film to the watchlist of existing user
}
else {
creatingWatchList.add(foundFilms[posOfWatched]); //create new WatchList
}
if (newCustomer)
this->newWatchList = creatingWatchList;
}
else {
QMessageBox::warning(this, "Add", "No movie was selected!");
}
}
void UserDialog::on_viewBtn_clicked()
{
int posOfWatched = ui->listWidget->selectionModel()->currentIndex().row();
std::string option = ui->genreComboBox->currentText().toStdString();
if (option == "all")
option = "";
std::vector<Film> foundFilms = ctrl.getFilmsGenre(option);
foundFilms[posOfWatched].play();
}
void UserDialog::logedIn() {
ui->userLbl->setText("Loged In as: " + QString::fromStdString(this->userName));
}
void UserDialog::on_listWidget_itemClicked(QListWidgetItem *item)
{
{
ui->yesRadio->setAutoExclusive(false);
ui->yesRadio->setChecked(false);
ui->NoRadio->setAutoExclusive(false);
ui->NoRadio->setChecked(false);
ui->yesRadio->setAutoExclusive(true);
ui->NoRadio->setAutoExclusive(true);
}
{
if (ui->crtInfo->text() == "Watchlist") {
ui->watchedBtn->setVisible(true);
ui->label->setVisible(true);
ui->yesRadio->setVisible(true);
ui->NoRadio->setVisible(true);
ui->viewBtn->setVisible(false);
ui->addBtn->setVisible(false);
//should be changed
}
else {
ui->viewBtn->setVisible(true);
ui->addBtn->setVisible(true);
ui->watchedBtn->setVisible(false);
ui->label->setVisible(false);
ui->yesRadio->setVisible(false);
ui->NoRadio->setVisible(false);
}
}
}