VirtualBox

Changeset 88702 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 26, 2021 10:40:36 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9930. Changing the way we handle machines with no log file

Location:
trunk/src/VBox/Frontends/VirtualBox/src/logviewer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp

    r88686 r88702  
    4040    , m_iFilteredLineCount(-1)
    4141    , m_iUnfilteredLineCount(-1)
     42    , m_iLogFileId(-1)
    4243{
    4344    prepare();
     
    341342    m_machineId = machineId;
    342343}
     344
     345void UIVMLogPage::setLogFileId(int iLogFileId)
     346{
     347    m_iLogFileId = iLogFileId;
     348}
     349
     350int UIVMLogPage::logFileId() const
     351{
     352    return m_iLogFileId;
     353}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h

    r88687 r88702  
    117117    void setMachineId(const QUuid &machineId);
    118118
     119    void setLogFileId(int iLogFileId);
     120    int logFileId() const;
     121
    119122private slots:
    120123
     
    162165    /** Id of the machine the log shown in this page belongs to. */
    163166    QUuid m_machineId;
     167    /** The id we pass to CMachine::ReadLog. Used while refreshing and saving page content. */
     168    int m_iLogFileId;
    164169};
    165170
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r88701 r88702  
    224224}
    225225
     226QString UIVMLogViewerWidget::readLogFile(CMachine &comMachine, int iLogFileId)
     227{
     228    QString strLogFileContent;
     229    ULONG uOffset = 0;
     230
     231    while (true)
     232    {
     233        QVector<BYTE> data = comMachine.ReadLog(iLogFileId, uOffset, _1M);
     234        if (data.size() == 0)
     235            break;
     236        strLogFileContent.append(QString::fromUtf8((char*)data.data(), data.size()));
     237        uOffset += data.size();
     238        /* Don't read futher if we have reached the allowed size limit: */
     239        if (uOffset >= uAllowedLogSize)
     240        {
     241            strLogFileContent.append("\n=========Log file has been truncated as it is too large.======");
     242            break;
     243        }
     244    }
     245    return strLogFileContent;
     246}
     247
    226248QFont UIVMLogViewerWidget::currentFont() const
    227249{
     
    249271void UIVMLogViewerWidget::sltRefresh()
    250272{
    251     // if (!m_pTabWidget)
    252     //     return;
    253     // /* Disconnect this connection to avoid initial signals during page creation/deletion: */
     273    if (!m_pTabWidget)
     274        return;
     275
     276    UIVMLogPage *pCurrentPage = currentLogPage();
     277    if (!pCurrentPage)
     278        return;
     279
     280    CMachine comMachine = uiCommon().virtualBox().FindMachine(pCurrentPage->machineId().toString());
     281    if (comMachine.isNull())
     282        return;
     283
     284
     285
     286
     287    /* Disconnect this connection to avoid initial signals during page creation/deletion: */
    254288    // disconnect(m_pTabWidget, &QITabWidget::currentChanged, m_pFilterPanel, &UIVMLogViewerFilterPanel::applyFilter);
    255289    // disconnect(m_pTabWidget, &QITabWidget::currentChanged, this, &UIVMLogViewerWidget::sltTabIndexChange);
     
    563597    retranslateUi();
    564598
    565     /* Reading log files: */
    566     sltRefresh();
    567599    /* Setup escape shortcut: */
    568600    manageEscapeShortCut();
     
    864896
    865897void UIVMLogViewerWidget::createLogPage(const QString &strFileName, const QString &strMachineName,
    866                                         const QUuid &machineId,
    867                                         const QString &strLogContent, bool noLogsToShow /* = false */)
     898                                        const QUuid &machineId, int iLogFileId,
     899                                        const QString &strLogContent, bool noLogsToShow)
    868900{
    869901    if (!m_pTabWidget)
     
    881913        pLogPage->setCurrentFont(m_font);
    882914        pLogPage->setMachineId(machineId);
     915        pLogPage->setLogFileId(iLogFileId);
    883916        /* Set the file name only if we really have log file to read. */
    884917        if (!noLogsToShow)
    885918            pLogPage->setLogFileName(strFileName);
    886919
    887         /* Add page-container to viewer-container: */
     920        /* Add page-container to viewer-container in stacked mode (manager UI case): */
    888921        bool fTitleWithMachineName = m_enmEmbedding == EmbedTo_Stack;
    889922        QString strTabTitle;
     
    934967}
    935968
    936 bool UIVMLogViewerWidget::createLogViewerPages(const QVector<QUuid> &machineList)
    937 {
    938     bool noLogsToShow = false;
    939 
    940     QString strDummyTabText;
    941     /* check if the machine is valid: */
    942     // if (m_comMachine.isNull())
    943     // {
    944     //     noLogsToShow = true;
    945     //     strDummyTabText = QString(tr("<p><b>No machine</b> is currently selected or the selected machine is not valid. "
    946     //                                  "Please select a Virtual Machine to see its logs"));
    947     // }
    948 
     969void UIVMLogViewerWidget::createLogViewerPages(const QVector<QUuid> &machineList)
     970{
    949971    const CSystemProperties &sys = uiCommon().virtualBox().GetSystemProperties();
    950972    unsigned cMaxLogs = sys.GetLogHistoryCount() + 1 /*VBox.log*/ + 1 /*VBoxHardening.log*/; /** @todo Add api for getting total possible log count! */
    951     //bool logFileRead = false;
    952973    foreach (const QUuid &machineId, machineList)
    953974    {
    954975        CMachine comMachine = uiCommon().virtualBox().FindMachine(machineId.toString());
    955 
    956976        if (comMachine.isNull())
    957977            continue;
    958         for (unsigned i = 0; i < cMaxLogs && !noLogsToShow; ++i)
    959         {
    960             /* Query the log file name for index i: */
    961             QString strFileName = comMachine.QueryLogFilename(i);
    962             if (!strFileName.isEmpty())
     978        bool fNoLogFileForMachine = true;
     979
     980        QUuid uMachineId = comMachine.GetId();
     981        QString strMachineName = comMachine.GetName();
     982        for (unsigned iLogFileId = 0; iLogFileId < cMaxLogs; ++iLogFileId)
     983        {
     984            QString strLogContent = readLogFile(comMachine, iLogFileId);
     985            if (!strLogContent.isEmpty())
    963986            {
    964                 /* Try to read the log file with the index i: */
    965                 ULONG uOffset = 0;
    966                 QString strText;
    967                 while (true)
    968                 {
    969                     QVector<BYTE> data = comMachine.ReadLog(i, uOffset, _1M);
    970                     if (data.size() == 0)
    971                         break;
    972                     strText.append(QString::fromUtf8((char*)data.data(), data.size()));
    973                     uOffset += data.size();
    974                     /* Don't read futher if we have reached the allowed size limit: */
    975                     if (uOffset >= uAllowedLogSize)
    976                     {
    977                         strText.append("\n=========Log file has been truncated as it is too large.======");
    978                         break;
    979                     }
    980                 }
    981                 /* Anything read at all? */
    982                 if (uOffset > 0)
    983                 {
    984                     //logFileRead = true;
    985                     createLogPage(strFileName, comMachine.GetName(), comMachine.GetId(), strText);
    986                 }
     987                fNoLogFileForMachine = false;
     988                createLogPage(comMachine.QueryLogFilename(iLogFileId),
     989                              strMachineName, uMachineId, iLogFileId,
     990                              strLogContent, false);
    987991            }
    988992        }
    989     }
    990     // if (!noLogsToShow && !logFileRead)
    991     // {
    992     //     noLogsToShow = true;
    993     //     // strDummyTabText = QString(tr("<p>No log files found. Press the "
    994     //     //                              "<b>Refresh</b> button to rescan the log folder "
    995     //     //                              "<nobr><b>%1</b></nobr>.</p>")
    996     //     //                              .arg(m_comMachine.GetLogFolder()));
    997     // }
    998 
    999     /* if noLogsToShow then ceate a single log page with an error message: */
    1000     // if (noLogsToShow)
    1001     // {
    1002     //     createLogPage("No Logs", strDummyTabText, noLogsToShow);
    1003     // }
    1004     return noLogsToShow;
     993        if (fNoLogFileForMachine)
     994        {
     995            QString strDummyTabText = QString(tr("<p>No log files for the machine %1 found. Press the "
     996                                                 "<b>Rescan</b> button to rescan the log folder "
     997                                                 "<nobr><b>%2</b></nobr>.</p>")
     998                                              .arg(strMachineName).arg(comMachine.GetLogFolder()));
     999            createLogPage(tr("NoLogFile"), strMachineName, uMachineId, -1 /* iLogFileId */, strDummyTabText, true);
     1000        }
     1001    }
    10051002}
    10061003
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r88700 r88702  
    9797    void sltSaveOptions();
    9898
    99     /** Handles refresh action triggering. */
     99    /** Rereads the log file shown in the current tab. */
    100100    void sltRefresh();
    101101    /** Handles save action triggering. */
     
    172172    /** Returns the newly created log-page using @a strPage filename. */
    173173    void createLogPage(const QString &strFileName, const QString &strMachineName,
    174                        const QUuid &machineId,
    175                        const QString &strLogContent, bool noLogsToShow = false);
     174                       const QUuid &machineId, int iLogFileId,
     175                       const QString &strLogContent, bool noLogsToShow);
    176176
    177177    const UIVMLogPage *currentLogPage() const;
     
    180180    UIVMLogPage *logPage(int iIndex);
    181181
    182     /** Attempts to read the logs through the API, returns true if there exists any logs, false otherwise.
    183      *  @p machineList is the list of machine whose log should be read. */
    184     bool createLogViewerPages(const QVector<QUuid> &machineList);
     182    void createLogViewerPages(const QVector<QUuid> &machineList);
    185183    /** Removes the log pages/tabs that shows logs of the machines from @p machineList. */
    186184    void removeLogViewerPages(const QVector<QUuid> &machineList);
     
    198196    void updateMachineSelectionMenu();
    199197    void setMachines(const QVector<QUuid> &machineIDs);
     198    /** Returns the content of the ith log file of @comMachine or possibly an empty string */
     199    QString readLogFile(CMachine &comMachine, int iLogFileId);
    200200
    201201    /** Holds the widget's embedding type. */
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