-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabasesettingsform.cpp
More file actions
73 lines (69 loc) · 2.06 KB
/
databasesettingsform.cpp
File metadata and controls
73 lines (69 loc) · 2.06 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
#include "databasesettingsform.h"
#include "ui_databasesettingsform.h"
#include <QMessageBox>
DatabaseSettingsForm::DatabaseSettingsForm(QWidget *parent) :
QDialog(parent),
ui(new Ui::DatabaseSettingsForm),edit(false)
{
ui->setupUi(this);
}
DatabaseSettingsForm::~DatabaseSettingsForm()
{
delete ui;
}
void DatabaseSettingsForm::setMasterKey(QString key)
{
newDatabase.SetMasterKey(key);
}
void DatabaseSettingsForm::setMainFormReference(HomeScreen *mainForm)
{
main=mainForm;
}
void DatabaseSettingsForm::setEdit(QString id)
{
edit=true;
dbID=id;
}
void DatabaseSettingsForm::on_buttonBox_Response_accepted()
{
QString dbName,dbDescription,dbUserName;
dbName=ui->lineEdit_dbName->text();
dbDescription=ui->lineEdit_description->text();
dbUserName=ui->lineEdit_userName->text();
if(edit)//changing details of currently open database
{
main->RemoveRoot();
newDatabase.SetDbName(dbName);
newDatabase.SetDescription(dbDescription);
newDatabase.SetUserName(dbUserName);
newDatabase.SetDbID(dbID);
newDatabase.EditSettings();
main->setDatabaseName(newDatabase.getDbName());
this->close();
}
else//entering details for a new database
{
//Make sure the database has a unique name
QSqlQuery check;
check.exec("select count(*) from databases where dbName='"+dbName+"'");
check.next();
int count=check.value(0).toInt();
if(count>0)
{
QMessageBox::warning(this,tr("Database Name"),tr("A database with that name already exists, would you please user another name"));
return;
}
newDatabase.SetDbName(dbName);
newDatabase.SetDescription(dbDescription);
newDatabase.SetUserName(dbUserName);
newDatabase.SaveSettings();
main->setDatabaseID(newDatabase.getDbID());
main->setDatabaseName(newDatabase.getDbName());
main->UnlockWorkspace();
this->close();
}
}
void DatabaseSettingsForm::on_buttonBox_Response_rejected()
{
this->close();
}