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; 9745ef183cSNicolas Bonnefon dataStatus_ = DataStatus::OLD_DATA; 9860864ff5SNicolas Bonnefon 999cacd6a9SNicolas Bonnefon currentLineNumber_ = 0; 100039481acSNicolas Bonnefon } 101039481acSNicolas Bonnefon 102039481acSNicolas Bonnefon // The top line is first one on the main display 103039481acSNicolas Bonnefon int CrawlerWidget::getTopLine() const 104039481acSNicolas Bonnefon { 105039481acSNicolas Bonnefon return logMainView->getTopLine(); 106039481acSNicolas Bonnefon } 107039481acSNicolas Bonnefon 108039481acSNicolas Bonnefon QString CrawlerWidget::getSelectedText() const 109039481acSNicolas Bonnefon { 110039481acSNicolas Bonnefon if ( filteredView->hasFocus() ) 111039481acSNicolas Bonnefon return filteredView->getSelection(); 112039481acSNicolas Bonnefon else 113039481acSNicolas Bonnefon return logMainView->getSelection(); 114039481acSNicolas Bonnefon } 115039481acSNicolas Bonnefon 116039481acSNicolas Bonnefon void CrawlerWidget::selectAll() 117039481acSNicolas Bonnefon { 118039481acSNicolas Bonnefon activeView()->selectAll(); 119039481acSNicolas Bonnefon } 120039481acSNicolas Bonnefon 121039481acSNicolas Bonnefon // Return a pointer to the view in which we should do the QuickFind 122b423cd88SNicolas Bonnefon SearchableWidgetInterface* CrawlerWidget::doGetActiveSearchable() const 123039481acSNicolas Bonnefon { 124b423cd88SNicolas Bonnefon return activeView(); 125b423cd88SNicolas Bonnefon } 126039481acSNicolas Bonnefon 127b423cd88SNicolas Bonnefon // Return all the searchable widgets (views) 128b423cd88SNicolas Bonnefon std::vector<QObject*> CrawlerWidget::doGetAllSearchables() const 129b423cd88SNicolas Bonnefon { 130b423cd88SNicolas Bonnefon std::vector<QObject*> searchables = 131b423cd88SNicolas Bonnefon { logMainView, filteredView }; 132039481acSNicolas Bonnefon 133b423cd88SNicolas Bonnefon return searchables; 134039481acSNicolas Bonnefon } 135039481acSNicolas Bonnefon 1369cacd6a9SNicolas Bonnefon // Update the state of the parent 1379cacd6a9SNicolas Bonnefon void CrawlerWidget::doSendAllStateSignals() 1389cacd6a9SNicolas Bonnefon { 1399cacd6a9SNicolas Bonnefon emit updateLineNumber( currentLineNumber_ ); 14060864ff5SNicolas Bonnefon if ( !loadingInProgress_ ) 141812146a8SNicolas Bonnefon emit loadingFinished( LoadingStatus::Successful ); 1429cacd6a9SNicolas Bonnefon } 1439cacd6a9SNicolas Bonnefon 1447847299cSNicolas Bonnefon // 1457847299cSNicolas Bonnefon // Public slots 1467847299cSNicolas Bonnefon // 1477847299cSNicolas Bonnefon 1487847299cSNicolas Bonnefon void CrawlerWidget::stopLoading() 1497847299cSNicolas Bonnefon { 1507847299cSNicolas Bonnefon logFilteredData_->interruptSearch(); 1517847299cSNicolas Bonnefon logData_->interruptLoading(); 1527847299cSNicolas Bonnefon } 1537847299cSNicolas Bonnefon 15432e44cfdSNicolas Bonnefon void CrawlerWidget::reload() 15532e44cfdSNicolas Bonnefon { 15632e44cfdSNicolas Bonnefon searchState_.resetState(); 15732e44cfdSNicolas Bonnefon logFilteredData_->clearSearch(); 15832e44cfdSNicolas Bonnefon filteredView->updateData(); 15932e44cfdSNicolas Bonnefon printSearchInfoMessage(); 16032e44cfdSNicolas Bonnefon 16132e44cfdSNicolas Bonnefon logData_->reload(); 16245ef183cSNicolas Bonnefon 16345ef183cSNicolas Bonnefon // A reload is considered as a first load, 16445ef183cSNicolas Bonnefon // this is to prevent the "new data" icon to be triggered. 16545ef183cSNicolas Bonnefon firstLoadDone_ = false; 16632e44cfdSNicolas Bonnefon } 16732e44cfdSNicolas Bonnefon 168039481acSNicolas Bonnefon // 169039481acSNicolas Bonnefon // Protected functions 170039481acSNicolas Bonnefon // 171039481acSNicolas Bonnefon void CrawlerWidget::doSetData( 172039481acSNicolas Bonnefon std::shared_ptr<LogData> log_data, 173039481acSNicolas Bonnefon std::shared_ptr<LogFilteredData> filtered_data ) 174039481acSNicolas Bonnefon { 175039481acSNicolas Bonnefon logData_ = log_data.get(); 176039481acSNicolas Bonnefon logFilteredData_ = filtered_data.get(); 1771b5e406eSNicolas Bonnefon } 178039481acSNicolas Bonnefon 179b423cd88SNicolas Bonnefon void CrawlerWidget::doSetQuickFindPattern( 180b423cd88SNicolas Bonnefon std::shared_ptr<QuickFindPattern> qfp ) 181b423cd88SNicolas Bonnefon { 182b423cd88SNicolas Bonnefon quickFindPattern_ = qfp; 183b423cd88SNicolas Bonnefon } 184b423cd88SNicolas Bonnefon 1851b5e406eSNicolas Bonnefon void CrawlerWidget::doSetSavedSearches( 1861b5e406eSNicolas Bonnefon std::shared_ptr<SavedSearches> saved_searches ) 1871b5e406eSNicolas Bonnefon { 1881b5e406eSNicolas Bonnefon savedSearches_ = saved_searches; 1891b5e406eSNicolas Bonnefon 1901b5e406eSNicolas Bonnefon // We do setup now, assuming doSetData has been called before 1911b5e406eSNicolas Bonnefon // us, that's not great really... 192039481acSNicolas Bonnefon setup(); 193039481acSNicolas Bonnefon } 194039481acSNicolas Bonnefon 195a44d09bcSNicolas Bonnefon void CrawlerWidget::doSetViewContext( 196a44d09bcSNicolas Bonnefon const char* view_context ) 197a44d09bcSNicolas Bonnefon { 198a44d09bcSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::doSetViewContext: " << view_context; 199a44d09bcSNicolas Bonnefon 200a44d09bcSNicolas Bonnefon CrawlerWidgetContext context = { view_context }; 201a44d09bcSNicolas Bonnefon 202a44d09bcSNicolas Bonnefon setSizes( context.sizes() ); 203f688be2eSNicolas Bonnefon ignoreCaseCheck->setCheckState( context.ignoreCase() ? Qt::Checked : Qt::Unchecked ); 204240a4b5eSNicolas Bonnefon 205240a4b5eSNicolas Bonnefon auto auto_refresh_check_state = context.autoRefresh() ? Qt::Checked : Qt::Unchecked; 206240a4b5eSNicolas Bonnefon searchRefreshCheck->setCheckState( auto_refresh_check_state ); 207240a4b5eSNicolas Bonnefon // Manually call the handler as it is not called when changing the state programmatically 208240a4b5eSNicolas Bonnefon searchRefreshChangedHandler( auto_refresh_check_state ); 209a44d09bcSNicolas Bonnefon } 210a44d09bcSNicolas Bonnefon 211a44d09bcSNicolas Bonnefon std::shared_ptr<const ViewContextInterface> 212a44d09bcSNicolas Bonnefon CrawlerWidget::doGetViewContext() const 213a44d09bcSNicolas Bonnefon { 214f688be2eSNicolas Bonnefon auto context = std::make_shared<const CrawlerWidgetContext>( 215f688be2eSNicolas Bonnefon sizes(), 216f688be2eSNicolas Bonnefon ( ignoreCaseCheck->checkState() == Qt::Checked ), 217f688be2eSNicolas Bonnefon ( searchRefreshCheck->checkState() == Qt::Checked ) ); 218a44d09bcSNicolas Bonnefon 219a44d09bcSNicolas Bonnefon return static_cast<std::shared_ptr<const ViewContextInterface>>( context ); 220a44d09bcSNicolas Bonnefon } 221a44d09bcSNicolas Bonnefon 222039481acSNicolas Bonnefon // 223039481acSNicolas Bonnefon // Slots 224039481acSNicolas Bonnefon // 225039481acSNicolas Bonnefon 226039481acSNicolas Bonnefon void CrawlerWidget::startNewSearch() 227039481acSNicolas Bonnefon { 228039481acSNicolas Bonnefon // Record the search line in the recent list 229039481acSNicolas Bonnefon // (reload the list first in case another glogg changed it) 230039481acSNicolas Bonnefon GetPersistentInfo().retrieve( "savedSearches" ); 2311b5e406eSNicolas Bonnefon savedSearches_->addRecent( searchLineEdit->currentText() ); 232039481acSNicolas Bonnefon GetPersistentInfo().save( "savedSearches" ); 233039481acSNicolas Bonnefon 234039481acSNicolas Bonnefon // Update the SearchLine (history) 235039481acSNicolas Bonnefon updateSearchCombo(); 236039481acSNicolas Bonnefon // Call the private function to do the search 237039481acSNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() ); 238039481acSNicolas Bonnefon } 239039481acSNicolas Bonnefon 240039481acSNicolas Bonnefon void CrawlerWidget::stopSearch() 241039481acSNicolas Bonnefon { 242039481acSNicolas Bonnefon logFilteredData_->interruptSearch(); 243039481acSNicolas Bonnefon searchState_.stopSearch(); 244039481acSNicolas Bonnefon printSearchInfoMessage(); 245039481acSNicolas Bonnefon } 246039481acSNicolas Bonnefon 247039481acSNicolas Bonnefon // When receiving the 'newDataAvailable' signal from LogFilteredData 248039481acSNicolas Bonnefon void CrawlerWidget::updateFilteredView( int nbMatches, int progress ) 249039481acSNicolas Bonnefon { 250039481acSNicolas Bonnefon LOG(logDEBUG) << "updateFilteredView received."; 251039481acSNicolas Bonnefon 252039481acSNicolas Bonnefon if ( progress == 100 ) { 253039481acSNicolas Bonnefon // Searching done 254039481acSNicolas Bonnefon printSearchInfoMessage( nbMatches ); 255039481acSNicolas Bonnefon searchInfoLine->hideGauge(); 256039481acSNicolas Bonnefon // De-activate the stop button 257039481acSNicolas Bonnefon stopButton->setEnabled( false ); 258039481acSNicolas Bonnefon } 259039481acSNicolas Bonnefon else { 260039481acSNicolas Bonnefon // Search in progress 261039481acSNicolas Bonnefon // We ignore 0% and 100% to avoid a flash when the search is very short 262039481acSNicolas Bonnefon if ( progress > 0 ) { 263039481acSNicolas Bonnefon searchInfoLine->setText( 264039481acSNicolas Bonnefon tr("Search in progress (%1 %)... %2 match%3 found so far.") 265039481acSNicolas Bonnefon .arg( progress ) 266039481acSNicolas Bonnefon .arg( nbMatches ) 267039481acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ) ); 268039481acSNicolas Bonnefon searchInfoLine->displayGauge( progress ); 269039481acSNicolas Bonnefon } 270039481acSNicolas Bonnefon } 271039481acSNicolas Bonnefon 272039481acSNicolas Bonnefon // Recompute the content of the filtered window. 273039481acSNicolas Bonnefon filteredView->updateData(); 274039481acSNicolas Bonnefon 275039481acSNicolas Bonnefon // Update the match overview 2760f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 277039481acSNicolas Bonnefon 278039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 279039481acSNicolas Bonnefon update(); 280039481acSNicolas Bonnefon } 281039481acSNicolas Bonnefon 282039481acSNicolas Bonnefon void CrawlerWidget::jumpToMatchingLine(int filteredLineNb) 283039481acSNicolas Bonnefon { 284039481acSNicolas Bonnefon int mainViewLine = logFilteredData_->getMatchingLineNumber(filteredLineNb); 285039481acSNicolas Bonnefon logMainView->selectAndDisplayLine(mainViewLine); // FIXME: should be done with a signal. 286039481acSNicolas Bonnefon } 287039481acSNicolas Bonnefon 2889cacd6a9SNicolas Bonnefon void CrawlerWidget::updateLineNumberHandler( int line ) 2899cacd6a9SNicolas Bonnefon { 2909cacd6a9SNicolas Bonnefon currentLineNumber_ = line; 2919cacd6a9SNicolas Bonnefon emit updateLineNumber( line ); 2929cacd6a9SNicolas Bonnefon } 2939cacd6a9SNicolas Bonnefon 294039481acSNicolas Bonnefon void CrawlerWidget::markLineFromMain( qint64 line ) 295039481acSNicolas Bonnefon { 296*2493b508SNicolas Bonnefon if ( line < logData_->getNbLine() ) { 297039481acSNicolas Bonnefon if ( logFilteredData_->isLineMarked( line ) ) 298039481acSNicolas Bonnefon logFilteredData_->deleteMark( line ); 299039481acSNicolas Bonnefon else 300039481acSNicolas Bonnefon logFilteredData_->addMark( line ); 301039481acSNicolas Bonnefon 302039481acSNicolas Bonnefon // Recompute the content of the filtered window. 303039481acSNicolas Bonnefon filteredView->updateData(); 304039481acSNicolas Bonnefon 305039481acSNicolas Bonnefon // Update the match overview 3060f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 307039481acSNicolas Bonnefon 308039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 309039481acSNicolas Bonnefon update(); 310039481acSNicolas Bonnefon } 311*2493b508SNicolas Bonnefon } 312039481acSNicolas Bonnefon 313039481acSNicolas Bonnefon void CrawlerWidget::markLineFromFiltered( qint64 line ) 314039481acSNicolas Bonnefon { 315*2493b508SNicolas Bonnefon if ( line < logFilteredData_->getNbLine() ) { 316039481acSNicolas Bonnefon qint64 line_in_file = logFilteredData_->getMatchingLineNumber( line ); 317039481acSNicolas Bonnefon if ( logFilteredData_->filteredLineTypeByIndex( line ) 318039481acSNicolas Bonnefon == LogFilteredData::Mark ) 319039481acSNicolas Bonnefon logFilteredData_->deleteMark( line_in_file ); 320039481acSNicolas Bonnefon else 321039481acSNicolas Bonnefon logFilteredData_->addMark( line_in_file ); 322039481acSNicolas Bonnefon 323039481acSNicolas Bonnefon // Recompute the content of the filtered window. 324039481acSNicolas Bonnefon filteredView->updateData(); 325039481acSNicolas Bonnefon 326039481acSNicolas Bonnefon // Update the match overview 3270f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 328039481acSNicolas Bonnefon 329039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 330039481acSNicolas Bonnefon update(); 331039481acSNicolas Bonnefon } 332*2493b508SNicolas Bonnefon } 333039481acSNicolas Bonnefon 334039481acSNicolas Bonnefon void CrawlerWidget::applyConfiguration() 335039481acSNicolas Bonnefon { 33611582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 33711582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 33811582726SNicolas Bonnefon QFont font = config->mainFont(); 339039481acSNicolas Bonnefon 340039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::applyConfiguration"; 341039481acSNicolas Bonnefon 342039481acSNicolas Bonnefon // Whatever font we use, we should NOT use kerning 343039481acSNicolas Bonnefon font.setKerning( false ); 344039481acSNicolas Bonnefon font.setFixedPitch( true ); 345039481acSNicolas Bonnefon #if QT_VERSION > 0x040700 346039481acSNicolas Bonnefon // Necessary on systems doing subpixel positionning (e.g. Ubuntu 12.04) 347039481acSNicolas Bonnefon font.setStyleStrategy( QFont::ForceIntegerMetrics ); 348039481acSNicolas Bonnefon #endif 349039481acSNicolas Bonnefon logMainView->setFont(font); 350039481acSNicolas Bonnefon filteredView->setFont(font); 351039481acSNicolas Bonnefon 35211582726SNicolas Bonnefon logMainView->setLineNumbersVisible( config->mainLineNumbersVisible() ); 35311582726SNicolas Bonnefon filteredView->setLineNumbersVisible( config->filteredLineNumbersVisible() ); 354039481acSNicolas Bonnefon 35511582726SNicolas Bonnefon overview_.setVisible( config->isOverviewVisible() ); 356039481acSNicolas Bonnefon logMainView->refreshOverview(); 357039481acSNicolas Bonnefon 358039481acSNicolas Bonnefon logMainView->updateDisplaySize(); 359039481acSNicolas Bonnefon logMainView->update(); 360039481acSNicolas Bonnefon filteredView->updateDisplaySize(); 361039481acSNicolas Bonnefon filteredView->update(); 362039481acSNicolas Bonnefon 36380bca0a3SNicolas Bonnefon // Polling interval 36480bca0a3SNicolas Bonnefon logData_->setPollingInterval( 36580bca0a3SNicolas Bonnefon config->pollingEnabled() ? config->pollIntervalMs() : 0 ); 36680bca0a3SNicolas Bonnefon 367039481acSNicolas Bonnefon // Update the SearchLine (history) 368039481acSNicolas Bonnefon updateSearchCombo(); 369039481acSNicolas Bonnefon } 370039481acSNicolas Bonnefon 3718570d8d2SNicolas Bonnefon void CrawlerWidget::enteringQuickFind() 3728570d8d2SNicolas Bonnefon { 3738570d8d2SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::enteringQuickFind"; 3748570d8d2SNicolas Bonnefon 3758570d8d2SNicolas Bonnefon // Remember who had the focus (only if it is one of our views) 3768570d8d2SNicolas Bonnefon QWidget* focus_widget = QApplication::focusWidget(); 3778570d8d2SNicolas Bonnefon 3788570d8d2SNicolas Bonnefon if ( ( focus_widget == logMainView ) || ( focus_widget == filteredView ) ) 3798570d8d2SNicolas Bonnefon qfSavedFocus_ = focus_widget; 3808570d8d2SNicolas Bonnefon else 3818570d8d2SNicolas Bonnefon qfSavedFocus_ = nullptr; 3828570d8d2SNicolas Bonnefon } 3838570d8d2SNicolas Bonnefon 3848570d8d2SNicolas Bonnefon void CrawlerWidget::exitingQuickFind() 3858570d8d2SNicolas Bonnefon { 3868570d8d2SNicolas Bonnefon // Restore the focus once the QFBar has been hidden 3878570d8d2SNicolas Bonnefon if ( qfSavedFocus_ ) 3888570d8d2SNicolas Bonnefon qfSavedFocus_->setFocus(); 3898570d8d2SNicolas Bonnefon } 3908570d8d2SNicolas Bonnefon 391812146a8SNicolas Bonnefon void CrawlerWidget::loadingFinishedHandler( LoadingStatus status ) 392039481acSNicolas Bonnefon { 39360864ff5SNicolas Bonnefon loadingInProgress_ = false; 39460864ff5SNicolas Bonnefon 395039481acSNicolas Bonnefon // We need to refresh the main window because the view lines on the 396039481acSNicolas Bonnefon // overview have probably changed. 3970f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 398039481acSNicolas Bonnefon 399039481acSNicolas Bonnefon // FIXME, handle topLine 400039481acSNicolas Bonnefon // logMainView->updateData( logData_, topLine ); 401039481acSNicolas Bonnefon logMainView->updateData(); 402039481acSNicolas Bonnefon 403039481acSNicolas Bonnefon // Shall we Forbid starting a search when loading in progress? 404039481acSNicolas Bonnefon // searchButton->setEnabled( false ); 405039481acSNicolas Bonnefon 406039481acSNicolas Bonnefon // searchButton->setEnabled( true ); 407039481acSNicolas Bonnefon 408039481acSNicolas Bonnefon // See if we need to auto-refresh the search 409039481acSNicolas Bonnefon if ( searchState_.isAutorefreshAllowed() ) { 41059d4e393SNicolas Bonnefon if ( searchState_.isFileTruncated() ) 41159d4e393SNicolas Bonnefon // We need to restart the search 41259d4e393SNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() ); 41359d4e393SNicolas Bonnefon else 414039481acSNicolas Bonnefon logFilteredData_->updateSearch(); 415039481acSNicolas Bonnefon } 416039481acSNicolas Bonnefon 417812146a8SNicolas Bonnefon emit loadingFinished( status ); 41845ef183cSNicolas Bonnefon 41945ef183cSNicolas Bonnefon // Also change the data available icon 42045ef183cSNicolas Bonnefon if ( firstLoadDone_ ) 42145ef183cSNicolas Bonnefon changeDataStatus( DataStatus::NEW_DATA ); 42245ef183cSNicolas Bonnefon else 42345ef183cSNicolas Bonnefon firstLoadDone_ = true; 424039481acSNicolas Bonnefon } 425039481acSNicolas Bonnefon 426039481acSNicolas Bonnefon void CrawlerWidget::fileChangedHandler( LogData::MonitoredFileStatus status ) 427039481acSNicolas Bonnefon { 428039481acSNicolas Bonnefon // Handle the case where the file has been truncated 429039481acSNicolas Bonnefon if ( status == LogData::Truncated ) { 430039481acSNicolas Bonnefon // Clear all marks (TODO offer the option to keep them) 431039481acSNicolas Bonnefon logFilteredData_->clearMarks(); 432039481acSNicolas Bonnefon if ( ! searchInfoLine->text().isEmpty() ) { 433039481acSNicolas Bonnefon // Invalidate the search 434039481acSNicolas Bonnefon logFilteredData_->clearSearch(); 435039481acSNicolas Bonnefon filteredView->updateData(); 436039481acSNicolas Bonnefon searchState_.truncateFile(); 437039481acSNicolas Bonnefon printSearchInfoMessage(); 438039481acSNicolas Bonnefon } 439039481acSNicolas Bonnefon } 440039481acSNicolas Bonnefon } 441039481acSNicolas Bonnefon 442039481acSNicolas Bonnefon // Returns a pointer to the window in which the search should be done 443039481acSNicolas Bonnefon AbstractLogView* CrawlerWidget::activeView() const 444039481acSNicolas Bonnefon { 445039481acSNicolas Bonnefon QWidget* activeView; 446039481acSNicolas Bonnefon 447039481acSNicolas Bonnefon // Search in the window that has focus, or the window where 'Find' was 448039481acSNicolas Bonnefon // called from, or the main window. 449039481acSNicolas Bonnefon if ( filteredView->hasFocus() || logMainView->hasFocus() ) 450039481acSNicolas Bonnefon activeView = QApplication::focusWidget(); 451039481acSNicolas Bonnefon else 4528570d8d2SNicolas Bonnefon activeView = qfSavedFocus_; 453039481acSNicolas Bonnefon 454b423cd88SNicolas Bonnefon if ( activeView ) { 455b423cd88SNicolas Bonnefon AbstractLogView* view = qobject_cast<AbstractLogView*>( activeView ); 456039481acSNicolas Bonnefon return view; 457b423cd88SNicolas Bonnefon } 458b423cd88SNicolas Bonnefon else { 459b423cd88SNicolas Bonnefon LOG(logWARNING) << "No active view, defaulting to logMainView"; 460039481acSNicolas Bonnefon return logMainView; 461039481acSNicolas Bonnefon } 462b423cd88SNicolas Bonnefon } 463039481acSNicolas Bonnefon 464039481acSNicolas Bonnefon void CrawlerWidget::searchForward() 465039481acSNicolas Bonnefon { 466039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchForward"; 467039481acSNicolas Bonnefon 468039481acSNicolas Bonnefon activeView()->searchForward(); 469039481acSNicolas Bonnefon } 470039481acSNicolas Bonnefon 471039481acSNicolas Bonnefon void CrawlerWidget::searchBackward() 472039481acSNicolas Bonnefon { 473039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchBackward"; 474039481acSNicolas Bonnefon 475039481acSNicolas Bonnefon activeView()->searchBackward(); 476039481acSNicolas Bonnefon } 477039481acSNicolas Bonnefon 478039481acSNicolas Bonnefon void CrawlerWidget::searchRefreshChangedHandler( int state ) 479039481acSNicolas Bonnefon { 480039481acSNicolas Bonnefon searchState_.setAutorefresh( state == Qt::Checked ); 481039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 482039481acSNicolas Bonnefon } 483039481acSNicolas Bonnefon 484039481acSNicolas Bonnefon void CrawlerWidget::searchTextChangeHandler() 485039481acSNicolas Bonnefon { 486039481acSNicolas Bonnefon // We suspend auto-refresh 487039481acSNicolas Bonnefon searchState_.changeExpression(); 488039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 489039481acSNicolas Bonnefon } 490039481acSNicolas Bonnefon 491039481acSNicolas Bonnefon void CrawlerWidget::changeFilteredViewVisibility( int index ) 492039481acSNicolas Bonnefon { 493039481acSNicolas Bonnefon QStandardItem* item = visibilityModel_->item( index ); 494039481acSNicolas Bonnefon FilteredView::Visibility visibility = 495039481acSNicolas Bonnefon static_cast< FilteredView::Visibility>( item->data().toInt() ); 496039481acSNicolas Bonnefon 497039481acSNicolas Bonnefon filteredView->setVisibility( visibility ); 498039481acSNicolas Bonnefon } 499039481acSNicolas Bonnefon 500039481acSNicolas Bonnefon void CrawlerWidget::addToSearch( const QString& string ) 501039481acSNicolas Bonnefon { 502039481acSNicolas Bonnefon QString text = searchLineEdit->currentText(); 503039481acSNicolas Bonnefon 504039481acSNicolas Bonnefon if ( text.isEmpty() ) 505039481acSNicolas Bonnefon text = string; 506039481acSNicolas Bonnefon else { 507039481acSNicolas Bonnefon // Escape the regexp chars from the string before adding it. 508039481acSNicolas Bonnefon text += ( '|' + QRegExp::escape( string ) ); 509039481acSNicolas Bonnefon } 510039481acSNicolas Bonnefon 511039481acSNicolas Bonnefon searchLineEdit->setEditText( text ); 512039481acSNicolas Bonnefon 513039481acSNicolas Bonnefon // Set the focus to lineEdit so that the user can press 'Return' immediately 514039481acSNicolas Bonnefon searchLineEdit->lineEdit()->setFocus(); 515039481acSNicolas Bonnefon } 516039481acSNicolas Bonnefon 517039481acSNicolas Bonnefon void CrawlerWidget::mouseHoveredOverMatch( qint64 line ) 518039481acSNicolas Bonnefon { 519039481acSNicolas Bonnefon qint64 line_in_mainview = logFilteredData_->getMatchingLineNumber( line ); 520039481acSNicolas Bonnefon 521039481acSNicolas Bonnefon overviewWidget_->highlightLine( line_in_mainview ); 522039481acSNicolas Bonnefon } 523039481acSNicolas Bonnefon 52445ef183cSNicolas Bonnefon void CrawlerWidget::activityDetected() 52545ef183cSNicolas Bonnefon { 52645ef183cSNicolas Bonnefon changeDataStatus( DataStatus::OLD_DATA ); 52745ef183cSNicolas Bonnefon } 52845ef183cSNicolas Bonnefon 529039481acSNicolas Bonnefon // 530039481acSNicolas Bonnefon // Private functions 531039481acSNicolas Bonnefon // 532039481acSNicolas Bonnefon 533039481acSNicolas Bonnefon // Build the widget and connect all the signals, this must be done once 534039481acSNicolas Bonnefon // the data are attached. 535039481acSNicolas Bonnefon void CrawlerWidget::setup() 536039481acSNicolas Bonnefon { 537bb02e0acSNicolas Bonnefon setOrientation(Qt::Vertical); 538bb02e0acSNicolas Bonnefon 539039481acSNicolas Bonnefon assert( logData_ ); 540039481acSNicolas Bonnefon assert( logFilteredData_ ); 541bb02e0acSNicolas Bonnefon 542bb02e0acSNicolas Bonnefon // The views 543bb02e0acSNicolas Bonnefon bottomWindow = new QWidget; 544bb02e0acSNicolas Bonnefon overviewWidget_ = new OverviewWidget(); 545bb02e0acSNicolas Bonnefon logMainView = new LogMainView( 5460f9fd9edSNicolas Bonnefon logData_, quickFindPattern_.get(), &overview_, overviewWidget_ ); 547bb02e0acSNicolas Bonnefon filteredView = new FilteredView( 548b423cd88SNicolas Bonnefon logFilteredData_, quickFindPattern_.get() ); 549bb02e0acSNicolas Bonnefon 5500f9fd9edSNicolas Bonnefon overviewWidget_->setOverview( &overview_ ); 551bb02e0acSNicolas Bonnefon overviewWidget_->setParent( logMainView ); 552bb02e0acSNicolas Bonnefon 55358ab9c53SNicolas Bonnefon // Connect the search to the top view 55458ab9c53SNicolas Bonnefon logMainView->useNewFiltering( logFilteredData_ ); 55558ab9c53SNicolas Bonnefon 556bb02e0acSNicolas Bonnefon // Construct the visibility button 557bb02e0acSNicolas Bonnefon visibilityModel_ = new QStandardItemModel( this ); 558bb02e0acSNicolas Bonnefon 559bb02e0acSNicolas Bonnefon QStandardItem *marksAndMatchesItem = new QStandardItem( tr( "Marks and matches" ) ); 560bb02e0acSNicolas Bonnefon QPixmap marksAndMatchesPixmap( 16, 10 ); 561bb02e0acSNicolas Bonnefon marksAndMatchesPixmap.fill( Qt::gray ); 562bb02e0acSNicolas Bonnefon marksAndMatchesItem->setIcon( QIcon( marksAndMatchesPixmap ) ); 563bb02e0acSNicolas Bonnefon marksAndMatchesItem->setData( FilteredView::MarksAndMatches ); 564bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksAndMatchesItem ); 565bb02e0acSNicolas Bonnefon 566bb02e0acSNicolas Bonnefon QStandardItem *marksItem = new QStandardItem( tr( "Marks" ) ); 567bb02e0acSNicolas Bonnefon QPixmap marksPixmap( 16, 10 ); 568bb02e0acSNicolas Bonnefon marksPixmap.fill( Qt::blue ); 569bb02e0acSNicolas Bonnefon marksItem->setIcon( QIcon( marksPixmap ) ); 570bb02e0acSNicolas Bonnefon marksItem->setData( FilteredView::MarksOnly ); 571bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksItem ); 572bb02e0acSNicolas Bonnefon 573bb02e0acSNicolas Bonnefon QStandardItem *matchesItem = new QStandardItem( tr( "Matches" ) ); 574bb02e0acSNicolas Bonnefon QPixmap matchesPixmap( 16, 10 ); 575bb02e0acSNicolas Bonnefon matchesPixmap.fill( Qt::red ); 576bb02e0acSNicolas Bonnefon matchesItem->setIcon( QIcon( matchesPixmap ) ); 577bb02e0acSNicolas Bonnefon matchesItem->setData( FilteredView::MatchesOnly ); 578bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( matchesItem ); 579bb02e0acSNicolas Bonnefon 580bb02e0acSNicolas Bonnefon QListView *visibilityView = new QListView( this ); 581bb02e0acSNicolas Bonnefon visibilityView->setMovement( QListView::Static ); 582bb02e0acSNicolas Bonnefon visibilityView->setMinimumWidth( 170 ); // Only needed with custom style-sheet 583bb02e0acSNicolas Bonnefon 584bb02e0acSNicolas Bonnefon visibilityBox = new QComboBox(); 585bb02e0acSNicolas Bonnefon visibilityBox->setModel( visibilityModel_ ); 586bb02e0acSNicolas Bonnefon visibilityBox->setView( visibilityView ); 587bb02e0acSNicolas Bonnefon 588bb02e0acSNicolas Bonnefon // Select "Marks and matches" by default (same default as the filtered view) 589bb02e0acSNicolas Bonnefon visibilityBox->setCurrentIndex( 0 ); 590bb02e0acSNicolas Bonnefon 591bb02e0acSNicolas Bonnefon // TODO: Maybe there is some way to set the popup width to be 592bb02e0acSNicolas Bonnefon // sized-to-content (as it is when the stylesheet is not overriden) in the 593bb02e0acSNicolas Bonnefon // stylesheet as opposed to setting a hard min-width on the view above. 594bb02e0acSNicolas Bonnefon visibilityBox->setStyleSheet( " \ 595bb02e0acSNicolas Bonnefon QComboBox:on {\ 596bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 6px;\ 597bb02e0acSNicolas Bonnefon width: 19px;\ 598bb02e0acSNicolas Bonnefon } \ 599bb02e0acSNicolas Bonnefon QComboBox:!on {\ 600bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 7px;\ 601bb02e0acSNicolas Bonnefon width: 19px;\ 602bb02e0acSNicolas Bonnefon height: 16px;\ 603bb02e0acSNicolas Bonnefon border: 1px solid gray;\ 604bb02e0acSNicolas Bonnefon } \ 605bb02e0acSNicolas Bonnefon QComboBox::drop-down::down-arrow {\ 606bb02e0acSNicolas Bonnefon width: 0px;\ 607bb02e0acSNicolas Bonnefon border-width: 0px;\ 608bb02e0acSNicolas Bonnefon } \ 609bb02e0acSNicolas Bonnefon " ); 610bb02e0acSNicolas Bonnefon 611bb02e0acSNicolas Bonnefon // Construct the Search Info line 612bb02e0acSNicolas Bonnefon searchInfoLine = new InfoLine(); 613bb02e0acSNicolas Bonnefon searchInfoLine->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 614bb02e0acSNicolas Bonnefon searchInfoLine->setLineWidth( 1 ); 615bb02e0acSNicolas Bonnefon searchInfoLineDefaultPalette = searchInfoLine->palette(); 616bb02e0acSNicolas Bonnefon 617bb02e0acSNicolas Bonnefon ignoreCaseCheck = new QCheckBox( "Ignore &case" ); 618bb02e0acSNicolas Bonnefon searchRefreshCheck = new QCheckBox( "Auto-&refresh" ); 619bb02e0acSNicolas Bonnefon 620bb02e0acSNicolas Bonnefon // Construct the Search line 621bb02e0acSNicolas Bonnefon searchLabel = new QLabel(tr("&Text: ")); 622bb02e0acSNicolas Bonnefon searchLineEdit = new QComboBox; 623bb02e0acSNicolas Bonnefon searchLineEdit->setEditable( true ); 624bb02e0acSNicolas Bonnefon searchLineEdit->setCompleter( 0 ); 6251b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() ); 626bb02e0acSNicolas Bonnefon searchLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); 627bb02e0acSNicolas Bonnefon searchLineEdit->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon ); 628bb02e0acSNicolas Bonnefon 629bb02e0acSNicolas Bonnefon searchLabel->setBuddy( searchLineEdit ); 630bb02e0acSNicolas Bonnefon 631bb02e0acSNicolas Bonnefon searchButton = new QToolButton(); 632bb02e0acSNicolas Bonnefon searchButton->setText( tr("&Search") ); 633bb02e0acSNicolas Bonnefon searchButton->setAutoRaise( true ); 634bb02e0acSNicolas Bonnefon 635bb02e0acSNicolas Bonnefon stopButton = new QToolButton(); 636bb02e0acSNicolas Bonnefon stopButton->setIcon( QIcon(":/images/stop16.png") ); 637bb02e0acSNicolas Bonnefon stopButton->setAutoRaise( true ); 638bb02e0acSNicolas Bonnefon stopButton->setEnabled( false ); 639bb02e0acSNicolas Bonnefon 640bb02e0acSNicolas Bonnefon QHBoxLayout* searchLineLayout = new QHBoxLayout; 641bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLabel); 642bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLineEdit); 643bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchButton); 644bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(stopButton); 645bb02e0acSNicolas Bonnefon searchLineLayout->setContentsMargins(6, 0, 6, 0); 646bb02e0acSNicolas Bonnefon stopButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 647bb02e0acSNicolas Bonnefon searchButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 648bb02e0acSNicolas Bonnefon 649bb02e0acSNicolas Bonnefon QHBoxLayout* searchInfoLineLayout = new QHBoxLayout; 650bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( visibilityBox ); 651bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchInfoLine ); 652bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( ignoreCaseCheck ); 653bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchRefreshCheck ); 654bb02e0acSNicolas Bonnefon 655bb02e0acSNicolas Bonnefon // Construct the bottom window 656bb02e0acSNicolas Bonnefon QVBoxLayout* bottomMainLayout = new QVBoxLayout; 657bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchLineLayout); 658bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchInfoLineLayout); 659bb02e0acSNicolas Bonnefon bottomMainLayout->addWidget(filteredView); 660bb02e0acSNicolas Bonnefon bottomMainLayout->setContentsMargins(2, 1, 2, 1); 661bb02e0acSNicolas Bonnefon bottomWindow->setLayout(bottomMainLayout); 662bb02e0acSNicolas Bonnefon 663bb02e0acSNicolas Bonnefon addWidget( logMainView ); 664bb02e0acSNicolas Bonnefon addWidget( bottomWindow ); 665bb02e0acSNicolas Bonnefon 666bb02e0acSNicolas Bonnefon // Default splitter position (usually overridden by the config file) 667bb02e0acSNicolas Bonnefon QList<int> splitterSizes; 668bb02e0acSNicolas Bonnefon splitterSizes += 400; 669bb02e0acSNicolas Bonnefon splitterSizes += 100; 670bb02e0acSNicolas Bonnefon setSizes( splitterSizes ); 671bb02e0acSNicolas Bonnefon 672f688be2eSNicolas Bonnefon // Default search checkboxes 673f688be2eSNicolas Bonnefon auto config = Persistent<Configuration>( "settings" ); 674f688be2eSNicolas Bonnefon searchRefreshCheck->setCheckState( config->isSearchAutoRefreshDefault() ? 675f688be2eSNicolas Bonnefon Qt::Checked : Qt::Unchecked ); 676c580560cSNicolas Bonnefon // Manually call the handler as it is not called when changing the state programmatically 677c580560cSNicolas Bonnefon searchRefreshChangedHandler( searchRefreshCheck->checkState() ); 678f688be2eSNicolas Bonnefon ignoreCaseCheck->setCheckState( config->isSearchIgnoreCaseDefault() ? 679f688be2eSNicolas Bonnefon Qt::Checked : Qt::Unchecked ); 680f688be2eSNicolas Bonnefon 681bb02e0acSNicolas Bonnefon // Connect the signals 682bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( returnPressed() ), 683bb02e0acSNicolas Bonnefon searchButton, SIGNAL( clicked() )); 684bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( textEdited( const QString& ) ), 685bb02e0acSNicolas Bonnefon this, SLOT( searchTextChangeHandler() )); 686bb02e0acSNicolas Bonnefon connect(searchButton, SIGNAL( clicked() ), 687bb02e0acSNicolas Bonnefon this, SLOT( startNewSearch() ) ); 688bb02e0acSNicolas Bonnefon connect(stopButton, SIGNAL( clicked() ), 689bb02e0acSNicolas Bonnefon this, SLOT( stopSearch() ) ); 690bb02e0acSNicolas Bonnefon 691bb02e0acSNicolas Bonnefon connect(visibilityBox, SIGNAL( currentIndexChanged( int ) ), 692bb02e0acSNicolas Bonnefon this, SLOT( changeFilteredViewVisibility( int ) ) ); 693bb02e0acSNicolas Bonnefon 694bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( newSelection( int ) ), 695bb02e0acSNicolas Bonnefon logMainView, SLOT( update() ) ); 696bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 697bb02e0acSNicolas Bonnefon this, SLOT( jumpToMatchingLine( int ) ) ); 698bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 699bb02e0acSNicolas Bonnefon filteredView, SLOT( update() ) ); 700bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( updateLineNumber( int ) ), 7019cacd6a9SNicolas Bonnefon this, SLOT( updateLineNumberHandler( int ) ) ); 702bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( markLine( qint64 ) ), 703bb02e0acSNicolas Bonnefon this, SLOT( markLineFromMain( qint64 ) ) ); 704bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( markLine( qint64 ) ), 705bb02e0acSNicolas Bonnefon this, SLOT( markLineFromFiltered( qint64 ) ) ); 706bb02e0acSNicolas Bonnefon 707bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( addToSearch( const QString& ) ), 708bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 709bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( addToSearch( const QString& ) ), 710bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 711bb02e0acSNicolas Bonnefon 712bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseHoveredOverLine( qint64 ) ), 713bb02e0acSNicolas Bonnefon this, SLOT( mouseHoveredOverMatch( qint64 ) ) ); 714bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseLeftHoveringZone() ), 715bb02e0acSNicolas Bonnefon overviewWidget_, SLOT( removeHighlight() ) ); 716bb02e0acSNicolas Bonnefon 717bb02e0acSNicolas Bonnefon // Follow option (up and down) 718bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 719bb02e0acSNicolas Bonnefon logMainView, SLOT( followSet( bool ) ) ); 720bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 721bb02e0acSNicolas Bonnefon filteredView, SLOT( followSet( bool ) ) ); 722b297d2f4SNicolas Bonnefon connect(logMainView, SIGNAL( followModeChanged( bool ) ), 723b297d2f4SNicolas Bonnefon this, SIGNAL( followModeChanged( bool ) ) ); 724b297d2f4SNicolas Bonnefon connect(filteredView, SIGNAL( followModeChanged( bool ) ), 725b297d2f4SNicolas Bonnefon this, SIGNAL( followModeChanged( bool ) ) ); 726bb02e0acSNicolas Bonnefon 72745ef183cSNicolas Bonnefon // Detect activity in the views 72845ef183cSNicolas Bonnefon connect(logMainView, SIGNAL( activity() ), 72945ef183cSNicolas Bonnefon this, SLOT( activityDetected() ) ); 73045ef183cSNicolas Bonnefon connect(filteredView, SIGNAL( activity() ), 73145ef183cSNicolas Bonnefon this, SLOT( activityDetected() ) ); 73245ef183cSNicolas Bonnefon 733bb02e0acSNicolas Bonnefon connect( logFilteredData_, SIGNAL( searchProgressed( int, int ) ), 734bb02e0acSNicolas Bonnefon this, SLOT( updateFilteredView( int, int ) ) ); 735bb02e0acSNicolas Bonnefon 736bb02e0acSNicolas Bonnefon // Sent load file update to MainWindow (for status update) 737bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( loadingProgressed( int ) ), 738bb02e0acSNicolas Bonnefon this, SIGNAL( loadingProgressed( int ) ) ); 739812146a8SNicolas Bonnefon connect( logData_, SIGNAL( loadingFinished( LoadingStatus ) ), 740812146a8SNicolas Bonnefon this, SLOT( loadingFinishedHandler( LoadingStatus ) ) ); 741bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( fileChanged( LogData::MonitoredFileStatus ) ), 742bb02e0acSNicolas Bonnefon this, SLOT( fileChangedHandler( LogData::MonitoredFileStatus ) ) ); 743bb02e0acSNicolas Bonnefon 744bb02e0acSNicolas Bonnefon // Search auto-refresh 745bb02e0acSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ), 746bb02e0acSNicolas Bonnefon this, SLOT( searchRefreshChangedHandler( int ) ) ); 747f688be2eSNicolas Bonnefon 748f688be2eSNicolas Bonnefon // Advise the parent the checkboxes have been changed 749f688be2eSNicolas Bonnefon // (for maintaining default config) 750f688be2eSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ), 751f688be2eSNicolas Bonnefon this, SIGNAL( searchRefreshChanged( int ) ) ); 752f688be2eSNicolas Bonnefon connect( ignoreCaseCheck, SIGNAL( stateChanged( int ) ), 753f688be2eSNicolas Bonnefon this, SIGNAL( ignoreCaseChanged( int ) ) ); 754bb02e0acSNicolas Bonnefon } 755bb02e0acSNicolas Bonnefon 756bb02e0acSNicolas Bonnefon // Create a new search using the text passed, replace the currently 757bb02e0acSNicolas Bonnefon // used one and destroy the old one. 758bb02e0acSNicolas Bonnefon void CrawlerWidget::replaceCurrentSearch( const QString& searchText ) 759bb02e0acSNicolas Bonnefon { 760bb02e0acSNicolas Bonnefon // Interrupt the search if it's ongoing 761bb02e0acSNicolas Bonnefon logFilteredData_->interruptSearch(); 762bb02e0acSNicolas Bonnefon 763bb02e0acSNicolas Bonnefon // We have to wait for the last search update (100%) 764bb02e0acSNicolas Bonnefon // before clearing/restarting to avoid having remaining results. 765bb02e0acSNicolas Bonnefon 766bb02e0acSNicolas Bonnefon // FIXME: this is a bit of a hack, we call processEvents 767bb02e0acSNicolas Bonnefon // for Qt to empty its event queue, including (hopefully) 768bb02e0acSNicolas Bonnefon // the search update event sent by logFilteredData_. It saves 769bb02e0acSNicolas Bonnefon // us the overhead of having proper sync. 770bb02e0acSNicolas Bonnefon QApplication::processEvents( QEventLoop::ExcludeUserInputEvents ); 771bb02e0acSNicolas Bonnefon 772bb02e0acSNicolas Bonnefon if ( !searchText.isEmpty() ) { 773bb02e0acSNicolas Bonnefon // Determine the type of regexp depending on the config 774bb02e0acSNicolas Bonnefon QRegExp::PatternSyntax syntax; 77511582726SNicolas Bonnefon static std::shared_ptr<Configuration> config = 77611582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 77711582726SNicolas Bonnefon switch ( config->mainRegexpType() ) { 778bb02e0acSNicolas Bonnefon case Wildcard: 779bb02e0acSNicolas Bonnefon syntax = QRegExp::Wildcard; 780bb02e0acSNicolas Bonnefon break; 781bb02e0acSNicolas Bonnefon case FixedString: 782bb02e0acSNicolas Bonnefon syntax = QRegExp::FixedString; 783bb02e0acSNicolas Bonnefon break; 784bb02e0acSNicolas Bonnefon default: 785bb02e0acSNicolas Bonnefon syntax = QRegExp::RegExp2; 786bb02e0acSNicolas Bonnefon break; 787bb02e0acSNicolas Bonnefon } 788bb02e0acSNicolas Bonnefon 789bb02e0acSNicolas Bonnefon // Set the pattern case insensitive if needed 790bb02e0acSNicolas Bonnefon Qt::CaseSensitivity case_sensitivity = Qt::CaseSensitive; 791bb02e0acSNicolas Bonnefon if ( ignoreCaseCheck->checkState() == Qt::Checked ) 792bb02e0acSNicolas Bonnefon case_sensitivity = Qt::CaseInsensitive; 793bb02e0acSNicolas Bonnefon 794bb02e0acSNicolas Bonnefon // Constructs the regexp 795bb02e0acSNicolas Bonnefon QRegExp regexp( searchText, case_sensitivity, syntax ); 796bb02e0acSNicolas Bonnefon 797bb02e0acSNicolas Bonnefon if ( regexp.isValid() ) { 798bb02e0acSNicolas Bonnefon // Activate the stop button 799bb02e0acSNicolas Bonnefon stopButton->setEnabled( true ); 800bb02e0acSNicolas Bonnefon // Start a new asynchronous search 801bb02e0acSNicolas Bonnefon logFilteredData_->runSearch( regexp ); 802bb02e0acSNicolas Bonnefon // Accept auto-refresh of the search 803bb02e0acSNicolas Bonnefon searchState_.startSearch(); 804bb02e0acSNicolas Bonnefon } 805bb02e0acSNicolas Bonnefon else { 806bb02e0acSNicolas Bonnefon // The regexp is wrong 807bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 808bb02e0acSNicolas Bonnefon filteredView->updateData(); 809bb02e0acSNicolas Bonnefon searchState_.resetState(); 810bb02e0acSNicolas Bonnefon 811bb02e0acSNicolas Bonnefon // Inform the user 812bb02e0acSNicolas Bonnefon QString errorMessage = tr("Error in expression: "); 813bb02e0acSNicolas Bonnefon errorMessage += regexp.errorString(); 814bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( errorPalette ); 815bb02e0acSNicolas Bonnefon searchInfoLine->setText( errorMessage ); 816bb02e0acSNicolas Bonnefon } 817bb02e0acSNicolas Bonnefon } 818bb02e0acSNicolas Bonnefon else { 819bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 820bb02e0acSNicolas Bonnefon filteredView->updateData(); 821bb02e0acSNicolas Bonnefon searchState_.resetState(); 822bb02e0acSNicolas Bonnefon printSearchInfoMessage(); 823bb02e0acSNicolas Bonnefon } 824bb02e0acSNicolas Bonnefon } 825bb02e0acSNicolas Bonnefon 826bb02e0acSNicolas Bonnefon // Updates the content of the drop down list for the saved searches, 827bb02e0acSNicolas Bonnefon // called when the SavedSearch has been changed. 828bb02e0acSNicolas Bonnefon void CrawlerWidget::updateSearchCombo() 829bb02e0acSNicolas Bonnefon { 830bb02e0acSNicolas Bonnefon const QString text = searchLineEdit->lineEdit()->text(); 831bb02e0acSNicolas Bonnefon searchLineEdit->clear(); 8321b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() ); 833bb02e0acSNicolas Bonnefon // In case we had something that wasn't added to the list (blank...): 834bb02e0acSNicolas Bonnefon searchLineEdit->lineEdit()->setText( text ); 835bb02e0acSNicolas Bonnefon } 836bb02e0acSNicolas Bonnefon 837bb02e0acSNicolas Bonnefon // Print the search info message. 838bb02e0acSNicolas Bonnefon void CrawlerWidget::printSearchInfoMessage( int nbMatches ) 839bb02e0acSNicolas Bonnefon { 840bb02e0acSNicolas Bonnefon QString text; 841bb02e0acSNicolas Bonnefon 842bb02e0acSNicolas Bonnefon switch ( searchState_.getState() ) { 843bb02e0acSNicolas Bonnefon case SearchState::NoSearch: 844bb02e0acSNicolas Bonnefon // Blank text is fine 845bb02e0acSNicolas Bonnefon break; 846bb02e0acSNicolas Bonnefon case SearchState::Static: 847bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found.").arg( nbMatches ) 848bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 849bb02e0acSNicolas Bonnefon break; 850bb02e0acSNicolas Bonnefon case SearchState::Autorefreshing: 851bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found. Search is auto-refreshing...").arg( nbMatches ) 852bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 853bb02e0acSNicolas Bonnefon break; 854bb02e0acSNicolas Bonnefon case SearchState::FileTruncated: 85559d4e393SNicolas Bonnefon case SearchState::TruncatedAutorefreshing: 856bb02e0acSNicolas Bonnefon text = tr("File truncated on disk, previous search results are not valid anymore."); 857bb02e0acSNicolas Bonnefon break; 858bb02e0acSNicolas Bonnefon } 859bb02e0acSNicolas Bonnefon 860bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( searchInfoLineDefaultPalette ); 861bb02e0acSNicolas Bonnefon searchInfoLine->setText( text ); 862bb02e0acSNicolas Bonnefon } 863bb02e0acSNicolas Bonnefon 86445ef183cSNicolas Bonnefon // Change the data status and, if needed, advise upstream. 86545ef183cSNicolas Bonnefon void CrawlerWidget::changeDataStatus( DataStatus status ) 86645ef183cSNicolas Bonnefon { 86745ef183cSNicolas Bonnefon if ( status != dataStatus_ ) { 86845ef183cSNicolas Bonnefon dataStatus_ = status; 86945ef183cSNicolas Bonnefon emit dataStatusChanged( dataStatus_ ); 87045ef183cSNicolas Bonnefon } 87145ef183cSNicolas Bonnefon } 87245ef183cSNicolas Bonnefon 873bb02e0acSNicolas Bonnefon // 874bb02e0acSNicolas Bonnefon // SearchState implementation 875bb02e0acSNicolas Bonnefon // 876bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::resetState() 877bb02e0acSNicolas Bonnefon { 878bb02e0acSNicolas Bonnefon state_ = NoSearch; 879bb02e0acSNicolas Bonnefon } 880bb02e0acSNicolas Bonnefon 881bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::setAutorefresh( bool refresh ) 882bb02e0acSNicolas Bonnefon { 883bb02e0acSNicolas Bonnefon autoRefreshRequested_ = refresh; 884bb02e0acSNicolas Bonnefon 885bb02e0acSNicolas Bonnefon if ( refresh ) { 886bb02e0acSNicolas Bonnefon if ( state_ == Static ) 887bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 88859d4e393SNicolas Bonnefon /* 88959d4e393SNicolas Bonnefon else if ( state_ == FileTruncated ) 89059d4e393SNicolas Bonnefon state_ = TruncatedAutorefreshing; 89159d4e393SNicolas Bonnefon */ 892bb02e0acSNicolas Bonnefon } 893bb02e0acSNicolas Bonnefon else { 894bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 895bb02e0acSNicolas Bonnefon state_ = Static; 89659d4e393SNicolas Bonnefon else if ( state_ == TruncatedAutorefreshing ) 89759d4e393SNicolas Bonnefon state_ = FileTruncated; 898bb02e0acSNicolas Bonnefon } 899bb02e0acSNicolas Bonnefon } 900bb02e0acSNicolas Bonnefon 901bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::truncateFile() 902bb02e0acSNicolas Bonnefon { 90359d4e393SNicolas Bonnefon if ( state_ == Autorefreshing || state_ == TruncatedAutorefreshing ) { 90459d4e393SNicolas Bonnefon state_ = TruncatedAutorefreshing; 90559d4e393SNicolas Bonnefon } 90659d4e393SNicolas Bonnefon else { 907bb02e0acSNicolas Bonnefon state_ = FileTruncated; 908bb02e0acSNicolas Bonnefon } 90959d4e393SNicolas Bonnefon } 910bb02e0acSNicolas Bonnefon 911bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::changeExpression() 912bb02e0acSNicolas Bonnefon { 913bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 914bb02e0acSNicolas Bonnefon state_ = Static; 915bb02e0acSNicolas Bonnefon } 916bb02e0acSNicolas Bonnefon 917bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::stopSearch() 918bb02e0acSNicolas Bonnefon { 919bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 920bb02e0acSNicolas Bonnefon state_ = Static; 921bb02e0acSNicolas Bonnefon } 922bb02e0acSNicolas Bonnefon 923bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::startSearch() 924bb02e0acSNicolas Bonnefon { 925bb02e0acSNicolas Bonnefon if ( autoRefreshRequested_ ) 926bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 927bb02e0acSNicolas Bonnefon else 928bb02e0acSNicolas Bonnefon state_ = Static; 929bb02e0acSNicolas Bonnefon } 930a44d09bcSNicolas Bonnefon 931a44d09bcSNicolas Bonnefon /* 932a44d09bcSNicolas Bonnefon * CrawlerWidgetContext 933a44d09bcSNicolas Bonnefon */ 934a44d09bcSNicolas Bonnefon CrawlerWidgetContext::CrawlerWidgetContext( const char* string ) 935a44d09bcSNicolas Bonnefon { 936a44d09bcSNicolas Bonnefon QRegExp regex = QRegExp( "S(\\d+):(\\d+)" ); 937a44d09bcSNicolas Bonnefon 938f688be2eSNicolas Bonnefon if ( regex.indexIn( string ) > -1 ) { 939a44d09bcSNicolas Bonnefon sizes_ = { regex.cap(1).toInt(), regex.cap(2).toInt() }; 940a44d09bcSNicolas Bonnefon LOG(logDEBUG) << "sizes_: " << sizes_[0] << " " << sizes_[1]; 941a44d09bcSNicolas Bonnefon } 942f688be2eSNicolas Bonnefon else { 943f688be2eSNicolas Bonnefon LOG(logWARNING) << "Unrecognised view size: " << string; 944a44d09bcSNicolas Bonnefon 945a44d09bcSNicolas Bonnefon // Default values; 946a44d09bcSNicolas Bonnefon sizes_ = { 100, 400 }; 947a44d09bcSNicolas Bonnefon } 948f688be2eSNicolas Bonnefon 949f688be2eSNicolas Bonnefon QRegExp case_refresh_regex = QRegExp( "IC(\\d+):AR(\\d+)" ); 950f688be2eSNicolas Bonnefon 951f688be2eSNicolas Bonnefon if ( case_refresh_regex.indexIn( string ) > -1 ) { 952f688be2eSNicolas Bonnefon ignore_case_ = ( case_refresh_regex.cap(1).toInt() == 1 ); 953f688be2eSNicolas Bonnefon auto_refresh_ = ( case_refresh_regex.cap(2).toInt() == 1 ); 954f688be2eSNicolas Bonnefon 955f688be2eSNicolas Bonnefon LOG(logDEBUG) << "ignore_case_: " << ignore_case_ << " auto_refresh_: " 956f688be2eSNicolas Bonnefon << auto_refresh_; 957f688be2eSNicolas Bonnefon } 958f688be2eSNicolas Bonnefon else { 959f688be2eSNicolas Bonnefon LOG(logWARNING) << "Unrecognised case/refresh: " << string; 960f688be2eSNicolas Bonnefon ignore_case_ = false; 961f688be2eSNicolas Bonnefon auto_refresh_ = false; 962f688be2eSNicolas Bonnefon } 963a44d09bcSNicolas Bonnefon } 964a44d09bcSNicolas Bonnefon 965a44d09bcSNicolas Bonnefon std::string CrawlerWidgetContext::toString() const 966a44d09bcSNicolas Bonnefon { 967a44d09bcSNicolas Bonnefon char string[160]; 968a44d09bcSNicolas Bonnefon 969f688be2eSNicolas Bonnefon snprintf( string, sizeof string, "S%d:%d:IC%d:AR%d", 970f688be2eSNicolas Bonnefon sizes_[0], sizes_[1], 971f688be2eSNicolas Bonnefon ignore_case_, auto_refresh_ ); 972a44d09bcSNicolas Bonnefon 973f688be2eSNicolas Bonnefon return { string }; 974a44d09bcSNicolas Bonnefon } 975