VirtualBox

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

Last change on this file was 104313, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the settings related GUI classes.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use