-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
120 lines (100 loc) · 3.69 KB
/
main.cpp
File metadata and controls
120 lines (100 loc) · 3.69 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
/*
* QHamLog - Simple, cross-platform, ADIF-compliant Amateur Radio QSO logging application
* Copyright (C) 2013 Alex Gladd
*
* QHamLog 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 3 of the License, or
* (at your option) any later version.
*
* QHamLog 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 QHamLog. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mainlogwindow.h"
#include "adifenums.h"
#include "qsolog.h"
#include <QApplication>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// splash screen example: http://qt-project.org/forums/viewthread/16927
/*
* TODO: Do all of this initialization while displaying a splash screen. Also load up all of the
* enumeration models now, so that the UI can just access them later.
*/
// BEGIN INITIALIZATION
QString appPath = QDir::homePath() + "/.qhamlog";
QString adifEnumsDbPath = appPath + "/adif-enums.db";
QString qsoLogDbPath = appPath + "/qso-log.db";
// the application directory ${HOME}/.qhamlog
QDir appDir(appPath);
if(!appDir.exists()) {
qDebug() << "Main: creating .qhamlog app directory: " << appPath;
if(!appDir.mkpath(appPath)) {
qCritical() << "Main: couldn't create .qhamlog app directory";
return 1;
}
}
// file permissions for db files
QFile::Permissions perm = QFile::WriteOwner | QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther;
// copy empty qso log if no log db file exists
if(!QFile::exists(qsoLogDbPath)) {
if(!QFile::copy(":/db/empty-qsolog", qsoLogDbPath)) {
qCritical() << "Main: couldn't copy empty QSO log database to filesystem";
return 1;
} else {
// set correct file permissions
QFile logDb(qsoLogDbPath);
if(!logDb.setPermissions(perm)) {
qCritical() << "Main: couldn't set permissions on empty QSO log database";
logDb.remove();
return 1;
}
}
}
// remove any existing enum db file
// TODO eventually only do this if there were DB changes
if(QFile::exists(adifEnumsDbPath) && !QFile::remove(adifEnumsDbPath)) {
qWarning() << "Main: couldn't delete existing ADIF enums database";
}
// copy enum db file out
if(!QFile::copy(":/db/adifenums", adifEnumsDbPath)) {
qCritical() << "Main: couldn't copy new ADIF enums database to filesystem";
return 1;
} else {
// copy success; set correct permissions
QFile adifDb(adifEnumsDbPath);
if(!adifDb.setPermissions(perm)) {
qCritical() << "Main couldn't set permissions on ADIF Enums database";
adifDb.remove();
return 1;
}
}
// init QSO log
if(!log::QsoLog::init(qsoLogDbPath.toStdString())) {
qCritical() << "Main: QSO log init failed";
return 1;
}
// init ADIF enums
if(!adif::AdifEnums::init(adifEnumsDbPath.toStdString())) {
qCritical() << "Main: ADIF enums init failed";
return 1;
}
// END INITIALIZATION
MainLogWindow w;
w.show();
int r = a.exec();
// cleanup
log::QsoLog::destroy();
adif::AdifEnums::destroy();
return r;
}