-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
88 lines (76 loc) · 2.95 KB
/
main.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
/**
DtBom
Copyright (C) 2014 RADICS Áron
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "mainwindow.h"
#include <QApplication>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setApplicationName("DtBom");
QApplication::setApplicationVersion(APP_VERSION);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
bool quit = false;
do
{
QFileDialog fd;
fd.setNameFilter("*.dtbom");
fd.setDefaultSuffix("dtbom");
fd.setAcceptMode(QFileDialog::AcceptSave);
fd.setConfirmOverwrite(false);
if (fd.exec())
{
db.setDatabaseName(fd.selectedFiles()[0]);
}
if (!db.open())
{
QMessageBox mbox;
mbox.setWindowTitle(QMessageBox::trUtf8("File open / create failed."));
mbox.setText(QMessageBox::trUtf8("File open / create failed.\nTry again?"));
mbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
quit = mbox.exec() == QMessageBox::No;
}
}
while( (!db.isOpen()) && (!quit) );
if (!quit)
{
QSqlQuery query(db);
query.exec("create table if not exists parts (id TEXT PRIMARY KEY, refdes TEXT, part TEXT, type TEXT, value TEXT, pattern TEXT, shop TEXT, shopid TEXT);");
query.exec("create table if not exists info (key TEXT PRIMARY KEY, val TEXT)");
query.exec("insert or replace into info (key, val) VALUES ('last open', CURRENT_TIMESTAMP);");
query.exec("insert or ignore into info (key, val) VALUES ('created', CURRENT_TIMESTAMP);");
query.exec("insert or ignore into info (key, val) VALUES ('db version', '" + QString::number(DB_VERSION) + "');");
query.exec("select val from info where key = 'db version'");
if (query.first())
{
if (query.value(0).toInt() < DB_VERSION)
{
// TODO
qCritical("old db version");
}
if (query.value(0).toInt() > DB_VERSION)
{
// TODO
qCritical("new db version");
}
}
MainWindow w(db);
w.show();
return a.exec();
}
return EXIT_FAILURE;
}