VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationModel.cpp@ 103977

Last change on this file since 103977 was 98928, checked in by vboxsync, 21 months ago

FE/Qt: bugref:10322: Notification-center: Reworking r156239 the way that the model cleanup should clean the tree itself, no need for separate redundant handler.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: UINotificationModel.cpp 98928 2023-03-13 10:37:02Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UINotificationModel class implementation.
4 */
5
6/*
7 * Copyright (C) 2021-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/* Qt includes: */
29#include <QSet>
30
31/* GUI includes: */
32#include "UICommon.h"
33#include "UIExtraDataManager.h"
34#include "UINotificationModel.h"
35#include "UINotificationObject.h"
36
37/* Other VBox includes: */
38#include "iprt/assert.h"
39
40
41UINotificationModel::UINotificationModel(QObject *pParent)
42 : QObject(pParent)
43{
44 prepare();
45}
46
47UINotificationModel::~UINotificationModel()
48{
49 cleanup();
50}
51
52QUuid UINotificationModel::appendObject(UINotificationObject *pObject)
53{
54 /* [Re]generate ID until unique: */
55 QUuid uId = QUuid::createUuid();
56 while (m_ids.contains(uId))
57 uId = QUuid::createUuid();
58 /* Append ID and object: */
59 m_ids << uId;
60 m_objects[uId] = pObject;
61 /* Connect object close signal: */
62 connect(pObject, &UINotificationObject::sigAboutToClose,
63 this, &UINotificationModel::sltHandleAboutToClose);
64 /* Notify listeners: */
65 emit sigItemAdded(uId);
66 /* Handle object: */
67 pObject->handle();
68 /* Return ID: */
69 return uId;
70}
71
72void UINotificationModel::revokeObject(const QUuid &uId)
73{
74 /* Remove id first of all: */
75 m_ids.removeAll(uId);
76 /* Notify listeners before object is deleted: */
77 emit sigItemRemoved(uId);
78 /* Delete object itself finally: */
79 delete m_objects.take(uId);
80}
81
82bool UINotificationModel::hasObject(const QUuid &uId) const
83{
84 return m_objects.contains(uId);
85}
86
87void UINotificationModel::revokeFinishedObjects()
88{
89 /* Check whether there are done objects: */
90 foreach (const QUuid &uId, m_ids)
91 {
92 UINotificationObject *pObject = m_objects.value(uId);
93 AssertPtrReturnVoid(pObject);
94 if (pObject->isDone())
95 revokeObject(uId);
96 }
97}
98
99QList<QUuid> UINotificationModel::ids() const
100{
101 return m_ids;
102}
103
104UINotificationObject *UINotificationModel::objectById(const QUuid &uId)
105{
106 return m_objects.value(uId);
107}
108
109void UINotificationModel::sltHandleAboutToClose(bool fDismiss)
110{
111 /* Determine sender: */
112 UINotificationObject *pSender = qobject_cast<UINotificationObject*>(sender());
113 AssertPtrReturnVoid(pSender);
114
115 /* Dismiss message if requested: */
116 if (fDismiss && !pSender->internalName().isEmpty())
117 {
118 QStringList suppressedMessages = gEDataManager->suppressedMessages();
119 if (!suppressedMessages.contains(pSender->internalName()))
120 {
121 suppressedMessages.push_back(pSender->internalName());
122 gEDataManager->setSuppressedMessages(suppressedMessages);
123 }
124 }
125
126 /* Revoke it from internal storage: */
127 const QUuid uId = m_objects.key(pSender);
128 AssertReturnVoid(!uId.isNull());
129 revokeObject(uId);
130}
131
132void UINotificationModel::sltDetachCOM()
133{
134 cleanup();
135}
136
137void UINotificationModel::prepare()
138{
139 connect(&uiCommon(), &UICommon::sigAskToDetachCOM,
140 this, &UINotificationModel::sltDetachCOM);
141}
142
143void UINotificationModel::cleanup()
144{
145 /* Wipe out all the objects: */
146 foreach (const QUuid &uId, m_ids)
147 revokeObject(uId);
148 m_objects.clear();
149 m_ids.clear();
150}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette