-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanagedatabases.cpp
More file actions
187 lines (173 loc) · 5.23 KB
/
managedatabases.cpp
File metadata and controls
187 lines (173 loc) · 5.23 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
#include "managedatabases.h"
#include "ui_managedatabases.h"
#include <QSettings>
#include "importdatabase.h"
#include <QMessageBox>
#include <QFile>
#include "clonedatabase.h"
#include <QDebug>
#include <QProcess>
ManageDatabases::ManageDatabases(QWidget *parent) :
QDialog(parent),
ui(new Ui::ManageDatabases)
{
ui->setupUi(this);
m_databases = new databaseModel(this);
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
m_databases->loadDatabases(settings.value("database_file").toString());
ui->tableView->setModel(m_databases);
ui->tableView->resizeColumnsToContents();
ui->tableView->hideColumn(0);
this->setWindowTitle("Set Parameter");
QString dbman_file = settings.value("dbman_file","").toString();
if (dbman_file.simplified() != "" && QFile::exists(dbman_file))
{
ui->cmdeditdata->setEnabled(true);
db_browser_binary = dbman_file;
}
else
{
ui->cmdeditdata->setEnabled(false);
ui->cmdeditdata->setText("You need to configure DB Browser for SQLite in the settings");
}
}
ManageDatabases::~ManageDatabases()
{
delete ui;
}
void ManageDatabases::on_cmdClose_clicked()
{
this->close();
}
void ManageDatabases::on_cmdImport_clicked()
{
importDatabase impDB;
impDB.exec();
if (impDB.db_code != "")
{
if (!m_databases->addDatabase(impDB.db_code, impDB.db_name, impDB.db_path))
{
QMessageBox msgBox;
msgBox.setText("The code already exists");
msgBox.exec();
}
}
}
void ManageDatabases::on_cmdClone_clicked()
{
if (ui->tableView->selectionModel()->selectedRows().count() == 1)
{
int row;
row = ui->tableView->selectionModel()->selectedRows()[0].row();
QString db_path = m_databases->getDBPath(row);
if (QFile::exists(db_path))
{
cloneDatabase clone;
QString db_code = m_databases->getDBCode(row);
QString db_name = m_databases->getDBName(row);
clone.setFrom(db_code,db_name,db_path);
clone.exec();
if (clone.db_code != "")
{
if (m_databases->addDatabase(clone.db_code, clone.db_name, clone.db_path))
{
QFile::copy(db_path, clone.db_path);
}
else
{
QMessageBox msgBox;
msgBox.setText("The code already exists");
msgBox.exec();
}
}
}
else
{
QMessageBox msgBox;
msgBox.setText("The database file does not exist");
msgBox.exec();
}
}
else
{
QMessageBox msgBox;
msgBox.setText("You need to select a database");
msgBox.exec();
}
}
void ManageDatabases::on_cmdDelete_clicked()
{
if (ui->tableView->selectionModel()->selectedRows().count() == 1)
{
int row;
row = ui->tableView->selectionModel()->selectedRows()[0].row();
if (m_databases->isDBRemovable(row))
{
QString db_code = m_databases->getDBCode(row);
QMessageBox msgBox;
msgBox.setText("Delete database \"" + db_code + "\"");
msgBox.setInformativeText("Do you want to delete this database?");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
if (ret == QMessageBox::Ok)
{
m_databases->deleteDatabase(row);
}
}
else
{
QMessageBox msgBox;
msgBox.setText("You cannot delete this database");
msgBox.exec();
}
}
else
{
QMessageBox msgBox;
msgBox.setText("You need to select a database");
msgBox.exec();
}
}
void ManageDatabases::on_cmdeditdata_clicked()
{
if (ui->tableView->selectionModel()->selectedRows().count() == 1)
{
int row;
row = ui->tableView->selectionModel()->selectedRows()[0].row();
QString db_path = m_databases->getDBPath(row);
if (QFile::exists(db_path))
{
QString db_code = m_databases->getDBCode(row);
if (db_code != "empty")
{
QStringList arguments;
arguments << db_path;
QProcess *myProcess = new QProcess(this);
myProcess->start(db_browser_binary, arguments);
myProcess->waitForFinished(-1);
}
else
{
QMessageBox msgBox;
msgBox.setText("You cannot edit the empty database. You need to clone it first.");
msgBox.exec();
}
}
else
{
QMessageBox msgBox;
msgBox.setText("The database file does not exist");
msgBox.exec();
}
}
}
void ManageDatabases::set_controls(bool status)
{
ui->cmdeditdata->setEnabled(status);
ui->cmdClone->setEnabled(status);
ui->cmdClose->setEnabled(status);
ui->cmdDelete->setEnabled(status);
ui->cmdImport->setEnabled(status);
ui->tableView->setEnabled(status);
}