-
Notifications
You must be signed in to change notification settings - Fork 66
/
settings.h
154 lines (126 loc) · 4.19 KB
/
settings.h
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
/*
* Copyright (c) 2015 Meinhard Ritscher <[email protected]>
*
* 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 3 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.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QObject>
#include <QtSerialPort>
class Settings : public QObject
{
Q_OBJECT
public:
enum Options {
Device,
BaudRate,
DataBits,
StopBits,
Parity,
FlowControl,
OpenMode,
ShowCtrlCharacters,
ShowTimestamp,
CommandHistory,
WindowGeometry,
WindowState,
LogFileLocation,
LineTermination,
CharacterDelay,
SendStartDir,
ProtocolOption,
MacroFile,
UdpLocalPort,
UdpRemoteHost,
UdpRemotePort,
TcpLocalPort,
CurrentSession
};
struct Session {
QString device;
quint32 baudRate;
QSerialPort::DataBits dataBits;
QSerialPort::Parity parity;
QSerialPort::StopBits stopBits;
QSerialPort::FlowControl flowControl;
QIODevice::OpenModeFlag openMode;
bool showCtrlCharacters;
bool showTimestamp;
QStringList command_history;
QString macroFile;
quint16 udpLocalPort;
QString udpRemoteHost;
quint16 udpRemotePort;
quint16 tcpLocalPort;
};
enum LineTerminator { LF = 0, CR, CRLF, NONE, HEX };
Q_ENUMS(LineTerminator)
enum Protocol { PLAIN, SCRIPT, XMODEM, YMODEM, ZMODEM, ONEKXMODEM, PROTOCOL_MAX };
Q_ENUMS(Protocol)
explicit Settings(QObject *parent = 0);
void readSettings(const QString &session);
const Settings::Session getCurrentSession();
QString getCurrentSessionName() const { return m_current_session; }
void settingChanged(Settings::Options option, QVariant setting);
QByteArray getWindowGeometry() const;
QByteArray getWindowState() const;
QString getLogFileLocation() const;
Settings::LineTerminator getLineTerminator() const;
quint8 getCharacterDelay() const { return m_character_delay; }
Settings::Protocol getProtocol() const { return m_protocol; }
QString getSendStartDir() const { return m_sendingStartDir; }
QList<QString> getSessionNames() const;
void removeSession(const QString &session);
void cloneSession(const QString &source, const QString &destination);
void renameSession(const QString &source, const QString &destination);
signals:
void sessionChanged(const Settings::Session &);
private:
void readSessionSettings(QSettings &settings);
void saveGenericSettings();
void saveSessionSettings();
bool readUIntSetting(QSettings &settings, QString const &name, quint32 *i);
QByteArray m_windowGeometry;
QByteArray m_windowState;
QString m_logFileLocation;
/**
* The location QFileDialog displayed for choosing a file
* to send starts off
* @brief m_sendingStartDir
*/
QString m_sendingStartDir;
Settings::LineTerminator m_lineterm;
/**
* This holds the last protocol selected for
* sending a file across the device
* @brief m_protocol
*/
Settings::Protocol m_protocol;
/**
* Delay between each character sent
* @brief m_character_delay;
*/
quint8 m_character_delay;
QHash<QString, Session> m_sessions;
QString m_current_session;
static const QString DEFAULT_SESSION_NAME;
};
Q_DECLARE_METATYPE(Settings::Session)
Q_DECLARE_METATYPE(Settings::LineTerminator)
Q_DECLARE_METATYPE(Settings::Protocol)
#endif // SETTINGS_H