VirtualBox

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

Last change on this file since 100347 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette