VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/cloud/consolemanager/UICloudConsoleManager.cpp@ 105266

Last change on this file since 105266 was 104586, checked in by vboxsync, 12 months ago

FE/Qt: bugref:10450: Get rid of pre-5.14 code related to QString/QStringList splitting.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 48.8 KB
Line 
1/* $Id: UICloudConsoleManager.cpp 104586 2024-05-13 12:12:44Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UICloudConsoleManager class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-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 <QApplication>
30#include <QDialog>
31#include <QGridLayout>
32#include <QHeaderView>
33#include <QLabel>
34#include <QLineEdit>
35#include <QPushButton>
36#include <QRegularExpression>
37#include <QUuid>
38#include <QVBoxLayout>
39
40/* GUI includes: */
41#include "QIDialogButtonBox.h"
42#include "QITreeWidget.h"
43#include "UIActionPoolManager.h"
44#include "UIExtraDataManager.h"
45#include "UIIconPool.h"
46#include "UICloudConsoleDetailsWidget.h"
47#include "UICloudConsoleManager.h"
48#include "UIMessageCenter.h"
49#include "UITranslationEventListener.h"
50#include "QIToolBar.h"
51
52
53/** Tree-widget item types. */
54enum CloudConsoleItemType
55{
56 CloudConsoleItemType_Invalid = 0,
57 CloudConsoleItemType_Application = 1,
58 CloudConsoleItemType_Profile = 2
59};
60Q_DECLARE_METATYPE(CloudConsoleItemType);
61
62/** Tree-widget data types. */
63enum
64{
65 Data_ItemType = Qt::UserRole + 1,
66 Data_ItemID = Qt::UserRole + 2,
67 Data_Definition = Qt::UserRole + 3,
68};
69
70/** Tree-widget column types. */
71enum
72{
73 Column_Name,
74 Column_ListInMenu,
75 Column_Max
76};
77
78
79/** Cloud Console Manager application's tree-widget item. */
80class UIItemCloudConsoleApplication : public QITreeWidgetItem, public UIDataCloudConsoleApplication
81{
82 Q_OBJECT;
83
84public:
85
86 /** Constructs item. */
87 UIItemCloudConsoleApplication();
88
89 /** Updates item fields from base-class data. */
90 void updateFields();
91
92 /** Returns item id. */
93 QString id() const { return m_strId; }
94 /** Returns item name. */
95 QString name() const { return m_strName; }
96 /** Returns item path. */
97 QString path() const { return m_strPath; }
98 /** Returns item argument. */
99 QString argument() const { return m_strArgument; }
100};
101
102/** Cloud Console Manager profile's tree-widget item. */
103class UIItemCloudConsoleProfile : public QITreeWidgetItem, public UIDataCloudConsoleProfile
104{
105 Q_OBJECT;
106
107public:
108
109 /** Constructs item. */
110 UIItemCloudConsoleProfile();
111
112 /** Updates item fields from base-class data. */
113 void updateFields();
114
115 /** Returns item application id. */
116 QString applicationId() const { return m_strApplicationId; }
117 /** Returns item id. */
118 QString id() const { return m_strId; }
119 /** Returns item name. */
120 QString name() const { return m_strName; }
121 /** Returns item argument. */
122 QString argument() const { return m_strArgument; }
123};
124
125/** QDialog extension used to acquire newly created console application parameters. */
126class UIInputDialogCloudConsoleApplication : public QDialog
127{
128 Q_OBJECT;
129
130public:
131
132 /** Constructs dialog passing @a pParent to the base-class. */
133 UIInputDialogCloudConsoleApplication(QWidget *pParent);
134
135 /** Returns application name. */
136 QString name() const;
137 /** Returns application path. */
138 QString path() const;
139 /** Returns application argument. */
140 QString argument() const;
141
142private slots:
143
144 /** Handles translation event. */
145 void sltRetranslateUI();
146
147private:
148
149 /** Prepares all. */
150 void prepare();
151
152 /** Holds the name label instance. */
153 QLabel *m_pLabelName;
154 /** Holds the name editor instance. */
155 QLineEdit *m_pEditorName;
156 /** Holds the path label instance. */
157 QLabel *m_pLabelPath;
158 /** Holds the path editor instance. */
159 QLineEdit *m_pEditorPath;
160 /** Holds the argument label instance. */
161 QLabel *m_pLabelArgument;
162 /** Holds the argument editor instance. */
163 QLineEdit *m_pEditorArgument;
164
165 /** Holds the button-box instance. */
166 QIDialogButtonBox *m_pButtonBox;
167};
168
169/** QDialog extension used to acquire newly created console profile parameters. */
170class UIInputDialogCloudConsoleProfile : public QDialog
171{
172 Q_OBJECT;
173
174public:
175
176 /** Constructs dialog passing @a pParent to the base-class. */
177 UIInputDialogCloudConsoleProfile(QWidget *pParent);
178
179 /** Returns profile name. */
180 QString name() const;
181 /** Returns profile argument. */
182 QString argument() const;
183
184private slots:
185
186 /** Handles translation event. */
187 void sltRetranslateUI();
188
189private:
190
191 /** Prepares all. */
192 void prepare();
193
194 /** Holds the name label instance. */
195 QLabel *m_pLabelName;
196 /** Holds the name editor instance. */
197 QLineEdit *m_pEditorName;
198 /** Holds the argument label instance. */
199 QLabel *m_pLabelArgument;
200 /** Holds the argument editor instance. */
201 QLineEdit *m_pEditorArgument;
202
203 /** Holds the button-box instance. */
204 QIDialogButtonBox *m_pButtonBox;
205};
206
207
208/*********************************************************************************************************************************
209* Class UIItemCloudConsoleApplication implementation. *
210*********************************************************************************************************************************/
211
212UIItemCloudConsoleApplication::UIItemCloudConsoleApplication()
213{
214 /* Assign icon: */
215 setIcon(Column_Name, UIIconPool::iconSet(":/cloud_console_application_16px.png"));
216 /* Assign item data: */
217 setData(Column_Name, Data_ItemType, QVariant::fromValue(CloudConsoleItemType_Application));
218}
219
220void UIItemCloudConsoleApplication::updateFields()
221{
222 /* Update item fields: */
223 setText(Column_Name, m_strName);
224 setData(Column_Name, Data_ItemID, m_strId);
225 setData(Column_Name, Data_Definition, QVariant::fromValue(QString("/%1").arg(m_strId)));
226 setCheckState(Column_ListInMenu, m_fRestricted ? Qt::Unchecked : Qt::Checked);
227}
228
229
230/*********************************************************************************************************************************
231* Class UIItemCloudConsoleProfile implementation. *
232*********************************************************************************************************************************/
233
234UIItemCloudConsoleProfile::UIItemCloudConsoleProfile()
235{
236 /* Assign icon: */
237 setIcon(Column_Name, UIIconPool::iconSet(":/cloud_console_profile_16px.png"));
238 /* Assign item data: */
239 setData(Column_Name, Data_ItemType, QVariant::fromValue(CloudConsoleItemType_Profile));
240}
241
242void UIItemCloudConsoleProfile::updateFields()
243{
244 /* Update item fields: */
245 setText(Column_Name, m_strName);
246 setData(Column_Name, Data_ItemID, m_strId);
247 setData(Column_Name, Data_Definition, QVariant::fromValue(QString("/%1/%2").arg(m_strApplicationId, m_strId)));
248 setCheckState(Column_ListInMenu, m_fRestricted ? Qt::Unchecked : Qt::Checked);
249}
250
251
252/*********************************************************************************************************************************
253* Class UIInputDialogCloudConsoleApplication implementation. *
254*********************************************************************************************************************************/
255
256UIInputDialogCloudConsoleApplication::UIInputDialogCloudConsoleApplication(QWidget *pParent)
257 : QDialog(pParent)
258 , m_pLabelName(0)
259 , m_pEditorName(0)
260 , m_pLabelPath(0)
261 , m_pEditorPath(0)
262 , m_pLabelArgument(0)
263 , m_pEditorArgument(0)
264 , m_pButtonBox(0)
265{
266 prepare();
267}
268
269QString UIInputDialogCloudConsoleApplication::name() const
270{
271 return m_pEditorName->text();
272}
273
274QString UIInputDialogCloudConsoleApplication::path() const
275{
276 return m_pEditorPath->text();
277}
278
279QString UIInputDialogCloudConsoleApplication::argument() const
280{
281 return m_pEditorArgument->text();
282}
283
284void UIInputDialogCloudConsoleApplication::sltRetranslateUI()
285{
286 setWindowTitle(UICloudConsoleManager::tr("Add Application"));
287 m_pLabelName->setText(UICloudConsoleManager::tr("Name:"));
288 m_pLabelPath->setText(UICloudConsoleManager::tr("Path:"));
289 m_pLabelArgument->setText(UICloudConsoleManager::tr("Argument:"));
290}
291
292void UIInputDialogCloudConsoleApplication::prepare()
293{
294#ifndef VBOX_WS_MAC
295 /* Assign window icon: */
296 setWindowIcon(UIIconPool::iconSetFull(":/cloud_console_application_add_32px.png" ,":/cloud_console_application_add_16px.png"));
297#endif
298
299 /* Prepare main layout: */
300 QGridLayout *pMainLayout = new QGridLayout(this);
301 if (pMainLayout)
302 {
303 pMainLayout->setRowStretch(3, 1);
304
305 /* Prepare name editor: */
306 m_pEditorName = new QLineEdit(this);
307 if (m_pEditorName)
308 {
309 pMainLayout->addWidget(m_pEditorName, 0, 1);
310 }
311 /* Prepare name editor label: */
312 m_pLabelName = new QLabel(this);
313 if (m_pLabelName)
314 {
315 m_pLabelName->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
316 m_pLabelName->setBuddy(m_pEditorName);
317 pMainLayout->addWidget(m_pLabelName, 0, 0);
318 }
319
320 /* Prepare path editor: */
321 m_pEditorPath = new QLineEdit(this);
322 if (m_pEditorPath)
323 {
324 pMainLayout->addWidget(m_pEditorPath, 1, 1);
325 }
326 /* Prepare path editor label: */
327 m_pLabelPath = new QLabel(this);
328 if (m_pLabelPath)
329 {
330 m_pLabelPath->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
331 m_pLabelPath->setBuddy(m_pEditorPath);
332 pMainLayout->addWidget(m_pLabelPath, 1, 0);
333 }
334
335 /* Prepare argument editor: */
336 m_pEditorArgument = new QLineEdit(this);
337 if (m_pEditorArgument)
338 {
339 pMainLayout->addWidget(m_pEditorArgument, 2, 1);
340 }
341 /* Prepare argument editor label: */
342 m_pLabelArgument = new QLabel(this);
343 if (m_pLabelArgument)
344 {
345 m_pLabelArgument->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
346 m_pLabelArgument->setBuddy(m_pEditorArgument);
347 pMainLayout->addWidget(m_pLabelArgument, 2, 0);
348 }
349
350 /* Prepare button-box: */
351 m_pButtonBox = new QIDialogButtonBox(this);
352 if (m_pButtonBox)
353 {
354 m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
355 connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIInputDialogCloudConsoleApplication::reject);
356 connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIInputDialogCloudConsoleApplication::accept);
357 pMainLayout->addWidget(m_pButtonBox, 4, 0, 1, 2);
358 }
359 }
360
361 /* Apply language settings: */
362 sltRetranslateUI();
363 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
364 this, &UIInputDialogCloudConsoleApplication::sltRetranslateUI);
365
366 /* Resize to suitable size: */
367 const int iMinimumHeightHint = minimumSizeHint().height();
368 resize(iMinimumHeightHint * 3, iMinimumHeightHint);
369}
370
371
372/*********************************************************************************************************************************
373* Class UIInputDialogCloudConsoleProfile implementation. *
374*********************************************************************************************************************************/
375
376UIInputDialogCloudConsoleProfile::UIInputDialogCloudConsoleProfile(QWidget *pParent)
377 : QDialog(pParent)
378 , m_pLabelName(0)
379 , m_pEditorName(0)
380 , m_pLabelArgument(0)
381 , m_pEditorArgument(0)
382 , m_pButtonBox(0)
383{
384 prepare();
385}
386
387QString UIInputDialogCloudConsoleProfile::name() const
388{
389 return m_pEditorName->text();
390}
391
392QString UIInputDialogCloudConsoleProfile::argument() const
393{
394 return m_pEditorArgument->text();
395}
396
397void UIInputDialogCloudConsoleProfile::sltRetranslateUI()
398{
399 setWindowTitle(UICloudConsoleManager::tr("Add Profile"));
400 m_pLabelName->setText(UICloudConsoleManager::tr("Name:"));
401 m_pLabelArgument->setText(UICloudConsoleManager::tr("Argument:"));
402}
403
404void UIInputDialogCloudConsoleProfile::prepare()
405{
406#ifndef VBOX_WS_MAC
407 /* Assign window icon: */
408 setWindowIcon(UIIconPool::iconSetFull(":/cloud_console_profile_add_32px.png", ":/cloud_console_profile_add_16px.png"));
409#endif
410
411 /* Prepare main layout: */
412 QGridLayout *pMainLayout = new QGridLayout(this);
413 if (pMainLayout)
414 {
415 pMainLayout->setRowStretch(0, 0);
416 pMainLayout->setRowStretch(1, 0);
417 pMainLayout->setRowStretch(2, 1);
418 pMainLayout->setRowStretch(3, 0);
419
420 /* Prepare name editor: */
421 m_pEditorName = new QLineEdit(this);
422 if (m_pEditorName)
423 {
424 pMainLayout->addWidget(m_pEditorName, 0, 1);
425 }
426 /* Prepare name editor label: */
427 m_pLabelName = new QLabel(this);
428 if (m_pLabelName)
429 {
430 m_pLabelName->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
431 m_pLabelName->setBuddy(m_pEditorName);
432 pMainLayout->addWidget(m_pLabelName, 0, 0);
433 }
434
435 /* Prepare argument editor: */
436 m_pEditorArgument = new QLineEdit(this);
437 if (m_pEditorArgument)
438 {
439 pMainLayout->addWidget(m_pEditorArgument, 1, 1);
440 }
441 /* Prepare argument editor label: */
442 m_pLabelArgument = new QLabel(this);
443 if (m_pLabelArgument)
444 {
445 m_pLabelArgument->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
446 m_pLabelArgument->setBuddy(m_pEditorArgument);
447 pMainLayout->addWidget(m_pLabelArgument, 1, 0);
448 }
449
450 /* Prepare button-box: */
451 m_pButtonBox = new QIDialogButtonBox(this);
452 if (m_pButtonBox)
453 {
454 m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
455 connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIInputDialogCloudConsoleApplication::reject);
456 connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIInputDialogCloudConsoleApplication::accept);
457 pMainLayout->addWidget(m_pButtonBox, 3, 0, 1, 2);
458 }
459 }
460
461 /* Apply language settings: */
462 sltRetranslateUI();
463 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
464 this, &UIInputDialogCloudConsoleProfile::sltRetranslateUI);
465
466 /* Resize to suitable size: */
467 const int iMinimumHeightHint = minimumSizeHint().height();
468 resize(iMinimumHeightHint * 3, iMinimumHeightHint);
469}
470
471
472/*********************************************************************************************************************************
473* Class UICloudConsoleManagerWidget implementation. *
474*********************************************************************************************************************************/
475
476UICloudConsoleManagerWidget::UICloudConsoleManagerWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool,
477 bool fShowToolbar /* = true */, QWidget *pParent /* = 0 */)
478 : QWidget(pParent)
479 , m_enmEmbedding(enmEmbedding)
480 , m_pActionPool(pActionPool)
481 , m_fShowToolbar(fShowToolbar)
482 , m_pToolBar(0)
483 , m_pTreeWidget(0)
484 , m_pDetailsWidget(0)
485{
486 prepare();
487}
488
489QMenu *UICloudConsoleManagerWidget::menu() const
490{
491 return m_pActionPool->action(UIActionIndexMN_M_CloudConsoleWindow)->menu();
492}
493
494void UICloudConsoleManagerWidget::sltRetranslateUI()
495{
496 /* Translate tree-widget: */
497 m_pTreeWidget->setHeaderLabels( QStringList()
498 << UICloudConsoleManager::tr("Application")
499 << UICloudConsoleManager::tr("List in Menu"));
500}
501
502void UICloudConsoleManagerWidget::sltResetCloudConsoleDetailsChanges()
503{
504 /* Just push the current-item data there again: */
505 sltHandleCurrentItemChange();
506}
507
508void UICloudConsoleManagerWidget::sltApplyCloudConsoleDetailsChanges()
509{
510 /* Check current-item type: */
511 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
512 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
513 switch (pItem->data(Column_Name, Data_ItemType).value<CloudConsoleItemType>())
514 {
515 case CloudConsoleItemType_Application:
516 {
517 /* Save application changes: */
518 UIItemCloudConsoleApplication *pItemApplication = qobject_cast<UIItemCloudConsoleApplication*>(pItem);
519 AssertPtrReturnVoid(pItemApplication);
520 const UIDataCloudConsoleApplication oldData = *pItemApplication;
521 const UIDataCloudConsoleApplication newData = m_pDetailsWidget->applicationData();
522 /* Save application settings if changed: */
523 if (newData != oldData)
524 gEDataManager->setCloudConsoleManagerApplication(newData.m_strId,
525 QString("%1,%2,%3").arg(newData.m_strName,
526 newData.m_strPath,
527 newData.m_strArgument));
528 break;
529 }
530 case CloudConsoleItemType_Profile:
531 {
532 /* Save profile changes: */
533 UIItemCloudConsoleProfile *pItemProfile = qobject_cast<UIItemCloudConsoleProfile*>(pItem);
534 AssertPtrReturnVoid(pItemProfile);
535 const UIDataCloudConsoleProfile oldData = *pItemProfile;
536 const UIDataCloudConsoleProfile newData = m_pDetailsWidget->profileData();
537 /* Save profile settings if changed: */
538 if (newData != oldData)
539 gEDataManager->setCloudConsoleManagerProfile(newData.m_strApplicationId,
540 newData.m_strId,
541 QString("%1,%2").arg(newData.m_strName, newData.m_strArgument));
542 break;
543 }
544 case CloudConsoleItemType_Invalid:
545 break;
546 }
547}
548
549void UICloudConsoleManagerWidget::sltAddCloudConsoleApplication()
550{
551 /* Acquire application attributes: */
552 QString strId;
553 QString strApplicationName;
554 QString strApplicationPath;
555 QString strApplicationArgument;
556 bool fCancelled = true;
557 QPointer<UIInputDialogCloudConsoleApplication> pDialog = new UIInputDialogCloudConsoleApplication(this);
558 if (pDialog)
559 {
560 if (pDialog->exec() == QDialog::Accepted)
561 {
562 strId = QUuid::createUuid().toString().remove(QRegularExpression("[{}]"));
563 strApplicationName = pDialog->name();
564 strApplicationPath = pDialog->path();
565 strApplicationArgument = pDialog->argument();
566 fCancelled = false;
567 }
568 delete pDialog;
569 }
570 if (fCancelled)
571 return;
572
573 /* Update current-item definition: */
574 m_strDefinition = QString("/%1").arg(strId);
575 /* Compose extra-data superset: */
576 const QString strValue = QString("%1,%2,%3").arg(strApplicationName, strApplicationPath, strApplicationArgument);
577
578 /* Save new console application to extra-data: */
579 gEDataManager->setCloudConsoleManagerApplication(strId, strValue);
580}
581
582void UICloudConsoleManagerWidget::sltRemoveCloudConsoleApplication()
583{
584 /* Get console application item: */
585 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
586 UIItemCloudConsoleApplication *pItemApplication = qobject_cast<UIItemCloudConsoleApplication*>(pItem);
587 AssertMsgReturnVoid(pItemApplication, ("Application item must not be null!\n"));
588 const QString strApplicationId = pItemApplication->id();
589
590 /* Confirm cloud console application removal: */
591 if (!msgCenter().confirmCloudConsoleApplicationRemoval(pItemApplication->name(), this))
592 return;
593
594 /* Enumerate all the application profiles: */
595 for (int i = 0; i < pItemApplication->childCount(); ++i)
596 {
597 /* Get console profile item: */
598 QITreeWidgetItem *pItem = pItemApplication->childItem(i);
599 UIItemCloudConsoleProfile *pItemProfile = qobject_cast<UIItemCloudConsoleProfile*>(pItem);
600 AssertMsgReturnVoid(pItemProfile, ("Profile item must not be null!\n"));
601
602 /* Delete profile from extra-data: */
603 gEDataManager->setCloudConsoleManagerProfile(strApplicationId, pItemProfile->id(), QString());
604 }
605
606 /* Delete application from extra-data: */
607 gEDataManager->setCloudConsoleManagerApplication(strApplicationId, QString());
608}
609
610void UICloudConsoleManagerWidget::sltAddCloudConsoleProfile()
611{
612 /* Check current-item type: */
613 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
614 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
615 UIItemCloudConsoleApplication *pItemApplication = 0;
616 switch (pItem->data(Column_Name, Data_ItemType).value<CloudConsoleItemType>())
617 {
618 case CloudConsoleItemType_Application:
619 pItemApplication = qobject_cast<UIItemCloudConsoleApplication*>(pItem);
620 break;
621 case CloudConsoleItemType_Profile:
622 pItemApplication = qobject_cast<UIItemCloudConsoleApplication*>(pItem->parentItem());
623 break;
624 case CloudConsoleItemType_Invalid:
625 break;
626 }
627 AssertMsgReturnVoid(pItemApplication, ("Application item must not be null!\n"));
628 const QString strApplicationId = pItemApplication->id();
629
630 /* Acquire profile attributes: */
631 QString strId;
632 QString strProfileName;
633 QString strProfileArgument;
634 bool fCancelled = true;
635 QPointer<UIInputDialogCloudConsoleProfile> pDialog = new UIInputDialogCloudConsoleProfile(this);
636 if (pDialog)
637 {
638 if (pDialog->exec() == QDialog::Accepted)
639 {
640 strId = QUuid::createUuid().toString().remove(QRegularExpression("[{}]"));
641 strProfileName = pDialog->name();
642 strProfileArgument = pDialog->argument();
643 fCancelled = false;
644 }
645 delete pDialog;
646 }
647 if (fCancelled)
648 return;
649
650 /* Update current-item definition: */
651 m_strDefinition = QString("/%1/%2").arg(strApplicationId, strId);
652 /* Compose extra-data superset: */
653 const QString strValue = QString("%1,%2").arg(strProfileName, strProfileArgument);
654
655 /* Save new console profile to extra-data: */
656 gEDataManager->setCloudConsoleManagerProfile(strApplicationId, strId, strValue);
657}
658
659void UICloudConsoleManagerWidget::sltRemoveCloudConsoleProfile()
660{
661 /* Get console profile item: */
662 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
663 UIItemCloudConsoleProfile *pItemProfile = qobject_cast<UIItemCloudConsoleProfile*>(pItem);
664 AssertMsgReturnVoid(pItemProfile, ("Profile item must not be null!\n"));
665
666 /* Confirm cloud console profile removal: */
667 if (!msgCenter().confirmCloudConsoleProfileRemoval(pItemProfile->name(), this))
668 return;
669
670 /* Delete profile from extra-data: */
671 gEDataManager->setCloudConsoleManagerProfile(pItemProfile->applicationId(), pItemProfile->id(), QString());
672}
673
674void UICloudConsoleManagerWidget::sltToggleCloudConsoleDetailsVisibility(bool fVisible)
675{
676 /* Save the setting: */
677 gEDataManager->setCloudConsoleManagerDetailsExpanded(fVisible);
678 /* Show/hide details area and Apply button: */
679 m_pDetailsWidget->setVisible(fVisible);
680 /* Notify external lsiteners: */
681 emit sigCloudConsoleDetailsVisibilityChanged(fVisible);
682}
683
684void UICloudConsoleManagerWidget::sltPerformTableAdjustment()
685{
686 AssertPtrReturnVoid(m_pTreeWidget);
687 AssertPtrReturnVoid(m_pTreeWidget->header());
688 AssertPtrReturnVoid(m_pTreeWidget->viewport());
689 m_pTreeWidget->header()->resizeSection(0, m_pTreeWidget->viewport()->width() - m_pTreeWidget->header()->sectionSize(1));
690}
691
692void UICloudConsoleManagerWidget::sltHandleCurrentItemChange()
693{
694 /* Check current-item type: */
695 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
696 UIItemCloudConsoleApplication *pItemApplication = qobject_cast<UIItemCloudConsoleApplication*>(pItem);
697 UIItemCloudConsoleProfile *pItemProfile = qobject_cast<UIItemCloudConsoleProfile*>(pItem);
698
699 /* Update actions availability: */
700 m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationAdd)->setEnabled(!pItem || pItemApplication);
701 m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationRemove)->setEnabled(pItemApplication);
702 m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileAdd)->setEnabled(pItemApplication || pItemProfile);
703 m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileRemove)->setEnabled(pItemProfile);
704 m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details)->setEnabled(pItemApplication || pItemProfile);
705
706 /* Update current-item definition: */
707 if (pItem)
708 m_strDefinition = pItem->data(Column_Name, Data_Definition).toString();
709
710 /* Update details data: */
711 if (pItemApplication)
712 m_pDetailsWidget->setApplicationData(*pItemApplication);
713 else if (pItemProfile)
714 m_pDetailsWidget->setProfileData(*pItemProfile);
715 else
716 m_pDetailsWidget->clearData();
717
718 /* Update details area visibility: */
719 sltToggleCloudConsoleDetailsVisibility(pItem && m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details)->isChecked());
720}
721
722void UICloudConsoleManagerWidget::sltHandleContextMenuRequest(const QPoint &position)
723{
724 /* Check item type: */
725 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->itemAt(position));
726 UIItemCloudConsoleApplication *pItemApplication = qobject_cast<UIItemCloudConsoleApplication*>(pItem);
727 UIItemCloudConsoleProfile *pItemProfile = qobject_cast<UIItemCloudConsoleProfile*>(pItem);
728
729 /* Compose temporary context-menu: */
730 QMenu menu;
731 if (pItemApplication)
732 {
733 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationRemove));
734 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileAdd));
735 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details));
736 }
737 else if (pItemProfile)
738 {
739 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileRemove));
740 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details));
741 }
742 else
743 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationAdd));
744
745 /* And show it: */
746 menu.exec(m_pTreeWidget->viewport()->mapToGlobal(position));
747}
748
749void UICloudConsoleManagerWidget::sltHandleItemChange(QTreeWidgetItem *pItem)
750{
751 /* Check item type: */
752 QITreeWidgetItem *pChangedItem = QITreeWidgetItem::toItem(pItem);
753 UIItemCloudConsoleApplication *pItemApplication = qobject_cast<UIItemCloudConsoleApplication*>(pChangedItem);
754 UIItemCloudConsoleProfile *pItemProfile = qobject_cast<UIItemCloudConsoleProfile*>(pChangedItem);
755
756 /* Check whether item is of application or profile type, then check whether it changed: */
757 bool fChanged = false;
758 if (pItemApplication)
759 {
760 const UIDataCloudConsoleApplication oldData = *pItemApplication;
761 if ( (oldData.m_fRestricted && pItemApplication->checkState(Column_ListInMenu) == Qt::Checked)
762 || (!oldData.m_fRestricted && pItemApplication->checkState(Column_ListInMenu) == Qt::Unchecked))
763 fChanged = true;
764 }
765 else if (pItemProfile)
766 {
767 const UIDataCloudConsoleProfile oldData = *pItemProfile;
768 if ( (oldData.m_fRestricted && pItemProfile->checkState(Column_ListInMenu) == Qt::Checked)
769 || (!oldData.m_fRestricted && pItemProfile->checkState(Column_ListInMenu) == Qt::Unchecked))
770 fChanged = true;
771 }
772
773 /* Gather Cloud Console Manager restrictions and save them to extra-data: */
774 if (fChanged)
775 gEDataManager->setCloudConsoleManagerRestrictions(gatherCloudConsoleManagerRestrictions(m_pTreeWidget->invisibleRootItem()));
776}
777
778void UICloudConsoleManagerWidget::prepare()
779{
780 /* Prepare actions: */
781 prepareActions();
782 /* Prepare widgets: */
783 prepareWidgets();
784
785 /* Load settings: */
786 loadSettings();
787
788 /* Apply language settings: */
789 sltRetranslateUI();
790 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
791 this, &UICloudConsoleManagerWidget::sltRetranslateUI);
792
793 /* Load cloud console stuff: */
794 loadCloudConsoleStuff();
795}
796
797void UICloudConsoleManagerWidget::prepareActions()
798{
799 /* First of all, add actions which has smaller shortcut scope: */
800 addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationAdd));
801 addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationRemove));
802 addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileAdd));
803 addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileRemove));
804 addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details));
805}
806
807void UICloudConsoleManagerWidget::prepareWidgets()
808{
809 /* Create main-layout: */
810 new QVBoxLayout(this);
811 if (layout())
812 {
813 /* Configure layout: */
814 layout()->setContentsMargins(0, 0, 0, 0);
815#ifdef VBOX_WS_MAC
816 layout()->setSpacing(10);
817#else
818 layout()->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) / 2);
819#endif
820
821 /* Prepare toolbar, if requested: */
822 if (m_fShowToolbar)
823 prepareToolBar();
824 /* Prepare tree-widget: */
825 prepareTreeWidget();
826 /* Prepare details-widget: */
827 prepareDetailsWidget();
828 /* Prepare connections: */
829 prepareConnections();
830 }
831}
832
833void UICloudConsoleManagerWidget::prepareToolBar()
834{
835 /* Create toolbar: */
836 m_pToolBar = new QIToolBar(parentWidget());
837 if (m_pToolBar)
838 {
839 /* Configure toolbar: */
840 const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize));
841 m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
842 m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
843
844 /* Add toolbar actions: */
845 m_pToolBar->addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationAdd));
846 m_pToolBar->addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationRemove));
847 m_pToolBar->addSeparator();
848 m_pToolBar->addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileAdd));
849 m_pToolBar->addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileRemove));
850 m_pToolBar->addSeparator();
851 m_pToolBar->addAction(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details));
852
853#ifdef VBOX_WS_MAC
854 /* Check whether we are embedded into a stack: */
855 if (m_enmEmbedding == EmbedTo_Stack)
856 {
857 /* Add into layout: */
858 layout()->addWidget(m_pToolBar);
859 }
860#else
861 /* Add into layout: */
862 layout()->addWidget(m_pToolBar);
863#endif
864 }
865}
866
867void UICloudConsoleManagerWidget::prepareTreeWidget()
868{
869 /* Create tree-widget: */
870 m_pTreeWidget = new QITreeWidget;
871 if (m_pTreeWidget)
872 {
873 /* Configure tree-widget: */
874 m_pTreeWidget->header()->setStretchLastSection(false);
875 m_pTreeWidget->setRootIsDecorated(false);
876 m_pTreeWidget->setAlternatingRowColors(true);
877 m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
878 m_pTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
879 m_pTreeWidget->setColumnCount(Column_Max);
880 m_pTreeWidget->setSortingEnabled(true);
881 m_pTreeWidget->sortByColumn(Column_Name, Qt::AscendingOrder);
882 m_pTreeWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
883
884 /* Add into layout: */
885 layout()->addWidget(m_pTreeWidget);
886 }
887}
888
889void UICloudConsoleManagerWidget::prepareDetailsWidget()
890{
891 /* Create details-widget: */
892 m_pDetailsWidget = new UICloudConsoleDetailsWidget(m_enmEmbedding);
893 if (m_pDetailsWidget)
894 {
895 /* Configure details-widget: */
896 m_pDetailsWidget->setVisible(false);
897 m_pDetailsWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
898
899 /* Add into layout: */
900 layout()->addWidget(m_pDetailsWidget);
901 }
902}
903
904void UICloudConsoleManagerWidget::prepareConnections()
905{
906 /* Action connections: */
907 connect(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationAdd), &QAction::triggered,
908 this, &UICloudConsoleManagerWidget::sltAddCloudConsoleApplication);
909 connect(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ApplicationRemove), &QAction::triggered,
910 this, &UICloudConsoleManagerWidget::sltRemoveCloudConsoleApplication);
911 connect(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileAdd), &QAction::triggered,
912 this, &UICloudConsoleManagerWidget::sltAddCloudConsoleProfile);
913 connect(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_S_ProfileRemove), &QAction::triggered,
914 this, &UICloudConsoleManagerWidget::sltRemoveCloudConsoleProfile);
915 connect(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details), &QAction::toggled,
916 this, &UICloudConsoleManagerWidget::sltToggleCloudConsoleDetailsVisibility);
917
918 /* Tree-widget connections: */
919 connect(m_pTreeWidget, &QITreeWidget::resized,
920 this, &UICloudConsoleManagerWidget::sltPerformTableAdjustment, Qt::QueuedConnection);
921 connect(m_pTreeWidget->header(), &QHeaderView::sectionResized,
922 this, &UICloudConsoleManagerWidget::sltPerformTableAdjustment, Qt::QueuedConnection);
923 connect(m_pTreeWidget, &QITreeWidget::currentItemChanged,
924 this, &UICloudConsoleManagerWidget::sltHandleCurrentItemChange);
925 connect(m_pTreeWidget, &QITreeWidget::customContextMenuRequested,
926 this, &UICloudConsoleManagerWidget::sltHandleContextMenuRequest);
927 connect(m_pTreeWidget, &QITreeWidget::itemDoubleClicked,
928 m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details), &QAction::setChecked);
929 connect(m_pTreeWidget, &QITreeWidget::itemChanged,
930 this, &UICloudConsoleManagerWidget::sltHandleItemChange);
931
932 /* Details-widget connections: */
933 connect(m_pDetailsWidget, &UICloudConsoleDetailsWidget::sigDataChanged,
934 this, &UICloudConsoleManagerWidget::sigCloudConsoleDetailsDataChanged);
935 connect(m_pDetailsWidget, &UICloudConsoleDetailsWidget::sigDataChangeRejected,
936 this, &UICloudConsoleManagerWidget::sltResetCloudConsoleDetailsChanges);
937 connect(m_pDetailsWidget, &UICloudConsoleDetailsWidget::sigDataChangeAccepted,
938 this, &UICloudConsoleManagerWidget::sltApplyCloudConsoleDetailsChanges);
939
940 /* Extra-data connections: */
941 connect(gEDataManager, &UIExtraDataManager::sigCloudConsoleManagerDataChange,
942 this, &UICloudConsoleManagerWidget::sltLoadCloudConsoleStuff);
943 connect(gEDataManager, &UIExtraDataManager::sigCloudConsoleManagerRestrictionChange,
944 this, &UICloudConsoleManagerWidget::sltLoadCloudConsoleStuff);
945}
946
947void UICloudConsoleManagerWidget::loadSettings()
948{
949 /* Details action/widget: */
950 m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details)->setChecked(gEDataManager->cloudConsoleManagerDetailsExpanded());
951 sltToggleCloudConsoleDetailsVisibility(m_pActionPool->action(UIActionIndexMN_M_CloudConsole_T_Details)->isChecked());
952}
953
954void UICloudConsoleManagerWidget::loadCloudConsoleStuff()
955{
956 /* Clear tree first of all: */
957 m_pTreeWidget->clear();
958
959 /* Acquire cloud console manager restrictions: */
960 const QStringList restrictions = gEDataManager->cloudConsoleManagerRestrictions();
961
962 /* Iterate through existing console applications: */
963 foreach (const QString &strApplicationId, gEDataManager->cloudConsoleManagerApplications())
964 {
965 /* Skip if we have nothing to populate: */
966 if (strApplicationId.isEmpty())
967 continue;
968
969 /* Compose extra-data superset: */
970 const QString strApplicationValue = gEDataManager->cloudConsoleManagerApplication(strApplicationId);
971 const QString strApplicationSuperset = QString("%1,%2").arg(strApplicationId, strApplicationValue);
972
973 /* Load console application data: */
974 UIDataCloudConsoleApplication applicationData;
975 loadCloudConsoleApplication(strApplicationSuperset, applicationData);
976 const QString strApplicationDefinition = QString("/%1").arg(applicationData.m_strId);
977 applicationData.m_fRestricted = restrictions.contains(strApplicationDefinition);
978 createItemForCloudConsoleApplication(applicationData, false);
979
980 /* Make sure console applications item is properly inserted: */
981 UIItemCloudConsoleApplication *pItem = searchApplicationItem(applicationData.m_strId);
982
983 /* Iterate through applications's profiles: */
984 foreach (const QString &strProfileId, gEDataManager->cloudConsoleManagerProfiles(strApplicationId))
985 {
986 /* Skip if we have nothing to populate: */
987 if (strProfileId.isEmpty())
988 continue;
989
990 /* Compose extra-data superset: */
991 const QString strProfileValue = gEDataManager->cloudConsoleManagerProfile(strApplicationId, strProfileId);
992 const QString strProfileSuperset = QString("%1,%2").arg(strProfileId, strProfileValue);
993
994 /* Load console profile data: */
995 UIDataCloudConsoleProfile profileData;
996 loadCloudConsoleProfile(strProfileSuperset, applicationData, profileData);
997 const QString strProfileDefinition = QString("/%1/%2").arg(applicationData.m_strId).arg(profileData.m_strId);
998 profileData.m_fRestricted = restrictions.contains(strProfileDefinition);
999 createItemForCloudConsoleProfile(pItem, profileData, false);
1000 }
1001
1002 /* Expand console application item finally: */
1003 pItem->setExpanded(true);
1004 }
1005
1006 /* Choose previous current-item if possible: */
1007 if (!m_strDefinition.isEmpty())
1008 m_pTreeWidget->setCurrentItem(searchItemByDefinition(m_strDefinition));
1009 /* Choose the 1st item as current if nothing chosen: */
1010 if (!m_pTreeWidget->currentItem())
1011 m_pTreeWidget->setCurrentItem(m_pTreeWidget->childItem(0));
1012 /* Make sure current-item is fetched: */
1013 sltHandleCurrentItemChange();
1014}
1015
1016void UICloudConsoleManagerWidget::loadCloudConsoleApplication(const QString &strSuperset,
1017 UIDataCloudConsoleApplication &applicationData)
1018{
1019 /* Parse superset: */
1020 const QStringList values = strSuperset.split(',');
1021
1022 /* Gather application settings: */
1023 applicationData.m_strId = values.value(0);
1024 applicationData.m_strName = values.value(1);
1025 applicationData.m_strPath = values.value(2);
1026 applicationData.m_strArgument = values.value(3);
1027}
1028
1029void UICloudConsoleManagerWidget::loadCloudConsoleProfile(const QString &strSuperset,
1030 const UIDataCloudConsoleApplication &applicationData,
1031 UIDataCloudConsoleProfile &profileData)
1032{
1033 /* Gather application settings: */
1034 profileData.m_strApplicationId = applicationData.m_strId;
1035
1036 /* Parse superset: */
1037 const QStringList values = strSuperset.split(',');
1038
1039 /* Gather profile settings: */
1040 profileData.m_strId = values.value(0);
1041 profileData.m_strName = values.value(1);
1042 profileData.m_strArgument = values.value(2);
1043}
1044
1045UIItemCloudConsoleApplication *UICloudConsoleManagerWidget::searchApplicationItem(const QString &strApplicationId) const
1046{
1047 /* Iterate through tree-widget children: */
1048 for (int i = 0; i < m_pTreeWidget->childCount(); ++i)
1049 if (m_pTreeWidget->childItem(i)->data(Column_Name, Data_ItemID).toString() == strApplicationId)
1050 return qobject_cast<UIItemCloudConsoleApplication*>(m_pTreeWidget->childItem(i));
1051 /* Null by default: */
1052 return 0;
1053}
1054
1055UIItemCloudConsoleProfile *UICloudConsoleManagerWidget::searchProfileItem(const QString &strApplicationId,
1056 const QString &strProfileId) const
1057{
1058 /* Search for application item first: */
1059 UIItemCloudConsoleApplication *pItemApplication = searchApplicationItem(strApplicationId);
1060 /* Iterate through application children: */
1061 for (int i = 0; i < pItemApplication->childCount(); ++i)
1062 if (pItemApplication->childItem(i)->data(Column_Name, Data_ItemID).toString() == strProfileId)
1063 return qobject_cast<UIItemCloudConsoleProfile*>(pItemApplication->childItem(i));
1064 /* Null by default: */
1065 return 0;
1066}
1067
1068QITreeWidgetItem *UICloudConsoleManagerWidget::searchItemByDefinition(const QString &strDefinition) const
1069{
1070 /* Parse definition: */
1071 const QStringList parts = strDefinition.split('/', Qt::SkipEmptyParts);
1072 /* Depending on parts amount: */
1073 switch (parts.size())
1074 {
1075 case 1: return searchApplicationItem(parts.at(0));
1076 case 2: return searchProfileItem(parts.at(0), parts.at(1));
1077 default: break;
1078 }
1079 /* Null by default: */
1080 return 0;
1081}
1082
1083void UICloudConsoleManagerWidget::createItemForCloudConsoleApplication(const UIDataCloudConsoleApplication &applicationData,
1084 bool fChooseItem)
1085{
1086 /* Create new console application item: */
1087 UIItemCloudConsoleApplication *pItem = new UIItemCloudConsoleApplication;
1088 if (pItem)
1089 {
1090 /* Configure item: */
1091 pItem->UIDataCloudConsoleApplication::operator=(applicationData);
1092 pItem->updateFields();
1093 /* Add item to the tree: */
1094 m_pTreeWidget->addTopLevelItem(pItem);
1095 /* And choose it as current if necessary: */
1096 if (fChooseItem)
1097 m_pTreeWidget->setCurrentItem(pItem);
1098 }
1099}
1100
1101void UICloudConsoleManagerWidget::createItemForCloudConsoleProfile(QTreeWidgetItem *pParent,
1102 const UIDataCloudConsoleProfile &profileData,
1103 bool fChooseItem)
1104{
1105 /* Create new console profile item: */
1106 UIItemCloudConsoleProfile *pItem = new UIItemCloudConsoleProfile;
1107 if (pItem)
1108 {
1109 /* Configure item: */
1110 pItem->UIDataCloudConsoleProfile::operator=(profileData);
1111 pItem->updateFields();
1112 /* Add item to the parent: */
1113 pParent->addChild(pItem);
1114 /* And choose it as current if necessary: */
1115 if (fChooseItem)
1116 m_pTreeWidget->setCurrentItem(pItem);
1117 }
1118}
1119
1120QStringList UICloudConsoleManagerWidget::gatherCloudConsoleManagerRestrictions(QTreeWidgetItem *pParentItem)
1121{
1122 /* Prepare result: */
1123 QStringList result;
1124 AssertPtrReturn(pParentItem, result);
1125
1126 /* Process unchecked QITreeWidgetItem(s) only: */
1127 QITreeWidgetItem *pChangedItem = QITreeWidgetItem::toItem(pParentItem);
1128 if ( pChangedItem
1129 && pChangedItem->checkState(Column_ListInMenu) == Qt::Unchecked)
1130 result << pChangedItem->data(Column_Name, Data_Definition).toString();
1131
1132 /* Iterate through children recursively: */
1133 for (int i = 0; i < pParentItem->childCount(); ++i)
1134 result << gatherCloudConsoleManagerRestrictions(pParentItem->child(i));
1135
1136 /* Return result: */
1137 return result;
1138}
1139
1140
1141/*********************************************************************************************************************************
1142* Class UICloudConsoleManagerFactory implementation. *
1143*********************************************************************************************************************************/
1144
1145UICloudConsoleManagerFactory::UICloudConsoleManagerFactory(UIActionPool *pActionPool /* = 0 */)
1146 : m_pActionPool(pActionPool)
1147{
1148}
1149
1150void UICloudConsoleManagerFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
1151{
1152 pDialog = new UICloudConsoleManager(pCenterWidget, m_pActionPool);
1153}
1154
1155
1156/*********************************************************************************************************************************
1157* Class UICloudConsoleManager implementation. *
1158*********************************************************************************************************************************/
1159
1160UICloudConsoleManager::UICloudConsoleManager(QWidget *pCenterWidget, UIActionPool *pActionPool)
1161 : QIManagerDialog(pCenterWidget)
1162 , m_pActionPool(pActionPool)
1163{
1164}
1165
1166void UICloudConsoleManager::sltHandleButtonBoxClick(QAbstractButton *pButton)
1167{
1168 /* Disable buttons first of all: */
1169 button(ButtonType_Reset)->setEnabled(false);
1170 button(ButtonType_Apply)->setEnabled(false);
1171
1172 /* Compare with known buttons: */
1173 if (pButton == button(ButtonType_Reset))
1174 emit sigDataChangeRejected();
1175 else
1176 if (pButton == button(ButtonType_Apply))
1177 emit sigDataChangeAccepted();
1178}
1179
1180void UICloudConsoleManager::sltRetranslateUI()
1181{
1182 /* Translate window title: */
1183 setWindowTitle(tr("Cloud Console Manager"));
1184
1185 /* Translate buttons: */
1186 button(ButtonType_Reset)->setText(tr("Reset"));
1187 button(ButtonType_Apply)->setText(tr("Apply"));
1188 button(ButtonType_Close)->setText(tr("Close"));
1189 button(ButtonType_Reset)->setStatusTip(tr("Reset changes in current cloud console details"));
1190 button(ButtonType_Apply)->setStatusTip(tr("Apply changes in current cloud console details"));
1191 button(ButtonType_Close)->setStatusTip(tr("Close dialog without saving"));
1192 button(ButtonType_Reset)->setShortcut(QString("Ctrl+Backspace"));
1193 button(ButtonType_Apply)->setShortcut(QString("Ctrl+Return"));
1194 button(ButtonType_Close)->setShortcut(Qt::Key_Escape);
1195 button(ButtonType_Reset)->setToolTip(tr("Reset Changes (%1)").arg(button(ButtonType_Reset)->shortcut().toString()));
1196 button(ButtonType_Apply)->setToolTip(tr("Apply Changes (%1)").arg(button(ButtonType_Apply)->shortcut().toString()));
1197 button(ButtonType_Close)->setToolTip(tr("Close Window (%1)").arg(button(ButtonType_Close)->shortcut().toString()));
1198}
1199
1200void UICloudConsoleManager::configure()
1201{
1202#ifndef VBOX_WS_MAC
1203 /* Assign window icon: */
1204 setWindowIcon(UIIconPool::iconSetFull(":/cloud_console_manager_32px.png", ":/cloud_console_manager_16px.png"));
1205#endif
1206}
1207
1208void UICloudConsoleManager::configureCentralWidget()
1209{
1210 /* Create widget: */
1211 UICloudConsoleManagerWidget *pWidget = new UICloudConsoleManagerWidget(EmbedTo_Dialog, m_pActionPool, true, this);
1212 if (pWidget)
1213 {
1214 /* Configure widget: */
1215 setWidget(pWidget);
1216 setWidgetMenu(pWidget->menu());
1217#ifdef VBOX_WS_MAC
1218 setWidgetToolbar(pWidget->toolbar());
1219#endif
1220 connect(this, &UICloudConsoleManager::sigDataChangeRejected,
1221 pWidget, &UICloudConsoleManagerWidget::sltResetCloudConsoleDetailsChanges);
1222 connect(this, &UICloudConsoleManager::sigDataChangeAccepted,
1223 pWidget, &UICloudConsoleManagerWidget::sltApplyCloudConsoleDetailsChanges);
1224
1225 /* Add into layout: */
1226 centralWidget()->layout()->addWidget(pWidget);
1227 }
1228}
1229
1230void UICloudConsoleManager::configureButtonBox()
1231{
1232 /* Configure button-box: */
1233 connect(widget(), &UICloudConsoleManagerWidget::sigCloudConsoleDetailsVisibilityChanged,
1234 button(ButtonType_Apply), &QPushButton::setVisible);
1235 connect(widget(), &UICloudConsoleManagerWidget::sigCloudConsoleDetailsVisibilityChanged,
1236 button(ButtonType_Reset), &QPushButton::setVisible);
1237 connect(widget(), &UICloudConsoleManagerWidget::sigCloudConsoleDetailsDataChanged,
1238 button(ButtonType_Apply), &QPushButton::setEnabled);
1239 connect(widget(), &UICloudConsoleManagerWidget::sigCloudConsoleDetailsDataChanged,
1240 button(ButtonType_Reset), &QPushButton::setEnabled);
1241 connect(buttonBox(), &QIDialogButtonBox::clicked,
1242 this, &UICloudConsoleManager::sltHandleButtonBoxClick);
1243 // WORKAROUND:
1244 // Since we connected signals later than extra-data loaded
1245 // for signals above, we should handle that stuff here again:
1246 button(ButtonType_Apply)->setVisible(gEDataManager->cloudConsoleManagerDetailsExpanded());
1247 button(ButtonType_Reset)->setVisible(gEDataManager->cloudConsoleManagerDetailsExpanded());
1248}
1249
1250void UICloudConsoleManager::finalize()
1251{
1252 /* Apply language settings: */
1253 sltRetranslateUI();
1254 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
1255 this, &UICloudConsoleManager::sltRetranslateUI);
1256}
1257
1258UICloudConsoleManagerWidget *UICloudConsoleManager::widget()
1259{
1260 return qobject_cast<UICloudConsoleManagerWidget*>(QIManagerDialog::widget());
1261}
1262
1263
1264#include "UICloudConsoleManager.moc"
Note: See TracBrowser for help on using the repository browser.

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