VirtualBox

Changeset 34543 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 1, 2010 12:32:54 AM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: 5386: Extension pack GUI: Initial implementation.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
6 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r34479 r34543  
    301301        src/settings/global/UIGlobalSettingsNetwork.h \
    302302        src/settings/global/UIGlobalSettingsNetworkDetails.h \
     303        src/settings/global/UIGlobalSettingsExtension.h \
    303304        src/settings/machine/UIMachineSettingsGeneral.h \
    304305        src/settings/machine/UIMachineSettingsSystem.h \
     
    464465        src/settings/global/UIGlobalSettingsNetwork.cpp \
    465466        src/settings/global/UIGlobalSettingsNetworkDetails.cpp \
     467        src/settings/global/UIGlobalSettingsExtension.cpp \
    466468        src/settings/machine/UIMachineSettingsGeneral.cpp \
    467469        src/settings/machine/UIMachineSettingsSystem.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/VBoxUI.pro

    r33882 r34543  
    3535    src/settings/global/UIGlobalSettingsNetwork.ui \
    3636    src/settings/global/UIGlobalSettingsNetworkDetails.ui \
     37    src/settings/global/UIGlobalSettingsExtension.ui \
    3738    src/settings/machine/UIMachineSettingsGeneral.ui \
    3839    src/settings/machine/UIMachineSettingsSystem.ui \
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxProblemReporter.cpp

    r34519 r34543  
    24182418}
    24192419
     2420void VBoxProblemReporter::cannotUninstallExtPack(const QString &strPackName, const CExtPackManager &extPackManager, QWidget *pParent /* = 0 */)
     2421{
     2422    message (pParent ? pParent : mainWindowShown(),
     2423             Error,
     2424             tr("Failed to uninstall the Extension Pack <b>%1</b>.").arg(strPackName),
     2425             formatErrorInfo(extPackManager));
     2426}
     2427
     2428bool VBoxProblemReporter::confirmRemovingPackage(const QString &strPackName, QWidget *pParent /* = 0 */)
     2429{
     2430    return messageOkCancel (pParent ? pParent : mainWindowShown(),
     2431                            Question,
     2432                            tr("You are about to remove the Extension Pack <b>%1</b>. Are you sure you want to do that?").arg(strPackName),
     2433                            0,
     2434                            tr("&Remove"));
     2435}
     2436
    24202437void VBoxProblemReporter::warnAboutIncorrectPort (QWidget *pParent) const
    24212438{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxProblemReporter.h

    r34519 r34543  
    384384
    385385    void cannotInstallExtPack(const QString &strFilename, const CExtPackManager &extPackManager, QWidget *pParent = 0);
     386    void cannotUninstallExtPack(const QString &strPackName, const CExtPackManager &extPackManager, QWidget *pParent = 0);
     387    bool confirmRemovingPackage(const QString &strPackName, QWidget *pParent = 0);
    386388
    387389    void warnAboutIncorrectPort(QWidget *pParent) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

    r33932 r34543  
    3737#include "UIGlobalSettingsLanguage.h"
    3838#include "UIGlobalSettingsNetwork.h"
     39#include "UIGlobalSettingsExtension.h"
    3940
    4041#include "UIMachineSettingsGeneral.h"
     
    360361                    break;
    361362                }
     363                /* Extension page: */
     364                case GLSettingsPage_Extension:
     365                {
     366                    UISettingsPage *pSettingsPage = new UIGlobalSettingsExtension;
     367                    pSettingsPage->setId(i);
     368                    addItem(":/shared_folder_32px.png", ":/shared_folder_disabled_32px.png",
     369                            ":/shared_folder_16px.png", ":/shared_folder_disabled_16px.png",
     370                            i, "#extension", pSettingsPage);
     371                    break;
     372                }
    362373                default:
    363374                    break;
     
    441452    m_pSelector->setItemText(GLSettingsPage_Network, tr("Network"));
    442453
     454    /* Extension page: */
     455    m_pSelector->setItemText(GLSettingsPage_Extension, tr("Extensions"));
     456
    443457    /* Translate the selector: */
    444458    m_pSelector->polish();
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h

    r33631 r34543  
    3939        GLSettingsPage_USB,
    4040        GLSettingsPage_Network,
     41        GLSettingsPage_Extension,
    4142        GLSettingsPage_MAX
    4243    };
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.cpp

    r34512 r34543  
    33 *
    44 * VBox frontends: Qt4 GUI ("VirtualBox"):
    5  * UIGlobalSettingsLanguage class implementation
     5 * UIGlobalSettingsExtension class implementation
    66 */
    77
    88/*
    9  * Copyright (C) 2006-2010 Oracle Corporation
     9 * Copyright (C) 2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1919
    2020/* Global includes */
    21 #include <QDir>
    2221#include <QHeaderView>
    23 #include <QPainter>
    24 #include <QTranslator>
    25 
    26 #include <iprt/err.h>
    27 #include <iprt/param.h>
    28 #include <iprt/path.h>
    29 #include <VBox/version.h>
    3022
    3123/* Local includes */
    32 #include "UIGlobalSettingsLanguage.h"
    33 #include "VBoxGlobalSettings.h"
     24#include "UIGlobalSettingsExtension.h"
     25#include "UIIconPool.h"
     26#include "QIFileDialog.h"
    3427#include "VBoxGlobal.h"
    35 
    36 extern const char *gVBoxLangSubDir;
    37 extern const char *gVBoxLangFileBase;
    38 extern const char *gVBoxLangFileExt;
    39 extern const char *gVBoxLangIDRegExp;
    40 extern const char *gVBoxBuiltInLangName;
    41 
    42 /* Language item: */
    43 class UILanguageItem : public QTreeWidgetItem
     28#include "VBoxProblemReporter.h"
     29
     30/* Extension package item: */
     31class UIExtensionPackageItem : public QTreeWidgetItem
    4432{
    4533public:
    4634
    47     /* Language item type: */
    48     enum { UILanguageItemType = QTreeWidgetItem::UserType + 1 };
    49 
    50     /* Language item constructor: */
    51     UILanguageItem(QTreeWidget *pParent, const QTranslator &translator,
    52                    const QString &strId, bool fBuiltIn = false)
    53         : QTreeWidgetItem(pParent, UILanguageItemType), m_fBuiltIn(fBuiltIn)
    54     {
    55         Assert (!strId.isEmpty());
    56 
    57         /* Note: context/source/comment arguments below must match strings
    58          * used in VBoxGlobal::languageName() and friends (the latter are the
    59          * source of information for the lupdate tool that generates
    60          * translation files) */
    61 
    62         QString strNativeLanguage = tratra(translator, "@@@", "English", "Native language name");
    63         QString strNativeCountry = tratra(translator, "@@@", "--", "Native language country name "
    64                                                                    "(empty if this language is for all countries)");
    65 
    66         QString strEnglishLanguage = tratra(translator, "@@@", "English", "Language name, in English");
    67         QString strEnglishCountry = tratra(translator, "@@@", "--", "Language country name, in English "
    68                                                                     "(empty if native country name is empty)");
    69 
    70         QString strTranslatorsName = tratra(translator, "@@@", "Oracle Corporation", "Comma-separated list of translators");
    71 
    72         QString strItemName = strNativeLanguage;
    73         QString strLanguageName = strEnglishLanguage;
    74 
    75         if (!m_fBuiltIn)
     35    /* Extension package item type: */
     36    enum { UIItemType = QTreeWidgetItem::UserType + 1 };
     37
     38    /* Extension package item constructor: */
     39    UIExtensionPackageItem(QTreeWidget *pParent, const UISettingsCacheGlobalExtensionItem &data)
     40        : QTreeWidgetItem(pParent, UIItemType)
     41        , m_data(data)
     42    {
     43        /* Icon: */
     44        setIcon(0, UIIconPool::iconSet(m_data.m_fIsUsable ?
     45                                       ":/shared_folder_16px.png" :
     46                                       ":/shared_folder_disabled_16px.png"));
     47
     48        /* Name: */
     49        setText(1, m_data.m_strName);
     50
     51        /* Version: */
     52        setText(2, m_data.m_strVersion);
     53
     54        /* Tool-tip: */
     55        QString strTip = m_data.m_strDescription;
     56        if (!m_data.m_fIsUsable)
    7657        {
    77             if (strNativeCountry != "--")
    78                 strItemName += " (" + strNativeCountry + ")";
    79 
    80             if (strEnglishCountry != "--")
    81                 strLanguageName += " (" + strEnglishCountry + ")";
    82 
    83             if (strItemName != strLanguageName)
    84                 strLanguageName = strItemName + " / " + strLanguageName;
     58            strTip += QString("<hr>");
     59            strTip += m_data.m_strWhyUnusable;
    8560        }
    86         else
    87         {
    88             strItemName += UIGlobalSettingsLanguage::tr(" (built-in)", "Language");
    89             strLanguageName += UIGlobalSettingsLanguage::tr(" (built-in)", "Language");
    90         }
    91 
    92         setText(0, strItemName);
    93         setText(1, strId);
    94         setText(2, strLanguageName);
    95         setText(3, strTranslatorsName);
    96 
    97         /* Current language appears in bold: */
    98         if (text(1) == VBoxGlobal::languageId())
    99         {
    100             QFont fnt = font(0);
    101             fnt.setBold(true);
    102             setFont(0, fnt);
    103         }
    104     }
    105 
    106     /* Constructs an item for an invalid language ID
    107      * (i.e. when a language file is missing or corrupt): */
    108     UILanguageItem(QTreeWidget *pParent, const QString &strId)
    109         : QTreeWidgetItem(pParent, UILanguageItemType), m_fBuiltIn(false)
    110     {
    111         Assert(!strId.isEmpty());
    112 
    113         setText(0, QString("<%1>").arg(strId));
    114         setText(1, strId);
    115         setText(2, UIGlobalSettingsLanguage::tr("<unavailable>", "Language"));
    116         setText(3, UIGlobalSettingsLanguage::tr("<unknown>", "Author(s)"));
    117 
    118         /* Invalid language appears in italic: */
    119         QFont fnt = font(0);
    120         fnt.setItalic(true);
    121         setFont(0, fnt);
    122     }
    123 
    124     /* Constructs an item for the default language ID
    125      * (column 1 will be set to QString::null): */
    126     UILanguageItem(QTreeWidget *pParent)
    127         : QTreeWidgetItem(pParent, UILanguageItemType), m_fBuiltIn(false)
    128     {
    129         setText(0, UIGlobalSettingsLanguage::tr("Default", "Language"));
    130         setText(1, QString::null);
    131         /* Empty strings of some reasonable length to prevent the info part
    132          * from being shrinked too much when the list wants to be wider */
    133         setText(2, "                ");
    134         setText(3, "                ");
    135     }
    136 
    137     bool isBuiltIn() const { return m_fBuiltIn; }
    138 
    139     bool operator<(const QTreeWidgetItem &other) const
    140     {
    141         QString thisId = text(1);
    142         QString thatId = other.text(1);
    143         if (thisId.isNull())
    144             return true;
    145         if (thatId.isNull())
    146             return false;
    147         if (m_fBuiltIn)
    148             return true;
    149         if (other.type() == UILanguageItemType && ((UILanguageItem*)&other)->m_fBuiltIn)
    150             return false;
    151         return QTreeWidgetItem::operator<(other);
    152     }
     61        setToolTip(0, strTip);
     62        setToolTip(1, strTip);
     63        setToolTip(2, strTip);
     64    }
     65
     66    QString name() const { return m_data.m_strName; }
    15367
    15468private:
    15569
    156     QString tratra(const QTranslator &translator, const char *pCtxt,
    157                    const char *pSrc, const char *pCmnt)
    158     {
    159         QString strMsg = translator.translate(pCtxt, pSrc, pCmnt);
    160         /* Return the source text if no translation is found: */
    161         if (strMsg.isEmpty())
    162             strMsg = QString(pSrc);
    163         return strMsg;
    164     }
    165 
    166     bool m_fBuiltIn : 1;
     70    UISettingsCacheGlobalExtensionItem m_data;
    16771};
    16872
    169 /* Language page constructor: */
    170 UIGlobalSettingsLanguage::UIGlobalSettingsLanguage()
    171     : m_fIsLanguageChanged(false)
     73/* Extension page constructor: */
     74UIGlobalSettingsExtension::UIGlobalSettingsExtension()
     75    : m_pActionAdd(0), m_pActionRemove(0)
    17276{
    17377    /* Apply UI decorations: */
    174     Ui::UIGlobalSettingsLanguage::setupUi(this);
    175 
    176     /* Setup widgets: */
    177     m_pLanguageTree->header()->hide();
    178     m_pLanguageTree->hideColumn(1);
    179     m_pLanguageTree->hideColumn(2);
    180     m_pLanguageTree->hideColumn(3);
    181 
    182     /* Setup connections: */
    183     connect(m_pLanguageTree, SIGNAL(painted(QTreeWidgetItem*, QPainter*)),
    184             this, SLOT(sltLanguageItemPainted(QTreeWidgetItem*, QPainter*)));
    185     connect(m_pLanguageTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    186             this, SLOT(sltCurrentLanguageChanged(QTreeWidgetItem*)));
     78    Ui::UIGlobalSettingsExtension::setupUi(this);
     79
     80    /* Setup tree-widget: */
     81    //m_pPackagesTree->header()->hide();
     82    m_pPackagesTree->header()->setStretchLastSection(false);
     83    m_pPackagesTree->header()->setResizeMode(0, QHeaderView::ResizeToContents);
     84    m_pPackagesTree->header()->setResizeMode(1, QHeaderView::Stretch);
     85    m_pPackagesTree->header()->setResizeMode(2, QHeaderView::ResizeToContents);
     86    m_pPackagesTree->setContextMenuPolicy(Qt::CustomContextMenu);
     87    connect(m_pPackagesTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
     88            this, SLOT(sltHandleCurrentItemChange(QTreeWidgetItem*)));
     89    connect(m_pPackagesTree, SIGNAL(customContextMenuRequested(const QPoint&)),
     90            this, SLOT(sltShowContextMenu(const QPoint&)));
     91
     92    /* Setup tool-bar: */
     93    m_pPackagesToolbar->setUsesTextLabel(false);
     94    m_pPackagesToolbar->setIconSize(QSize(16, 16));
     95    m_pActionAdd = m_pPackagesToolbar->addAction(UIIconPool::iconSet(":/controller_add_16px.png",
     96                                                                     ":/controller_add_disabled_16px.png"),
     97                                                 QString(), this, SLOT(sltInstallPackage()));
     98    m_pActionRemove = m_pPackagesToolbar->addAction(UIIconPool::iconSet(":/controller_remove_16px.png",
     99                                                                        ":/controller_remove_disabled_16px.png"),
     100                                                    QString(), this, SLOT(sltRemovePackage()));
    187101
    188102    /* Apply language settings: */
     
    192106/* Load data to cashe from corresponding external object(s),
    193107 * this task COULD be performed in other than GUI thread: */
    194 void UIGlobalSettingsLanguage::loadToCacheFrom(QVariant &data)
     108void UIGlobalSettingsExtension::loadToCacheFrom(QVariant &data)
    195109{
    196110    /* Fetch data to properties & settings: */
     
    198112
    199113    /* Load to cache: */
    200     m_cache.m_strLanguageId = m_settings.languageId();
     114    const CExtPackManager &manager = vboxGlobal().virtualBox().GetExtensionPackManager();
     115    const CExtPackVector &packages = manager.GetInstalledExtPacks();
     116    for (int i = 0; i < packages.size(); ++i)
     117        m_cache.m_items << fetchData(packages[i]);
    201118
    202119    /* Upload properties & settings to data: */
     
    206123/* Load data to corresponding widgets from cache,
    207124 * this task SHOULD be performed in GUI thread only: */
    208 void UIGlobalSettingsLanguage::getFromCache()
     125void UIGlobalSettingsExtension::getFromCache()
    209126{
    210127    /* Fetch from cache: */
    211     reload(m_cache.m_strLanguageId);
    212     m_pLanguageInfo->setFixedHeight(fontMetrics().height() * 4);
     128    for (int i = 0; i < m_cache.m_items.size(); ++i)
     129        new UIExtensionPackageItem(m_pPackagesTree, m_cache.m_items[i]);
     130    /* If at least one item present: */
     131    if (m_pPackagesTree->topLevelItemCount())
     132        m_pPackagesTree->setCurrentItem(m_pPackagesTree->topLevelItem(0));
     133    /* Update action's availability: */
     134    sltHandleCurrentItemChange(m_pPackagesTree->currentItem());
    213135}
    214136
    215137/* Save data from corresponding widgets to cache,
    216138 * this task SHOULD be performed in GUI thread only: */
    217 void UIGlobalSettingsLanguage::putToCache()
    218 {
    219     /* Upload to cache: */
    220     QTreeWidgetItem *pCurrentItem = m_pLanguageTree->currentItem();
    221     Assert(pCurrentItem);
    222     if (pCurrentItem)
    223         m_cache.m_strLanguageId = pCurrentItem->text(1);
     139void UIGlobalSettingsExtension::putToCache()
     140{
     141    /* Nothing to put to cache... */
    224142}
    225143
    226144/* Save data from cache to corresponding external object(s),
    227145 * this task COULD be performed in other than GUI thread: */
    228 void UIGlobalSettingsLanguage::saveFromCacheTo(QVariant &data)
     146void UIGlobalSettingsExtension::saveFromCacheTo(QVariant &data)
    229147{
    230148    /* Fetch data to properties & settings: */
    231149    UISettingsPageGlobal::fetchData(data);
    232150
    233     /* Save from cache: */
    234     if (m_fIsLanguageChanged)
    235     {
    236         m_settings.setLanguageId(m_cache.m_strLanguageId);
    237         VBoxGlobal::loadLanguage(m_cache.m_strLanguageId);
    238     }
     151    /* Nothing to save from cache... */
    239152
    240153    /* Upload properties & settings to data: */
     
    243156
    244157/* Navigation stuff: */
    245 void UIGlobalSettingsLanguage::setOrderAfter(QWidget *pWidget)
    246 {
    247     setTabOrder(pWidget, m_pLanguageTree);
     158void UIGlobalSettingsExtension::setOrderAfter(QWidget *pWidget)
     159{
     160    /* Setup tab-order: */
     161    setTabOrder(pWidget, m_pPackagesTree);
    248162}
    249163
    250164/* Translation stuff: */
    251 void UIGlobalSettingsLanguage::retranslateUi()
     165void UIGlobalSettingsExtension::retranslateUi()
    252166{
    253167    /* Translate uic generated strings: */
    254     Ui::UIGlobalSettingsLanguage::retranslateUi(this);
    255 
    256     /* Reload language tree: */
    257     reload(VBoxGlobal::languageId());
    258 }
    259 
    260 /* Reload language tree: */
    261 void UIGlobalSettingsLanguage::reload(const QString &strLangId)
    262 {
    263     /* Clear languages tree: */
    264     m_pLanguageTree->clear();
    265 
    266     /* Load languages tree: */
    267     char szNlsPath[RTPATH_MAX];
    268     int rc = RTPathAppPrivateNoArch(szNlsPath, sizeof(szNlsPath));
    269     AssertRC(rc);
    270     QString strNlsPath = QString(szNlsPath) + gVBoxLangSubDir;
    271     QDir nlsDir(strNlsPath);
    272     QStringList files = nlsDir.entryList(QStringList(QString("%1*%2").arg(gVBoxLangFileBase, gVBoxLangFileExt)), QDir::Files);
    273 
    274     QTranslator translator;
    275     /* Add the default language: */
    276     new UILanguageItem(m_pLanguageTree);
    277     /* Add the built-in language: */
    278     new UILanguageItem(m_pLanguageTree, translator, gVBoxBuiltInLangName, true /* built-in */);
    279     /* Add all existing languages */
    280     for (QStringList::Iterator it = files.begin(); it != files.end(); ++it)
    281     {
    282         QString strFileName = *it;
    283         QRegExp regExp(QString(gVBoxLangFileBase) + gVBoxLangIDRegExp);
    284         int iPos = regExp.indexIn(strFileName);
    285         if (iPos == -1)
    286             continue;
    287 
    288         /* Skip any English version, cause this is extra handled: */
    289         QString strLanguage = regExp.cap(2);
    290         if (strLanguage.toLower() == "en")
    291             continue;
    292 
    293         bool fLoadOk = translator.load(strFileName, strNlsPath);
    294         if (!fLoadOk)
    295             continue;
    296 
    297         new UILanguageItem(m_pLanguageTree, translator, regExp.cap(1));
    298     }
    299 
    300     /* Adjust selector list: */
    301 #ifdef Q_WS_MAC
    302     int width = qMax(static_cast<QAbstractItemView*>(m_pLanguageTree)->sizeHintForColumn(0) +
    303                      2 * m_pLanguageTree->frameWidth() + QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent),
    304                      220);
    305     m_pLanguageTree->setFixedWidth(width);
    306 #else /* Q_WS_MAC */
    307     m_pLanguageTree->setMinimumWidth(static_cast<QAbstractItemView*>(m_pLanguageTree)->sizeHintForColumn(0) +
    308                                      2 * m_pLanguageTree->frameWidth() + QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent));
    309 #endif /* Q_WS_MAC */
    310     m_pLanguageTree->resizeColumnToContents(0);
    311 
    312     /* Search for necessary language: */
    313     QList<QTreeWidgetItem*> itemsList = m_pLanguageTree->findItems(strLangId, Qt::MatchExactly, 1);
    314     QTreeWidgetItem *pItem = itemsList.isEmpty() ? 0 : itemsList[0];
    315     if (!pItem)
    316     {
    317         /* Add an pItem for an invalid language to represent it in the list: */
    318         pItem = new UILanguageItem(m_pLanguageTree, strLangId);
    319         m_pLanguageTree->resizeColumnToContents(0);
    320     }
    321     Assert(pItem);
     168    Ui::UIGlobalSettingsExtension::retranslateUi(this);
     169
     170    /* Translate actions: */
     171    m_pActionAdd->setText(tr("Add package"));
     172    m_pActionRemove->setText(tr("Remove package"));
     173}
     174
     175/* Handle current-item change fact: */
     176void UIGlobalSettingsExtension::sltHandleCurrentItemChange(QTreeWidgetItem *pCurrentItem)
     177{
     178    /* Check action's availability: */
     179    //m_pActionAdd->setEnabled(true);
     180    m_pActionRemove->setEnabled(pCurrentItem);
     181}
     182
     183/* Invoke context menu: */
     184void UIGlobalSettingsExtension::sltShowContextMenu(const QPoint &position)
     185{
     186    QMenu menu;
     187    if (m_pPackagesTree->itemAt(position))
     188    {
     189        menu.addAction(m_pActionAdd);
     190        menu.addAction(m_pActionRemove);
     191    }
     192    else
     193    {
     194        menu.addAction(m_pActionAdd);
     195    }
     196    menu.exec(m_pPackagesTree->viewport()->mapToGlobal(position));
     197}
     198
     199/* Package add procedure: */
     200void UIGlobalSettingsExtension::sltInstallPackage()
     201{
     202    /* Open file-open window to let user to choose package file: */
     203    QString strFilePath;
     204    QString strBaseFolder = vboxGlobal().virtualBox().GetHomeFolder();
     205    QString strTitle = tr("Select an extension package file");
     206    QStringList extensions;
     207    for (int i = 0; i < VBoxDefs::VBoxExtPackFileExts.size(); ++i)
     208        extensions << QString("*.%1").arg(VBoxDefs::VBoxExtPackFileExts[i]);
     209    QString strFilter = tr("Extension package files (%1)").arg(extensions.join(" "));
     210    /* Create open file dialog: */
     211    QStringList fileNames = QIFileDialog::getOpenFileNames(strBaseFolder, strFilter, this, strTitle, 0, true, true);
     212    if (!fileNames.isEmpty())
     213        strFilePath = fileNames.at(0);
     214
     215    /* Install chosen package: */
     216    if (!strFilePath.isEmpty())
     217    {
     218        /* Get package manager: */
     219        CExtPackManager manager = vboxGlobal().virtualBox().GetExtensionPackManager();
     220        /* Install package & get the name of newly installed package: */
     221        QString strAddedPackageName = manager.Install(strFilePath);
     222        if (manager.isOk())
     223        {
     224            /* Get the newly added package: */
     225            const CExtPack &package = manager.Find(strAddedPackageName);
     226            /* Add newly added package into cache: */
     227            m_cache.m_items << fetchData(package);
     228            /* Add newly added package into tree: */
     229            UIExtensionPackageItem *pItem = new UIExtensionPackageItem(m_pPackagesTree, m_cache.m_items.last());
     230            /* Set the newly created item as current: */
     231            m_pPackagesTree->setCurrentItem(pItem);
     232            /* Sort the tree by <name> column: */
     233            m_pPackagesTree->sortByColumn(1, Qt::AscendingOrder);
     234        }
     235        else vboxProblem().cannotInstallExtPack(strFilePath, manager, this);
     236    }
     237}
     238
     239/* Package remove procedure: */
     240void UIGlobalSettingsExtension::sltRemovePackage()
     241{
     242    /* Get current item: */
     243    UIExtensionPackageItem *pItem = m_pPackagesTree &&
     244                                    m_pPackagesTree->currentItem() &&
     245                                    m_pPackagesTree->currentItem()->type() == UIExtensionPackageItem::UIItemType ?
     246                                    static_cast<UIExtensionPackageItem*>(m_pPackagesTree->currentItem()) : 0;
     247
     248    /* Uninstall chosen package: */
    322249    if (pItem)
    323         m_pLanguageTree->setCurrentItem(pItem);
    324 
    325     m_pLanguageTree->sortItems(0, Qt::AscendingOrder);
    326     m_pLanguageTree->scrollToItem(pItem);
    327     m_fIsLanguageChanged = false;
    328 }
    329 
    330 /* Routine to paint language items: */
    331 void UIGlobalSettingsLanguage::sltLanguageItemPainted(QTreeWidgetItem *pItem, QPainter *pPainter)
    332 {
    333     if (pItem && pItem->type() == UILanguageItem::UILanguageItemType)
    334     {
    335         UILanguageItem *pLanguageItem = static_cast<UILanguageItem*>(pItem);
    336         if (pLanguageItem->isBuiltIn())
     250    {
     251        /* Get name of current package: */
     252        QString strSelectedPackageName = pItem->name();
     253        /* Ask the user about package removing: */
     254        if (vboxProblem().confirmRemovingPackage(strSelectedPackageName, this))
    337255        {
    338             QRect rect = m_pLanguageTree->visualItemRect(pLanguageItem);
    339             pPainter->setPen(m_pLanguageTree->palette().color(QPalette::Mid));
    340             pPainter->drawLine(rect.x(), rect.y() + rect.height() - 1,
    341                                rect.x() + rect.width(), rect.y() + rect.height() - 1);
     256            /* Get package manager: */
     257            CExtPackManager manager = vboxGlobal().virtualBox().GetExtensionPackManager();
     258            /* Uninstall package: */
     259            manager.Uninstall(strSelectedPackageName, false /* forced removal? */);
     260            if (manager.isOk())
     261            {
     262                /* Remove selected package from cache: */
     263                for (int i = 0; i < m_cache.m_items.size(); ++i)
     264                {
     265                    if (m_cache.m_items[i].m_strName == strSelectedPackageName)
     266                    {
     267                        m_cache.m_items.removeAt(i);
     268                        break;
     269                    }
     270                }
     271                /* Remove selected package from tree: */
     272                delete pItem;
     273            }
     274            else vboxProblem().cannotUninstallExtPack(strSelectedPackageName, manager, this);
    342275        }
    343276    }
    344277}
    345278
    346 /* Slot to handle currentl language change fact: */
    347 void UIGlobalSettingsLanguage::sltCurrentLanguageChanged(QTreeWidgetItem *pItem)
    348 {
    349     if (!pItem) return;
    350 
    351     /* Disable labels for the Default language item: */
    352     bool fEnabled = !pItem->text (1).isNull();
    353 
    354     m_pLanguageInfo->setEnabled(fEnabled);
    355     m_pLanguageInfo->setText(QString("<table>"
    356                              "<tr><td>%1&nbsp;</td><td>%2</td></tr>"
    357                              "<tr><td>%3&nbsp;</td><td>%4</td></tr>"
    358                              "</table>")
    359                              .arg(tr("Language:"))
    360                              .arg(pItem->text(2))
    361                              .arg(tr("Author(s):"))
    362                              .arg(pItem->text(3)));
    363 
    364     m_fIsLanguageChanged = true;
    365 }
    366 
     279UISettingsCacheGlobalExtensionItem UIGlobalSettingsExtension::fetchData(const CExtPack &package) const
     280{
     281    UISettingsCacheGlobalExtensionItem item;
     282    item.m_strName = package.GetName();
     283    item.m_strDescription = package.GetDescription();
     284    item.m_strVersion = package.GetVersion();
     285    item.m_strRevision = package.GetRevision();
     286    item.m_fIsUsable = package.GetUsable();
     287    if (!item.m_fIsUsable)
     288        item.m_strWhyUnusable = package.GetWhyUnusable();
     289    return item;
     290}
     291
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.h

    r34512 r34543  
    22 *
    33 * VBox frontends: Qt4 GUI ("VirtualBox"):
    4  * UIGlobalSettingsLanguage class declaration
     4 * UIGlobalSettingsExtension class declaration
    55 */
    66
    77/*
    8  * Copyright (C) 2006-2010 Oracle Corporation
     8 * Copyright (C) 2010 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717 */
    1818
    19 #ifndef __UIGlobalSettingsLanguage_h__
    20 #define __UIGlobalSettingsLanguage_h__
     19#ifndef __UIGlobalSettingsExtension_h__
     20#define __UIGlobalSettingsExtension_h__
    2121
    2222/* Local includes */
    2323#include "UISettingsPage.h"
    24 #include "UIGlobalSettingsLanguage.gen.h"
     24#include "UIGlobalSettingsExtension.gen.h"
    2525
    26 /* Global settings / Language page / Cache: */
    27 struct UISettingsCacheGlobalLanguage
     26/* Global settings / Extension page / Cache Item: */
     27struct UISettingsCacheGlobalExtensionItem
    2828{
    29     QString m_strLanguageId;
     29    QString m_strName;
     30    QString m_strDescription;
     31    QString m_strVersion;
     32    ULONG m_strRevision;
     33    bool m_fIsUsable;
     34    QString m_strWhyUnusable;
    3035};
    3136
    32 /* Global settings / Language page: */
    33 class UIGlobalSettingsLanguage : public UISettingsPageGlobal, public Ui::UIGlobalSettingsLanguage
     37/* Global settings / Extension page / Cache: */
     38struct UISettingsCacheGlobalExtension
     39{
     40    QList<UISettingsCacheGlobalExtensionItem> m_items;
     41};
     42
     43/* Global settings / Extension page: */
     44class UIGlobalSettingsExtension : public UISettingsPageGlobal, public Ui::UIGlobalSettingsExtension
    3445{
    3546    Q_OBJECT;
     
    3849
    3950    /* Constructor: */
    40     UIGlobalSettingsLanguage();
     51    UIGlobalSettingsExtension();
    4152
    4253protected:
     
    6273    void retranslateUi();
    6374
    64     /* Reload language tree: */
    65     void reload(const QString &strLangId);
    66 
    6775private slots:
    6876
    69     /* Routine to paint language items: */
    70     void sltLanguageItemPainted(QTreeWidgetItem *pItem, QPainter *pPainter);
     77    /* Tree-widget slots: */
     78    void sltHandleCurrentItemChange(QTreeWidgetItem *pCurrentItem);
     79    void sltShowContextMenu(const QPoint &position);
    7180
    72     /* Slot to handle current language change signal: */
    73     void sltCurrentLanguageChanged(QTreeWidgetItem *pItem);
     81    /* Package add/remove procedures: */
     82    void sltInstallPackage();
     83    void sltRemovePackage();
    7484
    7585private:
    7686
    77     /* Edited flag: */
    78     bool m_fIsLanguageChanged;
     87    /* Prepare UISettingsCacheGlobalExtensionItem basing on CExtPack: */
     88    UISettingsCacheGlobalExtensionItem fetchData(const CExtPack &package) const;
     89
     90    /* Actions: */
     91    QAction *m_pActionAdd;
     92    QAction *m_pActionRemove;
    7993
    8094    /* Cache: */
    81     UISettingsCacheGlobalLanguage m_cache;
     95    UISettingsCacheGlobalExtension m_cache;
    8296};
    8397
    84 #endif // __UIGlobalSettingsLanguage_h__
     98#endif // __UIGlobalSettingsExtension_h__
    8599
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.ui

    r34512 r34543  
    33 VBox frontends: Qt4 GUI ("VirtualBox"):
    44
    5      Copyright (C) 2008-2010 Oracle Corporation
     5     Copyright (C) 2010 Oracle Corporation
    66
    77     This file is part of VirtualBox Open Source Edition (OSE), as
     
    1313     hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1414 </comment>
    15  <class>UIGlobalSettingsLanguage</class>
    16  <widget class="QWidget" name="UIGlobalSettingsLanguage">
     15 <class>UIGlobalSettingsExtension</class>
     16 <widget class="QWidget" name="UIGlobalSettingsExtension">
    1717  <property name="geometry">
    1818   <rect>
     
    4646    <widget class="QLabel" name="m_pLanguageLabel">
    4747     <property name="text">
    48       <string>&amp;Interface Language:</string>
     48      <string>&amp;Extension Packages:</string>
    4949     </property>
    5050     <property name="buddy">
    51       <cstring>m_pLanguageTree</cstring>
     51      <cstring>m_pPackagesTree</cstring>
    5252     </property>
    5353    </widget>
     
    7070   </item>
    7171   <item row="1" column="2">
    72     <widget class="QITreeWidget" name="m_pLanguageTree">
    73      <property name="sizePolicy">
    74       <sizepolicy vsizetype="Expanding" hsizetype="Expanding">
    75        <horstretch>0</horstretch>
    76        <verstretch>0</verstretch>
    77       </sizepolicy>
     72    <layout class="QHBoxLayout" name="m_pLayout1">
     73     <property name="spacing">
     74      <number>1</number>
    7875     </property>
    79      <property name="minimumSize">
    80       <size>
    81        <width>0</width>
    82        <height>150</height>
    83       </size>
     76     <property name="margin">
     77      <number>0</number>
    8478     </property>
    85      <property name="whatsThis">
    86       <string>Lists all available user interface languages. The effective language is written in &lt;b>bold&lt;/b>. Select &lt;i>Default&lt;/i> to reset to the system default language.</string>
    87      </property>
    88      <property name="rootIsDecorated">
    89       <bool>false</bool>
    90      </property>
    91      <column>
    92       <property name="text">
    93        <string>Name</string>
    94       </property>
    95      </column>
    96      <column>
    97       <property name="text">
    98        <string>Id</string>
    99       </property>
    100      </column>
    101      <column>
    102       <property name="text">
    103        <string>Language</string>
    104       </property>
    105      </column>
    106      <column>
    107       <property name="text">
    108        <string>Author</string>
    109       </property>
    110      </column>
    111     </widget>
    112    </item>
    113    <item row="2" column="2">
    114     <widget class="QILabel" name="m_pLanguageInfo">
    115      <property name="sizePolicy">
    116       <sizepolicy vsizetype="Minimum" hsizetype="Expanding">
    117        <horstretch>0</horstretch>
    118        <verstretch>0</verstretch>
    119       </sizepolicy>
    120      </property>
    121      <property name="alignment">
    122       <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
    123      </property>
    124      <property name="wordWrap">
    125       <bool>true</bool>
    126      </property>
    127     </widget>
     79     <item>
     80      <widget class="QTreeWidget" name="m_pPackagesTree">
     81       <property name="sizePolicy">
     82        <sizepolicy vsizetype="Expanding" hsizetype="Expanding">
     83         <horstretch>0</horstretch>
     84         <verstretch>0</verstretch>
     85        </sizepolicy>
     86       </property>
     87       <property name="minimumSize">
     88        <size>
     89         <width>0</width>
     90         <height>150</height>
     91        </size>
     92       </property>
     93       <property name="whatsThis">
     94        <string>Lists all installed packages.</string>
     95       </property>
     96       <property name="rootIsDecorated">
     97        <bool>false</bool>
     98       </property>
     99       <column>
     100        <property name="text">
     101         <string>Active</string>
     102        </property>
     103       </column>
     104       <column>
     105        <property name="text">
     106         <string>Name</string>
     107        </property>
     108       </column>
     109       <column>
     110        <property name="text">
     111         <string>Version</string>
     112        </property>
     113       </column>
     114      </widget>
     115     </item>
     116     <item>
     117      <widget class="UIToolBar" name="m_pPackagesToolbar">
     118       <property name="orientation">
     119        <enum>Qt::Vertical</enum>
     120       </property>
     121      </widget>
     122     </item>
     123    </layout>
    128124   </item>
    129125  </layout>
     
    131127 <customwidgets>
    132128  <customwidget>
    133    <class>QITreeWidget</class>
    134    <extends>QTreeWidget</extends>
    135    <header>QITreeWidget.h</header>
    136   </customwidget>
    137   <customwidget>
    138    <class>QILabel</class>
    139    <extends>QLabel</extends>
    140    <header>QILabel.h</header>
     129   <class>UIToolBar</class>
     130   <extends>QToolBar</extends>
     131   <header>UIToolBar.h</header>
    141132  </customwidget>
    142133 </customwidgets>
Note: See TracChangeset for help on using the changeset viewer.

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