File: FSK441Preferences.cpp

package info (click to toggle)
wstools 0.4.8d-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,440 kB
  • ctags: 1,991
  • sloc: cpp: 13,880; makefile: 469
file content (152 lines) | stat: -rw-r--r-- 4,655 bytes parent folder | download | duplicates (2)
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
/*
 *   Copyright (C) 2002-2004 by Jonathan Naylor G4KLX
 *
 *   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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "FSK441Preferences.h"
#include "FSK441App.h"
#include "FSK441Defs.h"

const int BORDER_SIZE = 5;

BEGIN_EVENT_TABLE(CFSK441Preferences, wxDialog)
	EVT_BUTTON(wxID_OK,     CFSK441Preferences::onOK)
	EVT_BUTTON(wxID_CANCEL, CFSK441Preferences::onCancel)
END_EVENT_TABLE()

CFSK441Preferences::CFSK441Preferences(wxWindow* parent, int id) :
wxDialog(parent, id, wxString(wxT("FSK441 Preferences"))),
m_personal(NULL),
m_message(NULL),
m_sound(NULL),
m_ptt(NULL),
m_protocol(NULL)
{
	wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);

	wxNotebook* noteBook = new wxNotebook(this, -1);
	wxNotebookSizer* sizer = new wxNotebookSizer(noteBook);

	wxString callsign, locator;
	::wxGetApp().getPersonal(callsign, locator);
	m_personal = new CPersonalPreferences(noteBook, -1, callsign, locator);
	noteBook->AddPage(m_personal, wxT("Personal"), true);

	wxString* messages = new wxString[FSK441_MAX_MESSAGES];
	for (int i = 0; i < FSK441_MAX_MESSAGES; i++)
		messages[i] = ::wxGetApp().getOriginalMessage(i);
	m_message = new CMessagePreferences(noteBook, -1, messages, FSK441_MAX_MESSAGES, FSK441_MAX_MESSAGE_LENGTH);
	noteBook->AddPage(m_message, wxT("Messages"), false);
	delete[] messages;

	wxString soundFileName;
	::wxGetApp().getSound(soundFileName);
	m_sound = new CSoundPreferences(noteBook, -1, soundFileName);
	noteBook->AddPage(m_sound, wxT("Sound"), false);

	wxString pttType, pttDevice;
	::wxGetApp().getPTT(pttType, pttDevice);
	m_ptt = new CPTTPreferences(noteBook, -1, pttType, pttDevice);
	noteBook->AddPage(m_ptt, wxT("PTT"), false);

	int minLength, minStrength, maxOffset;
	::wxGetApp().getProtoSettings(minLength, minStrength, maxOffset);
	m_protocol = new CFSK441ProtocolPreferences(noteBook, -1, minLength, minStrength, maxOffset);
	noteBook->AddPage(m_protocol, wxT("FSK441"), false);

	mainSizer->Add(sizer, 1, wxALL | wxGROW, BORDER_SIZE);

	mainSizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	SetAutoLayout(true);
	Layout();

	mainSizer->Fit(this);
	mainSizer->SetSizeHints(this);

	SetSizer(mainSizer);
}

CFSK441Preferences::~CFSK441Preferences()
{
}

void CFSK441Preferences::onOK(const wxCommandEvent& event)
{
	wxASSERT(m_personal != NULL);
	wxASSERT(m_message != NULL);
	wxASSERT(m_sound != NULL);
	wxASSERT(m_ptt != NULL);
	wxASSERT(m_protocol != NULL);

	if (!m_personal->isCallsignValid()) {
		wxMessageDialog dialog(this, wxT("The Callsign is not valid"), wxT("FSK441 Error"), wxICON_ERROR);
		dialog.ShowModal();
		return;
	}

	if (!m_personal->isLocatorValid()) {
		wxMessageDialog dialog(this, wxT("The Locator is not valid"), wxT("FSK441 Error"), wxICON_ERROR);
		dialog.ShowModal();
		return;
	}

	for (int i = 0; i < FSK441_MAX_MESSAGES; i++) {
		if (!m_message->isValid(i)) {
			wxMessageDialog dialog(this, wxT("A message is not valid"), wxT("FSK441 Error"), wxICON_ERROR);
			dialog.ShowModal();
			return;
		}
	}

	wxString callsign = m_personal->getCallsign();
	wxString locator  = m_personal->getLocator();
	::wxGetApp().setPersonal(callsign, locator);

	wxString pttType   = m_ptt->getType();
	wxString pttDevice = m_ptt->getDevice();
	::wxGetApp().setPTT(pttType, pttDevice);

	wxString soundDevice = m_sound->getDevice();
	::wxGetApp().setSound(soundDevice);

	for (int i = 0; i < FSK441_MAX_MESSAGES; i++) {
		wxString message = m_message->getMessage(i);
		::wxGetApp().setMessage(i, message);
	}

	int minLength   = m_protocol->getMinLength();
	int minStrength = m_protocol->getMinStrength();
	int maxOffset   = m_protocol->getMaxOffset();
	::wxGetApp().setProtoSettings(minLength, minStrength, maxOffset);

	if (IsModal()) {
		EndModal(wxID_OK);
	} else {
		SetReturnCode(wxID_OK);
		Show(false);
	}
}

void CFSK441Preferences::onCancel(const wxCommandEvent& event)
{
	if (IsModal()) {
		EndModal(wxID_CANCEL);
	} else {
		SetReturnCode(wxID_CANCEL);
		Show(false);
	}
}