summaryrefslogtreecommitdiff
path: root/src/VBox/Frontends/VirtualBox/src/settings/editors/UIUSBFiltersEditor.h
blob: fe9f8f032ed27b73cb31502004d181151ec6af09 (plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* $Id$ */
/** @file
 * VBox Qt GUI - UIUSBFiltersEditor class declaration.
 */

/*
 * Copyright (C) 2006-2022 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

#ifndef FEQT_INCLUDED_SRC_settings_editors_UIUSBFiltersEditor_h
#define FEQT_INCLUDED_SRC_settings_editors_UIUSBFiltersEditor_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

/* GUI includes: */
#include "QIWithRetranslateUI.h"
#include "UIExtraDataDefs.h"

/* Forward declartions: */
class QHBoxLayout;
class QTreeWidgetItem;
class QILabelSeparator;
class QIToolBar;
class QITreeWidget;
class UIUSBMenu;

/** USB Filter data. */
struct UIDataUSBFilter
{
    /** Constructs data. */
    UIDataUSBFilter()
        : m_fActive(true)
        , m_enmRemoteMode(UIRemoteMode_Any)
    {}

    /** Returns whether the @a other passed data is equal to this one. */
    bool equal(const UIDataUSBFilter &other) const
    {
        return true
               && m_fActive == other.m_fActive
               && m_strName == other.m_strName
               && m_strVendorId == other.m_strVendorId
               && m_strProductId == other.m_strProductId
               && m_strRevision == other.m_strRevision
               && m_strManufacturer == other.m_strManufacturer
               && m_strProduct == other.m_strProduct
               && m_strSerialNumber == other.m_strSerialNumber
               && m_strPort == other.m_strPort
               && m_enmRemoteMode == other.m_enmRemoteMode
               ;
    }

    /** Returns whether the @a other passed data is equal to this one. */
    bool operator==(const UIDataUSBFilter &other) const { return equal(other); }
    /** Returns whether the @a other passed data is different from this one. */
    bool operator!=(const UIDataUSBFilter &other) const { return !equal(other); }

    /** Holds whether USB filter is active. */
    bool          m_fActive;
    /** Holds the USB filter name. */
    QString       m_strName;
    /** Holds the USB filter vendor ID. */
    QString       m_strVendorId;
    /** Holds the USB filter product ID. */
    QString       m_strProductId;
    /** Holds the USB filter revision. */
    QString       m_strRevision;
    /** Holds the USB filter manufacturer. */
    QString       m_strManufacturer;
    /** Holds the USB filter product. */
    QString       m_strProduct;
    /** Holds the USB filter serial number. */
    QString       m_strSerialNumber;
    /** Holds the USB filter port. */
    QString       m_strPort;
    /** Holds the USB filter remote. */
    UIRemoteMode  m_enmRemoteMode;
};

/** QWidget subclass used as a USB filters editor. */
class SHARED_LIBRARY_STUFF UIUSBFiltersEditor : public QIWithRetranslateUI<QWidget>
{
    Q_OBJECT;

signals:

    /** Notifies listeners about value change. */
    void sigValueChanged();

public:

    /** Constructs editor passing @a pParent to the base-class. */
    UIUSBFiltersEditor(QWidget *pParent = 0);

    /** Defines editor @a strValue. */
    void setValue(const QList<UIDataUSBFilter> &guiValue);
    /** Returns editor value. */
    QList<UIDataUSBFilter> value() const;

protected:

    /** Handles translation event. */
    virtual void retranslateUi() RT_OVERRIDE;

private slots:

    /** Handles @a pCurrentItem change. */
    void sltHandleCurrentItemChange(QTreeWidgetItem *pCurrentItem);
    /** Handles @a pItem double-click. */
    void sltHandleDoubleClick(QTreeWidgetItem *pItem);
    /** Handles context menu request for @a position. */
    void sltHandleContextMenuRequest(const QPoint &position);

    /** Handles command to create USB filter. */
    void sltCreateFilter();
    /** Handles command to add USB filter. */
    void sltAddFilter();
    /** Handles command to confirm add of existing USB filter defined by @a pAction. */
    void sltAddFilterConfirmed(QAction *pAction);
    /** Handles command to edit USB filter. */
    void sltEditFilter();
    /** Handles command to remove USB filter. */
    void sltRemoveFilter();
    /** Handles command to move chosen USB filter up. */
    void sltMoveFilterUp();
    /** Handles command to move chosen USB filter down. */
    void sltMoveFilterDown();

    /** Handles USB filter tree activity state change for @a pChangedItem. */
    void sltHandleActivityStateChange(QTreeWidgetItem *pChangedItem);

private:

    /** Prepares all. */
    void prepare();
    /** Prepares widgets. */
    void prepareWidgets();
    /** Prepare tree-widget. */
    void prepareTreeWidget();
    /** Prepare tool-bar. */
    void prepareToolbar();
    /** Prepares connections. */
    void prepareConnections();

    /** Creates USB filter item based on passed @a data. */
    void addUSBFilterItem(const UIDataUSBFilter &data, bool fChoose);
    /** Reloads tree. */
    void reloadTree();

    /** Holds the value to be set. */
    QList<UIDataUSBFilter>  m_guiValue;

    /** @name Internal
     * @{ */
        /** Holds the "New Filter %1" translation tag. */
        QString  m_strTrUSBFilterName;
    /** @} */

    /** @name Widgets
     * @{ */
        /** Holds the widget separator instance. */
        QILabelSeparator *m_pLabelSeparator;
        /** Holds the tree layout instance. */
        QHBoxLayout      *m_pLayoutTree;
        /** Holds the tree-widget instance. */
        QITreeWidget     *m_pTreeWidget;
        /** Holds the toolbar instance. */
        QIToolBar        *m_pToolbar;
        /** Holds the 'new USB filter' action instance. */
        QAction          *m_pActionNew;
        /** Holds the 'add USB filter' action instance. */
        QAction          *m_pActionAdd;
        /** Holds the 'edit USB filter' action instance. */
        QAction          *m_pActionEdit;
        /** Holds the 'remove USB filter' action instance. */
        QAction          *m_pActionRemove;
        /** Holds the Move Up action instance. */
        QAction          *m_pActionMoveUp;
        /** Holds the Move Down action instance. */
        QAction          *m_pActionMoveDown;
        /** Holds the USB devices menu instance. */
        UIUSBMenu        *m_pMenuUSBDevices;
    /** @} */
};

#endif /* !FEQT_INCLUDED_SRC_settings_editors_UIUSBFiltersEditor_h */