-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPV.cpp
More file actions
171 lines (118 loc) · 3.67 KB
/
PV.cpp
File metadata and controls
171 lines (118 loc) · 3.67 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
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
#include "PV.h"
#include "ui_PV.h"
#include "Global.h"
#include "ContactListDialog.h"
#include <QMessageBox>
#include "ExternalFunctions.h"
using namespace GlobalNameSpace;
PV::PV(const unsigned long long key1, QString username, QWidget *parent) :
QDialog(parent),
ui(new Ui::PV)
{
ui->setupUi(this);
keyOfContact = key1;
usernameOfContact = username;
if (keyOfContact == Globals::KEY_USER){
ui->headingL->setText("Saved Messages");
}
else{
ui->headingL->setText("Your chat log with " + usernameOfContact + " :");
}
ui->headingL->setStyleSheet("QLabel { background-color : #00bfff ; color : #4d3900 ;font-weight: bold;font-size: 16px;font-family: Arial; }");
refresh();
}
PV::~PV()
{
delete ui;
}
void PV::setBack(ContactListDialog *back)
{
this->back_contacts = back;
return;
}
void PV::refresh(){
const unsigned long long MyKey = Globals::KEY_USER;
LinkedListMessage tempList;
const int SIZE = Globals::MESSAGE_LIST.size();
Message message;
if (MyKey != keyOfContact){
for (int i = 0; i < SIZE; i++){
message = Globals::MESSAGE_LIST.get(i);
if (message.getKeySender() == MyKey && message.getKeyReciever() == keyOfContact) {
message.setText("\nMe : " + message.getText() + "\n");
tempList.pushBack(message);
}
else if(message.getKeySender() == keyOfContact && message.getKeyReciever() == MyKey){
message.setText("\n" + usernameOfContact + " : " + message.getText() + "\n");
tempList.pushBack(message);
}
}
}
else{
for (int i = 0; i < SIZE; i++){
message = Globals::MESSAGE_LIST.get(i);
if (message.getKeySender() == MyKey && message.getKeyReciever() == MyKey){
message.setText("\n" + message.getText() + "\n");
tempList.pushBack(message);
}
}
}
const int SIZE_2 = tempList.size();
for (int i = 0; i < SIZE_2; i++){
ui->listWidget->addItem(tempList.get(i).getText());
}
const QString lastTime = tempList.getTail()->getData().getDate();
ui->timeL->setText(lastTime);
}
void PV::on_backB_clicked()
{
ContactListDialog* d = new ContactListDialog();
d->show();
hide();
}
void PV::on_deleteB_clicked()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "",
"Messages will be deleted for both sides.\nAre you sure?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
Globals::MESSAGE_LIST.remove(keyOfContact, Globals::KEY_USER);
Globals::MESSAGE_LIST.writeFile();
ui->listWidget->clear();
ContactListDialog* d = new ContactListDialog();
d->show();
hide();
}
}
void PV::on_sendB_clicked()
{
if (!ui->textE->text().isEmpty()){
ui->listWidget->clear();
Message m;
m.setKeySender(Globals::KEY_USER);
m.setKeyReciever(keyOfContact);
m.setText(ui->textE->text());
Globals::MESSAGE_LIST.pushBack(m);
Globals::MESSAGE_LIST.writeFile();
ui->textE->clear();
refresh();
}
}
void PV::closeEvent(QCloseEvent *event) {
switch (QMessageBox(tr("Warning!"), tr("Are you sure you want to exit?"), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Escape).exec())
{
case 3:
{
updateFiles();
event->accept();
//rewrite files egain...
break;
}
default:
{
event->ignore();
break;
}
}
}