VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h@ 83671

Last change on this file since 83671 was 83671, checked in by vboxsync, 5 years ago

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: A bit of cleanup for r137126.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: UIChooserAbstractModel.h 83671 2020-04-10 15:29:33Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIChooserAbstractModel class declaration.
4 */
5
6/*
7 * Copyright (C) 2012-2020 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#ifndef FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h
19#define FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/* Qt includes: */
25#include <QThread>
26
27/* GUI includes: */
28#include "UIChooserDefs.h"
29
30/* COM includes: */
31#include "COMEnums.h"
32
33/* Forward declaration: */
34class QUuid;
35class UIChooser;
36class UIChooserNode;
37class CMachine;
38#ifdef VBOX_GUI_WITH_CLOUD_VMS
39class UITask;
40#endif
41
42
43/** QObject extension used as VM Chooser-pane abstract model.
44 * This class is used to load/save a tree of abstract invisible
45 * nodes representing VMs and their groups from/to extra-data. */
46class UIChooserAbstractModel : public QObject
47{
48 Q_OBJECT;
49
50signals:
51
52 /** @name Cloud machine stuff.
53 * @{ */
54 /** Notifies about state change for cloud machine with certain @a uId. */
55 void sigCloudMachineStateChange(const QUuid &uId);
56 /** @} */
57
58 /** @name Group saving stuff.
59 * @{ */
60 /** Commands to start group saving. */
61 void sigStartGroupSaving();
62 /** Notifies about group saving state changed. */
63 void sigGroupSavingStateChanged();
64 /** @} */
65
66public:
67
68 /** Constructs abstract Chooser-model passing @a pParent to the base-class. */
69 UIChooserAbstractModel(UIChooser *pParent);
70
71 /** @name General stuff.
72 * @{ */
73 /** Inits model. */
74 virtual void init();
75 /** Deinits model. */
76 virtual void deinit();
77 /** @} */
78
79 /** @name Children stuff.
80 * @{ */
81 /** Returns invisible root node instance. */
82 UIChooserNode *invisibleRoot() const;
83
84 /** Wipes out empty groups. */
85 void wipeOutEmptyGroups();
86
87 /** Generates unique group name traversing recursively starting from @a pRoot. */
88 static QString uniqueGroupName(UIChooserNode *pRoot);
89 /** @} */
90
91 /** @name Search stuff.
92 * @{ */
93 /** Performs a search starting from the m_pInvisibleRootNode. */
94 virtual void performSearch(const QString &strSearchTerm, int iItemSearchFlags);
95 /** Cleans the search result data members and disables item's visual effects.
96 * Also returns a list of all nodes which may be utilized by the calling code. */
97 virtual QList<UIChooserNode*> resetSearch();
98 /** Returns search result. */
99 QList<UIChooserNode*> searchResult() const;
100 /** @} */
101
102 /** @name Group saving stuff.
103 * @{ */
104 /** Commands to save group settings. */
105 void saveGroupSettings();
106 /** Returns whether group saving is in progress. */
107 bool isGroupSavingInProgress() const;
108 /** @} */
109
110public slots:
111
112 /** @name Cloud machine stuff.
113 * @{ */
114 /** Handles cloud machine state change. */
115 void sltHandleCloudMachineStateChange();
116 /** @} */
117
118 /** @name Group saving stuff.
119 * @{ */
120 /** Handles group definition saving complete. */
121 void sltGroupDefinitionsSaveComplete();
122 /** Handles group order saving complete. */
123 void sltGroupOrdersSaveComplete();
124 /** @} */
125
126protected slots:
127
128 /** @name Main event handling stuff.
129 * @{ */
130 /** Handles machine @a enmState change for machine with certain @a uMachineId. */
131 virtual void sltMachineStateChanged(const QUuid &uMachineId, const KMachineState enmState);
132 /** Handles machine data change for machine with certain @a uMachineId. */
133 virtual void sltMachineDataChanged(const QUuid &uMachineId);
134 /** Handles machine registering/unregistering for machine with certain @a uMachineId. */
135 virtual void sltMachineRegistered(const QUuid &uMachineId, const bool fRegistered);
136 /** Handles session @a enmState change for machine with certain @a uMachineId. */
137 virtual void sltSessionStateChanged(const QUuid &uMachineId, const KSessionState enmState);
138 /** Handles snapshot change for machine/snapshot with certain @a uMachineId / @a uSnapshotId. */
139 virtual void sltSnapshotChanged(const QUuid &uMachineId, const QUuid &uSnapshotId);
140 /** @} */
141
142 /** @name Children stuff.
143 * @{ */
144 /** Handles reload machine with certain @a uMachineId request. */
145 virtual void sltReloadMachine(const QUuid &uMachineId);
146 /** @} */
147
148#ifdef VBOX_GUI_WITH_CLOUD_VMS
149 /** @name Cloud stuff.
150 * @{ */
151 /** Handles list cloud machines task complete signal. */
152 virtual void sltHandleCloudListMachinesTaskComplete(UITask *pTask);
153 /** @} */
154#endif /* VBOX_GUI_WITH_CLOUD_VMS */
155
156private slots:
157
158 /** @name Group saving stuff.
159 * @{ */
160 /** Handles request to start group saving. */
161 void sltStartGroupSaving();
162 /** @} */
163
164private:
165
166 /** @name Prepare/Cleanup cascade.
167 * @{ */
168 /** Prepares all. */
169 void prepare();
170 /** Prepares connections. */
171 void prepareConnections();
172 /** @} */
173
174 /** @name Children stuff.
175 * @{ */
176 /** Loads tree. */
177 void loadTree();
178 /** Adds machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
179 void addMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
180 /** Acquires group node, creates one if necessary.
181 * @param strName Brings the name of group we looking for.
182 * @param pParentNode Brings the parent we starting to look for a group from.
183 * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
184 UIChooserNode *getGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
185 /** Returns whether group node with certain @a strName should be opened, searching starting from the passed @a pParentItem. */
186 bool shouldGroupNodeBeOpened(UIChooserNode *pParentNode, const QString &strName);
187
188 /** Wipes out empty groups starting from @a pParentItem. */
189 void wipeOutEmptyGroupsStartingFrom(UIChooserNode *pParentNode);
190
191 /** Returns whether global node within the @a pParentNode is favorite. */
192 bool isGlobalNodeFavorite(UIChooserNode *pParentNode) const;
193
194 /** Acquires desired position for a child of @a pParentNode with specified @a enmType and @a strName. */
195 int getDesiredNodePosition(UIChooserNode *pParentNode, UIChooserItemType enmType, const QString &strName);
196 /** Acquires defined position for a child of @a pParentNode with specified @a enmType and @a strName. */
197 int getDefinedNodePosition(UIChooserNode *pParentNode, UIChooserItemType enmType, const QString &strName);
198
199 /** Creates machine node based on certain @a comMachine as a child of specified @a pParentNode. */
200 void createMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine);
201 /** @} */
202
203 /** @name Group saving stuff.
204 * @{ */
205 /** Saves group definitions. */
206 void saveGroupDefinitions();
207 /** Saves group orders. */
208 void saveGroupOrders();
209
210 /** Gathers group @a definitions of @a pParentGroup. */
211 void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserNode *pParentGroup);
212 /** Gathers group @a orders of @a pParentGroup. */
213 void gatherGroupOrders(QMap<QString, QStringList> &orders, UIChooserNode *pParentGroup);
214
215 /** Makes sure group definitions saving is finished. */
216 void makeSureGroupDefinitionsSaveIsFinished();
217 /** Makes sure group orders saving is finished. */
218 void makeSureGroupOrdersSaveIsFinished();
219
220 /** Returns QString representation for passed @a uId, wiping out {} symbols.
221 * @note Required for backward compatibility after QString=>QUuid change. */
222 static QString toOldStyleUuid(const QUuid &uId);
223 /** @} */
224
225 /** @name General stuff.
226 * @{ */
227 /** Holds the parent widget reference. */
228 UIChooser *m_pParent;
229 /** @} */
230
231 /** @name Children stuff.
232 * @{ */
233 /** Holds the invisible root node instance. */
234 UIChooserNode *m_pInvisibleRootNode;
235 /** @} */
236
237 /** @name Search stuff.
238 * @{ */
239 /** Stores the results of the current search. */
240 QList<UIChooserNode*> m_searchResults;
241 /** @} */
242
243 /** @name Group saving stuff.
244 * @{ */
245 /** Holds the consolidated map of group definitions/orders. */
246 QMap<QString, QStringList> m_groups;
247 /** @} */
248};
249
250
251/** QThread subclass allowing to save group definitions asynchronously. */
252class UIThreadGroupDefinitionSave : public QThread
253{
254 Q_OBJECT;
255
256signals:
257
258 /** Notifies about machine with certain @a uMachineId to be reloaded. */
259 void sigReload(const QUuid &uMachineId);
260
261 /** Notifies about task is complete. */
262 void sigComplete();
263
264public:
265
266 /** Returns group saving thread instance. */
267 static UIThreadGroupDefinitionSave* instance();
268 /** Prepares group saving thread instance. */
269 static void prepare();
270 /** Cleanups group saving thread instance. */
271 static void cleanup();
272
273 /** Configures @a groups saving thread with corresponding @a pListener.
274 * @param oldLists Brings the old definition list to be compared.
275 * @param newLists Brings the new definition list to be saved. */
276 void configure(QObject *pParent,
277 const QMap<QString, QStringList> &oldLists,
278 const QMap<QString, QStringList> &newLists);
279
280protected:
281
282 /** Constructs group saving thread. */
283 UIThreadGroupDefinitionSave();
284 /** Destructs group saving thread. */
285 virtual ~UIThreadGroupDefinitionSave() /* override */;
286
287 /** Contains a thread task to be executed. */
288 void run();
289
290 /** Holds the singleton instance. */
291 static UIThreadGroupDefinitionSave *s_pInstance;
292
293 /** Holds the map of group definitions to be compared. */
294 QMap<QString, QStringList> m_oldLists;
295 /** Holds the map of group definitions to be saved. */
296 QMap<QString, QStringList> m_newLists;
297};
298
299
300/** QThread subclass allowing to save group order asynchronously. */
301class UIThreadGroupOrderSave : public QThread
302{
303 Q_OBJECT;
304
305signals:
306
307 /** Notifies about task is complete. */
308 void sigComplete();
309
310public:
311
312 /** Returns group saving thread instance. */
313 static UIThreadGroupOrderSave *instance();
314 /** Prepares group saving thread instance. */
315 static void prepare();
316 /** Cleanups group saving thread instance. */
317 static void cleanup();
318
319 /** Configures group saving thread with corresponding @a pListener.
320 * @param groups Brings the groups to be saved. */
321 void configure(QObject *pListener,
322 const QMap<QString, QStringList> &groups);
323
324protected:
325
326 /** Constructs group saving thread. */
327 UIThreadGroupOrderSave();
328 /** Destructs group saving thread. */
329 virtual ~UIThreadGroupOrderSave() /* override */;
330
331 /** Contains a thread task to be executed. */
332 virtual void run() /* override */;
333
334 /** Holds the singleton instance. */
335 static UIThreadGroupOrderSave *s_pInstance;
336
337 /** Holds the map of groups to be saved. */
338 QMap<QString, QStringList> m_groups;
339};
340
341
342#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h */
Note: See TracBrowser for help on using the repository browser.

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