-
Notifications
You must be signed in to change notification settings - Fork 0
/
newentryform.cpp
209 lines (194 loc) · 5.24 KB
/
newentryform.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
#include "newentryform.h"
#include "ui_newentryform.h"
#include "password.h"
#include "serial.h"
#include <Qtsql>
#include <QMessageBox>
NewEntryForm::NewEntryForm(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewEntryForm),edit(false),keyEdit(false),passwordVisible(false)
{
ui->setupUi(this);
}
NewEntryForm::~NewEntryForm()
{
delete ui;
main=0;
delete main;
}
void NewEntryForm::setDatabaseID(QString id)
{
databaseID=id;
}
void NewEntryForm::setGroupID(QString name)
{
QSqlQuery getID;
getID.prepare("select groupID from groups where groupName='"+name+"' and dbID='"+databaseID+"'");
if(getID.exec())
{
while(getID.next())
{
groupID=getID.value(0).toString();
}
}
else
{
qDebug()<<getID.lastError().text();
}
}
void NewEntryForm::setMainFormReference(HomeScreen * ref)
{
main=ref;
}
void NewEntryForm::setTempPassword(QString pass)
{
ui->lineEdit_password->setText(pass);
ui->lineEdit_password2->setText(pass);
}
void NewEntryForm::setEditFeatures(QString id)
{
passID=id;
ui->label_Heading->setText("\t\t\t\tEdit Entry");
QSqlQuery fill;
fill.prepare("select title,userName,password,notes,url from passwords where passID='"+passID+"'");
if(fill.exec())
{
while(fill.next())
{
ui->plainTextEdit_Notes->setPlainText(fill.value(3).toString());
ui->lineEdit_password->setText(fill.value(2).toString());
ui->lineEdit_passwordTitle->setText(fill.value(0).toString());
ui->lineEdit_url->setText(fill.value(4).toString());
ui->lineEdit_userName->setText(fill.value(1).toString());
ui->tabWidget->setCurrentIndex(0);
}
edit=true;
}
else
{
qDebug()<<fill.lastError().text();
}
}
void NewEntryForm::setTempUserName(QString id)
{
QSqlQuery getUserName;
getUserName.prepare("select userName from databases where dbID='"+id+"'");
getUserName.exec();
while(getUserName.next())
{
ui->lineEdit_userName->setText(getUserName.value(0).toString());
}
}
void NewEntryForm::setKeyEditFeatures(QString id)
{
keyID=id;
ui->label_Heading->setText("Edit Entry");
QSqlQuery fill;
fill.prepare("select title,serialKey,notes from serials where keyID='"+keyID+"'");
if(fill.exec())
{
while(fill.next())
{
ui->lineEdit_keyTitle->setText(fill.value(0).toString());
ui->lineEdit_key->setText(fill.value(1).toString());
ui->plainTextEdit_keyNotes->setPlainText(fill.value(2).toString());
ui->tabWidget->setCurrentIndex(1);
}
keyEdit=true;
}
else
{
qDebug()<<fill.lastError().text();
}
}
void NewEntryForm::on_buttonBox_response_accepted()
{
QString title,userName,pass,pass2,notes,url;
pass=ui->lineEdit_password->text();
pass2=ui->lineEdit_password2->text();
if(pass.isEmpty())
{
QMessageBox::warning(this,tr("Entry"),tr("Please enter a passsword..."));
return;
}
if(!passwordVisible)
{
if(pass!=pass2)
{
QMessageBox::warning(this,tr("Entry"),tr("Both passwords must match..."));
return;
}
}
title=ui->lineEdit_passwordTitle->text();
userName=ui->lineEdit_userName->text();
notes=ui->plainTextEdit_Notes->toPlainText();
url=ui->lineEdit_url->text();
if(edit)//editing a current password entry
{
Password editEntry;
editEntry.editEntry(title,userName,pass,notes,url,passID);
main->RefreshPasswords();
this->close();
}
else//adding a new password entry
{
Password addEntry;
addEntry.addNewEntry(title,userName,pass,notes,url,groupID,databaseID);
main->RefreshPasswords();
this->close();
}
}
void NewEntryForm::on_buttonBox_keyResponse_accepted()
{
QString title,key,notes;
key=ui->lineEdit_key->text();
if(key.isEmpty())
{
QMessageBox::warning(this,tr("Entry"),tr("Please enter the key value"));
return;
}
title=ui->lineEdit_keyTitle->text();
notes=ui->plainTextEdit_keyNotes->toPlainText();
if(keyEdit)//editing a key entry
{
Serial editEntry;
editEntry.editEntry(title,key,notes,keyID);
main->RefreshKeys();
this->close();
}
else//adding a new key entry
{
Serial addEntry;
addEntry.addEntry(title,key,notes,groupID,databaseID);
main->RefreshKeys();
this->close();
}
}
void NewEntryForm::on_buttonBox_response_rejected()
{
this->close();
}
void NewEntryForm::on_buttonBox_keyResponse_rejected()
{
this->close();
}
void NewEntryForm::on_toolButton_passwordVisible_clicked()
{
if(passwordVisible)
{
ui->lineEdit_password->setEchoMode(QLineEdit::EchoMode::Password);
ui->lineEdit_password2->setEnabled(true);
passwordVisible=false;
}
else
{
ui->lineEdit_password->setEchoMode(QLineEdit::EchoMode::Normal);
ui->lineEdit_password2->setEnabled(false);
passwordVisible=true;
}
}
void NewEntryForm::on_toolButton_generatePassword_clicked()
{
Password random;//generate random password
setTempPassword(random.generatePassword());
}