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 <QMutex>
|
---|
25 | #include <QList>
|
---|
26 | #include <QMap>
|
---|
27 |
|
---|
28 | /* Forward declarations: */
|
---|
29 | class UISettingsPage;
|
---|
30 |
|
---|
31 | /* Type definitions: */
|
---|
32 | typedef QList<UISettingsPage*> UISettingsPageList;
|
---|
33 | typedef QMap<int, UISettingsPage*> UISettingsPageMap;
|
---|
34 |
|
---|
35 | /** QThread reimplementation used for
|
---|
36 | * loading/saving settings in async mode. */
|
---|
37 | class UISettingsSerializer : public QThread
|
---|
38 | {
|
---|
39 | Q_OBJECT;
|
---|
40 |
|
---|
41 | signals:
|
---|
42 |
|
---|
43 | /** Notifies GUI thread about process has been started. */
|
---|
44 | void sigNotifyAboutProcessStarted();
|
---|
45 |
|
---|
46 | /** Notifies GUI thread about some page was processed. */
|
---|
47 | void sigNotifyAboutPageProcessed(int iPageId);
|
---|
48 |
|
---|
49 | /** Notifies GUI thread about all pages were processed. */
|
---|
50 | void sigNotifyAboutPagesProcessed();
|
---|
51 |
|
---|
52 | public:
|
---|
53 |
|
---|
54 | /** Serialization directions. */
|
---|
55 | enum SerializationDirection { Load, Save };
|
---|
56 |
|
---|
57 | /** Returns the singleton instance. */
|
---|
58 | static UISettingsSerializer* instance() { return m_spInstance; }
|
---|
59 |
|
---|
60 | /** Constructor.
|
---|
61 | * @param pParent being passed to the base-class,
|
---|
62 | * @param direction determines the load/save direction,
|
---|
63 | * @param data contains the wrapper(s) to load/save the data from/to,
|
---|
64 | * @param pages contains the page(s) to load/save the data to/from. */
|
---|
65 | UISettingsSerializer(QObject *pParent, SerializationDirection direction,
|
---|
66 | const QVariant &data, const UISettingsPageList &pages);
|
---|
67 |
|
---|
68 | /** Destructor. */
|
---|
69 | ~UISettingsSerializer();
|
---|
70 |
|
---|
71 | /** Returns the instance of wrapper(s) to load/save the data from/to. */
|
---|
72 | QVariant& data() { return m_data; }
|
---|
73 |
|
---|
74 | /** Raises the priority of page with @a iPageId. */
|
---|
75 | void raisePriorityOfPage(int iPageId);
|
---|
76 |
|
---|
77 | public slots:
|
---|
78 |
|
---|
79 | /** Starts the process of data loading with passed @a priority. */
|
---|
80 | void start(Priority priority = InheritPriority);
|
---|
81 |
|
---|
82 | protected slots:
|
---|
83 |
|
---|
84 | /** Handles the fact of page with @a iPageId was processed. */
|
---|
85 | void sltHandleProcessedPage(int iPageId);
|
---|
86 |
|
---|
87 | /** Handles the fact of all pages were processed. */
|
---|
88 | void sltHandleProcessedPages();
|
---|
89 |
|
---|
90 | /** Killing serializer, softly :) */
|
---|
91 | void sltDestroySerializer();
|
---|
92 |
|
---|
93 | protected:
|
---|
94 |
|
---|
95 | /** Worker-thread serialization rutine. */
|
---|
96 | void run();
|
---|
97 |
|
---|
98 | /** Holds the singleton instance. */
|
---|
99 | static UISettingsSerializer *m_spInstance;
|
---|
100 |
|
---|
101 | /** Holds the the load/save direction. */
|
---|
102 | SerializationDirection m_direction;
|
---|
103 |
|
---|
104 | /** Holds the wrapper(s) to load/save the data from/to. */
|
---|
105 | QVariant m_data;
|
---|
106 | /** Holds the page(s) to load/save the data to/from. */
|
---|
107 | UISettingsPageMap m_pages;
|
---|
108 |
|
---|
109 | /** Holds whether the save was complete. */
|
---|
110 | bool m_fSavingComplete;
|
---|
111 | /** Holds whether it is allowed to destroy the serializer. */
|
---|
112 | bool m_fAllowToDestroySerializer;
|
---|
113 | /** Holds the ID of the high priority page. */
|
---|
114 | int m_iIdOfHighPriorityPage;
|
---|
115 | /** Holds the synchronization mutex. */
|
---|
116 | QMutex m_mutex;
|
---|
117 | /** Holds the synchronization condition. */
|
---|
118 | QWaitCondition m_condition;
|
---|
119 | };
|
---|
120 |
|
---|
121 | #endif /* !___UISettingsSerializer_h___ */
|
---|