1bb02e0acSNicolas Bonnefon /* 2b423cd88SNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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 <QKeyEvent> 35bb02e0acSNicolas Bonnefon #include <QStandardItemModel> 36bb02e0acSNicolas Bonnefon #include <QHeaderView> 37bb02e0acSNicolas Bonnefon #include <QListView> 38bb02e0acSNicolas Bonnefon 39bb02e0acSNicolas Bonnefon #include "crawlerwidget.h" 40bb02e0acSNicolas Bonnefon 41bb02e0acSNicolas Bonnefon #include "quickfindpattern.h" 42bb02e0acSNicolas Bonnefon #include "overview.h" 43bb02e0acSNicolas Bonnefon #include "infoline.h" 44bb02e0acSNicolas Bonnefon #include "savedsearches.h" 45bb02e0acSNicolas Bonnefon #include "quickfindwidget.h" 46bb02e0acSNicolas Bonnefon #include "persistentinfo.h" 47bb02e0acSNicolas Bonnefon #include "configuration.h" 48bb02e0acSNicolas Bonnefon 49bb02e0acSNicolas Bonnefon // Palette for error signaling (yellow background) 50bb02e0acSNicolas Bonnefon const QPalette CrawlerWidget::errorPalette( QColor( "yellow" ) ); 51bb02e0acSNicolas Bonnefon 52039481acSNicolas Bonnefon // Constructor only does trivial construction. The real work is done once 53039481acSNicolas Bonnefon // the data is attached. 541b5e406eSNicolas Bonnefon CrawlerWidget::CrawlerWidget( QWidget *parent ) 550f9fd9edSNicolas Bonnefon : QSplitter( parent ), overview_() 56bb02e0acSNicolas Bonnefon { 57039481acSNicolas Bonnefon logData_ = nullptr; 58039481acSNicolas Bonnefon logFilteredData_ = nullptr; 59039481acSNicolas Bonnefon 60b423cd88SNicolas Bonnefon quickFindPattern_ = nullptr; 611b5e406eSNicolas Bonnefon savedSearches_ = nullptr; 628570d8d2SNicolas Bonnefon qfSavedFocus_ = nullptr; 639cacd6a9SNicolas Bonnefon 6460864ff5SNicolas Bonnefon // Until we have received confirmation loading is finished, we 6560864ff5SNicolas Bonnefon // should consider we are loading something. 6660864ff5SNicolas Bonnefon loadingInProgress_ = true; 6760864ff5SNicolas Bonnefon 689cacd6a9SNicolas Bonnefon currentLineNumber_ = 0; 69039481acSNicolas Bonnefon } 70039481acSNicolas Bonnefon 71039481acSNicolas Bonnefon // The top line is first one on the main display 72039481acSNicolas Bonnefon int CrawlerWidget::getTopLine() const 73039481acSNicolas Bonnefon { 74039481acSNicolas Bonnefon return logMainView->getTopLine(); 75039481acSNicolas Bonnefon } 76039481acSNicolas Bonnefon 77039481acSNicolas Bonnefon QString CrawlerWidget::getSelectedText() const 78039481acSNicolas Bonnefon { 79039481acSNicolas Bonnefon if ( filteredView->hasFocus() ) 80039481acSNicolas Bonnefon return filteredView->getSelection(); 81039481acSNicolas Bonnefon else 82039481acSNicolas Bonnefon return logMainView->getSelection(); 83039481acSNicolas Bonnefon } 84039481acSNicolas Bonnefon 85039481acSNicolas Bonnefon void CrawlerWidget::selectAll() 86039481acSNicolas Bonnefon { 87039481acSNicolas Bonnefon activeView()->selectAll(); 88039481acSNicolas Bonnefon } 89039481acSNicolas Bonnefon 90039481acSNicolas Bonnefon // Return a pointer to the view in which we should do the QuickFind 91b423cd88SNicolas Bonnefon SearchableWidgetInterface* CrawlerWidget::doGetActiveSearchable() const 92039481acSNicolas Bonnefon { 93b423cd88SNicolas Bonnefon return activeView(); 94b423cd88SNicolas Bonnefon } 95039481acSNicolas Bonnefon 96b423cd88SNicolas Bonnefon // Return all the searchable widgets (views) 97b423cd88SNicolas Bonnefon std::vector<QObject*> CrawlerWidget::doGetAllSearchables() const 98b423cd88SNicolas Bonnefon { 99b423cd88SNicolas Bonnefon std::vector<QObject*> searchables = 100b423cd88SNicolas Bonnefon { logMainView, filteredView }; 101039481acSNicolas Bonnefon 102b423cd88SNicolas Bonnefon return searchables; 103039481acSNicolas Bonnefon } 104039481acSNicolas Bonnefon 1059cacd6a9SNicolas Bonnefon // Update the state of the parent 1069cacd6a9SNicolas Bonnefon void CrawlerWidget::doSendAllStateSignals() 1079cacd6a9SNicolas Bonnefon { 1089cacd6a9SNicolas Bonnefon emit updateLineNumber( currentLineNumber_ ); 10960864ff5SNicolas Bonnefon if ( !loadingInProgress_ ) 110*812146a8SNicolas Bonnefon emit loadingFinished( LoadingStatus::Successful ); 1119cacd6a9SNicolas Bonnefon } 1129cacd6a9SNicolas Bonnefon 1137847299cSNicolas Bonnefon // 1147847299cSNicolas Bonnefon // Public slots 1157847299cSNicolas Bonnefon // 1167847299cSNicolas Bonnefon 1177847299cSNicolas Bonnefon void CrawlerWidget::stopLoading() 1187847299cSNicolas Bonnefon { 1197847299cSNicolas Bonnefon logFilteredData_->interruptSearch(); 1207847299cSNicolas Bonnefon logData_->interruptLoading(); 1217847299cSNicolas Bonnefon } 1227847299cSNicolas Bonnefon 12332e44cfdSNicolas Bonnefon void CrawlerWidget::reload() 12432e44cfdSNicolas Bonnefon { 12532e44cfdSNicolas Bonnefon searchState_.resetState(); 12632e44cfdSNicolas Bonnefon logFilteredData_->clearSearch(); 12732e44cfdSNicolas Bonnefon filteredView->updateData(); 12832e44cfdSNicolas Bonnefon printSearchInfoMessage(); 12932e44cfdSNicolas Bonnefon 13032e44cfdSNicolas Bonnefon logData_->reload(); 13132e44cfdSNicolas Bonnefon } 13232e44cfdSNicolas Bonnefon 133039481acSNicolas Bonnefon // 134039481acSNicolas Bonnefon // Protected functions 135039481acSNicolas Bonnefon // 136039481acSNicolas Bonnefon void CrawlerWidget::doSetData( 137039481acSNicolas Bonnefon std::shared_ptr<LogData> log_data, 138039481acSNicolas Bonnefon std::shared_ptr<LogFilteredData> filtered_data ) 139039481acSNicolas Bonnefon { 140039481acSNicolas Bonnefon logData_ = log_data.get(); 141039481acSNicolas Bonnefon logFilteredData_ = filtered_data.get(); 1421b5e406eSNicolas Bonnefon } 143039481acSNicolas Bonnefon 144b423cd88SNicolas Bonnefon void CrawlerWidget::doSetQuickFindPattern( 145b423cd88SNicolas Bonnefon std::shared_ptr<QuickFindPattern> qfp ) 146b423cd88SNicolas Bonnefon { 147b423cd88SNicolas Bonnefon quickFindPattern_ = qfp; 148b423cd88SNicolas Bonnefon } 149b423cd88SNicolas Bonnefon 1501b5e406eSNicolas Bonnefon void CrawlerWidget::doSetSavedSearches( 1511b5e406eSNicolas Bonnefon std::shared_ptr<SavedSearches> saved_searches ) 1521b5e406eSNicolas Bonnefon { 1531b5e406eSNicolas Bonnefon savedSearches_ = saved_searches; 1541b5e406eSNicolas Bonnefon 1551b5e406eSNicolas Bonnefon // We do setup now, assuming doSetData has been called before 1561b5e406eSNicolas Bonnefon // us, that's not great really... 157039481acSNicolas Bonnefon setup(); 158039481acSNicolas Bonnefon } 159039481acSNicolas Bonnefon 160039481acSNicolas Bonnefon // 161039481acSNicolas Bonnefon // Slots 162039481acSNicolas Bonnefon // 163039481acSNicolas Bonnefon 164039481acSNicolas Bonnefon void CrawlerWidget::startNewSearch() 165039481acSNicolas Bonnefon { 166039481acSNicolas Bonnefon // Record the search line in the recent list 167039481acSNicolas Bonnefon // (reload the list first in case another glogg changed it) 168039481acSNicolas Bonnefon GetPersistentInfo().retrieve( "savedSearches" ); 1691b5e406eSNicolas Bonnefon savedSearches_->addRecent( searchLineEdit->currentText() ); 170039481acSNicolas Bonnefon GetPersistentInfo().save( "savedSearches" ); 171039481acSNicolas Bonnefon 172039481acSNicolas Bonnefon // Update the SearchLine (history) 173039481acSNicolas Bonnefon updateSearchCombo(); 174039481acSNicolas Bonnefon // Call the private function to do the search 175039481acSNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() ); 176039481acSNicolas Bonnefon } 177039481acSNicolas Bonnefon 178039481acSNicolas Bonnefon void CrawlerWidget::stopSearch() 179039481acSNicolas Bonnefon { 180039481acSNicolas Bonnefon logFilteredData_->interruptSearch(); 181039481acSNicolas Bonnefon searchState_.stopSearch(); 182039481acSNicolas Bonnefon printSearchInfoMessage(); 183039481acSNicolas Bonnefon } 184039481acSNicolas Bonnefon 185039481acSNicolas Bonnefon // When receiving the 'newDataAvailable' signal from LogFilteredData 186039481acSNicolas Bonnefon void CrawlerWidget::updateFilteredView( int nbMatches, int progress ) 187039481acSNicolas Bonnefon { 188039481acSNicolas Bonnefon LOG(logDEBUG) << "updateFilteredView received."; 189039481acSNicolas Bonnefon 190039481acSNicolas Bonnefon if ( progress == 100 ) { 191039481acSNicolas Bonnefon // Searching done 192039481acSNicolas Bonnefon printSearchInfoMessage( nbMatches ); 193039481acSNicolas Bonnefon searchInfoLine->hideGauge(); 194039481acSNicolas Bonnefon // De-activate the stop button 195039481acSNicolas Bonnefon stopButton->setEnabled( false ); 196039481acSNicolas Bonnefon } 197039481acSNicolas Bonnefon else { 198039481acSNicolas Bonnefon // Search in progress 199039481acSNicolas Bonnefon // We ignore 0% and 100% to avoid a flash when the search is very short 200039481acSNicolas Bonnefon if ( progress > 0 ) { 201039481acSNicolas Bonnefon searchInfoLine->setText( 202039481acSNicolas Bonnefon tr("Search in progress (%1 %)... %2 match%3 found so far.") 203039481acSNicolas Bonnefon .arg( progress ) 204039481acSNicolas Bonnefon .arg( nbMatches ) 205039481acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ) ); 206039481acSNicolas Bonnefon searchInfoLine->displayGauge( progress ); 207039481acSNicolas Bonnefon } 208039481acSNicolas Bonnefon } 209039481acSNicolas Bonnefon 210039481acSNicolas Bonnefon // Recompute the content of the filtered window. 211039481acSNicolas Bonnefon filteredView->updateData(); 212039481acSNicolas Bonnefon 213039481acSNicolas Bonnefon // Update the match overview 2140f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 215039481acSNicolas Bonnefon 216039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 217039481acSNicolas Bonnefon update(); 218039481acSNicolas Bonnefon } 219039481acSNicolas Bonnefon 220039481acSNicolas Bonnefon void CrawlerWidget::jumpToMatchingLine(int filteredLineNb) 221039481acSNicolas Bonnefon { 222039481acSNicolas Bonnefon int mainViewLine = logFilteredData_->getMatchingLineNumber(filteredLineNb); 223039481acSNicolas Bonnefon logMainView->selectAndDisplayLine(mainViewLine); // FIXME: should be done with a signal. 224039481acSNicolas Bonnefon } 225039481acSNicolas Bonnefon 2269cacd6a9SNicolas Bonnefon void CrawlerWidget::updateLineNumberHandler( int line ) 2279cacd6a9SNicolas Bonnefon { 2289cacd6a9SNicolas Bonnefon currentLineNumber_ = line; 2299cacd6a9SNicolas Bonnefon emit updateLineNumber( line ); 2309cacd6a9SNicolas Bonnefon } 2319cacd6a9SNicolas Bonnefon 232039481acSNicolas Bonnefon void CrawlerWidget::markLineFromMain( qint64 line ) 233039481acSNicolas Bonnefon { 234039481acSNicolas Bonnefon if ( logFilteredData_->isLineMarked( line ) ) 235039481acSNicolas Bonnefon logFilteredData_->deleteMark( line ); 236039481acSNicolas Bonnefon else 237039481acSNicolas Bonnefon logFilteredData_->addMark( line ); 238039481acSNicolas Bonnefon 239039481acSNicolas Bonnefon // Recompute the content of the filtered window. 240039481acSNicolas Bonnefon filteredView->updateData(); 241039481acSNicolas Bonnefon 242039481acSNicolas Bonnefon // Update the match overview 2430f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 244039481acSNicolas Bonnefon 245039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 246039481acSNicolas Bonnefon update(); 247039481acSNicolas Bonnefon } 248039481acSNicolas Bonnefon 249039481acSNicolas Bonnefon void CrawlerWidget::markLineFromFiltered( qint64 line ) 250039481acSNicolas Bonnefon { 251039481acSNicolas Bonnefon qint64 line_in_file = logFilteredData_->getMatchingLineNumber( line ); 252039481acSNicolas Bonnefon if ( logFilteredData_->filteredLineTypeByIndex( line ) 253039481acSNicolas Bonnefon == LogFilteredData::Mark ) 254039481acSNicolas Bonnefon logFilteredData_->deleteMark( line_in_file ); 255039481acSNicolas Bonnefon else 256039481acSNicolas Bonnefon logFilteredData_->addMark( line_in_file ); 257039481acSNicolas Bonnefon 258039481acSNicolas Bonnefon // Recompute the content of the filtered window. 259039481acSNicolas Bonnefon filteredView->updateData(); 260039481acSNicolas Bonnefon 261039481acSNicolas Bonnefon // Update the match overview 2620f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 263039481acSNicolas Bonnefon 264039481acSNicolas Bonnefon // Also update the top window for the coloured bullets. 265039481acSNicolas Bonnefon update(); 266039481acSNicolas Bonnefon } 267039481acSNicolas Bonnefon 268039481acSNicolas Bonnefon void CrawlerWidget::applyConfiguration() 269039481acSNicolas Bonnefon { 27011582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 27111582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 27211582726SNicolas Bonnefon QFont font = config->mainFont(); 273039481acSNicolas Bonnefon 274039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::applyConfiguration"; 275039481acSNicolas Bonnefon 276039481acSNicolas Bonnefon // Whatever font we use, we should NOT use kerning 277039481acSNicolas Bonnefon font.setKerning( false ); 278039481acSNicolas Bonnefon font.setFixedPitch( true ); 279039481acSNicolas Bonnefon #if QT_VERSION > 0x040700 280039481acSNicolas Bonnefon // Necessary on systems doing subpixel positionning (e.g. Ubuntu 12.04) 281039481acSNicolas Bonnefon font.setStyleStrategy( QFont::ForceIntegerMetrics ); 282039481acSNicolas Bonnefon #endif 283039481acSNicolas Bonnefon logMainView->setFont(font); 284039481acSNicolas Bonnefon filteredView->setFont(font); 285039481acSNicolas Bonnefon 28611582726SNicolas Bonnefon logMainView->setLineNumbersVisible( config->mainLineNumbersVisible() ); 28711582726SNicolas Bonnefon filteredView->setLineNumbersVisible( config->filteredLineNumbersVisible() ); 288039481acSNicolas Bonnefon 28911582726SNicolas Bonnefon overview_.setVisible( config->isOverviewVisible() ); 290039481acSNicolas Bonnefon logMainView->refreshOverview(); 291039481acSNicolas Bonnefon 292039481acSNicolas Bonnefon logMainView->updateDisplaySize(); 293039481acSNicolas Bonnefon logMainView->update(); 294039481acSNicolas Bonnefon filteredView->updateDisplaySize(); 295039481acSNicolas Bonnefon filteredView->update(); 296039481acSNicolas Bonnefon 297039481acSNicolas Bonnefon // Update the SearchLine (history) 298039481acSNicolas Bonnefon updateSearchCombo(); 299039481acSNicolas Bonnefon } 300039481acSNicolas Bonnefon 3018570d8d2SNicolas Bonnefon void CrawlerWidget::enteringQuickFind() 3028570d8d2SNicolas Bonnefon { 3038570d8d2SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::enteringQuickFind"; 3048570d8d2SNicolas Bonnefon 3058570d8d2SNicolas Bonnefon // Remember who had the focus (only if it is one of our views) 3068570d8d2SNicolas Bonnefon QWidget* focus_widget = QApplication::focusWidget(); 3078570d8d2SNicolas Bonnefon 3088570d8d2SNicolas Bonnefon if ( ( focus_widget == logMainView ) || ( focus_widget == filteredView ) ) 3098570d8d2SNicolas Bonnefon qfSavedFocus_ = focus_widget; 3108570d8d2SNicolas Bonnefon else 3118570d8d2SNicolas Bonnefon qfSavedFocus_ = nullptr; 3128570d8d2SNicolas Bonnefon } 3138570d8d2SNicolas Bonnefon 3148570d8d2SNicolas Bonnefon void CrawlerWidget::exitingQuickFind() 3158570d8d2SNicolas Bonnefon { 3168570d8d2SNicolas Bonnefon // Restore the focus once the QFBar has been hidden 3178570d8d2SNicolas Bonnefon if ( qfSavedFocus_ ) 3188570d8d2SNicolas Bonnefon qfSavedFocus_->setFocus(); 3198570d8d2SNicolas Bonnefon } 3208570d8d2SNicolas Bonnefon 321*812146a8SNicolas Bonnefon void CrawlerWidget::loadingFinishedHandler( LoadingStatus status ) 322039481acSNicolas Bonnefon { 32360864ff5SNicolas Bonnefon loadingInProgress_ = false; 32460864ff5SNicolas Bonnefon 325039481acSNicolas Bonnefon // We need to refresh the main window because the view lines on the 326039481acSNicolas Bonnefon // overview have probably changed. 3270f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() ); 328039481acSNicolas Bonnefon 329039481acSNicolas Bonnefon // FIXME, handle topLine 330039481acSNicolas Bonnefon // logMainView->updateData( logData_, topLine ); 331039481acSNicolas Bonnefon logMainView->updateData(); 332039481acSNicolas Bonnefon 333039481acSNicolas Bonnefon // Shall we Forbid starting a search when loading in progress? 334039481acSNicolas Bonnefon // searchButton->setEnabled( false ); 335039481acSNicolas Bonnefon 336039481acSNicolas Bonnefon // searchButton->setEnabled( true ); 337039481acSNicolas Bonnefon 338039481acSNicolas Bonnefon // See if we need to auto-refresh the search 339039481acSNicolas Bonnefon if ( searchState_.isAutorefreshAllowed() ) { 340039481acSNicolas Bonnefon LOG(logDEBUG) << "Refreshing the search"; 341039481acSNicolas Bonnefon logFilteredData_->updateSearch(); 342039481acSNicolas Bonnefon } 343039481acSNicolas Bonnefon 344*812146a8SNicolas Bonnefon emit loadingFinished( status ); 345039481acSNicolas Bonnefon } 346039481acSNicolas Bonnefon 347039481acSNicolas Bonnefon void CrawlerWidget::fileChangedHandler( LogData::MonitoredFileStatus status ) 348039481acSNicolas Bonnefon { 349039481acSNicolas Bonnefon // Handle the case where the file has been truncated 350039481acSNicolas Bonnefon if ( status == LogData::Truncated ) { 351039481acSNicolas Bonnefon // Clear all marks (TODO offer the option to keep them) 352039481acSNicolas Bonnefon logFilteredData_->clearMarks(); 353039481acSNicolas Bonnefon if ( ! searchInfoLine->text().isEmpty() ) { 354039481acSNicolas Bonnefon // Invalidate the search 355039481acSNicolas Bonnefon logFilteredData_->clearSearch(); 356039481acSNicolas Bonnefon filteredView->updateData(); 357039481acSNicolas Bonnefon searchState_.truncateFile(); 358039481acSNicolas Bonnefon printSearchInfoMessage(); 359039481acSNicolas Bonnefon } 360039481acSNicolas Bonnefon } 361039481acSNicolas Bonnefon } 362039481acSNicolas Bonnefon 363039481acSNicolas Bonnefon // Returns a pointer to the window in which the search should be done 364039481acSNicolas Bonnefon AbstractLogView* CrawlerWidget::activeView() const 365039481acSNicolas Bonnefon { 366039481acSNicolas Bonnefon QWidget* activeView; 367039481acSNicolas Bonnefon 368039481acSNicolas Bonnefon // Search in the window that has focus, or the window where 'Find' was 369039481acSNicolas Bonnefon // called from, or the main window. 370039481acSNicolas Bonnefon if ( filteredView->hasFocus() || logMainView->hasFocus() ) 371039481acSNicolas Bonnefon activeView = QApplication::focusWidget(); 372039481acSNicolas Bonnefon else 3738570d8d2SNicolas Bonnefon activeView = qfSavedFocus_; 374039481acSNicolas Bonnefon 375b423cd88SNicolas Bonnefon if ( activeView ) { 376b423cd88SNicolas Bonnefon AbstractLogView* view = qobject_cast<AbstractLogView*>( activeView ); 377039481acSNicolas Bonnefon return view; 378b423cd88SNicolas Bonnefon } 379b423cd88SNicolas Bonnefon else { 380b423cd88SNicolas Bonnefon LOG(logWARNING) << "No active view, defaulting to logMainView"; 381039481acSNicolas Bonnefon return logMainView; 382039481acSNicolas Bonnefon } 383b423cd88SNicolas Bonnefon } 384039481acSNicolas Bonnefon 385039481acSNicolas Bonnefon void CrawlerWidget::searchForward() 386039481acSNicolas Bonnefon { 387039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchForward"; 388039481acSNicolas Bonnefon 389039481acSNicolas Bonnefon activeView()->searchForward(); 390039481acSNicolas Bonnefon } 391039481acSNicolas Bonnefon 392039481acSNicolas Bonnefon void CrawlerWidget::searchBackward() 393039481acSNicolas Bonnefon { 394039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchBackward"; 395039481acSNicolas Bonnefon 396039481acSNicolas Bonnefon activeView()->searchBackward(); 397039481acSNicolas Bonnefon } 398039481acSNicolas Bonnefon 399039481acSNicolas Bonnefon void CrawlerWidget::searchRefreshChangedHandler( int state ) 400039481acSNicolas Bonnefon { 401039481acSNicolas Bonnefon searchState_.setAutorefresh( state == Qt::Checked ); 402039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 403039481acSNicolas Bonnefon } 404039481acSNicolas Bonnefon 405039481acSNicolas Bonnefon void CrawlerWidget::searchTextChangeHandler() 406039481acSNicolas Bonnefon { 407039481acSNicolas Bonnefon // We suspend auto-refresh 408039481acSNicolas Bonnefon searchState_.changeExpression(); 409039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 410039481acSNicolas Bonnefon } 411039481acSNicolas Bonnefon 412039481acSNicolas Bonnefon void CrawlerWidget::changeFilteredViewVisibility( int index ) 413039481acSNicolas Bonnefon { 414039481acSNicolas Bonnefon QStandardItem* item = visibilityModel_->item( index ); 415039481acSNicolas Bonnefon FilteredView::Visibility visibility = 416039481acSNicolas Bonnefon static_cast< FilteredView::Visibility>( item->data().toInt() ); 417039481acSNicolas Bonnefon 418039481acSNicolas Bonnefon filteredView->setVisibility( visibility ); 419039481acSNicolas Bonnefon } 420039481acSNicolas Bonnefon 421039481acSNicolas Bonnefon void CrawlerWidget::addToSearch( const QString& string ) 422039481acSNicolas Bonnefon { 423039481acSNicolas Bonnefon QString text = searchLineEdit->currentText(); 424039481acSNicolas Bonnefon 425039481acSNicolas Bonnefon if ( text.isEmpty() ) 426039481acSNicolas Bonnefon text = string; 427039481acSNicolas Bonnefon else { 428039481acSNicolas Bonnefon // Escape the regexp chars from the string before adding it. 429039481acSNicolas Bonnefon text += ( '|' + QRegExp::escape( string ) ); 430039481acSNicolas Bonnefon } 431039481acSNicolas Bonnefon 432039481acSNicolas Bonnefon searchLineEdit->setEditText( text ); 433039481acSNicolas Bonnefon 434039481acSNicolas Bonnefon // Set the focus to lineEdit so that the user can press 'Return' immediately 435039481acSNicolas Bonnefon searchLineEdit->lineEdit()->setFocus(); 436039481acSNicolas Bonnefon } 437039481acSNicolas Bonnefon 438039481acSNicolas Bonnefon void CrawlerWidget::mouseHoveredOverMatch( qint64 line ) 439039481acSNicolas Bonnefon { 440039481acSNicolas Bonnefon qint64 line_in_mainview = logFilteredData_->getMatchingLineNumber( line ); 441039481acSNicolas Bonnefon 442039481acSNicolas Bonnefon overviewWidget_->highlightLine( line_in_mainview ); 443039481acSNicolas Bonnefon } 444039481acSNicolas Bonnefon 445039481acSNicolas Bonnefon // 446039481acSNicolas Bonnefon // Private functions 447039481acSNicolas Bonnefon // 448039481acSNicolas Bonnefon 449039481acSNicolas Bonnefon // Build the widget and connect all the signals, this must be done once 450039481acSNicolas Bonnefon // the data are attached. 451039481acSNicolas Bonnefon void CrawlerWidget::setup() 452039481acSNicolas Bonnefon { 453bb02e0acSNicolas Bonnefon setOrientation(Qt::Vertical); 454bb02e0acSNicolas Bonnefon 455039481acSNicolas Bonnefon assert( logData_ ); 456039481acSNicolas Bonnefon assert( logFilteredData_ ); 457bb02e0acSNicolas Bonnefon 458bb02e0acSNicolas Bonnefon // The views 459bb02e0acSNicolas Bonnefon bottomWindow = new QWidget; 460bb02e0acSNicolas Bonnefon overviewWidget_ = new OverviewWidget(); 461bb02e0acSNicolas Bonnefon logMainView = new LogMainView( 4620f9fd9edSNicolas Bonnefon logData_, quickFindPattern_.get(), &overview_, overviewWidget_ ); 463bb02e0acSNicolas Bonnefon filteredView = new FilteredView( 464b423cd88SNicolas Bonnefon logFilteredData_, quickFindPattern_.get() ); 465bb02e0acSNicolas Bonnefon 4660f9fd9edSNicolas Bonnefon overviewWidget_->setOverview( &overview_ ); 467bb02e0acSNicolas Bonnefon overviewWidget_->setParent( logMainView ); 468bb02e0acSNicolas Bonnefon 469bb02e0acSNicolas Bonnefon // Construct the visibility button 470bb02e0acSNicolas Bonnefon visibilityModel_ = new QStandardItemModel( this ); 471bb02e0acSNicolas Bonnefon 472bb02e0acSNicolas Bonnefon QStandardItem *marksAndMatchesItem = new QStandardItem( tr( "Marks and matches" ) ); 473bb02e0acSNicolas Bonnefon QPixmap marksAndMatchesPixmap( 16, 10 ); 474bb02e0acSNicolas Bonnefon marksAndMatchesPixmap.fill( Qt::gray ); 475bb02e0acSNicolas Bonnefon marksAndMatchesItem->setIcon( QIcon( marksAndMatchesPixmap ) ); 476bb02e0acSNicolas Bonnefon marksAndMatchesItem->setData( FilteredView::MarksAndMatches ); 477bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksAndMatchesItem ); 478bb02e0acSNicolas Bonnefon 479bb02e0acSNicolas Bonnefon QStandardItem *marksItem = new QStandardItem( tr( "Marks" ) ); 480bb02e0acSNicolas Bonnefon QPixmap marksPixmap( 16, 10 ); 481bb02e0acSNicolas Bonnefon marksPixmap.fill( Qt::blue ); 482bb02e0acSNicolas Bonnefon marksItem->setIcon( QIcon( marksPixmap ) ); 483bb02e0acSNicolas Bonnefon marksItem->setData( FilteredView::MarksOnly ); 484bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksItem ); 485bb02e0acSNicolas Bonnefon 486bb02e0acSNicolas Bonnefon QStandardItem *matchesItem = new QStandardItem( tr( "Matches" ) ); 487bb02e0acSNicolas Bonnefon QPixmap matchesPixmap( 16, 10 ); 488bb02e0acSNicolas Bonnefon matchesPixmap.fill( Qt::red ); 489bb02e0acSNicolas Bonnefon matchesItem->setIcon( QIcon( matchesPixmap ) ); 490bb02e0acSNicolas Bonnefon matchesItem->setData( FilteredView::MatchesOnly ); 491bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( matchesItem ); 492bb02e0acSNicolas Bonnefon 493bb02e0acSNicolas Bonnefon QListView *visibilityView = new QListView( this ); 494bb02e0acSNicolas Bonnefon visibilityView->setMovement( QListView::Static ); 495bb02e0acSNicolas Bonnefon visibilityView->setMinimumWidth( 170 ); // Only needed with custom style-sheet 496bb02e0acSNicolas Bonnefon 497bb02e0acSNicolas Bonnefon visibilityBox = new QComboBox(); 498bb02e0acSNicolas Bonnefon visibilityBox->setModel( visibilityModel_ ); 499bb02e0acSNicolas Bonnefon visibilityBox->setView( visibilityView ); 500bb02e0acSNicolas Bonnefon 501bb02e0acSNicolas Bonnefon // Select "Marks and matches" by default (same default as the filtered view) 502bb02e0acSNicolas Bonnefon visibilityBox->setCurrentIndex( 0 ); 503bb02e0acSNicolas Bonnefon 504bb02e0acSNicolas Bonnefon // TODO: Maybe there is some way to set the popup width to be 505bb02e0acSNicolas Bonnefon // sized-to-content (as it is when the stylesheet is not overriden) in the 506bb02e0acSNicolas Bonnefon // stylesheet as opposed to setting a hard min-width on the view above. 507bb02e0acSNicolas Bonnefon visibilityBox->setStyleSheet( " \ 508bb02e0acSNicolas Bonnefon QComboBox:on {\ 509bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 6px;\ 510bb02e0acSNicolas Bonnefon width: 19px;\ 511bb02e0acSNicolas Bonnefon } \ 512bb02e0acSNicolas Bonnefon QComboBox:!on {\ 513bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 7px;\ 514bb02e0acSNicolas Bonnefon width: 19px;\ 515bb02e0acSNicolas Bonnefon height: 16px;\ 516bb02e0acSNicolas Bonnefon border: 1px solid gray;\ 517bb02e0acSNicolas Bonnefon } \ 518bb02e0acSNicolas Bonnefon QComboBox::drop-down::down-arrow {\ 519bb02e0acSNicolas Bonnefon width: 0px;\ 520bb02e0acSNicolas Bonnefon border-width: 0px;\ 521bb02e0acSNicolas Bonnefon } \ 522bb02e0acSNicolas Bonnefon " ); 523bb02e0acSNicolas Bonnefon 524bb02e0acSNicolas Bonnefon // Construct the Search Info line 525bb02e0acSNicolas Bonnefon searchInfoLine = new InfoLine(); 526bb02e0acSNicolas Bonnefon searchInfoLine->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 527bb02e0acSNicolas Bonnefon searchInfoLine->setLineWidth( 1 ); 528bb02e0acSNicolas Bonnefon searchInfoLineDefaultPalette = searchInfoLine->palette(); 529bb02e0acSNicolas Bonnefon 530bb02e0acSNicolas Bonnefon ignoreCaseCheck = new QCheckBox( "Ignore &case" ); 531bb02e0acSNicolas Bonnefon searchRefreshCheck = new QCheckBox( "Auto-&refresh" ); 532bb02e0acSNicolas Bonnefon 533bb02e0acSNicolas Bonnefon // Construct the Search line 534bb02e0acSNicolas Bonnefon searchLabel = new QLabel(tr("&Text: ")); 535bb02e0acSNicolas Bonnefon searchLineEdit = new QComboBox; 536bb02e0acSNicolas Bonnefon searchLineEdit->setEditable( true ); 537bb02e0acSNicolas Bonnefon searchLineEdit->setCompleter( 0 ); 5381b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() ); 539bb02e0acSNicolas Bonnefon searchLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); 540bb02e0acSNicolas Bonnefon searchLineEdit->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon ); 541bb02e0acSNicolas Bonnefon 542bb02e0acSNicolas Bonnefon searchLabel->setBuddy( searchLineEdit ); 543bb02e0acSNicolas Bonnefon 544bb02e0acSNicolas Bonnefon searchButton = new QToolButton(); 545bb02e0acSNicolas Bonnefon searchButton->setText( tr("&Search") ); 546bb02e0acSNicolas Bonnefon searchButton->setAutoRaise( true ); 547bb02e0acSNicolas Bonnefon 548bb02e0acSNicolas Bonnefon stopButton = new QToolButton(); 549bb02e0acSNicolas Bonnefon stopButton->setIcon( QIcon(":/images/stop16.png") ); 550bb02e0acSNicolas Bonnefon stopButton->setAutoRaise( true ); 551bb02e0acSNicolas Bonnefon stopButton->setEnabled( false ); 552bb02e0acSNicolas Bonnefon 553bb02e0acSNicolas Bonnefon QHBoxLayout* searchLineLayout = new QHBoxLayout; 554bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLabel); 555bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLineEdit); 556bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchButton); 557bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(stopButton); 558bb02e0acSNicolas Bonnefon searchLineLayout->setContentsMargins(6, 0, 6, 0); 559bb02e0acSNicolas Bonnefon stopButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 560bb02e0acSNicolas Bonnefon searchButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 561bb02e0acSNicolas Bonnefon 562bb02e0acSNicolas Bonnefon QHBoxLayout* searchInfoLineLayout = new QHBoxLayout; 563bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( visibilityBox ); 564bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchInfoLine ); 565bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( ignoreCaseCheck ); 566bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchRefreshCheck ); 567bb02e0acSNicolas Bonnefon 568bb02e0acSNicolas Bonnefon // Construct the bottom window 569bb02e0acSNicolas Bonnefon QVBoxLayout* bottomMainLayout = new QVBoxLayout; 570bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchLineLayout); 571bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchInfoLineLayout); 572bb02e0acSNicolas Bonnefon bottomMainLayout->addWidget(filteredView); 573bb02e0acSNicolas Bonnefon bottomMainLayout->setContentsMargins(2, 1, 2, 1); 574bb02e0acSNicolas Bonnefon bottomWindow->setLayout(bottomMainLayout); 575bb02e0acSNicolas Bonnefon 576bb02e0acSNicolas Bonnefon addWidget( logMainView ); 577bb02e0acSNicolas Bonnefon addWidget( bottomWindow ); 578bb02e0acSNicolas Bonnefon 579bb02e0acSNicolas Bonnefon // Default splitter position (usually overridden by the config file) 580bb02e0acSNicolas Bonnefon QList<int> splitterSizes; 581bb02e0acSNicolas Bonnefon splitterSizes += 400; 582bb02e0acSNicolas Bonnefon splitterSizes += 100; 583bb02e0acSNicolas Bonnefon setSizes( splitterSizes ); 584bb02e0acSNicolas Bonnefon 585bb02e0acSNicolas Bonnefon // Connect the signals 586bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( returnPressed() ), 587bb02e0acSNicolas Bonnefon searchButton, SIGNAL( clicked() )); 588bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( textEdited( const QString& ) ), 589bb02e0acSNicolas Bonnefon this, SLOT( searchTextChangeHandler() )); 590bb02e0acSNicolas Bonnefon connect(searchButton, SIGNAL( clicked() ), 591bb02e0acSNicolas Bonnefon this, SLOT( startNewSearch() ) ); 592bb02e0acSNicolas Bonnefon connect(stopButton, SIGNAL( clicked() ), 593bb02e0acSNicolas Bonnefon this, SLOT( stopSearch() ) ); 594bb02e0acSNicolas Bonnefon 595bb02e0acSNicolas Bonnefon connect(visibilityBox, SIGNAL( currentIndexChanged( int ) ), 596bb02e0acSNicolas Bonnefon this, SLOT( changeFilteredViewVisibility( int ) ) ); 597bb02e0acSNicolas Bonnefon 598bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( newSelection( int ) ), 599bb02e0acSNicolas Bonnefon logMainView, SLOT( update() ) ); 600bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 601bb02e0acSNicolas Bonnefon this, SLOT( jumpToMatchingLine( int ) ) ); 602bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 603bb02e0acSNicolas Bonnefon filteredView, SLOT( update() ) ); 604bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( updateLineNumber( int ) ), 6059cacd6a9SNicolas Bonnefon this, SLOT( updateLineNumberHandler( int ) ) ); 606bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( markLine( qint64 ) ), 607bb02e0acSNicolas Bonnefon this, SLOT( markLineFromMain( qint64 ) ) ); 608bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( markLine( qint64 ) ), 609bb02e0acSNicolas Bonnefon this, SLOT( markLineFromFiltered( qint64 ) ) ); 610bb02e0acSNicolas Bonnefon 611bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( addToSearch( const QString& ) ), 612bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 613bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( addToSearch( const QString& ) ), 614bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 615bb02e0acSNicolas Bonnefon 616bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseHoveredOverLine( qint64 ) ), 617bb02e0acSNicolas Bonnefon this, SLOT( mouseHoveredOverMatch( qint64 ) ) ); 618bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseLeftHoveringZone() ), 619bb02e0acSNicolas Bonnefon overviewWidget_, SLOT( removeHighlight() ) ); 620bb02e0acSNicolas Bonnefon 621bb02e0acSNicolas Bonnefon // Follow option (up and down) 622bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 623bb02e0acSNicolas Bonnefon logMainView, SLOT( followSet( bool ) ) ); 624bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 625bb02e0acSNicolas Bonnefon filteredView, SLOT( followSet( bool ) ) ); 626bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( followDisabled() ), 627bb02e0acSNicolas Bonnefon this, SIGNAL( followDisabled() ) ); 628bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( followDisabled() ), 629bb02e0acSNicolas Bonnefon this, SIGNAL( followDisabled() ) ); 630bb02e0acSNicolas Bonnefon 631bb02e0acSNicolas Bonnefon connect( logFilteredData_, SIGNAL( searchProgressed( int, int ) ), 632bb02e0acSNicolas Bonnefon this, SLOT( updateFilteredView( int, int ) ) ); 633bb02e0acSNicolas Bonnefon 634bb02e0acSNicolas Bonnefon // Sent load file update to MainWindow (for status update) 635bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( loadingProgressed( int ) ), 636bb02e0acSNicolas Bonnefon this, SIGNAL( loadingProgressed( int ) ) ); 637*812146a8SNicolas Bonnefon connect( logData_, SIGNAL( loadingFinished( LoadingStatus ) ), 638*812146a8SNicolas Bonnefon this, SLOT( loadingFinishedHandler( LoadingStatus ) ) ); 639bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( fileChanged( LogData::MonitoredFileStatus ) ), 640bb02e0acSNicolas Bonnefon this, SLOT( fileChangedHandler( LogData::MonitoredFileStatus ) ) ); 641bb02e0acSNicolas Bonnefon 642bb02e0acSNicolas Bonnefon // Search auto-refresh 643bb02e0acSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ), 644bb02e0acSNicolas Bonnefon this, SLOT( searchRefreshChangedHandler( int ) ) ); 645bb02e0acSNicolas Bonnefon } 646bb02e0acSNicolas Bonnefon 647bb02e0acSNicolas Bonnefon // Create a new search using the text passed, replace the currently 648bb02e0acSNicolas Bonnefon // used one and destroy the old one. 649bb02e0acSNicolas Bonnefon void CrawlerWidget::replaceCurrentSearch( const QString& searchText ) 650bb02e0acSNicolas Bonnefon { 651bb02e0acSNicolas Bonnefon // Interrupt the search if it's ongoing 652bb02e0acSNicolas Bonnefon logFilteredData_->interruptSearch(); 653bb02e0acSNicolas Bonnefon 654bb02e0acSNicolas Bonnefon // We have to wait for the last search update (100%) 655bb02e0acSNicolas Bonnefon // before clearing/restarting to avoid having remaining results. 656bb02e0acSNicolas Bonnefon 657bb02e0acSNicolas Bonnefon // FIXME: this is a bit of a hack, we call processEvents 658bb02e0acSNicolas Bonnefon // for Qt to empty its event queue, including (hopefully) 659bb02e0acSNicolas Bonnefon // the search update event sent by logFilteredData_. It saves 660bb02e0acSNicolas Bonnefon // us the overhead of having proper sync. 661bb02e0acSNicolas Bonnefon QApplication::processEvents( QEventLoop::ExcludeUserInputEvents ); 662bb02e0acSNicolas Bonnefon 663bb02e0acSNicolas Bonnefon if ( !searchText.isEmpty() ) { 664bb02e0acSNicolas Bonnefon // Determine the type of regexp depending on the config 665bb02e0acSNicolas Bonnefon QRegExp::PatternSyntax syntax; 66611582726SNicolas Bonnefon static std::shared_ptr<Configuration> config = 66711582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 66811582726SNicolas Bonnefon switch ( config->mainRegexpType() ) { 669bb02e0acSNicolas Bonnefon case Wildcard: 670bb02e0acSNicolas Bonnefon syntax = QRegExp::Wildcard; 671bb02e0acSNicolas Bonnefon break; 672bb02e0acSNicolas Bonnefon case FixedString: 673bb02e0acSNicolas Bonnefon syntax = QRegExp::FixedString; 674bb02e0acSNicolas Bonnefon break; 675bb02e0acSNicolas Bonnefon default: 676bb02e0acSNicolas Bonnefon syntax = QRegExp::RegExp2; 677bb02e0acSNicolas Bonnefon break; 678bb02e0acSNicolas Bonnefon } 679bb02e0acSNicolas Bonnefon 680bb02e0acSNicolas Bonnefon // Set the pattern case insensitive if needed 681bb02e0acSNicolas Bonnefon Qt::CaseSensitivity case_sensitivity = Qt::CaseSensitive; 682bb02e0acSNicolas Bonnefon if ( ignoreCaseCheck->checkState() == Qt::Checked ) 683bb02e0acSNicolas Bonnefon case_sensitivity = Qt::CaseInsensitive; 684bb02e0acSNicolas Bonnefon 685bb02e0acSNicolas Bonnefon // Constructs the regexp 686bb02e0acSNicolas Bonnefon QRegExp regexp( searchText, case_sensitivity, syntax ); 687bb02e0acSNicolas Bonnefon 688bb02e0acSNicolas Bonnefon if ( regexp.isValid() ) { 689bb02e0acSNicolas Bonnefon // Activate the stop button 690bb02e0acSNicolas Bonnefon stopButton->setEnabled( true ); 691bb02e0acSNicolas Bonnefon // Start a new asynchronous search 692bb02e0acSNicolas Bonnefon logFilteredData_->runSearch( regexp ); 693bb02e0acSNicolas Bonnefon // Accept auto-refresh of the search 694bb02e0acSNicolas Bonnefon searchState_.startSearch(); 695bb02e0acSNicolas Bonnefon } 696bb02e0acSNicolas Bonnefon else { 697bb02e0acSNicolas Bonnefon // The regexp is wrong 698bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 699bb02e0acSNicolas Bonnefon filteredView->updateData(); 700bb02e0acSNicolas Bonnefon searchState_.resetState(); 701bb02e0acSNicolas Bonnefon 702bb02e0acSNicolas Bonnefon // Inform the user 703bb02e0acSNicolas Bonnefon QString errorMessage = tr("Error in expression: "); 704bb02e0acSNicolas Bonnefon errorMessage += regexp.errorString(); 705bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( errorPalette ); 706bb02e0acSNicolas Bonnefon searchInfoLine->setText( errorMessage ); 707bb02e0acSNicolas Bonnefon } 708bb02e0acSNicolas Bonnefon } 709bb02e0acSNicolas Bonnefon else { 710bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 711bb02e0acSNicolas Bonnefon filteredView->updateData(); 712bb02e0acSNicolas Bonnefon searchState_.resetState(); 713bb02e0acSNicolas Bonnefon printSearchInfoMessage(); 714bb02e0acSNicolas Bonnefon } 715bb02e0acSNicolas Bonnefon // Connect the search to the top view 716bb02e0acSNicolas Bonnefon logMainView->useNewFiltering( logFilteredData_ ); 717bb02e0acSNicolas Bonnefon } 718bb02e0acSNicolas Bonnefon 719bb02e0acSNicolas Bonnefon // Updates the content of the drop down list for the saved searches, 720bb02e0acSNicolas Bonnefon // called when the SavedSearch has been changed. 721bb02e0acSNicolas Bonnefon void CrawlerWidget::updateSearchCombo() 722bb02e0acSNicolas Bonnefon { 723bb02e0acSNicolas Bonnefon const QString text = searchLineEdit->lineEdit()->text(); 724bb02e0acSNicolas Bonnefon searchLineEdit->clear(); 7251b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() ); 726bb02e0acSNicolas Bonnefon // In case we had something that wasn't added to the list (blank...): 727bb02e0acSNicolas Bonnefon searchLineEdit->lineEdit()->setText( text ); 728bb02e0acSNicolas Bonnefon } 729bb02e0acSNicolas Bonnefon 730bb02e0acSNicolas Bonnefon // Print the search info message. 731bb02e0acSNicolas Bonnefon void CrawlerWidget::printSearchInfoMessage( int nbMatches ) 732bb02e0acSNicolas Bonnefon { 733bb02e0acSNicolas Bonnefon QString text; 734bb02e0acSNicolas Bonnefon 735bb02e0acSNicolas Bonnefon switch ( searchState_.getState() ) { 736bb02e0acSNicolas Bonnefon case SearchState::NoSearch: 737bb02e0acSNicolas Bonnefon // Blank text is fine 738bb02e0acSNicolas Bonnefon break; 739bb02e0acSNicolas Bonnefon case SearchState::Static: 740bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found.").arg( nbMatches ) 741bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 742bb02e0acSNicolas Bonnefon break; 743bb02e0acSNicolas Bonnefon case SearchState::Autorefreshing: 744bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found. Search is auto-refreshing...").arg( nbMatches ) 745bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 746bb02e0acSNicolas Bonnefon break; 747bb02e0acSNicolas Bonnefon case SearchState::FileTruncated: 748bb02e0acSNicolas Bonnefon text = tr("File truncated on disk, previous search results are not valid anymore."); 749bb02e0acSNicolas Bonnefon break; 750bb02e0acSNicolas Bonnefon } 751bb02e0acSNicolas Bonnefon 752bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( searchInfoLineDefaultPalette ); 753bb02e0acSNicolas Bonnefon searchInfoLine->setText( text ); 754bb02e0acSNicolas Bonnefon } 755bb02e0acSNicolas Bonnefon 756bb02e0acSNicolas Bonnefon // 757bb02e0acSNicolas Bonnefon // SearchState implementation 758bb02e0acSNicolas Bonnefon // 759bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::resetState() 760bb02e0acSNicolas Bonnefon { 761bb02e0acSNicolas Bonnefon state_ = NoSearch; 762bb02e0acSNicolas Bonnefon } 763bb02e0acSNicolas Bonnefon 764bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::setAutorefresh( bool refresh ) 765bb02e0acSNicolas Bonnefon { 766bb02e0acSNicolas Bonnefon autoRefreshRequested_ = refresh; 767bb02e0acSNicolas Bonnefon 768bb02e0acSNicolas Bonnefon if ( refresh ) { 769bb02e0acSNicolas Bonnefon if ( state_ == Static ) 770bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 771bb02e0acSNicolas Bonnefon } 772bb02e0acSNicolas Bonnefon else { 773bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 774bb02e0acSNicolas Bonnefon state_ = Static; 775bb02e0acSNicolas Bonnefon } 776bb02e0acSNicolas Bonnefon } 777bb02e0acSNicolas Bonnefon 778bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::truncateFile() 779bb02e0acSNicolas Bonnefon { 780bb02e0acSNicolas Bonnefon state_ = FileTruncated; 781bb02e0acSNicolas Bonnefon } 782bb02e0acSNicolas Bonnefon 783bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::changeExpression() 784bb02e0acSNicolas Bonnefon { 785bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 786bb02e0acSNicolas Bonnefon state_ = Static; 787bb02e0acSNicolas Bonnefon } 788bb02e0acSNicolas Bonnefon 789bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::stopSearch() 790bb02e0acSNicolas Bonnefon { 791bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 792bb02e0acSNicolas Bonnefon state_ = Static; 793bb02e0acSNicolas Bonnefon } 794bb02e0acSNicolas Bonnefon 795bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::startSearch() 796bb02e0acSNicolas Bonnefon { 797bb02e0acSNicolas Bonnefon if ( autoRefreshRequested_ ) 798bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 799bb02e0acSNicolas Bonnefon else 800bb02e0acSNicolas Bonnefon state_ = Static; 801bb02e0acSNicolas Bonnefon } 802