VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.cpp

Last change on this file was 104251, checked in by vboxsync, 6 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the manager UI classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1/* $Id: UIChooserNodeMachine.cpp 104251 2024-04-09 12:36:47Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIChooserNodeMachine class implementation.
4 */
5
6/*
7 * Copyright (C) 2012-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/* Qt includes: */
29#include <QRegularExpression>
30
31/* GUI includes: */
32#include "UIChooserAbstractModel.h"
33#include "UIChooserNodeMachine.h"
34#include "UITranslationEventListener.h"
35#include "UIVirtualMachineItemCloud.h"
36#include "UIVirtualMachineItemLocal.h"
37
38
39UIChooserNodeMachine::UIChooserNodeMachine(UIChooserNode *pParent,
40 int iPosition,
41 const CMachine &comMachine)
42 : UIChooserNode(pParent, false /* favorite */)
43 , m_pCache(new UIVirtualMachineItemLocal(comMachine))
44{
45 /* Add to parent: */
46 if (parentNode())
47 parentNode()->addNode(this, iPosition);
48
49 /* Apply language settings: */
50 sltRetranslateUI();
51 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
52 this, &UIChooserNodeMachine::sltRetranslateUI);
53}
54
55UIChooserNodeMachine::UIChooserNodeMachine(UIChooserNode *pParent,
56 int iPosition,
57 const CCloudMachine &comCloudMachine)
58 : UIChooserNode(pParent, false /* favorite */)
59 , m_pCache(new UIVirtualMachineItemCloud(comCloudMachine))
60{
61 /* Add to parent: */
62 if (parentNode())
63 parentNode()->addNode(this, iPosition);
64
65 /* Cloud VM item can notify machine node only directly (no console), we have to setup listener: */
66 connect(static_cast<UIVirtualMachineItemCloud*>(m_pCache), &UIVirtualMachineItemCloud::sigRefreshFinished,
67 this, &UIChooserNodeMachine::sltHandleStateChange);
68 connect(static_cast<UIVirtualMachineItemCloud*>(m_pCache), &UIVirtualMachineItemCloud::sigRefreshStarted,
69 static_cast<UIChooserAbstractModel*>(model()), &UIChooserAbstractModel::sltHandleCloudMachineRefreshStarted);
70 connect(static_cast<UIVirtualMachineItemCloud*>(m_pCache), &UIVirtualMachineItemCloud::sigRefreshFinished,
71 static_cast<UIChooserAbstractModel*>(model()), &UIChooserAbstractModel::sltHandleCloudMachineRefreshFinished);
72
73 /* Apply language settings: */
74 sltRetranslateUI();
75 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
76 this, &UIChooserNodeMachine::sltRetranslateUI);
77}
78
79UIChooserNodeMachine::UIChooserNodeMachine(UIChooserNode *pParent,
80 int iPosition,
81 UIFakeCloudVirtualMachineItemState enmState)
82 : UIChooserNode(pParent, false /* favorite */)
83 , m_pCache(new UIVirtualMachineItemCloud(enmState))
84{
85 /* Add to parent: */
86 if (parentNode())
87 parentNode()->addNode(this, iPosition);
88
89 /* Apply language settings: */
90 sltRetranslateUI();
91 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
92 this, &UIChooserNodeMachine::sltRetranslateUI);
93}
94
95UIChooserNodeMachine::UIChooserNodeMachine(UIChooserNode *pParent,
96 int iPosition,
97 UIChooserNodeMachine *pCopyFrom)
98 : UIChooserNode(pParent, pCopyFrom->isFavorite())
99{
100 /* Prepare cache of corresponding type: */
101 switch (pCopyFrom->cacheType())
102 {
103 case UIVirtualMachineItemType_Local:
104 m_pCache = new UIVirtualMachineItemLocal(pCopyFrom->cache()->toLocal()->machine());
105 break;
106 case UIVirtualMachineItemType_CloudFake:
107 m_pCache = new UIVirtualMachineItemCloud(pCopyFrom->cache()->toCloud()->fakeCloudItemState());
108 break;
109 case UIVirtualMachineItemType_CloudReal:
110 m_pCache = new UIVirtualMachineItemCloud(pCopyFrom->cache()->toCloud()->machine());
111 break;
112 default:
113 break;
114 }
115
116 /* Add to parent: */
117 if (parentNode())
118 parentNode()->addNode(this, iPosition);
119
120 /* Apply language settings: */
121 sltRetranslateUI();
122 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
123 this, &UIChooserNodeMachine::sltRetranslateUI);
124}
125
126UIChooserNodeMachine::~UIChooserNodeMachine()
127{
128 /* Delete item: */
129 delete item();
130
131 /* Remove from parent: */
132 if (parentNode())
133 parentNode()->removeNode(this);
134
135 /* Cleanup cache: */
136 delete m_pCache;
137}
138
139QString UIChooserNodeMachine::name() const
140{
141 return m_pCache->name();
142}
143
144QString UIChooserNodeMachine::fullName() const
145{
146 /* Get full parent name, append with '/' if not yet appended: */
147 AssertReturn(parentNode(), name());
148 QString strFullParentName = parentNode()->fullName();
149 if (!strFullParentName.endsWith('/'))
150 strFullParentName.append('/');
151 /* Return full item name based on parent prefix: */
152 return strFullParentName + name();
153}
154
155QString UIChooserNodeMachine::description() const
156{
157 return m_strDescription;
158}
159
160QString UIChooserNodeMachine::definition(bool) const
161{
162 const QString strNodePrefix = UIChooserAbstractModel::prefixToString(UIChooserNodeDataPrefixType_Machine);
163 return QString("%1=%2").arg(strNodePrefix).arg(UIChooserAbstractModel::toOldStyleUuid(id()));
164}
165
166bool UIChooserNodeMachine::hasNodes(UIChooserNodeType enmType /* = UIChooserNodeType_Any */) const
167{
168 Q_UNUSED(enmType);
169 AssertFailedReturn(false);
170}
171
172QList<UIChooserNode*> UIChooserNodeMachine::nodes(UIChooserNodeType enmType /* = UIChooserNodeType_Any */) const
173{
174 Q_UNUSED(enmType);
175 AssertFailedReturn(QList<UIChooserNode*>());
176}
177
178void UIChooserNodeMachine::addNode(UIChooserNode *pNode, int iPosition)
179{
180 Q_UNUSED(pNode);
181 Q_UNUSED(iPosition);
182 AssertFailedReturnVoid();
183}
184
185void UIChooserNodeMachine::removeNode(UIChooserNode *pNode)
186{
187 Q_UNUSED(pNode);
188 AssertFailedReturnVoid();
189}
190
191void UIChooserNodeMachine::removeAllNodes(const QUuid &uId)
192{
193 /* Skip other ids: */
194 if (id() != uId)
195 return;
196
197 /* Remove this node: */
198 delete this;
199}
200
201void UIChooserNodeMachine::updateAllNodes(const QUuid &uId)
202{
203 /* Skip other ids: */
204 if (id() != uId)
205 return;
206
207 /* Update cache: */
208 m_pCache->recache();
209
210 /* Update machine-item: */
211 if (item())
212 item()->updateItem();
213}
214
215int UIChooserNodeMachine::positionOf(UIChooserNode *pNode)
216{
217 Q_UNUSED(pNode);
218 AssertFailedReturn(0);
219}
220
221void UIChooserNodeMachine::searchForNodes(const QString &strSearchTerm, int iSearchFlags, QList<UIChooserNode*> &matchedItems)
222{
223 /* Ignore if we are not searching for the machine-node: */
224 if (!(iSearchFlags & UIChooserItemSearchFlag_Machine))
225 return;
226
227 /* If the search term is empty we just add the node to the matched list: */
228 if (strSearchTerm.isEmpty())
229 matchedItems << this;
230 else
231 {
232 /* If exact ID flag specified => check node ID: */
233 if (iSearchFlags & UIChooserItemSearchFlag_ExactId)
234 {
235 if (id() == QUuid(strSearchTerm))
236 matchedItems << this;
237 }
238 /* If exact name flag specified => check full node name: */
239 else if (iSearchFlags & UIChooserItemSearchFlag_ExactName)
240 {
241 if (name() == strSearchTerm)
242 matchedItems << this;
243 }
244 /* Otherwise check if name contains search term, including wildcards: */
245 else
246 {
247 QRegularExpression searchRegEx = QRegularExpression::fromWildcard(strSearchTerm, Qt::CaseInsensitive,
248 QRegularExpression::UnanchoredWildcardConversion);
249 if (name().contains(searchRegEx))
250 matchedItems << this;
251 }
252 }
253}
254
255void UIChooserNodeMachine::sortNodes()
256{
257 AssertFailedReturnVoid();
258}
259
260UIVirtualMachineItem *UIChooserNodeMachine::cache() const
261{
262 return m_pCache;
263}
264
265UIVirtualMachineItemType UIChooserNodeMachine::cacheType() const
266{
267 return cache() ? cache()->itemType() : UIVirtualMachineItemType_Invalid;
268}
269
270QUuid UIChooserNodeMachine::id() const
271{
272 return cache() ? cache()->id() : QUuid();
273}
274
275bool UIChooserNodeMachine::accessible() const
276{
277 return cache() ? cache()->accessible() : false;
278}
279
280void UIChooserNodeMachine::sltRetranslateUI()
281{
282 /* Update internal stuff: */
283 m_strDescription = tr("Virtual Machine");
284
285 /* Update machine-item: */
286 if (item())
287 item()->updateItem();
288}
289
290void UIChooserNodeMachine::sltHandleStateChange()
291{
292 /* Update machine-item: */
293 if (item())
294 item()->updateItem();
295}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use