-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
8551 lines (7275 loc) · 300 KB
/
mainwindow.cpp
File metadata and controls
8551 lines (7275 loc) · 300 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
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @licence app begin@
* Copyright (C) 2011-2012 BMW AG
*
* This file is part of COVESA Project Dlt Viewer.
*
* Contributions are licensed to the COVESA Alliance under one or more
* Contribution License Agreements.
*
* \copyright
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* \file mainwindow.cpp
* For further information see http://www.covesa.global/.
* @licence end@
*/
#include "filtergrouplogs.h"
#include <algorithm>
#include <QMimeData>
#include <QTreeView>
#include <QFileDialog>
#include <QProgressDialog>
#include <QTemporaryFile>
#include <QPluginLoader>
#include <QPushButton>
#include <QKeyEvent>
#include <QClipboard>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QFileSystemModel>
#include <QLineEdit>
#include <QUrl>
#include <QDateTime>
#include <QLabel>
#include <QInputDialog>
#include <QByteArray>
#include <QSysInfo>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QNetworkProxyFactory>
#include <QNetworkInterface>
#include <QSortFilterProxyModel>
#include <QDesktopServices>
#include <QProcess>
#include <QStyleFactory>
#include <QTextStream>
#include <QTemporaryFile>
#include <QtEndian>
#include <QDir>
#include <QDirIterator>
#include <QThread>
#include <QTableWidget>
#if defined(_MSC_VER)
#include <io.h>
#include <WinSock.h>
#endif
#include "mainwindow.h"
#include "ecudialog.h"
#include "applicationdialog.h"
#include "contextdialog.h"
#include "multiplecontextdialog.h"
#include "plugindialog.h"
#include "settingsdialog.h"
#include "injectiondialog.h"
#include "version.h"
#include "dltfileutils.h"
#include "dltuiutils.h"
#include "qdltexporter.h"
#include "qdltimporter.h"
#include "jumptodialog.h"
#include "fieldnames.h"
#include "tablemodel.h"
#include "qdltoptmanager.h"
#include "qdltctrlmsg.h"
#include <qdltmsgwrapper.h>
#include "ecutree.h"
#include "updatechecker.h"
#include "filespliting.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
timer(this),
qcontrol(this),
pulseButtonColor(255, 40, 40),
isSearchOngoing(false),
crlfFilterWindow(nullptr)
{
dltIndexer = NULL;
settings = QDltSettingsManager::getInstance();
ui->setupUi(this);
ui->enableConfigFrame->setVisible(false);
setAcceptDrops(true);
target_version_string = "";
searchDlg->loadSearchHistoryList(searchHistory);
filterIsChanged = false;
initState();
/* Apply loaded settings */
initSearchTable();
initView();
applySettings();
initSignalConnections();
initFileHandling();
/* Commands plugin after loading log file */
qDebug() << "### Plugin commands after loading log file";
if(!QDltOptManager::getInstance()->getPostPluginCommands().isEmpty())
{
QStringList commands = QDltOptManager::getInstance()->getPostPluginCommands();
for(int num = 0; num< commands.size();num++)
{
qDebug() << "Command:" << commands[num];
QStringList args = commands[num].split("|");
if(args.size() > 1)
{
QString pluginName = args.at(0);
QString commandName = args.at(1);
args.removeAt(0);
args.removeAt(0);
QStringList commandParams = args;
commandLineExecutePlugin(pluginName,commandName,commandParams);
}
}
}
filterUpdate(); // update filters of qfile before starting Exporting for RegEx operation
if(!QDltOptManager::getInstance()->getConvertDestFile().isEmpty())
{
switch ( QDltOptManager::getInstance()->get_convertionmode() )
{
case e_UTF8:
commandLineConvertToUTF8();
break;
case e_DLT:
commandLineConvertToDLT();
break;
case e_ASCI:
commandLineConvertToASCII();
break;
case e_CSV:
commandLineConvertToCSV();
break;
case e_DDLT:
commandLineConvertToDLTDecoded();
break;
default:
commandLineConvertToASCII();
break;
}
}
if(QDltOptManager::getInstance()->isTerminate())
{
qDebug() << "### Terminate DLT Viewer by option -t";
exit(0);
}
/* auto connect */
if( (settings->autoConnect != 0) ) // in convertion mode we do not need any connection ...)
{
connectAll();
}
/* start timer for autoconnect */
connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); // we want to start the timer only when an ECU connection is active
restoreGeometry(settings->geometry);
restoreState(settings->windowState);
/* update plugins again to hide plugins shown before after restoreState */
updatePlugins();
/*sync checkboxes with action toolbar*/
ui->actionToggle_FiltersEnabled->setChecked(ui->filtersEnabled->isChecked());
ui->actionToggle_PluginsEnabled->setChecked(ui->pluginsEnabled->isChecked());
ui->actionToggle_SortByTimeEnabled->setChecked(ui->checkBoxSortByTime->isChecked());
ui->actionSort_By_Timestamp->setChecked(ui->checkBoxSortByTimestamp->isChecked());
ui->actionProject->setChecked(ui->dockWidgetContents->isVisible());
ui->actionSearch_Results->setChecked(ui->dockWidgetSearchIndex->isVisible());
if ( true == (bool) settings->StartupMinimized )
{
qDebug() << "Start minimzed as defined in the settings";
this->setWindowState(Qt::WindowMinimized);
}
}
MainWindow::~MainWindow()
{
timer.stop(); // stop the receive timeout timer in case it is running
dltIndexer->stop(); // in case a thread is running we want to stop it
/**
* All plugin dockwidgets must be removed from the layout manually and
* then deleted. This has to be done here, because they contain
* UI components owned by the plugins. The plugins will destroy their
* own UI components. If the dockwidget is not manually removed, the
* parent destructor of MainWindow will try to automatically delete
* the dockWidgets subcomponents, which are already destroyed
* when unloading plugins.
**/
for(int i=0;i<project.plugin->topLevelItemCount();i++)
{
PluginItem *item = (PluginItem *) project.plugin->topLevelItem(i);
if(item->dockWidget != NULL)
{
removeDockWidget(item->dockWidget);
delete item->dockWidget;
}
}
if(( settings->appendDateTime == 1) && (outputfile.size() != 0))
{
// get new filename
QFileInfo info(outputfile.fileName());
QString newFilename = info.baseName()+
(startLoggingDateTime.toString("__yyyyMMdd_hhmmss"))+
(QDateTime::currentDateTime().toString("__yyyyMMdd_hhmmss"))+
QString(".dlt");
QFileInfo infoNew(info.absolutePath(),newFilename);
// rename old file
qfile.close();
outputfile.flush();
outputfile.close();
bool result = outputfile.rename(info.absoluteFilePath(), infoNew.absoluteFilePath());
if ( false == result )
{
qDebug() << "ERROR renaming" << info.absoluteFilePath() << "to" << infoNew.absoluteFilePath();
}
else
{
qDebug() << "Renaming " << info.absoluteFilePath() << "to" << infoNew.absoluteFilePath();
}
}
// deleting search history
for (int i= 0; i < MaxSearchHistory; i++)
{
if (NULL != searchHistoryActs[i])
{
delete searchHistoryActs[i];
}
}
QDltSettingsManager::close();
delete ui;
delete tableModel;
delete searchDlg;
delete dltIndexer;
delete m_shortcut_searchnext;
delete m_shortcut_searchprev;
delete crlfFilterWindow;
}
void MainWindow::initState()
{
/* Shortcut for Copy Selection Payload to Clipboard */
copyPayloadShortcut = new QShortcut(QKeySequence("Ctrl+P"), this);
connect(copyPayloadShortcut, &QShortcut::activated, this, &MainWindow::onActionMenuConfigCopyPayloadToClipboardTriggered);
/* Shortcut for Mark/Unmark lines */
markShortcut = new QShortcut(QKeySequence("Ctrl+M"), this);
connect(markShortcut, &QShortcut::activated, this, &MainWindow::mark_unmark_lines);
/* Shortcuts for traversing manually marked messages */
nextMarkedShortcut = new QShortcut(QKeySequence("F4"), this);
connect(nextMarkedShortcut, &QShortcut::activated, this, &MainWindow::goto_next_marked_line);
prevMarkedShortcut = new QShortcut(QKeySequence("F5"), this);
connect(prevMarkedShortcut, &QShortcut::activated, this, &MainWindow::goto_prev_marked_line);
/* Settings */
settingsDlg = new SettingsDialog(&qfile,this);
settingsDlg->assertSettingsVersion();
settingsDlg->readSettings();
/* Update Checker call for timer to check if there is any new update*/
updChecker = new UpdateChecker(this);
updChecker->checkForUpdates(); //runs intervalPassed on start of DLT Viewer
updChecker->startAutoCheck();// keeps the periodic check for every 120 mins
if (QDltSettingsManager::UI_Colour::UI_Dark == QDltSettingsManager::getInstance()->uiColour)
{
qApp->setStyle(QStyleFactory::create("Fusion"));
QPalette darkMode;
QColor foregroundColor = QColor(49,50,53);
QColor backgroundColor = QColor(31,31,31);
QColor disabledColor = QColor(127,127,127);
QColor brightColor = QColor(253,253,255);
QColor brighterColor = QColor(Qt::white);
QColor darkColor = QColor(Qt::black);
QColor highlightColor = QColor(51,144,255);
darkMode.setColor(QPalette::AlternateBase, foregroundColor);
darkMode.setColor(QPalette::Base, backgroundColor);
darkMode.setColor(QPalette::BrightText, brighterColor);
darkMode.setColor(QPalette::Disabled, QPalette::BrightText, disabledColor);
darkMode.setColor(QPalette::Button, foregroundColor);
darkMode.setColor(QPalette::ButtonText, brightColor);
darkMode.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor);
darkMode.setColor(QPalette::Highlight, highlightColor);
darkMode.setColor(QPalette::HighlightedText, darkColor);
darkMode.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor);
darkMode.setColor(QPalette::Link, highlightColor);
darkMode.setColor(QPalette::Text, brightColor);
darkMode.setColor(QPalette::Disabled, QPalette::Text, disabledColor);
darkMode.setColor(QPalette::ToolTipBase, foregroundColor);
darkMode.setColor(QPalette::ToolTipText, brighterColor);
darkMode.setColor(QPalette::Disabled, QPalette::ToolTipText, disabledColor);
darkMode.setColor(QPalette::PlaceholderText, brightColor);
darkMode.setColor(QPalette::Disabled, QPalette::PlaceholderText, disabledColor);
darkMode.setColor(QPalette::Window, foregroundColor);
darkMode.setColor(QPalette::WindowText, brightColor);
darkMode.setColor(QPalette::Disabled, QPalette::WindowText, disabledColor);
darkMode.setColor(QPalette::Light, disabledColor);
darkMode.setColor(QPalette::Midlight, disabledColor);
darkMode.setColor(QPalette::Dark, foregroundColor);
darkMode.setColor(QPalette::Mid, backgroundColor);
darkMode.setColor(QPalette::Shadow, darkColor);
qApp->setPalette(darkMode);
}
recentFiles = settingsDlg->getRecentFiles();
recentProjects = settingsDlg->getRecentProjects();
recentFilters = settingsDlg->getRecentFilters();
/* Initialize recent files */
for (int i = 0; i < MaxRecentFiles; ++i) {
recentFileActs[i] = new QAction(this);
recentFileActs[i]->setVisible(false);
connect(recentFileActs[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
ui->menuRecent_files->addAction(recentFileActs[i]);
}
/* Initialize recent projects */
for (int i = 0; i < MaxRecentProjects; ++i) {
recentProjectActs[i] = new QAction(this);
recentProjectActs[i]->setVisible(false);
connect(recentProjectActs[i], SIGNAL(triggered()), this, SLOT(openRecentProject()));
ui->menuRecent_projects->addAction(recentProjectActs[i]);
}
/* Initialize recent filters */
for (int i = 0; i < MaxRecentFilters; ++i) {
recentFiltersActs[i] = new QAction(this);
recentFiltersActs[i]->setVisible(false);
connect(recentFiltersActs[i], SIGNAL(triggered()), this, SLOT(openRecentFilters()));
ui->menuRecent_Filters->addAction(recentFiltersActs[i]);
}
/* Update recent file and project actions */
updateRecentFileActions();
updateRecentProjectActions();
updateRecentFiltersActions();
/* initialise DLT file handling */
tableModel = new TableModel("Hello Tree");
tableModel->qfile = &qfile;
tableModel->project = &project;
tableModel->pluginManager = &pluginManager;
/* initialise project configuration */
project.ecu = ui->configWidget;
project.filter = ui->filterWidget;
project.plugin = ui->pluginWidget;
connect(ui->pluginWidget, SIGNAL(pluginOrderChanged(QString, int)), this, SLOT(onPluginWidgetPluginPriorityChanged(QString, int)));
//project.settings = settings;
project.settings = QDltSettingsManager::getInstance();
/* Load Plugins before loading default project */
qDebug() << "### Load Plugins";
loadPlugins();
pluginManager.autoscrollStateChanged(settings->autoScroll);
/* initialize injection */
injectionAplicationId.clear();
injectionContextId.clear();
injectionServiceId.clear();
injectionData.clear();
injectionDataBinary = false;
}
void MainWindow::goto_next_marked_line()
{
if(!ui || !ui->tableView || !ui->tableView->model() || !ui->tableView->selectionModel())
return;
if(selectedMarkerRows.isEmpty())
return;
rebuildMarkedRowCache();
if(markedRowsInView.isEmpty())
return;
const QModelIndex current = ui->tableView->currentIndex();
const int currentRow = current.isValid() ? current.row() : -1;
auto it = std::upper_bound(markedRowsInView.begin(), markedRowsInView.end(), currentRow);
const int targetRow = (it == markedRowsInView.end()) ? markedRowsInView.first() : *it;
const QModelIndex targetIndex = ui->tableView->model()->index(targetRow, 0);
if(!targetIndex.isValid())
{
return;
}
ui->tableView->selectionModel()->setCurrentIndex(
targetIndex,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
ui->tableView->scrollTo(targetIndex, QAbstractItemView::PositionAtCenter);
}
void MainWindow::goto_prev_marked_line()
{
if(!ui || !ui->tableView || !ui->tableView->model() || !ui->tableView->selectionModel())
return;
if(selectedMarkerRows.isEmpty())
return;
rebuildMarkedRowCache();
if(markedRowsInView.isEmpty())
return;
const QModelIndex current = ui->tableView->currentIndex();
const int currentRow = current.isValid() ? current.row() : -1;
if(currentRow < 0)
{
const int targetRow = markedRowsInView.last();
const QModelIndex targetIndex = ui->tableView->model()->index(targetRow, 0);
if(!targetIndex.isValid())
return;
ui->tableView->selectionModel()->setCurrentIndex(
targetIndex,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
ui->tableView->scrollTo(targetIndex, QAbstractItemView::PositionAtCenter);
return;
}
auto it = std::lower_bound(markedRowsInView.begin(), markedRowsInView.end(), currentRow);
int targetRow = -1;
if(it == markedRowsInView.begin())
targetRow = markedRowsInView.last();
else
targetRow = *(--it);
const QModelIndex targetIndex = ui->tableView->model()->index(targetRow, 0);
if(!targetIndex.isValid())
{
return;
}
ui->tableView->selectionModel()->setCurrentIndex(
targetIndex,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
ui->tableView->scrollTo(targetIndex, QAbstractItemView::PositionAtCenter);
}
void MainWindow::initView()
{
int maxWidth = 0;
// With QT5.8 we have a bug with the system proxy configuration
// which we want to avoid, so we disable it
QNetworkProxyFactory::setUseSystemConfiguration(false);
/* make focus on elements visible */
project.ecu->setStyleSheet("QTreeWidget:focus { border-color:lightgray; border-style:solid; border-width:1px; }");
ui->tableView->setStyleSheet("QTableView:focus { border-color:lightgray; border-style:solid; border-width:1px; }");
ui->tableView_SearchIndex->setStyleSheet("QTableView:focus { border-color:lightgray; border-style:solid; border-width:1px; }");
if (QDltSettingsManager::UI_Colour::UI_Dark == QDltSettingsManager::getInstance()->uiColour)
{
project.ecu->setStyleSheet("QTreeWidget:focus { border-color:#7f7f7f; border-style:solid; border-width:1px; }");
ui->tableView->setStyleSheet("QTableView:focus { border-color:#7f7f7f; border-style:solid; border-width:1px; }");
ui->tableView_SearchIndex->setStyleSheet("QTableView:focus { border-color:#7f7f7f; border-style:solid; border-width:1px; }");
}
/* update default filter selection */
on_actionDefault_Filter_Reload_triggered();
/* set table size and en */
ui->tableView->setModel(tableModel);
// Keep marked-row traversal cache in sync with model changes.
connect(tableModel, &QAbstractItemModel::modelReset, this, &MainWindow::invalidateMarkedRowCache);
connect(tableModel, &QAbstractItemModel::layoutChanged, this, &MainWindow::invalidateMarkedRowCache);
connect(tableModel, &QAbstractItemModel::rowsInserted, this, &MainWindow::invalidateMarkedRowCache);
connect(tableModel, &QAbstractItemModel::rowsRemoved, this, &MainWindow::invalidateMarkedRowCache);
QHeaderView *header = ui->tableView->horizontalHeader();
header->installEventFilter(tableModel);
/* For future use enable HTML View in Table */
//HtmlDelegate* delegate = new HtmlDelegate();
//ui->tableView->setItemDelegate(delegate);
//ui->tableView->setItemDelegateForColumn(FieldNames::Payload,delegate);
/* preset the witdth of the columns somwhow */
for (int col=0;col <= ui->tableView->model()->columnCount();col++)
{
ui->tableView->setColumnWidth(col,FieldNames::getColumnWidth((FieldNames::Fields)col,settings));
}
// Some decoder-plugins can create very long payloads, which in turn severly impact performance
// So set some limit on what is displayed in the tableview. All details are always available
// using the message viewer-plugin
ui->tableView->horizontalHeader()->setMaximumSectionSize(5000);
// set initial file explorer view
if (!recentFiles.empty()) {
ui->tabExplore->setCurrentFile(recentFiles[0]);
}
connect(ui->tabExplore, &FileExplorerTab::fileActivated, this, [this](const QString& path){
openSupportedFile(path);
});
/* Enable column sorting of config widget */
ui->configWidget->sortByColumn(0, Qt::AscendingOrder); // column/order to sort by
ui->configWidget->setSortingEnabled(true); // should cause sort on add
ui->configWidget->setHeaderHidden(false);
ui->filterWidget->setHeaderHidden(false);
ui->pluginWidget->setHeaderHidden(false);
/* Start pulsing the apply changes button, when filters draged&dropped */
connect(ui->filterWidget, SIGNAL(filterItemDropped()), this, SLOT(filterOrderChanged()));
connect(ui->filterWidget, SIGNAL(filterCountChanged()), this, SLOT(filterCountChanged()));
/* initialise statusbar */
totalBytesRcvd = 0;
totalByteErrorsRcvd = 0;
totalSyncFoundRcvd = 0;
/* filename string */
statusFilename = new QLabel("No log file loaded");
statusFilename->setMinimumWidth(statusFilename->width());
//statusFilename->setMaximumWidth(statusFilename->width());
statusFilename->setMaximumWidth(1240);
// 640 is the initial width of the label
// but for some reason we need this for the very
// first call when setting the tempfile string
// unless this there are is displayed "..."
// more propper solution appreciated ...
statusFilename->setWordWrap(true);
/* version string */
statusFileVersion = new QLabel("Version: <n.a.>");
maxWidth = QFontMetrics(statusFileVersion->font()).averageCharWidth() * 70;
statusFileVersion->setMaximumWidth(maxWidth);
statusFileVersion->setMinimumWidth(1);
statusFileError = new QLabel("FileErr: 0");
statusFileError->setText(QString("FileErr: %L1").arg(0));
statusBytesReceived = new QLabel("Recv: 0");
statusByteErrorsReceived = new QLabel("Recv Errors: 0");
statusSyncFoundReceived = new QLabel("Sync found: 0");
statusProgressBar = new QProgressBar();
statusBar()->addWidget(statusFilename,1);
statusBar()->addWidget(statusFileVersion, 1);
statusBar()->addWidget(statusFileError, 0);
statusBar()->addWidget(statusBytesReceived, 0);
statusBar()->addWidget(statusByteErrorsReceived);
statusBar()->addWidget(statusSyncFoundReceived);
statusBar()->addWidget(statusProgressBar);
/* Create search text box */
searchInput = new SearchForm;
connect(searchInput, &SearchForm::abortSearch, searchDlg, &SearchDialog::abortSearch);
searchDlg->appendLineEdit(searchInput->input());
searchInput->loadComboBoxSearchHistory();
connect(searchInput->input(), SIGNAL(textChanged(QString)),searchDlg,SLOT(textEditedFromToolbar(QString)));
connect(searchInput->input(), SIGNAL(returnPressed()), this, SLOT(on_actionFindNext()));
connect(searchInput->input(), SIGNAL(returnPressed()),searchDlg,SLOT(findNextClicked()));
connect(searchDlg, SIGNAL(searchProgressChanged(bool)), this, SLOT(onSearchProgressChanged(bool)));
connect(searchDlg, &SearchDialog::searchProgressValueChanged, this, [this](int progress){
searchInput->setProgress(progress);
});
connect(settingsDlg, SIGNAL(FilterPathChanged()), this, SLOT(on_actionDefault_Filter_Reload_triggered()));
connect(settingsDlg, SIGNAL(PluginsAutoloadChanged()), this, SLOT(triggerPluginsAutoload()));
QAction *focusSearchTextbox = new QAction(this);
focusSearchTextbox->setShortcut(Qt::Key_L | Qt::CTRL);
connect(focusSearchTextbox, SIGNAL(triggered()), searchInput->input(), SLOT(setFocus()));
addAction(focusSearchTextbox);
/* Initialize toolbars. Most of the construction and connection is done via the
* UI file. See mainwindow.ui, ActionEditor and Signal & Slots editor */
QList<QAction *> mainActions = ui->mainToolBar->actions();
m_searchActions = ui->searchToolbar->actions();
/* Point scroll toggle button to right place */
scrollButton = mainActions.at(ToolbarPosition::AutoScroll);
/* Update the scrollbutton status */
updateScrollButton();
/* Add shortcut to apply config */
QAction *applyConfig = new QAction(this);
applyConfig->setShortcut((Qt::SHIFT | Qt::CTRL) | Qt::Key_C);
connect(applyConfig, SIGNAL(triggered()), this, SLOT(on_applyConfig_clicked()));
addAction(applyConfig);
/* Add shortcut to add filter */
QAction *addFilter = new QAction(this);
addFilter->setShortcut((Qt::SHIFT | Qt::CTRL) | Qt::Key_A);
connect(addFilter, SIGNAL(triggered()), this, SLOT(on_action_menuFilter_Add_triggered()));
addAction(addFilter);
}
void MainWindow::initSignalConnections()
{
/* Initialize Search History */
for (int i= 0; i < MaxSearchHistory; i++)
{
searchHistoryActs[i] = new QAction(this);
searchHistoryActs[i]->setVisible(false);
connect(searchHistoryActs[i], SIGNAL(triggered()), searchDlg, SLOT(loadSearchHistory()));
ui->menuHistory->addAction(searchHistoryActs[i]);
}
/* Connect RegExp settings from and to search dialog */
connect(m_searchActions.at(ToolbarPosition::Regexp), SIGNAL(toggled(bool)), searchDlg->regexpCheckBox, SLOT(setChecked(bool)));
connect(searchDlg->regexpCheckBox, SIGNAL(toggled(bool)), m_searchActions.at(ToolbarPosition::Regexp), SLOT(setChecked(bool)));
/* Connect previous and next buttons to search dialog slots */
connect(m_searchActions.at(ToolbarPosition::FindPrevious), SIGNAL(triggered()), searchDlg, SLOT(findPreviousClicked()));
connect(m_searchActions.at(ToolbarPosition::FindNext), SIGNAL(triggered()), searchDlg, SLOT(findNextClicked()));
connect(m_searchActions.at(ToolbarPosition::FindNext), SIGNAL(triggered()), this, SLOT(on_actionFindNext()));
/* Connect Search dialog find to action History */
connect(searchDlg,SIGNAL(addActionHistory()),this,SLOT(onAddActionToHistory()));
/* Insert search text box to search toolbar, before previous button */
QAction *before = m_searchActions.at(ToolbarPosition::FindPrevious);
ui->searchToolbar->insertWidget(before, searchInput);
/* adding shortcuts - regard: in the search window, the signal is caught by another way, this here only catches the keys when main window is active */
m_shortcut_searchnext = new QShortcut(QKeySequence("F3"), this);
connect(m_shortcut_searchnext, &QShortcut::activated, searchDlg, &SearchDialog::findNextClicked);
m_shortcut_searchprev = new QShortcut(QKeySequence("F2"), this);
connect(m_shortcut_searchprev, &QShortcut::activated, searchDlg, &SearchDialog::findPreviousClicked);
connect(ui->tableView->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(sectionInTableDoubleClicked(int)));
//for search result table
connect(searchDlg, SIGNAL(refreshedSearchIndex()), this, SLOT(searchTableRenewed()));
connect( m_searchresultsTable, SIGNAL( doubleClicked (QModelIndex) ), this, SLOT( searchtable_cellSelected( QModelIndex ) ) );
connect( m_searchresultsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::onSearchresultsTableSelectionChanged );
// connect tableView selection model change to handler in mainwindow
connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::onTableViewSelectionChanged);
// connect file loaded signal with explorerView
connect(this, &MainWindow::dltFileLoaded, this, [this](){
ui->tabExplore->setCurrentFile(recentFiles[0]);
});
connect(ui->tableView, &DltTableView::changeFontSize, this, [this](int direction){
QFont font;
font.fromString(settings->fontName);
int fontSize = font.pointSize() + direction;
font.setPointSize(fontSize);
settings->fontName = font.toString();
ui->tableView->setFont(font);
});
}
void MainWindow::initSearchTable()
{
//init search Dialog
searchDlg = new SearchDialog(this);
searchDlg->file = &qfile;
searchDlg->table = ui->tableView;
searchDlg->pluginManager = &pluginManager;
/* initialise DLT Search handling */
m_searchtableModel = new SearchTableModel("Search Index Mainwindow");
m_searchtableModel->qfile = &qfile;
m_searchtableModel->project = &project;
m_searchtableModel->pluginManager = &pluginManager;
searchDlg->registerSearchTableModel(m_searchtableModel);
m_searchresultsTable = ui->tableView_SearchIndex;
m_searchresultsTable->setModel(m_searchtableModel);
m_searchresultsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
/* With Autoscroll= false the tableview doesn't jump to the right edge,
for example, if the payload column is stretched to full size */
m_searchresultsTable->setAutoScroll(false);
m_searchresultsTable->verticalHeader()->setVisible(false);
m_searchresultsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
/* set table size and en */
for (int col=0;col <= m_searchresultsTable->model()->columnCount();col++)
{
m_searchresultsTable->setColumnWidth(col,FieldNames::getColumnWidth((FieldNames::Fields)col,settings));
}
}
void MainWindow::initFileHandling()
{
/* Initialize dlt-file indexer */
dltIndexer = new DltFileIndexer(&qfile,&pluginManager,&defaultFilter, this);
/* connect signals */
connect(dltIndexer, SIGNAL(progressMax(int)), this, SLOT(reloadLogFileProgressMax(int)));
connect(dltIndexer, SIGNAL(progress(int)), this, SLOT(reloadLogFileProgress(int)));
connect(dltIndexer, SIGNAL(progressText(QString)), this, SLOT(reloadLogFileProgressText(QString)));
connect(dltIndexer, SIGNAL(versionString(QString,QString)), this, SLOT(reloadLogFileVersionString(QString,QString)));
connect(dltIndexer, SIGNAL(finishIndex()), this, SLOT(reloadLogFileFinishIndex()));
connect(dltIndexer, SIGNAL(finishFilter()), this, SLOT(reloadLogFileFinishFilter()));
connect(dltIndexer, SIGNAL(finishDefaultFilter()), this, SLOT(reloadLogFileFinishDefaultFilter()));
connect(dltIndexer, SIGNAL(timezone(int,unsigned char)), this, SLOT(controlMessage_Timezone(int,unsigned char)));
connect(dltIndexer, SIGNAL(unregisterContext(QString,QString,QString)), this, SLOT(controlMessage_UnregisterContext(QString,QString,QString)));
connect(dltIndexer, SIGNAL(finished()), this, SLOT(indexDone()));
connect(dltIndexer, SIGNAL(started()), this, SLOT(indexStart()));
/* Plugins/Filters enabled checkboxes */
pluginsEnabled = QDltSettingsManager::getInstance()->value("startup/pluginsEnabled", true).toBool();
dltIndexer->setPluginsEnabled(pluginsEnabled);
ui->pluginsEnabled->setChecked(pluginsEnabled);
ui->filtersEnabled->setChecked(QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool());
ui->checkBoxSortByTime->setEnabled(ui->filtersEnabled->isChecked());
ui->checkBoxSortByTime->setChecked(QDltSettingsManager::getInstance()->value("startup/sortByTimeEnabled", false).toBool());
ui->checkBoxSortByTimestamp->setEnabled(ui->filtersEnabled->isChecked());
ui->checkBoxSortByTimestamp->setChecked(QDltSettingsManager::getInstance()->value("startup/sortByTimestampEnabled", false).toBool());
ui->checkBoxFilterRange->setEnabled(ui->filtersEnabled->isChecked());
ui->lineEditFilterStart->setEnabled(ui->checkBoxFilterRange->isChecked() && ui->filtersEnabled->isChecked());
ui->lineEditFilterEnd->setEnabled(ui->checkBoxFilterRange->isChecked() && ui->filtersEnabled->isChecked());
/* Process Project */
if(QDltOptManager::getInstance()->isProjectFile())
{
openDlpFile(QDltOptManager::getInstance()->getProjectFile());
}
else
{
/* Load default project file */
this->setWindowTitle(QString("DLT Viewer - unnamed project - Version : %1 %2").arg(PACKAGE_VERSION).arg(PACKAGE_VERSION_STATE));
if(settings->defaultProjectFile)
{
qDebug() << QString("Loading default project %1").arg(settings->defaultProjectFileName);
if(!openDlpFile(settings->defaultProjectFileName))
{
if (QDltOptManager::getInstance()->issilentMode())
{
qDebug() << QString("Cannot load default project %1").arg(settings->defaultProjectFileName);
}
else
{
QMessageBox::critical(0, QString("DLT Viewer"), QString("Cannot load default project \"%1\"").arg(settings->defaultProjectFileName));
}
}
}
}
/* Commands plugin before loading log file */
qDebug() << "### Plugin commands before loading log file";
if(!QDltOptManager::getInstance()->getPrePluginCommands().isEmpty())
{
QStringList commands = QDltOptManager::getInstance()->getPrePluginCommands();
// Enable plugins, if they are not enabled
if(!pluginsEnabled)
{
qDebug() << "Enable plugins, because they were disabled!";
pluginsEnabled = true;
dltIndexer->setPluginsEnabled(pluginsEnabled);
}
for(int num = 0; num< commands.size();num++)
{
qDebug() << "Command:" << commands[num];
QStringList args = commands[num].split("|");
if(args.size() > 1)
{
QString pluginName = args.at(0);
QString commandName = args.at(1);
args.removeAt(0);
args.removeAt(0);
QStringList commandParams = args;
commandLineExecutePlugin(pluginName,commandName,commandParams);
}
}
}
/* load filters by command line */
if(!QDltOptManager::getInstance()->getFilterFiles().isEmpty())
{
qDebug() << "### Load filter";
// enable filters if they are not enabled
if(QDltSettingsManager::getInstance()->value("startup/filtersEnabled", true).toBool()==false)
{
qDebug("Enable filters, as they were disabled and at least one filter is provided by the commandline!");
QDltSettingsManager::getInstance()->setValue("startup/filtersEnabled", true);
}
for ( const auto& filter : QDltOptManager::getInstance()->getFilterFiles() )
{
qDebug() << "Load filter:" << filter;
if(project.LoadFilter(filter,false))
{
// qDebug() << QString("Loading default filter %1").arg(settings->defaultFilterPath);
filterUpdate();
setCurrentFilters(filter);
}
else
{
if (QDltOptManager::getInstance()->issilentMode())
{
qDebug() << "Loading DLT Filter file failed!";
}
else
{
QMessageBox::critical(0, QString("DLT Viewer"),QString("Loading DLT Filter file failed!"));
}
}
}
}
/* Process Logfile */
outputfileIsFromCLI = false;
outputfileIsTemporary = false;
if(!QDltOptManager::getInstance()->getLogFiles().isEmpty())
{
qDebug() << "### Load DLT files";
QStringList logFiles = QDltOptManager::getInstance()->getLogFiles();
logFiles.sort();
openDltFile(logFiles);
/* Command line file is treated as temp file */
outputfileIsTemporary = true;
outputfileIsFromCLI = true;
}
else
{
/* load default log file */
if(settings->defaultLogFile)
{
openDltFile(QStringList(settings->defaultLogFileName));
qDebug() << QString("Open default log file ") << QStringList(settings->defaultLogFileName);
outputfileIsFromCLI = false;
outputfileIsTemporary = false;
}
else
{
/* Create temp file */
QString fn = DltFileUtils::createTempFile(DltFileUtils::getTempPath(QDltOptManager::getInstance()->issilentMode()), QDltOptManager::getInstance()->issilentMode());
outputfile.setFileName(fn);
outputfileIsTemporary = true;
outputfileIsFromCLI = false;
if(true == outputfile.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
openFileNames = QStringList(fn);
isDltFileReadOnly = false;
if(QDltOptManager::getInstance()->isCommandlineMode())
// if dlt viewer started as converter or with plugin option load file non multithreaded
reloadLogFile(false,false);
else
// normally load log file mutithreaded
reloadLogFile();
outputfile.close(); // open later again when writing
}
else
{
if (QDltOptManager::getInstance()->issilentMode())
{
qDebug() << QString("Cannot load temporary log file %1 %2").arg(outputfile.fileName()).arg(outputfile.errorString());
}
else
{
QMessageBox::critical(0, QString("DLT Viewer"), QString("Cannot load temporary log file \"%1\"\n%2").arg(outputfile.fileName()).arg(outputfile.errorString()));
}
}
}
}
// Import PCAP files from commandline
if(!QDltOptManager::getInstance()->getPcapFiles().isEmpty())
{
qDebug() << "### Import PCAP files";
for ( const auto& filename : QDltOptManager::getInstance()->getPcapFiles() )
{
QDltImporter importer(&outputfile);
importer.setPcapPorts(settings->importerPcapPorts);
importer.dltIpcFromPCAP(filename);
}
if(QDltOptManager::getInstance()->isCommandlineMode())
// if dlt viewer started as converter or with plugin option load file non multithreaded
reloadLogFile(false,false);
else
// normally load log file mutithreaded
reloadLogFile();
}
// Import mf4 files from commandline
if(!QDltOptManager::getInstance()->getMf4Files().isEmpty())
{
qDebug() << "### Import MF4 files";
for ( const auto& filename : QDltOptManager::getInstance()->getMf4Files() )
{
QDltImporter importer(&outputfile);
importer.dltIpcFromMF4(filename);
}
if(QDltOptManager::getInstance()->isCommandlineMode())
// if dlt viewer started as converter or with plugin option load file non multithreaded
reloadLogFile(false,false);
else
// normally load log file mutithreaded
reloadLogFile();
}
}
void MainWindow::commandLineConvertToDLT()
{
qDebug() << "### Convert to DLT";
/* start exporter */
QDltExporter exporter(&qfile,QDltOptManager::getInstance()->getConvertDestFile(),&pluginManager,QDltExporter::FormatDlt,QDltExporter::SelectionFiltered,0,project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter(),QDltOptManager::getInstance()->getSignature());
qDebug() << "Commandline DLT convert to " << QDltOptManager::getInstance()->getConvertDestFile();
exporter.exportMessages();
qDebug() << "DLT export to DLT file format done";
}
void MainWindow::commandLineConvertToASCII()
{
qDebug() << "### Convert to ASCII";
/* start exporter */
QDltExporter exporter(&qfile,QDltOptManager::getInstance()->getConvertDestFile(),&pluginManager,QDltExporter::FormatAscii,QDltExporter::SelectionFiltered,0,project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter(),QDltOptManager::getInstance()->getSignature());
qDebug() << "Commandline ASCII convert to " << QDltOptManager::getInstance()->getConvertDestFile();
exporter.exportMessages();
qDebug() << "DLT export ASCII done";
}
void MainWindow::commandLineConvertToCSV()
{
qDebug() << "### Convert to CSV";
/* start exporter */
QDltExporter exporter(&qfile,QDltOptManager::getInstance()->getConvertDestFile(),&pluginManager,QDltExporter::FormatCsv,QDltExporter::SelectionFiltered,0,project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter(),QDltOptManager::getInstance()->getSignature());
qDebug() << "Commandline ASCII convert to " << QDltOptManager::getInstance()->getConvertDestFile();
exporter.exportMessages();
qDebug() << "DLT export CSV done";
}
void MainWindow::commandLineConvertToUTF8()
{
/* start exporter */
qDebug() << "### Convert to UTF8";
QDltExporter exporter(&qfile,QDltOptManager::getInstance()->getConvertDestFile(),&pluginManager,QDltExporter::FormatUTF8,QDltExporter::SelectionFiltered,0,project.settings->automaticTimeSettings,project.settings->utcOffset,project.settings->dst,QDltOptManager::getInstance()->getDelimiter(),QDltOptManager::getInstance()->getSignature());
qDebug() << "Commandline UTF8 convert to " << QDltOptManager::getInstance()->getConvertDestFile();
exporter.exportMessages();
qDebug() << "DLT export UTF8 done";
}
void MainWindow::commandLineConvertToDLTDecoded()
{