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 public slots: 77 // Reload the displayed file 78 void reload(); 79 80 protected: 81 void keyPressEvent( QKeyEvent* keyEvent ); 82 83 // Implementation of the ViewInterface functions 84 virtual void doSetData( 85 std::shared_ptr<LogData> log_data, 86 std::shared_ptr<LogFilteredData> filtered_data ); 87 88 signals: 89 // Sent to signal the client load has progressed, 90 // passing the completion percentage. 91 void loadingProgressed( int progress ); 92 // Sent to the client when the loading has finished 93 // weither succesfull or not. 94 void loadingFinished( bool success ); 95 // Sent when follow mode is enabled/disabled 96 void followSet( bool checked ); 97 // Sent up to the MainWindow to disable the follow mode 98 void followDisabled(); 99 // Sent up when the current line number is updated 100 void updateLineNumber( int line ); 101 102 private slots: 103 // Instructs the widget to start a search using the current search line. 104 void startNewSearch(); 105 // Stop the currently ongoing search (if one exists) 106 void stopSearch(); 107 // Instructs the widget to reconfigure itself because Config() has changed. 108 void applyConfiguration(); 109 // Called when new data must be displayed in the filtered window. 110 void updateFilteredView( int nbMatches, int progress ); 111 // Called when a new line has been selected in the filtered view, 112 // to instruct the main view to jump to the matching line. 113 void jumpToMatchingLine( int filteredLineNb ); 114 // Mark a line that has been clicked on the main (top) view. 115 void markLineFromMain( qint64 line ); 116 // Mark a line that has been clicked on the filtered (bottom) view. 117 void markLineFromFiltered( qint64 line ); 118 119 void loadingFinishedHandler( bool success ); 120 // Manages the info lines to inform the user the file has changed. 121 void fileChangedHandler( LogData::MonitoredFileStatus ); 122 123 void hideQuickFindBar(); 124 125 // Instructs the widget to change the pattern in the QuickFind widget 126 // and confirm it. 127 void changeQFPattern( const QString& newPattern ); 128 129 void searchForward(); 130 void searchBackward(); 131 132 // Called when the checkbox for search auto-refresh is changed 133 void searchRefreshChangedHandler( int state ); 134 135 // Called when the text on the search line is modified 136 void searchTextChangeHandler(); 137 138 // Called when the user change the visibility combobox 139 void changeFilteredViewVisibility( int index ); 140 141 // Called when the user add the string to the search 142 void addToSearch( const QString& string ); 143 144 // Called when a match is hovered on in the filtered view 145 void mouseHoveredOverMatch( qint64 line ); 146 147 private: 148 // State machine holding the state of the search, used to allow/disallow 149 // auto-refresh and inform the user via the info line. 150 class SearchState { 151 public: 152 enum State { 153 NoSearch, 154 Static, 155 Autorefreshing, 156 FileTruncated, 157 }; 158 159 SearchState() { state_ = NoSearch; autoRefreshRequested_ = false; } 160 161 // Reset the state (no search active) 162 void resetState(); 163 // The user changed auto-refresh request 164 void setAutorefresh( bool refresh ); 165 // The file has been truncated (stops auto-refresh) 166 void truncateFile(); 167 // The expression has been changed (stops auto-refresh) 168 void changeExpression(); 169 // The search has been stopped (stops auto-refresh) 170 void stopSearch(); 171 // The search has been started (enable auto-refresh) 172 void startSearch(); 173 174 // Get the state in order to display the proper message 175 State getState() const { return state_; } 176 // Is auto-refresh allowed 177 bool isAutorefreshAllowed() const 178 { return ( state_ == Autorefreshing ); } 179 180 private: 181 State state_; 182 bool autoRefreshRequested_; 183 }; 184 185 // Private functions 186 void setup(); 187 void replaceCurrentSearch( const QString& searchText ); 188 void updateSearchCombo(); 189 AbstractLogView* activeView() const; 190 void printSearchInfoMessage( int nbMatches = 0 ); 191 192 // Palette for error notification (yellow background) 193 static const QPalette errorPalette; 194 195 LogMainView* logMainView; 196 QWidget* bottomWindow; 197 QLabel* searchLabel; 198 QComboBox* searchLineEdit; 199 QToolButton* searchButton; 200 QToolButton* stopButton; 201 FilteredView* filteredView; 202 QComboBox* visibilityBox; 203 InfoLine* searchInfoLine; 204 QCheckBox* ignoreCaseCheck; 205 QCheckBox* searchRefreshCheck; 206 QuickFindWidget* quickFindWidget_; 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 SavedSearches* savedSearches; 217 218 QuickFindMux* quickFindMux_; 219 220 LogData* logData_; 221 LogFilteredData* logFilteredData_; 222 223 qint64 logFileSize_; 224 225 QWidget* qfSavedFocus_; 226 227 // Search state (for auto-refresh and truncation) 228 SearchState searchState_; 229 230 // Matches overview 231 Overview* overview_; 232 233 // Model for the visibility selector 234 QStandardItemModel* visibilityModel_; 235 }; 236 237 #endif 238