1 | /** @file
|
---|
2 | * VBox Qt GUI - UISettingsSerializer class declaration.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2015 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ___UISettingsSerializer_h___
|
---|
18 | #define ___UISettingsSerializer_h___
|
---|
19 |
|
---|
20 | /* Qt includes: */
|
---|
21 | #include <QThread>
|
---|
22 | #include <QVariant>
|
---|
23 | #include <QWaitCondition>
|
---|
24 | #include <QProgressDialog>
|
---|
25 | #include <QMutex>
|
---|
26 | #include <QList>
|
---|
27 | #include <QMap>
|
---|
28 |
|
---|
29 | /* GUI includes: */
|
---|
30 | #include "QIWithRetranslateUI.h"
|
---|
31 |
|
---|
32 | /* Forward declarations: */
|
---|
33 | class UISettingsPage;
|
---|
34 |
|
---|
35 | /* Type definitions: */
|
---|
36 | typedef QList<UISettingsPage*> UISettingsPageList;
|
---|
37 | typedef QMap<int, UISettingsPage*> UISettingsPageMap;
|
---|
38 |
|
---|
39 | /** QThread reimplementation used for
|
---|
40 | * loading/saving settings in async mode. */
|
---|
41 | class UISettingsSerializer : public QThread
|
---|
42 | {
|
---|
43 | Q_OBJECT;
|
---|
44 |
|
---|
45 | signals:
|
---|
46 |
|
---|
47 | /** Notifies GUI thread about process has been started. */
|
---|
48 | void sigNotifyAboutProcessStarted();
|
---|
49 |
|
---|
50 | /** Notifies GUI thread about some page was processed. */
|
---|
51 | void sigNotifyAboutPageProcessed(int iPageId);
|
---|
52 | /** Notifies GUI thread about all pages were processed. */
|
---|
53 | void sigNotifyAboutPagesProcessed();
|
---|
54 |
|
---|
55 | /** Notifies listeners about some page was post-processed. */
|
---|
56 | void sigNotifyAboutPagePostprocessed(int iPageId);
|
---|
57 | /** Notifies listeners about all pages were post-processed. */
|
---|
58 | void sigNotifyAboutPagesPostprocessed();
|
---|
59 |
|
---|
60 | /** Notifies listeners about process has been finished. */
|
---|
61 | void sigNotifyAboutProcessFinished();
|
---|
62 |
|
---|
63 | public:
|
---|
64 |
|
---|
65 | /** Serialization directions. */
|
---|
66 | enum SerializationDirection { Load, Save };
|
---|
67 |
|
---|
68 | /** Constructor.
|
---|
69 | * @param pParent being passed to the base-class,
|
---|
70 | * @param direction determines the load/save direction,
|
---|
71 | * @param data contains the wrapper(s) to load/save the data from/to,
|
---|
72 | * @param pages contains the page(s) to load/save the data to/from. */
|
---|
73 | UISettingsSerializer(QObject *pParent, SerializationDirection direction,
|
---|
74 | const QVariant &data, const UISettingsPageList &pages);
|
---|
75 |
|
---|
76 | /** Destructor. */
|
---|
77 | ~UISettingsSerializer();
|
---|
78 |
|
---|
79 | /** Returns the load/save direction. */
|
---|
80 | SerializationDirection direction() const { return m_direction; }
|
---|
81 |
|
---|
82 | /** Returns the instance of wrapper(s) to load/save the data from/to. */
|
---|
83 | QVariant& data() { return m_data; }
|
---|
84 |
|
---|
85 | /** Returns the count of the page(s) to load/save the data to/from. */
|
---|
86 | int pageCount() const { return m_pages.size(); }
|
---|
87 |
|
---|
88 | /** Raises the priority of page with @a iPageId. */
|
---|
89 | void raisePriorityOfPage(int iPageId);
|
---|
90 |
|
---|
91 | public slots:
|
---|
92 |
|
---|
93 | /** Starts the process of data loading with passed @a priority. */
|
---|
94 | void start(Priority priority = InheritPriority);
|
---|
95 |
|
---|
96 | protected slots:
|
---|
97 |
|
---|
98 | /** Handles the fact of page with @a iPageId was processed. */
|
---|
99 | void sltHandleProcessedPage(int iPageId);
|
---|
100 |
|
---|
101 | /** Handles the fact of all pages were processed. */
|
---|
102 | void sltHandleProcessedPages();
|
---|
103 |
|
---|
104 | protected:
|
---|
105 |
|
---|
106 | /** Worker-thread serialization rutine. */
|
---|
107 | void run();
|
---|
108 |
|
---|
109 | /** Holds the load/save direction. */
|
---|
110 | const SerializationDirection m_direction;
|
---|
111 |
|
---|
112 | /** Holds the wrapper(s) to load/save the data from/to. */
|
---|
113 | QVariant m_data;
|
---|
114 | /** Holds the page(s) to load/save the data to/from. */
|
---|
115 | UISettingsPageMap m_pages;
|
---|
116 |
|
---|
117 | /** Holds whether the save was complete. */
|
---|
118 | bool m_fSavingComplete;
|
---|
119 | /** Holds the ID of the high priority page. */
|
---|
120 | int m_iIdOfHighPriorityPage;
|
---|
121 | /** Holds the synchronization mutex. */
|
---|
122 | QMutex m_mutex;
|
---|
123 | /** Holds the synchronization condition. */
|
---|
124 | QWaitCondition m_condition;
|
---|
125 | };
|
---|
126 |
|
---|
127 | /** QProgressDialog reimplementation used to
|
---|
128 | * reflect the settings serialization operation. */
|
---|
129 | class UISettingsSerializerProgress : public QIWithRetranslateUI<QProgressDialog>
|
---|
130 | {
|
---|
131 | Q_OBJECT;
|
---|
132 |
|
---|
133 | public:
|
---|
134 |
|
---|
135 | /** Constructor.
|
---|
136 | * @param pParent being passed to the base-class,
|
---|
137 | * @param direction determines the load/save direction,
|
---|
138 | * @param data contains the wrapper(s) to load/save the data from/to,
|
---|
139 | * @param pages contains the page(s) to load/save the data to/from. */
|
---|
140 | UISettingsSerializerProgress(QWidget *pParent, UISettingsSerializer::SerializationDirection direction,
|
---|
141 | const QVariant &data, const UISettingsPageList &pages);
|
---|
142 |
|
---|
143 | /** Executes the dialog. */
|
---|
144 | int exec();
|
---|
145 |
|
---|
146 | /** Returns the instance of wrapper(s) to load/save the data from/to. */
|
---|
147 | QVariant& data();
|
---|
148 |
|
---|
149 | protected:
|
---|
150 |
|
---|
151 | /** Prepare routine. */
|
---|
152 | void prepare();
|
---|
153 |
|
---|
154 | /** Translate routine: */
|
---|
155 | void retranslateUi();
|
---|
156 |
|
---|
157 | private slots:
|
---|
158 |
|
---|
159 | /** Advances the current progress value. */
|
---|
160 | void sltAdvanceProgressValue() { setValue(value() + 1); }
|
---|
161 |
|
---|
162 | private:
|
---|
163 |
|
---|
164 | /** Holds the load/save direction. */
|
---|
165 | const UISettingsSerializer::SerializationDirection m_direction;
|
---|
166 |
|
---|
167 | /** Holds the wrapper(s) to load/save the data from/to. */
|
---|
168 | QVariant m_data;
|
---|
169 | /** Holds the page(s) to load/save the data to/from. */
|
---|
170 | UISettingsPageList m_pages;
|
---|
171 |
|
---|
172 | /** Holds the pointer to the thread loading/saving settings in async mode. */
|
---|
173 | UISettingsSerializer *m_pSerializer;
|
---|
174 | };
|
---|
175 |
|
---|
176 | #endif /* !___UISettingsSerializer_h___ */
|
---|