1 | /* $Id: UIVMLogViewerWidget.h 77078 2019-01-31 15:34:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMLogViewerWidget class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerWidget_h
|
---|
19 | #define FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerWidget_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QKeySequence>
|
---|
26 | #include <QPair>
|
---|
27 | #include <QWidget>
|
---|
28 |
|
---|
29 | /* GUI includes: */
|
---|
30 | #include "QIManagerDialog.h"
|
---|
31 | #include "QIWithRetranslateUI.h"
|
---|
32 | #include "UILibraryDefs.h"
|
---|
33 |
|
---|
34 | /* COM includes: */
|
---|
35 | #include "COMEnums.h"
|
---|
36 | #include "CMachine.h"
|
---|
37 |
|
---|
38 | /* Forward declarations: */
|
---|
39 | class QITabWidget;
|
---|
40 | class QPlainTextEdit;
|
---|
41 | class QVBoxLayout;
|
---|
42 | class UIActionPool;
|
---|
43 | class UIDialogPanel;
|
---|
44 | class UIToolBar;
|
---|
45 | class UIVMLogPage;
|
---|
46 | class UIVMLogViewerBookmarksPanel;
|
---|
47 | class UIVMLogViewerFilterPanel;
|
---|
48 | class UIVMLogViewerPanel;
|
---|
49 | class UIVMLogViewerSearchPanel;
|
---|
50 | class UIVMLogViewerOptionsPanel;
|
---|
51 |
|
---|
52 | /** QWidget extension providing GUI for VirtualBox LogViewer. It
|
---|
53 | * encapsulates log pages, toolbar, a tab widget and manages
|
---|
54 | * interaction between these classes. */
|
---|
55 | class SHARED_LIBRARY_STUFF UIVMLogViewerWidget : public QIWithRetranslateUI<QWidget>
|
---|
56 | {
|
---|
57 | Q_OBJECT;
|
---|
58 |
|
---|
59 | signals:
|
---|
60 |
|
---|
61 | void sigSetCloseButtonShortCut(QKeySequence);
|
---|
62 |
|
---|
63 | public:
|
---|
64 |
|
---|
65 | /** Constructs the VM Log-Viewer by passing @a pParent to QWidget base-class constructor.
|
---|
66 | * @param enmEmbedding Brings the type of widget embedding.
|
---|
67 | * @param pActionPool Brings the action-pool reference.
|
---|
68 | * @param fShowToolbar Brings whether we should create/show toolbar.
|
---|
69 | * @param comMachine Brings the machine for which VM Log-Viewer is requested. */
|
---|
70 | UIVMLogViewerWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool,
|
---|
71 | bool fShowToolbar = true, const CMachine &comMachine = CMachine(), QWidget *pParent = 0);
|
---|
72 | /** Destructs the VM Log-Viewer. */
|
---|
73 | ~UIVMLogViewerWidget();
|
---|
74 | /** Returns the width of the current log page. return 0 if there is no current log page: */
|
---|
75 | int defaultLogPageWidth() const;
|
---|
76 |
|
---|
77 | /** Returns the menu. */
|
---|
78 | QMenu *menu() const;
|
---|
79 |
|
---|
80 | #ifdef VBOX_WS_MAC
|
---|
81 | /** Returns the toolbar. */
|
---|
82 | UIToolBar *toolbar() const { return m_pToolBar; }
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | /** Defines the @a comMachine whose logs to show. */
|
---|
86 | void setMachine(const CMachine &comMachine);
|
---|
87 | QFont currentFont() const;
|
---|
88 |
|
---|
89 | protected:
|
---|
90 |
|
---|
91 | /** Returns whether the window should be maximized when geometry being restored. */
|
---|
92 | virtual bool shouldBeMaximized() const /* override */;
|
---|
93 |
|
---|
94 | private slots:
|
---|
95 |
|
---|
96 | /** Handles refresh action triggering. */
|
---|
97 | void sltRefresh();
|
---|
98 | /** Handles save action triggering. */
|
---|
99 | void sltSave();
|
---|
100 |
|
---|
101 | /** @name Bookmark related slots
|
---|
102 | * @{ */
|
---|
103 | /** Deletes the bookmark with @p index from the current logs bookmark list. */
|
---|
104 | void sltDeleteBookmark(int index);
|
---|
105 | /** Receives delete all signal from the bookmark panel and notifies UIVMLogPage. */
|
---|
106 | void sltDeleteAllBookmarks();
|
---|
107 | /** Manages bookmark panel update when bookmark vector is updated. */
|
---|
108 | void sltUpdateBookmarkPanel();
|
---|
109 | /** Makes the current UIVMLogPage to goto (scroll) its bookmark with index @a index. */
|
---|
110 | void gotoBookmark(int bookmarkIndex);
|
---|
111 | /** @} */
|
---|
112 |
|
---|
113 | void sltPanelActionToggled(bool fChecked);
|
---|
114 | /** Handles the search result highlight changes. */
|
---|
115 | void sltSearchResultHighLigting();
|
---|
116 | void sltHandleSearchUpdated();
|
---|
117 | /** Handles the tab change of the logviewer. */
|
---|
118 | void sltTabIndexChange(int tabIndex);
|
---|
119 | /* if @a isOriginal true than the result of the filtering is equal to
|
---|
120 | the original log file for some reason. */
|
---|
121 | void sltFilterApplied(bool isOriginal);
|
---|
122 | /* Handles the UIVMLogPage signal which is emitted when isFiltered property
|
---|
123 | of UIVMLogPage is changed. */
|
---|
124 | void sltLogPageFilteredChanged(bool isFiltered);
|
---|
125 | void sltHandleHidePanel(UIDialogPanel *pPanel);
|
---|
126 |
|
---|
127 | /** @name Slots to handle signals from settings panel
|
---|
128 | * @{ */
|
---|
129 | void sltShowLineNumbers(bool bShowLineNumbers);
|
---|
130 | void sltWrapLines(bool bWrapLine);
|
---|
131 | void sltFontSizeChanged(int fontSize);
|
---|
132 | void sltChangeFont(QFont font);
|
---|
133 | void sltResetOptionsToDefault();
|
---|
134 | /** @} */
|
---|
135 |
|
---|
136 | private:
|
---|
137 |
|
---|
138 | /** @name Prepare/Cleanup
|
---|
139 | * @{ */
|
---|
140 | /** Prepares VM Log-Viewer. */
|
---|
141 | void prepare();
|
---|
142 | /** Prepares actions. */
|
---|
143 | void prepareActions();
|
---|
144 | /** Prepares widgets. */
|
---|
145 | void prepareWidgets();
|
---|
146 | /** Prepares toolbar. */
|
---|
147 | void prepareToolBar();
|
---|
148 | /** Loads options. */
|
---|
149 | void loadOptions();
|
---|
150 | /** Shows the panels that have been visible the last time logviewer is closed. */
|
---|
151 | void restorePanelVisibility();
|
---|
152 |
|
---|
153 | /** Saves options. */
|
---|
154 | void saveOptions();
|
---|
155 | /** Cleanups VM Log-Viewer. */
|
---|
156 | void cleanup();
|
---|
157 | /** @} */
|
---|
158 |
|
---|
159 | /** @name Event handling stuff.
|
---|
160 | * @{ */
|
---|
161 | /** Handles translation event. */
|
---|
162 | virtual void retranslateUi() /* override */;
|
---|
163 |
|
---|
164 | /** Handles Qt show @a pEvent. */
|
---|
165 | virtual void showEvent(QShowEvent *pEvent) /* override */;
|
---|
166 | /** Handles Qt key-press @a pEvent. */
|
---|
167 | virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
|
---|
168 | /** @} */
|
---|
169 |
|
---|
170 |
|
---|
171 | /** Returns the log-page from the tab with index @a pIndex. */
|
---|
172 | QPlainTextEdit* logPage(int pIndex) const;
|
---|
173 | /** Returns the newly created log-page using @a strPage filename. */
|
---|
174 | void createLogPage(const QString &strFileName, const QString &strLogContent, bool noLogsToShow = false);
|
---|
175 |
|
---|
176 | const UIVMLogPage *currentLogPage() const;
|
---|
177 | UIVMLogPage *currentLogPage();
|
---|
178 |
|
---|
179 | /** Attempts to read the logs through the API, returns true if there exists any logs, false otherwise. */
|
---|
180 | bool createLogViewerPages();
|
---|
181 |
|
---|
182 | /** Resets document (of the curent tab) and scrollbar highligthing */
|
---|
183 | void resetHighlighthing();
|
---|
184 |
|
---|
185 | void hidePanel(UIDialogPanel* panel);
|
---|
186 | void showPanel(UIDialogPanel* panel);
|
---|
187 |
|
---|
188 | /** Make sure escape key is assigned to only a single widget. This is done by checking
|
---|
189 | several things in the following order:
|
---|
190 | - when there are no more panels visible assign it to the parent dialog
|
---|
191 | - grab it from the dialog as soon as a panel becomes visible again
|
---|
192 | - assigned it to the most recently "unhidden" panel */
|
---|
193 | void manageEscapeShortCut();
|
---|
194 |
|
---|
195 | /** Holds the widget's embedding type. */
|
---|
196 | const EmbedTo m_enmEmbedding;
|
---|
197 | /** Hold sthe action-pool reference. */
|
---|
198 | UIActionPool *m_pActionPool;
|
---|
199 | /** Holds whether we should create/show toolbar. */
|
---|
200 | const bool m_fShowToolbar;
|
---|
201 | /** Holds the machine instance. */
|
---|
202 | CMachine m_comMachine;
|
---|
203 |
|
---|
204 | /** Holds whether the dialog is polished. */
|
---|
205 | bool m_fIsPolished;
|
---|
206 |
|
---|
207 | /** Holds container for log-pages. */
|
---|
208 | QITabWidget *m_pTabWidget;
|
---|
209 | /** Stores the UIVMLogPage instances. This is modified as we add and remove new tabs
|
---|
210 | * to the m_pTabWidget. Index is the index of the tab widget. */
|
---|
211 | QVector<QWidget*> m_logPageList;
|
---|
212 |
|
---|
213 | /** @name Panel instances and a QMap for mapping panel instances to related actions.
|
---|
214 | * @{ */
|
---|
215 | UIVMLogViewerSearchPanel *m_pSearchPanel;
|
---|
216 | UIVMLogViewerFilterPanel *m_pFilterPanel;
|
---|
217 | UIVMLogViewerBookmarksPanel *m_pBookmarksPanel;
|
---|
218 | UIVMLogViewerOptionsPanel *m_pOptionsPanel;
|
---|
219 | QMap<UIDialogPanel*, QAction*> m_panelActionMap;
|
---|
220 | QList<UIDialogPanel*> m_visiblePanelsList;
|
---|
221 | /** @} */
|
---|
222 | QVBoxLayout *m_pMainLayout;
|
---|
223 |
|
---|
224 | /** @name Toolbar and menu variables.
|
---|
225 | * @{ */
|
---|
226 | UIToolBar *m_pToolBar;
|
---|
227 | /** @} */
|
---|
228 |
|
---|
229 | /** @name Toolbar and menu variables. Cache these to restore them after refresh.
|
---|
230 | * @{ */
|
---|
231 | /** Showing/hiding line numbers and line wraping options are set per
|
---|
232 | UIVMLogViewerWidget and applies to all log pages (all tabs) */
|
---|
233 | bool m_bShowLineNumbers;
|
---|
234 | bool m_bWrapLines;
|
---|
235 | QFont m_font;
|
---|
236 | /** @} */
|
---|
237 | friend class UIVMLogViewerFilterPanel;
|
---|
238 | friend class UIVMLogViewerPanel;
|
---|
239 | friend class UIVMLogViewerDialog;
|
---|
240 | };
|
---|
241 |
|
---|
242 | #endif /* !FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerWidget_h */
|
---|