1 | /* $Id: UIChooser.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIChooser class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2024 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 <QVBoxLayout>
|
---|
30 |
|
---|
31 | /* GUI includes: */
|
---|
32 | #include "UIChooser.h"
|
---|
33 | #include "UIChooserModel.h"
|
---|
34 | #include "UIChooserView.h"
|
---|
35 | #include "UIVirtualMachineItem.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | UIChooser::UIChooser(QWidget *pParent, UIActionPool *pActionPool)
|
---|
39 | : QWidget(pParent)
|
---|
40 | , m_pActionPool(pActionPool)
|
---|
41 | , m_pChooserModel(0)
|
---|
42 | , m_pChooserView(0)
|
---|
43 | {
|
---|
44 | prepare();
|
---|
45 | }
|
---|
46 |
|
---|
47 | UIChooser::~UIChooser()
|
---|
48 | {
|
---|
49 | cleanup();
|
---|
50 | }
|
---|
51 |
|
---|
52 | bool UIChooser::isGroupSavingInProgress() const
|
---|
53 | {
|
---|
54 | AssertPtrReturn(model(), false);
|
---|
55 | return model()->isGroupSavingInProgress();
|
---|
56 | }
|
---|
57 |
|
---|
58 | void UIChooser::setKeepCloudNodesUpdated(bool fUpdate)
|
---|
59 | {
|
---|
60 | AssertPtrReturnVoid(model());
|
---|
61 | return model()->setKeepCloudNodesUpdated(fUpdate);
|
---|
62 | }
|
---|
63 |
|
---|
64 | bool UIChooser::isCloudProfileUpdateInProgress() const
|
---|
65 | {
|
---|
66 | AssertPtrReturn(model(), false);
|
---|
67 | return model()->isCloudProfileUpdateInProgress();
|
---|
68 | }
|
---|
69 |
|
---|
70 | QList<UIVirtualMachineItemCloud*> UIChooser::cloudMachineItems() const
|
---|
71 | {
|
---|
72 | AssertPtrReturn(model(), QList<UIVirtualMachineItemCloud*>());
|
---|
73 | return model()->cloudMachineItems();
|
---|
74 | }
|
---|
75 |
|
---|
76 | UIVirtualMachineItem *UIChooser::currentItem() const
|
---|
77 | {
|
---|
78 | AssertPtrReturn(model(), 0);
|
---|
79 | return model()->firstSelectedMachineItem();
|
---|
80 | }
|
---|
81 |
|
---|
82 | QList<UIVirtualMachineItem*> UIChooser::currentItems() const
|
---|
83 | {
|
---|
84 | AssertPtrReturn(model(), QList<UIVirtualMachineItem*>());
|
---|
85 | return model()->selectedMachineItems();
|
---|
86 | }
|
---|
87 |
|
---|
88 | bool UIChooser::isGroupItemSelected() const
|
---|
89 | {
|
---|
90 | AssertPtrReturn(model(), false);
|
---|
91 | return model()->isGroupItemSelected();
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool UIChooser::isGlobalItemSelected() const
|
---|
95 | {
|
---|
96 | AssertPtrReturn(model(), false);
|
---|
97 | return model()->isGlobalItemSelected();
|
---|
98 | }
|
---|
99 |
|
---|
100 | bool UIChooser::isMachineItemSelected() const
|
---|
101 | {
|
---|
102 | AssertPtrReturn(model(), false);
|
---|
103 | return model()->isMachineItemSelected();
|
---|
104 | }
|
---|
105 |
|
---|
106 | bool UIChooser::isLocalMachineItemSelected() const
|
---|
107 | {
|
---|
108 | AssertPtrReturn(model(), false);
|
---|
109 | return model()->isLocalMachineItemSelected();
|
---|
110 | }
|
---|
111 |
|
---|
112 | bool UIChooser::isCloudMachineItemSelected() const
|
---|
113 | {
|
---|
114 | AssertPtrReturn(model(), false);
|
---|
115 | return model()->isCloudMachineItemSelected();
|
---|
116 | }
|
---|
117 |
|
---|
118 | bool UIChooser::isSingleGroupSelected() const
|
---|
119 | {
|
---|
120 | AssertPtrReturn(model(), false);
|
---|
121 | return model()->isSingleGroupSelected();
|
---|
122 | }
|
---|
123 |
|
---|
124 | bool UIChooser::isSingleLocalGroupSelected() const
|
---|
125 | {
|
---|
126 | AssertPtrReturn(model(), false);
|
---|
127 | return model()->isSingleLocalGroupSelected();
|
---|
128 | }
|
---|
129 |
|
---|
130 | bool UIChooser::isSingleCloudProviderGroupSelected() const
|
---|
131 | {
|
---|
132 | AssertPtrReturn(model(), false);
|
---|
133 | return model()->isSingleCloudProviderGroupSelected();
|
---|
134 | }
|
---|
135 |
|
---|
136 | bool UIChooser::isSingleCloudProfileGroupSelected() const
|
---|
137 | {
|
---|
138 | AssertPtrReturn(model(), false);
|
---|
139 | return model()->isSingleCloudProfileGroupSelected();
|
---|
140 | }
|
---|
141 |
|
---|
142 | bool UIChooser::isAllItemsOfOneGroupSelected() const
|
---|
143 | {
|
---|
144 | AssertPtrReturn(model(), false);
|
---|
145 | return model()->isAllItemsOfOneGroupSelected();
|
---|
146 | }
|
---|
147 |
|
---|
148 | QString UIChooser::fullGroupName() const
|
---|
149 | {
|
---|
150 | AssertPtrReturn(model(), QString());
|
---|
151 | return model()->fullGroupName();
|
---|
152 | }
|
---|
153 |
|
---|
154 | void UIChooser::openGroupNameEditor()
|
---|
155 | {
|
---|
156 | AssertPtrReturnVoid(model());
|
---|
157 | model()->startEditingSelectedGroupItemName();
|
---|
158 | }
|
---|
159 |
|
---|
160 | void UIChooser::disbandGroup()
|
---|
161 | {
|
---|
162 | AssertPtrReturnVoid(model());
|
---|
163 | model()->disbandSelectedGroupItem();
|
---|
164 | }
|
---|
165 |
|
---|
166 | void UIChooser::removeMachine()
|
---|
167 | {
|
---|
168 | AssertPtrReturnVoid(model());
|
---|
169 | model()->removeSelectedMachineItems();
|
---|
170 | }
|
---|
171 |
|
---|
172 | void UIChooser::moveMachineToGroup(const QString &strName)
|
---|
173 | {
|
---|
174 | AssertPtrReturnVoid(model());
|
---|
175 | model()->moveSelectedMachineItemsToGroupItem(strName);
|
---|
176 | }
|
---|
177 |
|
---|
178 | QStringList UIChooser::possibleGroupsForMachineToMove(const QUuid &uId)
|
---|
179 | {
|
---|
180 | AssertPtrReturn(model(), QStringList());
|
---|
181 | return model()->possibleGroupNodeNamesForMachineNodeToMove(uId);
|
---|
182 | }
|
---|
183 |
|
---|
184 | QStringList UIChooser::possibleGroupsForGroupToMove(const QString &strFullName)
|
---|
185 | {
|
---|
186 | AssertPtrReturn(model(), QStringList());
|
---|
187 | return model()->possibleGroupNodeNamesForGroupNodeToMove(strFullName);
|
---|
188 | }
|
---|
189 |
|
---|
190 | void UIChooser::refreshMachine()
|
---|
191 | {
|
---|
192 | AssertPtrReturnVoid(model());
|
---|
193 | model()->refreshSelectedMachineItems();
|
---|
194 | }
|
---|
195 |
|
---|
196 | void UIChooser::sortGroup()
|
---|
197 | {
|
---|
198 | AssertPtrReturnVoid(model());
|
---|
199 | model()->sortSelectedGroupItem();
|
---|
200 | }
|
---|
201 |
|
---|
202 | void UIChooser::setMachineSearchWidgetVisibility(bool fVisible)
|
---|
203 | {
|
---|
204 | AssertPtrReturnVoid(view());
|
---|
205 | view()->setSearchWidgetVisible(fVisible);
|
---|
206 | }
|
---|
207 |
|
---|
208 | void UIChooser::setCurrentMachine(const QUuid &uId)
|
---|
209 | {
|
---|
210 | AssertPtrReturnVoid(model());
|
---|
211 | model()->setCurrentMachineItem(uId);
|
---|
212 | }
|
---|
213 |
|
---|
214 | void UIChooser::setCurrentGlobal()
|
---|
215 | {
|
---|
216 | AssertPtrReturnVoid(model());
|
---|
217 | model()->setCurrentGlobalItem();
|
---|
218 | }
|
---|
219 |
|
---|
220 | void UIChooser::setGlobalItemHeightHint(int iHeight)
|
---|
221 | {
|
---|
222 | AssertPtrReturnVoid(model());
|
---|
223 | model()->setGlobalItemHeightHint(iHeight);
|
---|
224 | }
|
---|
225 |
|
---|
226 | void UIChooser::sltToolMenuRequested(const QPoint &position, UIVirtualMachineItem *pItem)
|
---|
227 | {
|
---|
228 | /* Translate scene coordinates to global one: */
|
---|
229 | AssertPtrReturnVoid(view());
|
---|
230 | emit sigToolMenuRequested(mapToGlobal(view()->mapFromScene(position)), pItem);
|
---|
231 | }
|
---|
232 |
|
---|
233 | void UIChooser::prepare()
|
---|
234 | {
|
---|
235 | /* Prepare everything: */
|
---|
236 | prepareModel();
|
---|
237 | prepareWidgets();
|
---|
238 | prepareConnections();
|
---|
239 |
|
---|
240 | /* Init model: */
|
---|
241 | initModel();
|
---|
242 | }
|
---|
243 |
|
---|
244 | void UIChooser::prepareModel()
|
---|
245 | {
|
---|
246 | /* Prepare Chooser-model: */
|
---|
247 | m_pChooserModel = new UIChooserModel(this, actionPool());
|
---|
248 | }
|
---|
249 |
|
---|
250 | void UIChooser::prepareWidgets()
|
---|
251 | {
|
---|
252 | /* Prepare main-layout: */
|
---|
253 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
254 | if (pMainLayout)
|
---|
255 | {
|
---|
256 | pMainLayout->setContentsMargins(0, 0, 0, 0);
|
---|
257 | pMainLayout->setSpacing(0);
|
---|
258 |
|
---|
259 | /* Prepare Chooser-view: */
|
---|
260 | m_pChooserView = new UIChooserView(this);
|
---|
261 | if (m_pChooserView)
|
---|
262 | {
|
---|
263 | AssertPtrReturnVoid(model());
|
---|
264 | m_pChooserView->setModel(model());
|
---|
265 | m_pChooserView->setScene(model()->scene());
|
---|
266 | m_pChooserView->show();
|
---|
267 | setFocusProxy(m_pChooserView);
|
---|
268 |
|
---|
269 | /* Add into layout: */
|
---|
270 | pMainLayout->addWidget(m_pChooserView);
|
---|
271 | }
|
---|
272 | }
|
---|
273 | }
|
---|
274 |
|
---|
275 | void UIChooser::prepareConnections()
|
---|
276 | {
|
---|
277 | AssertPtrReturnVoid(model());
|
---|
278 | AssertPtrReturnVoid(view());
|
---|
279 |
|
---|
280 | /* Abstract Chooser-model connections: */
|
---|
281 | connect(model(), &UIChooserModel::sigGroupSavingStateChanged,
|
---|
282 | this, &UIChooser::sigGroupSavingStateChanged);
|
---|
283 | connect(model(), &UIChooserModel::sigCloudProfileStateChange,
|
---|
284 | this, &UIChooser::sigCloudProfileStateChange);
|
---|
285 | connect(model(), &UIChooserModel::sigCloudMachineStateChange,
|
---|
286 | this, &UIChooser::sigCloudMachineStateChange);
|
---|
287 | connect(model(), &UIChooserModel::sigCloudUpdateStateChanged,
|
---|
288 | this, &UIChooser::sigCloudUpdateStateChanged);
|
---|
289 |
|
---|
290 | /* Chooser-model connections: */
|
---|
291 | connect(model(), &UIChooserModel::sigToolMenuRequested,
|
---|
292 | this, &UIChooser::sltToolMenuRequested);
|
---|
293 | connect(model(), &UIChooserModel::sigSelectionChanged,
|
---|
294 | this, &UIChooser::sigSelectionChanged);
|
---|
295 | connect(model(), &UIChooserModel::sigSelectionInvalidated,
|
---|
296 | this, &UIChooser::sigSelectionInvalidated);
|
---|
297 | connect(model(), &UIChooserModel::sigToggleStarted,
|
---|
298 | this, &UIChooser::sigToggleStarted);
|
---|
299 | connect(model(), &UIChooserModel::sigToggleFinished,
|
---|
300 | this, &UIChooser::sigToggleFinished);
|
---|
301 | connect(model(), &UIChooserModel::sigRootItemMinimumWidthHintChanged,
|
---|
302 | view(), &UIChooserView::sltMinimumWidthHintChanged);
|
---|
303 | connect(model(), &UIChooserModel::sigStartOrShowRequest,
|
---|
304 | this, &UIChooser::sigStartOrShowRequest);
|
---|
305 |
|
---|
306 | /* Chooser-view connections: */
|
---|
307 | connect(view(), &UIChooserView::sigResized,
|
---|
308 | model(), &UIChooserModel::sltHandleViewResized);
|
---|
309 | connect(view(), &UIChooserView::sigSearchWidgetVisibilityChanged,
|
---|
310 | this, &UIChooser::sigMachineSearchWidgetVisibilityChanged);
|
---|
311 | }
|
---|
312 |
|
---|
313 | void UIChooser::initModel()
|
---|
314 | {
|
---|
315 | AssertPtrReturnVoid(model());
|
---|
316 | model()->init();
|
---|
317 | }
|
---|
318 |
|
---|
319 | void UIChooser::deinitModel()
|
---|
320 | {
|
---|
321 | AssertPtrReturnVoid(model());
|
---|
322 | model()->deinit();
|
---|
323 | }
|
---|
324 |
|
---|
325 | void UIChooser::cleanupConnections()
|
---|
326 | {
|
---|
327 | AssertPtrReturnVoid(model());
|
---|
328 | AssertPtrReturnVoid(view());
|
---|
329 |
|
---|
330 | /* Abstract Chooser-model connections: */
|
---|
331 | disconnect(model(), &UIChooserModel::sigGroupSavingStateChanged,
|
---|
332 | this, &UIChooser::sigGroupSavingStateChanged);
|
---|
333 | disconnect(model(), &UIChooserModel::sigCloudProfileStateChange,
|
---|
334 | this, &UIChooser::sigCloudProfileStateChange);
|
---|
335 | disconnect(model(), &UIChooserModel::sigCloudMachineStateChange,
|
---|
336 | this, &UIChooser::sigCloudMachineStateChange);
|
---|
337 | disconnect(model(), &UIChooserModel::sigCloudUpdateStateChanged,
|
---|
338 | this, &UIChooser::sigCloudUpdateStateChanged);
|
---|
339 |
|
---|
340 | /* Chooser-model connections: */
|
---|
341 | disconnect(model(), &UIChooserModel::sigToolMenuRequested,
|
---|
342 | this, &UIChooser::sltToolMenuRequested);
|
---|
343 | disconnect(model(), &UIChooserModel::sigSelectionChanged,
|
---|
344 | this, &UIChooser::sigSelectionChanged);
|
---|
345 | disconnect(model(), &UIChooserModel::sigSelectionInvalidated,
|
---|
346 | this, &UIChooser::sigSelectionInvalidated);
|
---|
347 | disconnect(model(), &UIChooserModel::sigToggleStarted,
|
---|
348 | this, &UIChooser::sigToggleStarted);
|
---|
349 | disconnect(model(), &UIChooserModel::sigToggleFinished,
|
---|
350 | this, &UIChooser::sigToggleFinished);
|
---|
351 | disconnect(model(), &UIChooserModel::sigRootItemMinimumWidthHintChanged,
|
---|
352 | view(), &UIChooserView::sltMinimumWidthHintChanged);
|
---|
353 | disconnect(model(), &UIChooserModel::sigStartOrShowRequest,
|
---|
354 | this, &UIChooser::sigStartOrShowRequest);
|
---|
355 |
|
---|
356 | /* Chooser-view connections: */
|
---|
357 | disconnect(view(), &UIChooserView::sigResized,
|
---|
358 | model(), &UIChooserModel::sltHandleViewResized);
|
---|
359 | disconnect(view(), &UIChooserView::sigSearchWidgetVisibilityChanged,
|
---|
360 | this, &UIChooser::sigMachineSearchWidgetVisibilityChanged);
|
---|
361 | }
|
---|
362 |
|
---|
363 | void UIChooser::cleanup()
|
---|
364 | {
|
---|
365 | /* Deinit model: */
|
---|
366 | deinitModel();
|
---|
367 |
|
---|
368 | /* Cleanup everything: */
|
---|
369 | cleanupConnections();
|
---|
370 | }
|
---|