1 | /* $Id: UIProgressTaskReadCloudMachineList.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIProgressTaskReadCloudMachineList class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020-2024 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 "UICloudNetworkingStuff.h"
|
---|
30 | #include "UIErrorString.h"
|
---|
31 | #include "UIProgressTaskReadCloudMachineList.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | UIProgressTaskReadCloudMachineList::UIProgressTaskReadCloudMachineList(QObject *pParent,
|
---|
35 | const UICloudEntityKey &guiCloudProfileKey,
|
---|
36 | bool fWithRefresh)
|
---|
37 | : UIProgressTask(pParent)
|
---|
38 | , m_guiCloudProfileKey(guiCloudProfileKey)
|
---|
39 | , m_fWithRefresh(fWithRefresh)
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 | UICloudEntityKey UIProgressTaskReadCloudMachineList::cloudProfileKey() const
|
---|
44 | {
|
---|
45 | return m_guiCloudProfileKey;
|
---|
46 | }
|
---|
47 |
|
---|
48 | QVector<CCloudMachine> UIProgressTaskReadCloudMachineList::machines() const
|
---|
49 | {
|
---|
50 | return m_machines;
|
---|
51 | }
|
---|
52 |
|
---|
53 | QString UIProgressTaskReadCloudMachineList::errorMessage() const
|
---|
54 | {
|
---|
55 | return m_strErrorMessage;
|
---|
56 | }
|
---|
57 |
|
---|
58 | CProgress UIProgressTaskReadCloudMachineList::createProgress()
|
---|
59 | {
|
---|
60 | /* Create cloud client: */
|
---|
61 | m_comCloudClient = cloudClientByName(m_guiCloudProfileKey.m_strProviderShortName,
|
---|
62 | m_guiCloudProfileKey.m_strProfileName,
|
---|
63 | m_strErrorMessage);
|
---|
64 | if (m_comCloudClient.isNull())
|
---|
65 | return CProgress();
|
---|
66 |
|
---|
67 | /* Initialize progress-wrapper: */
|
---|
68 | CProgress comProgress = m_fWithRefresh
|
---|
69 | ? m_comCloudClient.ReadCloudMachineList()
|
---|
70 | : m_comCloudClient.ReadCloudMachineStubList();
|
---|
71 | if (!m_comCloudClient.isOk())
|
---|
72 | {
|
---|
73 | m_strErrorMessage = UIErrorString::formatErrorInfo(m_comCloudClient);
|
---|
74 | return CProgress();
|
---|
75 | }
|
---|
76 |
|
---|
77 | /* Return progress-wrapper: */
|
---|
78 | return comProgress;
|
---|
79 | }
|
---|
80 |
|
---|
81 | void UIProgressTaskReadCloudMachineList::handleProgressFinished(CProgress &comProgress)
|
---|
82 | {
|
---|
83 | /* Check if we already have error-mesage: */
|
---|
84 | if (!m_strErrorMessage.isEmpty())
|
---|
85 | return;
|
---|
86 |
|
---|
87 | /* Handle progress-wrapper errors: */
|
---|
88 | if (comProgress.isNotNull() && !comProgress.GetCanceled() && (!comProgress.isOk() || comProgress.GetResultCode() != 0))
|
---|
89 | {
|
---|
90 | m_strErrorMessage = UIErrorString::formatErrorInfo(comProgress);
|
---|
91 | return;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* Fill the result: */
|
---|
95 | m_machines = m_fWithRefresh
|
---|
96 | ? m_comCloudClient.GetCloudMachineList()
|
---|
97 | : m_comCloudClient.GetCloudMachineStubList();
|
---|
98 | if (!m_comCloudClient.isOk())
|
---|
99 | m_strErrorMessage = UIErrorString::formatErrorInfo(m_comCloudClient);
|
---|
100 | }
|
---|