-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKSearch.cpp
140 lines (110 loc) · 3.5 KB
/
KSearch.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
#include <iostream>
#include <fstream>
#include <string>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDialog>
#include <QLabel>
#include "KSearch.h"
#include <QMessageBox>
using namespace std;
KSearch::KSearch(QWidget* parent, Netflix* netflix, string userInput)
{
this->netflix = netflix;
getUserKeyword = userInput;
this->parent = parent;
KeywordsearchLabel = new QLabel("Show movie");
KshowKeyword = new QLabel("put movie");
Kinformation = new QLabel("------Movie Info----------------");
KeywordnextMovieButton = new QPushButton("Next Movie");
KeywordaddQueueButton = new QPushButton("Add it in Queue");
KeywordreturnMainButton = new QPushButton("Returning to main menu");
QHBoxLayout* searchKeywordButtons = new QHBoxLayout;
searchKeywordButtons->addWidget(KeywordnextMovieButton);
searchKeywordButtons->addWidget(KeywordaddQueueButton);
searchKeywordButtons->addWidget(KeywordreturnMainButton);
QVBoxLayout* searchKeyword = new QVBoxLayout;
searchKeyword->addWidget(KeywordsearchLabel);
searchKeyword->addWidget(Kinformation);
searchKeyword->addWidget(KshowKeyword);
searchKeyword->addLayout(searchKeywordButtons);
printKeyword(getUserKeyword);
connect(KeywordnextMovieButton, SIGNAL(clicked()), this, SLOT(KeywordNextMovieClicked()));
connect(KeywordaddQueueButton, SIGNAL(clicked()), this, SLOT(KeywordAddQueueClicked()));
connect(KeywordreturnMainButton, SIGNAL(clicked()), this, SLOT(KeywordReturnMainButtonClicked()));
setLayout(searchKeyword);
}
void KSearch::KeywordNextMovieClicked()
{
if(++itA != temp1->end() )
{
printKeyword2(getUserKeyword);
}
else
{
QMessageBox incrementWarning;
incrementWarning.setText("No More Movie Corresponding the keyword!");
incrementWarning.exec();
}
}
void KSearch::KeywordAddQueueClicked()
{
Movie *temp = NULL;
temp = new Movie(putqueue);
netflix->getCurrentUser()->movieQueue()->push(temp);
QMessageBox Addingsign;
Addingsign.setText("ADDED!!!");
Addingsign.exec();
}
void KSearch::KeywordReturnMainButtonClicked()
{
close();
}
void KSearch::printKeyword(string x)
{
//Set<Movie*>* temp1; what senond is
//map <string, Set<Movie*>*>* keywords; --> keyword map looks like
//map <string, User*>* users;
//map<string, User*>::iterator p;
//p = users->find(id);
//userLogin = p -> second;
map<string, set<Movie*>*>::iterator p;
p = netflix->getKeywordsMap()->find(x);
temp1 = p -> second;
//temp1 = netflix->getKeywordsMap()->get(x);
itA = temp1->begin();//first element
string temp2 = (*itA)->getTitle(); //first string
set<string> temp3 = (*itA)->getAllKeywords();
for(itB = temp3.begin(); itB != temp3.end(); ++itB)
{
Keywordstr = Keywordstr + (*itB) + "\n";
}
putqueue = (*itA)->getTitle();
KeywordsearchLabel->setText(QString::fromStdString((*itA)->getTitle()));
KshowKeyword->setText(QString::fromStdString(Keywordstr));
}
void KSearch::printKeyword2(string x)
{
//Set<Movie*>* temp1;
map<string, set<Movie*>*>::iterator p;
p = netflix->getKeywordsMap()->find(x);
temp1 = p -> second;
//temp1 = netflix->getKeywordsMap()->get(x);
//first element
string temp2 = (*itA)->getTitle(); //first string
set<string> temp3 = (*itA)->getAllKeywords();
Keywordstr = "";
for(itB = temp3.begin(); itB != temp3.end(); ++itB)
{
Keywordstr = Keywordstr + (*itB) + "\n";
}
putqueue = (*itA)->getTitle();
KeywordsearchLabel->setText(QString::fromStdString((*itA)->getTitle()));
KshowKeyword->setText(QString::fromStdString(Keywordstr));
}
void KSearch::closeEvent(QCloseEvent *event)
{
parent->show();
close();
}