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 1225fa25391SNicolas Bonnefon CrawlerWidget::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 1607847299cSNicolas Bonnefon // 1617847299cSNicolas Bonnefon // Public slots 1627847299cSNicolas Bonnefon // 1637847299cSNicolas Bonnefon 1647847299cSNicolas Bonnefon void CrawlerWidget::stopLoading() 1657847299cSNicolas Bonnefon { 1667847299cSNicolas Bonnefon logFilteredData_->interruptSearch(); 1677847299cSNicolas Bonnefon logData_->interruptLoading(); 1687847299cSNicolas Bonnefon } 1697847299cSNicolas Bonnefon 17032e44cfdSNicolas Bonnefon void CrawlerWidget::reload() 17132e44cfdSNicolas Bonnefon { 17232e44cfdSNicolas Bonnefon searchState_.resetState(); 17332e44cfdSNicolas Bonnefon logFilteredData_->clearSearch(); 17432e44cfdSNicolas Bonnefon filteredView->updateData(); 17532e44cfdSNicolas Bonnefon printSearchInfoMessage(); 17632e44cfdSNicolas Bonnefon 17732e44cfdSNicolas Bonnefon logData_->reload(); 17845ef183cSNicolas Bonnefon 17945ef183cSNicolas Bonnefon // A reload is considered as a first load, 18045ef183cSNicolas Bonnefon // this is to prevent the "new data" icon to be triggered. 18145ef183cSNicolas Bonnefon firstLoadDone_ = false; 18232e44cfdSNicolas Bonnefon } 18332e44cfdSNicolas Bonnefon 1845fa25391SNicolas Bonnefon void CrawlerWidget::setEncoding( Encoding encoding ) 1855fa25391SNicolas Bonnefon { 1865fa25391SNicolas Bonnefon encodingSetting_ = encoding; 1875fa25391SNicolas Bonnefon updateEncoding(); 1885fa25391SNicolas Bonnefon 1895fa25391SNicolas Bonnefon update(); 1905fa25391SNicolas Bonnefon } 1915fa25391SNicolas Bonnefon 192039481acSNicolas Bonnefon // 193039481acSNicolas Bonnefon // Protected functions 194039481acSNicolas Bonnefon // 195039481acSNicolas Bonnefon void CrawlerWidget::doSetData( 196039481acSNicolas Bonnefon std::shared_ptr<LogData> log_data, 197039481acSNicolas Bonnefon std::shared_ptr<LogFilteredData> filtered_data ) 198039481acSNicolas Bonnefon { 199039481acSNicolas Bonnefon logData_ = log_data.get(); 200039481acSNicolas Bonnefon logFilteredData_ = filtered_data.get(); 2011b5e406eSNicolas Bonnefon } 202039481acSNicolas Bonnefon 203b423cd88SNicolas Bonnefon void CrawlerWidget::doSetQuickFindPattern( 204b423cd88SNicolas Bonnefon std::shared_ptr<QuickFindPattern> qfp ) 205b423cd88SNicolas Bonnefon { 206b423cd88SNicolas Bonnefon quickFindPattern_ = qfp; 207b423cd88SNicolas Bonnefon } 208b423cd88SNicolas Bonnefon 2091b5e406eSNicolas Bonnefon void CrawlerWidget::doSetSavedSearches( 2101b5e406eSNicolas Bonnefon std::shared_ptr<SavedSearches> saved_searches ) 2111b5e406eSNicolas Bonnefon { 2121b5e406eSNicolas Bonnefon savedSearches_ = saved_searches; 2131b5e406eSNicolas Bonnefon 2141b5e406eSNicolas Bonnefon // We do setup now, assuming doSetData has been called before 2151b5e406eSNicolas Bonnefon // us, that's not great really... 216039481acSNicolas Bonnefon setup(); 217039481acSNicolas Bonnefon } 218039481acSNicolas Bonnefon 219a44d09bcSNicolas Bonnefon void CrawlerWidget::doSetViewContext( 220a44d09bcSNicolas Bonnefon const char* view_context ) 221a44d09bcSNicolas Bonnefon { 222a44d09bcSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::doSetViewContext: " << view_context; 223a44d09bcSNicolas Bonnefon 224a44d09bcSNicolas Bonnefon CrawlerWidgetContext context = { view_context }; 225a44d09bcSNicolas Bonnefon 226a44d09bcSNicolas Bonnefon setSizes( context.sizes() ); 227f688be2eSNicolas Bonnefon ignoreCaseCheck->setCheckState( context.ignoreCase() ? Qt::Checked : Qt::Unchecked ); 228240a4b5eSNicolas Bonnefon 229240a4b5eSNicolas Bonnefon auto auto_refresh_check_state = context.autoRefresh() ? Qt::Checked : Qt::Unchecked; 230240a4b5eSNicolas Bonnefon searchRefreshCheck->setCheckState( auto_refresh_check_state ); 231240a4b5eSNicolas Bonnefon // Manually call the handler as it is not called when changing the state programmatically 232240a4b5eSNicolas Bonnefon searchRefreshChangedHandler( auto_refresh_check_state ); 233a44d09bcSNicolas Bonnefon } 234a44d09bcSNicolas Bonnefon 235a44d09bcSNicolas Bonnefon std::shared_ptr<const ViewContextInterface> 236a44d09bcSNicolas Bonnefon CrawlerWidget::doGetViewContext() const 237a44d09bcSNicolas Bonnefon { 238f688be2eSNicolas Bonnefon auto context = std::make_shared<const CrawlerWidgetContext>( 239f688be2eSNicolas Bonnefon sizes(), 240f688be2eSNicolas Bonnefon ( ignoreCaseCheck->checkState() == Qt::Checked ), 241f688be2eSNicolas Bonnefon ( searchRefreshCheck->checkState() == Qt::Checked ) ); 242a44d09bcSNicolas Bonnefon 243a44d09bcSNicolas Bonnefon return static_cast<std::shared_ptr<const ViewContextInterface>>( context ); 244a44d09bcSNicolas Bonnefon } 245a44d09bcSNicolas Bonnefon 246039481acSNicolas Bonnefon // 247039481acSNicolas Bonnefon // Slots 248039481acSNicolas Bonnefon // 249039481acSNicolas Bonnefon 250039481acSNicolas Bonnefon void CrawlerWidget::startNewSearch() 251039481acSNicolas Bonnefon { 252039481acSNicolas Bonnefon // Record the search line in the recent list 253039481acSNicolas Bonnefon // (reload the list first in case another glogg changed it) 254039481acSNicolas Bonnefon GetPersistentInfo().retrieve( "savedSearches" ); 2551b5e406eSNicolas Bonnefon savedSearches_->addRecent( searchLineEdit->currentText() ); 256039481acSNicolas Bonnefon GetPersistentInfo().save( "savedSearches" ); 257039481acSNicolas Bonnefon 258039481acSNicolas Bonnefon // Update the SearchLine (history) 259039481acSNicolas Bonnefon updateSearchCombo(); 260039481acSNicolas Bonnefon // Call the private function to do the search 261039481acSNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() ); 262039481acSNicolas Bonnefon } 263039481acSNicolas Bonnefon 264039481acSNicolas Bonnefon void CrawlerWidget::stopSearch() 265039481acSNicolas Bonnefon { 266039481acSNicolas Bonnefon logFilteredData_->interruptSearch(); 267039481acSNicolas Bonnefon searchState_.stopSearch(); 268039481acSNicolas Bonnefon printSearchInfoMessage(); 269039481acSNicolas Bonnefon } 270039481acSNicolas Bonnefon 271039481acSNicolas Bonnefon // When receiving the 'newDataAvailable' signal from LogFilteredData 272039481acSNicolas Bonnefon void CrawlerWidget::updateFilteredView( int nbMatches, int progress ) 273039481acSNicolas Bonnefon { 274039481acSNicolas Bonnefon LOG(logDEBUG) << "updateFilteredView received."; 275039481acSNicolas Bonnefon 276039481acSNicolas Bonnefon if ( progress == 100 ) { 277039481acSNicolas Bonnefon // Searching done 278039481acSNicolas Bonnefon printSearchInfoMessage( nbMatches ); 279039481acSNicolas Bonnefon searchInfoLine->hideGauge(); 280039481acSNicolas Bonnefon // De-activate the stop button 281039481acSNicolas Bonnefon stopButton->setEnabled( false ); 282039481acSNicolas Bonnefon } 283039481acSNicolas Bonnefon else { 284039481acSNicolas Bonnefon // Search in progress 285039481acSNicolas Bonnefon // We ignore 0% and 100% to avoid a flash when the search is very short 286039481acSNicolas Bonnefon if ( progress > 0 ) { 287039481acSNicolas Bonnefon searchInfoLine->setText( 288039481acSNicolas Bonnefon tr("Search in progress (%1 %)... %2 match%3 found so far.") 289039481acSNicolas Bonnefon .arg( progress ) 290039481acSNicolas Bonnefon .arg( nbMatches ) 291039481acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ) ); 292039481acSNicolas Bonnefon searchInfoLine->displayGauge( progress ); 293039481acSNicolas Bonnefon } 294039481acSNicolas Bonnefon } 295039481acSNicolas Bonnefon 2968ea5bc4cSNicolas Bonnefon // If more (or less, e.g. come back to 0) matches have been found 2978ea5bc4cSNicolas Bonnefon if ( nbMatches != nbMatches_ ) { 2987999f43eSNicolas Bonnefon nbMatches_ = nbMatches; 2997999f43eSNicolas Bonnefon 300039481acSNicolas Bonnefon // Recompute the content of the filtered window. 301039481acSNicolas Bonnefon filteredView->updateData(); 302039481acSNicolas Bonnefon 303039481acSNicolas Bonnefon // Update the match overview 3040f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 305039481acSNicolas Bonnefon 3067999f43eSNicolas Bonnefon // New data found icon 3077999f43eSNicolas Bonnefon changeDataStatus( DataStatus::NEW_FILTERED_DATA ); 3087999f43eSNicolas Bonnefon 309039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 310039481acSNicolas Bonnefon update(); 311039481acSNicolas Bonnefon } 3127999f43eSNicolas Bonnefon } 313039481acSNicolas Bonnefon 314039481acSNicolas Bonnefon void CrawlerWidget::jumpToMatchingLine(int filteredLineNb) 315039481acSNicolas Bonnefon { 316039481acSNicolas Bonnefon int mainViewLine = logFilteredData_->getMatchingLineNumber(filteredLineNb); 317039481acSNicolas Bonnefon logMainView->selectAndDisplayLine(mainViewLine); // FIXME: should be done with a signal. 318039481acSNicolas Bonnefon } 319039481acSNicolas Bonnefon 3209cacd6a9SNicolas Bonnefon void CrawlerWidget::updateLineNumberHandler( int line ) 3219cacd6a9SNicolas Bonnefon { 3229cacd6a9SNicolas Bonnefon currentLineNumber_ = line; 3239cacd6a9SNicolas Bonnefon emit updateLineNumber( line ); 3249cacd6a9SNicolas Bonnefon } 3259cacd6a9SNicolas Bonnefon 326039481acSNicolas Bonnefon void CrawlerWidget::markLineFromMain( qint64 line ) 327039481acSNicolas Bonnefon { 3282493b508SNicolas Bonnefon if ( line < logData_->getNbLine() ) { 329039481acSNicolas Bonnefon if ( logFilteredData_->isLineMarked( line ) ) 330039481acSNicolas Bonnefon logFilteredData_->deleteMark( line ); 331039481acSNicolas Bonnefon else 332039481acSNicolas Bonnefon logFilteredData_->addMark( line ); 333039481acSNicolas Bonnefon 334*7552c461SNicolas Bonnefon // Recompute the content of both window. 335039481acSNicolas Bonnefon filteredView->updateData(); 336*7552c461SNicolas Bonnefon logMainView->updateData(); 337039481acSNicolas Bonnefon 338039481acSNicolas Bonnefon // Update the match overview 3390f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 340039481acSNicolas Bonnefon 341039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 342039481acSNicolas Bonnefon update(); 343039481acSNicolas Bonnefon } 3442493b508SNicolas Bonnefon } 345039481acSNicolas Bonnefon 346039481acSNicolas Bonnefon void CrawlerWidget::markLineFromFiltered( qint64 line ) 347039481acSNicolas Bonnefon { 3482493b508SNicolas Bonnefon if ( line < logFilteredData_->getNbLine() ) { 349039481acSNicolas Bonnefon qint64 line_in_file = logFilteredData_->getMatchingLineNumber( line ); 350039481acSNicolas Bonnefon if ( logFilteredData_->filteredLineTypeByIndex( line ) 351039481acSNicolas Bonnefon == LogFilteredData::Mark ) 352039481acSNicolas Bonnefon logFilteredData_->deleteMark( line_in_file ); 353039481acSNicolas Bonnefon else 354039481acSNicolas Bonnefon logFilteredData_->addMark( line_in_file ); 355039481acSNicolas Bonnefon 356*7552c461SNicolas Bonnefon // Recompute the content of both window. 357039481acSNicolas Bonnefon filteredView->updateData(); 358*7552c461SNicolas Bonnefon logMainView->updateData(); 359039481acSNicolas Bonnefon 360039481acSNicolas Bonnefon // Update the match overview 3610f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 362039481acSNicolas Bonnefon 363039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 364039481acSNicolas Bonnefon update(); 365039481acSNicolas Bonnefon } 3662493b508SNicolas Bonnefon } 367039481acSNicolas Bonnefon 368039481acSNicolas Bonnefon void CrawlerWidget::applyConfiguration() 369039481acSNicolas Bonnefon { 37011582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 37111582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 37211582726SNicolas Bonnefon QFont font = config->mainFont(); 373039481acSNicolas Bonnefon 374039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::applyConfiguration"; 375039481acSNicolas Bonnefon 376039481acSNicolas Bonnefon // Whatever font we use, we should NOT use kerning 377039481acSNicolas Bonnefon font.setKerning( false ); 378039481acSNicolas Bonnefon font.setFixedPitch( true ); 379039481acSNicolas Bonnefon #if QT_VERSION > 0x040700 380039481acSNicolas Bonnefon // Necessary on systems doing subpixel positionning (e.g. Ubuntu 12.04) 381039481acSNicolas Bonnefon font.setStyleStrategy( QFont::ForceIntegerMetrics ); 382039481acSNicolas Bonnefon #endif 383039481acSNicolas Bonnefon logMainView->setFont(font); 384039481acSNicolas Bonnefon filteredView->setFont(font); 385039481acSNicolas Bonnefon 38611582726SNicolas Bonnefon logMainView->setLineNumbersVisible( config->mainLineNumbersVisible() ); 38711582726SNicolas Bonnefon filteredView->setLineNumbersVisible( config->filteredLineNumbersVisible() ); 388039481acSNicolas Bonnefon 38911582726SNicolas Bonnefon overview_.setVisible( config->isOverviewVisible() ); 390039481acSNicolas Bonnefon logMainView->refreshOverview(); 391039481acSNicolas Bonnefon 392039481acSNicolas Bonnefon logMainView->updateDisplaySize(); 393039481acSNicolas Bonnefon logMainView->update(); 394039481acSNicolas Bonnefon filteredView->updateDisplaySize(); 395039481acSNicolas Bonnefon filteredView->update(); 396039481acSNicolas Bonnefon 39780bca0a3SNicolas Bonnefon // Polling interval 39880bca0a3SNicolas Bonnefon logData_->setPollingInterval( 39980bca0a3SNicolas Bonnefon config->pollingEnabled() ? config->pollIntervalMs() : 0 ); 40080bca0a3SNicolas Bonnefon 401039481acSNicolas Bonnefon // Update the SearchLine (history) 402039481acSNicolas Bonnefon updateSearchCombo(); 403039481acSNicolas Bonnefon } 404039481acSNicolas Bonnefon 4058570d8d2SNicolas Bonnefon void CrawlerWidget::enteringQuickFind() 4068570d8d2SNicolas Bonnefon { 4078570d8d2SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::enteringQuickFind"; 4088570d8d2SNicolas Bonnefon 4098570d8d2SNicolas Bonnefon // Remember who had the focus (only if it is one of our views) 4108570d8d2SNicolas Bonnefon QWidget* focus_widget = QApplication::focusWidget(); 4118570d8d2SNicolas Bonnefon 4128570d8d2SNicolas Bonnefon if ( ( focus_widget == logMainView ) || ( focus_widget == filteredView ) ) 4138570d8d2SNicolas Bonnefon qfSavedFocus_ = focus_widget; 4148570d8d2SNicolas Bonnefon else 4158570d8d2SNicolas Bonnefon qfSavedFocus_ = nullptr; 4168570d8d2SNicolas Bonnefon } 4178570d8d2SNicolas Bonnefon 4188570d8d2SNicolas Bonnefon void CrawlerWidget::exitingQuickFind() 4198570d8d2SNicolas Bonnefon { 4208570d8d2SNicolas Bonnefon // Restore the focus once the QFBar has been hidden 4218570d8d2SNicolas Bonnefon if ( qfSavedFocus_ ) 4228570d8d2SNicolas Bonnefon qfSavedFocus_->setFocus(); 4238570d8d2SNicolas Bonnefon } 4248570d8d2SNicolas Bonnefon 425812146a8SNicolas Bonnefon void CrawlerWidget::loadingFinishedHandler( LoadingStatus status ) 426039481acSNicolas Bonnefon { 42760864ff5SNicolas Bonnefon loadingInProgress_ = false; 42860864ff5SNicolas Bonnefon 429039481acSNicolas Bonnefon // We need to refresh the main window because the view lines on the 430039481acSNicolas Bonnefon // overview have probably changed. 4310f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 432039481acSNicolas Bonnefon 433039481acSNicolas Bonnefon // FIXME, handle topLine 434039481acSNicolas Bonnefon // logMainView->updateData( logData_, topLine ); 435039481acSNicolas Bonnefon logMainView->updateData(); 436039481acSNicolas Bonnefon 437039481acSNicolas Bonnefon // Shall we Forbid starting a search when loading in progress? 438039481acSNicolas Bonnefon // searchButton->setEnabled( false ); 439039481acSNicolas Bonnefon 440039481acSNicolas Bonnefon // searchButton->setEnabled( true ); 441039481acSNicolas Bonnefon 442039481acSNicolas Bonnefon // See if we need to auto-refresh the search 443039481acSNicolas Bonnefon if ( searchState_.isAutorefreshAllowed() ) { 44459d4e393SNicolas Bonnefon if ( searchState_.isFileTruncated() ) 44559d4e393SNicolas Bonnefon // We need to restart the search 44659d4e393SNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() ); 44759d4e393SNicolas Bonnefon else 448039481acSNicolas Bonnefon logFilteredData_->updateSearch(); 449039481acSNicolas Bonnefon } 450039481acSNicolas Bonnefon 4515fa25391SNicolas Bonnefon // Set the encoding for the views 4525fa25391SNicolas Bonnefon updateEncoding(); 4535fa25391SNicolas Bonnefon 454812146a8SNicolas Bonnefon emit loadingFinished( status ); 45545ef183cSNicolas Bonnefon 45645ef183cSNicolas Bonnefon // Also change the data available icon 45745ef183cSNicolas Bonnefon if ( firstLoadDone_ ) 45845ef183cSNicolas Bonnefon changeDataStatus( DataStatus::NEW_DATA ); 45945ef183cSNicolas Bonnefon else 46045ef183cSNicolas Bonnefon firstLoadDone_ = true; 461039481acSNicolas Bonnefon } 462039481acSNicolas Bonnefon 463039481acSNicolas Bonnefon void CrawlerWidget::fileChangedHandler( LogData::MonitoredFileStatus status ) 464039481acSNicolas Bonnefon { 465039481acSNicolas Bonnefon // Handle the case where the file has been truncated 466039481acSNicolas Bonnefon if ( status == LogData::Truncated ) { 467039481acSNicolas Bonnefon // Clear all marks (TODO offer the option to keep them) 468039481acSNicolas Bonnefon logFilteredData_->clearMarks(); 469039481acSNicolas Bonnefon if ( ! searchInfoLine->text().isEmpty() ) { 470039481acSNicolas Bonnefon // Invalidate the search 471039481acSNicolas Bonnefon logFilteredData_->clearSearch(); 472039481acSNicolas Bonnefon filteredView->updateData(); 473039481acSNicolas Bonnefon searchState_.truncateFile(); 474039481acSNicolas Bonnefon printSearchInfoMessage(); 4757999f43eSNicolas Bonnefon nbMatches_ = 0; 476039481acSNicolas Bonnefon } 477039481acSNicolas Bonnefon } 478039481acSNicolas Bonnefon } 479039481acSNicolas Bonnefon 480039481acSNicolas Bonnefon // Returns a pointer to the window in which the search should be done 481039481acSNicolas Bonnefon AbstractLogView* CrawlerWidget::activeView() const 482039481acSNicolas Bonnefon { 483039481acSNicolas Bonnefon QWidget* activeView; 484039481acSNicolas Bonnefon 485039481acSNicolas Bonnefon // Search in the window that has focus, or the window where 'Find' was 486039481acSNicolas Bonnefon // called from, or the main window. 487039481acSNicolas Bonnefon if ( filteredView->hasFocus() || logMainView->hasFocus() ) 488039481acSNicolas Bonnefon activeView = QApplication::focusWidget(); 489039481acSNicolas Bonnefon else 4908570d8d2SNicolas Bonnefon activeView = qfSavedFocus_; 491039481acSNicolas Bonnefon 492b423cd88SNicolas Bonnefon if ( activeView ) { 493b423cd88SNicolas Bonnefon AbstractLogView* view = qobject_cast<AbstractLogView*>( activeView ); 494039481acSNicolas Bonnefon return view; 495b423cd88SNicolas Bonnefon } 496b423cd88SNicolas Bonnefon else { 497b423cd88SNicolas Bonnefon LOG(logWARNING) << "No active view, defaulting to logMainView"; 498039481acSNicolas Bonnefon return logMainView; 499039481acSNicolas Bonnefon } 500b423cd88SNicolas Bonnefon } 501039481acSNicolas Bonnefon 502039481acSNicolas Bonnefon void CrawlerWidget::searchForward() 503039481acSNicolas Bonnefon { 504039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchForward"; 505039481acSNicolas Bonnefon 506039481acSNicolas Bonnefon activeView()->searchForward(); 507039481acSNicolas Bonnefon } 508039481acSNicolas Bonnefon 509039481acSNicolas Bonnefon void CrawlerWidget::searchBackward() 510039481acSNicolas Bonnefon { 511039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchBackward"; 512039481acSNicolas Bonnefon 513039481acSNicolas Bonnefon activeView()->searchBackward(); 514039481acSNicolas Bonnefon } 515039481acSNicolas Bonnefon 516039481acSNicolas Bonnefon void CrawlerWidget::searchRefreshChangedHandler( int state ) 517039481acSNicolas Bonnefon { 518039481acSNicolas Bonnefon searchState_.setAutorefresh( state == Qt::Checked ); 519039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 520039481acSNicolas Bonnefon } 521039481acSNicolas Bonnefon 522039481acSNicolas Bonnefon void CrawlerWidget::searchTextChangeHandler() 523039481acSNicolas Bonnefon { 524039481acSNicolas Bonnefon // We suspend auto-refresh 525039481acSNicolas Bonnefon searchState_.changeExpression(); 526039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 527039481acSNicolas Bonnefon } 528039481acSNicolas Bonnefon 529039481acSNicolas Bonnefon void CrawlerWidget::changeFilteredViewVisibility( int index ) 530039481acSNicolas Bonnefon { 531039481acSNicolas Bonnefon QStandardItem* item = visibilityModel_->item( index ); 532039481acSNicolas Bonnefon FilteredView::Visibility visibility = 533039481acSNicolas Bonnefon static_cast< FilteredView::Visibility>( item->data().toInt() ); 534039481acSNicolas Bonnefon 535039481acSNicolas Bonnefon filteredView->setVisibility( visibility ); 536039481acSNicolas Bonnefon } 537039481acSNicolas Bonnefon 538039481acSNicolas Bonnefon void CrawlerWidget::addToSearch( const QString& string ) 539039481acSNicolas Bonnefon { 540039481acSNicolas Bonnefon QString text = searchLineEdit->currentText(); 541039481acSNicolas Bonnefon 542039481acSNicolas Bonnefon if ( text.isEmpty() ) 543039481acSNicolas Bonnefon text = string; 544039481acSNicolas Bonnefon else { 545039481acSNicolas Bonnefon // Escape the regexp chars from the string before adding it. 546039481acSNicolas Bonnefon text += ( '|' + QRegExp::escape( string ) ); 547039481acSNicolas Bonnefon } 548039481acSNicolas Bonnefon 549039481acSNicolas Bonnefon searchLineEdit->setEditText( text ); 550039481acSNicolas Bonnefon 551039481acSNicolas Bonnefon // Set the focus to lineEdit so that the user can press 'Return' immediately 552039481acSNicolas Bonnefon searchLineEdit->lineEdit()->setFocus(); 553039481acSNicolas Bonnefon } 554039481acSNicolas Bonnefon 555039481acSNicolas Bonnefon void CrawlerWidget::mouseHoveredOverMatch( qint64 line ) 556039481acSNicolas Bonnefon { 557039481acSNicolas Bonnefon qint64 line_in_mainview = logFilteredData_->getMatchingLineNumber( line ); 558039481acSNicolas Bonnefon 559039481acSNicolas Bonnefon overviewWidget_->highlightLine( line_in_mainview ); 560039481acSNicolas Bonnefon } 561039481acSNicolas Bonnefon 56245ef183cSNicolas Bonnefon void CrawlerWidget::activityDetected() 56345ef183cSNicolas Bonnefon { 56445ef183cSNicolas Bonnefon changeDataStatus( DataStatus::OLD_DATA ); 56545ef183cSNicolas Bonnefon } 56645ef183cSNicolas Bonnefon 567039481acSNicolas Bonnefon // 568039481acSNicolas Bonnefon // Private functions 569039481acSNicolas Bonnefon // 570039481acSNicolas Bonnefon 571039481acSNicolas Bonnefon // Build the widget and connect all the signals, this must be done once 572039481acSNicolas Bonnefon // the data are attached. 573039481acSNicolas Bonnefon void CrawlerWidget::setup() 574039481acSNicolas Bonnefon { 575bb02e0acSNicolas Bonnefon setOrientation(Qt::Vertical); 576bb02e0acSNicolas Bonnefon 577039481acSNicolas Bonnefon assert( logData_ ); 578039481acSNicolas Bonnefon assert( logFilteredData_ ); 579bb02e0acSNicolas Bonnefon 580bb02e0acSNicolas Bonnefon // The views 581bb02e0acSNicolas Bonnefon bottomWindow = new QWidget; 582bb02e0acSNicolas Bonnefon overviewWidget_ = new OverviewWidget(); 583bb02e0acSNicolas Bonnefon logMainView = new LogMainView( 5840f9fd9edSNicolas Bonnefon logData_, quickFindPattern_.get(), &overview_, overviewWidget_ ); 585bb02e0acSNicolas Bonnefon filteredView = new FilteredView( 586b423cd88SNicolas Bonnefon logFilteredData_, quickFindPattern_.get() ); 587bb02e0acSNicolas Bonnefon 5880f9fd9edSNicolas Bonnefon overviewWidget_->setOverview( &overview_ ); 589bb02e0acSNicolas Bonnefon overviewWidget_->setParent( logMainView ); 590bb02e0acSNicolas Bonnefon 59158ab9c53SNicolas Bonnefon // Connect the search to the top view 59258ab9c53SNicolas Bonnefon logMainView->useNewFiltering( logFilteredData_ ); 59358ab9c53SNicolas Bonnefon 594bb02e0acSNicolas Bonnefon // Construct the visibility button 595bb02e0acSNicolas Bonnefon visibilityModel_ = new QStandardItemModel( this ); 596bb02e0acSNicolas Bonnefon 597bb02e0acSNicolas Bonnefon QStandardItem *marksAndMatchesItem = new QStandardItem( tr( "Marks and matches" ) ); 598bb02e0acSNicolas Bonnefon QPixmap marksAndMatchesPixmap( 16, 10 ); 599bb02e0acSNicolas Bonnefon marksAndMatchesPixmap.fill( Qt::gray ); 600bb02e0acSNicolas Bonnefon marksAndMatchesItem->setIcon( QIcon( marksAndMatchesPixmap ) ); 601bb02e0acSNicolas Bonnefon marksAndMatchesItem->setData( FilteredView::MarksAndMatches ); 602bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksAndMatchesItem ); 603bb02e0acSNicolas Bonnefon 604bb02e0acSNicolas Bonnefon QStandardItem *marksItem = new QStandardItem( tr( "Marks" ) ); 605bb02e0acSNicolas Bonnefon QPixmap marksPixmap( 16, 10 ); 606bb02e0acSNicolas Bonnefon marksPixmap.fill( Qt::blue ); 607bb02e0acSNicolas Bonnefon marksItem->setIcon( QIcon( marksPixmap ) ); 608bb02e0acSNicolas Bonnefon marksItem->setData( FilteredView::MarksOnly ); 609bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksItem ); 610bb02e0acSNicolas Bonnefon 611bb02e0acSNicolas Bonnefon QStandardItem *matchesItem = new QStandardItem( tr( "Matches" ) ); 612bb02e0acSNicolas Bonnefon QPixmap matchesPixmap( 16, 10 ); 613bb02e0acSNicolas Bonnefon matchesPixmap.fill( Qt::red ); 614bb02e0acSNicolas Bonnefon matchesItem->setIcon( QIcon( matchesPixmap ) ); 615bb02e0acSNicolas Bonnefon matchesItem->setData( FilteredView::MatchesOnly ); 616bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( matchesItem ); 617bb02e0acSNicolas Bonnefon 618bb02e0acSNicolas Bonnefon QListView *visibilityView = new QListView( this ); 619bb02e0acSNicolas Bonnefon visibilityView->setMovement( QListView::Static ); 620bb02e0acSNicolas Bonnefon visibilityView->setMinimumWidth( 170 ); // Only needed with custom style-sheet 621bb02e0acSNicolas Bonnefon 622bb02e0acSNicolas Bonnefon visibilityBox = new QComboBox(); 623bb02e0acSNicolas Bonnefon visibilityBox->setModel( visibilityModel_ ); 624bb02e0acSNicolas Bonnefon visibilityBox->setView( visibilityView ); 625bb02e0acSNicolas Bonnefon 626bb02e0acSNicolas Bonnefon // Select "Marks and matches" by default (same default as the filtered view) 627bb02e0acSNicolas Bonnefon visibilityBox->setCurrentIndex( 0 ); 628bb02e0acSNicolas Bonnefon 629bb02e0acSNicolas Bonnefon // TODO: Maybe there is some way to set the popup width to be 630bb02e0acSNicolas Bonnefon // sized-to-content (as it is when the stylesheet is not overriden) in the 631bb02e0acSNicolas Bonnefon // stylesheet as opposed to setting a hard min-width on the view above. 632bb02e0acSNicolas Bonnefon visibilityBox->setStyleSheet( " \ 633bb02e0acSNicolas Bonnefon QComboBox:on {\ 634bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 6px;\ 635bb02e0acSNicolas Bonnefon width: 19px;\ 636bb02e0acSNicolas Bonnefon } \ 637bb02e0acSNicolas Bonnefon QComboBox:!on {\ 638bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 7px;\ 639bb02e0acSNicolas Bonnefon width: 19px;\ 640bb02e0acSNicolas Bonnefon height: 16px;\ 641bb02e0acSNicolas Bonnefon border: 1px solid gray;\ 642bb02e0acSNicolas Bonnefon } \ 643bb02e0acSNicolas Bonnefon QComboBox::drop-down::down-arrow {\ 644bb02e0acSNicolas Bonnefon width: 0px;\ 645bb02e0acSNicolas Bonnefon border-width: 0px;\ 646bb02e0acSNicolas Bonnefon } \ 647bb02e0acSNicolas Bonnefon " ); 648bb02e0acSNicolas Bonnefon 649bb02e0acSNicolas Bonnefon // Construct the Search Info line 650bb02e0acSNicolas Bonnefon searchInfoLine = new InfoLine(); 651bb02e0acSNicolas Bonnefon searchInfoLine->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 652bb02e0acSNicolas Bonnefon searchInfoLine->setLineWidth( 1 ); 653bb02e0acSNicolas Bonnefon searchInfoLineDefaultPalette = searchInfoLine->palette(); 654bb02e0acSNicolas Bonnefon 655bb02e0acSNicolas Bonnefon ignoreCaseCheck = new QCheckBox( "Ignore &case" ); 656bb02e0acSNicolas Bonnefon searchRefreshCheck = new QCheckBox( "Auto-&refresh" ); 657bb02e0acSNicolas Bonnefon 658bb02e0acSNicolas Bonnefon // Construct the Search line 659bb02e0acSNicolas Bonnefon searchLabel = new QLabel(tr("&Text: ")); 660bb02e0acSNicolas Bonnefon searchLineEdit = new QComboBox; 661bb02e0acSNicolas Bonnefon searchLineEdit->setEditable( true ); 662bb02e0acSNicolas Bonnefon searchLineEdit->setCompleter( 0 ); 6631b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() ); 664bb02e0acSNicolas Bonnefon searchLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); 665bb02e0acSNicolas Bonnefon searchLineEdit->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon ); 666bb02e0acSNicolas Bonnefon 667bb02e0acSNicolas Bonnefon searchLabel->setBuddy( searchLineEdit ); 668bb02e0acSNicolas Bonnefon 669bb02e0acSNicolas Bonnefon searchButton = new QToolButton(); 670bb02e0acSNicolas Bonnefon searchButton->setText( tr("&Search") ); 671bb02e0acSNicolas Bonnefon searchButton->setAutoRaise( true ); 672bb02e0acSNicolas Bonnefon 673bb02e0acSNicolas Bonnefon stopButton = new QToolButton(); 67428c802baSNicolas Bonnefon stopButton->setIcon( QIcon(":/images/stop14.png") ); 675bb02e0acSNicolas Bonnefon stopButton->setAutoRaise( true ); 676bb02e0acSNicolas Bonnefon stopButton->setEnabled( false ); 677bb02e0acSNicolas Bonnefon 678bb02e0acSNicolas Bonnefon QHBoxLayout* searchLineLayout = new QHBoxLayout; 679bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLabel); 680bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLineEdit); 681bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchButton); 682bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(stopButton); 683bb02e0acSNicolas Bonnefon searchLineLayout->setContentsMargins(6, 0, 6, 0); 684bb02e0acSNicolas Bonnefon stopButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 685bb02e0acSNicolas Bonnefon searchButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 686bb02e0acSNicolas Bonnefon 687bb02e0acSNicolas Bonnefon QHBoxLayout* searchInfoLineLayout = new QHBoxLayout; 688bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( visibilityBox ); 689bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchInfoLine ); 690bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( ignoreCaseCheck ); 691bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchRefreshCheck ); 692bb02e0acSNicolas Bonnefon 693bb02e0acSNicolas Bonnefon // Construct the bottom window 694bb02e0acSNicolas Bonnefon QVBoxLayout* bottomMainLayout = new QVBoxLayout; 695bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchLineLayout); 696bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchInfoLineLayout); 697bb02e0acSNicolas Bonnefon bottomMainLayout->addWidget(filteredView); 698bb02e0acSNicolas Bonnefon bottomMainLayout->setContentsMargins(2, 1, 2, 1); 699bb02e0acSNicolas Bonnefon bottomWindow->setLayout(bottomMainLayout); 700bb02e0acSNicolas Bonnefon 701bb02e0acSNicolas Bonnefon addWidget( logMainView ); 702bb02e0acSNicolas Bonnefon addWidget( bottomWindow ); 703bb02e0acSNicolas Bonnefon 704bb02e0acSNicolas Bonnefon // Default splitter position (usually overridden by the config file) 705bb02e0acSNicolas Bonnefon QList<int> splitterSizes; 706bb02e0acSNicolas Bonnefon splitterSizes += 400; 707bb02e0acSNicolas Bonnefon splitterSizes += 100; 708bb02e0acSNicolas Bonnefon setSizes( splitterSizes ); 709bb02e0acSNicolas Bonnefon 710f688be2eSNicolas Bonnefon // Default search checkboxes 711f688be2eSNicolas Bonnefon auto config = Persistent<Configuration>( "settings" ); 712f688be2eSNicolas Bonnefon searchRefreshCheck->setCheckState( config->isSearchAutoRefreshDefault() ? 713f688be2eSNicolas Bonnefon Qt::Checked : Qt::Unchecked ); 714c580560cSNicolas Bonnefon // Manually call the handler as it is not called when changing the state programmatically 715c580560cSNicolas Bonnefon searchRefreshChangedHandler( searchRefreshCheck->checkState() ); 716f688be2eSNicolas Bonnefon ignoreCaseCheck->setCheckState( config->isSearchIgnoreCaseDefault() ? 717f688be2eSNicolas Bonnefon Qt::Checked : Qt::Unchecked ); 718f688be2eSNicolas Bonnefon 719bb02e0acSNicolas Bonnefon // Connect the signals 720bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( returnPressed() ), 721bb02e0acSNicolas Bonnefon searchButton, SIGNAL( clicked() )); 722bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( textEdited( const QString& ) ), 723bb02e0acSNicolas Bonnefon this, SLOT( searchTextChangeHandler() )); 724bb02e0acSNicolas Bonnefon connect(searchButton, SIGNAL( clicked() ), 725bb02e0acSNicolas Bonnefon this, SLOT( startNewSearch() ) ); 726bb02e0acSNicolas Bonnefon connect(stopButton, SIGNAL( clicked() ), 727bb02e0acSNicolas Bonnefon this, SLOT( stopSearch() ) ); 728bb02e0acSNicolas Bonnefon 729bb02e0acSNicolas Bonnefon connect(visibilityBox, SIGNAL( currentIndexChanged( int ) ), 730bb02e0acSNicolas Bonnefon this, SLOT( changeFilteredViewVisibility( int ) ) ); 731bb02e0acSNicolas Bonnefon 732bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( newSelection( int ) ), 733bb02e0acSNicolas Bonnefon logMainView, SLOT( update() ) ); 734bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 735bb02e0acSNicolas Bonnefon this, SLOT( jumpToMatchingLine( int ) ) ); 736bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 737bb02e0acSNicolas Bonnefon filteredView, SLOT( update() ) ); 738bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( updateLineNumber( int ) ), 7399cacd6a9SNicolas Bonnefon this, SLOT( updateLineNumberHandler( int ) ) ); 740bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( markLine( qint64 ) ), 741bb02e0acSNicolas Bonnefon this, SLOT( markLineFromMain( qint64 ) ) ); 742bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( markLine( qint64 ) ), 743bb02e0acSNicolas Bonnefon this, SLOT( markLineFromFiltered( qint64 ) ) ); 744bb02e0acSNicolas Bonnefon 745bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( addToSearch( const QString& ) ), 746bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 747bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( addToSearch( const QString& ) ), 748bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 749bb02e0acSNicolas Bonnefon 750bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseHoveredOverLine( qint64 ) ), 751bb02e0acSNicolas Bonnefon this, SLOT( mouseHoveredOverMatch( qint64 ) ) ); 752bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseLeftHoveringZone() ), 753bb02e0acSNicolas Bonnefon overviewWidget_, SLOT( removeHighlight() ) ); 754bb02e0acSNicolas Bonnefon 755bb02e0acSNicolas Bonnefon // Follow option (up and down) 756bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 757bb02e0acSNicolas Bonnefon logMainView, SLOT( followSet( bool ) ) ); 758bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 759bb02e0acSNicolas Bonnefon filteredView, SLOT( followSet( bool ) ) ); 760b297d2f4SNicolas Bonnefon connect(logMainView, SIGNAL( followModeChanged( bool ) ), 761b297d2f4SNicolas Bonnefon this, SIGNAL( followModeChanged( bool ) ) ); 762b297d2f4SNicolas Bonnefon connect(filteredView, SIGNAL( followModeChanged( bool ) ), 763b297d2f4SNicolas Bonnefon this, SIGNAL( followModeChanged( bool ) ) ); 764bb02e0acSNicolas Bonnefon 76545ef183cSNicolas Bonnefon // Detect activity in the views 76645ef183cSNicolas Bonnefon connect(logMainView, SIGNAL( activity() ), 76745ef183cSNicolas Bonnefon this, SLOT( activityDetected() ) ); 76845ef183cSNicolas Bonnefon connect(filteredView, SIGNAL( activity() ), 76945ef183cSNicolas Bonnefon this, SLOT( activityDetected() ) ); 77045ef183cSNicolas Bonnefon 771bb02e0acSNicolas Bonnefon connect( logFilteredData_, SIGNAL( searchProgressed( int, int ) ), 772bb02e0acSNicolas Bonnefon this, SLOT( updateFilteredView( int, int ) ) ); 773bb02e0acSNicolas Bonnefon 774bb02e0acSNicolas Bonnefon // Sent load file update to MainWindow (for status update) 775bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( loadingProgressed( int ) ), 776bb02e0acSNicolas Bonnefon this, SIGNAL( loadingProgressed( int ) ) ); 777812146a8SNicolas Bonnefon connect( logData_, SIGNAL( loadingFinished( LoadingStatus ) ), 778812146a8SNicolas Bonnefon this, SLOT( loadingFinishedHandler( LoadingStatus ) ) ); 779bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( fileChanged( LogData::MonitoredFileStatus ) ), 780bb02e0acSNicolas Bonnefon this, SLOT( fileChangedHandler( LogData::MonitoredFileStatus ) ) ); 781bb02e0acSNicolas Bonnefon 782bb02e0acSNicolas Bonnefon // Search auto-refresh 783bb02e0acSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ), 784bb02e0acSNicolas Bonnefon this, SLOT( searchRefreshChangedHandler( int ) ) ); 785f688be2eSNicolas Bonnefon 786f688be2eSNicolas Bonnefon // Advise the parent the checkboxes have been changed 787f688be2eSNicolas Bonnefon // (for maintaining default config) 788f688be2eSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ), 789f688be2eSNicolas Bonnefon this, SIGNAL( searchRefreshChanged( int ) ) ); 790f688be2eSNicolas Bonnefon connect( ignoreCaseCheck, SIGNAL( stateChanged( int ) ), 791f688be2eSNicolas Bonnefon this, SIGNAL( ignoreCaseChanged( int ) ) ); 792*7552c461SNicolas Bonnefon 793*7552c461SNicolas Bonnefon // Switch between views 794*7552c461SNicolas Bonnefon connect( logMainView, SIGNAL( exitView() ), 795*7552c461SNicolas Bonnefon filteredView, SLOT( setFocus() ) ); 796*7552c461SNicolas Bonnefon connect( filteredView, SIGNAL( exitView() ), 797*7552c461SNicolas Bonnefon logMainView, SLOT( setFocus() ) ); 798bb02e0acSNicolas Bonnefon } 799bb02e0acSNicolas Bonnefon 800bb02e0acSNicolas Bonnefon // Create a new search using the text passed, replace the currently 801bb02e0acSNicolas Bonnefon // used one and destroy the old one. 802bb02e0acSNicolas Bonnefon void CrawlerWidget::replaceCurrentSearch( const QString& searchText ) 803bb02e0acSNicolas Bonnefon { 804bb02e0acSNicolas Bonnefon // Interrupt the search if it's ongoing 805bb02e0acSNicolas Bonnefon logFilteredData_->interruptSearch(); 806bb02e0acSNicolas Bonnefon 807bb02e0acSNicolas Bonnefon // We have to wait for the last search update (100%) 808bb02e0acSNicolas Bonnefon // before clearing/restarting to avoid having remaining results. 809bb02e0acSNicolas Bonnefon 810bb02e0acSNicolas Bonnefon // FIXME: this is a bit of a hack, we call processEvents 811bb02e0acSNicolas Bonnefon // for Qt to empty its event queue, including (hopefully) 812bb02e0acSNicolas Bonnefon // the search update event sent by logFilteredData_. It saves 813bb02e0acSNicolas Bonnefon // us the overhead of having proper sync. 814bb02e0acSNicolas Bonnefon QApplication::processEvents( QEventLoop::ExcludeUserInputEvents ); 815bb02e0acSNicolas Bonnefon 8168ea5bc4cSNicolas Bonnefon nbMatches_ = 0; 8178ea5bc4cSNicolas Bonnefon 8188ea5bc4cSNicolas Bonnefon // Clear and recompute the content of the filtered window. 8198ea5bc4cSNicolas Bonnefon logFilteredData_->clearSearch(); 8208ea5bc4cSNicolas Bonnefon filteredView->updateData(); 8218ea5bc4cSNicolas Bonnefon 8228ea5bc4cSNicolas Bonnefon // Update the match overview 8238ea5bc4cSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 8248ea5bc4cSNicolas Bonnefon 825bb02e0acSNicolas Bonnefon if ( !searchText.isEmpty() ) { 826bb02e0acSNicolas Bonnefon // Determine the type of regexp depending on the config 827bb02e0acSNicolas Bonnefon QRegExp::PatternSyntax syntax; 82811582726SNicolas Bonnefon static std::shared_ptr<Configuration> config = 82911582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 83011582726SNicolas Bonnefon switch ( config->mainRegexpType() ) { 831bb02e0acSNicolas Bonnefon case Wildcard: 832bb02e0acSNicolas Bonnefon syntax = QRegExp::Wildcard; 833bb02e0acSNicolas Bonnefon break; 834bb02e0acSNicolas Bonnefon case FixedString: 835bb02e0acSNicolas Bonnefon syntax = QRegExp::FixedString; 836bb02e0acSNicolas Bonnefon break; 837bb02e0acSNicolas Bonnefon default: 838bb02e0acSNicolas Bonnefon syntax = QRegExp::RegExp2; 839bb02e0acSNicolas Bonnefon break; 840bb02e0acSNicolas Bonnefon } 841bb02e0acSNicolas Bonnefon 842bb02e0acSNicolas Bonnefon // Set the pattern case insensitive if needed 843bb02e0acSNicolas Bonnefon Qt::CaseSensitivity case_sensitivity = Qt::CaseSensitive; 844bb02e0acSNicolas Bonnefon if ( ignoreCaseCheck->checkState() == Qt::Checked ) 845bb02e0acSNicolas Bonnefon case_sensitivity = Qt::CaseInsensitive; 846bb02e0acSNicolas Bonnefon 847bb02e0acSNicolas Bonnefon // Constructs the regexp 848bb02e0acSNicolas Bonnefon QRegExp regexp( searchText, case_sensitivity, syntax ); 849bb02e0acSNicolas Bonnefon 850bb02e0acSNicolas Bonnefon if ( regexp.isValid() ) { 851bb02e0acSNicolas Bonnefon // Activate the stop button 852bb02e0acSNicolas Bonnefon stopButton->setEnabled( true ); 853bb02e0acSNicolas Bonnefon // Start a new asynchronous search 854bb02e0acSNicolas Bonnefon logFilteredData_->runSearch( regexp ); 855bb02e0acSNicolas Bonnefon // Accept auto-refresh of the search 856bb02e0acSNicolas Bonnefon searchState_.startSearch(); 857bb02e0acSNicolas Bonnefon } 858bb02e0acSNicolas Bonnefon else { 859bb02e0acSNicolas Bonnefon // The regexp is wrong 860bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 861bb02e0acSNicolas Bonnefon filteredView->updateData(); 862bb02e0acSNicolas Bonnefon searchState_.resetState(); 863bb02e0acSNicolas Bonnefon 864bb02e0acSNicolas Bonnefon // Inform the user 865bb02e0acSNicolas Bonnefon QString errorMessage = tr("Error in expression: "); 866bb02e0acSNicolas Bonnefon errorMessage += regexp.errorString(); 867bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( errorPalette ); 868bb02e0acSNicolas Bonnefon searchInfoLine->setText( errorMessage ); 869bb02e0acSNicolas Bonnefon } 870bb02e0acSNicolas Bonnefon } 871bb02e0acSNicolas Bonnefon else { 872bb02e0acSNicolas Bonnefon searchState_.resetState(); 873bb02e0acSNicolas Bonnefon printSearchInfoMessage(); 874bb02e0acSNicolas Bonnefon } 875bb02e0acSNicolas Bonnefon } 876bb02e0acSNicolas Bonnefon 877bb02e0acSNicolas Bonnefon // Updates the content of the drop down list for the saved searches, 878bb02e0acSNicolas Bonnefon // called when the SavedSearch has been changed. 879bb02e0acSNicolas Bonnefon void CrawlerWidget::updateSearchCombo() 880bb02e0acSNicolas Bonnefon { 881bb02e0acSNicolas Bonnefon const QString text = searchLineEdit->lineEdit()->text(); 882bb02e0acSNicolas Bonnefon searchLineEdit->clear(); 8831b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() ); 884bb02e0acSNicolas Bonnefon // In case we had something that wasn't added to the list (blank...): 885bb02e0acSNicolas Bonnefon searchLineEdit->lineEdit()->setText( text ); 886bb02e0acSNicolas Bonnefon } 887bb02e0acSNicolas Bonnefon 888bb02e0acSNicolas Bonnefon // Print the search info message. 889bb02e0acSNicolas Bonnefon void CrawlerWidget::printSearchInfoMessage( int nbMatches ) 890bb02e0acSNicolas Bonnefon { 891bb02e0acSNicolas Bonnefon QString text; 892bb02e0acSNicolas Bonnefon 893bb02e0acSNicolas Bonnefon switch ( searchState_.getState() ) { 894bb02e0acSNicolas Bonnefon case SearchState::NoSearch: 895bb02e0acSNicolas Bonnefon // Blank text is fine 896bb02e0acSNicolas Bonnefon break; 897bb02e0acSNicolas Bonnefon case SearchState::Static: 898bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found.").arg( nbMatches ) 899bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 900bb02e0acSNicolas Bonnefon break; 901bb02e0acSNicolas Bonnefon case SearchState::Autorefreshing: 902bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found. Search is auto-refreshing...").arg( nbMatches ) 903bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 904bb02e0acSNicolas Bonnefon break; 905bb02e0acSNicolas Bonnefon case SearchState::FileTruncated: 90659d4e393SNicolas Bonnefon case SearchState::TruncatedAutorefreshing: 907bb02e0acSNicolas Bonnefon text = tr("File truncated on disk, previous search results are not valid anymore."); 908bb02e0acSNicolas Bonnefon break; 909bb02e0acSNicolas Bonnefon } 910bb02e0acSNicolas Bonnefon 911bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( searchInfoLineDefaultPalette ); 912bb02e0acSNicolas Bonnefon searchInfoLine->setText( text ); 913bb02e0acSNicolas Bonnefon } 914bb02e0acSNicolas Bonnefon 91545ef183cSNicolas Bonnefon // Change the data status and, if needed, advise upstream. 91645ef183cSNicolas Bonnefon void CrawlerWidget::changeDataStatus( DataStatus status ) 91745ef183cSNicolas Bonnefon { 9187999f43eSNicolas Bonnefon if ( ( status != dataStatus_ ) 9197999f43eSNicolas Bonnefon && (! ( dataStatus_ == DataStatus::NEW_FILTERED_DATA 9207999f43eSNicolas Bonnefon && status == DataStatus::NEW_DATA ) ) ) { 92145ef183cSNicolas Bonnefon dataStatus_ = status; 92245ef183cSNicolas Bonnefon emit dataStatusChanged( dataStatus_ ); 92345ef183cSNicolas Bonnefon } 92445ef183cSNicolas Bonnefon } 92545ef183cSNicolas Bonnefon 9265fa25391SNicolas Bonnefon // Determine the right encoding and set the views. 9275fa25391SNicolas Bonnefon void CrawlerWidget::updateEncoding() 9285fa25391SNicolas Bonnefon { 9295fa25391SNicolas Bonnefon static const char* latin1_encoding = "iso-8859-1"; 9305fa25391SNicolas Bonnefon static const char* utf8_encoding = "utf-8"; 9315fa25391SNicolas Bonnefon 9325fa25391SNicolas Bonnefon const char* encoding; 9335fa25391SNicolas Bonnefon 9345fa25391SNicolas Bonnefon switch ( encodingSetting_ ) { 9355fa25391SNicolas Bonnefon case ENCODING_AUTO: 9365fa25391SNicolas Bonnefon switch ( logData_->getDetectedEncoding() ) { 9375fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::ASCII7: 9385fa25391SNicolas Bonnefon encoding = latin1_encoding; 9395fa25391SNicolas Bonnefon encoding_text_ = tr( "US-ASCII" ); 9405fa25391SNicolas Bonnefon break; 9415fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::ASCII8: 9425fa25391SNicolas Bonnefon encoding = latin1_encoding; 9435fa25391SNicolas Bonnefon encoding_text_ = tr( "ISO-8859-1" ); 9445fa25391SNicolas Bonnefon break; 9455fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::UTF8: 9465fa25391SNicolas Bonnefon encoding = utf8_encoding; 9475fa25391SNicolas Bonnefon encoding_text_ = tr( "UTF-8" ); 9485fa25391SNicolas Bonnefon break; 9495fa25391SNicolas Bonnefon } 9505fa25391SNicolas Bonnefon break; 9515fa25391SNicolas Bonnefon case ENCODING_UTF8: 9525fa25391SNicolas Bonnefon encoding = utf8_encoding; 9535fa25391SNicolas Bonnefon encoding_text_ = tr( "Displayed as UTF-8" ); 9545fa25391SNicolas Bonnefon break; 9555fa25391SNicolas Bonnefon case ENCODING_ISO_8859_1: 9565fa25391SNicolas Bonnefon default: 9575fa25391SNicolas Bonnefon encoding = latin1_encoding; 9585fa25391SNicolas Bonnefon encoding_text_ = tr( "Displayed as ISO-8859-1" ); 9595fa25391SNicolas Bonnefon break; 9605fa25391SNicolas Bonnefon } 9615fa25391SNicolas Bonnefon 9625fa25391SNicolas Bonnefon logData_->setDisplayEncoding( encoding ); 9635fa25391SNicolas Bonnefon logMainView->forceRefresh(); 9645fa25391SNicolas Bonnefon logFilteredData_->setDisplayEncoding( encoding ); 9655fa25391SNicolas Bonnefon filteredView->forceRefresh(); 9665fa25391SNicolas Bonnefon } 9675fa25391SNicolas Bonnefon 968bb02e0acSNicolas Bonnefon // 969bb02e0acSNicolas Bonnefon // SearchState implementation 970bb02e0acSNicolas Bonnefon // 971bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::resetState() 972bb02e0acSNicolas Bonnefon { 973bb02e0acSNicolas Bonnefon state_ = NoSearch; 974bb02e0acSNicolas Bonnefon } 975bb02e0acSNicolas Bonnefon 976bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::setAutorefresh( bool refresh ) 977bb02e0acSNicolas Bonnefon { 978bb02e0acSNicolas Bonnefon autoRefreshRequested_ = refresh; 979bb02e0acSNicolas Bonnefon 980bb02e0acSNicolas Bonnefon if ( refresh ) { 981bb02e0acSNicolas Bonnefon if ( state_ == Static ) 982bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 98359d4e393SNicolas Bonnefon /* 98459d4e393SNicolas Bonnefon else if ( state_ == FileTruncated ) 98559d4e393SNicolas Bonnefon state_ = TruncatedAutorefreshing; 98659d4e393SNicolas Bonnefon */ 987bb02e0acSNicolas Bonnefon } 988bb02e0acSNicolas Bonnefon else { 989bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 990bb02e0acSNicolas Bonnefon state_ = Static; 99159d4e393SNicolas Bonnefon else if ( state_ == TruncatedAutorefreshing ) 99259d4e393SNicolas Bonnefon state_ = FileTruncated; 993bb02e0acSNicolas Bonnefon } 994bb02e0acSNicolas Bonnefon } 995bb02e0acSNicolas Bonnefon 996bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::truncateFile() 997bb02e0acSNicolas Bonnefon { 99859d4e393SNicolas Bonnefon if ( state_ == Autorefreshing || state_ == TruncatedAutorefreshing ) { 99959d4e393SNicolas Bonnefon state_ = TruncatedAutorefreshing; 100059d4e393SNicolas Bonnefon } 100159d4e393SNicolas Bonnefon else { 1002bb02e0acSNicolas Bonnefon state_ = FileTruncated; 1003bb02e0acSNicolas Bonnefon } 100459d4e393SNicolas Bonnefon } 1005bb02e0acSNicolas Bonnefon 1006bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::changeExpression() 1007bb02e0acSNicolas Bonnefon { 1008bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 1009bb02e0acSNicolas Bonnefon state_ = Static; 1010bb02e0acSNicolas Bonnefon } 1011bb02e0acSNicolas Bonnefon 1012bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::stopSearch() 1013bb02e0acSNicolas Bonnefon { 1014bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 1015bb02e0acSNicolas Bonnefon state_ = Static; 1016bb02e0acSNicolas Bonnefon } 1017bb02e0acSNicolas Bonnefon 1018bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::startSearch() 1019bb02e0acSNicolas Bonnefon { 1020bb02e0acSNicolas Bonnefon if ( autoRefreshRequested_ ) 1021bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 1022bb02e0acSNicolas Bonnefon else 1023bb02e0acSNicolas Bonnefon state_ = Static; 1024bb02e0acSNicolas Bonnefon } 1025a44d09bcSNicolas Bonnefon 1026a44d09bcSNicolas Bonnefon /* 1027a44d09bcSNicolas Bonnefon * CrawlerWidgetContext 1028a44d09bcSNicolas Bonnefon */ 1029a44d09bcSNicolas Bonnefon CrawlerWidgetContext::CrawlerWidgetContext( const char* string ) 1030a44d09bcSNicolas Bonnefon { 1031a44d09bcSNicolas Bonnefon QRegExp regex = QRegExp( "S(\\d+):(\\d+)" ); 1032a44d09bcSNicolas Bonnefon 1033f688be2eSNicolas Bonnefon if ( regex.indexIn( string ) > -1 ) { 1034a44d09bcSNicolas Bonnefon sizes_ = { regex.cap(1).toInt(), regex.cap(2).toInt() }; 1035a44d09bcSNicolas Bonnefon LOG(logDEBUG) << "sizes_: " << sizes_[0] << " " << sizes_[1]; 1036a44d09bcSNicolas Bonnefon } 1037f688be2eSNicolas Bonnefon else { 1038f688be2eSNicolas Bonnefon LOG(logWARNING) << "Unrecognised view size: " << string; 1039a44d09bcSNicolas Bonnefon 1040a44d09bcSNicolas Bonnefon // Default values; 1041a44d09bcSNicolas Bonnefon sizes_ = { 100, 400 }; 1042a44d09bcSNicolas Bonnefon } 1043f688be2eSNicolas Bonnefon 1044f688be2eSNicolas Bonnefon QRegExp case_refresh_regex = QRegExp( "IC(\\d+):AR(\\d+)" ); 1045f688be2eSNicolas Bonnefon 1046f688be2eSNicolas Bonnefon if ( case_refresh_regex.indexIn( string ) > -1 ) { 1047f688be2eSNicolas Bonnefon ignore_case_ = ( case_refresh_regex.cap(1).toInt() == 1 ); 1048f688be2eSNicolas Bonnefon auto_refresh_ = ( case_refresh_regex.cap(2).toInt() == 1 ); 1049f688be2eSNicolas Bonnefon 1050f688be2eSNicolas Bonnefon LOG(logDEBUG) << "ignore_case_: " << ignore_case_ << " auto_refresh_: " 1051f688be2eSNicolas Bonnefon << auto_refresh_; 1052f688be2eSNicolas Bonnefon } 1053f688be2eSNicolas Bonnefon else { 1054f688be2eSNicolas Bonnefon LOG(logWARNING) << "Unrecognised case/refresh: " << string; 1055f688be2eSNicolas Bonnefon ignore_case_ = false; 1056f688be2eSNicolas Bonnefon auto_refresh_ = false; 1057f688be2eSNicolas Bonnefon } 1058a44d09bcSNicolas Bonnefon } 1059a44d09bcSNicolas Bonnefon 1060a44d09bcSNicolas Bonnefon std::string CrawlerWidgetContext::toString() const 1061a44d09bcSNicolas Bonnefon { 1062a44d09bcSNicolas Bonnefon char string[160]; 1063a44d09bcSNicolas Bonnefon 1064f688be2eSNicolas Bonnefon snprintf( string, sizeof string, "S%d:%d:IC%d:AR%d", 1065f688be2eSNicolas Bonnefon sizes_[0], sizes_[1], 1066f688be2eSNicolas Bonnefon ignore_case_, auto_refresh_ ); 1067a44d09bcSNicolas Bonnefon 1068f688be2eSNicolas Bonnefon return { string }; 1069a44d09bcSNicolas Bonnefon } 1070