-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestimonialWindow.cpp
More file actions
117 lines (92 loc) · 2.97 KB
/
testimonialWindow.cpp
File metadata and controls
117 lines (92 loc) · 2.97 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
#include "testimonialWindow.h"
#include <QLayout>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <iostream>
#include <QFile>
#include <QTextStream>
testimonialWindow::testimonialWindow(QDialog *parent):
QDialog(parent)
{
this->setWindowTitle(tr("Leave a testimonial"));
nameLabel = new QLabel(this);
nameLabel->move(50,80);
nameLabel->setText("First Name: ");
name = new QLineEdit(this);
name->move(120,80);
name->setPlaceholderText(tr("First name"));
author = name->text().toStdString();
messageLabel = new QLabel(this);
messageLabel->move(50,130);
messageLabel->setText("Testimonial: ");
message = new QLineEdit(this);
message->move(120,130);
message->setPlaceholderText("Enter your message");
description = message->text().toStdString();
submitButton = new QPushButton(this);
submitButton->move(80, 200);
submitButton->setText("Submit");
cancelButton = new QPushButton(this);
cancelButton->move(170,200);
cancelButton->setText("Cancel");
connect(submitButton,&QPushButton::clicked,this,&testimonialWindow::submit);
connect(cancelButton,&QPushButton::clicked,this,&testimonialWindow::close);
}
void testimonialWindow::submit()
{
description = message->text().toStdString();
author = name->text().toStdString();
writeFile();
testimonialWindow::close();
}
bool testimonialWindow::writeFile()
{
QString qPath = "./testimonies.txt";
QFile file(qPath);
if(!file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
{
qCritical() << "Could not open file:";
qCritical() << file.errorString();
return false;
}
qInfo() << "Writing into file:";
QTextStream out(&file);
out << "Author: " << QString::fromStdString(author) << "\n";
out << "Description: " << QString::fromStdString(description) << "\n";
out << "\n";
file.close();
return true;
}
testimonialWindow::Testimony LoadTestimony(string name)
{
{
ifstream fin;
fin.open(":/testimonies.txt");
testimonialWindow::Testimony testimony = testimonialWindow::Testimony();
string input;
string author;
string description;
string shapeType;
while(fin)
{
//Ignore the line of whitespace above each testimonies.
fin.ignore(10000, '\n');
//Read in the tesimony's email
fin.ignore(10000, ' ');
fin >> input;
if(name==input){
fin.ignore(10000, ' ');
fin >> author;
fin.ignore(10000, ' ');
fin >> description;
fin.close();
testimony = testimonialWindow::Testimony(author,description);
return testimony;
}
}//end while(fin)
fin.close();
//returns an empty testimony if not found
return testimony;
}
}