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