1 | /* $Id: UIProgressEventHandler.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIProgressEventHandler class implementation.
|
---|
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 | /* GUI includes: */
|
---|
29 | #include "UIExtraDataManager.h"
|
---|
30 | #include "UIMainEventListener.h"
|
---|
31 | #include "UIProgressEventHandler.h"
|
---|
32 | #include "UICommon.h"
|
---|
33 | #ifdef VBOX_WS_MAC
|
---|
34 | # include "VBoxUtils-darwin.h"
|
---|
35 | #endif /* VBOX_WS_MAC */
|
---|
36 |
|
---|
37 | UIProgressEventHandler::UIProgressEventHandler(QObject *pParent, const CProgress &comProgress)
|
---|
38 | : QObject(pParent)
|
---|
39 | , m_comProgress(comProgress)
|
---|
40 | {
|
---|
41 | /* Prepare: */
|
---|
42 | prepare();
|
---|
43 | }
|
---|
44 |
|
---|
45 | UIProgressEventHandler::~UIProgressEventHandler()
|
---|
46 | {
|
---|
47 | /* Cleanup: */
|
---|
48 | cleanup();
|
---|
49 | }
|
---|
50 |
|
---|
51 | void UIProgressEventHandler::prepare()
|
---|
52 | {
|
---|
53 | /* Prepare: */
|
---|
54 | prepareListener();
|
---|
55 | prepareConnections();
|
---|
56 | }
|
---|
57 |
|
---|
58 | void UIProgressEventHandler::prepareListener()
|
---|
59 | {
|
---|
60 | /* Create event listener instance: */
|
---|
61 | m_pQtListener.createObject();
|
---|
62 | m_pQtListener->init(new UIMainEventListener, this);
|
---|
63 | m_comEventListener = CEventListener(m_pQtListener);
|
---|
64 |
|
---|
65 | /* Get CProgress event source: */
|
---|
66 | CEventSource comEventSourceProgress = m_comProgress.GetEventSource();
|
---|
67 | AssertWrapperOk(comEventSourceProgress);
|
---|
68 |
|
---|
69 | /* Enumerate all the required event-types: */
|
---|
70 | QVector<KVBoxEventType> eventTypes;
|
---|
71 | eventTypes
|
---|
72 | << KVBoxEventType_OnProgressPercentageChanged
|
---|
73 | << KVBoxEventType_OnProgressTaskCompleted;
|
---|
74 |
|
---|
75 | /* Register event listener for CProgress event source: */
|
---|
76 | comEventSourceProgress.RegisterListener(m_comEventListener, eventTypes, FALSE /* active? */);
|
---|
77 | AssertWrapperOk(comEventSourceProgress);
|
---|
78 |
|
---|
79 | /* Register event sources in their listeners as well: */
|
---|
80 | m_pQtListener->getWrapped()->registerSource(comEventSourceProgress,
|
---|
81 | m_comEventListener,
|
---|
82 | QSet<KVBoxEventType>() << KVBoxEventType_OnProgressTaskCompleted);
|
---|
83 | }
|
---|
84 |
|
---|
85 | void UIProgressEventHandler::prepareConnections()
|
---|
86 | {
|
---|
87 | /* Create direct (sync) connections for signals of main listener: */
|
---|
88 | connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigListeningFinished,
|
---|
89 | this, &UIProgressEventHandler::sigHandlingFinished,
|
---|
90 | Qt::DirectConnection);
|
---|
91 | connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigProgressPercentageChange,
|
---|
92 | this, &UIProgressEventHandler::sigProgressPercentageChange,
|
---|
93 | Qt::DirectConnection);
|
---|
94 | connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigProgressTaskComplete,
|
---|
95 | this, &UIProgressEventHandler::sigProgressTaskComplete,
|
---|
96 | Qt::DirectConnection);
|
---|
97 | }
|
---|
98 |
|
---|
99 | void UIProgressEventHandler::cleanupConnections()
|
---|
100 | {
|
---|
101 | /* Nothing for now. */
|
---|
102 | }
|
---|
103 |
|
---|
104 | void UIProgressEventHandler::cleanupListener()
|
---|
105 | {
|
---|
106 | /* Unregister everything: */
|
---|
107 | m_pQtListener->getWrapped()->unregisterSources();
|
---|
108 |
|
---|
109 | /* Make sure VBoxSVC is available: */
|
---|
110 | if (!uiCommon().isVBoxSVCAvailable())
|
---|
111 | return;
|
---|
112 |
|
---|
113 | /* Get CProgress event source: */
|
---|
114 | CEventSource comEventSourceProgress = m_comProgress.GetEventSource();
|
---|
115 | AssertWrapperOk(comEventSourceProgress);
|
---|
116 |
|
---|
117 | /* Unregister event listener for CProgress event source: */
|
---|
118 | comEventSourceProgress.UnregisterListener(m_comEventListener);
|
---|
119 | }
|
---|
120 |
|
---|
121 | void UIProgressEventHandler::cleanup()
|
---|
122 | {
|
---|
123 | /* Cleanup: */
|
---|
124 | cleanupConnections();
|
---|
125 | cleanupListener();
|
---|
126 | }
|
---|