-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewMessageDialog.cpp
More file actions
110 lines (84 loc) · 2.47 KB
/
NewMessageDialog.cpp
File metadata and controls
110 lines (84 loc) · 2.47 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
#include "NewMessageDialog.h"
#include "ui_NewMessageDialog.h"
#include "DetailOfAllProducts.h"
#include "DetailOfFavoriteProducts.h"
#include <QMessageBox>
#include <QKeyEvent>
#include "Global.h"
#include "ContactListDialog.h"
using namespace std;
using namespace GlobalNameSpace;
NewMessageDialog::NewMessageDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewMessageDialog)
{
ui->setupUi(this);
}
NewMessageDialog::~NewMessageDialog()
{
delete ui;
}
void NewMessageDialog::setBack(ContactListDialog *b)
{
this->back_ = b;
return;
}
void NewMessageDialog::on_sendB_clicked()
{
if (ui->userNameE->text().isEmpty()){
QMessageBox::critical(this, "Failed", "First mention your reciever.");
}
else {
const unsigned long long keyOfReciever = keyOfUser(ui->userNameE->text());
if (keyOfReciever == 0){
QMessageBox::critical(this, "Failed", "No user exists with this username.");
}
else{
const QString text = ui->textE->text();
if (text.isEmpty()){
QMessageBox::critical(this, "Failed", "You forget to enter the message!");
}
else{
Message m;
m.setText(text);
m.setKeySender(Globals::KEY_USER);
m.setKeyReciever(keyOfReciever);
Globals::MESSAGE_LIST.pushBack(m);
Globals::MESSAGE_LIST.writeFile();
QMessageBox::information(this, "Done", "Message sent.");
ContactListDialog* d = new ContactListDialog();
d->show();
this->close();
this->back_->hide();
}
}
}
}
unsigned long long NewMessageDialog::keyOfUser(QString username){
TNodeUser<Dealer> *temp = Globals::DEALER_LIST.getHead();
while (temp != nullptr){
if (temp->getData().getUserName() == username){
return temp->getData().getKey();
}
temp = temp->getNext();
}
TNodeUser<Users> *temp2 = Globals::USER_LIST.getHead();
while (temp2 != nullptr){
if (temp2->getData().getUserName() == username){
return temp2->getData().getKey();
}
temp2 = temp2->getNext();
}
return 0;
}
void NewMessageDialog::on_backB_clicked()
{
close();
}
void NewMessageDialog::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
{
on_sendB_clicked();
}
}