1 | /* $Id: UIVMLogViewerWidget.h 103923 2024-03-19 17:01:11Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMLogViewerWidget class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerWidget_h
|
---|
29 | #define FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerWidget_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QKeySequence>
|
---|
36 | #include <QPair>
|
---|
37 | #include <QPointer>
|
---|
38 | #include <QSet>
|
---|
39 | #include <QWidget>
|
---|
40 | #include <QUuid>
|
---|
41 |
|
---|
42 | /* GUI includes: */
|
---|
43 | #include "QIManagerDialog.h"
|
---|
44 |
|
---|
45 | /* Forward declarations: */
|
---|
46 | class QVBoxLayout;
|
---|
47 | class QIToolBar;
|
---|
48 | class QIToolButton;
|
---|
49 | class UIActionPool;
|
---|
50 | class UIDialogPanel;
|
---|
51 | class UIMachineListMenu;
|
---|
52 | class UITabWidget;
|
---|
53 | class UIVirtualMachineItem;
|
---|
54 | class UIVMLogPage;
|
---|
55 | class UIVMLogTab;
|
---|
56 | class UIVMLogViewerBookmarksPanel;
|
---|
57 | class UIVMLogViewerPaneContainer;
|
---|
58 | class UIVMLogViewerFilterPanel;
|
---|
59 | class UIVMLogViewerPanel;
|
---|
60 | class CMachine;
|
---|
61 |
|
---|
62 | /** QWidget extension providing GUI for VirtualBox LogViewer. It
|
---|
63 | * encapsulates log pages, toolbar, a tab widget and manages
|
---|
64 | * interaction between these classes. */
|
---|
65 | class SHARED_LIBRARY_STUFF UIVMLogViewerWidget : public QWidget
|
---|
66 | {
|
---|
67 | Q_OBJECT;
|
---|
68 |
|
---|
69 | signals:
|
---|
70 |
|
---|
71 | void sigSetCloseButtonShortCut(QKeySequence);
|
---|
72 | void sigDetach();
|
---|
73 |
|
---|
74 | public:
|
---|
75 |
|
---|
76 | /** Constructs the VM Log-Viewer by passing @a pParent to QWidget base-class constructor.
|
---|
77 | * @param enmEmbedding Brings the type of widget embedding.
|
---|
78 | * @param pActionPool Brings the action-pool reference.
|
---|
79 | * @param fShowToolbar Brings whether we should create/show toolbar.
|
---|
80 | * @param machineIDs Brings the list of machine IDs. */
|
---|
81 | UIVMLogViewerWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool,
|
---|
82 | bool fShowToolbar = true, const QList<QUuid> &machineIDs = QList<QUuid>(), QWidget *pParent = 0);
|
---|
83 | ~UIVMLogViewerWidget();
|
---|
84 |
|
---|
85 | /** Returns the widget's embedding type. */
|
---|
86 | EmbedTo embeddingType() const { return m_enmEmbedding; }
|
---|
87 |
|
---|
88 | /** Returns the width of the current log page. return 0 if there is no current log page: */
|
---|
89 | int defaultLogPageWidth() const;
|
---|
90 |
|
---|
91 | /** Returns the menu. */
|
---|
92 | QMenu *menu() const;
|
---|
93 |
|
---|
94 | #ifdef VBOX_WS_MAC
|
---|
95 | /** Returns the toolbar. */
|
---|
96 | QIToolBar *toolbar() const { return m_pToolBar; }
|
---|
97 | #endif
|
---|
98 |
|
---|
99 | void setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items);
|
---|
100 | QFont currentFont() const;
|
---|
101 |
|
---|
102 | protected:
|
---|
103 |
|
---|
104 | /** Returns whether the window should be maximized when geometry being restored. */
|
---|
105 | virtual bool shouldBeMaximized() const;
|
---|
106 |
|
---|
107 | private slots:
|
---|
108 |
|
---|
109 | /** Rereads the log file shown in the current tab. */
|
---|
110 | void sltRefresh();
|
---|
111 | /** Rereads all the log files . */
|
---|
112 | void sltReload();
|
---|
113 | /** Handles save action triggering. */
|
---|
114 | void sltSave();
|
---|
115 |
|
---|
116 | /** @name Bookmark related slots
|
---|
117 | * @{ */
|
---|
118 | /** Deletes the bookmark with @p index from the current logs bookmark list. */
|
---|
119 | void sltDeleteBookmarkByIndex(int index);
|
---|
120 | /** Receives delete all signal from the bookmark panel and notifies UIVMLogPage. */
|
---|
121 | void sltDeleteAllBookmarks();
|
---|
122 | /** Manages bookmark panel update when bookmark vector is updated. */
|
---|
123 | void sltUpdateBookmarkPanel();
|
---|
124 | /** Makes the current UIVMLogPage to goto (scroll) its bookmark with index @a index. */
|
---|
125 | void gotoBookmark(int bookmarkIndex);
|
---|
126 | /** @} */
|
---|
127 |
|
---|
128 | void sltPanelActionToggled(bool fChecked);
|
---|
129 | /** Handles the search result highlight changes. */
|
---|
130 | void sltSearchResultHighLigting();
|
---|
131 | void sltHandleSearchUpdated();
|
---|
132 | /** Handles the tab change of the logviewer. */
|
---|
133 | void sltCurrentTabChanged(int tabIndex);
|
---|
134 | void sltFilterApplied();
|
---|
135 | /* Handles the UIVMLogPage signal which is emitted when isFiltered property
|
---|
136 | of UIVMLogPage is changed. */
|
---|
137 | void sltLogPageFilteredChanged(bool isFiltered);
|
---|
138 |
|
---|
139 | /** @name Slots to handle signals from settings panel
|
---|
140 | * @{ */
|
---|
141 | void sltShowLineNumbers(bool bShowLineNumbers);
|
---|
142 | void sltWrapLines(bool bWrapLine);
|
---|
143 | void sltFontSizeChanged(int fontSize);
|
---|
144 | void sltChangeFont(QFont font);
|
---|
145 | void sltResetOptionsToDefault();
|
---|
146 | /** @} */
|
---|
147 | void sltCloseMachineLogs();
|
---|
148 | void sltCommitDataSignalReceived();
|
---|
149 | void sltPanelContainerHidden();
|
---|
150 | void sltPanelCurrentTabChanged(int iIndex);
|
---|
151 | void sltShowSearchPane();
|
---|
152 | void sltRetranslateUI();
|
---|
153 |
|
---|
154 | private:
|
---|
155 |
|
---|
156 | /** @name Prepare/Cleanup
|
---|
157 | * @{ */
|
---|
158 | /** Prepares VM Log-Viewer. */
|
---|
159 | void prepare();
|
---|
160 | /** Prepares actions. */
|
---|
161 | void prepareActions();
|
---|
162 | /** Prepares widgets. */
|
---|
163 | void prepareWidgets();
|
---|
164 | /** Prepares toolbar. */
|
---|
165 | void prepareToolBar();
|
---|
166 | void saveOptions();
|
---|
167 | /** Loads options. */
|
---|
168 | void loadOptions();
|
---|
169 | /** @} */
|
---|
170 |
|
---|
171 | /** @name Event handling stuff.
|
---|
172 | * @{ */
|
---|
173 | /** Handles Qt show @a pEvent. */
|
---|
174 | virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
|
---|
175 | /** Handles Qt key-press @a pEvent. */
|
---|
176 | virtual void keyPressEvent(QKeyEvent *pEvent) RT_OVERRIDE;
|
---|
177 | /** @} */
|
---|
178 |
|
---|
179 | /** Returns the newly created log-page using @a strPage filename. */
|
---|
180 | void createLogPage(const QString &strFileName,
|
---|
181 | const QString &strMachineName,
|
---|
182 | const QUuid &machineId, int iLogFileId,
|
---|
183 | const QString &strLogContent, bool noLogsToShow);
|
---|
184 |
|
---|
185 | const UIVMLogPage *currentLogPage() const;
|
---|
186 | UIVMLogPage *currentLogPage();
|
---|
187 | /** Returns the log tab at tab with iIndex if it contains a log page. Return 0 otherwise. */
|
---|
188 | UIVMLogTab *logTab(int iIndex);
|
---|
189 | UIVMLogPage *logPage(int iIndex);
|
---|
190 | /** Returns a vector of all the log pages of the tab widget. */
|
---|
191 | QVector<UIVMLogTab*> logTabs();
|
---|
192 |
|
---|
193 | void createLogViewerPages(const QVector<QUuid> &machineList);
|
---|
194 | /** Removes the log pages/tabs that shows logs of the machines from @p machineList. */
|
---|
195 | void removeLogViewerPages(const QVector<QUuid> &machineList);
|
---|
196 | void removeAllLogPages();
|
---|
197 | void markLabelTabs();
|
---|
198 |
|
---|
199 | /** Resets document (of the current tab) and scrollbar highligthing */
|
---|
200 | void resetHighlighthing();
|
---|
201 | void setMachines(const QVector<QUuid> &machineIDs);
|
---|
202 | /** Returns the content of the ith log file of @comMachine or possibly an empty string */
|
---|
203 | QString readLogFile(const CMachine &comConstMachine, int iLogFileId);
|
---|
204 | /** If the current tab is a label tab then switch to the next tab and return true. Returns false otherwise. */
|
---|
205 | bool labelTabHandler();
|
---|
206 | void uncheckPaneActions();
|
---|
207 |
|
---|
208 | /** Holds the widget's embedding type. */
|
---|
209 | const EmbedTo m_enmEmbedding;
|
---|
210 | /** Holds the action-pool reference. Wrapped around with QPointer to avoid use-after-delete case during vm window close.*/
|
---|
211 | QPointer<UIActionPool> m_pActionPool;
|
---|
212 | /** Holds whether we should create/show toolbar. */
|
---|
213 | const bool m_fShowToolbar;
|
---|
214 | QVector<QUuid> m_machines;
|
---|
215 |
|
---|
216 | /** Holds whether the dialog is polished. */
|
---|
217 | bool m_fIsPolished;
|
---|
218 |
|
---|
219 | /** Holds container for log-pages. */
|
---|
220 | UITabWidget *m_pTabWidget;
|
---|
221 |
|
---|
222 | /** @name Panel instances and a QMap for mapping panel instances to related actions.
|
---|
223 | * @{ */
|
---|
224 | QList<UIDialogPanel*> m_visiblePanelsList;
|
---|
225 | /** @} */
|
---|
226 | QVBoxLayout *m_pMainLayout;
|
---|
227 |
|
---|
228 | /** @name Toolbar and menu variables.
|
---|
229 | * @{ */
|
---|
230 | QIToolBar *m_pToolBar;
|
---|
231 | /** @} */
|
---|
232 |
|
---|
233 | /** @name Toolbar and menu variables. Cache these to restore them after refresh.
|
---|
234 | * @{ */
|
---|
235 | /** Showing/hiding line numbers and line wraping options are set per
|
---|
236 | UIVMLogViewerWidget and applies to all log pages (all tabs) */
|
---|
237 | bool m_bShowLineNumbers;
|
---|
238 | bool m_bWrapLines;
|
---|
239 | QFont m_font;
|
---|
240 | /** @} */
|
---|
241 | QIToolButton *m_pCornerButton;
|
---|
242 | UIMachineListMenu *m_pMachineSelectionMenu;
|
---|
243 | /** All extra data saves are done dynamically (as an option changes etc.). The this flag is true
|
---|
244 | * we should not try to save anything to extra data anymore. */
|
---|
245 | bool m_fCommitDataSignalReceived;
|
---|
246 | QPointer<UIVMLogPage> m_pPreviousLogPage;
|
---|
247 | UIVMLogViewerPaneContainer *m_pPanel;
|
---|
248 | QSet<QAction*> m_paneActions;
|
---|
249 | friend class UIVMLogViewerFilterWidget;
|
---|
250 | friend class UIVMLogViewerPane;
|
---|
251 | friend class UIVMLogViewerDialog;
|
---|
252 | };
|
---|
253 |
|
---|
254 | #endif /* !FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerWidget_h */
|
---|