VirtualBox

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

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

Copyright year updates by scm.

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