VirtualBox

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

Last change on this file since 69498 was 69498, checked in by vboxsync, 7 years ago

backed out r118835 as it incorrectly updated the 'This file is based on' file headers.

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