-
Notifications
You must be signed in to change notification settings - Fork 5
/
mainwindow.cpp
124 lines (107 loc) · 3.77 KB
/
mainwindow.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
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*-
*
* XASTIR, Amateur Station Tracking and Information Reporting
* Copyright (C) 1999,2000 Frank Giannandrea
* Copyright (C) 2000-2018 The Xastir Group
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Look at the README for more information on the program.
*/
#include "ui_mainwindow.h"
#include "interfacecontroldialog.h"
#include "xastir.h"
#include "symbols.h"
#include "colors.h"
#include <iostream>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
interfaceControlDialog = NULL;
stationConfigurationDialog = NULL;
connect(&interfaceManager, SIGNAL(interfaceAdded(PacketInterface*)), this, SLOT(newInterface(PacketInterface*)));
// connect(&netInterface,SIGNAL(interfaceChangedState(PacketInterface::Device_Status)), this, SLOT(statusChanged(PacketInterface::Device_Status)));
// connect(&netInterface,SIGNAL(packetReceived(PacketInterface *, QString)), this, SLOT(newData(PacketInterface *,QString)));
total_lines = 0;
interfaceManager.restoreInterfaces();
QSettings settings;
settings.beginGroup("StationSettings");
stationSettings.restoreFromSettings(settings);
settings.endGroup();
initializeColors();
load_pixmap_symbol_file( (char *)":/xastir/symbols.dat", 0);
}
MainWindow::~MainWindow()
{
delete ui;
interfaceManager.saveInterfaces();
QSettings settings;
settings.beginGroup("StationSettings");
settings.remove(""); // Delete previous settings
stationSettings.saveSettings(settings);
settings.endGroup();
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::newInterface(PacketInterface *iface)
{
connect(iface, SIGNAL(packetReceived(PacketInterface*,QString)), this, SLOT(newData(PacketInterface*,QString)));
}
void MainWindow::newData (PacketInterface *device, QString data)
{
int max_lines = 15;
QString tmp;
// Best here would be to look for CR or LF in "data", remove, then add "\n".
// We're not doing that yet.
//
// packetDisplay.append(device->deviceName() + "-> " + data + "\n");
packetDisplay.append(device->deviceName() + "-> " + data);
if (total_lines >= max_lines) {
int ii = packetDisplay.indexOf("\n");
// Chop first line
tmp = packetDisplay.right(packetDisplay.size() - (ii + 1));
packetDisplay = tmp;
}
else {
total_lines++;
}
ui->incomingPackets->setText(packetDisplay);
}
void MainWindow::interfaceControlAction()
{
if( interfaceControlDialog == NULL) {
interfaceControlDialog = new InterfaceControlDialog(interfaceManager, this);
}
interfaceControlDialog->show();
interfaceControlDialog->raise();
}
void MainWindow::stationSettingsAction()
{
stationConfigurationDialog = new StationConfigurationDialog(&stationSettings, this);
stationConfigurationDialog->show();
stationConfigurationDialog->raise();
}