-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomescreen.cpp
More file actions
815 lines (759 loc) · 26.7 KB
/
homescreen.cpp
File metadata and controls
815 lines (759 loc) · 26.7 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
#include "homescreen.h"
#include "ui_homescreen.h"
#include"masterpasswordform.h"
#include"opendatabaseform.h"
#include "newentryform.h"
#include "database.h"
#include "databasesettingsform.h"
#include "changemasterkeyform.h"
#include "groups.h"
#include "about.h"
#include "password.h"
#include <QMessageBox>
#include <QtSql>
HomeScreen::HomeScreen(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::HomeScreen),dbPtr(new Database),locked(false),currentDbID("None"),currentGroupName("Default"),
currentKeyID("None"),currentPassID("None"),currentDbName("None")
{
ui->setupUi(this);
this->setWindowState(Qt::WindowMaximized);
//set default values
ui->treeWidget_groups->setColumnCount(1);
ui->treeWidget_groups->setHeaderLabel("Groups");
LockWorkspace();
ui->treeWidget_groups->setContextMenuPolicy(Qt::CustomContextMenu);
ui->tableView_info->setContextMenuPolicy(Qt::CustomContextMenu);
ui->tableView_keyInfo->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->treeWidget_groups,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(showGroupContextMenu(const QPoint&)));
connect(ui->tableView_info,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(showContextMenu(const QPoint&)));
connect(ui->tableView_keyInfo,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(showKeyContextMenu(const QPoint&)));
}
void HomeScreen::showGroupContextMenu(const QPoint& pos)
{
QPoint globalPos=ui->treeWidget_groups->mapToGlobal(pos);
QMenu myMenu;
myMenu.addAction("Add Group");
myMenu.addAction("Edit Group");
myMenu.addAction("Delete Group");
QAction* selectedItem=myMenu.exec(globalPos);
if(!selectedItem)
{
qDebug()<<"none selected";
}
else
{
if(selectedItem->text()=="Add Group")
{
qDebug()<<"add group selected";
//Open form to add a new Group
Groups newGroup;
newGroup.setMainFormReference(this);
newGroup.setDbID(currentDbID);
newGroup.exec();
}
if(selectedItem->text()=="Edit Group")
{
qDebug()<<"edit group selected";
QModelIndex index=ui->treeWidget_groups->currentIndex();
currentGroupName=index.data(0).toString();
if(currentGroupName==currentDbName)
{ currentGroupName="Default";}
Groups editForm;
editForm.setMainFormReference(this);
editForm.setEditFeatures(currentGroupName,currentDbID);//set Edit Form to edit currently selected group
editForm.exec();
}
if(selectedItem->text()=="Delete Group")
{
qDebug()<<"delete group selected";
QModelIndex index=ui->treeWidget_groups->currentIndex();
currentGroupName=index.data(0).toString();
if(currentGroupName==currentDbName)
{ currentGroupName="Default";}
int ret= QMessageBox::warning(this,tr("Delete"),tr("Are You Sure You want to permanently delete the selected group?\nDoing so will also delete the entries in that group."),QMessageBox::Yes|QMessageBox::Cancel,QMessageBox::Cancel);
if (ret==QMessageBox::Yes)
{
QSqlQuery getID;
getID.prepare("select groupID from groups where groupName='"+currentGroupName+"' and dbID='"+currentDbID+"'");
if(getID.exec())
{
while(getID.next())
{
DeleteGroup(getID.value(0).toString());
}
}
}
if(ret==QMessageBox::Cancel)
{
qDebug()<<"Cancel pressed";
}
}
}
}
void HomeScreen::showContextMenu(const QPoint& pos)
{
QPoint globalPos=ui->tableView_info->mapToGlobal(pos);
QMenu myMenu;
myMenu.addAction(QIcon(":/icon1.ico"),"Add Entry");
myMenu.addAction("Edit Entry");
myMenu.addAction("Delete Entry");
myMenu.addAction("Duplicate Entry");
myMenu.addSeparator();
myMenu.addAction("Generate Password");
QAction* selectedItem=myMenu.exec(globalPos);
if(!selectedItem)
{
qDebug()<<"none selected";
}
else
{
if(selectedItem->text()=="Add Entry")
{
qDebug()<<"add entry selected";
//Add new password/key entry
NewEntryForm entry;
entry.setDatabaseID(currentDbID);
entry.setGroupID(currentGroupName);
entry.setMainFormReference(this);
entry.setModal(true);
entry.exec();
}
if(selectedItem->text()=="Edit Entry")
{
qDebug()<<"Edit entry selected..";
QModelIndex index=ui->tableView_info->currentIndex();
currentPassID=index.sibling(index.row(),7).data(0).toString();//set currentPassID to that of the currently selected record in the table
//validate current passID and keyID
NewEntryForm edit;
edit.setMainFormReference(this);
edit.setEditFeatures(currentPassID);//set the Edit Entry form to edit currently selected password
edit.exec();//open the Edit Entry Form
}
if(selectedItem->text()=="Delete Entry")
{
qDebug()<<"Delete entry selected..";
QModelIndex index=ui->tableView_info->currentIndex();
currentPassID=index.sibling(index.row(),7).data(0).toString();//set currentPassID to that of the currently selected record in the table
int ret= QMessageBox::warning(this,tr("Delete"),tr("Are You Sure You want to permanently delete the selected entry?\n"),QMessageBox::Yes|QMessageBox::Cancel,QMessageBox::Cancel);
if (ret==QMessageBox::Yes)
{
DeletePassword(currentPassID);
}
if(ret==QMessageBox::Cancel)
{
qDebug()<<"Cancel pressed";
}
}
if(selectedItem->text()=="Duplicate Entry")
{
qDebug()<<"Duplicate entry selected..";
QModelIndex index=ui->tableView_info->currentIndex();
currentPassID=index.sibling(index.row(),7).data(0).toString();//set currentPassID to that of the currently selected record in the table
DuplicateEntry("passwords",currentPassID);
}
if(selectedItem->text()=="Generate Password")
{
Password gen;
QString str =gen.generatePassword();
//Add new password entry with an already generated password
NewEntryForm entry;
entry.setDatabaseID(currentDbID);
entry.setGroupID(currentGroupName);
entry.setMainFormReference(this);
entry.setTempPassword(str);
entry.setTempUserName(currentDbID);
entry.setModal(true);
entry.exec();
}
}
}
void HomeScreen::showKeyContextMenu(const QPoint & pos)
{
QPoint globalPos=ui->tableView_keyInfo->mapToGlobal(pos);
QMenu myMenu;
myMenu.addAction("Add Entry");
myMenu.addAction("Edit Entry");
myMenu.addAction("Delete Entry");
myMenu.addAction("Duplicate Entry");
QAction* selectedItem=myMenu.exec(globalPos);
if(!selectedItem)
{
//none selected
}
else
{
if(selectedItem->text()=="Add Entry")
{
NewEntryForm entry;
entry.setDatabaseID(currentDbID);
entry.setGroupID(currentGroupName);
entry.setMainFormReference(this);
entry.setModal(true);
entry.exec();
}
if(selectedItem->text()=="Edit Entry")
{
QModelIndex index=ui->tableView_keyInfo->currentIndex();
currentKeyID=index.sibling(index.row(),3).data(0).toString();
NewEntryForm edit;
edit.setMainFormReference(this);
edit.setKeyEditFeatures(currentKeyID);//set the Edit Entry form to edit currently selected key
edit.exec();//open the Edit Entry Form
}
if(selectedItem->text()=="Delete Entry")
{
QModelIndex index=ui->tableView_keyInfo->currentIndex();
currentKeyID=index.sibling(index.row(),3).data(0).toString();
int ret= QMessageBox::warning(this,tr("Delete"),tr("Are You Sure You want to permanently delete the selected entry?\n"),QMessageBox::Yes|QMessageBox::Cancel,QMessageBox::Cancel);
if (ret==QMessageBox::Yes)
{
DeleteKey(currentKeyID);
}
if(ret==QMessageBox::Cancel)
{
qDebug()<<"Cancel pressed";
}
}
if(selectedItem->text()=="Duplicate Entry")
{
QModelIndex index=ui->tableView_keyInfo->currentIndex();
currentKeyID=index.sibling(index.row(),3).data(0).toString();
DuplicateEntry("serials",currentKeyID);
}
}
}
HomeScreen::~HomeScreen()
{
delete ui;
}
void HomeScreen::setDatabaseID(QString id)
{
currentDbID=id;
}
void HomeScreen::setDatabaseName(QString name)
{
currentDbName=name;
AddRoot(currentDbName);//Adds the current database to group tree
qDebug()<<currentDbName;
}
void HomeScreen::AddRoot(QString name)
{
QTreeWidgetItem *group=new QTreeWidgetItem(ui->treeWidget_groups);
group->setText(0,name);
QSqlQuery getGroups;
getGroups.prepare("select groupName from groups where dbID='"+currentDbID+"'");
if(getGroups.exec())
{
while(getGroups.next())
{
AddChild(group,getGroups.value(0).toString());//add each group of the database as a child in the tree
}
}
}
void HomeScreen::AddChild(QTreeWidgetItem *parent,QString name)
{
QTreeWidgetItem *child=new QTreeWidgetItem();
child->setText(0,name);
parent->addChild(child);
}
void HomeScreen::RemoveRoot()
{
ui->treeWidget_groups->clear();
}
void HomeScreen::RefreshTree()
{
ui->treeWidget_groups->clear();
AddRoot(currentDbName);
}
QString HomeScreen::getDatabaseID()
{
return currentDbID;
}
QString HomeScreen::getGroupID()
{
QSqlQuery id;
id.prepare("select groupID from groups where dbID='"+currentDbID+"' and groupName='"+currentGroupName+"'");
if(id.exec())
{
while(id.next())
{
QString gID=id.value(0).toString();
return gID;
}
}
else
QMessageBox::warning(this,tr("Error"),id.lastError().text());
return "None" ;
}
void HomeScreen::loadPasswords(QString id)
{
//load all the passwords to the tableView
QSqlQuery loadPass;
QSqlQueryModel *load=new QSqlQueryModel();
loadPass.prepare("select title,userName,hide,notes,url,creationTime,modificationTime,passID,password from passwords where dbID='"+id+"'");
loadPass.exec();
load->setQuery(loadPass);
load->setHeaderData(0,Qt::Horizontal,QObject::tr("Title"));
load->setHeaderData(1,Qt::Horizontal,QObject::tr("User Name"));
load->setHeaderData(2,Qt::Horizontal,QObject::tr("Password"));
load->setHeaderData(3,Qt::Horizontal,QObject::tr("Notes"));
load->setHeaderData(4,Qt::Horizontal,QObject::tr("URL"));
load->setHeaderData(5,Qt::Horizontal,QObject::tr("Creation Time"));
load->setHeaderData(6,Qt::Horizontal,QObject::tr("Modification Time"));
load->setHeaderData(7,Qt::Horizontal,QObject::tr("Hidden"));
ui->tableView_info->setModel(load);
ui->tableView_info->hideColumn(7);
ui->tableView_info->hideColumn(8);
}
void HomeScreen::RefreshPasswords()
{
QSqlQuery loadPass;
QSqlQueryModel *load=new QSqlQueryModel();
QString id=getGroupID();
loadPass.prepare("select title,userName,hide,notes,url,creationTime,modificationTime,passID,password from passwords where dbID='"+currentDbID+"' and groupID='"+id+"'");
loadPass.exec();
load->setQuery(loadPass);
load->setHeaderData(0,Qt::Horizontal,QObject::tr("Title"));
load->setHeaderData(1,Qt::Horizontal,QObject::tr("User Name"));
load->setHeaderData(2,Qt::Horizontal,QObject::tr("Password"));
load->setHeaderData(3,Qt::Horizontal,QObject::tr("Notes"));
load->setHeaderData(4,Qt::Horizontal,QObject::tr("URL"));
load->setHeaderData(5,Qt::Horizontal,QObject::tr("Creation Time"));
load->setHeaderData(6,Qt::Horizontal,QObject::tr("Modification Time"));
load->setHeaderData(7,Qt::Horizontal,QObject::tr("Hidden"));
ui->tableView_info->setModel(load);
ui->tableView_info->hideColumn(7);
ui->tableView_info->hideColumn(8);
}
void HomeScreen::DeletePassword(QString id)
{
QSqlQuery del;
del.prepare("delete from passwords where passID='"+id+"'");
if(del.exec())
{
qDebug()<<"Password deleted...";
RefreshPasswords();
}
else
{
qDebug()<<del.lastError().text();
}
}
void HomeScreen::loadKeys(QString id)
{
//load all the serial/product keys to the tableView
QSqlQuery loadKey;
QSqlQueryModel *load=new QSqlQueryModel();
loadKey.prepare("select title,serialKey,notes,keyID from serials where dbID='"+id+"'");
loadKey.exec();
load->setQuery(loadKey);
load->setHeaderData(0,Qt::Horizontal,QObject::tr("Title"));
load->setHeaderData(1,Qt::Horizontal,QObject::tr("Serial/Product Key"));
load->setHeaderData(2,Qt::Horizontal,QObject::tr("Notes"));
load->setHeaderData(3,Qt::Horizontal,QObject::tr("Hidden"));
ui->tableView_keyInfo->setModel(load);
ui->tableView_keyInfo->hideColumn(3);
}
void HomeScreen::RefreshKeys()
{
QSqlQuery loadKey;
QSqlQueryModel *load=new QSqlQueryModel();
QString id=getGroupID();
loadKey.prepare("select title,serialKey,notes,keyID from serials where dbID='"+currentDbID+"'and groupID='"+id+"'");
loadKey.exec();
load->setQuery(loadKey);
load->setHeaderData(0,Qt::Horizontal,QObject::tr("Title"));
load->setHeaderData(1,Qt::Horizontal,QObject::tr("Serial/Product Key"));
load->setHeaderData(2,Qt::Horizontal,QObject::tr("Notes"));
load->setHeaderData(3,Qt::Horizontal,QObject::tr("Hidden"));
ui->tableView_keyInfo->setModel(load);
ui->tableView_keyInfo->hideColumn(3);
}
void HomeScreen::DeleteKey(QString id)
{
QSqlQuery del;
del.prepare("delete from serials where keyID='"+id+"'");
if(del.exec())
{
qDebug()<<"Key deleted...";
RefreshKeys();
}
else
{
qDebug()<<del.lastError().text();
}
}
void HomeScreen::DeleteGroup(QString id)
{
QSqlQuery delPasswords,delKeys,delGroup;
delPasswords.prepare("delete from passwords where groupID='"+id+"'");
delKeys.prepare("delete serials where groupID='"+id+"'");
delGroup.prepare("delete from groups where groupID='"+id+"'");
if(delPasswords.exec())
{
if(delKeys.exec())
{
if(delGroup.exec())
{
qDebug()<<"Group deleted....";
RefreshTree();
}
else
qDebug()<<"Error="<<delGroup.lastError().text();
}
else
qDebug()<<"Error="<<delKeys.lastError().text();
}
else
qDebug()<<"Error="<<delPasswords.lastError().text();
}
void HomeScreen::UnlockWorkspace()
{
ui->tableView_info->setVisible(true);
ui->tableView_keyInfo->setVisible(true);
ui->treeWidget_groups->setVisible(true);
ui->actionDatabase_Settings->setEnabled(true);
ui->actionChange_Master_Key->setEnabled(true);
ui->actionLock_Workspace->setEnabled(true);
ui->actionAdd_Group->setEnabled(true);
ui->actionAdd_New_Entry->setEnabled(true);
locked=false;
ui->actionLock_Workspace->setText("Lock Workspace");
}
void HomeScreen::LockWorkspace()
{
ui->tableView_info->setVisible(false);
ui->tableView_keyInfo->setVisible(false);
ui->treeWidget_groups->setVisible(false);
ui->actionDatabase_Settings->setEnabled(false);
ui->actionChange_Master_Key->setEnabled(false);
ui->actionLock_Workspace->setEnabled(false);
ui->actionAdd_Group->setEnabled(false);
ui->actionAdd_New_Entry->setEnabled(false);
this->ui->actionDelete_Entry->setDisabled(true);
this->ui->actionEdit_View_Entry->setDisabled(true);
this->ui->actionDuplicate_Entry->setDisabled(true);
this->ui->actionEdit_Group->setDisabled(true);
this->ui->actionDelete_Group->setDisabled(true);
if(locked)
{
ui->actionLock_Workspace->setEnabled(true);
ui->actionLock_Workspace->setText("Unlock Workspace");
}
}
void HomeScreen::DuplicateEntry(QString entryName, QString id)
{
if(entryName=="passwords")
{
QSqlQuery getDetails,cloneDetails;
getDetails.exec("select title,userName,password,notes,url from passwords where passID='"+id+"'");
getDetails.next();
QString title,userName,password,notes,url,charac;
title=getDetails.value(0).toString();
userName=getDetails.value(1).toString();
password=getDetails.value(2).toString();
notes=getDetails.value(3).toString();
url=getDetails.value(4).toString();
charac="*****";
QString gID=getGroupID();
if( cloneDetails.exec("insert into passwords (dbID,groupID,title,userName,password,notes,url,creationTime,modificationTime,hide)"
"values('"+currentDbID+"','"+gID+"','"+title+"','"+userName+"','"+password+"','"+notes+"','"+url+"',GETDATE(),GETDATE(),'"+charac+"')"))
{
qDebug()<<"Duplicated....";
RefreshPasswords();
}
else
{
qDebug()<<cloneDetails.lastError().text();
}
}
else
{
QSqlQuery getDetails,cloneDetails;
getDetails.exec("select title,serialKey,notes from serials where keyID='"+id+"'");
getDetails.next();
QString title,serialKey,notes;
title=getDetails.value(0).toString();
serialKey=getDetails.value(1).toString();
notes=getDetails.value(2).toString();
QString gID=getGroupID();
if( cloneDetails.exec("insert into serials (dbID,groupID,title,serialKey,notes)"
"values('"+currentDbID+"','"+gID+"','"+title+"','"+serialKey+"','"+notes+"')"))
{
qDebug()<<"Duplicated....";
RefreshKeys();
}
else
{
qDebug()<<cloneDetails.lastError().text();
}
}
}
void HomeScreen::on_actionNew_Database_triggered()
{
MasterPasswordForm masterForm;
masterForm.setMainFormReference(this);//set the master password form to reference the MainWindow
masterForm.exec();//open master password form
masterForm.setModal(true);
this->ui->actionDelete_Entry->setDisabled(true);
this->ui->actionEdit_View_Entry->setDisabled(true);
this->ui->actionDuplicate_Entry->setDisabled(true);
this->ui->actionEdit_Group->setDisabled(true);
this->ui->actionDelete_Group->setDisabled(true);
}
void HomeScreen::on_actionOpen_Database_triggered()
{
OpenDatabaseForm openDB;
openDB.setMainFormReference(this);//set the open database form to reference the MainWindow
openDB.setModal(true);
openDB.exec();//show the open database form
this->ui->actionDelete_Entry->setDisabled(true);
this->ui->actionEdit_View_Entry->setDisabled(true);
this->ui->actionDuplicate_Entry->setDisabled(true);
this->ui->actionEdit_Group->setDisabled(true);
this->ui->actionDelete_Group->setDisabled(true);
if(currentDbID=="None")
{
//no database opened
//do nothing
}
else
{
loadPasswords(currentDbID);//load all the database's passwords
loadKeys(currentDbID);//load all the database's serial/product keys
}
}
void HomeScreen::on_actionEdit_View_Entry_triggered()
{
NewEntryForm edit;
edit.setMainFormReference(this);
if(currentPassID=="None")
{
edit.setKeyEditFeatures(currentKeyID);//set the Edit Entry form to edit currently selected key
}
else
{
edit.setEditFeatures(currentPassID);//set the Edit Entry form to edit currently selected password
}
edit.exec();//open the Edit Entry Form
}
void HomeScreen::on_actionAdd_New_Entry_triggered()
{
//Add new password/key entry
NewEntryForm entry;
entry.setDatabaseID(currentDbID);
entry.setGroupID(currentGroupName);
entry.setMainFormReference(this);
entry.setModal(true);
entry.exec();
}
void HomeScreen::on_actionExit_triggered()
{
QMessageBox::information(this,tr("Vault"),tr("Thank you for using Vault Password Safe"));
dbPtr->connectionClose();//close database connection
this->close();//exit program
}
void HomeScreen::on_actionChange_Master_Key_triggered()
{
ChangeMasterKeyForm form;//Form to change the database's master key
form.SetDbID(currentDbID);
form.exec();
}
void HomeScreen::on_actionAdd_Group_triggered()
{
//Open form to add a new Group
Groups newGroup;
newGroup.setMainFormReference(this);
newGroup.setDbID(currentDbID);
newGroup.exec();
}
void HomeScreen::on_treeWidget_groups_itemClicked(QTreeWidgetItem *item, int column)
{
currentGroupName=item->data(column,0).toString();
if(currentGroupName==currentDbName)
{
currentGroupName="Default";
}
else
{
//Only show passwords and keys for currently selected group
this->ui->actionEdit_Group->setDisabled(false);
this->ui->actionDelete_Group->setDisabled(false);
RefreshPasswords();
RefreshKeys();
}
qDebug()<<currentGroupName;
}
void HomeScreen::on_actionEdit_Group_triggered()
{
Groups editForm;
editForm.setMainFormReference(this);
editForm.setEditFeatures(currentGroupName,currentDbID);//set Edit Form to edit currently selected group
editForm.exec();
}
void HomeScreen::on_tableView_info_doubleClicked(const QModelIndex &index)
{
//allow editing for currently selected password
this->ui->actionDelete_Entry->setDisabled(false);
this->ui->actionEdit_View_Entry->setDisabled(false);
this->ui->actionDuplicate_Entry->setDisabled(false);
int col= index.column();
int row=index.row();
currentPassID=index.sibling(row,7).data(0).toString();
if(col==0)//if 1st column double clicked open EditForm
{
NewEntryForm edit;
edit.setMainFormReference(this);
edit.setEditFeatures(currentPassID);
edit.exec();
return;
}
if(col==2)//if password column double clicked
{
QString pass=index.sibling(row,8).data(0).toString();
QClipboard *clipboard=QApplication::clipboard();
clipboard->setText(pass,QClipboard::Clipboard);
return;
}
if(col==4)//if url clicked
{
QDesktopServices::openUrl(QUrl(index.data(0).toString()));
}
else//copy the text to the clipboard for pasting
{
QClipboard *clipboard=QApplication::clipboard();
clipboard->setText(index.data(0).toString(),QClipboard::Clipboard);
}
qDebug()<<QString::number(col);
}
void HomeScreen::on_actionDelete_Entry_triggered()
{
int ret= QMessageBox::warning(this,tr("Delete"),tr("Are You Sure You want to permanently delete the selected entry?\n"),QMessageBox::Yes|QMessageBox::Cancel,QMessageBox::Cancel);
if (ret==QMessageBox::Yes)
{
if(currentKeyID=="None")
{
DeletePassword(currentPassID);
}
else
{
DeleteKey(currentKeyID);
}
}
if(ret==QMessageBox::Cancel)
{
qDebug()<<"Cancel pressed";
}
}
void HomeScreen::on_tableView_info_clicked(const QModelIndex &index)
{
this->ui->actionDelete_Entry->setDisabled(false);
this->ui->actionEdit_View_Entry->setDisabled(false);
this->ui->actionDuplicate_Entry->setDisabled(false);
int row=index.row();
currentPassID=index.sibling(row,7).data(0).toString();//set currentPassID to that of the currently selected record in the table
}
void HomeScreen::on_tableView_keyInfo_doubleClicked(const QModelIndex &index)
{
this->ui->actionDelete_Entry->setDisabled(false);
this->ui->actionEdit_View_Entry->setDisabled(false);
this->ui->actionDuplicate_Entry->setDisabled(false);
int col= index.column();
int row=index.row();
currentKeyID=index.sibling(row,3).data(0).toString();
if(col==0)//open EditForm to edit the Key's Information
{
NewEntryForm edit;
edit.setMainFormReference(this);
edit.setKeyEditFeatures(currentKeyID);
edit.exec();
}
else//copy selected text to the clipboard
{
QClipboard *clipboard=QApplication::clipboard();
clipboard->setText(index.data(0).toString(),QClipboard::Clipboard);
}
qDebug()<<QString::number(col);
}
void HomeScreen::on_tableView_keyInfo_clicked(const QModelIndex &index)
{
int row=index.row();
currentKeyID=index.sibling(row,3).data(0).toString();//set currentKeyID to that of the currently selected record in the table
this->ui->actionDelete_Entry->setDisabled(false);
this->ui->actionEdit_View_Entry->setDisabled(false);
this->ui->actionDuplicate_Entry->setDisabled(false);
}
void HomeScreen::on_tabWidget_tabBarClicked(int index)
{
//reset values every time the tabBar is clicked
if(index==0)
{
currentKeyID="None";
}
else
{
currentPassID="None";
}
this->ui->actionEdit_View_Entry->setDisabled(true);
this->ui->actionDelete_Entry->setDisabled(true);
this->ui->actionDuplicate_Entry->setDisabled(true);
}
void HomeScreen::on_actionLock_Workspace_triggered()
{
//Hides all info on screen and prevents use till the user opens the database again
locked=true;
LockWorkspace();
OpenDatabaseForm lock;
lock.setLockFeatures(currentDbID);
lock.setMainFormReference(this);
lock.setModal(true);
lock.exec();
if(locked==true)
this->showMinimized();
}
void HomeScreen::on_actionDatabase_Settings_triggered()
{
//Change the details for the database
DatabaseSettingsForm edit;
edit.setMainFormReference(this);
edit.setEdit(currentDbID);
edit.exec();
}
void HomeScreen::on_actionDelete_Group_triggered()
{
int ret= QMessageBox::warning(this,tr("Delete"),tr("Are You Sure You want to permanently delete the selected group?\nDoing so will also delete the entries in that group."),QMessageBox::Yes|QMessageBox::Cancel,QMessageBox::Cancel);
if (ret==QMessageBox::Yes)
{
QSqlQuery getID;
getID.prepare("select groupID from groups where groupName='"+currentGroupName+"' and dbID='"+currentDbID+"'");
if(getID.exec())
{
while(getID.next())
{
DeleteGroup(getID.value(0).toString());
}
}
}
if(ret==QMessageBox::Cancel)
{
qDebug()<<"Cancel pressed";
}
}
void HomeScreen::on_actionAbout_Vault_triggered()
{
About about;
about.setModal(true);
about.exec();
}
void HomeScreen::on_actionDuplicate_Entry_triggered()
{
if(currentKeyID=="None")//if a password is the currently selected item
{
DuplicateEntry("passwords",currentPassID);
}
else//a key is the currently selected item
{
DuplicateEntry("serials",currentKeyID);
}
}