[48270] | 1 | /* $Id: UIProgressTaskReadCloudMachineList.cpp 99187 2023-03-27 15:11:13Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[86795] | 3 | * VBox Qt GUI - UIProgressTaskReadCloudMachineList class implementation.
|
---|
[48270] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2020-2023 Oracle and/or its affiliates.
|
---|
[48270] | 8 | *
|
---|
[96407] | 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
|
---|
[48270] | 26 | */
|
---|
| 27 |
|
---|
| 28 | /* GUI includes: */
|
---|
[83111] | 29 | #include "UICloudNetworkingStuff.h"
|
---|
[86910] | 30 | #include "UIErrorString.h"
|
---|
[86795] | 31 | #include "UIProgressTaskReadCloudMachineList.h"
|
---|
[48270] | 32 |
|
---|
[83008] | 33 |
|
---|
[86795] | 34 | UIProgressTaskReadCloudMachineList::UIProgressTaskReadCloudMachineList(QObject *pParent,
|
---|
| 35 | const UICloudEntityKey &guiCloudProfileKey,
|
---|
| 36 | bool fWithRefresh)
|
---|
| 37 | : UIProgressTask(pParent)
|
---|
| 38 | , m_guiCloudProfileKey(guiCloudProfileKey)
|
---|
[86609] | 39 | , m_fWithRefresh(fWithRefresh)
|
---|
[48270] | 40 | {
|
---|
| 41 | }
|
---|
[83008] | 42 |
|
---|
[86795] | 43 | UICloudEntityKey UIProgressTaskReadCloudMachineList::cloudProfileKey() const
|
---|
[83008] | 44 | {
|
---|
[86795] | 45 | return m_guiCloudProfileKey;
|
---|
[83008] | 46 | }
|
---|
| 47 |
|
---|
[86795] | 48 | QVector<CCloudMachine> UIProgressTaskReadCloudMachineList::machines() const
|
---|
[83008] | 49 | {
|
---|
[86795] | 50 | return m_machines;
|
---|
[83008] | 51 | }
|
---|
| 52 |
|
---|
[86910] | 53 | QString UIProgressTaskReadCloudMachineList::errorMessage() const
|
---|
| 54 | {
|
---|
| 55 | return m_strErrorMessage;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[86795] | 58 | CProgress UIProgressTaskReadCloudMachineList::createProgress()
|
---|
[83008] | 59 | {
|
---|
[86795] | 60 | /* Create cloud client: */
|
---|
| 61 | m_comCloudClient = cloudClientByName(m_guiCloudProfileKey.m_strProviderShortName,
|
---|
[86910] | 62 | m_guiCloudProfileKey.m_strProfileName,
|
---|
| 63 | m_strErrorMessage);
|
---|
| 64 | if (m_comCloudClient.isNull())
|
---|
| 65 | return CProgress();
|
---|
[86795] | 66 |
|
---|
[86910] | 67 | /* Initialize progress-wrapper: */
|
---|
| 68 | CProgress comProgress = m_fWithRefresh
|
---|
| 69 | ? m_comCloudClient.ReadCloudMachineList()
|
---|
| 70 | : m_comCloudClient.ReadCloudMachineStubList();
|
---|
| 71 | if (!m_comCloudClient.isOk())
|
---|
[86795] | 72 | {
|
---|
[86910] | 73 | m_strErrorMessage = UIErrorString::formatErrorInfo(m_comCloudClient);
|
---|
| 74 | return CProgress();
|
---|
[86795] | 75 | }
|
---|
| 76 |
|
---|
[86910] | 77 | /* Return progress-wrapper: */
|
---|
| 78 | return comProgress;
|
---|
[83008] | 79 | }
|
---|
[86795] | 80 |
|
---|
| 81 | void UIProgressTaskReadCloudMachineList::handleProgressFinished(CProgress &comProgress)
|
---|
| 82 | {
|
---|
[99187] | 83 | /* Check if we already have error-mesage: */
|
---|
| 84 | if (!m_strErrorMessage.isEmpty())
|
---|
| 85 | return;
|
---|
| 86 |
|
---|
[86795] | 87 | /* Handle progress-wrapper errors: */
|
---|
[99186] | 88 | if (comProgress.isNotNull() && !comProgress.GetCanceled() && (!comProgress.isOk() || comProgress.GetResultCode() != 0))
|
---|
[86795] | 89 | {
|
---|
[86910] | 90 | m_strErrorMessage = UIErrorString::formatErrorInfo(comProgress);
|
---|
| 91 | return;
|
---|
[86795] | 92 | }
|
---|
[86910] | 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);
|
---|
[86795] | 100 | }
|
---|