1 | /* $Id: UIChooserNodeGroup.cpp 77638 2019-03-10 19:21:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIChooserNodeGroup class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-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 | /* GUI includes: */
|
---|
19 | #include "UIChooserNodeGroup.h"
|
---|
20 | #include "UIChooserNodeGlobal.h"
|
---|
21 | #include "UIChooserNodeMachine.h"
|
---|
22 |
|
---|
23 |
|
---|
24 | UIChooserNodeGroup::UIChooserNodeGroup(UIChooserNode *pParent,
|
---|
25 | bool fFavorite,
|
---|
26 | int iPosition,
|
---|
27 | const QString &strName,
|
---|
28 | bool fOpened)
|
---|
29 | : UIChooserNode(pParent, fFavorite)
|
---|
30 | , m_strName(strName)
|
---|
31 | , m_fOpened(fOpened)
|
---|
32 | {
|
---|
33 | if (parentNode())
|
---|
34 | parentNode()->addNode(this, iPosition);
|
---|
35 | retranslateUi();
|
---|
36 | }
|
---|
37 |
|
---|
38 | UIChooserNodeGroup::UIChooserNodeGroup(UIChooserNode *pParent,
|
---|
39 | UIChooserNodeGroup *pCopyFrom,
|
---|
40 | int iPosition)
|
---|
41 | : UIChooserNode(pParent, pCopyFrom->isFavorite())
|
---|
42 | , m_strName(pCopyFrom->name())
|
---|
43 | , m_fOpened(pCopyFrom->isOpened())
|
---|
44 | {
|
---|
45 | if (parentNode())
|
---|
46 | parentNode()->addNode(this, iPosition);
|
---|
47 | copyContents(pCopyFrom);
|
---|
48 | retranslateUi();
|
---|
49 | }
|
---|
50 |
|
---|
51 | UIChooserNodeGroup::~UIChooserNodeGroup()
|
---|
52 | {
|
---|
53 | /* Cleanup groups first, that
|
---|
54 | * gives us proper recursion: */
|
---|
55 | while (!m_nodesGroup.isEmpty())
|
---|
56 | delete m_nodesGroup.last();
|
---|
57 | while (!m_nodesGlobal.isEmpty())
|
---|
58 | delete m_nodesGlobal.last();
|
---|
59 | while (!m_nodesMachine.isEmpty())
|
---|
60 | delete m_nodesMachine.last();
|
---|
61 | delete item();
|
---|
62 | if (parentNode())
|
---|
63 | parentNode()->removeNode(this);
|
---|
64 | }
|
---|
65 |
|
---|
66 | QString UIChooserNodeGroup::name() const
|
---|
67 | {
|
---|
68 | return m_strName;
|
---|
69 | }
|
---|
70 |
|
---|
71 | QString UIChooserNodeGroup::fullName() const
|
---|
72 | {
|
---|
73 | /* Return "/" for root item: */
|
---|
74 | if (isRoot())
|
---|
75 | return "/";
|
---|
76 | /* Get full parent name, append with '/' if not yet appended: */
|
---|
77 | QString strFullParentName = parentNode()->fullName();
|
---|
78 | if (!strFullParentName.endsWith('/'))
|
---|
79 | strFullParentName.append('/');
|
---|
80 | /* Return full item name based on parent prefix: */
|
---|
81 | return strFullParentName + name();
|
---|
82 | }
|
---|
83 |
|
---|
84 | QString UIChooserNodeGroup::description() const
|
---|
85 | {
|
---|
86 | return m_strDescription;
|
---|
87 | }
|
---|
88 |
|
---|
89 | QString UIChooserNodeGroup::definition() const
|
---|
90 | {
|
---|
91 | return QString("g=%1").arg(name());
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool UIChooserNodeGroup::hasNodes(UIChooserItemType enmType) const
|
---|
95 | {
|
---|
96 | switch (enmType)
|
---|
97 | {
|
---|
98 | case UIChooserItemType_Any:
|
---|
99 | return hasNodes(UIChooserItemType_Group) || hasNodes(UIChooserItemType_Global) || hasNodes(UIChooserItemType_Machine);
|
---|
100 | case UIChooserItemType_Group:
|
---|
101 | return !m_nodesGroup.isEmpty();
|
---|
102 | case UIChooserItemType_Global:
|
---|
103 | return !m_nodesGlobal.isEmpty();
|
---|
104 | case UIChooserItemType_Machine:
|
---|
105 | return !m_nodesMachine.isEmpty();
|
---|
106 | }
|
---|
107 | return false;
|
---|
108 | }
|
---|
109 |
|
---|
110 | QList<UIChooserNode*> UIChooserNodeGroup::nodes(UIChooserItemType enmType) const
|
---|
111 | {
|
---|
112 | switch (enmType)
|
---|
113 | {
|
---|
114 | case UIChooserItemType_Any: return m_nodesGlobal + m_nodesGroup + m_nodesMachine;
|
---|
115 | case UIChooserItemType_Group: return m_nodesGroup;
|
---|
116 | case UIChooserItemType_Global: return m_nodesGlobal;
|
---|
117 | case UIChooserItemType_Machine: return m_nodesMachine;
|
---|
118 | }
|
---|
119 | AssertFailedReturn(QList<UIChooserNode*>());
|
---|
120 | }
|
---|
121 |
|
---|
122 | void UIChooserNodeGroup::addNode(UIChooserNode *pNode, int iPosition)
|
---|
123 | {
|
---|
124 | switch (pNode->type())
|
---|
125 | {
|
---|
126 | case UIChooserItemType_Group: m_nodesGroup.insert(iPosition, pNode); return;
|
---|
127 | case UIChooserItemType_Global: m_nodesGlobal.insert(iPosition, pNode); return;
|
---|
128 | case UIChooserItemType_Machine: m_nodesMachine.insert(iPosition, pNode); return;
|
---|
129 | default: break;
|
---|
130 | }
|
---|
131 | AssertFailedReturnVoid();
|
---|
132 | }
|
---|
133 |
|
---|
134 | void UIChooserNodeGroup::removeNode(UIChooserNode *pNode)
|
---|
135 | {
|
---|
136 | switch (pNode->type())
|
---|
137 | {
|
---|
138 | case UIChooserItemType_Group: m_nodesGroup.removeAll(pNode); return;
|
---|
139 | case UIChooserItemType_Global: m_nodesGlobal.removeAll(pNode); return;
|
---|
140 | case UIChooserItemType_Machine: m_nodesMachine.removeAll(pNode); return;
|
---|
141 | default: break;
|
---|
142 | }
|
---|
143 | AssertFailedReturnVoid();
|
---|
144 | }
|
---|
145 |
|
---|
146 | void UIChooserNodeGroup::removeAllNodes(const QUuid &uId)
|
---|
147 | {
|
---|
148 | foreach (UIChooserNode *pNode, nodes())
|
---|
149 | pNode->removeAllNodes(uId);
|
---|
150 | }
|
---|
151 |
|
---|
152 | void UIChooserNodeGroup::updateAllNodes(const QUuid &uId)
|
---|
153 | {
|
---|
154 | // Nothing to update for group-node..
|
---|
155 |
|
---|
156 | /* Update group-item: */
|
---|
157 | item()->updateItem();
|
---|
158 |
|
---|
159 | /* Update all the children recursively: */
|
---|
160 | foreach (UIChooserNode *pNode, nodes())
|
---|
161 | pNode->updateAllNodes(uId);
|
---|
162 | }
|
---|
163 |
|
---|
164 | int UIChooserNodeGroup::positionOf(UIChooserNode *pNode)
|
---|
165 | {
|
---|
166 | switch (pNode->type())
|
---|
167 | {
|
---|
168 | case UIChooserItemType_Group: return m_nodesGroup.indexOf(pNode->toGroupNode());
|
---|
169 | case UIChooserItemType_Global: return m_nodesGlobal.indexOf(pNode->toGlobalNode());
|
---|
170 | case UIChooserItemType_Machine: return m_nodesMachine.indexOf(pNode->toMachineNode());
|
---|
171 | default: break;
|
---|
172 | }
|
---|
173 | AssertFailedReturn(0);
|
---|
174 | }
|
---|
175 |
|
---|
176 | void UIChooserNodeGroup::setName(const QString &strName)
|
---|
177 | {
|
---|
178 | /* Make sure something changed: */
|
---|
179 | if (m_strName == strName)
|
---|
180 | return;
|
---|
181 |
|
---|
182 | /* Save name: */
|
---|
183 | m_strName = strName;
|
---|
184 |
|
---|
185 | /* Update group-item: */
|
---|
186 | if (item())
|
---|
187 | item()->updateItem();
|
---|
188 | }
|
---|
189 |
|
---|
190 | void UIChooserNodeGroup::retranslateUi()
|
---|
191 | {
|
---|
192 | /* Update description: */
|
---|
193 | m_strDescription = tr("Virtual Machine group");
|
---|
194 |
|
---|
195 | /* Update group-item: */
|
---|
196 | if (item())
|
---|
197 | item()->updateItem();
|
---|
198 | }
|
---|
199 |
|
---|
200 | void UIChooserNodeGroup::copyContents(UIChooserNodeGroup *pCopyFrom)
|
---|
201 | {
|
---|
202 | foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Group))
|
---|
203 | new UIChooserNodeGroup(this, pNode->toGroupNode(), m_nodesGroup.size());
|
---|
204 | foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Global))
|
---|
205 | new UIChooserNodeGlobal(this, pNode->toGlobalNode(), m_nodesGlobal.size());
|
---|
206 | foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Machine))
|
---|
207 | new UIChooserNodeMachine(this, pNode->toMachineNode(), m_nodesMachine.size());
|
---|
208 | }
|
---|