VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensionpackmanager/UIExtensionPackManager.cpp@ 102493

Last change on this file since 102493 was 102269, checked in by vboxsync, 11 months ago

FE/Qt: bugref:10450: macOS: No need to QIToolBar layout/paint hacks since Qt6.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.8 KB
Line 
1/* $Id: UIExtensionPackManager.cpp 102269 2023-11-22 18:50:08Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIExtensionPackManager 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 <QDir>
30#include <QHeaderView>
31#include <QPushButton>
32#include <QTextStream>
33#include <QVBoxLayout>
34
35/* GUI includes: */
36#include "QIFileDialog.h"
37#include "QIToolBar.h"
38#include "QITreeWidget.h"
39#include "UIActionPoolManager.h"
40#include "UICommon.h"
41#include "UIExtension.h"
42#include "UIExtensionPackManager.h"
43#include "UIExtraDataManager.h"
44#include "UIIconPool.h"
45#include "UIMessageCenter.h"
46#include "UINotificationCenter.h"
47#include "UIVirtualBoxEventHandler.h"
48
49/* COM includes: */
50#include "CExtPack.h"
51#include "CExtPackManager.h"
52
53
54/** Extension pack tree-widget column indexes. */
55enum ExtensionPackColumn
56{
57 ExtensionPackColumn_Usable,
58 ExtensionPackColumn_Name,
59 ExtensionPackColumn_Version,
60 ExtensionPackColumn_Max,
61};
62
63
64/** Extension Pack Manager: Extension Pack data structure. */
65struct UIDataExtensionPack
66{
67 /** Constructs data. */
68 UIDataExtensionPack()
69 : m_strName(QString())
70 , m_strDescription(QString())
71 , m_strVersion(QString())
72 , m_uRevision(0)
73 , m_fIsUsable(false)
74 , m_strWhyUnusable(QString())
75 {}
76
77 /** Returns whether the @a other passed data is equal to this one. */
78 bool equal(const UIDataExtensionPack &other) const
79 {
80 return true
81 && (m_strName == other.m_strName)
82 && (m_strDescription == other.m_strDescription)
83 && (m_strVersion == other.m_strVersion)
84 && (m_uRevision == other.m_uRevision)
85 && (m_fIsUsable == other.m_fIsUsable)
86 && (m_strWhyUnusable == other.m_strWhyUnusable)
87 ;
88 }
89
90 /** Returns whether the @a other passed data is equal to this one. */
91 bool operator==(const UIDataExtensionPack &other) const { return equal(other); }
92 /** Returns whether the @a other passed data is different from this one. */
93 bool operator!=(const UIDataExtensionPack &other) const { return !equal(other); }
94
95 /** Holds the extension item name. */
96 QString m_strName;
97 /** Holds the extension item description. */
98 QString m_strDescription;
99 /** Holds the extension item version. */
100 QString m_strVersion;
101 /** Holds the extension item revision. */
102 ULONG m_uRevision;
103 /** Holds whether the extension item usable. */
104 bool m_fIsUsable;
105 /** Holds why the extension item is unusable. */
106 QString m_strWhyUnusable;
107};
108
109
110/** Extension Pack Manager tree-widget item. */
111class UIItemExtensionPack : public QITreeWidgetItem, public UIDataExtensionPack
112{
113 Q_OBJECT;
114
115public:
116
117 /** Updates item fields from base-class data. */
118 void updateFields();
119
120 /** Returns item name. */
121 QString name() const { return m_strName; }
122
123protected:
124
125 /** Returns default text. */
126 virtual QString defaultText() const RT_OVERRIDE;
127};
128
129
130/*********************************************************************************************************************************
131* Class UIItemExtensionPack implementation. *
132*********************************************************************************************************************************/
133
134void UIItemExtensionPack::updateFields()
135{
136 /* Icon: */
137 setIcon(ExtensionPackColumn_Usable, UIIconPool::iconSet( m_fIsUsable
138 ? ":/status_check_16px.png"
139 : ":/status_error_16px.png"));
140
141 /* Name: */
142 setText(ExtensionPackColumn_Name, m_strName);
143
144 /* Version, Revision, Edition: */
145 const QString strVersion(m_strVersion.section(QRegularExpression("[-_]"), 0, 0));
146 // WORKAROUND:
147 // for http://qt.gitorious.org/qt/qt/commit/7fc63dd0ff368a637dcd17e692b9d6b26278b538
148 QString strAppend;
149 if (m_strVersion.contains(QRegularExpression("[-_]")))
150 strAppend = m_strVersion.section(QRegularExpression("[-_]"), 1, -1, QString::SectionIncludeLeadingSep);
151 setText(ExtensionPackColumn_Version, QString("%1r%2%3").arg(strVersion).arg(m_uRevision).arg(strAppend));
152
153 /* Tool-tip: */
154 QString strTip = m_strDescription;
155 if (!m_fIsUsable)
156 {
157 strTip += QString("<hr>");
158 strTip += m_strWhyUnusable;
159 }
160 setToolTip(ExtensionPackColumn_Usable, strTip);
161 setToolTip(ExtensionPackColumn_Name, strTip);
162 setToolTip(ExtensionPackColumn_Version, strTip);
163}
164
165QString UIItemExtensionPack::defaultText() const
166{
167 return m_fIsUsable
168 ? QString("%1, %2: %3, %4")
169 .arg(text(1))
170 .arg(parentTree()->headerItem()->text(2)).arg(text(2))
171 .arg(parentTree()->headerItem()->text(0))
172 : QString("%1, %2: %3")
173 .arg(text(1))
174 .arg(parentTree()->headerItem()->text(2)).arg(text(2));
175}
176
177
178/*********************************************************************************************************************************
179* Class UIExtensionPackManagerWidget implementation. *
180*********************************************************************************************************************************/
181
182UIExtensionPackManagerWidget::UIExtensionPackManagerWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool,
183 bool fShowToolbar /* = true */, QWidget *pParent /* = 0 */)
184 : QIWithRetranslateUI<QWidget>(pParent)
185 , m_enmEmbedding(enmEmbedding)
186 , m_pActionPool(pActionPool)
187 , m_fShowToolbar(fShowToolbar)
188 , m_pToolBar(0)
189 , m_pTreeWidget(0)
190{
191 prepare();
192}
193
194QMenu *UIExtensionPackManagerWidget::menu() const
195{
196 return m_pActionPool->action(UIActionIndexMN_M_ExtensionWindow)->menu();
197}
198
199void UIExtensionPackManagerWidget::retranslateUi()
200{
201 /* Translate tree-widget: */
202 m_pTreeWidget->setHeaderLabels( QStringList()
203 << UIExtensionPackManager::tr("Active", "ext pack")
204 << UIExtensionPackManager::tr("Name")
205 << UIExtensionPackManager::tr("Version"));
206 m_pTreeWidget->setWhatsThis(UIExtensionPackManager::tr("Registered extension packs"));
207}
208
209void UIExtensionPackManagerWidget::sltInstallExtensionPack()
210{
211 /* Show file-open dialog to let user to choose package file.
212 * The default location is the user's Download or Downloads directory
213 * with the user's home directory as a fallback. ExtPacks are downloaded. */
214 QString strBaseFolder = QDir::homePath() + "/Downloads";
215 if (!QDir(strBaseFolder).exists())
216 {
217 strBaseFolder = QDir::homePath() + "/Download";
218 if (!QDir(strBaseFolder).exists())
219 strBaseFolder = QDir::homePath();
220 }
221 const QString strTitle = UIExtensionPackManager::tr("Select an extension package file");
222 QStringList extensions;
223 for (int i = 0; i < VBoxExtPackFileExts.size(); ++i)
224 extensions << QString("*.%1").arg(VBoxExtPackFileExts[i]);
225 const QString strFilter = UIExtensionPackManager::tr("Extension package files (%1)").arg(extensions.join(" "));
226 const QStringList fileNames = QIFileDialog::getOpenFileNames(strBaseFolder, strFilter, window(), strTitle, 0, true, true);
227 QString strFilePath;
228 if (!fileNames.isEmpty())
229 strFilePath = fileNames.at(0);
230
231 /* Install the chosen package: */
232 if (!strFilePath.isEmpty())
233 UIExtension::install(strFilePath, QString(), this, NULL);
234}
235
236void UIExtensionPackManagerWidget::sltUninstallExtensionPack()
237{
238 /* Get current item: */
239 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
240 UIItemExtensionPack *pItemEP = qobject_cast<UIItemExtensionPack*>(pItem);
241
242 /* Uninstall chosen package: */
243 if (pItemEP)
244 {
245 /* Get name of current package: */
246 const QString strSelectedPackageName = pItemEP->name();
247 /* Ask user about package removing: */
248 if (msgCenter().confirmRemoveExtensionPack(strSelectedPackageName, this))
249 {
250 /* Get VirtualBox for further activities: */
251 const CVirtualBox comVBox = uiCommon().virtualBox();
252 /* Get Extension Pack Manager for further activities: */
253 CExtPackManager comEPManager = comVBox.GetExtensionPackManager();
254
255 /* Show error message if necessary: */
256 if (!comVBox.isOk())
257 UINotificationMessage::cannotGetExtensionPackManager(comVBox);
258 else
259 {
260 /* Uninstall the package: */
261 /** @todo Refuse this if any VMs are running. */
262 QString displayInfo;
263#ifdef VBOX_WS_WIN
264 QTextStream stream(&displayInfo);
265 stream.setNumberFlags(QTextStream::ShowBase);
266 stream.setIntegerBase(16);
267 stream << "hwnd=" << winId();
268#endif
269
270 /* Uninstall extension pack: */
271 UINotificationProgressExtensionPackUninstall *pNotification =
272 new UINotificationProgressExtensionPackUninstall(comEPManager,
273 strSelectedPackageName,
274 displayInfo);
275 connect(pNotification, &UINotificationProgressExtensionPackUninstall::sigExtensionPackUninstalled,
276 this, &UIExtensionPackManagerWidget::sltHandleExtensionPackUninstalled);
277 connect(pNotification, &UINotificationProgressExtensionPackUninstall::sigExtensionPackUninstalled,
278 &uiCommon(), &UICommon::sigExtensionPackUninstalled);
279 gpNotificationCenter->append(pNotification);
280 }
281 }
282 }
283}
284
285void UIExtensionPackManagerWidget::sltAdjustTreeWidget()
286{
287 /* Get the tree-widget abstract interface: */
288 QAbstractItemView *pItemView = m_pTreeWidget;
289 /* Get the tree-widget header-view: */
290 QHeaderView *pItemHeader = m_pTreeWidget->header();
291
292 /* Calculate the total tree-widget width: */
293 const int iTotal = m_pTreeWidget->viewport()->width();
294 /* Look for a minimum width hints for non-important columns: */
295 const int iMinWidth1 = qMax(pItemView->sizeHintForColumn(ExtensionPackColumn_Usable),
296 pItemHeader->sectionSizeHint(ExtensionPackColumn_Usable));
297 const int iMinWidth2 = qMax(pItemView->sizeHintForColumn(ExtensionPackColumn_Version),
298 pItemHeader->sectionSizeHint(ExtensionPackColumn_Version));
299 /* Propose suitable width hints for non-important columns: */
300 const int iWidth1 = iMinWidth1 < iTotal / ExtensionPackColumn_Max ? iMinWidth1 : iTotal / ExtensionPackColumn_Max;
301 const int iWidth2 = iMinWidth2 < iTotal / ExtensionPackColumn_Max ? iMinWidth2 : iTotal / ExtensionPackColumn_Max;
302 /* Apply the proposal: */
303 m_pTreeWidget->setColumnWidth(ExtensionPackColumn_Usable, iWidth1);
304 m_pTreeWidget->setColumnWidth(ExtensionPackColumn_Version, iWidth2);
305 m_pTreeWidget->setColumnWidth(ExtensionPackColumn_Name, iTotal - iWidth1 - iWidth2);
306}
307
308void UIExtensionPackManagerWidget::sltHandleCurrentItemChange()
309{
310 /* Check current-item type: */
311 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
312
313 /* Update actions availability: */
314 m_pActionPool->action(UIActionIndexMN_M_Extension_S_Uninstall)->setEnabled(pItem);
315}
316
317void UIExtensionPackManagerWidget::sltHandleContextMenuRequest(const QPoint &position)
318{
319 /* Check clicked-item type: */
320 QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->itemAt(position));
321
322 /* Compose temporary context-menu: */
323 QMenu menu;
324 if (pItem)
325 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_Extension_S_Uninstall));
326 else
327 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_Extension_S_Install));
328
329 /* And show it: */
330 menu.exec(m_pTreeWidget->viewport()->mapToGlobal(position));
331}
332
333void UIExtensionPackManagerWidget::sltHandleExtensionPackInstalled(const QString &strName)
334{
335 /* Make sure the name was set: */
336 if (strName.isNull())
337 return;
338
339 /* Look for a list of items matching strName: */
340 const QList<QTreeWidgetItem*> items = m_pTreeWidget->findItems(strName, Qt::MatchCaseSensitive, ExtensionPackColumn_Name);
341 /* Remove first found item from the list if present: */
342 if (!items.isEmpty())
343 delete items.first();
344
345 /* [Re]insert it into the tree: */
346 CExtPackManager comManager = uiCommon().virtualBox().GetExtensionPackManager();
347 const CExtPack comExtensionPack = comManager.Find(strName);
348 if (comExtensionPack.isOk())
349 {
350 /* Load extension pack data: */
351 UIDataExtensionPack extensionPackData;
352 loadExtensionPack(comExtensionPack, extensionPackData);
353 createItemForExtensionPack(extensionPackData, true /* choose item? */);
354 }
355}
356
357void UIExtensionPackManagerWidget::sltHandleExtensionPackUninstalled(const QString &strName)
358{
359 /* Make sure the name was set: */
360 if (strName.isNull())
361 return;
362
363 /* Look for a list of items matching strName: */
364 const QList<QTreeWidgetItem*> items = m_pTreeWidget->findItems(strName, Qt::MatchCaseSensitive, ExtensionPackColumn_Name);
365 AssertReturnVoid(!items.isEmpty());
366 /* Remove first found item from the list: */
367 delete items.first();
368
369 /* Adjust tree-widget: */
370 sltAdjustTreeWidget();
371}
372
373void UIExtensionPackManagerWidget::prepare()
374{
375 /* Prepare self: */
376 uiCommon().setHelpKeyword(this, "ext-pack-manager");
377 /* Connect un/install event we get from IVirtualBox to UICommon since all
378 * ext pack installation events should go through its signal. Several
379 * other objects listen to those signals for menu update etc: */
380 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigExtensionPackInstalled,
381 &uiCommon(), &UICommon::sigExtensionPackInstalled);
382 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigExtensionPackUninstalled,
383 &uiCommon(), &UICommon::sigExtensionPackUninstalled);
384
385
386 connect(&uiCommon(), &UICommon::sigExtensionPackInstalled,
387 this, &UIExtensionPackManagerWidget::sltHandleExtensionPackInstalled);
388
389 /* Prepare stuff: */
390 prepareActions();
391 prepareWidgets();
392
393 /* Apply language settings: */
394 retranslateUi();
395
396 /* Load extension packs: */
397 loadExtensionPacks();
398}
399
400void UIExtensionPackManagerWidget::prepareActions()
401{
402 /* First of all, add actions which has smaller shortcut scope: */
403 addAction(m_pActionPool->action(UIActionIndexMN_M_Extension_S_Install));
404 addAction(m_pActionPool->action(UIActionIndexMN_M_Extension_S_Uninstall));
405
406 /* Connect actions: */
407 connect(m_pActionPool->action(UIActionIndexMN_M_Extension_S_Install), &QAction::triggered,
408 this, &UIExtensionPackManagerWidget::sltInstallExtensionPack);
409 connect(m_pActionPool->action(UIActionIndexMN_M_Extension_S_Uninstall), &QAction::triggered,
410 this, &UIExtensionPackManagerWidget::sltUninstallExtensionPack);
411}
412
413void UIExtensionPackManagerWidget::prepareWidgets()
414{
415 /* Create main-layout: */
416 new QVBoxLayout(this);
417 if (layout())
418 {
419 /* Configure layout: */
420 layout()->setContentsMargins(0, 0, 0, 0);
421#ifdef VBOX_WS_MAC
422 layout()->setSpacing(10);
423#else
424 layout()->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) / 2);
425#endif
426
427 /* Prepare toolbar, if requested: */
428 if (m_fShowToolbar)
429 prepareToolBar();
430
431 /* Prepare tree-widget: */
432 prepareTreeWidget();
433 }
434}
435
436void UIExtensionPackManagerWidget::prepareToolBar()
437{
438 /* Prepare toolbar: */
439 m_pToolBar = new QIToolBar(parentWidget());
440 if (m_pToolBar)
441 {
442 const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize));
443 m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
444 m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
445 m_pToolBar->addAction(m_pActionPool->action(UIActionIndexMN_M_Extension_S_Install));
446 m_pToolBar->addAction(m_pActionPool->action(UIActionIndexMN_M_Extension_S_Uninstall));
447
448#ifdef VBOX_WS_MAC
449 /* Check whether we are embedded into a stack: */
450 if (m_enmEmbedding == EmbedTo_Stack)
451 {
452 /* Add into layout: */
453 layout()->addWidget(m_pToolBar);
454 }
455#else
456 /* Add into layout: */
457 layout()->addWidget(m_pToolBar);
458#endif
459 }
460}
461
462void UIExtensionPackManagerWidget::prepareTreeWidget()
463{
464 /* Prepare tree-widget: */
465 m_pTreeWidget = new QITreeWidget(this);
466 if (m_pTreeWidget)
467 {
468 m_pTreeWidget->setRootIsDecorated(false);
469 m_pTreeWidget->setAlternatingRowColors(true);
470 m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
471 m_pTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
472 m_pTreeWidget->setColumnCount(ExtensionPackColumn_Max);
473 m_pTreeWidget->setSortingEnabled(true);
474 m_pTreeWidget->sortByColumn(ExtensionPackColumn_Name, Qt::AscendingOrder);
475 m_pTreeWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
476 connect(m_pTreeWidget, &QITreeWidget::resized,
477 this, &UIExtensionPackManagerWidget::sltAdjustTreeWidget, Qt::QueuedConnection);
478 connect(m_pTreeWidget->header(), &QHeaderView::sectionResized,
479 this, &UIExtensionPackManagerWidget::sltAdjustTreeWidget, Qt::QueuedConnection);
480 connect(m_pTreeWidget, &QITreeWidget::currentItemChanged,
481 this, &UIExtensionPackManagerWidget::sltHandleCurrentItemChange);
482 connect(m_pTreeWidget, &QITreeWidget::customContextMenuRequested,
483 this, &UIExtensionPackManagerWidget::sltHandleContextMenuRequest);
484
485 /* Add into layout: */
486 layout()->addWidget(m_pTreeWidget);
487 }
488}
489
490void UIExtensionPackManagerWidget::loadExtensionPacks()
491{
492 /* Check tree-widget: */
493 if (!m_pTreeWidget)
494 return;
495
496 /* Clear tree first of all: */
497 m_pTreeWidget->clear();
498
499 /* Get VirtualBox for further activities: */
500 const CVirtualBox comVBox = uiCommon().virtualBox();
501 /* Get Extension Pack Manager for further activities: */
502 const CExtPackManager comEPManager = comVBox.GetExtensionPackManager();
503
504 /* Show error message if necessary: */
505 if (!comVBox.isOk())
506 UINotificationMessage::cannotGetExtensionPackManager(comVBox);
507 else
508 {
509 /* Get extension packs for further activities: */
510 const QVector<CExtPack> extensionPacks = comEPManager.GetInstalledExtPacks();
511
512 /* Show error message if necessary: */
513 if (!comEPManager.isOk())
514 UINotificationMessage::cannotAcquireExtensionPackManagerParameter(comEPManager);
515 else
516 {
517 /* Iterate through existing extension packs: */
518 foreach (const CExtPack &comExtensionPack, extensionPacks)
519 {
520 /* Skip if we have nothing to populate: */
521 if (comExtensionPack.isNull())
522 continue;
523
524 /* Load extension pack data: */
525 UIDataExtensionPack extensionPackData;
526 loadExtensionPack(comExtensionPack, extensionPackData);
527 createItemForExtensionPack(extensionPackData, false /* choose item? */);
528 }
529
530 /* Choose the 1st item as current if nothing chosen: */
531 if (!m_pTreeWidget->currentItem())
532 m_pTreeWidget->setCurrentItem(m_pTreeWidget->topLevelItem(0));
533 /* Handle current item change in any case: */
534 sltHandleCurrentItemChange();
535 }
536 }
537}
538
539void UIExtensionPackManagerWidget::loadExtensionPack(const CExtPack &comExtensionPack, UIDataExtensionPack &extensionPackData)
540{
541 /* Gather extension pack settings: */
542 if (comExtensionPack.isOk())
543 extensionPackData.m_strName = comExtensionPack.GetName();
544 if (comExtensionPack.isOk())
545 extensionPackData.m_strDescription = comExtensionPack.GetDescription();
546 if (comExtensionPack.isOk())
547 extensionPackData.m_strVersion = comExtensionPack.GetVersion();
548 if (comExtensionPack.isOk())
549 extensionPackData.m_uRevision = comExtensionPack.GetRevision();
550 if (comExtensionPack.isOk())
551 {
552 extensionPackData.m_fIsUsable = comExtensionPack.GetUsable();
553 if (!extensionPackData.m_fIsUsable && comExtensionPack.isOk())
554 extensionPackData.m_strWhyUnusable = comExtensionPack.GetWhyUnusable();
555 }
556
557 /* Show error message if necessary: */
558 if (!comExtensionPack.isOk())
559 UINotificationMessage::cannotAcquireExtensionPackParameter(comExtensionPack);
560}
561
562void UIExtensionPackManagerWidget::createItemForExtensionPack(const UIDataExtensionPack &extensionPackData, bool fChooseItem)
563{
564 /* Prepare new provider item: */
565 UIItemExtensionPack *pItem = new UIItemExtensionPack;
566 if (pItem)
567 {
568 pItem->UIDataExtensionPack::operator=(extensionPackData);
569 pItem->updateFields();
570
571 /* Add item to the tree: */
572 m_pTreeWidget->addTopLevelItem(pItem);
573
574 /* And choose it as current if necessary: */
575 if (fChooseItem)
576 m_pTreeWidget->setCurrentItem(pItem);
577 }
578}
579
580
581/*********************************************************************************************************************************
582* Class UIExtensionPackManagerFactory implementation. *
583*********************************************************************************************************************************/
584
585UIExtensionPackManagerFactory::UIExtensionPackManagerFactory(UIActionPool *pActionPool /* = 0 */)
586 : m_pActionPool(pActionPool)
587{
588}
589
590void UIExtensionPackManagerFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
591{
592 pDialog = new UIExtensionPackManager(pCenterWidget, m_pActionPool);
593}
594
595
596/*********************************************************************************************************************************
597* Class UIExtensionPackManager implementation. *
598*********************************************************************************************************************************/
599
600UIExtensionPackManager::UIExtensionPackManager(QWidget *pCenterWidget, UIActionPool *pActionPool)
601 : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
602 , m_pActionPool(pActionPool)
603{
604}
605
606void UIExtensionPackManager::retranslateUi()
607{
608 /* Translate window title: */
609 setWindowTitle(tr("Extension Pack Manager"));
610
611 /* Translate buttons: */
612 button(ButtonType_Close)->setText(tr("Close"));
613 button(ButtonType_Help)->setText(tr("Help"));
614 button(ButtonType_Close)->setStatusTip(tr("Close dialog"));
615 button(ButtonType_Help)->setStatusTip(tr("Show dialog help"));
616 button(ButtonType_Close)->setShortcut(Qt::Key_Escape);
617 button(ButtonType_Help)->setShortcut(QKeySequence::HelpContents);
618 button(ButtonType_Close)->setToolTip(tr("Close Window (%1)").arg(button(ButtonType_Close)->shortcut().toString()));
619 button(ButtonType_Help)->setToolTip(tr("Show Help (%1)").arg(button(ButtonType_Help)->shortcut().toString()));
620}
621
622void UIExtensionPackManager::configure()
623{
624#ifndef VBOX_WS_MAC
625 /* Assign window icon: */
626 setWindowIcon(UIIconPool::iconSetFull(":/extension_pack_manager_24px.png", ":/extension_pack_manager_16px.png"));
627#endif
628}
629
630void UIExtensionPackManager::configureCentralWidget()
631{
632 /* Prepare widget: */
633 UIExtensionPackManagerWidget *pWidget = new UIExtensionPackManagerWidget(EmbedTo_Dialog, m_pActionPool, true, this);
634 if (pWidget)
635 {
636 setWidget(pWidget);
637 setWidgetMenu(pWidget->menu());
638#ifdef VBOX_WS_MAC
639 setWidgetToolbar(pWidget->toolbar());
640#endif
641
642 /* Add into layout: */
643 centralWidget()->layout()->addWidget(pWidget);
644 }
645}
646
647void UIExtensionPackManager::finalize()
648{
649 /* Apply language settings: */
650 retranslateUi();
651}
652
653UIExtensionPackManagerWidget *UIExtensionPackManager::widget()
654{
655 return qobject_cast<UIExtensionPackManagerWidget*>(QIManagerDialog::widget());
656}
657
658
659#include "UIExtensionPackManager.moc"
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