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