VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use