VirtualBox

Changeset 28344 in vbox


Ignore:
Timestamp:
Apr 15, 2010 2:50:36 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60103
Message:

FE/Qt4: use the new ReadLog Main method in the log viewer.

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

Legend:

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

    r26719 r28344  
    164164{
    165165    /* Clearing old data if any */
    166     mLogFilesList.clear();
     166    mLogFiles.clear();
    167167    mLogList->setEnabled (true);
    168168    while (mLogList->count())
     
    175175    bool isAnyLogPresent = false;
    176176
    177     /* Entering log files folder */
    178     QString logFilesPath = mMachine.GetLogFolder();
    179     QDir logFilesDir (logFilesPath);
    180     if (logFilesDir.exists())
    181     {
    182         /* Reading log files folder */
    183         QStringList filters;
    184         filters << "*.log" << "*.log.*";
    185         logFilesDir.setNameFilters (filters);
    186         QStringList logList = logFilesDir.entryList (QDir::Files);
    187         if (!logList.empty()) isAnyLogPresent = true;
    188         foreach (QString logFile, logList)
    189             loadLogFile (logFilesDir.filePath (logFile));
     177    const CSystemProperties &sys = vboxGlobal().virtualBox().GetSystemProperties();
     178    int cMaxLogs = sys.GetLogHistoryCount();
     179    for (int i=0; i <= cMaxLogs; ++i)
     180    {
     181        /* Query the log file name for index i */
     182        QString file = mMachine.QueryLogFilename(i);
     183        if (!file.isEmpty())
     184        {
     185            /* Try to read the log file with the index i */
     186            ULONG uOffset = 0;
     187            QString text;
     188            while (true)
     189            {
     190                QVector<BYTE> data = mMachine.ReadLog(i, uOffset, _1M);
     191                if (data.size() == 0)
     192                    break;
     193                text.append(QString::fromUtf8((char*)data.data(), data.size()));
     194                uOffset += data.size();
     195            }
     196            /* Anything read at all? */
     197            if (uOffset > 0)
     198            {
     199                /* Create a log viewer page and append the read text to it */
     200                QTextEdit *logViewer = createLogPage(QFileInfo(file).fileName());
     201                logViewer->setPlainText(text);
     202                /* Add the actual file name and the QTextEdit containing the
     203                   content to a list. */
     204                mLogFiles << qMakePair(file, logViewer);
     205                isAnyLogPresent = true;
     206            }
     207        }
    190208    }
    191209
     
    198216            "<b>Refresh</b> button to rescan the log folder "
    199217            "<nobr><b>%1</b></nobr>.</p>")
    200             .arg (logFilesPath));
     218            .arg (mMachine.GetLogFolder()));
    201219        /* We don't want it to remain white */
    202220        QPalette pal = dummyLog->palette();
     
    222240{
    223241    /* Prepare "save as" dialog */
    224     QFileInfo fileInfo (mLogFilesList [mLogList->currentIndex()]);
     242    QFileInfo fileInfo (mLogFiles.at(mLogList->currentIndex()).first);
    225243    QDateTime dtInfo = fileInfo.lastModified();
    226244    QString dtString = dtInfo.toString ("yyyy-MM-dd-hh-mm-ss");
     
    236254    {
    237255        /* Reread log data */
    238         QFile oldFile (mLogFilesList [mLogList->currentIndex()]);
    239256        QFile newFile (newFileName);
    240         if (!oldFile.open (QIODevice::ReadOnly) ||
    241             !newFile.open (QIODevice::WriteOnly))
     257        if (!newFile.open (QIODevice::WriteOnly))
    242258            return;
    243259
    244260        /* Save log data into the new file */
    245         newFile.write (oldFile.readAll());
     261        newFile.write (mLogFiles.at(mLogList->currentIndex()).second->toPlainText().toUtf8());
    246262    }
    247263}
     
    255271{
    256272    if (aIndex >= 0 &&
    257         aIndex < mLogFilesList.count())
    258         setFileForProxyIcon (mLogFilesList.at (aIndex));
     273        aIndex < mLogFiles.count())
     274        setFileForProxyIcon(mLogFiles.at(aIndex).first);
    259275}
    260276
     
    311327    if (w)
    312328        w->setFocus();
    313 }
    314 
    315 void VBoxVMLogViewer::loadLogFile (const QString &aFileName)
    316 {
    317     /* Prepare log file */
    318     QFile logFile (aFileName);
    319     if (!logFile.exists() || !logFile.open (QIODevice::ReadOnly))
    320         return;
    321 
    322     /* Read log file and write it into the log page */
    323     QTextEdit *logViewer = createLogPage (QFileInfo (aFileName).fileName());
    324     logViewer->setPlainText (logFile.readAll());
    325 
    326     mLogFilesList << aFileName;
    327329}
    328330
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMLogViewer.h

    r25171 r28344  
    7373
    7474    void showEvent (QShowEvent *aEvent);
    75     void loadLogFile (const QString &aName);
    7675    QTextEdit* createLogPage (const QString &aPage);
    7776
     
    8281    CMachine              mMachine;
    8382    QTabWidget           *mLogList;
    84     QStringList           mLogFilesList;
    8583    VBoxLogSearchPanel   *mSearchPanel;
     84    QList< QPair<QString, QTextEdit*> > mLogFiles;
    8685
    8786    QPushButton *mBtnHelp;
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