1bb02e0acSNicolas Bonnefon /* 245ef183cSNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicolas Bonnefon and other contributors 3bb02e0acSNicolas Bonnefon * 4bb02e0acSNicolas Bonnefon * This file is part of glogg. 5bb02e0acSNicolas Bonnefon * 6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9bb02e0acSNicolas Bonnefon * (at your option) any later version. 10bb02e0acSNicolas Bonnefon * 11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15bb02e0acSNicolas Bonnefon * 16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18bb02e0acSNicolas Bonnefon */ 19bb02e0acSNicolas Bonnefon 20bb02e0acSNicolas Bonnefon // This file implements the CrawlerWidget class. 21bb02e0acSNicolas Bonnefon // It is responsible for creating and managing the two views and all 22bb02e0acSNicolas Bonnefon // the UI elements. It implements the connection between the UI elements. 2332e44cfdSNicolas Bonnefon // It also interacts with the sets of data (full and filtered). 24bb02e0acSNicolas Bonnefon 25bb02e0acSNicolas Bonnefon #include "log.h" 26bb02e0acSNicolas Bonnefon 27039481acSNicolas Bonnefon #include <cassert> 28039481acSNicolas Bonnefon 29bb02e0acSNicolas Bonnefon #include <Qt> 30bb02e0acSNicolas Bonnefon #include <QApplication> 31bb02e0acSNicolas Bonnefon #include <QFile> 32bb02e0acSNicolas Bonnefon #include <QLineEdit> 33bb02e0acSNicolas Bonnefon #include <QFileInfo> 34bb02e0acSNicolas Bonnefon #include <QStandardItemModel> 35bb02e0acSNicolas Bonnefon #include <QHeaderView> 36bb02e0acSNicolas Bonnefon #include <QListView> 37bb02e0acSNicolas Bonnefon 38bb02e0acSNicolas Bonnefon #include "crawlerwidget.h" 39bb02e0acSNicolas Bonnefon 40bb02e0acSNicolas Bonnefon #include "quickfindpattern.h" 41bb02e0acSNicolas Bonnefon #include "overview.h" 42bb02e0acSNicolas Bonnefon #include "infoline.h" 43bb02e0acSNicolas Bonnefon #include "savedsearches.h" 44bb02e0acSNicolas Bonnefon #include "quickfindwidget.h" 45bb02e0acSNicolas Bonnefon #include "persistentinfo.h" 46bb02e0acSNicolas Bonnefon #include "configuration.h" 47bb02e0acSNicolas Bonnefon 48bb02e0acSNicolas Bonnefon // Palette for error signaling (yellow background) 49bb02e0acSNicolas Bonnefon const QPalette CrawlerWidget::errorPalette( QColor( "yellow" ) ); 50bb02e0acSNicolas Bonnefon 51a44d09bcSNicolas Bonnefon // Implementation of the view context for the CrawlerWidget 52a44d09bcSNicolas Bonnefon class CrawlerWidgetContext : public ViewContextInterface { 53a44d09bcSNicolas Bonnefon public: 54a44d09bcSNicolas Bonnefon // Construct from the stored string representation 55a44d09bcSNicolas Bonnefon CrawlerWidgetContext( const char* string ); 56a44d09bcSNicolas Bonnefon // Construct from the value passsed 57f688be2eSNicolas Bonnefon CrawlerWidgetContext( QList<int> sizes, 58f688be2eSNicolas Bonnefon bool ignore_case, 59f688be2eSNicolas Bonnefon bool auto_refresh ) 60f688be2eSNicolas Bonnefon : sizes_( sizes ), 61f688be2eSNicolas Bonnefon ignore_case_( ignore_case ), 62f688be2eSNicolas Bonnefon auto_refresh_( auto_refresh ) {} 63a44d09bcSNicolas Bonnefon 64a44d09bcSNicolas Bonnefon // Implementation of the ViewContextInterface function 65a44d09bcSNicolas Bonnefon std::string toString() const; 66a44d09bcSNicolas Bonnefon 67a44d09bcSNicolas Bonnefon // Access the Qt sizes array for the QSplitter 68a44d09bcSNicolas Bonnefon QList<int> sizes() const { return sizes_; } 69a44d09bcSNicolas Bonnefon 70f688be2eSNicolas Bonnefon bool ignoreCase() const { return ignore_case_; } 71f688be2eSNicolas Bonnefon bool autoRefresh() const { return auto_refresh_; } 72f688be2eSNicolas Bonnefon 73a44d09bcSNicolas Bonnefon private: 74a44d09bcSNicolas Bonnefon QList<int> sizes_; 75f688be2eSNicolas Bonnefon 76f688be2eSNicolas Bonnefon bool ignore_case_; 77f688be2eSNicolas Bonnefon bool auto_refresh_; 78a44d09bcSNicolas Bonnefon }; 79a44d09bcSNicolas Bonnefon 80039481acSNicolas Bonnefon // Constructor only does trivial construction. The real work is done once 81039481acSNicolas Bonnefon // the data is attached. 821b5e406eSNicolas Bonnefon CrawlerWidget::CrawlerWidget( QWidget *parent ) 830f9fd9edSNicolas Bonnefon : QSplitter( parent ), overview_() 84bb02e0acSNicolas Bonnefon { 85039481acSNicolas Bonnefon logData_ = nullptr; 86039481acSNicolas Bonnefon logFilteredData_ = nullptr; 87039481acSNicolas Bonnefon 88b423cd88SNicolas Bonnefon quickFindPattern_ = nullptr; 891b5e406eSNicolas Bonnefon savedSearches_ = nullptr; 908570d8d2SNicolas Bonnefon qfSavedFocus_ = nullptr; 919cacd6a9SNicolas Bonnefon 9260864ff5SNicolas Bonnefon // Until we have received confirmation loading is finished, we 9360864ff5SNicolas Bonnefon // should consider we are loading something. 9460864ff5SNicolas Bonnefon loadingInProgress_ = true; 9545ef183cSNicolas Bonnefon // and it's the first time 9645ef183cSNicolas Bonnefon firstLoadDone_ = false; 977999f43eSNicolas Bonnefon nbMatches_ = 0; 9845ef183cSNicolas Bonnefon dataStatus_ = DataStatus::OLD_DATA; 9960864ff5SNicolas Bonnefon 1009cacd6a9SNicolas Bonnefon currentLineNumber_ = 0; 101039481acSNicolas Bonnefon } 102039481acSNicolas Bonnefon 103039481acSNicolas Bonnefon // The top line is first one on the main display 104039481acSNicolas Bonnefon int CrawlerWidget::getTopLine() const 105039481acSNicolas Bonnefon { 106039481acSNicolas Bonnefon return logMainView->getTopLine(); 107039481acSNicolas Bonnefon } 108039481acSNicolas Bonnefon 109039481acSNicolas Bonnefon QString CrawlerWidget::getSelectedText() const 110039481acSNicolas Bonnefon { 111039481acSNicolas Bonnefon if ( filteredView->hasFocus() ) 112039481acSNicolas Bonnefon return filteredView->getSelection(); 113039481acSNicolas Bonnefon else 114039481acSNicolas Bonnefon return logMainView->getSelection(); 115039481acSNicolas Bonnefon } 116039481acSNicolas Bonnefon 117039481acSNicolas Bonnefon void CrawlerWidget::selectAll() 118039481acSNicolas Bonnefon { 119039481acSNicolas Bonnefon activeView()->selectAll(); 120039481acSNicolas Bonnefon } 121039481acSNicolas Bonnefon 122209000a6SNicolas Bonnefon Encoding CrawlerWidget::encodingSetting() const 1235fa25391SNicolas Bonnefon { 1245fa25391SNicolas Bonnefon return encodingSetting_; 1255fa25391SNicolas Bonnefon } 1265fa25391SNicolas Bonnefon 12778dc0425SNicolas Bonnefon bool CrawlerWidget::isFollowEnabled() const 12878dc0425SNicolas Bonnefon { 12978dc0425SNicolas Bonnefon return logMainView->isFollowEnabled(); 13078dc0425SNicolas Bonnefon } 13178dc0425SNicolas Bonnefon 1325fa25391SNicolas Bonnefon QString CrawlerWidget::encodingText() const 1335fa25391SNicolas Bonnefon { 1345fa25391SNicolas Bonnefon return encoding_text_; 1355fa25391SNicolas Bonnefon } 1365fa25391SNicolas Bonnefon 137039481acSNicolas Bonnefon // Return a pointer to the view in which we should do the QuickFind 138b423cd88SNicolas Bonnefon SearchableWidgetInterface* CrawlerWidget::doGetActiveSearchable() const 139039481acSNicolas Bonnefon { 140b423cd88SNicolas Bonnefon return activeView(); 141b423cd88SNicolas Bonnefon } 142039481acSNicolas Bonnefon 143b423cd88SNicolas Bonnefon // Return all the searchable widgets (views) 144b423cd88SNicolas Bonnefon std::vector<QObject*> CrawlerWidget::doGetAllSearchables() const 145b423cd88SNicolas Bonnefon { 146b423cd88SNicolas Bonnefon std::vector<QObject*> searchables = 147b423cd88SNicolas Bonnefon { logMainView, filteredView }; 148039481acSNicolas Bonnefon 149b423cd88SNicolas Bonnefon return searchables; 150039481acSNicolas Bonnefon } 151039481acSNicolas Bonnefon 1529cacd6a9SNicolas Bonnefon // Update the state of the parent 1539cacd6a9SNicolas Bonnefon void CrawlerWidget::doSendAllStateSignals() 1549cacd6a9SNicolas Bonnefon { 1559cacd6a9SNicolas Bonnefon emit updateLineNumber( currentLineNumber_ ); 15660864ff5SNicolas Bonnefon if ( !loadingInProgress_ ) 157812146a8SNicolas Bonnefon emit loadingFinished( LoadingStatus::Successful ); 1589cacd6a9SNicolas Bonnefon } 1599cacd6a9SNicolas Bonnefon 160aa0a9454SNicolas Bonnefon void CrawlerWidget::keyPressEvent( QKeyEvent* keyEvent ) 161aa0a9454SNicolas Bonnefon { 162aa0a9454SNicolas Bonnefon bool noModifier = keyEvent->modifiers() == Qt::NoModifier; 163aa0a9454SNicolas Bonnefon 164aa0a9454SNicolas Bonnefon if ( keyEvent->key() == Qt::Key_V && noModifier ) 165aa0a9454SNicolas Bonnefon visibilityBox->setCurrentIndex( 166aa0a9454SNicolas Bonnefon ( visibilityBox->currentIndex() + 1 ) % visibilityBox->count() ); 167aa0a9454SNicolas Bonnefon else { 168aa0a9454SNicolas Bonnefon const char character = (keyEvent->text())[0].toLatin1(); 169aa0a9454SNicolas Bonnefon 170aa0a9454SNicolas Bonnefon if ( character == '+' ) 171aa0a9454SNicolas Bonnefon changeTopViewSize( 1 ); 172aa0a9454SNicolas Bonnefon else if ( character == '-' ) 173aa0a9454SNicolas Bonnefon changeTopViewSize( -1 ); 174aa0a9454SNicolas Bonnefon else 175aa0a9454SNicolas Bonnefon QSplitter::keyPressEvent( keyEvent ); 176aa0a9454SNicolas Bonnefon } 177aa0a9454SNicolas Bonnefon } 178aa0a9454SNicolas Bonnefon 1797847299cSNicolas Bonnefon // 1807847299cSNicolas Bonnefon // Public slots 1817847299cSNicolas Bonnefon // 1827847299cSNicolas Bonnefon 1837847299cSNicolas Bonnefon void CrawlerWidget::stopLoading() 1847847299cSNicolas Bonnefon { 1857847299cSNicolas Bonnefon logFilteredData_->interruptSearch(); 1867847299cSNicolas Bonnefon logData_->interruptLoading(); 1877847299cSNicolas Bonnefon } 1887847299cSNicolas Bonnefon 18932e44cfdSNicolas Bonnefon void CrawlerWidget::reload() 19032e44cfdSNicolas Bonnefon { 19132e44cfdSNicolas Bonnefon searchState_.resetState(); 19232e44cfdSNicolas Bonnefon logFilteredData_->clearSearch(); 19332e44cfdSNicolas Bonnefon filteredView->updateData(); 19432e44cfdSNicolas Bonnefon printSearchInfoMessage(); 19532e44cfdSNicolas Bonnefon 19632e44cfdSNicolas Bonnefon logData_->reload(); 19745ef183cSNicolas Bonnefon 19845ef183cSNicolas Bonnefon // A reload is considered as a first load, 19945ef183cSNicolas Bonnefon // this is to prevent the "new data" icon to be triggered. 20045ef183cSNicolas Bonnefon firstLoadDone_ = false; 20132e44cfdSNicolas Bonnefon } 20232e44cfdSNicolas Bonnefon 2035fa25391SNicolas Bonnefon void CrawlerWidget::setEncoding( Encoding encoding ) 2045fa25391SNicolas Bonnefon { 2055fa25391SNicolas Bonnefon encodingSetting_ = encoding; 2065fa25391SNicolas Bonnefon updateEncoding(); 2075fa25391SNicolas Bonnefon 2085fa25391SNicolas Bonnefon update(); 2095fa25391SNicolas Bonnefon } 2105fa25391SNicolas Bonnefon 211039481acSNicolas Bonnefon // 212039481acSNicolas Bonnefon // Protected functions 213039481acSNicolas Bonnefon // 214039481acSNicolas Bonnefon void CrawlerWidget::doSetData( 215039481acSNicolas Bonnefon std::shared_ptr<LogData> log_data, 216039481acSNicolas Bonnefon std::shared_ptr<LogFilteredData> filtered_data ) 217039481acSNicolas Bonnefon { 218039481acSNicolas Bonnefon logData_ = log_data.get(); 219039481acSNicolas Bonnefon logFilteredData_ = filtered_data.get(); 2201b5e406eSNicolas Bonnefon } 221039481acSNicolas Bonnefon 222b423cd88SNicolas Bonnefon void CrawlerWidget::doSetQuickFindPattern( 223b423cd88SNicolas Bonnefon std::shared_ptr<QuickFindPattern> qfp ) 224b423cd88SNicolas Bonnefon { 225b423cd88SNicolas Bonnefon quickFindPattern_ = qfp; 226b423cd88SNicolas Bonnefon } 227b423cd88SNicolas Bonnefon 2281b5e406eSNicolas Bonnefon void CrawlerWidget::doSetSavedSearches( 2291b5e406eSNicolas Bonnefon std::shared_ptr<SavedSearches> saved_searches ) 2301b5e406eSNicolas Bonnefon { 2311b5e406eSNicolas Bonnefon savedSearches_ = saved_searches; 2321b5e406eSNicolas Bonnefon 2331b5e406eSNicolas Bonnefon // We do setup now, assuming doSetData has been called before 2341b5e406eSNicolas Bonnefon // us, that's not great really... 235039481acSNicolas Bonnefon setup(); 236039481acSNicolas Bonnefon } 237039481acSNicolas Bonnefon 238a44d09bcSNicolas Bonnefon void CrawlerWidget::doSetViewContext( 239a44d09bcSNicolas Bonnefon const char* view_context ) 240a44d09bcSNicolas Bonnefon { 241a44d09bcSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::doSetViewContext: " << view_context; 242a44d09bcSNicolas Bonnefon 243a44d09bcSNicolas Bonnefon CrawlerWidgetContext context = { view_context }; 244a44d09bcSNicolas Bonnefon 245a44d09bcSNicolas Bonnefon setSizes( context.sizes() ); 246f688be2eSNicolas Bonnefon ignoreCaseCheck->setCheckState( context.ignoreCase() ? Qt::Checked : Qt::Unchecked ); 247240a4b5eSNicolas Bonnefon 248240a4b5eSNicolas Bonnefon auto auto_refresh_check_state = context.autoRefresh() ? Qt::Checked : Qt::Unchecked; 249240a4b5eSNicolas Bonnefon searchRefreshCheck->setCheckState( auto_refresh_check_state ); 250240a4b5eSNicolas Bonnefon // Manually call the handler as it is not called when changing the state programmatically 251240a4b5eSNicolas Bonnefon searchRefreshChangedHandler( auto_refresh_check_state ); 252a44d09bcSNicolas Bonnefon } 253a44d09bcSNicolas Bonnefon 254a44d09bcSNicolas Bonnefon std::shared_ptr<const ViewContextInterface> 255a44d09bcSNicolas Bonnefon CrawlerWidget::doGetViewContext() const 256a44d09bcSNicolas Bonnefon { 257f688be2eSNicolas Bonnefon auto context = std::make_shared<const CrawlerWidgetContext>( 258f688be2eSNicolas Bonnefon sizes(), 259f688be2eSNicolas Bonnefon ( ignoreCaseCheck->checkState() == Qt::Checked ), 260f688be2eSNicolas Bonnefon ( searchRefreshCheck->checkState() == Qt::Checked ) ); 261a44d09bcSNicolas Bonnefon 262a44d09bcSNicolas Bonnefon return static_cast<std::shared_ptr<const ViewContextInterface>>( context ); 263a44d09bcSNicolas Bonnefon } 264a44d09bcSNicolas Bonnefon 265039481acSNicolas Bonnefon // 266039481acSNicolas Bonnefon // Slots 267039481acSNicolas Bonnefon // 268039481acSNicolas Bonnefon 269039481acSNicolas Bonnefon void CrawlerWidget::startNewSearch() 270039481acSNicolas Bonnefon { 271039481acSNicolas Bonnefon // Record the search line in the recent list 272039481acSNicolas Bonnefon // (reload the list first in case another glogg changed it) 273039481acSNicolas Bonnefon GetPersistentInfo().retrieve( "savedSearches" ); 2741b5e406eSNicolas Bonnefon savedSearches_->addRecent( searchLineEdit->currentText() ); 275039481acSNicolas Bonnefon GetPersistentInfo().save( "savedSearches" ); 276039481acSNicolas Bonnefon 277039481acSNicolas Bonnefon // Update the SearchLine (history) 278039481acSNicolas Bonnefon updateSearchCombo(); 279039481acSNicolas Bonnefon // Call the private function to do the search 280039481acSNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() ); 281039481acSNicolas Bonnefon } 282039481acSNicolas Bonnefon 283039481acSNicolas Bonnefon void CrawlerWidget::stopSearch() 284039481acSNicolas Bonnefon { 285039481acSNicolas Bonnefon logFilteredData_->interruptSearch(); 286039481acSNicolas Bonnefon searchState_.stopSearch(); 287039481acSNicolas Bonnefon printSearchInfoMessage(); 288039481acSNicolas Bonnefon } 289039481acSNicolas Bonnefon 290039481acSNicolas Bonnefon // When receiving the 'newDataAvailable' signal from LogFilteredData 291039481acSNicolas Bonnefon void CrawlerWidget::updateFilteredView( int nbMatches, int progress ) 292039481acSNicolas Bonnefon { 293039481acSNicolas Bonnefon LOG(logDEBUG) << "updateFilteredView received."; 294039481acSNicolas Bonnefon 295039481acSNicolas Bonnefon if ( progress == 100 ) { 296039481acSNicolas Bonnefon // Searching done 297039481acSNicolas Bonnefon printSearchInfoMessage( nbMatches ); 298039481acSNicolas Bonnefon searchInfoLine->hideGauge(); 299039481acSNicolas Bonnefon // De-activate the stop button 300039481acSNicolas Bonnefon stopButton->setEnabled( false ); 301039481acSNicolas Bonnefon } 302039481acSNicolas Bonnefon else { 303039481acSNicolas Bonnefon // Search in progress 304039481acSNicolas Bonnefon // We ignore 0% and 100% to avoid a flash when the search is very short 305039481acSNicolas Bonnefon if ( progress > 0 ) { 306039481acSNicolas Bonnefon searchInfoLine->setText( 307039481acSNicolas Bonnefon tr("Search in progress (%1 %)... %2 match%3 found so far.") 308039481acSNicolas Bonnefon .arg( progress ) 309039481acSNicolas Bonnefon .arg( nbMatches ) 310039481acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ) ); 311039481acSNicolas Bonnefon searchInfoLine->displayGauge( progress ); 312039481acSNicolas Bonnefon } 313039481acSNicolas Bonnefon } 314039481acSNicolas Bonnefon 3158ea5bc4cSNicolas Bonnefon // If more (or less, e.g. come back to 0) matches have been found 3168ea5bc4cSNicolas Bonnefon if ( nbMatches != nbMatches_ ) { 3177999f43eSNicolas Bonnefon nbMatches_ = nbMatches; 3187999f43eSNicolas Bonnefon 319039481acSNicolas Bonnefon // Recompute the content of the filtered window. 320039481acSNicolas Bonnefon filteredView->updateData(); 321039481acSNicolas Bonnefon 322039481acSNicolas Bonnefon // Update the match overview 3230f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 324039481acSNicolas Bonnefon 3257999f43eSNicolas Bonnefon // New data found icon 3267999f43eSNicolas Bonnefon changeDataStatus( DataStatus::NEW_FILTERED_DATA ); 3277999f43eSNicolas Bonnefon 328039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 329039481acSNicolas Bonnefon update(); 330039481acSNicolas Bonnefon } 331*3ff6c941SAnton Filimonov 332*3ff6c941SAnton Filimonov if ( progress == 100 ) { 333*3ff6c941SAnton Filimonov const int currenLineIndex = logFilteredData_->getLineIndexNumber(currentLineNumber_); 334*3ff6c941SAnton Filimonov LOG(logDEBUG) << "updateFilteredView: restoring selection: " 335*3ff6c941SAnton Filimonov << " absolute line number (0based) " << currentLineNumber_ 336*3ff6c941SAnton Filimonov << " index " << currenLineIndex; 337*3ff6c941SAnton Filimonov filteredView->selectAndDisplayLine(currenLineIndex); 338*3ff6c941SAnton Filimonov } 3397999f43eSNicolas Bonnefon } 340039481acSNicolas Bonnefon 341039481acSNicolas Bonnefon void CrawlerWidget::jumpToMatchingLine(int filteredLineNb) 342039481acSNicolas Bonnefon { 343039481acSNicolas Bonnefon int mainViewLine = logFilteredData_->getMatchingLineNumber(filteredLineNb); 344039481acSNicolas Bonnefon logMainView->selectAndDisplayLine(mainViewLine); // FIXME: should be done with a signal. 345039481acSNicolas Bonnefon } 346039481acSNicolas Bonnefon 3479cacd6a9SNicolas Bonnefon void CrawlerWidget::updateLineNumberHandler( int line ) 3489cacd6a9SNicolas Bonnefon { 3499cacd6a9SNicolas Bonnefon currentLineNumber_ = line; 3509cacd6a9SNicolas Bonnefon emit updateLineNumber( line ); 3519cacd6a9SNicolas Bonnefon } 3529cacd6a9SNicolas Bonnefon 353039481acSNicolas Bonnefon void CrawlerWidget::markLineFromMain( qint64 line ) 354039481acSNicolas Bonnefon { 3552493b508SNicolas Bonnefon if ( line < logData_->getNbLine() ) { 356039481acSNicolas Bonnefon if ( logFilteredData_->isLineMarked( line ) ) 357039481acSNicolas Bonnefon logFilteredData_->deleteMark( line ); 358039481acSNicolas Bonnefon else 359039481acSNicolas Bonnefon logFilteredData_->addMark( line ); 360039481acSNicolas Bonnefon 3617552c461SNicolas Bonnefon // Recompute the content of both window. 362039481acSNicolas Bonnefon filteredView->updateData(); 3637552c461SNicolas Bonnefon logMainView->updateData(); 364039481acSNicolas Bonnefon 365039481acSNicolas Bonnefon // Update the match overview 3660f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 367039481acSNicolas Bonnefon 368039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 369039481acSNicolas Bonnefon update(); 370039481acSNicolas Bonnefon } 3712493b508SNicolas Bonnefon } 372039481acSNicolas Bonnefon 373039481acSNicolas Bonnefon void CrawlerWidget::markLineFromFiltered( qint64 line ) 374039481acSNicolas Bonnefon { 3752493b508SNicolas Bonnefon if ( line < logFilteredData_->getNbLine() ) { 376039481acSNicolas Bonnefon qint64 line_in_file = logFilteredData_->getMatchingLineNumber( line ); 377039481acSNicolas Bonnefon if ( logFilteredData_->filteredLineTypeByIndex( line ) 378039481acSNicolas Bonnefon == LogFilteredData::Mark ) 379039481acSNicolas Bonnefon logFilteredData_->deleteMark( line_in_file ); 380039481acSNicolas Bonnefon else 381039481acSNicolas Bonnefon logFilteredData_->addMark( line_in_file ); 382039481acSNicolas Bonnefon 3837552c461SNicolas Bonnefon // Recompute the content of both window. 384039481acSNicolas Bonnefon filteredView->updateData(); 3857552c461SNicolas Bonnefon logMainView->updateData(); 386039481acSNicolas Bonnefon 387039481acSNicolas Bonnefon // Update the match overview 3880f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 389039481acSNicolas Bonnefon 390039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 391039481acSNicolas Bonnefon update(); 392039481acSNicolas Bonnefon } 3932493b508SNicolas Bonnefon } 394039481acSNicolas Bonnefon 395039481acSNicolas Bonnefon void CrawlerWidget::applyConfiguration() 396039481acSNicolas Bonnefon { 39711582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 39811582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 39911582726SNicolas Bonnefon QFont font = config->mainFont(); 400039481acSNicolas Bonnefon 401039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::applyConfiguration"; 402039481acSNicolas Bonnefon 403039481acSNicolas Bonnefon // Whatever font we use, we should NOT use kerning 404039481acSNicolas Bonnefon font.setKerning( false ); 405039481acSNicolas Bonnefon font.setFixedPitch( true ); 406039481acSNicolas Bonnefon #if QT_VERSION > 0x040700 407039481acSNicolas Bonnefon // Necessary on systems doing subpixel positionning (e.g. Ubuntu 12.04) 408039481acSNicolas Bonnefon font.setStyleStrategy( QFont::ForceIntegerMetrics ); 409039481acSNicolas Bonnefon #endif 410039481acSNicolas Bonnefon logMainView->setFont(font); 411039481acSNicolas Bonnefon filteredView->setFont(font); 412039481acSNicolas Bonnefon 41311582726SNicolas Bonnefon logMainView->setLineNumbersVisible( config->mainLineNumbersVisible() ); 41411582726SNicolas Bonnefon filteredView->setLineNumbersVisible( config->filteredLineNumbersVisible() ); 415039481acSNicolas Bonnefon 41611582726SNicolas Bonnefon overview_.setVisible( config->isOverviewVisible() ); 417039481acSNicolas Bonnefon logMainView->refreshOverview(); 418039481acSNicolas Bonnefon 419039481acSNicolas Bonnefon logMainView->updateDisplaySize(); 420039481acSNicolas Bonnefon logMainView->update(); 421039481acSNicolas Bonnefon filteredView->updateDisplaySize(); 422039481acSNicolas Bonnefon filteredView->update(); 423039481acSNicolas Bonnefon 42480bca0a3SNicolas Bonnefon // Polling interval 42580bca0a3SNicolas Bonnefon logData_->setPollingInterval( 42680bca0a3SNicolas Bonnefon config->pollingEnabled() ? config->pollIntervalMs() : 0 ); 42780bca0a3SNicolas Bonnefon 428039481acSNicolas Bonnefon // Update the SearchLine (history) 429039481acSNicolas Bonnefon updateSearchCombo(); 430039481acSNicolas Bonnefon } 431039481acSNicolas Bonnefon 4328570d8d2SNicolas Bonnefon void CrawlerWidget::enteringQuickFind() 4338570d8d2SNicolas Bonnefon { 4348570d8d2SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::enteringQuickFind"; 4358570d8d2SNicolas Bonnefon 4368570d8d2SNicolas Bonnefon // Remember who had the focus (only if it is one of our views) 4378570d8d2SNicolas Bonnefon QWidget* focus_widget = QApplication::focusWidget(); 4388570d8d2SNicolas Bonnefon 4398570d8d2SNicolas Bonnefon if ( ( focus_widget == logMainView ) || ( focus_widget == filteredView ) ) 4408570d8d2SNicolas Bonnefon qfSavedFocus_ = focus_widget; 4418570d8d2SNicolas Bonnefon else 4428570d8d2SNicolas Bonnefon qfSavedFocus_ = nullptr; 4438570d8d2SNicolas Bonnefon } 4448570d8d2SNicolas Bonnefon 4458570d8d2SNicolas Bonnefon void CrawlerWidget::exitingQuickFind() 4468570d8d2SNicolas Bonnefon { 4478570d8d2SNicolas Bonnefon // Restore the focus once the QFBar has been hidden 4488570d8d2SNicolas Bonnefon if ( qfSavedFocus_ ) 4498570d8d2SNicolas Bonnefon qfSavedFocus_->setFocus(); 4508570d8d2SNicolas Bonnefon } 4518570d8d2SNicolas Bonnefon 452812146a8SNicolas Bonnefon void CrawlerWidget::loadingFinishedHandler( LoadingStatus status ) 453039481acSNicolas Bonnefon { 45460864ff5SNicolas Bonnefon loadingInProgress_ = false; 45560864ff5SNicolas Bonnefon 456039481acSNicolas Bonnefon // We need to refresh the main window because the view lines on the 457039481acSNicolas Bonnefon // overview have probably changed. 4580f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 459039481acSNicolas Bonnefon 460039481acSNicolas Bonnefon // FIXME, handle topLine 461039481acSNicolas Bonnefon // logMainView->updateData( logData_, topLine ); 462039481acSNicolas Bonnefon logMainView->updateData(); 463039481acSNicolas Bonnefon 464039481acSNicolas Bonnefon // Shall we Forbid starting a search when loading in progress? 465039481acSNicolas Bonnefon // searchButton->setEnabled( false ); 466039481acSNicolas Bonnefon 467039481acSNicolas Bonnefon // searchButton->setEnabled( true ); 468039481acSNicolas Bonnefon 469039481acSNicolas Bonnefon // See if we need to auto-refresh the search 470039481acSNicolas Bonnefon if ( searchState_.isAutorefreshAllowed() ) { 47159d4e393SNicolas Bonnefon if ( searchState_.isFileTruncated() ) 47259d4e393SNicolas Bonnefon // We need to restart the search 47359d4e393SNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() ); 47459d4e393SNicolas Bonnefon else 475039481acSNicolas Bonnefon logFilteredData_->updateSearch(); 476039481acSNicolas Bonnefon } 477039481acSNicolas Bonnefon 4785fa25391SNicolas Bonnefon // Set the encoding for the views 4795fa25391SNicolas Bonnefon updateEncoding(); 4805fa25391SNicolas Bonnefon 481812146a8SNicolas Bonnefon emit loadingFinished( status ); 48245ef183cSNicolas Bonnefon 48345ef183cSNicolas Bonnefon // Also change the data available icon 48445ef183cSNicolas Bonnefon if ( firstLoadDone_ ) 48545ef183cSNicolas Bonnefon changeDataStatus( DataStatus::NEW_DATA ); 48645ef183cSNicolas Bonnefon else 48745ef183cSNicolas Bonnefon firstLoadDone_ = true; 488039481acSNicolas Bonnefon } 489039481acSNicolas Bonnefon 490039481acSNicolas Bonnefon void CrawlerWidget::fileChangedHandler( LogData::MonitoredFileStatus status ) 491039481acSNicolas Bonnefon { 492039481acSNicolas Bonnefon // Handle the case where the file has been truncated 493039481acSNicolas Bonnefon if ( status == LogData::Truncated ) { 494039481acSNicolas Bonnefon // Clear all marks (TODO offer the option to keep them) 495039481acSNicolas Bonnefon logFilteredData_->clearMarks(); 496039481acSNicolas Bonnefon if ( ! searchInfoLine->text().isEmpty() ) { 497039481acSNicolas Bonnefon // Invalidate the search 498039481acSNicolas Bonnefon logFilteredData_->clearSearch(); 499039481acSNicolas Bonnefon filteredView->updateData(); 500039481acSNicolas Bonnefon searchState_.truncateFile(); 501039481acSNicolas Bonnefon printSearchInfoMessage(); 5027999f43eSNicolas Bonnefon nbMatches_ = 0; 503039481acSNicolas Bonnefon } 504039481acSNicolas Bonnefon } 505039481acSNicolas Bonnefon } 506039481acSNicolas Bonnefon 507039481acSNicolas Bonnefon // Returns a pointer to the window in which the search should be done 508039481acSNicolas Bonnefon AbstractLogView* CrawlerWidget::activeView() const 509039481acSNicolas Bonnefon { 510039481acSNicolas Bonnefon QWidget* activeView; 511039481acSNicolas Bonnefon 512039481acSNicolas Bonnefon // Search in the window that has focus, or the window where 'Find' was 513039481acSNicolas Bonnefon // called from, or the main window. 514039481acSNicolas Bonnefon if ( filteredView->hasFocus() || logMainView->hasFocus() ) 515039481acSNicolas Bonnefon activeView = QApplication::focusWidget(); 516039481acSNicolas Bonnefon else 5178570d8d2SNicolas Bonnefon activeView = qfSavedFocus_; 518039481acSNicolas Bonnefon 519b423cd88SNicolas Bonnefon if ( activeView ) { 520b423cd88SNicolas Bonnefon AbstractLogView* view = qobject_cast<AbstractLogView*>( activeView ); 521039481acSNicolas Bonnefon return view; 522b423cd88SNicolas Bonnefon } 523b423cd88SNicolas Bonnefon else { 524b423cd88SNicolas Bonnefon LOG(logWARNING) << "No active view, defaulting to logMainView"; 525039481acSNicolas Bonnefon return logMainView; 526039481acSNicolas Bonnefon } 527b423cd88SNicolas Bonnefon } 528039481acSNicolas Bonnefon 529039481acSNicolas Bonnefon void CrawlerWidget::searchForward() 530039481acSNicolas Bonnefon { 531039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchForward"; 532039481acSNicolas Bonnefon 533039481acSNicolas Bonnefon activeView()->searchForward(); 534039481acSNicolas Bonnefon } 535039481acSNicolas Bonnefon 536039481acSNicolas Bonnefon void CrawlerWidget::searchBackward() 537039481acSNicolas Bonnefon { 538039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchBackward"; 539039481acSNicolas Bonnefon 540039481acSNicolas Bonnefon activeView()->searchBackward(); 541039481acSNicolas Bonnefon } 542039481acSNicolas Bonnefon 543039481acSNicolas Bonnefon void CrawlerWidget::searchRefreshChangedHandler( int state ) 544039481acSNicolas Bonnefon { 545039481acSNicolas Bonnefon searchState_.setAutorefresh( state == Qt::Checked ); 546039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 547039481acSNicolas Bonnefon } 548039481acSNicolas Bonnefon 549039481acSNicolas Bonnefon void CrawlerWidget::searchTextChangeHandler() 550039481acSNicolas Bonnefon { 551039481acSNicolas Bonnefon // We suspend auto-refresh 552039481acSNicolas Bonnefon searchState_.changeExpression(); 553039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 554039481acSNicolas Bonnefon } 555039481acSNicolas Bonnefon 556039481acSNicolas Bonnefon void CrawlerWidget::changeFilteredViewVisibility( int index ) 557039481acSNicolas Bonnefon { 558039481acSNicolas Bonnefon QStandardItem* item = visibilityModel_->item( index ); 559039481acSNicolas Bonnefon FilteredView::Visibility visibility = 560039481acSNicolas Bonnefon static_cast< FilteredView::Visibility>( item->data().toInt() ); 561039481acSNicolas Bonnefon 562039481acSNicolas Bonnefon filteredView->setVisibility( visibility ); 563*3ff6c941SAnton Filimonov 564*3ff6c941SAnton Filimonov const int lineIndex = logFilteredData_->getLineIndexNumber( currentLineNumber_ ); 565*3ff6c941SAnton Filimonov filteredView->selectAndDisplayLine( lineIndex ); 566039481acSNicolas Bonnefon } 567039481acSNicolas Bonnefon 568039481acSNicolas Bonnefon void CrawlerWidget::addToSearch( const QString& string ) 569039481acSNicolas Bonnefon { 570039481acSNicolas Bonnefon QString text = searchLineEdit->currentText(); 571039481acSNicolas Bonnefon 572039481acSNicolas Bonnefon if ( text.isEmpty() ) 573039481acSNicolas Bonnefon text = string; 574039481acSNicolas Bonnefon else { 575039481acSNicolas Bonnefon // Escape the regexp chars from the string before adding it. 5764fb0346eSAnton Filimonov text += ( '|' + QRegularExpression::escape( string ) ); 577039481acSNicolas Bonnefon } 578039481acSNicolas Bonnefon 579039481acSNicolas Bonnefon searchLineEdit->setEditText( text ); 580039481acSNicolas Bonnefon 581039481acSNicolas Bonnefon // Set the focus to lineEdit so that the user can press 'Return' immediately 582039481acSNicolas Bonnefon searchLineEdit->lineEdit()->setFocus(); 583039481acSNicolas Bonnefon } 584039481acSNicolas Bonnefon 585039481acSNicolas Bonnefon void CrawlerWidget::mouseHoveredOverMatch( qint64 line ) 586039481acSNicolas Bonnefon { 587039481acSNicolas Bonnefon qint64 line_in_mainview = logFilteredData_->getMatchingLineNumber( line ); 588039481acSNicolas Bonnefon 589039481acSNicolas Bonnefon overviewWidget_->highlightLine( line_in_mainview ); 590039481acSNicolas Bonnefon } 591039481acSNicolas Bonnefon 59245ef183cSNicolas Bonnefon void CrawlerWidget::activityDetected() 59345ef183cSNicolas Bonnefon { 59445ef183cSNicolas Bonnefon changeDataStatus( DataStatus::OLD_DATA ); 59545ef183cSNicolas Bonnefon } 59645ef183cSNicolas Bonnefon 597039481acSNicolas Bonnefon // 598039481acSNicolas Bonnefon // Private functions 599039481acSNicolas Bonnefon // 600039481acSNicolas Bonnefon 601039481acSNicolas Bonnefon // Build the widget and connect all the signals, this must be done once 602039481acSNicolas Bonnefon // the data are attached. 603039481acSNicolas Bonnefon void CrawlerWidget::setup() 604039481acSNicolas Bonnefon { 605bb02e0acSNicolas Bonnefon setOrientation(Qt::Vertical); 606bb02e0acSNicolas Bonnefon 607039481acSNicolas Bonnefon assert( logData_ ); 608039481acSNicolas Bonnefon assert( logFilteredData_ ); 609bb02e0acSNicolas Bonnefon 610bb02e0acSNicolas Bonnefon // The views 611bb02e0acSNicolas Bonnefon bottomWindow = new QWidget; 612bb02e0acSNicolas Bonnefon overviewWidget_ = new OverviewWidget(); 613bb02e0acSNicolas Bonnefon logMainView = new LogMainView( 6140f9fd9edSNicolas Bonnefon logData_, quickFindPattern_.get(), &overview_, overviewWidget_ ); 615bb02e0acSNicolas Bonnefon filteredView = new FilteredView( 616b423cd88SNicolas Bonnefon logFilteredData_, quickFindPattern_.get() ); 617bb02e0acSNicolas Bonnefon 6180f9fd9edSNicolas Bonnefon overviewWidget_->setOverview( &overview_ ); 619bb02e0acSNicolas Bonnefon overviewWidget_->setParent( logMainView ); 620bb02e0acSNicolas Bonnefon 62158ab9c53SNicolas Bonnefon // Connect the search to the top view 62258ab9c53SNicolas Bonnefon logMainView->useNewFiltering( logFilteredData_ ); 62358ab9c53SNicolas Bonnefon 624bb02e0acSNicolas Bonnefon // Construct the visibility button 625bb02e0acSNicolas Bonnefon visibilityModel_ = new QStandardItemModel( this ); 626bb02e0acSNicolas Bonnefon 627bb02e0acSNicolas Bonnefon QStandardItem *marksAndMatchesItem = new QStandardItem( tr( "Marks and matches" ) ); 628bb02e0acSNicolas Bonnefon QPixmap marksAndMatchesPixmap( 16, 10 ); 629bb02e0acSNicolas Bonnefon marksAndMatchesPixmap.fill( Qt::gray ); 630bb02e0acSNicolas Bonnefon marksAndMatchesItem->setIcon( QIcon( marksAndMatchesPixmap ) ); 631bb02e0acSNicolas Bonnefon marksAndMatchesItem->setData( FilteredView::MarksAndMatches ); 632bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksAndMatchesItem ); 633bb02e0acSNicolas Bonnefon 634bb02e0acSNicolas Bonnefon QStandardItem *marksItem = new QStandardItem( tr( "Marks" ) ); 635bb02e0acSNicolas Bonnefon QPixmap marksPixmap( 16, 10 ); 636bb02e0acSNicolas Bonnefon marksPixmap.fill( Qt::blue ); 637bb02e0acSNicolas Bonnefon marksItem->setIcon( QIcon( marksPixmap ) ); 638bb02e0acSNicolas Bonnefon marksItem->setData( FilteredView::MarksOnly ); 639bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksItem ); 640bb02e0acSNicolas Bonnefon 641bb02e0acSNicolas Bonnefon QStandardItem *matchesItem = new QStandardItem( tr( "Matches" ) ); 642bb02e0acSNicolas Bonnefon QPixmap matchesPixmap( 16, 10 ); 643bb02e0acSNicolas Bonnefon matchesPixmap.fill( Qt::red ); 644bb02e0acSNicolas Bonnefon matchesItem->setIcon( QIcon( matchesPixmap ) ); 645bb02e0acSNicolas Bonnefon matchesItem->setData( FilteredView::MatchesOnly ); 646bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( matchesItem ); 647bb02e0acSNicolas Bonnefon 648bb02e0acSNicolas Bonnefon QListView *visibilityView = new QListView( this ); 649bb02e0acSNicolas Bonnefon visibilityView->setMovement( QListView::Static ); 650bb02e0acSNicolas Bonnefon visibilityView->setMinimumWidth( 170 ); // Only needed with custom style-sheet 651bb02e0acSNicolas Bonnefon 652bb02e0acSNicolas Bonnefon visibilityBox = new QComboBox(); 653bb02e0acSNicolas Bonnefon visibilityBox->setModel( visibilityModel_ ); 654bb02e0acSNicolas Bonnefon visibilityBox->setView( visibilityView ); 655bb02e0acSNicolas Bonnefon 656bb02e0acSNicolas Bonnefon // Select "Marks and matches" by default (same default as the filtered view) 657bb02e0acSNicolas Bonnefon visibilityBox->setCurrentIndex( 0 ); 658bb02e0acSNicolas Bonnefon 659bb02e0acSNicolas Bonnefon // TODO: Maybe there is some way to set the popup width to be 660bb02e0acSNicolas Bonnefon // sized-to-content (as it is when the stylesheet is not overriden) in the 661bb02e0acSNicolas Bonnefon // stylesheet as opposed to setting a hard min-width on the view above. 662bb02e0acSNicolas Bonnefon visibilityBox->setStyleSheet( " \ 663bb02e0acSNicolas Bonnefon QComboBox:on {\ 664bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 6px;\ 665bb02e0acSNicolas Bonnefon width: 19px;\ 666bb02e0acSNicolas Bonnefon } \ 667bb02e0acSNicolas Bonnefon QComboBox:!on {\ 668bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 7px;\ 669bb02e0acSNicolas Bonnefon width: 19px;\ 670bb02e0acSNicolas Bonnefon height: 16px;\ 671bb02e0acSNicolas Bonnefon border: 1px solid gray;\ 672bb02e0acSNicolas Bonnefon } \ 673bb02e0acSNicolas Bonnefon QComboBox::drop-down::down-arrow {\ 674bb02e0acSNicolas Bonnefon width: 0px;\ 675bb02e0acSNicolas Bonnefon border-width: 0px;\ 676bb02e0acSNicolas Bonnefon } \ 677bb02e0acSNicolas Bonnefon " ); 678bb02e0acSNicolas Bonnefon 679bb02e0acSNicolas Bonnefon // Construct the Search Info line 680bb02e0acSNicolas Bonnefon searchInfoLine = new InfoLine(); 681bb02e0acSNicolas Bonnefon searchInfoLine->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 682bb02e0acSNicolas Bonnefon searchInfoLine->setLineWidth( 1 ); 683bb02e0acSNicolas Bonnefon searchInfoLineDefaultPalette = searchInfoLine->palette(); 684bb02e0acSNicolas Bonnefon 685bb02e0acSNicolas Bonnefon ignoreCaseCheck = new QCheckBox( "Ignore &case" ); 686bb02e0acSNicolas Bonnefon searchRefreshCheck = new QCheckBox( "Auto-&refresh" ); 687bb02e0acSNicolas Bonnefon 688bb02e0acSNicolas Bonnefon // Construct the Search line 689bb02e0acSNicolas Bonnefon searchLabel = new QLabel(tr("&Text: ")); 690bb02e0acSNicolas Bonnefon searchLineEdit = new QComboBox; 691bb02e0acSNicolas Bonnefon searchLineEdit->setEditable( true ); 692bb02e0acSNicolas Bonnefon searchLineEdit->setCompleter( 0 ); 6931b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() ); 694bb02e0acSNicolas Bonnefon searchLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); 695bb02e0acSNicolas Bonnefon searchLineEdit->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon ); 696bb02e0acSNicolas Bonnefon 697bb02e0acSNicolas Bonnefon searchLabel->setBuddy( searchLineEdit ); 698bb02e0acSNicolas Bonnefon 699bb02e0acSNicolas Bonnefon searchButton = new QToolButton(); 700bb02e0acSNicolas Bonnefon searchButton->setText( tr("&Search") ); 701bb02e0acSNicolas Bonnefon searchButton->setAutoRaise( true ); 702bb02e0acSNicolas Bonnefon 703bb02e0acSNicolas Bonnefon stopButton = new QToolButton(); 70428c802baSNicolas Bonnefon stopButton->setIcon( QIcon(":/images/stop14.png") ); 705bb02e0acSNicolas Bonnefon stopButton->setAutoRaise( true ); 706bb02e0acSNicolas Bonnefon stopButton->setEnabled( false ); 707bb02e0acSNicolas Bonnefon 708bb02e0acSNicolas Bonnefon QHBoxLayout* searchLineLayout = new QHBoxLayout; 709bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLabel); 710bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLineEdit); 711bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchButton); 712bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(stopButton); 713bb02e0acSNicolas Bonnefon searchLineLayout->setContentsMargins(6, 0, 6, 0); 714bb02e0acSNicolas Bonnefon stopButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 715bb02e0acSNicolas Bonnefon searchButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 716bb02e0acSNicolas Bonnefon 717bb02e0acSNicolas Bonnefon QHBoxLayout* searchInfoLineLayout = new QHBoxLayout; 718bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( visibilityBox ); 719bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchInfoLine ); 720bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( ignoreCaseCheck ); 721bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchRefreshCheck ); 722bb02e0acSNicolas Bonnefon 723bb02e0acSNicolas Bonnefon // Construct the bottom window 724bb02e0acSNicolas Bonnefon QVBoxLayout* bottomMainLayout = new QVBoxLayout; 725bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchLineLayout); 726bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchInfoLineLayout); 727bb02e0acSNicolas Bonnefon bottomMainLayout->addWidget(filteredView); 728bb02e0acSNicolas Bonnefon bottomMainLayout->setContentsMargins(2, 1, 2, 1); 729bb02e0acSNicolas Bonnefon bottomWindow->setLayout(bottomMainLayout); 730bb02e0acSNicolas Bonnefon 731bb02e0acSNicolas Bonnefon addWidget( logMainView ); 732bb02e0acSNicolas Bonnefon addWidget( bottomWindow ); 733bb02e0acSNicolas Bonnefon 734bb02e0acSNicolas Bonnefon // Default splitter position (usually overridden by the config file) 735bb02e0acSNicolas Bonnefon QList<int> splitterSizes; 736bb02e0acSNicolas Bonnefon splitterSizes += 400; 737bb02e0acSNicolas Bonnefon splitterSizes += 100; 738bb02e0acSNicolas Bonnefon setSizes( splitterSizes ); 739bb02e0acSNicolas Bonnefon 740f688be2eSNicolas Bonnefon // Default search checkboxes 741f688be2eSNicolas Bonnefon auto config = Persistent<Configuration>( "settings" ); 742f688be2eSNicolas Bonnefon searchRefreshCheck->setCheckState( config->isSearchAutoRefreshDefault() ? 743f688be2eSNicolas Bonnefon Qt::Checked : Qt::Unchecked ); 744c580560cSNicolas Bonnefon // Manually call the handler as it is not called when changing the state programmatically 745c580560cSNicolas Bonnefon searchRefreshChangedHandler( searchRefreshCheck->checkState() ); 746f688be2eSNicolas Bonnefon ignoreCaseCheck->setCheckState( config->isSearchIgnoreCaseDefault() ? 747f688be2eSNicolas Bonnefon Qt::Checked : Qt::Unchecked ); 748f688be2eSNicolas Bonnefon 749bb02e0acSNicolas Bonnefon // Connect the signals 750bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( returnPressed() ), 751bb02e0acSNicolas Bonnefon searchButton, SIGNAL( clicked() )); 752bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( textEdited( const QString& ) ), 753bb02e0acSNicolas Bonnefon this, SLOT( searchTextChangeHandler() )); 754bb02e0acSNicolas Bonnefon connect(searchButton, SIGNAL( clicked() ), 755bb02e0acSNicolas Bonnefon this, SLOT( startNewSearch() ) ); 756bb02e0acSNicolas Bonnefon connect(stopButton, SIGNAL( clicked() ), 757bb02e0acSNicolas Bonnefon this, SLOT( stopSearch() ) ); 758bb02e0acSNicolas Bonnefon 759bb02e0acSNicolas Bonnefon connect(visibilityBox, SIGNAL( currentIndexChanged( int ) ), 760bb02e0acSNicolas Bonnefon this, SLOT( changeFilteredViewVisibility( int ) ) ); 761bb02e0acSNicolas Bonnefon 762bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( newSelection( int ) ), 763bb02e0acSNicolas Bonnefon logMainView, SLOT( update() ) ); 764bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 765bb02e0acSNicolas Bonnefon this, SLOT( jumpToMatchingLine( int ) ) ); 766bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 767bb02e0acSNicolas Bonnefon filteredView, SLOT( update() ) ); 768bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( updateLineNumber( int ) ), 7699cacd6a9SNicolas Bonnefon this, SLOT( updateLineNumberHandler( int ) ) ); 770bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( markLine( qint64 ) ), 771bb02e0acSNicolas Bonnefon this, SLOT( markLineFromMain( qint64 ) ) ); 772bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( markLine( qint64 ) ), 773bb02e0acSNicolas Bonnefon this, SLOT( markLineFromFiltered( qint64 ) ) ); 774bb02e0acSNicolas Bonnefon 775bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( addToSearch( const QString& ) ), 776bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 777bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( addToSearch( const QString& ) ), 778bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 779bb02e0acSNicolas Bonnefon 780bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseHoveredOverLine( qint64 ) ), 781bb02e0acSNicolas Bonnefon this, SLOT( mouseHoveredOverMatch( qint64 ) ) ); 782bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseLeftHoveringZone() ), 783bb02e0acSNicolas Bonnefon overviewWidget_, SLOT( removeHighlight() ) ); 784bb02e0acSNicolas Bonnefon 785bb02e0acSNicolas Bonnefon // Follow option (up and down) 786bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 787bb02e0acSNicolas Bonnefon logMainView, SLOT( followSet( bool ) ) ); 788bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 789bb02e0acSNicolas Bonnefon filteredView, SLOT( followSet( bool ) ) ); 790b297d2f4SNicolas Bonnefon connect(logMainView, SIGNAL( followModeChanged( bool ) ), 791b297d2f4SNicolas Bonnefon this, SIGNAL( followModeChanged( bool ) ) ); 792b297d2f4SNicolas Bonnefon connect(filteredView, SIGNAL( followModeChanged( bool ) ), 793b297d2f4SNicolas Bonnefon this, SIGNAL( followModeChanged( bool ) ) ); 794bb02e0acSNicolas Bonnefon 79545ef183cSNicolas Bonnefon // Detect activity in the views 79645ef183cSNicolas Bonnefon connect(logMainView, SIGNAL( activity() ), 79745ef183cSNicolas Bonnefon this, SLOT( activityDetected() ) ); 79845ef183cSNicolas Bonnefon connect(filteredView, SIGNAL( activity() ), 79945ef183cSNicolas Bonnefon this, SLOT( activityDetected() ) ); 80045ef183cSNicolas Bonnefon 801bb02e0acSNicolas Bonnefon connect( logFilteredData_, SIGNAL( searchProgressed( int, int ) ), 802bb02e0acSNicolas Bonnefon this, SLOT( updateFilteredView( int, int ) ) ); 803bb02e0acSNicolas Bonnefon 804bb02e0acSNicolas Bonnefon // Sent load file update to MainWindow (for status update) 805bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( loadingProgressed( int ) ), 806bb02e0acSNicolas Bonnefon this, SIGNAL( loadingProgressed( int ) ) ); 807812146a8SNicolas Bonnefon connect( logData_, SIGNAL( loadingFinished( LoadingStatus ) ), 808812146a8SNicolas Bonnefon this, SLOT( loadingFinishedHandler( LoadingStatus ) ) ); 809bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( fileChanged( LogData::MonitoredFileStatus ) ), 810bb02e0acSNicolas Bonnefon this, SLOT( fileChangedHandler( LogData::MonitoredFileStatus ) ) ); 811bb02e0acSNicolas Bonnefon 812bb02e0acSNicolas Bonnefon // Search auto-refresh 813bb02e0acSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ), 814bb02e0acSNicolas Bonnefon this, SLOT( searchRefreshChangedHandler( int ) ) ); 815f688be2eSNicolas Bonnefon 816f688be2eSNicolas Bonnefon // Advise the parent the checkboxes have been changed 817f688be2eSNicolas Bonnefon // (for maintaining default config) 818f688be2eSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ), 819f688be2eSNicolas Bonnefon this, SIGNAL( searchRefreshChanged( int ) ) ); 820f688be2eSNicolas Bonnefon connect( ignoreCaseCheck, SIGNAL( stateChanged( int ) ), 821f688be2eSNicolas Bonnefon this, SIGNAL( ignoreCaseChanged( int ) ) ); 8227552c461SNicolas Bonnefon 8237552c461SNicolas Bonnefon // Switch between views 8247552c461SNicolas Bonnefon connect( logMainView, SIGNAL( exitView() ), 8257552c461SNicolas Bonnefon filteredView, SLOT( setFocus() ) ); 8267552c461SNicolas Bonnefon connect( filteredView, SIGNAL( exitView() ), 8277552c461SNicolas Bonnefon logMainView, SLOT( setFocus() ) ); 828bb02e0acSNicolas Bonnefon } 829bb02e0acSNicolas Bonnefon 830bb02e0acSNicolas Bonnefon // Create a new search using the text passed, replace the currently 831bb02e0acSNicolas Bonnefon // used one and destroy the old one. 832bb02e0acSNicolas Bonnefon void CrawlerWidget::replaceCurrentSearch( const QString& searchText ) 833bb02e0acSNicolas Bonnefon { 834bb02e0acSNicolas Bonnefon // Interrupt the search if it's ongoing 835bb02e0acSNicolas Bonnefon logFilteredData_->interruptSearch(); 836bb02e0acSNicolas Bonnefon 837bb02e0acSNicolas Bonnefon // We have to wait for the last search update (100%) 838bb02e0acSNicolas Bonnefon // before clearing/restarting to avoid having remaining results. 839bb02e0acSNicolas Bonnefon 840bb02e0acSNicolas Bonnefon // FIXME: this is a bit of a hack, we call processEvents 841bb02e0acSNicolas Bonnefon // for Qt to empty its event queue, including (hopefully) 842bb02e0acSNicolas Bonnefon // the search update event sent by logFilteredData_. It saves 843bb02e0acSNicolas Bonnefon // us the overhead of having proper sync. 844bb02e0acSNicolas Bonnefon QApplication::processEvents( QEventLoop::ExcludeUserInputEvents ); 845bb02e0acSNicolas Bonnefon 8468ea5bc4cSNicolas Bonnefon nbMatches_ = 0; 8478ea5bc4cSNicolas Bonnefon 8488ea5bc4cSNicolas Bonnefon // Clear and recompute the content of the filtered window. 8498ea5bc4cSNicolas Bonnefon logFilteredData_->clearSearch(); 8508ea5bc4cSNicolas Bonnefon filteredView->updateData(); 8518ea5bc4cSNicolas Bonnefon 8528ea5bc4cSNicolas Bonnefon // Update the match overview 8538ea5bc4cSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 8548ea5bc4cSNicolas Bonnefon 855bb02e0acSNicolas Bonnefon if ( !searchText.isEmpty() ) { 8564fb0346eSAnton Filimonov 8574fb0346eSAnton Filimonov QString pattern; 8584fb0346eSAnton Filimonov 859bb02e0acSNicolas Bonnefon // Determine the type of regexp depending on the config 86011582726SNicolas Bonnefon static std::shared_ptr<Configuration> config = 86111582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 86211582726SNicolas Bonnefon switch ( config->mainRegexpType() ) { 863bb02e0acSNicolas Bonnefon case FixedString: 8644fb0346eSAnton Filimonov pattern = QRegularExpression::escape(searchText); 865bb02e0acSNicolas Bonnefon break; 866bb02e0acSNicolas Bonnefon default: 8674fb0346eSAnton Filimonov pattern = searchText; 868bb02e0acSNicolas Bonnefon break; 869bb02e0acSNicolas Bonnefon } 870bb02e0acSNicolas Bonnefon 871bb02e0acSNicolas Bonnefon // Set the pattern case insensitive if needed 8724fb0346eSAnton Filimonov QRegularExpression::PatternOptions patternOptions = 8734fb0346eSAnton Filimonov QRegularExpression::UseUnicodePropertiesOption 8744fb0346eSAnton Filimonov | QRegularExpression::OptimizeOnFirstUsageOption; 8754fb0346eSAnton Filimonov 876bb02e0acSNicolas Bonnefon if ( ignoreCaseCheck->checkState() == Qt::Checked ) 8774fb0346eSAnton Filimonov patternOptions |= QRegularExpression::CaseInsensitiveOption; 878bb02e0acSNicolas Bonnefon 879bb02e0acSNicolas Bonnefon // Constructs the regexp 8804fb0346eSAnton Filimonov QRegularExpression regexp( pattern, patternOptions ); 881bb02e0acSNicolas Bonnefon 882bb02e0acSNicolas Bonnefon if ( regexp.isValid() ) { 883bb02e0acSNicolas Bonnefon // Activate the stop button 884bb02e0acSNicolas Bonnefon stopButton->setEnabled( true ); 885bb02e0acSNicolas Bonnefon // Start a new asynchronous search 886bb02e0acSNicolas Bonnefon logFilteredData_->runSearch( regexp ); 887bb02e0acSNicolas Bonnefon // Accept auto-refresh of the search 888bb02e0acSNicolas Bonnefon searchState_.startSearch(); 889bb02e0acSNicolas Bonnefon } 890bb02e0acSNicolas Bonnefon else { 891bb02e0acSNicolas Bonnefon // The regexp is wrong 892bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 893bb02e0acSNicolas Bonnefon filteredView->updateData(); 894bb02e0acSNicolas Bonnefon searchState_.resetState(); 895bb02e0acSNicolas Bonnefon 896bb02e0acSNicolas Bonnefon // Inform the user 8974fb0346eSAnton Filimonov QString errorMessage = tr("Error in expression"); 8984fb0346eSAnton Filimonov const int offset = regexp.patternErrorOffset(); 8994fb0346eSAnton Filimonov if (offset != -1) { 9004fb0346eSAnton Filimonov errorMessage += " at position "; 9014fb0346eSAnton Filimonov errorMessage += QString::number(offset); 9024fb0346eSAnton Filimonov } 9034fb0346eSAnton Filimonov errorMessage += ": "; 904bb02e0acSNicolas Bonnefon errorMessage += regexp.errorString(); 905bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( errorPalette ); 906bb02e0acSNicolas Bonnefon searchInfoLine->setText( errorMessage ); 907bb02e0acSNicolas Bonnefon } 908bb02e0acSNicolas Bonnefon } 909bb02e0acSNicolas Bonnefon else { 910bb02e0acSNicolas Bonnefon searchState_.resetState(); 911bb02e0acSNicolas Bonnefon printSearchInfoMessage(); 912bb02e0acSNicolas Bonnefon } 913bb02e0acSNicolas Bonnefon } 914bb02e0acSNicolas Bonnefon 915bb02e0acSNicolas Bonnefon // Updates the content of the drop down list for the saved searches, 916bb02e0acSNicolas Bonnefon // called when the SavedSearch has been changed. 917bb02e0acSNicolas Bonnefon void CrawlerWidget::updateSearchCombo() 918bb02e0acSNicolas Bonnefon { 919bb02e0acSNicolas Bonnefon const QString text = searchLineEdit->lineEdit()->text(); 920bb02e0acSNicolas Bonnefon searchLineEdit->clear(); 9211b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() ); 922bb02e0acSNicolas Bonnefon // In case we had something that wasn't added to the list (blank...): 923bb02e0acSNicolas Bonnefon searchLineEdit->lineEdit()->setText( text ); 924bb02e0acSNicolas Bonnefon } 925bb02e0acSNicolas Bonnefon 926bb02e0acSNicolas Bonnefon // Print the search info message. 927bb02e0acSNicolas Bonnefon void CrawlerWidget::printSearchInfoMessage( int nbMatches ) 928bb02e0acSNicolas Bonnefon { 929bb02e0acSNicolas Bonnefon QString text; 930bb02e0acSNicolas Bonnefon 931bb02e0acSNicolas Bonnefon switch ( searchState_.getState() ) { 932bb02e0acSNicolas Bonnefon case SearchState::NoSearch: 933bb02e0acSNicolas Bonnefon // Blank text is fine 934bb02e0acSNicolas Bonnefon break; 935bb02e0acSNicolas Bonnefon case SearchState::Static: 936bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found.").arg( nbMatches ) 937bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 938bb02e0acSNicolas Bonnefon break; 939bb02e0acSNicolas Bonnefon case SearchState::Autorefreshing: 940bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found. Search is auto-refreshing...").arg( nbMatches ) 941bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 942bb02e0acSNicolas Bonnefon break; 943bb02e0acSNicolas Bonnefon case SearchState::FileTruncated: 94459d4e393SNicolas Bonnefon case SearchState::TruncatedAutorefreshing: 945bb02e0acSNicolas Bonnefon text = tr("File truncated on disk, previous search results are not valid anymore."); 946bb02e0acSNicolas Bonnefon break; 947bb02e0acSNicolas Bonnefon } 948bb02e0acSNicolas Bonnefon 949bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( searchInfoLineDefaultPalette ); 950bb02e0acSNicolas Bonnefon searchInfoLine->setText( text ); 951bb02e0acSNicolas Bonnefon } 952bb02e0acSNicolas Bonnefon 95345ef183cSNicolas Bonnefon // Change the data status and, if needed, advise upstream. 95445ef183cSNicolas Bonnefon void CrawlerWidget::changeDataStatus( DataStatus status ) 95545ef183cSNicolas Bonnefon { 9567999f43eSNicolas Bonnefon if ( ( status != dataStatus_ ) 9577999f43eSNicolas Bonnefon && (! ( dataStatus_ == DataStatus::NEW_FILTERED_DATA 9587999f43eSNicolas Bonnefon && status == DataStatus::NEW_DATA ) ) ) { 95945ef183cSNicolas Bonnefon dataStatus_ = status; 96045ef183cSNicolas Bonnefon emit dataStatusChanged( dataStatus_ ); 96145ef183cSNicolas Bonnefon } 96245ef183cSNicolas Bonnefon } 96345ef183cSNicolas Bonnefon 9645fa25391SNicolas Bonnefon // Determine the right encoding and set the views. 9655fa25391SNicolas Bonnefon void CrawlerWidget::updateEncoding() 9665fa25391SNicolas Bonnefon { 967209000a6SNicolas Bonnefon Encoding encoding = Encoding::ENCODING_MAX; 9685fa25391SNicolas Bonnefon 9695fa25391SNicolas Bonnefon switch ( encodingSetting_ ) { 970209000a6SNicolas Bonnefon case Encoding::ENCODING_AUTO: 9715fa25391SNicolas Bonnefon switch ( logData_->getDetectedEncoding() ) { 9725fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::ASCII7: 973209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_ISO_8859_1; 9745fa25391SNicolas Bonnefon encoding_text_ = tr( "US-ASCII" ); 9755fa25391SNicolas Bonnefon break; 9765fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::ASCII8: 977209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_ISO_8859_1; 9785fa25391SNicolas Bonnefon encoding_text_ = tr( "ISO-8859-1" ); 9795fa25391SNicolas Bonnefon break; 9805fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::UTF8: 981209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_UTF8; 9825fa25391SNicolas Bonnefon encoding_text_ = tr( "UTF-8" ); 9835fa25391SNicolas Bonnefon break; 9840faa4758SNicolas Bonnefon case EncodingSpeculator::Encoding::UTF16LE: 985209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_UTF16LE; 9860faa4758SNicolas Bonnefon encoding_text_ = tr( "UTF-16LE" ); 9870faa4758SNicolas Bonnefon break; 9880faa4758SNicolas Bonnefon case EncodingSpeculator::Encoding::UTF16BE: 989209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_UTF16BE; 9900faa4758SNicolas Bonnefon encoding_text_ = tr( "UTF-16BE" ); 9910faa4758SNicolas Bonnefon break; 9925fa25391SNicolas Bonnefon } 9935fa25391SNicolas Bonnefon break; 994209000a6SNicolas Bonnefon case Encoding::ENCODING_UTF8: 995209000a6SNicolas Bonnefon encoding = encodingSetting_; 9965fa25391SNicolas Bonnefon encoding_text_ = tr( "Displayed as UTF-8" ); 9975fa25391SNicolas Bonnefon break; 998209000a6SNicolas Bonnefon case Encoding::ENCODING_UTF16LE: 999209000a6SNicolas Bonnefon encoding = encodingSetting_; 10004a4a124eSNicolas Bonnefon encoding_text_ = tr( "Displayed as UTF-16LE" ); 10014a4a124eSNicolas Bonnefon break; 1002209000a6SNicolas Bonnefon case Encoding::ENCODING_UTF16BE: 1003209000a6SNicolas Bonnefon encoding = encodingSetting_; 10044a4a124eSNicolas Bonnefon encoding_text_ = tr( "Displayed as UTF-16BE" ); 10054a4a124eSNicolas Bonnefon break; 1006209000a6SNicolas Bonnefon case Encoding::ENCODING_CP1251: 1007209000a6SNicolas Bonnefon encoding = encodingSetting_; 1008f25e35f2SNicolas Bonnefon encoding_text_ = tr( "Displayed as CP1251" ); 1009f25e35f2SNicolas Bonnefon break; 1010209000a6SNicolas Bonnefon case Encoding::ENCODING_CP1252: 1011209000a6SNicolas Bonnefon encoding = encodingSetting_; 1012f25e35f2SNicolas Bonnefon encoding_text_ = tr( "Displayed as CP1252" ); 1013f25e35f2SNicolas Bonnefon break; 1014209000a6SNicolas Bonnefon case Encoding::ENCODING_ISO_8859_1: 10155fa25391SNicolas Bonnefon default: 1016209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_ISO_8859_1; 10175fa25391SNicolas Bonnefon encoding_text_ = tr( "Displayed as ISO-8859-1" ); 10185fa25391SNicolas Bonnefon break; 10195fa25391SNicolas Bonnefon } 10205fa25391SNicolas Bonnefon 10215fa25391SNicolas Bonnefon logData_->setDisplayEncoding( encoding ); 10225fa25391SNicolas Bonnefon logMainView->forceRefresh(); 10235fa25391SNicolas Bonnefon logFilteredData_->setDisplayEncoding( encoding ); 10245fa25391SNicolas Bonnefon filteredView->forceRefresh(); 10255fa25391SNicolas Bonnefon } 10265fa25391SNicolas Bonnefon 1027aa0a9454SNicolas Bonnefon // Change the respective size of the two views 1028aa0a9454SNicolas Bonnefon void CrawlerWidget::changeTopViewSize( int32_t delta ) 1029aa0a9454SNicolas Bonnefon { 1030aa0a9454SNicolas Bonnefon int min, max; 1031aa0a9454SNicolas Bonnefon getRange( 1, &min, &max ); 1032aa0a9454SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::changeTopViewSize " << sizes()[0] << " " << min << " " << max; 1033aa0a9454SNicolas Bonnefon moveSplitter( closestLegalPosition( sizes()[0] + ( delta * 10 ), 1 ), 1 ); 1034aa0a9454SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::changeTopViewSize " << sizes()[0]; 1035aa0a9454SNicolas Bonnefon } 1036aa0a9454SNicolas Bonnefon 1037bb02e0acSNicolas Bonnefon // 1038bb02e0acSNicolas Bonnefon // SearchState implementation 1039bb02e0acSNicolas Bonnefon // 1040bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::resetState() 1041bb02e0acSNicolas Bonnefon { 1042bb02e0acSNicolas Bonnefon state_ = NoSearch; 1043bb02e0acSNicolas Bonnefon } 1044bb02e0acSNicolas Bonnefon 1045bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::setAutorefresh( bool refresh ) 1046bb02e0acSNicolas Bonnefon { 1047bb02e0acSNicolas Bonnefon autoRefreshRequested_ = refresh; 1048bb02e0acSNicolas Bonnefon 1049bb02e0acSNicolas Bonnefon if ( refresh ) { 1050bb02e0acSNicolas Bonnefon if ( state_ == Static ) 1051bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 105259d4e393SNicolas Bonnefon /* 105359d4e393SNicolas Bonnefon else if ( state_ == FileTruncated ) 105459d4e393SNicolas Bonnefon state_ = TruncatedAutorefreshing; 105559d4e393SNicolas Bonnefon */ 1056bb02e0acSNicolas Bonnefon } 1057bb02e0acSNicolas Bonnefon else { 1058bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 1059bb02e0acSNicolas Bonnefon state_ = Static; 106059d4e393SNicolas Bonnefon else if ( state_ == TruncatedAutorefreshing ) 106159d4e393SNicolas Bonnefon state_ = FileTruncated; 1062bb02e0acSNicolas Bonnefon } 1063bb02e0acSNicolas Bonnefon } 1064bb02e0acSNicolas Bonnefon 1065bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::truncateFile() 1066bb02e0acSNicolas Bonnefon { 106759d4e393SNicolas Bonnefon if ( state_ == Autorefreshing || state_ == TruncatedAutorefreshing ) { 106859d4e393SNicolas Bonnefon state_ = TruncatedAutorefreshing; 106959d4e393SNicolas Bonnefon } 107059d4e393SNicolas Bonnefon else { 1071bb02e0acSNicolas Bonnefon state_ = FileTruncated; 1072bb02e0acSNicolas Bonnefon } 107359d4e393SNicolas Bonnefon } 1074bb02e0acSNicolas Bonnefon 1075bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::changeExpression() 1076bb02e0acSNicolas Bonnefon { 1077bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 1078bb02e0acSNicolas Bonnefon state_ = Static; 1079bb02e0acSNicolas Bonnefon } 1080bb02e0acSNicolas Bonnefon 1081bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::stopSearch() 1082bb02e0acSNicolas Bonnefon { 1083bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 1084bb02e0acSNicolas Bonnefon state_ = Static; 1085bb02e0acSNicolas Bonnefon } 1086bb02e0acSNicolas Bonnefon 1087bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::startSearch() 1088bb02e0acSNicolas Bonnefon { 1089bb02e0acSNicolas Bonnefon if ( autoRefreshRequested_ ) 1090bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 1091bb02e0acSNicolas Bonnefon else 1092bb02e0acSNicolas Bonnefon state_ = Static; 1093bb02e0acSNicolas Bonnefon } 1094a44d09bcSNicolas Bonnefon 1095a44d09bcSNicolas Bonnefon /* 1096a44d09bcSNicolas Bonnefon * CrawlerWidgetContext 1097a44d09bcSNicolas Bonnefon */ 1098a44d09bcSNicolas Bonnefon CrawlerWidgetContext::CrawlerWidgetContext( const char* string ) 1099a44d09bcSNicolas Bonnefon { 11004fb0346eSAnton Filimonov QRegularExpression regex( "S(\\d+):(\\d+)" ); 11014fb0346eSAnton Filimonov QRegularExpressionMatch match = regex.match( string ); 11024fb0346eSAnton Filimonov if ( match.hasMatch() ) { 11034fb0346eSAnton Filimonov sizes_ = { match.captured(1).toInt(), match.captured(2).toInt() }; 1104a44d09bcSNicolas Bonnefon LOG(logDEBUG) << "sizes_: " << sizes_[0] << " " << sizes_[1]; 1105a44d09bcSNicolas Bonnefon } 1106f688be2eSNicolas Bonnefon else { 1107f688be2eSNicolas Bonnefon LOG(logWARNING) << "Unrecognised view size: " << string; 1108a44d09bcSNicolas Bonnefon 1109a44d09bcSNicolas Bonnefon // Default values; 1110a44d09bcSNicolas Bonnefon sizes_ = { 100, 400 }; 1111a44d09bcSNicolas Bonnefon } 1112f688be2eSNicolas Bonnefon 11134fb0346eSAnton Filimonov QRegularExpression case_refresh_regex( "IC(\\d+):AR(\\d+)" ); 11144fb0346eSAnton Filimonov match = case_refresh_regex.match( string ); 11154fb0346eSAnton Filimonov if ( match.hasMatch() ) { 11164fb0346eSAnton Filimonov ignore_case_ = ( match.captured(1).toInt() == 1 ); 11174fb0346eSAnton Filimonov auto_refresh_ = ( match.captured(2).toInt() == 1 ); 1118f688be2eSNicolas Bonnefon 1119f688be2eSNicolas Bonnefon LOG(logDEBUG) << "ignore_case_: " << ignore_case_ << " auto_refresh_: " 1120f688be2eSNicolas Bonnefon << auto_refresh_; 1121f688be2eSNicolas Bonnefon } 1122f688be2eSNicolas Bonnefon else { 1123f688be2eSNicolas Bonnefon LOG(logWARNING) << "Unrecognised case/refresh: " << string; 1124f688be2eSNicolas Bonnefon ignore_case_ = false; 1125f688be2eSNicolas Bonnefon auto_refresh_ = false; 1126f688be2eSNicolas Bonnefon } 1127a44d09bcSNicolas Bonnefon } 1128a44d09bcSNicolas Bonnefon 1129a44d09bcSNicolas Bonnefon std::string CrawlerWidgetContext::toString() const 1130a44d09bcSNicolas Bonnefon { 1131a44d09bcSNicolas Bonnefon char string[160]; 1132a44d09bcSNicolas Bonnefon 1133f688be2eSNicolas Bonnefon snprintf( string, sizeof string, "S%d:%d:IC%d:AR%d", 1134f688be2eSNicolas Bonnefon sizes_[0], sizes_[1], 1135f688be2eSNicolas Bonnefon ignore_case_, auto_refresh_ ); 1136a44d09bcSNicolas Bonnefon 1137f688be2eSNicolas Bonnefon return { string }; 1138a44d09bcSNicolas Bonnefon } 1139