VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSerializer.h@ 103977

Last change on this file since 103977 was 103977, checked in by vboxsync, 9 months ago

Apply RT_OVERRIDE/NS_OVERRIDE where required to shut up clang.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/* $Id: UISettingsSerializer.h 103977 2024-03-21 02:04:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UISettingsSerializer class declaration.
4 */
5
6/*
7 * Copyright (C) 2006-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#ifndef FEQT_INCLUDED_SRC_settings_UISettingsSerializer_h
29#define FEQT_INCLUDED_SRC_settings_UISettingsSerializer_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QList>
36#include <QMap>
37#include <QMutex>
38#include <QThread>
39#include <QVariant>
40#include <QWaitCondition>
41
42/* GUI includes: */
43#include "QIDialog.h"
44#include "QIWithRetranslateUI.h"
45
46/* Forward declarations: */
47class QCloseEvent;
48class QLabel;
49class QMutex;
50class QObject;
51class QString;
52class QThread;
53class QProgressBar;
54class QVariant;
55class QWaitCondition;
56class QWidget;
57class QILabel;
58class UISettingsPage;
59
60/* Type definitions: */
61typedef QList<UISettingsPage*> UISettingsPageList;
62typedef QMap<int, UISettingsPage*> UISettingsPageMap;
63
64
65/** QThread reimplementation used for
66 * loading/saving settings in async mode. */
67class SHARED_LIBRARY_STUFF UISettingsSerializer : public QThread
68{
69 Q_OBJECT;
70
71signals:
72
73 /** Notifies listeners about process has been started. */
74 void sigNotifyAboutProcessStarted();
75 /** Notifies listeners about process reached @a iValue. */
76 void sigNotifyAboutProcessProgressChanged(int iValue);
77 /** Notifies listeners about process has been finished. */
78 void sigNotifyAboutProcessFinished();
79
80 /** Notifies GUI thread about some page was processed. */
81 void sigNotifyAboutPageProcessed(int iPageId);
82 /** Notifies GUI thread about all pages were processed. */
83 void sigNotifyAboutPagesProcessed();
84
85 /** Notifies listeners about particular operation progress change.
86 * @param iOperations Brings the number of operations CProgress have.
87 * @param strOperation Brings the description of the current CProgress operation.
88 * @param iOperation Brings the index of the current CProgress operation.
89 * @param iPercent Brings the percentage of the current CProgress operation. */
90 void sigOperationProgressChange(ulong iOperations, QString strOperation,
91 ulong iOperation, ulong iPercent);
92
93 /** Notifies listeners about particular COM error.
94 * @param strErrorInfo Brings the details of the error happened. */
95 void sigOperationProgressError(QString strErrorInfo);
96
97public:
98
99 /** Serialization directions. */
100 enum SerializationDirection { Load, Save };
101
102 /** Constructs serializer passing @a pParent to the base-class.
103 * @param enmDirection Brings the load/save direction.
104 * @param data Brings the wrapper(s) to load/save the data from/to.
105 * @param pages Brings the page(s) to load/save the data to/from. */
106 UISettingsSerializer(QObject *pParent, SerializationDirection enmDirection,
107 const QVariant &data, const UISettingsPageList &pages);
108
109 /** Destructs serializer. */
110 virtual ~UISettingsSerializer() RT_OVERRIDE;
111
112 /** Returns the load/save direction. */
113 SerializationDirection direction() const { return m_enmDirection; }
114
115 /** Returns the instance of wrapper(s) to load/save the data from/to. */
116 QVariant &data() { return m_data; }
117
118 /** Returns the count of the page(s) to load/save the data to/from. */
119 int pageCount() const { return m_pages.size(); }
120
121 /** Raises the priority of page with @a iPageId. */
122 void raisePriorityOfPage(int iPageId);
123
124public slots:
125
126 /** Starts the process of data loading with passed @a priority. */
127 void start(Priority priority = InheritPriority);
128
129protected slots:
130
131 /** Handles the fact of page with @a iPageId was processed. */
132 void sltHandleProcessedPage(int iPageId);
133
134 /** Handles the fact of all pages were processed. */
135 void sltHandleProcessedPages();
136
137protected:
138
139 /** Worker-thread serialization rutine. */
140 void run() RT_OVERRIDE;
141
142 /** Holds the load/save direction. */
143 const SerializationDirection m_enmDirection;
144
145 /** Holds the wrapper(s) to load/save the data from/to. */
146 QVariant m_data;
147 /** Holds the page(s) to load/save the data to/from. */
148 UISettingsPageMap m_pages;
149 /** Holds the page(s) to load/save the data to/from for which that task was done. */
150 UISettingsPageMap m_pagesDone;
151
152 /** Holds whether the save was complete. */
153 bool m_fSavingComplete;
154 /** Holds the ID of the high priority page. */
155 int m_iIdOfHighPriorityPage;
156 /** Holds the synchronization mutex. */
157 QMutex m_mutex;
158 /** Holds the synchronization condition. */
159 QWaitCondition m_condition;
160};
161
162
163/** QIDialog reimplementation used to
164 * reflect the settings serialization operation. */
165class SHARED_LIBRARY_STUFF UISettingsSerializerProgress : public QIWithRetranslateUI<QIDialog>
166{
167 Q_OBJECT;
168
169signals:
170
171 /** Asks itself for process start. */
172 void sigAskForProcessStart();
173
174public:
175
176 /** Constructs serializer passing @a pParent to the base-class.
177 * @param enmDirection Brings the load/save direction.
178 * @param data Brings the wrapper(s) to load/save the data from/to.
179 * @param pages Brings the page(s) to load/save the data to/from. */
180 UISettingsSerializerProgress(QWidget *pParent, UISettingsSerializer::SerializationDirection enmDirection,
181 const QVariant &data, const UISettingsPageList &pages);
182
183 /** Executes the dialog. */
184 int exec() RT_OVERRIDE;
185
186 /** Returns the instance of wrapper(s) to load/save the data from/to. */
187 QVariant &data();
188
189 /** Returns whether there were no errors. */
190 bool isClean() const { return m_fClean; }
191
192protected:
193
194 /** Prepare routine. */
195 void prepare();
196
197 /** Translate routine: */
198 virtual void retranslateUi() RT_OVERRIDE;
199
200 /** Close event-handler called with the given window system @a pEvent. */
201 virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;
202
203private slots:
204
205 /** Hides the modal dialog and sets the result code to <i>Rejected</i>. */
206 virtual void reject() RT_OVERRIDE;
207
208 /** Starts the process. */
209 void sltStartProcess();
210
211 /** Handles process progress change to @a iValue. */
212 void sltHandleProcessProgressChange(int iValue);
213
214 /** Handles particular operation progress change.
215 * @param iOperations Brings the number of operations CProgress have.
216 * @param strOperation Brings the description of the current CProgress operation.
217 * @param iOperation Brings the index of the current CProgress operation.
218 * @param iPercent Brings the percentage of the current CProgress operation. */
219 void sltHandleOperationProgressChange(ulong iOperations, QString strOperation,
220 ulong iOperation, ulong iPercent);
221
222 /** Handles particular COM error.
223 * @param strErrorInfo Brings the details of the error happened. */
224 void sltHandleOperationProgressError(QString strErrorInfo);
225
226private:
227
228 /** Holds the load/save direction. */
229 const UISettingsSerializer::SerializationDirection m_enmDirection;
230
231 /** Holds the wrapper(s) to load/save the data from/to. */
232 QVariant m_data;
233 /** Holds the page(s) to load/save the data to/from. */
234 UISettingsPageList m_pages;
235
236 /** Holds the pointer to the thread loading/saving settings in async mode. */
237 UISettingsSerializer *m_pSerializer;
238
239 /** Holds the operation progress label. */
240 QLabel *m_pLabelOperationProgress;
241 /** Holds the operation progress bar. */
242 QProgressBar *m_pBarOperationProgress;
243
244 /** Holds the sub-operation progress label. */
245 QILabel *m_pLabelSubOperationProgress;
246 /** Holds the sub-operation progress bar. */
247 QProgressBar *m_pBarSubOperationProgress;
248
249 /** Holds whether there were no errors. */
250 bool m_fClean;
251
252 /** Holds the template for the sub-operation progress label. */
253 static QString s_strProgressDescriptionTemplate;
254};
255
256
257#endif /* !FEQT_INCLUDED_SRC_settings_UISettingsSerializer_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