1bb02e0acSNicolas Bonnefon /* 245ef183cSNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2013, 2014, 2015 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" 37f0708ca8SNicolas Bonnefon #include "viewinterface.h" 389cacd6a9SNicolas Bonnefon #include "signalmux.h" 390f9fd9edSNicolas Bonnefon #include "overview.h" 40812146a8SNicolas Bonnefon #include "loadingstatus.h" 41bb02e0acSNicolas Bonnefon 42bb02e0acSNicolas Bonnefon class InfoLine; 43bb02e0acSNicolas Bonnefon class QuickFindPattern; 44bb02e0acSNicolas Bonnefon class SavedSearches; 45bb02e0acSNicolas Bonnefon class QStandardItemModel; 46bb02e0acSNicolas Bonnefon class OverviewWidget; 47bb02e0acSNicolas Bonnefon 48bb02e0acSNicolas Bonnefon // Implements the central widget of the application. 49bb02e0acSNicolas Bonnefon // It includes both windows, the search line, the info 50bb02e0acSNicolas Bonnefon // lines and various buttons. 51f0708ca8SNicolas Bonnefon class CrawlerWidget : public QSplitter, 529cacd6a9SNicolas Bonnefon public QuickFindMuxSelectorInterface, public ViewInterface, 539cacd6a9SNicolas Bonnefon public MuxableDocumentInterface 54bb02e0acSNicolas Bonnefon { 55bb02e0acSNicolas Bonnefon Q_OBJECT 56bb02e0acSNicolas Bonnefon 57bb02e0acSNicolas Bonnefon public: 581b5e406eSNicolas Bonnefon CrawlerWidget( QWidget *parent=0 ); 59bb02e0acSNicolas Bonnefon 60bb02e0acSNicolas Bonnefon // Get the line number of the first line displayed. 61bb02e0acSNicolas Bonnefon int getTopLine() const; 62bb02e0acSNicolas Bonnefon // Get the selected text as a string (from the main window) 63bb02e0acSNicolas Bonnefon QString getSelectedText() const; 64bb02e0acSNicolas Bonnefon 65bb02e0acSNicolas Bonnefon // Display the QFB at the bottom, remembering where the focus was 66bb02e0acSNicolas Bonnefon void displayQuickFindBar( QuickFindMux::QFDirection direction ); 67bb02e0acSNicolas Bonnefon 68bb02e0acSNicolas Bonnefon // Instructs the widget to select all the text in the window the user 69bb02e0acSNicolas Bonnefon // is interacting with 70bb02e0acSNicolas Bonnefon void selectAll(); 71bb02e0acSNicolas Bonnefon 725fa25391SNicolas Bonnefon enum Encoding { 735fa25391SNicolas Bonnefon ENCODING_AUTO = 0, 745fa25391SNicolas Bonnefon ENCODING_ISO_8859_1, 755fa25391SNicolas Bonnefon ENCODING_UTF8, 765fa25391SNicolas Bonnefon ENCODING_MAX, 775fa25391SNicolas Bonnefon }; 785fa25391SNicolas Bonnefon 795fa25391SNicolas Bonnefon Encoding encodingSetting() const; 805fa25391SNicolas Bonnefon 8178dc0425SNicolas Bonnefon // Returns whether follow is enabled in this crawler 8278dc0425SNicolas Bonnefon bool isFollowEnabled() const; 8378dc0425SNicolas Bonnefon 845fa25391SNicolas Bonnefon // Get the text description of the encoding effectively used, 855fa25391SNicolas Bonnefon // suitable to display to the user. 865fa25391SNicolas Bonnefon QString encodingText() const; 875fa25391SNicolas Bonnefon 8832e44cfdSNicolas Bonnefon public slots: 897847299cSNicolas Bonnefon // Stop the asynchoronous loading of the file if one is in progress 907847299cSNicolas Bonnefon // The file is identified by the view attached to it. 917847299cSNicolas Bonnefon void stopLoading(); 9232e44cfdSNicolas Bonnefon // Reload the displayed file 9332e44cfdSNicolas Bonnefon void reload(); 945fa25391SNicolas Bonnefon // Set the encoding 955fa25391SNicolas Bonnefon void setEncoding( Encoding encoding ); 9632e44cfdSNicolas Bonnefon 97bb02e0acSNicolas Bonnefon protected: 98f0708ca8SNicolas Bonnefon // Implementation of the ViewInterface functions 99039481acSNicolas Bonnefon virtual void doSetData( 100039481acSNicolas Bonnefon std::shared_ptr<LogData> log_data, 101039481acSNicolas Bonnefon std::shared_ptr<LogFilteredData> filtered_data ); 102b423cd88SNicolas Bonnefon virtual void doSetQuickFindPattern( 103b423cd88SNicolas Bonnefon std::shared_ptr<QuickFindPattern> qfp ); 1041b5e406eSNicolas Bonnefon virtual void doSetSavedSearches( 1051b5e406eSNicolas Bonnefon std::shared_ptr<SavedSearches> saved_searches ); 106a44d09bcSNicolas Bonnefon virtual void doSetViewContext( const char* view_context ); 107a44d09bcSNicolas Bonnefon virtual std::shared_ptr<const ViewContextInterface> 108a44d09bcSNicolas Bonnefon doGetViewContext( void ) const; 109f0708ca8SNicolas Bonnefon 110b423cd88SNicolas Bonnefon // Implementation of the mux selector interface 111b423cd88SNicolas Bonnefon // (for dispatching QuickFind to the right widget) 112b423cd88SNicolas Bonnefon virtual SearchableWidgetInterface* doGetActiveSearchable() const; 113b423cd88SNicolas Bonnefon virtual std::vector<QObject*> doGetAllSearchables() const; 114b423cd88SNicolas Bonnefon 1159cacd6a9SNicolas Bonnefon // Implementation of the MuxableDocumentInterface 1169cacd6a9SNicolas Bonnefon virtual void doSendAllStateSignals(); 1179cacd6a9SNicolas Bonnefon 118*aa0a9454SNicolas Bonnefon virtual void keyPressEvent( QKeyEvent* keyEvent ); 119*aa0a9454SNicolas Bonnefon 120bb02e0acSNicolas Bonnefon signals: 121bb02e0acSNicolas Bonnefon // Sent to signal the client load has progressed, 122bb02e0acSNicolas Bonnefon // passing the completion percentage. 123bb02e0acSNicolas Bonnefon void loadingProgressed( int progress ); 124bb02e0acSNicolas Bonnefon // Sent to the client when the loading has finished 125bb02e0acSNicolas Bonnefon // weither succesfull or not. 126812146a8SNicolas Bonnefon void loadingFinished( LoadingStatus status ); 127bb02e0acSNicolas Bonnefon // Sent when follow mode is enabled/disabled 128bb02e0acSNicolas Bonnefon void followSet( bool checked ); 129b297d2f4SNicolas Bonnefon // Sent up to the MainWindow to enable/disable the follow mode 130b297d2f4SNicolas Bonnefon void followModeChanged( bool follow ); 131bb02e0acSNicolas Bonnefon // Sent up when the current line number is updated 132bb02e0acSNicolas Bonnefon void updateLineNumber( int line ); 133bb02e0acSNicolas Bonnefon 134f688be2eSNicolas Bonnefon // "auto-refresh" check has been changed 135f688be2eSNicolas Bonnefon void searchRefreshChanged( int state ); 136f688be2eSNicolas Bonnefon // "ignore case" check has been changed 137f688be2eSNicolas Bonnefon void ignoreCaseChanged( int state ); 138f688be2eSNicolas Bonnefon 13945ef183cSNicolas Bonnefon // Sent when the data status (whether new not seen data are 14045ef183cSNicolas Bonnefon // available) has changed 14145ef183cSNicolas Bonnefon void dataStatusChanged( DataStatus status ); 14245ef183cSNicolas Bonnefon 143bb02e0acSNicolas Bonnefon private slots: 144bb02e0acSNicolas Bonnefon // Instructs the widget to start a search using the current search line. 145bb02e0acSNicolas Bonnefon void startNewSearch(); 146bb02e0acSNicolas Bonnefon // Stop the currently ongoing search (if one exists) 147bb02e0acSNicolas Bonnefon void stopSearch(); 148bb02e0acSNicolas Bonnefon // Instructs the widget to reconfigure itself because Config() has changed. 149bb02e0acSNicolas Bonnefon void applyConfiguration(); 1508570d8d2SNicolas Bonnefon // QuickFind is being entered, save the focus for incremental qf. 1518570d8d2SNicolas Bonnefon void enteringQuickFind(); 1528570d8d2SNicolas Bonnefon // QuickFind is being closed. 1538570d8d2SNicolas Bonnefon void exitingQuickFind(); 154bb02e0acSNicolas Bonnefon // Called when new data must be displayed in the filtered window. 155bb02e0acSNicolas Bonnefon void updateFilteredView( int nbMatches, int progress ); 156bb02e0acSNicolas Bonnefon // Called when a new line has been selected in the filtered view, 157bb02e0acSNicolas Bonnefon // to instruct the main view to jump to the matching line. 158bb02e0acSNicolas Bonnefon void jumpToMatchingLine( int filteredLineNb ); 1599cacd6a9SNicolas Bonnefon // Called when the main view is on a new line number 1609cacd6a9SNicolas Bonnefon void updateLineNumberHandler( int line ); 161bb02e0acSNicolas Bonnefon // Mark a line that has been clicked on the main (top) view. 162bb02e0acSNicolas Bonnefon void markLineFromMain( qint64 line ); 163bb02e0acSNicolas Bonnefon // Mark a line that has been clicked on the filtered (bottom) view. 164bb02e0acSNicolas Bonnefon void markLineFromFiltered( qint64 line ); 165bb02e0acSNicolas Bonnefon 166812146a8SNicolas Bonnefon void loadingFinishedHandler( LoadingStatus status ); 167bb02e0acSNicolas Bonnefon // Manages the info lines to inform the user the file has changed. 168bb02e0acSNicolas Bonnefon void fileChangedHandler( LogData::MonitoredFileStatus ); 169bb02e0acSNicolas Bonnefon 170bb02e0acSNicolas Bonnefon void searchForward(); 171bb02e0acSNicolas Bonnefon void searchBackward(); 172bb02e0acSNicolas Bonnefon 173bb02e0acSNicolas Bonnefon // Called when the checkbox for search auto-refresh is changed 174bb02e0acSNicolas Bonnefon void searchRefreshChangedHandler( int state ); 175bb02e0acSNicolas Bonnefon 176bb02e0acSNicolas Bonnefon // Called when the text on the search line is modified 177bb02e0acSNicolas Bonnefon void searchTextChangeHandler(); 178bb02e0acSNicolas Bonnefon 179bb02e0acSNicolas Bonnefon // Called when the user change the visibility combobox 180bb02e0acSNicolas Bonnefon void changeFilteredViewVisibility( int index ); 181bb02e0acSNicolas Bonnefon 182bb02e0acSNicolas Bonnefon // Called when the user add the string to the search 183bb02e0acSNicolas Bonnefon void addToSearch( const QString& string ); 184bb02e0acSNicolas Bonnefon 185bb02e0acSNicolas Bonnefon // Called when a match is hovered on in the filtered view 186bb02e0acSNicolas Bonnefon void mouseHoveredOverMatch( qint64 line ); 187bb02e0acSNicolas Bonnefon 18845ef183cSNicolas Bonnefon // Called when there was activity in the views 18945ef183cSNicolas Bonnefon void activityDetected(); 19045ef183cSNicolas Bonnefon 191bb02e0acSNicolas Bonnefon private: 192bb02e0acSNicolas Bonnefon // State machine holding the state of the search, used to allow/disallow 193bb02e0acSNicolas Bonnefon // auto-refresh and inform the user via the info line. 194bb02e0acSNicolas Bonnefon class SearchState { 195bb02e0acSNicolas Bonnefon public: 196bb02e0acSNicolas Bonnefon enum State { 197bb02e0acSNicolas Bonnefon NoSearch, 198bb02e0acSNicolas Bonnefon Static, 199bb02e0acSNicolas Bonnefon Autorefreshing, 200bb02e0acSNicolas Bonnefon FileTruncated, 20159d4e393SNicolas Bonnefon TruncatedAutorefreshing, 202bb02e0acSNicolas Bonnefon }; 203bb02e0acSNicolas Bonnefon 204bb02e0acSNicolas Bonnefon SearchState() { state_ = NoSearch; autoRefreshRequested_ = false; } 205bb02e0acSNicolas Bonnefon 206bb02e0acSNicolas Bonnefon // Reset the state (no search active) 207bb02e0acSNicolas Bonnefon void resetState(); 208bb02e0acSNicolas Bonnefon // The user changed auto-refresh request 209bb02e0acSNicolas Bonnefon void setAutorefresh( bool refresh ); 210bb02e0acSNicolas Bonnefon // The file has been truncated (stops auto-refresh) 211bb02e0acSNicolas Bonnefon void truncateFile(); 212bb02e0acSNicolas Bonnefon // The expression has been changed (stops auto-refresh) 213bb02e0acSNicolas Bonnefon void changeExpression(); 214bb02e0acSNicolas Bonnefon // The search has been stopped (stops auto-refresh) 215bb02e0acSNicolas Bonnefon void stopSearch(); 216bb02e0acSNicolas Bonnefon // The search has been started (enable auto-refresh) 217bb02e0acSNicolas Bonnefon void startSearch(); 218bb02e0acSNicolas Bonnefon 219bb02e0acSNicolas Bonnefon // Get the state in order to display the proper message 220bb02e0acSNicolas Bonnefon State getState() const { return state_; } 221bb02e0acSNicolas Bonnefon // Is auto-refresh allowed 222bb02e0acSNicolas Bonnefon bool isAutorefreshAllowed() const 22359d4e393SNicolas Bonnefon { return ( state_ == Autorefreshing || state_ == TruncatedAutorefreshing ); } 22459d4e393SNicolas Bonnefon bool isFileTruncated() const 22559d4e393SNicolas Bonnefon { return ( state_ == FileTruncated || state_ == TruncatedAutorefreshing ); } 226bb02e0acSNicolas Bonnefon 227bb02e0acSNicolas Bonnefon private: 228bb02e0acSNicolas Bonnefon State state_; 229bb02e0acSNicolas Bonnefon bool autoRefreshRequested_; 230bb02e0acSNicolas Bonnefon }; 231bb02e0acSNicolas Bonnefon 232bb02e0acSNicolas Bonnefon // Private functions 233039481acSNicolas Bonnefon void setup(); 234bb02e0acSNicolas Bonnefon void replaceCurrentSearch( const QString& searchText ); 235bb02e0acSNicolas Bonnefon void updateSearchCombo(); 236bb02e0acSNicolas Bonnefon AbstractLogView* activeView() const; 237bb02e0acSNicolas Bonnefon void printSearchInfoMessage( int nbMatches = 0 ); 23845ef183cSNicolas Bonnefon void changeDataStatus( DataStatus status ); 2395fa25391SNicolas Bonnefon void updateEncoding(); 240*aa0a9454SNicolas Bonnefon void changeTopViewSize( int32_t delta ); 241bb02e0acSNicolas Bonnefon 242bb02e0acSNicolas Bonnefon // Palette for error notification (yellow background) 243bb02e0acSNicolas Bonnefon static const QPalette errorPalette; 244bb02e0acSNicolas Bonnefon 245bb02e0acSNicolas Bonnefon LogMainView* logMainView; 246bb02e0acSNicolas Bonnefon QWidget* bottomWindow; 247bb02e0acSNicolas Bonnefon QLabel* searchLabel; 248bb02e0acSNicolas Bonnefon QComboBox* searchLineEdit; 249bb02e0acSNicolas Bonnefon QToolButton* searchButton; 250bb02e0acSNicolas Bonnefon QToolButton* stopButton; 251bb02e0acSNicolas Bonnefon FilteredView* filteredView; 252bb02e0acSNicolas Bonnefon QComboBox* visibilityBox; 253bb02e0acSNicolas Bonnefon InfoLine* searchInfoLine; 254bb02e0acSNicolas Bonnefon QCheckBox* ignoreCaseCheck; 255bb02e0acSNicolas Bonnefon QCheckBox* searchRefreshCheck; 256bb02e0acSNicolas Bonnefon OverviewWidget* overviewWidget_; 257bb02e0acSNicolas Bonnefon 258bb02e0acSNicolas Bonnefon QVBoxLayout* bottomMainLayout; 259bb02e0acSNicolas Bonnefon QHBoxLayout* searchLineLayout; 260bb02e0acSNicolas Bonnefon QHBoxLayout* searchInfoLineLayout; 261bb02e0acSNicolas Bonnefon 262bb02e0acSNicolas Bonnefon // Default palette to be remembered 263bb02e0acSNicolas Bonnefon QPalette searchInfoLineDefaultPalette; 264bb02e0acSNicolas Bonnefon 2651b5e406eSNicolas Bonnefon std::shared_ptr<SavedSearches> savedSearches_; 266bb02e0acSNicolas Bonnefon 267b423cd88SNicolas Bonnefon // Reference to the QuickFind Pattern (not owned) 268b423cd88SNicolas Bonnefon std::shared_ptr<QuickFindPattern> quickFindPattern_; 269bb02e0acSNicolas Bonnefon 270bb02e0acSNicolas Bonnefon LogData* logData_; 271bb02e0acSNicolas Bonnefon LogFilteredData* logFilteredData_; 272bb02e0acSNicolas Bonnefon 273bb02e0acSNicolas Bonnefon qint64 logFileSize_; 274bb02e0acSNicolas Bonnefon 275bb02e0acSNicolas Bonnefon QWidget* qfSavedFocus_; 276bb02e0acSNicolas Bonnefon 277bb02e0acSNicolas Bonnefon // Search state (for auto-refresh and truncation) 278bb02e0acSNicolas Bonnefon SearchState searchState_; 279bb02e0acSNicolas Bonnefon 280bb02e0acSNicolas Bonnefon // Matches overview 2810f9fd9edSNicolas Bonnefon Overview overview_; 282bb02e0acSNicolas Bonnefon 283bb02e0acSNicolas Bonnefon // Model for the visibility selector 284bb02e0acSNicolas Bonnefon QStandardItemModel* visibilityModel_; 2859cacd6a9SNicolas Bonnefon 2869cacd6a9SNicolas Bonnefon // Last main line number received 2879cacd6a9SNicolas Bonnefon qint64 currentLineNumber_; 28860864ff5SNicolas Bonnefon 28960864ff5SNicolas Bonnefon // Are we loading something? 29060864ff5SNicolas Bonnefon // Set to false when we receive a completion message from the LogData 29160864ff5SNicolas Bonnefon bool loadingInProgress_; 29245ef183cSNicolas Bonnefon 29345ef183cSNicolas Bonnefon // Is it not the first time we are loading something? 29445ef183cSNicolas Bonnefon bool firstLoadDone_; 29545ef183cSNicolas Bonnefon 2967999f43eSNicolas Bonnefon // Current number of matches 2977999f43eSNicolas Bonnefon int nbMatches_; 2987999f43eSNicolas Bonnefon 29945ef183cSNicolas Bonnefon // the current dataStatus (whether we have new, not seen, data) 30045ef183cSNicolas Bonnefon DataStatus dataStatus_; 3015fa25391SNicolas Bonnefon 3025fa25391SNicolas Bonnefon // Current encoding setting; 3035fa25391SNicolas Bonnefon Encoding encodingSetting_ = ENCODING_AUTO; 3045fa25391SNicolas Bonnefon QString encoding_text_; 305bb02e0acSNicolas Bonnefon }; 306bb02e0acSNicolas Bonnefon 307bb02e0acSNicolas Bonnefon #endif 308