1- /* $Id: UIMessageCenter.cpp 113937 2026-04-17 09:26:37Z sergey.dubov@oracle.com $ */
1+ /* $Id: UIMessageCenter.cpp 113938 2026-04-17 09:37:43Z sergey.dubov@oracle.com $ */
22/* * @file
33 * VBox Qt GUI - UIMessageCenter class implementation.
44 */
2525 * SPDX-License-Identifier: GPL-3.0-only
2626 */
2727
28- /* Qt includes: */
29- #include < QThread>
30-
3128/* GUI includes: */
32- #include " QIMessageBox.h"
3329#include " UICommon.h"
3430#include " UIExtraDataManager.h"
3531#include " UIGlobalSession.h"
@@ -79,60 +75,6 @@ void UIMessageCenter::destroy()
7975 delete s_pInstance;
8076}
8177
82- int UIMessageCenter::message (QWidget *pParent, MessageType enmType,
83- const QString &strMessage,
84- const QString &strDetails,
85- const char *pcszAutoConfirmId /* = 0 */ ,
86- int iButton1 /* = 0 */ ,
87- int iButton2 /* = 0 */ ,
88- int iButton3 /* = 0 */ ,
89- const QString &strButtonText1 /* = QString() */ ,
90- const QString &strButtonText2 /* = QString() */ ,
91- const QString &strButtonText3 /* = QString() */ ,
92- const QString &strHelpKeyword /* = QString() */ ) const
93- {
94- /* If this is NOT a GUI thread: */
95- if (thread () != QThread::currentThread ())
96- {
97- /* We have to throw a blocking signal
98- * to show a message-box in the GUI thread: */
99- emit sigToShowMessageBox (pParent, enmType,
100- strMessage, strDetails,
101- iButton1, iButton2, iButton3,
102- strButtonText1, strButtonText2, strButtonText3,
103- QString (pcszAutoConfirmId), strHelpKeyword);
104- // Inter-thread communications are not yet implemented, so
105- // we are not returning effective value, but zero otherwise.
106- return 0 ;
107- }
108-
109- /* In usual case we can chow a message-box directly: */
110- return showMessageBox (pParent, enmType,
111- strMessage, strDetails,
112- iButton1, iButton2, iButton3,
113- strButtonText1, strButtonText2, strButtonText3,
114- QString (pcszAutoConfirmId), strHelpKeyword);
115- }
116-
117- void UIMessageCenter::error (QWidget *pParent, MessageType enmType,
118- const QString &strMessage,
119- const QString &strDetails,
120- const char *pcszAutoConfirmId /* = 0 */ ,
121- const QString &strHelpKeyword /* = QString() */ ) const
122- {
123- message (pParent, enmType, strMessage, strDetails, pcszAutoConfirmId,
124- AlertButton_Ok | AlertButtonOption_Default | AlertButtonOption_Escape, 0 /* Button 2 */ , 0 /* Button 3 */ ,
125- QString () /* strButtonText1 */ , QString () /* strButtonText2 */ , QString () /* strButtonText3 */ , strHelpKeyword);
126- }
127-
128- void UIMessageCenter::alert (QWidget *pParent, MessageType enmType,
129- const QString &strMessage,
130- const char *pcszAutoConfirmId /* = 0 */ ,
131- const QString &strHelpKeyword /* = QString() */ ) const
132- {
133- error (pParent, enmType, strMessage, QString (), pcszAutoConfirmId, strHelpKeyword);
134- }
135-
13678void UIMessageCenter::sltShowHelpWebDialog ()
13779{
13880 uiCommon ().openURL (" https://www.virtualbox.org" );
@@ -178,27 +120,6 @@ void UIMessageCenter::sltResetSuppressedMessages()
178120 gEDataManager ->setSuppressedMessages (QStringList ());
179121}
180122
181- void UIMessageCenter::sltShowMessageBox (QWidget *pParent,
182- MessageType enmType,
183- const QString &strMessage,
184- const QString &strDetails,
185- int iButton1,
186- int iButton2,
187- int iButton3,
188- const QString &strButtonText1,
189- const QString &strButtonText2,
190- const QString &strButtonText3,
191- const QString &strAutoConfirmId,
192- const QString &strHelpKeyword) const
193- {
194- /* Now we can show a message-box directly: */
195- showMessageBox (pParent, enmType,
196- strMessage, strDetails,
197- iButton1, iButton2, iButton3,
198- strButtonText1, strButtonText2, strButtonText3,
199- strAutoConfirmId, strHelpKeyword);
200- }
201-
202123UIMessageCenter::UIMessageCenter ()
203124{
204125 /* Assign instance: */
@@ -215,9 +136,6 @@ void UIMessageCenter::prepare()
215136{
216137 /* Prepare interthread connection: */
217138 qRegisterMetaType<MessageType>();
218- connect (this , &UIMessageCenter::sigToShowMessageBox,
219- this , &UIMessageCenter::sltShowMessageBox,
220- Qt::BlockingQueuedConnection);
221139
222140 /* Translations for Main.
223141 * Please make sure they corresponds to the strings coming from Main one-by-one symbol! */
@@ -232,119 +150,3 @@ void UIMessageCenter::prepare()
232150 tr (" The USB Proxy Service has not yet been ported to this host" );
233151 tr (" Could not load the Host USB Proxy service" );
234152}
235-
236- int UIMessageCenter::showMessageBox (QWidget *pParent,
237- MessageType enmType,
238- const QString &strMessage,
239- const QString &strDetails,
240- int iButton1,
241- int iButton2,
242- int iButton3,
243- const QString &strButtonText1,
244- const QString &strButtonText2,
245- const QString &strButtonText3,
246- const QString &strAutoConfirmId,
247- const QString &strHelpKeyword) const
248- {
249- /* Choose the 'default' button: */
250- if (iButton1 == 0 && iButton2 == 0 && iButton3 == 0 )
251- iButton1 = AlertButton_Ok | AlertButtonOption_Default;
252-
253- /* Check if message-box was auto-confirmed before: */
254- QStringList confirmedMessageList;
255- if (!strAutoConfirmId.isEmpty ())
256- {
257- const QUuid uID = uiCommon ().uiType () == UIType_RuntimeUI
258- ? uiCommon ().managedVMUuid ()
259- : UIExtraDataManager::GlobalID;
260- confirmedMessageList = gEDataManager ->suppressedMessages (uID);
261- if ( confirmedMessageList.contains (strAutoConfirmId)
262- || confirmedMessageList.contains (" allMessageBoxes" )
263- || confirmedMessageList.contains (" all" ) )
264- {
265- int iResultCode = AlertOption_AutoConfirmed;
266- if (iButton1 & AlertButtonOption_Default)
267- iResultCode |= (iButton1 & AlertButtonMask);
268- if (iButton2 & AlertButtonOption_Default)
269- iResultCode |= (iButton2 & AlertButtonMask);
270- if (iButton3 & AlertButtonOption_Default)
271- iResultCode |= (iButton3 & AlertButtonMask);
272- return iResultCode;
273- }
274- }
275-
276- /* Choose title and icon: */
277- QString title;
278- AlertIconType icon;
279- switch (enmType)
280- {
281- default :
282- case MessageType_Question:
283- title = tr (" VirtualBox - Question" , " msg box title" );
284- icon = AlertIconType_Question;
285- break ;
286- case MessageType_Warning:
287- title = tr (" VirtualBox - Warning" , " msg box title" );
288- icon = AlertIconType_Warning;
289- break ;
290- case MessageType_Error:
291- title = tr (" VirtualBox - Error" , " msg box title" );
292- icon = AlertIconType_Critical;
293- break ;
294- case MessageType_Critical:
295- title = tr (" VirtualBox - Critical Error" , " msg box title" );
296- icon = AlertIconType_Critical;
297- break ;
298- }
299-
300- /* Create message-box: */
301- QWidget *pMessageBoxParent = windowManager ().realParentWindow (pParent ? pParent : windowManager ().mainWindowShown ());
302- const QString strHackValue = gEDataManager ->extraDataString (" GUI/Hack/MakeMessageBoxParentless" );
303- QPointer<QIMessageBox> pMessageBox = new QIMessageBox (title, strMessage, icon,
304- iButton1, iButton2, iButton3,
305- strHackValue == " true" ? 0 : pMessageBoxParent,
306- strHelpKeyword);
307- windowManager ().registerNewParent (pMessageBox, pMessageBoxParent);
308-
309- /* Prepare auto-confirmation check-box: */
310- if (!strAutoConfirmId.isEmpty ())
311- {
312- pMessageBox->setFlagText (tr (" Do not show this message again" , " msg box flag" ));
313- pMessageBox->setFlagChecked (false );
314- }
315-
316- /* Configure details: */
317- if (!strDetails.isEmpty ())
318- pMessageBox->setDetailsText (strDetails);
319-
320- /* Configure button-text: */
321- if (!strButtonText1.isNull ())
322- pMessageBox->setButtonText (0 , strButtonText1);
323- if (!strButtonText2.isNull ())
324- pMessageBox->setButtonText (1 , strButtonText2);
325- if (!strButtonText3.isNull ())
326- pMessageBox->setButtonText (2 , strButtonText3);
327-
328- /* Show message-box: */
329- int iResultCode = pMessageBox->exec ();
330-
331- /* Make sure message-box still valid: */
332- if (!pMessageBox)
333- return iResultCode;
334-
335- /* Remember auto-confirmation check-box value: */
336- if (!strAutoConfirmId.isEmpty ())
337- {
338- if (pMessageBox->flagChecked ())
339- {
340- confirmedMessageList << strAutoConfirmId;
341- gEDataManager ->setSuppressedMessages (confirmedMessageList);
342- }
343- }
344-
345- /* Delete message-box: */
346- delete pMessageBox;
347-
348- /* Return result-code: */
349- return iResultCode;
350- }
0 commit comments