VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.h@ 82781

Last change on this file since 82781 was 76581, checked in by vboxsync, 5 years ago

Fe/QT: scm header guard alignment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: UIPortForwardingTable.h 76581 2019-01-01 06:24:57Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIPortForwardingTable class declaration.
4 */
5
6/*
7 * Copyright (C) 2010-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef FEQT_INCLUDED_SRC_widgets_UIPortForwardingTable_h
19#define FEQT_INCLUDED_SRC_widgets_UIPortForwardingTable_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/* Qt includes: */
25#include <QString>
26#include <QWidget>
27
28/* GUI includes: */
29#include "QIWithRetranslateUI.h"
30#include "UILibraryDefs.h"
31
32/* COM includes: */
33#include "COMEnums.h"
34
35/* Forward declarations: */
36class QAction;
37class QHBoxLayout;
38class QIDialogButtonBox;
39class QITableView;
40class UIPortForwardingModel;
41class UIToolBar;
42
43
44/** QString subclass used to distinguish name data from simple QString. */
45class NameData : public QString
46{
47public:
48
49 /** Constructs null name data. */
50 NameData() : QString() {}
51 /** Constructs name data passing @a strName to the base-class. */
52 NameData(const QString &strName) : QString(strName) {}
53};
54Q_DECLARE_METATYPE(NameData);
55
56
57/** QString subclass used to distinguish IP data from simple QString. */
58class IpData : public QString
59{
60public:
61
62 /** Constructs null IP data. */
63 IpData() : QString() {}
64 /** Constructs name data passing @a strIp to the base-class. */
65 IpData(const QString &strIp) : QString(strIp) {}
66};
67Q_DECLARE_METATYPE(IpData);
68
69
70/** Wrapper for ushort used to distinguish port data from simple ushort. */
71class PortData
72{
73public:
74
75 /** Constructs null port data. */
76 PortData() : m_uValue(0) {}
77 /** Constructs port data based on @a uValue. */
78 PortData(ushort uValue) : m_uValue(uValue) {}
79 /** Constructs port data based on @a other port data value. */
80 PortData(const PortData &other) : m_uValue(other.value()) {}
81
82 /** Returns whether this port data is equal to @a another. */
83 bool operator==(const PortData &another) const { return m_uValue == another.m_uValue; }
84
85 /** Returns serialized port data value. */
86 ushort value() const { return m_uValue; }
87
88private:
89
90 /** Holds the port data value. */
91 ushort m_uValue;
92};
93Q_DECLARE_METATYPE(PortData);
94
95
96/** Port Forwarding Rule structure. */
97struct UIDataPortForwardingRule
98{
99 /** Constructs data. */
100 UIDataPortForwardingRule()
101 : name(QString())
102 , protocol(KNATProtocol_UDP)
103 , hostIp(IpData())
104 , hostPort(PortData())
105 , guestIp(IpData())
106 , guestPort(PortData())
107 {}
108
109 /** Constructs data on the basis of passed arguments.
110 * @param strName Brings the rule name.
111 * @param enmProtocol Brings the rule protocol.
112 * @param strHostIP Brings the rule host IP.
113 * @param uHostPort Brings the rule host port.
114 * @param strGuestIP Brings the rule guest IP.
115 * @param uGuestPort Brings the rule guest port. */
116 UIDataPortForwardingRule(const NameData &strName,
117 KNATProtocol enmProtocol,
118 const IpData &strHostIP,
119 PortData uHostPort,
120 const IpData &strGuestIP,
121 PortData uGuestPort)
122 : name(strName)
123 , protocol(enmProtocol)
124 , hostIp(strHostIP)
125 , hostPort(uHostPort)
126 , guestIp(strGuestIP)
127 , guestPort(uGuestPort)
128 {}
129
130 /** Returns whether the @a other passed data is equal to this one. */
131 bool equal(const UIDataPortForwardingRule &other) const
132 {
133 return true
134 && (name == other.name)
135 && (protocol == other.protocol)
136 && (hostIp == other.hostIp)
137 && (hostPort == other.hostPort)
138 && (guestIp == other.guestIp)
139 && (guestPort == other.guestPort)
140 ;
141 }
142
143 /** Returns whether the @a other passed data is equal to this one. */
144 bool operator==(const UIDataPortForwardingRule &other) const { return equal(other); }
145 /** Returns whether the @a other passed data is different from this one. */
146 bool operator!=(const UIDataPortForwardingRule &other) const { return !equal(other); }
147
148 /** Holds the rule name. */
149 NameData name;
150 /** Holds the rule protocol. */
151 KNATProtocol protocol;
152 /** Holds the rule host IP. */
153 IpData hostIp;
154 /** Holds the rule host port. */
155 PortData hostPort;
156 /** Holds the rule guest IP. */
157 IpData guestIp;
158 /** Holds the rule guest port. */
159 PortData guestPort;
160};
161
162/** Port Forwarding Data list. */
163typedef QList<UIDataPortForwardingRule> UIPortForwardingDataList;
164
165
166/** Unique part of port forwarding data. */
167struct UIPortForwardingDataUnique
168{
169 /** Constructs unique port forwarding data based on
170 * @a enmProtocol, @a uHostPort and @a uHostPort. */
171 UIPortForwardingDataUnique(KNATProtocol enmProtocol,
172 PortData uHostPort,
173 const IpData &strHostIp)
174 : protocol(enmProtocol)
175 , hostPort(uHostPort)
176 , hostIp(strHostIp)
177 {}
178
179 /** Returns whether this port data is equal to @a another. */
180 bool operator==(const UIPortForwardingDataUnique &another)
181 {
182 return protocol == another.protocol
183 && hostPort == another.hostPort
184 && ( hostIp.isEmpty() || another.hostIp.isEmpty()
185 || hostIp == "0.0.0.0" || another.hostIp == "0.0.0.0"
186 || hostIp == another.hostIp);
187 }
188
189 /** Holds the port forwarding data protocol type. */
190 KNATProtocol protocol;
191 /** Holds the port forwarding data host port. */
192 PortData hostPort;
193 /** Holds the port forwarding data host IP. */
194 IpData hostIp;
195};
196
197
198/** QWidget subclass representig Port Forwarding table. */
199class SHARED_LIBRARY_STUFF UIPortForwardingTable : public QIWithRetranslateUI<QWidget>
200{
201 Q_OBJECT;
202
203public:
204
205 /** Constructs Port Forwarding table.
206 * @param rules Brings the current list of Port Forwarding rules.
207 * @param fIPv6 Brings whether this table contains IPv6 rules, not IPv4.
208 * @param fAllowEmptyGuestIPs Brings whether this table allows empty guest IPs. */
209 UIPortForwardingTable(const UIPortForwardingDataList &rules, bool fIPv6, bool fAllowEmptyGuestIPs);
210
211 /** Returns the list of port forwarding rules. */
212 const UIPortForwardingDataList rules() const;
213
214 /** Validates the table. */
215 bool validate() const;
216
217 /** Returns whether the table data was changed. */
218 bool isChanged() const { return m_fTableDataChanged; }
219
220 /** Makes sure current editor data committed. */
221 void makeSureEditorDataCommitted();
222
223protected:
224
225 /** Preprocesses any Qt @a pEvent for passed @a pObject. */
226 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
227
228 /** Handles translation event. */
229 virtual void retranslateUi() /* override */;
230
231private slots:
232
233 /** Adds the rule. */
234 void sltAddRule();
235 /** Copies the rule. */
236 void sltCopyRule();
237 /** Removes the rule. */
238 void sltRemoveRule();
239
240 /** Marks table data as changed. */
241 void sltTableDataChanged() { m_fTableDataChanged = true; }
242
243 /** Handles current item change. */
244 void sltCurrentChanged();
245 /** Handles request to show context-menu in certain @a position. */
246 void sltShowTableContexMenu(const QPoint &position);
247 /** Adjusts table column sizes. */
248 void sltAdjustTable();
249
250private:
251
252 /** Prepares all. */
253 void prepare();
254 /** Prepares layout. */
255 void prepareLayout();
256 /** Prepares table-view. */
257 void prepareTableView();
258 /** Prepares table-model. */
259 void prepareTableModel();
260 /** Prepares table-delegates. */
261 void prepareTableDelegates();
262 /** Prepares toolbar. */
263 void prepareToolbar();
264
265 /** Holds the _initial_ list of Port Forwarding rules. */
266 const UIPortForwardingDataList &m_rules;
267
268 /** Holds whether this table contains IPv6 rules, not IPv4. */
269 bool m_fIPv6 : 1;
270 /** Holds whether this table allows empty guest IPs. */
271 bool m_fAllowEmptyGuestIPs : 1;
272 /** Holds whether this table data was changed. */
273 bool m_fTableDataChanged : 1;
274
275 /** Holds the layout instance. */
276 QHBoxLayout *m_pLayout;
277 /** Holds the table-view instance. */
278 QITableView *m_pTableView;
279 /** Holds the tool-bar instance. */
280 UIToolBar *m_pToolBar;
281
282 /** Holds the table-model instance. */
283 UIPortForwardingModel *m_pTableModel;
284
285 /** Holds the Add action instance. */
286 QAction *m_pActionAdd;
287 /** Holds the Copy action instance. */
288 QAction *m_pActionCopy;
289 /** Holds the Remove action instance. */
290 QAction *m_pActionRemove;
291};
292
293
294#endif /* !FEQT_INCLUDED_SRC_widgets_UIPortForwardingTable_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use