VirtualBox

Changeset 90966 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Aug 27, 2021 7:53:10 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
146605
Message:

FE/Qt: bugref:10067: UICommon: A bit of rework for native and arguments stuff.

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

Legend:

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

    r90965 r90966  
    544544            enmOptType = OptType_VMRunner;
    545545            if (++i < argc)
    546                 m_strFloppyImage = arguments.at(i);
     546                m_uFloppyImage = arguments.at(i);
    547547        }
    548548        else if (!::strcmp(arg, "--dvd") || !::strcmp(arg, "--cdrom"))
     
    550550            enmOptType = OptType_VMRunner;
    551551            if (++i < argc)
    552                 m_strDvdImage = arguments.at(i);
     552                m_uDvdImage = arguments.at(i);
    553553        }
    554554        /* VMM Options: */
     
    10381038}
    10391039#endif /* VBOX_WS_MAC */
    1040 
    1041 bool UICommon::processArgs()
    1042 {
    1043     /* Among those arguments: */
    1044     bool fResult = false;
    1045     const QStringList args = qApp->arguments();
    1046 
    1047     /* We are looking for a list of file URLs passed to the executable: */
    1048     QList<QUrl> listArgUrls;
    1049     for (int i = 1; i < args.size(); ++i)
    1050     {
    1051         /* But we break out after the first parameter, cause there
    1052          * could be parameters with arguments (e.g. --comment comment). */
    1053         if (args.at(i).startsWith("-"))
    1054             break;
    1055 
    1056 #ifdef VBOX_WS_MAC
    1057         const QString strArg = ::darwinResolveAlias(args.at(i));
    1058 #else
    1059         const QString strArg = args.at(i);
    1060 #endif
    1061 
    1062         /* So if the argument file exists, we add it to URL list: */
    1063         if (   !strArg.isEmpty()
    1064             && QFile::exists(strArg))
    1065             listArgUrls << QUrl::fromLocalFile(QFileInfo(strArg).absoluteFilePath());
    1066     }
    1067 
    1068     /* If there are file URLs: */
    1069     if (!listArgUrls.isEmpty())
    1070     {
    1071         /* We enumerate them and: */
    1072         for (int i = 0; i < listArgUrls.size(); ++i)
    1073         {
    1074             /* Check which of them has allowed VM extensions: */
    1075             const QUrl url = listArgUrls.at(i);
    1076             const QString strFile = url.toLocalFile();
    1077             if (UICommon::hasAllowedExtension(strFile, VBoxFileExts))
    1078             {
    1079                 /* So that we could run existing VMs: */
    1080                 CVirtualBox comVBox = virtualBox();
    1081                 CMachine comMachine = comVBox.FindMachine(strFile);
    1082                 if (!comMachine.isNull())
    1083                 {
    1084                     fResult = true;
    1085                     launchMachine(comMachine);
    1086                     /* And remove their URLs from the ULR list: */
    1087                     listArgUrls.removeAll(url);
    1088                 }
    1089             }
    1090         }
    1091     }
    1092 
    1093     /* And if there are *still* URLs: */
    1094     if (!listArgUrls.isEmpty())
    1095     {
    1096         /* We store them, they will be handled later: */
    1097         m_listArgUrls = listArgUrls;
    1098     }
    1099 
    1100     return fResult;
    1101 }
    1102 
    1103 bool UICommon::argumentUrlsPresent() const
    1104 {
    1105     return !m_listArgUrls.isEmpty();
    1106 }
    1107 
    1108 QList<QUrl> UICommon::takeArgumentUrls()
    1109 {
    1110     const QList<QUrl> result = m_listArgUrls;
    1111     m_listArgUrls.clear();
    1112     return result;
    1113 }
    1114 
    1115 #ifdef VBOX_WITH_DEBUGGER_GUI
    1116 
    1117 bool UICommon::isDebuggerEnabled() const
    1118 {
    1119     return isDebuggerWorker(&m_fDbgEnabled, GUI_Dbg_Enabled);
    1120 }
    1121 
    1122 bool UICommon::isDebuggerAutoShowEnabled() const
    1123 {
    1124     return isDebuggerWorker(&m_fDbgAutoShow, GUI_Dbg_AutoShow);
    1125 }
    1126 
    1127 bool UICommon::isDebuggerAutoShowCommandLineEnabled() const
    1128 {
    1129     return isDebuggerWorker(&m_fDbgAutoShowCommandLine, GUI_Dbg_AutoShow);
    1130 }
    1131 
    1132 bool UICommon::isDebuggerAutoShowStatisticsEnabled() const
    1133 {
    1134     return isDebuggerWorker(&m_fDbgAutoShowStatistics, GUI_Dbg_AutoShow);
    1135 }
    1136 
    1137 #endif /* VBOX_WITH_DEBUGGER_GUI */
    1138 
    1139 bool UICommon::shouldStartPaused() const
    1140 {
    1141 #ifdef VBOX_WITH_DEBUGGER_GUI
    1142     return m_enmLaunchRunning == LaunchRunning_Default ? isDebuggerAutoShowEnabled() : m_enmLaunchRunning == LaunchRunning_No;
    1143 #else
    1144     return false;
    1145 #endif
    1146 }
    1147 
    1148 #ifdef VBOX_GUI_WITH_PIDFILE
    1149 
    1150 void UICommon::createPidfile()
    1151 {
    1152     if (!m_strPidFile.isEmpty())
    1153     {
    1154         const qint64 iPid = qApp->applicationPid();
    1155         QFile file(m_strPidFile);
    1156         if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
    1157         {
    1158              QTextStream out(&file);
    1159              out << iPid << endl;
    1160         }
    1161         else
    1162             LogRel(("Failed to create pid file %s\n", m_strPidFile.toUtf8().constData()));
    1163     }
    1164 }
    1165 
    1166 void UICommon::deletePidfile()
    1167 {
    1168     if (   !m_strPidFile.isEmpty()
    1169         && QFile::exists(m_strPidFile))
    1170         QFile::remove(m_strPidFile);
    1171 }
    1172 
    1173 #endif /* VBOX_GUI_WITH_PIDFILE */
    11741040
    11751041#ifdef VBOX_WS_WIN
     
    12201086}
    12211087#endif /* VBOX_WS_WIN */
     1088
     1089bool UICommon::processArgs()
     1090{
     1091    /* Among those arguments: */
     1092    bool fResult = false;
     1093    const QStringList args = qApp->arguments();
     1094
     1095    /* We are looking for a list of file URLs passed to the executable: */
     1096    QList<QUrl> listArgUrls;
     1097    for (int i = 1; i < args.size(); ++i)
     1098    {
     1099        /* But we break out after the first parameter, cause there
     1100         * could be parameters with arguments (e.g. --comment comment). */
     1101        if (args.at(i).startsWith("-"))
     1102            break;
     1103
     1104#ifdef VBOX_WS_MAC
     1105        const QString strArg = ::darwinResolveAlias(args.at(i));
     1106#else
     1107        const QString strArg = args.at(i);
     1108#endif
     1109
     1110        /* So if the argument file exists, we add it to URL list: */
     1111        if (   !strArg.isEmpty()
     1112            && QFile::exists(strArg))
     1113            listArgUrls << QUrl::fromLocalFile(QFileInfo(strArg).absoluteFilePath());
     1114    }
     1115
     1116    /* If there are file URLs: */
     1117    if (!listArgUrls.isEmpty())
     1118    {
     1119        /* We enumerate them and: */
     1120        for (int i = 0; i < listArgUrls.size(); ++i)
     1121        {
     1122            /* Check which of them has allowed VM extensions: */
     1123            const QUrl url = listArgUrls.at(i);
     1124            const QString strFile = url.toLocalFile();
     1125            if (UICommon::hasAllowedExtension(strFile, VBoxFileExts))
     1126            {
     1127                /* So that we could run existing VMs: */
     1128                CVirtualBox comVBox = virtualBox();
     1129                CMachine comMachine = comVBox.FindMachine(strFile);
     1130                if (!comMachine.isNull())
     1131                {
     1132                    fResult = true;
     1133                    launchMachine(comMachine);
     1134                    /* And remove their URLs from the ULR list: */
     1135                    listArgUrls.removeAll(url);
     1136                }
     1137            }
     1138        }
     1139    }
     1140
     1141    /* And if there are *still* URLs: */
     1142    if (!listArgUrls.isEmpty())
     1143    {
     1144        /* We store them, they will be handled later: */
     1145        m_listArgUrls = listArgUrls;
     1146    }
     1147
     1148    return fResult;
     1149}
     1150
     1151bool UICommon::argumentUrlsPresent() const
     1152{
     1153    return !m_listArgUrls.isEmpty();
     1154}
     1155
     1156QList<QUrl> UICommon::takeArgumentUrls()
     1157{
     1158    const QList<QUrl> result = m_listArgUrls;
     1159    m_listArgUrls.clear();
     1160    return result;
     1161}
     1162
     1163#ifdef VBOX_WITH_DEBUGGER_GUI
     1164
     1165bool UICommon::isDebuggerEnabled() const
     1166{
     1167    return isDebuggerWorker(&m_fDbgEnabled, GUI_Dbg_Enabled);
     1168}
     1169
     1170bool UICommon::isDebuggerAutoShowEnabled() const
     1171{
     1172    return isDebuggerWorker(&m_fDbgAutoShow, GUI_Dbg_AutoShow);
     1173}
     1174
     1175bool UICommon::isDebuggerAutoShowCommandLineEnabled() const
     1176{
     1177    return isDebuggerWorker(&m_fDbgAutoShowCommandLine, GUI_Dbg_AutoShow);
     1178}
     1179
     1180bool UICommon::isDebuggerAutoShowStatisticsEnabled() const
     1181{
     1182    return isDebuggerWorker(&m_fDbgAutoShowStatistics, GUI_Dbg_AutoShow);
     1183}
     1184
     1185#endif /* VBOX_WITH_DEBUGGER_GUI */
     1186
     1187bool UICommon::shouldStartPaused() const
     1188{
     1189#ifdef VBOX_WITH_DEBUGGER_GUI
     1190    return m_enmLaunchRunning == LaunchRunning_Default ? isDebuggerAutoShowEnabled() : m_enmLaunchRunning == LaunchRunning_No;
     1191#else
     1192    return false;
     1193#endif
     1194}
     1195
     1196#ifdef VBOX_GUI_WITH_PIDFILE
     1197
     1198void UICommon::createPidfile()
     1199{
     1200    if (!m_strPidFile.isEmpty())
     1201    {
     1202        const qint64 iPid = qApp->applicationPid();
     1203        QFile file(m_strPidFile);
     1204        if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
     1205        {
     1206             QTextStream out(&file);
     1207             out << iPid << endl;
     1208        }
     1209        else
     1210            LogRel(("Failed to create pid file %s\n", m_strPidFile.toUtf8().constData()));
     1211    }
     1212}
     1213
     1214void UICommon::deletePidfile()
     1215{
     1216    if (   !m_strPidFile.isEmpty()
     1217        && QFile::exists(m_strPidFile))
     1218        QFile::remove(m_strPidFile);
     1219}
     1220
     1221#endif /* VBOX_GUI_WITH_PIDFILE */
    12221222
    12231223/* static */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h

    r90965 r90966  
    212212#endif
    213213
     214#ifdef VBOX_WS_WIN
     215        /** Loads the color theme. */
     216        static void loadColorTheme();
     217#endif
     218
    214219#ifdef VBOX_WS_X11
    215220        /** X11: Returns whether the Window Manager we are running under is composition one. */
     
    246251
    247252        /** Returns the --fda option value (whether we have floppy image). */
    248         bool hasFloppyImageToMount() const { return !m_strFloppyImage.isNull(); }
     253        bool hasFloppyImageToMount() const { return !m_uFloppyImage.isNull(); }
    249254        /** Returns the --dvd | --cdrom option value (whether we have DVD image). */
    250         bool hasDvdImageToMount() const { return !m_strDvdImage.isNull(); }
     255        bool hasDvdImageToMount() const { return !m_uDvdImage.isNull(); }
    251256        /** Returns floppy image name. */
    252         QUuid const &getFloppyImage() const { return m_strFloppyImage; }
     257        QUuid getFloppyImage() const { return m_uFloppyImage; }
    253258        /** Returns DVD image name. */
    254         QUuid const &getDvdImage() const { return m_strDvdImage; }
     259        QUuid getDvdImage() const { return m_uDvdImage; }
    255260
    256261        /** Returns the --disable-patm option value. */
     
    300305    /** @name Localization stuff.
    301306     * @{ */
    302 #ifdef VBOX_WS_WIN
    303         /** Loads the color theme. */
    304         static void loadColorTheme();
    305 #endif
    306 
    307307        /** Returns tr("%n year(s)"). */
    308308        static QString yearsToString(uint32_t cVal);
     
    890890
    891891        /** Holds the --fda option value (floppy image). */
    892         QUuid  m_strFloppyImage;
     892        QUuid  m_uFloppyImage;
    893893        /** Holds the --dvd | --cdrom option value (DVD image). */
    894         QUuid  m_strDvdImage;
     894        QUuid  m_uDvdImage;
    895895
    896896        /** Holds the --disable-patm option value. */
     
    925925
    926926        /** Holds whether --start-running, --start-paused or nothing was given. */
    927         enum LaunchRunning  m_enmLaunchRunning;
     927        LaunchRunning  m_enmLaunchRunning;
    928928#endif
    929929
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