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 "quickfindwidget.h" 38 #include "quickfindmux.h" 39 #include "viewinterface.h" 40 41 class InfoLine; 42 class QuickFindPattern; 43 class QuickFindWidget; 44 class SavedSearches; 45 class Overview; 46 class QStandardItemModel; 47 class OverviewWidget; 48 49 // Implements the central widget of the application. 50 // It includes both windows, the search line, the info 51 // lines and various buttons. 52 class CrawlerWidget : public QSplitter, 53 public QuickFindMuxSelectorInterface, public ViewInterface 54 { 55 Q_OBJECT 56 57 public: 58 CrawlerWidget( SavedSearches* searches, QWidget *parent=0 ); 59 60 // Get the line number of the first line displayed. 61 int getTopLine() const; 62 // Get the selected text as a string (from the main window) 63 QString getSelectedText() const; 64 65 // Display the QFB at the bottom, remembering where the focus was 66 void displayQuickFindBar( QuickFindMux::QFDirection direction ); 67 68 // Instructs the widget to select all the text in the window the user 69 // is interacting with 70 void selectAll(); 71 72 // Implementation on the mux selector interface 73 // (for dispatching QuickFind to the right widget) 74 virtual SearchableWidgetInterface* getActiveSearchable() const; 75 76 protected: 77 void keyPressEvent( QKeyEvent* keyEvent ); 78 79 // Implementation of the ViewInterface functions 80 virtual void doSetData( 81 std::shared_ptr<LogData> log_data, 82 std::shared_ptr<LogFilteredData> filtered_data ); 83 84 signals: 85 // Sent to signal the client load has progressed, 86 // passing the completion percentage. 87 void loadingProgressed( int progress ); 88 // Sent to the client when the loading has finished 89 // weither succesfull or not. 90 void loadingFinished( bool success ); 91 // Sent when follow mode is enabled/disabled 92 void followSet( bool checked ); 93 // Sent up to the MainWindow to disable the follow mode 94 void followDisabled(); 95 // Sent up when the current line number is updated 96 void updateLineNumber( int line ); 97 98 private slots: 99 // Instructs the widget to start a search using the current search line. 100 void startNewSearch(); 101 // Stop the currently ongoing search (if one exists) 102 void stopSearch(); 103 // Instructs the widget to reconfigure itself because Config() has changed. 104 void applyConfiguration(); 105 // Called when new data must be displayed in the filtered window. 106 void updateFilteredView( int nbMatches, int progress ); 107 // Called when a new line has been selected in the filtered view, 108 // to instruct the main view to jump to the matching line. 109 void jumpToMatchingLine( int filteredLineNb ); 110 // Mark a line that has been clicked on the main (top) view. 111 void markLineFromMain( qint64 line ); 112 // Mark a line that has been clicked on the filtered (bottom) view. 113 void markLineFromFiltered( qint64 line ); 114 115 void loadingFinishedHandler( bool success ); 116 // Manages the info lines to inform the user the file has changed. 117 void fileChangedHandler( LogData::MonitoredFileStatus ); 118 119 void hideQuickFindBar(); 120 121 // Instructs the widget to change the pattern in the QuickFind widget 122 // and confirm it. 123 void changeQFPattern( const QString& newPattern ); 124 125 void searchForward(); 126 void searchBackward(); 127 128 // Called when the checkbox for search auto-refresh is changed 129 void searchRefreshChangedHandler( int state ); 130 131 // Called when the text on the search line is modified 132 void searchTextChangeHandler(); 133 134 // Called when the user change the visibility combobox 135 void changeFilteredViewVisibility( int index ); 136 137 // Called when the user add the string to the search 138 void addToSearch( const QString& string ); 139 140 // Called when a match is hovered on in the filtered view 141 void mouseHoveredOverMatch( qint64 line ); 142 143 private: 144 // State machine holding the state of the search, used to allow/disallow 145 // auto-refresh and inform the user via the info line. 146 class SearchState { 147 public: 148 enum State { 149 NoSearch, 150 Static, 151 Autorefreshing, 152 FileTruncated, 153 }; 154 155 SearchState() { state_ = NoSearch; autoRefreshRequested_ = false; } 156 157 // Reset the state (no search active) 158 void resetState(); 159 // The user changed auto-refresh request 160 void setAutorefresh( bool refresh ); 161 // The file has been truncated (stops auto-refresh) 162 void truncateFile(); 163 // The expression has been changed (stops auto-refresh) 164 void changeExpression(); 165 // The search has been stopped (stops auto-refresh) 166 void stopSearch(); 167 // The search has been started (enable auto-refresh) 168 void startSearch(); 169 170 // Get the state in order to display the proper message 171 State getState() const { return state_; } 172 // Is auto-refresh allowed 173 bool isAutorefreshAllowed() const 174 { return ( state_ == Autorefreshing ); } 175 176 private: 177 State state_; 178 bool autoRefreshRequested_; 179 }; 180 181 // Private functions 182 void setup(); 183 void replaceCurrentSearch( const QString& searchText ); 184 void updateSearchCombo(); 185 AbstractLogView* activeView() const; 186 void printSearchInfoMessage( int nbMatches = 0 ); 187 188 // Palette for error notification (yellow background) 189 static const QPalette errorPalette; 190 191 LogMainView* logMainView; 192 QWidget* bottomWindow; 193 QLabel* searchLabel; 194 QComboBox* searchLineEdit; 195 QToolButton* searchButton; 196 QToolButton* stopButton; 197 FilteredView* filteredView; 198 QComboBox* visibilityBox; 199 InfoLine* searchInfoLine; 200 QCheckBox* ignoreCaseCheck; 201 QCheckBox* searchRefreshCheck; 202 QuickFindWidget* quickFindWidget_; 203 OverviewWidget* overviewWidget_; 204 205 QVBoxLayout* bottomMainLayout; 206 QHBoxLayout* searchLineLayout; 207 QHBoxLayout* searchInfoLineLayout; 208 209 // Default palette to be remembered 210 QPalette searchInfoLineDefaultPalette; 211 212 SavedSearches* savedSearches; 213 214 QuickFindMux* quickFindMux_; 215 216 LogData* logData_; 217 LogFilteredData* logFilteredData_; 218 219 qint64 logFileSize_; 220 221 QWidget* qfSavedFocus_; 222 223 // Search state (for auto-refresh and truncation) 224 SearchState searchState_; 225 226 // Matches overview 227 Overview* overview_; 228 229 // Model for the visibility selector 230 QStandardItemModel* visibilityModel_; 231 }; 232 233 #endif 234