VirtualBox

Changeset 9886 in vbox


Ignore:
Timestamp:
Jun 23, 2008 3:12:24 PM (16 years ago)
Author:
vboxsync
Message:

Fe/Qt4: Language Global Settings ported. Global Settings now checks for USB page after ui retranslated due to Global Settings Selector updated in that case. Global Settings dialog is now fully ported.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
4 edited

Legend:

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

    r9866 r9886  
    410410VirtualBox_QT_UISRCS3 := $(filter-out ui/VBoxGlobalSettingsInput.ui,$(VirtualBox_QT_UISRCS3))
    411411VirtualBox_QT_UISRCS4 += ui/VBoxGlobalSettingsInput.ui
     412
     413VirtualBox_QT_UISRCS3 := $(filter-out ui/VBoxGlobalSettingsLanguage.ui,$(VirtualBox_QT_UISRCS3))
     414VirtualBox_QT_UISRCS4 += ui/VBoxGlobalSettingsLanguage.ui
    412415
    413416VirtualBox_QT_UISRCS3 := $(filter-out ui/VBoxGlobalSettingsDlg.ui,$(VirtualBox_QT_UISRCS3))
     
    577580        include/VBoxGlobalSettingsGeneral.h \
    578581        include/VBoxGlobalSettingsInput.h \
     582        include/VBoxGlobalSettingsLanguage.h \
    579583        include/VBoxGlobalSettingsDlg.h
    580584
     
    666670        src/VBoxGlobalSettingsGeneral.cpp \
    667671        src/VBoxGlobalSettingsInput.cpp \
     672        src/VBoxGlobalSettingsLanguage.cpp \
    668673        src/VBoxGlobalSettingsDlg.cpp
    669674
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobalSettingsDlg.h

    r9783 r9886  
    6969    QString pagePath (QWidget *aPage);
    7070    void setWarning (const QString &aWarning);
    71     void updateMediaShortcuts();
     71    void updateAvailability();
    7272
    7373    /* Common */
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobalSettingsDlg.cpp

    r9828 r9886  
    3636#include "VBoxGlobalSettingsInput.h"
    3737#include "VBoxVMSettingsUSB.h"
    38 //#include "VBoxGlobalSettingsLanguage.h"
     38#include "VBoxGlobalSettingsLanguage.h"
    3939
    4040#include "VBoxGlobal.h"
     
    4444#include <QTimer>
    4545#include <QPushButton>
     46
     47//#define ENABLE_GLOBAL_USB
    4648
    4749/**
     
    7274    return list.count() ? list [0] : 0;
    7375}
    74 
    75 // /* Language page */
    76 // /* Defined in VBoxGlobal.cpp */
    77 // extern const char *gVBoxLangSubDir;
    78 // extern const char *gVBoxLangFileBase;
    79 // extern const char *gVBoxLangFileExt;
    80 // extern const char *gVBoxLangIDRegExp;
    81 // extern const char *gVBoxBuiltInLangName;
    82 // class LanguageItem : public Q3ListViewItem
    83 // {
    84 // public:
    85 //
    86 //     enum { TypeId = 1001 };
    87 //
    88 //     LanguageItem (Q3ListView *aParent, const QTranslator &aTranslator,
    89 //                   const QString &aId, bool aBuiltIn = false)
    90 //         : Q3ListViewItem (aParent), mBuiltIn (aBuiltIn), mInvalid (false)
    91 //     {
    92 //         Assert (!aId.isEmpty());
    93 //
    94 // //        QTranslatorMessage transMes;
    95 //
    96 //         /* Note: context/source/comment arguments below must match strings
    97 //          * used in VBoxGlobal::languageName() and friends (the latter are the
    98 //          * source of information for the lupdate tool that generates
    99 //          * translation files) */
    100 //
    101 //         QString nativeLanguage = tratra (aTranslator,
    102 //             "@@@", "English", "Native language name");
    103 //         QString nativeCountry = tratra (aTranslator,
    104 //             "@@@", "--", "Native language country name "
    105 //             "(empty if this language is for all countries)");
    106 //
    107 //         QString englishLanguage = tratra (aTranslator,
    108 //             "@@@", "English", "Language name, in English");
    109 //         QString englishCountry = tratra (aTranslator,
    110 //             "@@@", "--", "Language country name, in English "
    111 //             "(empty if native country name is empty)");
    112 //
    113 //         QString translatorsName = tratra (aTranslator,
    114 //             "@@@", "Sun Microsystems, Inc.", "Comma-separated list of translators");
    115 //
    116 //         QString itemName = nativeLanguage;
    117 //         QString langName = englishLanguage;
    118 //
    119 //         if (!aBuiltIn)
    120 //         {
    121 //             if (nativeCountry != "--")
    122 //                 itemName += " (" + nativeCountry + ")";
    123 //
    124 //             if (englishCountry != "--")
    125 //                 langName += " (" + englishCountry + ")";
    126 //
    127 //             if (itemName != langName)
    128 //                 langName = itemName + " / " + langName;
    129 //         }
    130 //         else
    131 //         {
    132 //             itemName += VBoxGlobalSettingsDlg::tr (" (built-in)", "Language");
    133 //             langName += VBoxGlobalSettingsDlg::tr (" (built-in)", "Language");
    134 //         }
    135 //
    136 //         setText (0, itemName);
    137 //         setText (1, aId);
    138 //         setText (2, langName);
    139 //         setText (3, translatorsName);
    140 //     }
    141 //
    142 //     /* Constructs an item for an invalid language ID (i.e. when a language
    143 //      * file is missing or corrupt). */
    144 //     LanguageItem (Q3ListView *aParent, const QString &aId)
    145 //         : Q3ListViewItem (aParent), mBuiltIn (false), mInvalid (true)
    146 //     {
    147 //         Assert (!aId.isEmpty());
    148 //
    149 //         setText (0, QString ("<%1>").arg (aId));
    150 //         setText (1, aId);
    151 //         setText (2, VBoxGlobalSettingsDlg::tr ("<unavailable>", "Language"));
    152 //         setText (3, VBoxGlobalSettingsDlg::tr ("<unknown>", "Author(s)"));
    153 //     }
    154 //
    155 //     /* Constructs an item for the default language ID (column 1 will be set
    156 //      * to QString::null) */
    157 //     LanguageItem (Q3ListView *aParent)
    158 //         : Q3ListViewItem (aParent), mBuiltIn (false), mInvalid (false)
    159 //     {
    160 //         setText (0, VBoxGlobalSettingsDlg::tr ("Default", "Language"));
    161 //         setText (1, QString::null);
    162 //         /* empty strings of some reasonable length to prevent the info part
    163 //          * from being shrinked too much when the list wants to be wider */
    164 //         setText (2, "                ");
    165 //         setText (3, "                ");
    166 //     }
    167 //
    168 //     int rtti() const { return TypeId; }
    169 //
    170 //     int compare (Q3ListViewItem *aItem, int aColumn, bool aAscending) const
    171 //     {
    172 //         QString thisId = text (1);
    173 //         QString thatId = aItem->text (1);
    174 //         if (thisId.isNull())
    175 //             return -1;
    176 //         if (thatId.isNull())
    177 //             return 1;
    178 //         if (mBuiltIn)
    179 //             return -1;
    180 //         if (aItem->rtti() == TypeId && ((LanguageItem *) aItem)->mBuiltIn)
    181 //             return 1;
    182 //         return Q3ListViewItem::compare (aItem, aColumn, aAscending);
    183 //     }
    184 //
    185 //     void paintCell (QPainter *aPainter, const QColorGroup &aGroup,
    186 //                     int aColumn, int aWidth, int aAlign)
    187 //     {
    188 //         QFont font = aPainter->font();
    189 //
    190 //         if (mInvalid)
    191 //             font.setItalic (true);
    192 //         /* mark the effectively active language */
    193 //         if (text (1) == VBoxGlobal::languageId())
    194 //             font.setBold (true);
    195 //
    196 //         if (aPainter->font() != font)
    197 //             aPainter->setFont (font);
    198 //
    199 //         Q3ListViewItem::paintCell (aPainter, aGroup, aColumn, aWidth, aAlign);
    200 //
    201 //         if (mBuiltIn)
    202 //         {
    203 //             int y = height() - 1;
    204 //             aPainter->setPen (aGroup.mid());
    205 //             aPainter->drawLine (0, y, aWidth - 1, y);
    206 //         }
    207 //     }
    208 //
    209 //     int width (const QFontMetrics &aFM, const Q3ListView *aLV, int aC) const
    210 //     {
    211 //         QFont font = aLV->font();
    212 //
    213 //         if (mInvalid)
    214 //             font.setItalic (true);
    215 //         /* mark the effectively active language */
    216 //         if (text (1) == VBoxGlobal::languageId())
    217 //             font.setBold (true);
    218 //
    219 //         QFontMetrics fm = aFM;
    220 //         if (aLV->font() != font)
    221 //             fm = QFontMetrics (font);
    222 //
    223 //         return Q3ListViewItem::width (fm, aLV, aC);
    224 //     }
    225 //
    226 //     void setup ()
    227 //     {
    228 //         Q3ListViewItem::setup();
    229 //         if (mBuiltIn)
    230 //             setHeight (height() + 1);
    231 //     }
    232 //
    233 // private:
    234 //
    235 //     QString tratra (const QTranslator &aTranslator, const char *aCtxt,
    236 //                        const char *aSrc, const char *aCmnt)
    237 //     {
    238 // //#warning port me: check this
    239 //         QString msg = aTranslator.translate (aCtxt, aSrc, aCmnt);
    240 // //        QString msg = aTranslator.findMessage (aCtxt, aSrc, aCmnt).translation();
    241 //         /* return the source text if no translation is found */
    242 //         if (msg.isEmpty())
    243 //             msg = QString (aSrc);
    244 //         return msg;
    245 //     }
    246 //
    247 //     bool mBuiltIn : 1;
    248 //     bool mInvalid : 1;
    249 // };
    25076
    25177VBoxGlobalSettingsDlg::VBoxGlobalSettingsDlg (QWidget *aParent)
     
    298124             this, SLOT (settingsGroupChanged (QTreeWidgetItem *, QTreeWidgetItem*)));
    299125
    300 //     /* Language page */
    301 //     lvLanguages->header()->hide();
    302 //     lvLanguages->setSorting (0);
    303 //
    304 //     char szNlsPath[RTPATH_MAX];
    305 //     int rc = RTPathAppPrivateNoArch (szNlsPath, sizeof(szNlsPath));
    306 //     AssertRC (rc);
    307 //     QString nlsPath = QString (szNlsPath) + gVBoxLangSubDir;
    308 //     QDir nlsDir (nlsPath);
    309 //     QStringList files = nlsDir.entryList (QString ("%1*%2")
    310 //                                           .arg (gVBoxLangFileBase, gVBoxLangFileExt),
    311 //                                           QDir::Files);
    312 //     QTranslator translator;
    313 //     /* add the default language */
    314 //     new LanguageItem (lvLanguages);
    315 //     /* add the built-in language */
    316 //     new LanguageItem (lvLanguages, translator, gVBoxBuiltInLangName, true /* built-in */);
    317 //     /* add all existing languages */
    318 //     for (QStringList::Iterator it = files.begin(); it != files.end(); ++ it)
    319 //     {
    320 //         QString fileName = *it;
    321 //         QRegExp regExp (QString (gVBoxLangFileBase) + gVBoxLangIDRegExp);
    322 //         int pos = regExp.search (fileName);
    323 //         if (pos == -1)
    324 //             continue;
    325 //
    326 //         bool loadOk = translator.load (fileName, nlsPath);
    327 //         if (!loadOk)
    328 //             continue;
    329 //
    330 //         new LanguageItem (lvLanguages, translator, regExp.cap (1));
    331 //     }
    332 //     lvLanguages->adjustColumn (0);
    333 
    334126    /* Hide unnecessary columns and header */
    335127    mTwSelector->header()->hide();
     
    337129    mTwSelector->hideColumn (listView_Link);
    338130
    339     /* Adjust selector list */
    340     int minWid = 0;
    341     for (int i = 0; i < mTwSelector->topLevelItemCount(); ++ i)
    342     {
    343         QTreeWidgetItem *item = mTwSelector->topLevelItem (i);
    344         QFontMetrics fm (item->font (0));
    345         int wid = fm.width (item->text (0)) +
    346                   16 /* icon */ + 2 * 8 /* 2 margins */;
    347         minWid = wid > minWid ? wid : minWid;
    348         int hei = fm.height() > 16 ?
    349                   fm.height() /* text height */ :
    350                   16 /* icon */ + 2 * 2 /* 2 margins */;
    351         item->setSizeHint (0, QSize (wid, hei));
    352     }
    353     mTwSelector->setFixedWidth (minWid);
    354 
    355     /* Sort selector by the id column (to have pages in the desired order) */
    356     mTwSelector->sortItems (listView_Id, Qt::AscendingOrder);
    357 
    358131    /* Initially select the first settings page */
    359132    mTwSelector->setCurrentItem (mTwSelector->topLevelItem (0));
     
    370143                                     const VBoxGlobalSettings &aGs)
    371144{
    372 //     /* Language page */
    373 //     QString langId = gs.languageId();
    374 //     Q3ListViewItem *item = lvLanguages->findItem (langId, 1);
    375 //     if (!item)
    376 //     {
    377 //         /* add an item for an invalid language to represent it in the list */
    378 //         item = new LanguageItem (lvLanguages, langId);
    379 //         lvLanguages->adjustColumn (0);
    380 //     }
    381 //     Assert (item);
    382 //     if (item)
    383 //     {
    384 //         lvLanguages->setCurrentItem (item);
    385 //         lvLanguages->setSelected (item, true);
    386 //     }
    387 
    388145    /* General Page */
    389146    VBoxGlobalSettingsGeneral::getFrom (aProps, aGs, mPageGeneral, this);
     
    393150
    394151    /* USB Page */
    395     VBoxVMSettingsUSB::getFrom (mPageUSB, this, pagePath (mPageUSB));
     152    if (mPageUSB->isEnabled())
     153        VBoxVMSettingsUSB::getFrom (mPageUSB, this, pagePath (mPageUSB));
    396154
    397155    /* Language Page */
    398     //VBoxGlobalSettingsLanguage::getFrom (aProps, aGs, mPageLanguage);
     156    VBoxGlobalSettingsLanguage::getFrom (aProps, aGs, mPageLanguage, this);
    399157}
    400158
     
    406164                                            VBoxGlobalSettings &aGs)
    407165{
    408 //     /* Language Page */
    409 //     Q3ListViewItem *selItem = lvLanguages->selectedItem();
    410 //     Assert (selItem);
    411 //     if (mLanguageChanged && selItem)
    412 //     {
    413 //         gs.setLanguageId (selItem->text (1));
    414 //         VBoxGlobal::loadLanguage (selItem->text (1));
    415 //     }
    416 
    417166    /* General Page */
    418167    VBoxGlobalSettingsGeneral::putBackTo (aProps, aGs);
     
    425174
    426175    /* Language Page */
    427     //VBoxGlobalSettingsLanguage::putBackTo (aProps, aGs);
     176    VBoxGlobalSettingsLanguage::putBackTo (aProps, aGs);
    428177
    429178    return COMResult();
     
    439188    /* Set the old index */
    440189    mTwSelector->setCurrentItem (mTwSelector->topLevelItem (ci));
     190
     191    /* Update QTreeWidget with available items */
     192    updateAvailability();
     193
     194    /* Adjust selector list */
     195    mTwSelector->setFixedWidth (static_cast<QAbstractItemView*> (mTwSelector)
     196        ->sizeHintForColumn (0) + 2 * mTwSelector->frameWidth());
     197
     198    /* Sort selector by the id column (to have pages in the desired order) */
     199    mTwSelector->sortItems (listView_Id, Qt::AscendingOrder);
     200    mTwSelector->resizeColumnToContents (0);
    441201
    442202    mWarnIconLabel->setWarningText (tr ("Invalid settings detected"));
     
    642402}
    643403
    644 // /* Language Page */
    645 // void VBoxGlobalSettingsDlg::lvLanguages_currentChanged (Q3ListViewItem *aItem)
    646 // {
    647 //     Assert (aItem);
    648 //     if (!aItem) return;
    649 //
    650 //     /* disable labels for the Default language item */
    651 //     bool enabled = !aItem->text (1).isNull();
    652 //
    653 //     tlLangName->setEnabled (enabled);
    654 //     tlAuthorName->setEnabled (enabled);
    655 //     tlLangData->setText (aItem->text (2));
    656 //     tlAuthorData->setText (aItem->text (3));
    657 //
    658 //     mLanguageChanged = true;
    659 // }
    660 //
    661 // void VBoxGlobalSettingsDlg::fixLanguageChange()
    662 // {
    663 //     /* fix for usb page */
    664 //
    665 // #ifdef DEBUG_dmik
    666 //     CHost host = vboxGlobal().virtualBox().GetHost();
    667 //     CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
    668 //     if (coll.isNull())
    669 //     {
    670 // #endif
    671 //         /* disable the USB host filters category if the USB is
    672 //          * not available (i.e. in VirtualBox OSE) */
    673 //
    674 //         Q3ListViewItem *usbItem = listView->findItem ("#usb", listView_Link);
    675 //         Assert (usbItem);
    676 //         usbItem->setVisible (false);
    677 //
    678 //         /* disable validators if any */
    679 //         pageUSB->setEnabled (false);
    680 //
    681 // #ifdef DEBUG_dmik
    682 //     }
    683 // #endif
    684 // }
    685 
     404void VBoxGlobalSettingsDlg::updateAvailability()
     405{
     406#ifdef ENABLE_GLOBAL_USB
     407    CHost host = vboxGlobal().virtualBox().GetHost();
     408    CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
     409
     410    /* Show an error message (if there is any).
     411     * This message box may be suppressed if the user wishes so. */
     412    if (!host.isReallyOk())
     413        vboxProblem().cannotAccessUSB (host);
     414
     415    if (coll.isNull())
     416    {
     417#endif
     418        /* Disable the USB controller category if the USB controller is
     419         * not available (i.e. in VirtualBox OSE) */
     420        QList<QTreeWidgetItem*> items = mTwSelector->findItems (
     421            "#usb", Qt::MatchExactly, listView_Link);
     422        QTreeWidgetItem *usbItem = items.count() ? items [0] : 0;
     423        Assert (usbItem);
     424        if (usbItem)
     425            usbItem->setHidden (true);
     426        mPageUSB->setEnabled (false);
     427#ifdef ENABLE_GLOBAL_USB
     428    }
     429#endif
     430}
     431
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsUSB.cpp

    r9827 r9886  
    3030#include "VBoxProblemReporter.h"
    3131
    32 //#define ENABLE_GLOBAL_USB
    33 
    3432inline static QString emptyToNull (const QString &str)
    3533{
     
    4341                                 const QString &aPath)
    4442{
    45     /* USB Page */
    46 #ifdef ENABLE_GLOBAL_USB
    47     CHost host = vboxGlobal().virtualBox().GetHost();
    48     CHostUSBDeviceFilterCollection coll = host.GetUSBDeviceFilters();
    49 
    50     /* Show an error message (if there is any).
    51      * This message box may be suppressed if the user wishes so. */
    52     if (!host.isReallyOk())
    53         vboxProblem().cannotAccessUSB (host);
    54 
    55     if (coll.isNull())
    56     {
    57 #else
    58     NOREF (aPage);
    59     NOREF (aPath);
    60 #endif
    61         /* Disable the USB controller category if the USB controller is
    62          * not available (i.e. in VirtualBox OSE) */
    63         QList<QTreeWidgetItem*> items = aDlg->mTwSelector->findItems (
    64             "#usb", Qt::MatchExactly, listView_Link);
    65         QTreeWidgetItem *usbItem = items.count() ? items [0] : 0;
    66         Assert (usbItem);
    67         if (usbItem)
    68             usbItem->setHidden (true);
    69         return;
    70 #ifdef ENABLE_GLOBAL_USB
    71     }
    72 
    7343    mSettings = new VBoxVMSettingsUSB (aPage, HostType, aDlg, aPath);
    7444    QVBoxLayout *layout = new QVBoxLayout (aPage);
     
    8959    setTabOrder (mSettings->mLeSerialNo, mSettings->mLePort);
    9060    setTabOrder (mSettings->mLePort, mSettings->mCbAction);
    91 #endif
    9261}
    9362
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