-
Notifications
You must be signed in to change notification settings - Fork 3
/
fix8logInit.cpp
357 lines (331 loc) · 13.8 KB
/
fix8logInit.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
Fix8logviewer is released under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
Fix8logviewer Open Source FIX Log Viewer.
Copyright (C) 2010-14 David N Boosalis [email protected], David L. Dight <[email protected]>
Fix8logviewer is free software: you can redistribute it and / or modify it under the terms of the
GNU Lesser General Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
Fix8logviewer 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.
You should have received a copy of the GNU Lesser General Public License along with Fix8.
If not, see <http://www.gnu.org/licenses/>.
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO
THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO
THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED
ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
//-------------------------------------------------------------------------------------------------
#include "database.h"
#include "fix8log.h"
#include "fix8sharedlib.h"
#include "fixmimedata.h"
#include "globals.h"
#include "mainwindow.h"
#include "messagefield.h"
#include "newwindowwizard.h"
#include "schemaeditordialog.h"
#include "worksheetmodel.h"
#include "windowdata.h"
#include <QApplication>
#include <QDebug>
#include <QtWidgets>
#include <QThreadPool>
#include "worksheetmodel.h"
#include <fix8/f8includes.hpp>
#include "fix8/field.hpp"
#include "fix8/message.hpp"
#include <fix8/f8types.hpp>
#include <iostream>
#include <string.h>
using namespace GUI;
using namespace FIX8;
using namespace std;
bool Fix8Log::init()
{
bool bstatus;
bool createdTable = false;
QString errorStr;
QString fieldName;
QString key;
QString value;
quint32 ikey;
Fix8SharedLib *f8lib = 0;
QString fileName;
QString libName;
int status;
FieldTrait::FieldType ft;
const BaseMsgEntry *tbme;
WorkSheetModel *model = 0;
QList <WindowData> windowDataList;
WindowData wd;
const BaseEntry *tbe;
messageFieldList = new MessageFieldList();
MessageField *messageField;
QStringList errorStrList;
MainWindow *newMW;
//QMap <QString, QStandardItemModel *>::iterator currentItemIter;
bool haveError = false;
readSettings();
initDatabase();
copySampleFilesToUser();
QThreadPool::globalInstance()->setMaxThreadCount(10);
// initial screeen
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,10);
windowDataList = database->getWindows();
// cleanWindowDataList(windowDataList);
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,10);
QListIterator <WindowData> iter(windowDataList);
Fix8SharedLib *fixlib;
// qDebug() << "AUTO SAVE ON:" << autoSaveOn << __FILE__ << __LINE__;
if (autoSaveOn){
while(iter.hasNext()) {
wd = iter.next();
if (wd.fix8sharedlib.length() > 0) {
fixlib = fix8ShareLibList.findByFileName(wd.fix8sharedlib);
if (!fixlib) {
// qDebug() << "Create Shared Lib" << __FILE__ << __LINE__;
bstatus = createSharedLib(wd.fix8sharedlib,&fixlib,defaultTableSchema);
if (!bstatus)
goto done;
fix8ShareLibList.append(fixlib);
}
wd.tableSchema = fixlib->getTableSchema(wd.tableSchemaID);
if (!wd.tableSchema) {
wd.tableSchema = fixlib->getDefaultTableSchema();
if (wd.tableSchema)
wd.tableSchemaID = wd.tableSchema->id;
}
else
fixlib->generateSchema(wd.tableSchema);
newMW = new MainWindow(database,true,0);
newMW->setSharedLibrary(fixlib);
//newMW->setTableSchema(wd.tableSchema);
newMW->setFieldUsePair(&(fixlib->fieldUsePairList));
newMW->setSearchFunctions(searchFunctionList);
newMW->setFilterFunctions(filterFunctionList);
wireSignalAndSlots(newMW);
mainWindows.append(newMW);
newMW->setAutoSaveOn(autoSaveOn);
// have to set style sheet after show to see it take effect
newMW->mainMenuBar->setStyleSheet(wd.menubarStyleSheet);
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,40);
QList <WorkSheetData> wsdList = database->getWorkSheets(wd.id);
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,40);
if (!wd.tableSchema) {
wd.tableSchema = fixlib->getDefaultTableSchema();
}
newMW->setWindowData(wd);
newMW->show();
if (wsdList.count() > 0) {
QListIterator <WorkSheetData> iter2(wsdList);
while(iter2.hasNext()) {
WorkSheetData wsd = iter2.next();
//currentItemIter = fileNameModelMap.find(wsd.fileName);
newMW->addWorkSheet(wsd); // do not create model, have code reuse and redo busy screen for each tab
newMW->setCurrentTabAndSelectedRow(wd.currentTab,2);
}
}
newMW->setLoading(false);
}
done:
;
}
}
displayConsoleMessage("Session restored from autosave");
if (mainWindows.count() < 1) {
newWindowWizard = new NewWindowWizard(fix8ShareLibList,firstTimeToUse);
if (!firstTimeToUse)
newWindowWizard->readSettings();
else
newWindowWizard->resize(newWindowWizard->sizeHint());
// QDesktopWidget *desktop = QApplication::desktop();
status = newWindowWizard->exec();
newWindowWizard->saveSettings();
if (status != QDialog::Accepted) {
if (dbFile) {
dbFile->remove();
delete dbFile;
}
qApp->exit(0);
return false;
}
qDebug() << "Continue after newWindowWizard, status = " << status << __FILE__ << __LINE__;
fileName = newWindowWizard->getSelectedFile();
libName = newWindowWizard->getSelectedLib();
bstatus = createSharedLib(libName,&f8lib,defaultTableSchema);
if (!bstatus) {
errorStr = "Error2 - failed to load FIX8 sharelib: " + libName;
QMessageBox::warning(0,Globals::appName,errorStr);
newWindowWizard->deleteLater();
qApp->exit(0);
return false;
}
if (!f8lib) {
qWarning() << ">>>>>>>>>>>>>SHARE LIB SET TO" << f8lib->fileName << __FILE__ << __LINE__;
errorStr = "Error - failed to create FIX8 sharelib: " + libName;
QMessageBox::warning(0,Globals::appName,errorStr);
newWindowWizard->deleteLater();
qApp->exit(0);
return false;
}
if (!(f8lib->isOK)) {
qWarning() << ">>>>>>>>>>>>>SHARE LIB SET TO" << f8lib->fileName << __FILE__ << __LINE__;
errorStr = "Error - FIX8 sharelib: " + libName + " has error.";
QMessageBox::warning(0,Globals::appName,errorStr);
newWindowWizard->deleteLater();
qApp->exit(0);
return false;
}
newMW = new MainWindow(database);
newMW->setAutoSaveOn(autoSaveOn);
// have to set style sheet after show to see it take effect
newMW->mainMenuBar->setStyleSheet(wd.menubarStyleSheet);
fix8ShareLibList.append(f8lib);
newMW->setSearchFunctions(searchFunctionList);
newMW->setFilterFunctions(filterFunctionList);
wireSignalAndSlots(newMW);
newMW->setSharedLibrary(f8lib);
newMW->setFieldUsePair(&(f8lib->fieldUsePairList));
newMW->setAutoSaveOn(autoSaveOn);
//windowData.tableSchema = f8lib->getDefaultTableSchema();
wd = newMW->getWindowData();
wd.tableSchema = f8lib->defaultTableSchema;
wd.tableSchemaID = f8lib->defaultTableSchema->id;
wd.fix8sharedlib = f8lib->fileName;
newMW->setWindowData(wd);
newMW->show();
newMW->loadFile(fileName);
newMW->setAutoSaveOn(autoSaveOn);
mainWindows.append(newMW);
}
return true;
}
bool Fix8Log::init(QString fileNameToLoad)
{
/*
WorkSheetModel *model = 0;
MainWindow *newMW =new MainWindow(database,true);
newMW->setFieldUsePair(&fieldUsePairList);
newMW->setSearchFunctions(searchFunctionList);
WindowData wd;
WorkSheetData wsd;
QString errorStr;
wsd.fileName = fileNameToLoad;
wd.isVisible = true;
wd.name = "Fix8LogViewer";
wireSignalAndSlots(newMW);
newMW->setWindowData(wd);
wireSignalAndSlots(newMW);
mainWindows.append(newMW);
newMW->setLoadMessage("Loading File " + wsd.fileName);
model = readLogFile(wsd.fileName,errorStr);
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,4);
if (model) {
fileNameModelMap.insert(wsd.fileName,model);
newMW->addWorkSheet(model,wsd);
newMW->show();
}
newMW->setLoading(false);
*/
return true;
}
bool Fix8Log::createSharedLib(QString &fix8sharedlib,Fix8SharedLib **fixlib,
TableSchema *defaultTableSchema)
{
bool bstatus;
TableSchemaList *tsl;
*fixlib = Fix8SharedLib::create(fix8sharedlib);
if (!fixlib) {
qWarning() << "Create shared lib vailed, value is null" << __FILE__ << __LINE__;
return false;
}
if (!*fixlib) {
qWarning() << "1 FAILED TO CREATED SHARED LIB FOR " << fix8sharedlib;
return false;
}
if(!(*fixlib)->isOK) {
qWarning() << "2 FAILED TO CREATED SHARED LIB FOR " << fix8sharedlib;
return false;
}
tsl = database->getTableSchemasByLibName((*fixlib)->fileName);
if (!tsl) {
qWarning() << "NO table schemas found for shared lib:"
<< (*fixlib)->fileName << __FILE__ << __LINE__;
tsl = new TableSchemaList();
}
QListIterator <TableSchema *> tsiter(*tsl);
while(tsiter.hasNext()) {
TableSchema *ts = tsiter.next();
ts->fieldNames = database->getSchemaFields(ts->id);
(*fixlib)->generateSchema(ts);
}
(*fixlib)->setTableSchemas(tsl);
defaultTableSchema = tsl->findDefault();
if (!defaultTableSchema) {
qWarning() << "HEY NO DEFAULT TABLE SCHEMA FOUND............" << __FILE__ << __LINE__;
defaultTableSchema = (*fixlib)->createDefaultTableSchema();
if (defaultTableSchema) {
tsl->append(defaultTableSchema);
bstatus = database->addTableSchema(*defaultTableSchema);
if (bstatus ) {
qWarning() << "Save default table schema to database";
database->saveTableSchemaFields(*defaultTableSchema);
}
}
else {
qWarning() << "Failed to create default table schema for share lib: " << (*fixlib)->fileName << __FILE__ << __LINE__;
}
//qDebug() << "FIELD NAMES: " << defaultTableSchema->fieldNames << __FILE__ << __LINE__;
(*fixlib)->generateSchema(defaultTableSchema);
}
(*fixlib)->setDefaultTableSchema(defaultTableSchema);
(*fixlib)->setTableSchemas(tsl);
//qDebug() << "STATUS OF SHARED LIB AT END = " << (*fixlib)->isOK << __FILE__ << __LINE__;
return true;
}
bool Fix8Log::copySampleFilesToUser()
{
bool bstatus;
QDir systemDir(qApp->applicationDirPath() + "/samples");
QDir usersDir(QDir::homePath() + "/f8logview/samples");
if (!systemDir.exists()) {
qWarning() << "System sample files not found:" << systemDir.absolutePath() << __FILE__ << __LINE__;
sampleFilesAvailable = false;
return false;
}
if (!usersDir.exists()) {
bstatus = usersDir.mkdir(usersDir.absolutePath());
if (!bstatus) {
qWarning() << "Failed to create a path for " << usersDir.absolutePath() << __FILE__ << __LINE__;
sampleFilesAvailable = false;
return false;
}
}
QFileInfoList fileInfoList = systemDir.entryInfoList(QDir::Files |QDir::NoDotAndDotDot| QDir::NoSymLinks);
QFileInfo fi;
QStandardItem *si;
QListIterator<QFileInfo> iter(fileInfoList);
while(iter.hasNext()) {
QString baseName;
fi = iter.next();
baseName = fi.fileName();
QString userFileName = usersDir.path() + QDir::separator() + baseName;
QFile userFile(userFileName);
if (!userFile.exists()) {
qDebug() << "Creating user file: " << userFileName << __FILE__ << __LINE__;
//QFile oldFile(fi.absoluteFilePath());
QFile::copy(fi.absoluteFilePath(),userFileName);
}
}
return true;
}