Changeset 88702 in vbox for trunk/src/VBox
- Timestamp:
- Apr 26, 2021 10:40:36 AM (4 years ago)
- 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 40 40 , m_iFilteredLineCount(-1) 41 41 , m_iUnfilteredLineCount(-1) 42 , m_iLogFileId(-1) 42 43 { 43 44 prepare(); … … 341 342 m_machineId = machineId; 342 343 } 344 345 void UIVMLogPage::setLogFileId(int iLogFileId) 346 { 347 m_iLogFileId = iLogFileId; 348 } 349 350 int UIVMLogPage::logFileId() const 351 { 352 return m_iLogFileId; 353 } -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h
r88687 r88702 117 117 void setMachineId(const QUuid &machineId); 118 118 119 void setLogFileId(int iLogFileId); 120 int logFileId() const; 121 119 122 private slots: 120 123 … … 162 165 /** Id of the machine the log shown in this page belongs to. */ 163 166 QUuid m_machineId; 167 /** The id we pass to CMachine::ReadLog. Used while refreshing and saving page content. */ 168 int m_iLogFileId; 164 169 }; 165 170 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp
r88701 r88702 224 224 } 225 225 226 QString 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 226 248 QFont UIVMLogViewerWidget::currentFont() const 227 249 { … … 249 271 void UIVMLogViewerWidget::sltRefresh() 250 272 { 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: */ 254 288 // disconnect(m_pTabWidget, &QITabWidget::currentChanged, m_pFilterPanel, &UIVMLogViewerFilterPanel::applyFilter); 255 289 // disconnect(m_pTabWidget, &QITabWidget::currentChanged, this, &UIVMLogViewerWidget::sltTabIndexChange); … … 563 597 retranslateUi(); 564 598 565 /* Reading log files: */566 sltRefresh();567 599 /* Setup escape shortcut: */ 568 600 manageEscapeShortCut(); … … 864 896 865 897 void 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) 868 900 { 869 901 if (!m_pTabWidget) … … 881 913 pLogPage->setCurrentFont(m_font); 882 914 pLogPage->setMachineId(machineId); 915 pLogPage->setLogFileId(iLogFileId); 883 916 /* Set the file name only if we really have log file to read. */ 884 917 if (!noLogsToShow) 885 918 pLogPage->setLogFileName(strFileName); 886 919 887 /* Add page-container to viewer-container : */920 /* Add page-container to viewer-container in stacked mode (manager UI case): */ 888 921 bool fTitleWithMachineName = m_enmEmbedding == EmbedTo_Stack; 889 922 QString strTabTitle; … … 934 967 } 935 968 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 969 void UIVMLogViewerWidget::createLogViewerPages(const QVector<QUuid> &machineList) 970 { 949 971 const CSystemProperties &sys = uiCommon().virtualBox().GetSystemProperties(); 950 972 unsigned cMaxLogs = sys.GetLogHistoryCount() + 1 /*VBox.log*/ + 1 /*VBoxHardening.log*/; /** @todo Add api for getting total possible log count! */ 951 //bool logFileRead = false;952 973 foreach (const QUuid &machineId, machineList) 953 974 { 954 975 CMachine comMachine = uiCommon().virtualBox().FindMachine(machineId.toString()); 955 956 976 if (comMachine.isNull()) 957 977 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()) 963 986 { 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); 987 991 } 988 992 } 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 } 1005 1002 } 1006 1003 -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h
r88700 r88702 97 97 void sltSaveOptions(); 98 98 99 /** Handles refresh action triggering. */99 /** Rereads the log file shown in the current tab. */ 100 100 void sltRefresh(); 101 101 /** Handles save action triggering. */ … … 172 172 /** Returns the newly created log-page using @a strPage filename. */ 173 173 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); 176 176 177 177 const UIVMLogPage *currentLogPage() const; … … 180 180 UIVMLogPage *logPage(int iIndex); 181 181 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); 185 183 /** Removes the log pages/tabs that shows logs of the machines from @p machineList. */ 186 184 void removeLogViewerPages(const QVector<QUuid> &machineList); … … 198 196 void updateMachineSelectionMenu(); 199 197 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); 200 200 201 201 /** Holds the widget's embedding type. */
Note:
See TracChangeset
for help on using the changeset viewer.