1 | /* $Id: UINotificationObject.cpp 90290 2021-07-22 14:40:08Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UINotificationObject class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2021 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* GUI includes: */
|
---|
19 | #include "UINotificationObject.h"
|
---|
20 | #include "UINotificationProgressTask.h"
|
---|
21 |
|
---|
22 |
|
---|
23 | /*********************************************************************************************************************************
|
---|
24 | * Class UINotificationObject implementation. *
|
---|
25 | *********************************************************************************************************************************/
|
---|
26 |
|
---|
27 | UINotificationObject::UINotificationObject()
|
---|
28 | {
|
---|
29 | }
|
---|
30 |
|
---|
31 | void UINotificationObject::close()
|
---|
32 | {
|
---|
33 | emit sigAboutToClose();
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 | /*********************************************************************************************************************************
|
---|
38 | * Class UINotificationProgress implementation. *
|
---|
39 | *********************************************************************************************************************************/
|
---|
40 |
|
---|
41 | UINotificationProgress::UINotificationProgress()
|
---|
42 | : m_pTask(0)
|
---|
43 | , m_uPercent(0)
|
---|
44 | {
|
---|
45 | }
|
---|
46 |
|
---|
47 | UINotificationProgress::~UINotificationProgress()
|
---|
48 | {
|
---|
49 | delete m_pTask;
|
---|
50 | m_pTask = 0;
|
---|
51 | }
|
---|
52 |
|
---|
53 | ulong UINotificationProgress::percent() const
|
---|
54 | {
|
---|
55 | return m_uPercent;
|
---|
56 | }
|
---|
57 |
|
---|
58 | bool UINotificationProgress::isCancelable() const
|
---|
59 | {
|
---|
60 | return m_pTask->isCancelable();
|
---|
61 | }
|
---|
62 |
|
---|
63 | QString UINotificationProgress::error() const
|
---|
64 | {
|
---|
65 | return m_pTask->errorMessage();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void UINotificationProgress::handle()
|
---|
69 | {
|
---|
70 | /* Prepare task: */
|
---|
71 | m_pTask = new UINotificationProgressTask(this);
|
---|
72 | if (m_pTask)
|
---|
73 | {
|
---|
74 | connect(m_pTask, &UIProgressTask::sigProgressStarted,
|
---|
75 | this, &UINotificationProgress::sigProgressStarted);
|
---|
76 | connect(m_pTask, &UIProgressTask::sigProgressChange,
|
---|
77 | this, &UINotificationProgress::sltHandleProgressChange);
|
---|
78 | connect(m_pTask, &UIProgressTask::sigProgressFinished,
|
---|
79 | this, &UINotificationProgress::sltHandleProgressFinished);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /* And start it finally: */
|
---|
83 | m_pTask->start();
|
---|
84 | }
|
---|
85 |
|
---|
86 | void UINotificationProgress::close()
|
---|
87 | {
|
---|
88 | /* Cancel task: */
|
---|
89 | m_pTask->cancel();
|
---|
90 | /* Call to base-class: */
|
---|
91 | UINotificationObject::close();
|
---|
92 | }
|
---|
93 |
|
---|
94 | void UINotificationProgress::sltHandleProgressChange(ulong uPercent)
|
---|
95 | {
|
---|
96 | m_uPercent = uPercent;
|
---|
97 | emit sigProgressChange(uPercent);
|
---|
98 | }
|
---|
99 |
|
---|
100 | void UINotificationProgress::sltHandleProgressFinished()
|
---|
101 | {
|
---|
102 | m_uPercent = 100;
|
---|
103 | emit sigProgressFinished();
|
---|
104 | }
|
---|