VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

Last change on this file was 106061, checked in by vboxsync, 3 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.5 KB
Line 
1/* $Id: UIChooserModel.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIChooserModel class declaration.
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#ifndef FEQT_INCLUDED_SRC_manager_chooser_UIChooserModel_h
29#define FEQT_INCLUDED_SRC_manager_chooser_UIChooserModel_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QPointer>
36
37/* GUI includes: */
38#include "UIChooserAbstractModel.h"
39#include "UIExtraDataDefs.h"
40
41/* COM includes: */
42#include "CCloudMachine.h"
43#include "CMachine.h"
44
45/* Forward declaration: */
46class QDrag;
47class UIActionPool;
48class UIChooser;
49class UIChooserHandlerMouse;
50class UIChooserHandlerKeyboard;
51class UIChooserItem;
52class UIChooserItemMachine;
53class UIChooserNode;
54class UIChooserView;
55class UIVirtualMachineItem;
56
57/** UIChooserAbstractModel extension used as VM Chooser-pane model.
58 * This class is used to operate on tree of visible tree items
59 * representing VMs and their groups. */
60class UIChooserModel : public UIChooserAbstractModel
61{
62 Q_OBJECT;
63
64signals:
65
66 /** @name Tool stuff.
67 * @{ */
68 /** Notifies listeners about tool popup-menu request for certain @a position and optionally machine @a pItem. */
69 void sigToolMenuRequested(const QPoint &position, UIVirtualMachineItem *pItem);
70 /** @} */
71
72 /** @name Selection stuff.
73 * @{ */
74 /** Notifies listeners about selection changed. */
75 void sigSelectionChanged();
76 /** Notifies listeners about selection invalidated. */
77 void sigSelectionInvalidated();
78
79 /** Notifies listeners about group toggling started. */
80 void sigToggleStarted();
81 /** Notifies listeners about group toggling finished. */
82 void sigToggleFinished();
83 /** @} */
84
85 /** @name Layout stuff.
86 * @{ */
87 /** Notifies listeners about root item minimum width @a iHint changed. */
88 void sigRootItemMinimumWidthHintChanged(int iHint);
89 /** @} */
90
91 /** @name Action stuff.
92 * @{ */
93 /** Notifies listeners about start or show request. */
94 void sigStartOrShowRequest();
95 /** @} */
96
97public:
98
99 /** Constructs Chooser-model passing @a pParent to the base-class. */
100 UIChooserModel(UIChooser *pParent, UIActionPool *pActionPool);
101 /** Destructs Chooser-model. */
102 virtual ~UIChooserModel() RT_OVERRIDE;
103
104 /** @name General stuff.
105 * @{ */
106 /** Inits model. */
107 virtual void init() RT_OVERRIDE;
108
109 /** Returns the action-pool reference. */
110 UIActionPool *actionPool() const;
111 /** Returns the scene reference. */
112 QGraphicsScene *scene() const;
113 /** Returns the reference of the first view of the scene(). */
114 UIChooserView *view() const;
115 /** Returns the paint device reference. */
116 QPaintDevice *paintDevice() const;
117
118 /** Returns item at @a position, taking into account possible @a deviceTransform. */
119 QGraphicsItem *itemAt(const QPointF &position, const QTransform &deviceTransform = QTransform()) const;
120
121 /** Handles tool button click for certain @a pItem. */
122 void handleToolButtonClick(UIChooserItem *pItem);
123 /** Handles pin button click for certain @a pItem. */
124 void handlePinButtonClick(UIChooserItem *pItem);
125 /** @} */
126
127 /** @name Selection stuff.
128 * @{ */
129 /** Sets a list of selected @a items. */
130 void setSelectedItems(const QList<UIChooserItem*> &items);
131 /** Defines selected @a pItem. */
132 void setSelectedItem(UIChooserItem *pItem);
133 /** Defines selected-item by @a definition. */
134 void setSelectedItem(const QString &strDefinition);
135 /** Clear selected-items list. */
136 void clearSelectedItems();
137
138 /** Returns a list of selected-items. */
139 const QList<UIChooserItem*> &selectedItems() const;
140
141 /** Adds @a pItem to list of selected. */
142 void addToSelectedItems(UIChooserItem *pItem);
143 /** Removes @a pItem from list of selected. */
144 void removeFromSelectedItems(UIChooserItem *pItem);
145
146 /** Returns first selected-item. */
147 UIChooserItem *firstSelectedItem() const;
148 /** Returns first selected machine item. */
149 UIVirtualMachineItem *firstSelectedMachineItem() const;
150 /** Returns a list of selected machine items. */
151 QList<UIVirtualMachineItem*> selectedMachineItems() const;
152
153 /** Returns whether group item is selected. */
154 bool isGroupItemSelected() const;
155 /** Returns whether global item is selected. */
156 bool isGlobalItemSelected() const;
157 /** Returns whether machine item is selected. */
158 bool isMachineItemSelected() const;
159 /** Returns whether local machine item is selected. */
160 bool isLocalMachineItemSelected() const;
161 /** Returns whether cloud machine item is selected. */
162 bool isCloudMachineItemSelected() const;
163
164 /** Returns whether single group is selected. */
165 bool isSingleGroupSelected() const;
166 /** Returns whether single local group is selected. */
167 bool isSingleLocalGroupSelected() const;
168 /** Returns whether single cloud provider group is selected. */
169 bool isSingleCloudProviderGroupSelected() const;
170 /** Returns whether single cloud profile group is selected. */
171 bool isSingleCloudProfileGroupSelected() const;
172 /** Returns whether all machine items of one group is selected. */
173 bool isAllItemsOfOneGroupSelected() const;
174
175 /** Returns full name of currently selected group. */
176 QString fullGroupName() const;
177
178 /** Finds closest non-selected-item. */
179 UIChooserItem *findClosestUnselectedItem() const;
180 /** Makes sure selection doesn't contain item with certain @a uId. */
181 void makeSureNoItemWithCertainIdSelected(const QUuid &uId);
182 /** Makes sure at least one item selected. */
183 void makeSureAtLeastOneItemSelected();
184
185 /** Defines current @a pItem. */
186 void setCurrentItem(UIChooserItem *pItem);
187 /** Returns current-item. */
188 UIChooserItem *currentItem() const;
189 /** @} */
190
191 /** @name Navigation stuff.
192 * @{ */
193 /** Returns a list of navigation-items. */
194 const QList<UIChooserItem*> &navigationItems() const;
195 /** Removes @a pItem from navigation list. */
196 void removeFromNavigationItems(UIChooserItem *pItem);
197 /** Updates navigation list. */
198 void updateNavigationItemList();
199 /** @} */
200
201 /** @name Search stuff.
202 * @{ */
203 /** Performs a search for an item matching @a strDefinition. */
204 UIChooserItem *searchItemByDefinition(const QString &strDefinition) const;
205
206 /** Performs a search using @a strSearchTerm and @a iSearchFlags specified. */
207 virtual void performSearch(const QString &strSearchTerm, int iSearchFlags) RT_OVERRIDE;
208 /** Resets the search result data members and disables item's visual effects.
209 * Also returns a list of all nodes which may be utilized by the calling code. */
210 virtual QList<UIChooserNode*> resetSearch() RT_OVERRIDE;
211
212 /** Selects next/prev (wrt. @a fIsNext) search result. */
213 void selectSearchResult(bool fIsNext);
214 /** Shows/hides machine search widget. */
215 void setSearchWidgetVisible(bool fVisible);
216 /** @} */
217
218 /** @name Children stuff.
219 * @{ */
220 /** Returns the root instance. */
221 UIChooserItem *root() const;
222
223 /** Starts editing selected group item name. */
224 void startEditingSelectedGroupItemName();
225 /** Disbands selected group item. */
226 void disbandSelectedGroupItem();
227 /** Removes selected machine items. */
228 void removeSelectedMachineItems();
229 /** Moves selected machine items to group item.
230 * @param strName Holds the group item name to move items to, if
231 * that name isn't specified, new top-level group
232 * item will be created. */
233 void moveSelectedMachineItemsToGroupItem(const QString &strName);
234 /** Starts or shows selected items. */
235 void startOrShowSelectedItems();
236 /** Refreshes selected machine items. */
237 void refreshSelectedMachineItems();
238 /** Sorts selected [parent] group item. */
239 void sortSelectedGroupItem();
240 /** Changes current machine item to the one with certain @a uId. */
241 void setCurrentMachineItem(const QUuid &uId);
242 /** Sets global tools item to be the current one. */
243 void setCurrentGlobalItem();
244
245 /** Defines current @a pDragObject. */
246 void setCurrentDragObject(QDrag *pDragObject);
247
248 /** Looks for item with certain @a strLookupText. */
249 void lookFor(const QString &strLookupText);
250 /** @} */
251
252 /** @name Layout stuff.
253 * @{ */
254 /** Updates layout. */
255 void updateLayout();
256
257 /** Defines global item height @a iHint. */
258 void setGlobalItemHeightHint(int iHint);
259 /** @} */
260
261public slots:
262
263 /** @name General stuff.
264 * @{ */
265 /** Handles Chooser-view resize. */
266 void sltHandleViewResized();
267 /** @} */
268
269protected:
270
271 /** @name Event handling stuff.
272 * @{ */
273 /** Preprocesses Qt @a pEvent for passed @a pObject. */
274 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
275 /** @} */
276
277protected slots:
278
279 /** @name Main event handling stuff.
280 * @{ */
281 /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
282 virtual void sltLocalMachineRegistrationChanged(const QUuid &uMachineId, const bool fRegistered) RT_OVERRIDE;
283
284 /** Handles event about cloud provider with @a uProviderId being uninstalled. */
285 virtual void sltHandleCloudProviderUninstall(const QUuid &uProviderId) RT_OVERRIDE;
286 /** @} */
287
288 /** @name Children stuff.
289 * @{ */
290 /** Handles reload machine with certain @a uMachineId request. */
291 virtual void sltReloadMachine(const QUuid &uMachineId) RT_OVERRIDE;
292
293 /** Handles command to detach COM. */
294 virtual void sltDetachCOM() RT_OVERRIDE;
295 /** @} */
296
297 /** @name Cloud stuff.
298 * @{ */
299 /** Handles cloud machine unregistering for @a uId.
300 * @param strProviderShortName Brings provider short name.
301 * @param strProfileName Brings profile name. */
302 virtual void sltCloudMachineUnregistered(const QString &strProviderShortName,
303 const QString &strProfileName,
304 const QUuid &uId) RT_OVERRIDE;
305 /** Handles cloud machine unregistering for a list of @a ids.
306 * @param strProviderShortName Brings provider short name.
307 * @param strProfileName Brings profile name. */
308 virtual void sltCloudMachinesUnregistered(const QString &strProviderShortName,
309 const QString &strProfileName,
310 const QList<QUuid> &ids) RT_OVERRIDE;
311 /** Handles cloud machine registering for @a comMachine.
312 * @param strProviderShortName Brings provider short name.
313 * @param strProfileName Brings profile name. */
314 virtual void sltCloudMachineRegistered(const QString &strProviderShortName,
315 const QString &strProfileName,
316 const CCloudMachine &comMachine) RT_OVERRIDE;
317 /** Handles cloud machine registering for a list of @a machines.
318 * @param strProviderShortName Brings provider short name.
319 * @param strProfileName Brings profile name. */
320 virtual void sltCloudMachinesRegistered(const QString &strProviderShortName,
321 const QString &strProfileName,
322 const QVector<CCloudMachine> &machines) RT_OVERRIDE;
323
324 /** Handles read cloud machine list task complete signal. */
325 virtual void sltHandleReadCloudMachineListTaskComplete() RT_OVERRIDE;
326
327 /** Handles Cloud Profile Manager cumulative changes. */
328 virtual void sltHandleCloudProfileManagerCumulativeChange() RT_OVERRIDE;
329 /** @} */
330
331private slots:
332
333 /** @name Selection stuff.
334 * @{ */
335 /** Makes sure current item is visible. */
336 void sltMakeSureCurrentItemVisible();
337
338 /** Handles current-item destruction. */
339 void sltCurrentItemDestroyed();
340 /** @} */
341
342 /** @name Children stuff.
343 * @{ */
344 /** Handles D&D scrolling. */
345 void sltStartScrolling();
346 /** Handles D&D object destruction. */
347 void sltCurrentDragObjectDestroyed();
348 /** @} */
349
350 /** @name Cloud stuff.
351 * @{ */
352 /** Handles cloud machine removal.
353 * @param strProviderShortName Brings the provider short name.
354 * @param strProfileName Brings the profile name.
355 * @param strName Brings the machine name. */
356 void sltHandleCloudMachineRemoved(const QString &strProviderShortName,
357 const QString &strProfileName,
358 const QString &strName);
359
360 /** Updates selected cloud profiles. */
361 void sltUpdateSelectedCloudProfiles();
362 /** @} */
363
364private:
365
366 /** @name Prepare/Cleanup cascade.
367 * @{ */
368 /** Prepares all. */
369 void prepare();
370 /** Prepares scene. */
371 void prepareScene();
372 /** Prepares context-menu. */
373 void prepareContextMenu();
374 /** Prepares handlers. */
375 void prepareHandlers();
376 /** Prepares cloud update timer. */
377 void prepareCloudUpdateTimer();
378 /** Prepares connections. */
379 void prepareConnections();
380 /** Loads settings. */
381 void loadSettings();
382
383 /** Cleanups connections. */
384 void cleanupConnections();
385 /** Cleanups cloud update timer.*/
386 void cleanupCloudUpdateTimer();
387 /** Cleanups handlers. */
388 void cleanupHandlers();
389 /** Cleanups context-menu. */
390 void cleanupContextMenu();
391 /** Cleanups scene. */
392 void cleanupScene();
393 /** Cleanups all. */
394 void cleanup();
395 /** @} */
396
397 /** @name General stuff.
398 * @{ */
399 /** Handles context-menu @a pEvent. */
400 bool processContextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent);
401 /** @} */
402
403 /** @name Selection stuff.
404 * @{ */
405 /** Clears real focus. */
406 void clearRealFocus();
407 /** @} */
408
409 /** @name Navigation stuff.
410 * @{ */
411 /** Creates navigation list for passed root @a pItem. */
412 QList<UIChooserItem*> createNavigationItemList(UIChooserItem *pItem);
413 /** @} */
414
415 /** @name Children stuff.
416 * @{ */
417 /** Clears tree for main root. */
418 void clearTreeForMainRoot();
419 /** [Re]builds tree for main root, preserves selection if requested. */
420 void buildTreeForMainRoot(bool fPreserveSelection = false);
421 /** Update tree for main root. */
422 void updateTreeForMainRoot();
423
424 /** Removes a list of local virtual @a machineItems. */
425 void removeLocalMachineItems(const QList<UIChooserItemMachine*> &machineItems);
426 /** Unregisters a list of local virtual @a machines. */
427 void unregisterLocalMachines(const QList<CMachine> &machines);
428 /** Unregisters a list of cloud virtual @a machineItems. */
429 void unregisterCloudMachineItems(const QList<UIChooserItemMachine*> &machineItems);
430
431 /** Processes drag move @a pEvent. */
432 bool processDragMoveEvent(QGraphicsSceneDragDropEvent *pEvent);
433 /** Processes drag leave @a pEvent. */
434 bool processDragLeaveEvent(QGraphicsSceneDragDropEvent *pEvent);
435
436 /** Applies the global item height hint. */
437 void applyGlobalItemHeightHint();
438 /** @} */
439
440 /** @name General stuff.
441 * @{ */
442 /** Holds the action-pool reference. */
443 UIActionPool *m_pActionPool;
444
445 /** Holds the scene reference. */
446 QGraphicsScene *m_pScene;
447
448 /** Holds the mouse handler instance. */
449 UIChooserHandlerMouse *m_pMouseHandler;
450 /** Holds the keyboard handler instance. */
451 UIChooserHandlerKeyboard *m_pKeyboardHandler;
452
453 /** Holds the map of local context-menu instances. */
454 QMap<UIChooserNodeType, QMenu*> m_localMenus;
455 /** Holds the map of cloud context-menu instances. */
456 QMap<UIChooserNodeType, QMenu*> m_cloudMenus;
457 /** @} */
458
459 /** @name Selection stuff.
460 * @{ */
461 /** Holds the current-item reference. */
462 QPointer<UIChooserItem> m_pCurrentItem;
463
464 /** Holds whether selection save allowed. */
465 bool m_fSelectionSaveAllowed;
466 /** @} */
467
468 /** @name Search stuff.
469 * @{ */
470 /** Stores the index (within the m_searchResults) of the currently selected found item. */
471 int m_iCurrentSearchResultIndex;
472 /** @} */
473
474 /** @name Children stuff.
475 * @{ */
476 /** Holds the root instance. */
477 QPointer<UIChooserItem> m_pRoot;
478
479 /** Holds the navigation-items. */
480 QList<UIChooserItem*> m_navigationItems;
481 /** Holds the selected-items. */
482 QList<UIChooserItem*> m_selectedItems;
483
484 /** Holds the current drag object instance. */
485 QPointer<QDrag> m_pCurrentDragObject;
486 /** Holds the drag scrolling token size. */
487 int m_iScrollingTokenSize;
488 /** Holds whether drag scrolling is in progress. */
489 bool m_fIsScrollingInProgress;
490
491 /** Holds the global item height hint. */
492 int m_iGlobalItemHeightHint;
493 /** @} */
494
495 /** @name Cloud stuff.
496 * @{ */
497 /** Holds cloud profile update timer instance. */
498 QTimer *m_pTimerCloudProfileUpdate;
499 /** @} */
500};
501
502#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserModel_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette