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 // Stop the asynchoronous loading of the file if one is in progress 78 // The file is identified by the view attached to it. 79 void stopLoading(); 80 // Reload the displayed file 81 void reload(); 82 83 protected: 84 void keyPressEvent( QKeyEvent* keyEvent ); 85 86 // Implementation of the ViewInterface functions 87 virtual void doSetData( 88 std::shared_ptr<LogData> log_data, 89 std::shared_ptr<LogFilteredData> filtered_data ); 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 // Called when new data must be displayed in the filtered window. 113 void updateFilteredView( int nbMatches, int progress ); 114 // Called when a new line has been selected in the filtered view, 115 // to instruct the main view to jump to the matching line. 116 void jumpToMatchingLine( int filteredLineNb ); 117 // Mark a line that has been clicked on the main (top) view. 118 void markLineFromMain( qint64 line ); 119 // Mark a line that has been clicked on the filtered (bottom) view. 120 void markLineFromFiltered( qint64 line ); 121 122 void loadingFinishedHandler( bool success ); 123 // Manages the info lines to inform the user the file has changed. 124 void fileChangedHandler( LogData::MonitoredFileStatus ); 125 126 void hideQuickFindBar(); 127 128 // Instructs the widget to change the pattern in the QuickFind widget 129 // and confirm it. 130 void changeQFPattern( const QString& newPattern ); 131 132 void searchForward(); 133 void searchBackward(); 134 135 // Called when the checkbox for search auto-refresh is changed 136 void searchRefreshChangedHandler( int state ); 137 138 // Called when the text on the search line is modified 139 void searchTextChangeHandler(); 140 141 // Called when the user change the visibility combobox 142 void changeFilteredViewVisibility( int index ); 143 144 // Called when the user add the string to the search 145 void addToSearch( const QString& string ); 146 147 // Called when a match is hovered on in the filtered view 148 void mouseHoveredOverMatch( qint64 line ); 149 150 private: 151 // State machine holding the state of the search, used to allow/disallow 152 // auto-refresh and inform the user via the info line. 153 class SearchState { 154 public: 155 enum State { 156 NoSearch, 157 Static, 158 Autorefreshing, 159 FileTruncated, 160 }; 161 162 SearchState() { state_ = NoSearch; autoRefreshRequested_ = false; } 163 164 // Reset the state (no search active) 165 void resetState(); 166 // The user changed auto-refresh request 167 void setAutorefresh( bool refresh ); 168 // The file has been truncated (stops auto-refresh) 169 void truncateFile(); 170 // The expression has been changed (stops auto-refresh) 171 void changeExpression(); 172 // The search has been stopped (stops auto-refresh) 173 void stopSearch(); 174 // The search has been started (enable auto-refresh) 175 void startSearch(); 176 177 // Get the state in order to display the proper message 178 State getState() const { return state_; } 179 // Is auto-refresh allowed 180 bool isAutorefreshAllowed() const 181 { return ( state_ == Autorefreshing ); } 182 183 private: 184 State state_; 185 bool autoRefreshRequested_; 186 }; 187 188 // Private functions 189 void setup(); 190 void replaceCurrentSearch( const QString& searchText ); 191 void updateSearchCombo(); 192 AbstractLogView* activeView() const; 193 void printSearchInfoMessage( int nbMatches = 0 ); 194 195 // Palette for error notification (yellow background) 196 static const QPalette errorPalette; 197 198 LogMainView* logMainView; 199 QWidget* bottomWindow; 200 QLabel* searchLabel; 201 QComboBox* searchLineEdit; 202 QToolButton* searchButton; 203 QToolButton* stopButton; 204 FilteredView* filteredView; 205 QComboBox* visibilityBox; 206 InfoLine* searchInfoLine; 207 QCheckBox* ignoreCaseCheck; 208 QCheckBox* searchRefreshCheck; 209 QuickFindWidget* quickFindWidget_; 210 OverviewWidget* overviewWidget_; 211 212 QVBoxLayout* bottomMainLayout; 213 QHBoxLayout* searchLineLayout; 214 QHBoxLayout* searchInfoLineLayout; 215 216 // Default palette to be remembered 217 QPalette searchInfoLineDefaultPalette; 218 219 SavedSearches* savedSearches; 220 221 QuickFindMux* quickFindMux_; 222 223 LogData* logData_; 224 LogFilteredData* logFilteredData_; 225 226 qint64 logFileSize_; 227 228 QWidget* qfSavedFocus_; 229 230 // Search state (for auto-refresh and truncation) 231 SearchState searchState_; 232 233 // Matches overview 234 Overview* overview_; 235 236 // Model for the visibility selector 237 QStandardItemModel* visibilityModel_; 238 }; 239 240 #endif 241