-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimetrackerapp.cpp
50 lines (43 loc) · 1.47 KB
/
timetrackerapp.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
#include "timetrackerapp.h"
#define ORG_NAME "HumbertoApps"
#define APP_NAME "TimeTracker"
#define DB_NAME "timetracker.sqlite"
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDir>
#include <QDesktopWidget>
TimeTrackerApp::TimeTrackerApp(int & argc, char** argv) :
QApplication(argc, argv)
{
setOrganizationName(ORG_NAME);
setApplicationName(APP_NAME);
initDB();
mainWindow = new MainWindow();
QRect frect = mainWindow->frameGeometry();
frect.moveCenter(QDesktopWidget().availableGeometry().center());
mainWindow->move(frect.topLeft());
mainWindow->show();
}
TimeTrackerApp::~TimeTrackerApp()
{
delete mainWindow;
closeDB();
}
void TimeTrackerApp::initDB()
{
QString path(QDir::homePath());
path.append(QDir::separator()).append(DB_NAME);
path = QDir::toNativeSeparators(path);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(path);
db.open();
QSqlQuery ("create table project(id integer primary key, name text, description text, created text, lastModified text)");
QSqlQuery ("create table timespan(id integer primary key, start text, end text, projectId integer, FOREIGN KEY(projectId) REFERENCES project(id))");
QSqlQuery ("create index project_id ON project (id)");
QSqlQuery ("create index timespan_id ON timespan (id)");
}
void TimeTrackerApp::closeDB()
{
QSqlDatabase db = QSqlDatabase::database();
db.close();
}