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