VirtualBox

儲存庫 vbox 的更動 91121


忽略:
時間撮記:
2021-9-6 下午12:32:06 (3 年 以前)
作者:
vboxsync
訊息:

FE/Qt: bugref:10067: A bit of minor fixes across whole the UICommon; Mostly refactoring and coding-style.

位置:
trunk/src/VBox/Frontends/VirtualBox/src
檔案:
修改 5 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r91114 r91121  
    11611161#endif /* VBOX_GUI_WITH_PIDFILE */
    11621162
    1163 /* static */
    1164 QString UICommon::helpFile()
    1165 {
    1166 #if defined (VBOX_WITH_QHELP_VIEWER)
    1167     const QString strName = "UserManual";
    1168     const QString strSuffix = "qhc";
    1169 #else
    1170  #if defined(VBOX_WS_WIN)
    1171      const QString strName = "VirtualBox";
    1172      const QString strSuffix = "chm";
    1173  #elif defined(VBOX_WS_MAC)
    1174      const QString strName = "UserManual";
    1175      const QString strSuffix = "pdf";
    1176  #elif defined(VBOX_WS_X11)
    1177      //# if defined(VBOX_OSE) || !defined(VBOX_WITH_KCHMVIEWER)
    1178      const QString strName = "UserManual";
    1179      const QString strSuffix = "pdf";
    1180  #endif
    1181 #endif
    1182     /* Where are the docs located? */
    1183     char szDocsPath[RTPATH_MAX];
    1184     int rc = RTPathAppDocs(szDocsPath, sizeof(szDocsPath));
    1185     AssertRC(rc);
    1186 
    1187     /* Make sure that the language is in two letter code.
    1188      * Note: if languageId() returns an empty string lang.name() will
    1189      * return "C" which is an valid language code. */
    1190     QLocale lang(UITranslator::languageId());
    1191 
    1192     /* Construct the path and the filename: */
    1193     QString strManual = QString("%1/%2_%3.%4").arg(szDocsPath)
    1194                                               .arg(strName)
    1195                                               .arg(lang.name())
    1196                                               .arg(strSuffix);
    1197 
    1198     /* Check if a help file with that name exists: */
    1199     QFileInfo fi(strManual);
    1200     if (fi.exists())
    1201         return strManual;
    1202 
    1203     /* Fall back to the standard: */
    1204     strManual = QString("%1/%2.%4").arg(szDocsPath)
    1205                                    .arg(strName)
    1206                                    .arg(strSuffix);
    1207     return strManual;
    1208 }
    1209 
    1210 /* static */
    1211 QString UICommon::documentsPath()
    1212 {
    1213     QString strPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
    1214     QDir dir(strPath);
    1215     if (dir.exists())
    1216         return QDir::cleanPath(dir.canonicalPath());
    1217     else
    1218     {
    1219         dir.setPath(QDir::homePath() + "/Documents");
    1220         if (dir.exists())
    1221             return QDir::cleanPath(dir.canonicalPath());
    1222         else
    1223             return QDir::homePath();
    1224     }
    1225 }
    1226 
    1227 /* static */
    1228 bool UICommon::hasAllowedExtension(const QString &strFileName, const QStringList &extensions)
    1229 {
    1230     foreach (const QString &strExtension, extensions)
    1231         if (strFileName.endsWith(strExtension, Qt::CaseInsensitive))
    1232             return true;
    1233     return false;
    1234 }
    1235 
    1236 /* static */
    1237 QString UICommon::findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName)
    1238 {
    1239     QDir folder(strFullFolderPath);
    1240     if (!folder.exists())
    1241         return strBaseFileName;
    1242     QFileInfoList folderContent = folder.entryInfoList();
    1243     QSet<QString> fileNameSet;
    1244     foreach (const QFileInfo &fileInfo, folderContent)
    1245     {
    1246         /* Remove the extension : */
    1247         fileNameSet.insert(fileInfo.completeBaseName());
    1248     }
    1249     int iSuffix = 0;
    1250     QString strNewName(strBaseFileName);
    1251     while (fileNameSet.contains(strNewName))
    1252     {
    1253         strNewName = strBaseFileName + QString("_") + QString::number(++iSuffix);
    1254     }
    1255     return strNewName;
    1256 }
    1257 
    1258 /* static */
    1259 void UICommon::setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount)
    1260 {
    1261     /* Shame on Qt it hasn't stuff for tuning
    1262      * widget size suitable for reflecting content of desired size.
    1263      * For example QLineEdit, QSpinBox and similar widgets should have a methods
    1264      * to strict the minimum width to reflect at least [n] symbols. */
    1265 
    1266     /* Load options: */
    1267     QStyleOptionSpinBox option;
    1268     option.initFrom(pSpinBox);
    1269 
    1270     /* Acquire edit-field rectangle: */
    1271     QRect rect = pSpinBox->style()->subControlRect(QStyle::CC_SpinBox,
    1272                                                    &option,
    1273                                                    QStyle::SC_SpinBoxEditField,
    1274                                                    pSpinBox);
    1275 
    1276     /* Calculate minimum-width magic: */
    1277     const int iSpinBoxWidth = pSpinBox->width();
    1278     const int iSpinBoxEditFieldWidth = rect.width();
    1279     const int iSpinBoxDelta = qMax(0, iSpinBoxWidth - iSpinBoxEditFieldWidth);
    1280     QFontMetrics metrics(pSpinBox->font(), pSpinBox);
    1281     const QString strDummy(cCount, '0');
    1282     const int iTextWidth = metrics.width(strDummy);
    1283 
    1284     /* Tune spin-box minimum-width: */
    1285     pSpinBox->setMinimumWidth(iTextWidth + iSpinBoxDelta);
    1286 }
    1287 
    12881163QString UICommon::vmGuestOSFamilyDescription(const QString &strFamilyId) const
    12891164{
     
    13021177
    13031178CGuestOSType UICommon::vmGuestOSType(const QString &strTypeId,
    1304                                        const QString &strFamilyId /* = QString() */) const
     1179                                     const QString &strFamilyId /* = QString() */) const
    13051180{
    13061181    QList<CGuestOSType> list;
     
    13941269}
    13951270
     1271/* static */
    13961272bool UICommon::launchMachine(CMachine &comMachine, LaunchMode enmLaunchMode /* = LaunchMode_Default */)
    13971273{
     
    14001276        && comMachine.CanShowConsoleWindow())
    14011277    {
    1402         switch (uiType())
     1278        switch (uiCommon().uiType())
    14031279        {
    14041280            /* For Selector UI: */
     
    14601336    {
    14611337        case LaunchMode_Default:  strType = ""; break;
    1462         case LaunchMode_Separate: strType = isSeparateProcess() ? "headless" : "separate"; break;
     1338        case LaunchMode_Separate: strType = uiCommon().isSeparateProcess() ? "headless" : "separate"; break;
    14631339        case LaunchMode_Headless: strType = "headless"; break;
    14641340        default: AssertFailedReturn(false);
     
    23792255}
    23802256
    2381 QString UICommon::details(const CMedium &comMedium, bool fPredictDiff, bool fUseHtml /* = true */)
     2257QString UICommon::storageDetails(const CMedium &comMedium, bool fPredictDiff, bool fUseHtml /* = true */)
    23822258{
    23832259    /* Search for corresponding UI medium: */
     
    26642540}
    26652541
     2542/* static */
     2543QString UICommon::helpFile()
     2544{
     2545#if defined (VBOX_WITH_QHELP_VIEWER)
     2546    const QString strName = "UserManual";
     2547    const QString strSuffix = "qhc";
     2548#else
     2549 #if defined(VBOX_WS_WIN)
     2550     const QString strName = "VirtualBox";
     2551     const QString strSuffix = "chm";
     2552 #elif defined(VBOX_WS_MAC)
     2553     const QString strName = "UserManual";
     2554     const QString strSuffix = "pdf";
     2555 #elif defined(VBOX_WS_X11)
     2556     //# if defined(VBOX_OSE) || !defined(VBOX_WITH_KCHMVIEWER)
     2557     const QString strName = "UserManual";
     2558     const QString strSuffix = "pdf";
     2559 #endif
     2560#endif
     2561    /* Where are the docs located? */
     2562    char szDocsPath[RTPATH_MAX];
     2563    int rc = RTPathAppDocs(szDocsPath, sizeof(szDocsPath));
     2564    AssertRC(rc);
     2565
     2566    /* Make sure that the language is in two letter code.
     2567     * Note: if languageId() returns an empty string lang.name() will
     2568     * return "C" which is an valid language code. */
     2569    QLocale lang(UITranslator::languageId());
     2570
     2571    /* Construct the path and the filename: */
     2572    QString strManual = QString("%1/%2_%3.%4").arg(szDocsPath)
     2573                                              .arg(strName)
     2574                                              .arg(lang.name())
     2575                                              .arg(strSuffix);
     2576
     2577    /* Check if a help file with that name exists: */
     2578    QFileInfo fi(strManual);
     2579    if (fi.exists())
     2580        return strManual;
     2581
     2582    /* Fall back to the standard: */
     2583    strManual = QString("%1/%2.%4").arg(szDocsPath)
     2584                                   .arg(strName)
     2585                                   .arg(strSuffix);
     2586    return strManual;
     2587}
     2588
     2589/* static */
     2590QString UICommon::documentsPath()
     2591{
     2592    QString strPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
     2593    QDir dir(strPath);
     2594    if (dir.exists())
     2595        return QDir::cleanPath(dir.canonicalPath());
     2596    else
     2597    {
     2598        dir.setPath(QDir::homePath() + "/Documents");
     2599        if (dir.exists())
     2600            return QDir::cleanPath(dir.canonicalPath());
     2601        else
     2602            return QDir::homePath();
     2603    }
     2604}
     2605
     2606/* static */
     2607bool UICommon::hasAllowedExtension(const QString &strFileName, const QStringList &extensions)
     2608{
     2609    foreach (const QString &strExtension, extensions)
     2610        if (strFileName.endsWith(strExtension, Qt::CaseInsensitive))
     2611            return true;
     2612    return false;
     2613}
     2614
     2615/* static */
     2616QString UICommon::findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName)
     2617{
     2618    QDir folder(strFullFolderPath);
     2619    if (!folder.exists())
     2620        return strBaseFileName;
     2621    QFileInfoList folderContent = folder.entryInfoList();
     2622    QSet<QString> fileNameSet;
     2623    foreach (const QFileInfo &fileInfo, folderContent)
     2624    {
     2625        /* Remove the extension : */
     2626        fileNameSet.insert(fileInfo.completeBaseName());
     2627    }
     2628    int iSuffix = 0;
     2629    QString strNewName(strBaseFileName);
     2630    while (fileNameSet.contains(strNewName))
     2631    {
     2632        strNewName = strBaseFileName + QString("_") + QString::number(++iSuffix);
     2633    }
     2634    return strNewName;
     2635}
     2636
     2637/* static */
     2638void UICommon::setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount)
     2639{
     2640    /* Shame on Qt it hasn't stuff for tuning
     2641     * widget size suitable for reflecting content of desired size.
     2642     * For example QLineEdit, QSpinBox and similar widgets should have a methods
     2643     * to strict the minimum width to reflect at least [n] symbols. */
     2644
     2645    /* Load options: */
     2646    QStyleOptionSpinBox option;
     2647    option.initFrom(pSpinBox);
     2648
     2649    /* Acquire edit-field rectangle: */
     2650    QRect rect = pSpinBox->style()->subControlRect(QStyle::CC_SpinBox,
     2651                                                   &option,
     2652                                                   QStyle::SC_SpinBoxEditField,
     2653                                                   pSpinBox);
     2654
     2655    /* Calculate minimum-width magic: */
     2656    const int iSpinBoxWidth = pSpinBox->width();
     2657    const int iSpinBoxEditFieldWidth = rect.width();
     2658    const int iSpinBoxDelta = qMax(0, iSpinBoxWidth - iSpinBoxEditFieldWidth);
     2659    QFontMetrics metrics(pSpinBox->font(), pSpinBox);
     2660    const QString strDummy(cCount, '0');
     2661    const int iTextWidth = metrics.width(strDummy);
     2662
     2663    /* Tune spin-box minimum-width: */
     2664    pSpinBox->setMinimumWidth(iTextWidth + iSpinBoxDelta);
     2665}
     2666
    26662667#ifdef VBOX_WITH_3D_ACCELERATION
    26672668/* static */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h

    r91109 r91121  
    298298    /** @} */
    299299
    300     /** @name File-system stuff.
    301      * @{ */
    302         /** Returns full help file name. */
    303         static QString helpFile();
    304 
    305         /** Returns documents path. */
    306         static QString documentsPath();
    307 
    308         /** Returns whether passed @a strFileName ends with one of allowed extension in the @a extensions list. */
    309         static bool hasAllowedExtension(const QString &strFileName, const QStringList &extensions);
    310 
    311         /** Returns a file name (unique up to extension) wrt. @a strFullFolderPath folder content. Starts
    312           * searching strBaseFileName and adds suffixes until a unique file name is found. */
    313         static QString findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName);
    314     /** @} */
    315 
    316     /** @name Widget stuff.
    317      * @{ */
    318         /** Assigns minimum @a pSpinBox to correspond to @a cCount digits. */
    319         static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
    320     /** @} */
    321 
    322300    /** @name COM stuff.
    323301     * @{ */
     
    340318    /** @} */
    341319
    342     /** @name COM: Guest OS Type.
     320    /** @name COM: Guest OS Type stuff.
    343321     * @{ */
    344322        /** Returns the list of family IDs. */
     
    365343        static bool switchToMachine(CMachine &comMachine);
    366344        /** Launches certain @a comMachine in specified @a enmLaunchMode. */
    367         bool launchMachine(CMachine &comMachine, LaunchMode enmLaunchMode = LaunchMode_Default);
     345        static bool launchMachine(CMachine &comMachine, LaunchMode enmLaunchMode = LaunchMode_Default);
    368346
    369347        /** Opens session of certain @a enmLockType for VM with certain @a uId. */
     
    377355    /** @} */
    378356
    379     /** @name Cloud Virtual Machine stuff.
     357    /** @name COM: Cloud Virtual Machine stuff.
    380358     * @{ */
    381359        /** Notifies listeners about cloud VM was unregistered.
     
    425403          * @param  fUseLastFolder    Brings whether we should propose to use last used folder. */
    426404        QUuid openMediumWithFileOpenDialog(UIMediumDeviceType enmMediumType, QWidget *pParent = 0,
    427                                              const QString &strDefaultFolder = QString(), bool fUseLastFolder = false);
     405                                           const QString &strDefaultFolder = QString(), bool fUseLastFolder = false);
    428406
    429407        /** Creates and shows a UIMediumSelector dialog.
     
    469447          * @param  fPredictDiff  Brings whether medium will be marked differencing on attaching.
    470448          * @param  fUseHtml      Brings whether HTML subsets should be used in the generated output. */
    471         QString details(const CMedium &comMedium, bool fPredictDiff, bool fUseHtml = true);
     449        QString storageDetails(const CMedium &comMedium, bool fPredictDiff, bool fUseHtml = true);
    472450
    473451        /** Update extra data related to recently used/referred media.
     
    497475        /** Generates tool-tip for passed USB @a comWebcam. */
    498476        static QString toolTip(const CHostVideoInputDevice &comWebcam);
     477    /** @} */
     478
     479    /** @name File-system stuff.
     480     * @{ */
     481        /** Returns full help file name. */
     482        static QString helpFile();
     483
     484        /** Returns documents path. */
     485        static QString documentsPath();
     486
     487        /** Returns whether passed @a strFileName ends with one of allowed extension in the @a extensions list. */
     488        static bool hasAllowedExtension(const QString &strFileName, const QStringList &extensions);
     489
     490        /** Returns a file name (unique up to extension) wrt. @a strFullFolderPath folder content. Starts
     491          * searching strBaseFileName and adds suffixes until a unique file name is found. */
     492        static QString findUniqueFileName(const QString &strFullFolderPath, const QString &strBaseFileName);
     493    /** @} */
     494
     495    /** @name Widget stuff.
     496     * @{ */
     497        /** Assigns minimum @a pSpinBox to correspond to @a cCount digits. */
     498        static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
    499499    /** @} */
    500500
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDetailsGenerator.cpp

    r90967 r91121  
    516516
    517517            /* Prepare attachment information: */
    518             QString strAttachmentInfo = uiCommon().details(attachment.GetMedium(), false, false);
     518            QString strAttachmentInfo = uiCommon().storageDetails(attachment.GetMedium(), false, false);
    519519            /* That hack makes sure 'Inaccessible' word is always bold: */
    520520            { // hack
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r88633 r91121  
    8181
    8282        /* Try to launch corresponding machine: */
    83         if (!uiCommon().launchMachine(machine, UICommon::LaunchMode_Separate))
     83        if (!UICommon::launchMachine(machine, UICommon::LaunchMode_Separate))
    8484            return false;
    8585    }
  • trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotDetailsWidget.cpp

    r91109 r91121  
    17951795            /* Prepare current medium information: */
    17961796            const QString strMediumInfo = comAttachment.isOk()
    1797                                         ? wipeHtmlStuff(uiCommon().details(comAttachment.GetMedium(), false))
     1797                                        ? wipeHtmlStuff(uiCommon().storageDetails(comAttachment.GetMedium(), false))
    17981798                                        : QString();
    17991799
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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