VirtualBox

Ignore:
Timestamp:
Jun 4, 2018 4:35:07 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Huge overhaul for VBoxGlobal class: Remove obsolete code, move implementation for large parts to source file.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/globals
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r72425 r72432  
    303303    , m_enmWindowManagerType(X11WMType_Unknown)
    304304#endif
    305     , mVerString("1.0")
    306305    , m_fSeparateProcess(false)
    307306    , mShowStartVMErrors(true)
     
    318317    , mExecuteAllInIem(false)
    319318    , mWarpPct(100)
     319#ifdef VBOX_WITH_DEBUGGER_GUI
     320    , m_fDbgEnabled(0)
     321    , m_fDbgAutoShow(0)
     322    , m_fDbgAutoShowCommandLine(0)
     323    , m_fDbgAutoShowStatistics(0)
     324    , m_hVBoxDbg(NIL_RTLDRMOD)
     325    , m_enmStartRunning(StartRunning_Default)
     326#endif
    320327    , mSettingsPwSet(false)
    321328    , m_fWrappersValid(false)
     
    427434    QSettings s(mBrandingConfig, QSettings::IniFormat);
    428435    return s.value(QString("%1").arg(aKey)).toString();
     436}
     437
     438/* static */
     439bool VBoxGlobal::hasAllowedExtension(const QString &strExt, const QStringList &extList)
     440{
     441    for (int i = 0; i < extList.size(); ++i)
     442        if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
     443            return true;
     444    return false;
    429445}
    430446
     
    509525
    510526#endif /* VBOX_WITH_DEBUGGER_GUI */
     527
     528bool VBoxGlobal::shouldStartPaused() const
     529{
     530#ifdef VBOX_WITH_DEBUGGER_GUI
     531    return m_enmStartRunning == StartRunning_Default ? isDebuggerAutoShowEnabled() : m_enmStartRunning == StartRunning_No;
     532#else
     533    return false;
     534#endif
     535}
    511536
    512537#ifdef VBOX_GUI_WITH_PIDFILE
     
    793818
    794819/* static */
     820QString VBoxGlobal::yearsToString(uint32_t cVal)
     821{
     822    return QApplication::translate("VBoxGlobal", "%n year(s)", "", cVal);
     823}
     824
     825/* static */
     826QString VBoxGlobal::monthsToString(uint32_t cVal)
     827{
     828    return QApplication::translate("VBoxGlobal", "%n month(s)", "", cVal);
     829}
     830
     831/* static */
     832QString VBoxGlobal::daysToString(uint32_t cVal)
     833{
     834    return QApplication::translate("VBoxGlobal", "%n day(s)", "", cVal);
     835}
     836
     837/* static */
     838QString VBoxGlobal::hoursToString(uint32_t cVal)
     839{
     840    return QApplication::translate("VBoxGlobal", "%n hour(s)", "", cVal);
     841}
     842
     843/* static */
     844QString VBoxGlobal::minutesToString(uint32_t cVal)
     845{
     846    return QApplication::translate("VBoxGlobal", "%n minute(s)", "", cVal);
     847}
     848
     849/* static */
     850QString VBoxGlobal::secondsToString(uint32_t cVal)
     851{
     852    return QApplication::translate("VBoxGlobal", "%n second(s)", "", cVal);
     853}
     854
     855/* static */
    795856QChar VBoxGlobal::decimalSep()
    796857{
     
    11871248    else
    11881249        return pattern.arg(strText).arg(QKeySequence(strKey).toString(QKeySequence::NativeText));
    1189 }
    1190 
    1191 /* static */
    1192 QString VBoxGlobal::replaceHtmlEntities(QString strText)
    1193 {
    1194     return strText
    1195         .replace('&', "&amp;")
    1196         .replace('<', "&lt;")
    1197         .replace('>', "&gt;")
    1198         .replace('\"', "&quot;");
    11991250}
    12001251
     
    14591510        extrah = qMax (extrah, frameh);
    14601511    }
    1461 
    1462     /// @todo (r=dmik) not sure if we really need this
    1463 #if 0
    1464     /* sanity check for decoration frames. With embedding, we
    1465      * might get extraordinary values */
    1466     if (extraw == 0 || extrah == 0 || extraw > 20 || extrah > 50)
    1467     {
    1468         extrah = 50;
    1469         extraw = 20;
    1470     }
    1471 #endif
    14721512
    14731513    /* On non-X11 platforms, the following would be enough instead of the
     
    19421982}
    19431983
    1944 QList<QRect> XGetDesktopList()
    1945 {
    1946     /* Prepare empty resulting list: */
    1947     QList<QRect> result;
    1948 
    1949     /* Get current display: */
    1950     Display* pDisplay = QX11Info::display();
    1951 
    1952     /* If it's a Xinerama desktop: */
    1953     if (XineramaIsActive(pDisplay))
    1954     {
    1955         /* Reading Xinerama data: */
    1956         int iScreens = 0;
    1957         XineramaScreenInfo *pScreensData = XineramaQueryScreens(pDisplay, &iScreens);
    1958 
    1959         /* Fill resulting list: */
    1960         for (int i = 0; i < iScreens; ++ i)
    1961             result << QRect(pScreensData[i].x_org, pScreensData[i].y_org,
    1962                             pScreensData[i].width, pScreensData[i].height);
    1963 
    1964         /* Free screens data: */
    1965         XFree(pScreensData);
    1966     }
    1967 
    1968     /* Return resulting list: */
    1969     return result;
    1970 }
    1971 
    1972 QList<Window> XGetWindowIDList()
    1973 {
    1974     /* Get current display: */
    1975     Display *pDisplay = QX11Info::display();
    1976 
    1977     /* Get virtual desktop window: */
    1978     Window window = QX11Info::appRootWindow();
    1979 
    1980     /* Get 'client list' atom: */
    1981     Atom propNameAtom = XInternAtom(pDisplay, "_NET_CLIENT_LIST", True /* only if exists */);
    1982 
    1983     /* Prepare empty resulting list: */
    1984     QList<Window> result;
    1985 
    1986     /* If atom does not exists return empty list: */
    1987     if (propNameAtom == None)
    1988         return result;
    1989 
    1990     /* Get atom value: */
    1991     Atom realAtomType = None;
    1992     int iRealFormat = 0;
    1993     unsigned long uItemsCount = 0;
    1994     unsigned long uBytesAfter = 0;
    1995     unsigned char *pData = 0;
    1996     int rc = XGetWindowProperty(pDisplay, window, propNameAtom,
    1997                                 0, 0x7fffffff /*LONG_MAX*/, False /* delete */,
    1998                                 XA_WINDOW, &realAtomType, &iRealFormat,
    1999                                 &uItemsCount, &uBytesAfter, &pData);
    2000 
    2001     /* If get property is failed return empty list: */
    2002     if (rc != Success)
    2003         return result;
    2004 
    2005     /* Fill resulting list with win ids: */
    2006     Window *pWindowData = reinterpret_cast<Window*>(pData);
    2007     for (ulong i = 0; i < uItemsCount; ++ i)
    2008         result << pWindowData[i];
    2009 
    2010     /* Releasing resources: */
    2011     XFree(pData);
    2012 
    2013     /* Return resulting list: */
    2014     return result;
    2015 }
    2016 
    2017 QList<ulong> XGetStrut(Window window)
    2018 {
    2019     /* Get current display: */
    2020     Display *pDisplay = QX11Info::display();
    2021 
    2022     /* Get 'strut' atom: */
    2023     Atom propNameAtom = XInternAtom(pDisplay, "_NET_WM_STRUT_PARTIAL", True /* only if exists */);
    2024 
    2025     /* Prepare empty resulting list: */
    2026     QList<ulong> result;
    2027 
    2028     /* If atom does not exists return empty list: */
    2029     if (propNameAtom == None)
    2030         return result;
    2031 
    2032     /* Get atom value: */
    2033     Atom realAtomType = None;
    2034     int iRealFormat = 0;
    2035     ulong uItemsCount = 0;
    2036     ulong uBytesAfter = 0;
    2037     unsigned char *pData = 0;
    2038     int rc = XGetWindowProperty(pDisplay, window, propNameAtom,
    2039                                 0, LONG_MAX, False /* delete */,
    2040                                 XA_CARDINAL, &realAtomType, &iRealFormat,
    2041                                 &uItemsCount, &uBytesAfter, &pData);
    2042 
    2043     /* If get property is failed return empty list: */
    2044     if (rc != Success)
    2045         return result;
    2046 
    2047     /* Fill resulting list with strut shifts: */
    2048     ulong *pStrutsData = reinterpret_cast<ulong*>(pData);
    2049     for (ulong i = 0; i < uItemsCount; ++ i)
    2050         result << pStrutsData[i];
    2051 
    2052     /* Releasing resources: */
    2053     XFree(pData);
    2054 
    2055     /* Return resulting list: */
    2056     return result;
    2057 }
    20581984#endif
    20591985
     
    21912117
    21922118    return false;
    2193 
    2194 #endif
    2195 
    2196 
    2197     /// @todo Below is the old method of switching to the console window
    2198     //  based on the process ID of the console process. It should go away
    2199     //  after the new (callback-based) method is fully tested.
    2200 #if 0
    2201 
    2202     if (!canSwitchTo())
    2203         return false;
    2204 
    2205 #if defined (VBOX_WS_WIN)
    2206 
    2207     HWND hwnd = mWinId;
    2208 
    2209     /* if there are blockers (modal and modeless dialogs, etc), find the
    2210      * topmost one */
    2211     HWND hwndAbove = NULL;
    2212     do
    2213     {
    2214         hwndAbove = GetNextWindow(hwnd, GW_HWNDPREV);
    2215         HWND hwndOwner;
    2216         if (hwndAbove != NULL &&
    2217             ((hwndOwner = GetWindow(hwndAbove, GW_OWNER)) == hwnd ||
    2218              hwndOwner  == hwndAbove))
    2219             hwnd = hwndAbove;
    2220         else
    2221             break;
    2222     }
    2223     while (1);
    2224 
    2225     /* first, check that the primary window is visible */
    2226     if (IsIconic(mWinId))
    2227         ShowWindow(mWinId, SW_RESTORE);
    2228     else if (!IsWindowVisible(mWinId))
    2229         ShowWindow(mWinId, SW_SHOW);
    2230 
    2231 #if 0
    2232     LogFlowFunc(("mWinId=%08X hwnd=%08X\n", mWinId, hwnd));
    2233 #endif
    2234 
    2235     /* then, activate the topmost in the group */
    2236     AllowSetForegroundWindow(m_pid);
    2237     SetForegroundWindow(hwnd);
    2238 
    2239     return true;
    2240 
    2241 #elif defined (VBOX_WS_X11)
    2242 
    2243     return false;
    2244 
    2245 #elif defined (VBOX_WS_MAC)
    2246 
    2247     ProcessSerialNumber psn;
    2248     OSStatus rc = ::GetProcessForPID(m_pid, &psn);
    2249     if (!rc)
    2250     {
    2251         rc = ::SetFrontProcess(&psn);
    2252 
    2253         if (!rc)
    2254         {
    2255             ShowHideProcess(&psn, true);
    2256             return true;
    2257         }
    2258     }
    2259     return false;
    2260 
    2261 #else
    2262 
    2263     return false;
    2264 
    2265 #endif
    22662119
    22672120#endif
     
    33903243}
    33913244
     3245bool VBoxGlobal::is3DAvailable() const
     3246{
     3247    if (m3DAvailable < 0)
     3248        return is3DAvailableWorker();
     3249    return m3DAvailable != 0;
     3250}
     3251
    33923252#ifdef VBOX_WITH_CRHGSMI
    33933253/* static */
     
    35513411
    35523412    return result;
    3553 }
    3554 
    3555 /* static */
    3556 void VBoxGlobal::setTextLabel (QToolButton *aToolButton,
    3557                                const QString &aTextLabel)
    3558 {
    3559     AssertReturnVoid (aToolButton != NULL);
    3560 
    3561     /* remember the icon set as setText() will kill it */
    3562     QIcon iset = aToolButton->icon();
    3563     /* re-use the setText() method to detect and set the accelerator */
    3564     aToolButton->setText (aTextLabel);
    3565     QKeySequence accel = aToolButton->shortcut();
    3566     aToolButton->setText (aTextLabel);
    3567     aToolButton->setIcon (iset);
    3568     /* set the accel last as setIconSet() would kill it */
    3569     aToolButton->setShortcut (accel);
    3570 }
    3571 
    3572 /* static */
    3573 QString VBoxGlobal::locationForHTML (const QString &aFileName)
    3574 {
    3575 /// @todo (dmik) remove?
    3576 //    QString result = QDir::toNativeSeparators (fn);
    3577 //#ifdef Q_OS_LINUX
    3578 //    result.replace ('/', "/<font color=red>&shy;</font>");
    3579 //#else
    3580 //    result.replace ('\\', "\\<font color=red>&shy;</font>");
    3581 //#endif
    3582 //    return result;
    3583     QFileInfo fi (aFileName);
    3584     return fi.fileName();
    3585 }
    3586 
    3587 /* static */
    3588 QWidget *VBoxGlobal::findWidget (QWidget *aParent, const char *aName,
    3589                                  const char *aClassName /* = NULL */,
    3590                                  bool aRecursive /* = false */)
    3591 {
    3592     if (aParent == NULL)
    3593     {
    3594         QWidgetList list = QApplication::topLevelWidgets();
    3595         foreach(QWidget *w, list)
    3596         {
    3597             if ((!aName || strcmp (w->objectName().toLatin1().constData(), aName) == 0) &&
    3598                 (!aClassName || strcmp (w->metaObject()->className(), aClassName) == 0))
    3599                 return w;
    3600             if (aRecursive)
    3601             {
    3602                 w = findWidget (w, aName, aClassName, aRecursive);
    3603                 if (w)
    3604                     return w;
    3605             }
    3606         }
    3607         return NULL;
    3608     }
    3609 
    3610     /* Find the first children of aParent with the appropriate properties.
    3611      * Please note that this call is recursively. */
    3612     QList<QWidget *> list = aParent->findChildren<QWidget*>(aName);
    3613     foreach(QWidget *child, list)
    3614     {
    3615         if (!aClassName || strcmp (child->metaObject()->className(), aClassName) == 0)
    3616             return child;
    3617     }
    3618     return NULL;
    36193413}
    36203414
     
    37913585    /* Load translation based on the current locale: */
    37923586    loadLanguage();
    3793 
    3794 #ifdef DEBUG
    3795     mVerString += " [DEBUG]";
    3796 #endif
    37973587
    37983588    HRESULT rc = COMBase::InitializeCOM(true);
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r72414 r72432  
    165165        bool isBeta() const;
    166166
    167         /** todo remove */
    168         QString versionString() const { return mVerString; }
    169 
    170167#ifdef VBOX_WS_MAC
    171168        /** Mac OS X: Returns #MacOSXRelease determined by <i>uname</i> call. */
     
    191188     * @{ */
    192189        /** Returns whether passed @a strExt ends with one of allowed extension in the @a extList. */
    193         static bool hasAllowedExtension(const QString &strExt, const QStringList &extList)
    194         {
    195             for (int i = 0; i < extList.size(); ++i)
    196                 if (strExt.endsWith(extList.at(i), Qt::CaseInsensitive))
    197                     return true;
    198             return false;
    199         }
     190        static bool hasAllowedExtension(const QString &strExt, const QStringList &extList);
    200191
    201192        /** Process application args. */
     
    261252
    262253        /** Returns whether VM should start paused. */
    263         bool shouldStartPaused() const
    264         {
    265 #ifdef VBOX_WITH_DEBUGGER_GUI
    266             return m_enmStartRunning == StartRunning_Default ? isDebuggerAutoShowEnabled() : m_enmStartRunning == StartRunning_No;
    267 #else
    268             return false;
    269 #endif
    270         }
     254        bool shouldStartPaused() const;
    271255
    272256#ifdef VBOX_GUI_WITH_PIDFILE
     
    313297
    314298        /** Returns tr("%n year(s)"). */
    315         static inline QString yearsToString (uint32_t cVal)
    316         {
    317             return tr("%n year(s)", "", cVal);
    318         }
     299        static QString yearsToString(uint32_t cVal);
    319300        /** Returns tr("%n month(s)"). */
    320         static inline QString monthsToString (uint32_t cVal)
    321         {
    322             return tr("%n month(s)", "", cVal);
    323         }
     301        static QString monthsToString(uint32_t cVal);
    324302        /** Returns tr("%n day(s)"). */
    325         static inline QString daysToString (uint32_t cVal)
    326         {
    327             return tr("%n day(s)", "", cVal);
    328         }
     303        static QString daysToString(uint32_t cVal);
    329304        /** Returns tr("%n hour(s)"). */
    330         static inline QString hoursToString (uint32_t cVal)
    331         {
    332             return tr("%n hour(s)", "", cVal);
    333         }
     305        static QString hoursToString(uint32_t cVal);
    334306        /** Returns tr("%n minute(s)"). */
    335         static inline QString minutesToString (uint32_t cVal)
    336         {
    337             return tr("%n minute(s)", "", cVal);
    338         }
     307        static QString minutesToString(uint32_t cVal);
    339308        /** Returns tr("%n second(s)"). */
    340         static inline QString secondsToString (uint32_t cVal)
    341         {
    342             return tr("%n second(s)", "", cVal);
    343         }
     309        static QString secondsToString(uint32_t cVal);
    344310
    345311        /** Returns the decimal separator for the current locale. */
     
    383349        /** Inserts a passed @a strKey into action @a strText. */
    384350        static QString insertKeyToActionText (const QString &aText, const QString &aKey);
    385 
    386         /** @todo remove */
    387         static QString replaceHtmlEntities(QString strText);
    388351    /** @} */
    389352
     
    604567        bool is3DAvailableWorker() const;
    605568        /** Returns whether 3D is available, runs worker above if necessary. */
    606         bool is3DAvailable() const { if (m3DAvailable < 0) return is3DAvailableWorker(); return m3DAvailable != 0; }
     569        bool is3DAvailable() const;
    607570
    608571#ifdef VBOX_WITH_CRHGSMI
     
    651614        /** Joins two pixmaps horizontally with 2px space between them and returns the result. */
    652615        static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2);
    653 
    654         /** @todo remove */
    655         static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
    656 
    657         /** @todo remove */
    658         static QString locationForHTML (const QString &aFileName);
    659 
    660         /** @todo remove */
    661         static QWidget *findWidget (QWidget *aParent, const char *aName,
    662                                     const char *aClassName = NULL,
    663                                     bool aRecursive = false);
    664616    /** @} */
    665617
     
    757709    /** @name Common stuff.
    758710     * @{ */
     711        /** Holds whether VBoxGlobal cleanup is in progress. */
     712        static bool        s_fCleanupInProgress;
     713
    759714        /** Holds the currently loaded language ID. */
    760715        static QString     s_strLoadedLanguageId;
    761 
    762         /** Holds whether VBoxGlobal cleanup is in progress. */
    763         static bool        s_fCleanupInProgress;
    764716
    765717#ifdef VBOX_GUI_WITH_SHARED_LIBRARY
     
    777729
    778730#ifdef VBOX_WS_X11
     731        /** X11: Holds the #X11WMType of the Window Manager we are running under. */
     732        X11WMType m_enmWindowManagerType;
    779733        /** X11: Holds whether the Window Manager we are running at is composition one. */
    780734        bool m_fCompositingManagerRunning;
    781         /** X11: Holds the #X11WMType of the Window Manager we are running under. */
    782         X11WMType m_enmWindowManagerType;
    783735#endif /* VBOX_WS_X11 */
    784736
    785         /** @todo remove */
    786         QString mVerString;
    787737        /** Holds the VBox branding config file path. */
    788738        QString mBrandingConfig;
     
    927877#endif
    928878
    929 #if defined (VBOX_WS_WIN)
    930     /** @todo remove */
    931     DWORD dwHTMLHelpCookie;
    932 #endif
    933 
    934879    /** Allows for shortcut access. */
    935880    friend VBoxGlobal &vboxGlobal();
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