1 /* 2 * Copyright (C) 2009, 2010, 2011, 2013 Nicolas Bonnefon 3 * and other contributors 4 * 5 * This file is part of glogg. 6 * 7 * glogg is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * glogg is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with glogg. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef CRAWLERWIDGET_H 22 #define CRAWLERWIDGET_H 23 24 #include <QSplitter> 25 #include <QComboBox> 26 #include <QPushButton> 27 #include <QCheckBox> 28 #include <QToolButton> 29 #include <QVBoxLayout> 30 #include <QHBoxLayout> 31 #include <QLabel> 32 33 #include "logmainview.h" 34 #include "filteredview.h" 35 #include "data/logdata.h" 36 #include "data/logfiltereddata.h" 37 #include "viewinterface.h" 38 39 class InfoLine; 40 class QuickFindPattern; 41 class SavedSearches; 42 class Overview; 43 class QStandardItemModel; 44 class OverviewWidget; 45 46 // Implements the central widget of the application. 47 // It includes both windows, the search line, the info 48 // lines and various buttons. 49 class CrawlerWidget : public QSplitter, 50 public QuickFindMuxSelectorInterface, public ViewInterface 51 { 52 Q_OBJECT 53 54 public: 55 CrawlerWidget( QWidget *parent=0 ); 56 57 // Get the line number of the first line displayed. 58 int getTopLine() const; 59 // Get the selected text as a string (from the main window) 60 QString getSelectedText() const; 61 62 // Display the QFB at the bottom, remembering where the focus was 63 void displayQuickFindBar( QuickFindMux::QFDirection direction ); 64 65 // Instructs the widget to select all the text in the window the user 66 // is interacting with 67 void selectAll(); 68 69 public slots: 70 // Stop the asynchoronous loading of the file if one is in progress 71 // The file is identified by the view attached to it. 72 void stopLoading(); 73 // Reload the displayed file 74 void reload(); 75 76 protected: 77 // Implementation of the ViewInterface functions 78 virtual void doSetData( 79 std::shared_ptr<LogData> log_data, 80 std::shared_ptr<LogFilteredData> filtered_data ); 81 virtual void doSetQuickFindPattern( 82 std::shared_ptr<QuickFindPattern> qfp ); 83 virtual void doSetSavedSearches( 84 std::shared_ptr<SavedSearches> saved_searches ); 85 86 // Implementation of the mux selector interface 87 // (for dispatching QuickFind to the right widget) 88 virtual SearchableWidgetInterface* doGetActiveSearchable() const; 89 virtual std::vector<QObject*> doGetAllSearchables() const; 90 91 signals: 92 // Sent to signal the client load has progressed, 93 // passing the completion percentage. 94 void loadingProgressed( int progress ); 95 // Sent to the client when the loading has finished 96 // weither succesfull or not. 97 void loadingFinished( bool success ); 98 // Sent when follow mode is enabled/disabled 99 void followSet( bool checked ); 100 // Sent up to the MainWindow to disable the follow mode 101 void followDisabled(); 102 // Sent up when the current line number is updated 103 void updateLineNumber( int line ); 104 105 private slots: 106 // Instructs the widget to start a search using the current search line. 107 void startNewSearch(); 108 // Stop the currently ongoing search (if one exists) 109 void stopSearch(); 110 // Instructs the widget to reconfigure itself because Config() has changed. 111 void applyConfiguration(); 112 // QuickFind is being entered, save the focus for incremental qf. 113 void enteringQuickFind(); 114 // QuickFind is being closed. 115 void exitingQuickFind(); 116 // Called when new data must be displayed in the filtered window. 117 void updateFilteredView( int nbMatches, int progress ); 118 // Called when a new line has been selected in the filtered view, 119 // to instruct the main view to jump to the matching line. 120 void jumpToMatchingLine( int filteredLineNb ); 121 // Mark a line that has been clicked on the main (top) view. 122 void markLineFromMain( qint64 line ); 123 // Mark a line that has been clicked on the filtered (bottom) view. 124 void markLineFromFiltered( qint64 line ); 125 126 void loadingFinishedHandler( bool success ); 127 // Manages the info lines to inform the user the file has changed. 128 void fileChangedHandler( LogData::MonitoredFileStatus ); 129 130 void searchForward(); 131 void searchBackward(); 132 133 // Called when the checkbox for search auto-refresh is changed 134 void searchRefreshChangedHandler( int state ); 135 136 // Called when the text on the search line is modified 137 void searchTextChangeHandler(); 138 139 // Called when the user change the visibility combobox 140 void changeFilteredViewVisibility( int index ); 141 142 // Called when the user add the string to the search 143 void addToSearch( const QString& string ); 144 145 // Called when a match is hovered on in the filtered view 146 void mouseHoveredOverMatch( qint64 line ); 147 148 private: 149 // State machine holding the state of the search, used to allow/disallow 150 // auto-refresh and inform the user via the info line. 151 class SearchState { 152 public: 153 enum State { 154 NoSearch, 155 Static, 156 Autorefreshing, 157 FileTruncated, 158 }; 159 160 SearchState() { state_ = NoSearch; autoRefreshRequested_ = false; } 161 162 // Reset the state (no search active) 163 void resetState(); 164 // The user changed auto-refresh request 165 void setAutorefresh( bool refresh ); 166 // The file has been truncated (stops auto-refresh) 167 void truncateFile(); 168 // The expression has been changed (stops auto-refresh) 169 void changeExpression(); 170 // The search has been stopped (stops auto-refresh) 171 void stopSearch(); 172 // The search has been started (enable auto-refresh) 173 void startSearch(); 174 175 // Get the state in order to display the proper message 176 State getState() const { return state_; } 177 // Is auto-refresh allowed 178 bool isAutorefreshAllowed() const 179 { return ( state_ == Autorefreshing ); } 180 181 private: 182 State state_; 183 bool autoRefreshRequested_; 184 }; 185 186 // Private functions 187 void setup(); 188 void replaceCurrentSearch( const QString& searchText ); 189 void updateSearchCombo(); 190 AbstractLogView* activeView() const; 191 void printSearchInfoMessage( int nbMatches = 0 ); 192 193 // Palette for error notification (yellow background) 194 static const QPalette errorPalette; 195 196 LogMainView* logMainView; 197 QWidget* bottomWindow; 198 QLabel* searchLabel; 199 QComboBox* searchLineEdit; 200 QToolButton* searchButton; 201 QToolButton* stopButton; 202 FilteredView* filteredView; 203 QComboBox* visibilityBox; 204 InfoLine* searchInfoLine; 205 QCheckBox* ignoreCaseCheck; 206 QCheckBox* searchRefreshCheck; 207 OverviewWidget* overviewWidget_; 208 209 QVBoxLayout* bottomMainLayout; 210 QHBoxLayout* searchLineLayout; 211 QHBoxLayout* searchInfoLineLayout; 212 213 // Default palette to be remembered 214 QPalette searchInfoLineDefaultPalette; 215 216 std::shared_ptr<SavedSearches> savedSearches_; 217 218 // Reference to the QuickFind Pattern (not owned) 219 std::shared_ptr<QuickFindPattern> quickFindPattern_; 220 221 LogData* logData_; 222 LogFilteredData* logFilteredData_; 223 224 qint64 logFileSize_; 225 226 QWidget* qfSavedFocus_; 227 228 // Search state (for auto-refresh and truncation) 229 SearchState searchState_; 230 231 // Matches overview 232 Overview* overview_; 233 234 // Model for the visibility selector 235 QStandardItemModel* visibilityModel_; 236 }; 237 238 #endif 239