1*bb02e0acSNicolas Bonnefon /* 2*bb02e0acSNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicolas Bonnefon and other contributors 3*bb02e0acSNicolas Bonnefon * 4*bb02e0acSNicolas Bonnefon * This file is part of glogg. 5*bb02e0acSNicolas Bonnefon * 6*bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7*bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8*bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9*bb02e0acSNicolas Bonnefon * (at your option) any later version. 10*bb02e0acSNicolas Bonnefon * 11*bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12*bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15*bb02e0acSNicolas Bonnefon * 16*bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17*bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18*bb02e0acSNicolas Bonnefon */ 19*bb02e0acSNicolas Bonnefon 20*bb02e0acSNicolas Bonnefon // This file implements the CrawlerWidget class. 21*bb02e0acSNicolas Bonnefon // It is responsible for creating and managing the two views and all 22*bb02e0acSNicolas Bonnefon // the UI elements. It implements the connection between the UI elements. 23*bb02e0acSNicolas Bonnefon // It also owns the sets of data (full and filtered). 24*bb02e0acSNicolas Bonnefon 25*bb02e0acSNicolas Bonnefon #include "log.h" 26*bb02e0acSNicolas Bonnefon 27*bb02e0acSNicolas Bonnefon #include <Qt> 28*bb02e0acSNicolas Bonnefon #include <QApplication> 29*bb02e0acSNicolas Bonnefon #include <QFile> 30*bb02e0acSNicolas Bonnefon #include <QLineEdit> 31*bb02e0acSNicolas Bonnefon #include <QFileInfo> 32*bb02e0acSNicolas Bonnefon #include <QKeyEvent> 33*bb02e0acSNicolas Bonnefon #include <QStandardItemModel> 34*bb02e0acSNicolas Bonnefon #include <QHeaderView> 35*bb02e0acSNicolas Bonnefon #include <QListView> 36*bb02e0acSNicolas Bonnefon 37*bb02e0acSNicolas Bonnefon #include "crawlerwidget.h" 38*bb02e0acSNicolas Bonnefon 39*bb02e0acSNicolas Bonnefon #include "quickfindpattern.h" 40*bb02e0acSNicolas Bonnefon #include "overview.h" 41*bb02e0acSNicolas Bonnefon #include "infoline.h" 42*bb02e0acSNicolas Bonnefon #include "savedsearches.h" 43*bb02e0acSNicolas Bonnefon #include "quickfindwidget.h" 44*bb02e0acSNicolas Bonnefon #include "persistentinfo.h" 45*bb02e0acSNicolas Bonnefon #include "configuration.h" 46*bb02e0acSNicolas Bonnefon 47*bb02e0acSNicolas Bonnefon // Palette for error signaling (yellow background) 48*bb02e0acSNicolas Bonnefon const QPalette CrawlerWidget::errorPalette( QColor( "yellow" ) ); 49*bb02e0acSNicolas Bonnefon 50*bb02e0acSNicolas Bonnefon // Constructor makes all the child widgets and set up connections. 51*bb02e0acSNicolas Bonnefon CrawlerWidget::CrawlerWidget(SavedSearches* searches, QWidget *parent) 52*bb02e0acSNicolas Bonnefon : QSplitter(parent) 53*bb02e0acSNicolas Bonnefon { 54*bb02e0acSNicolas Bonnefon setOrientation(Qt::Vertical); 55*bb02e0acSNicolas Bonnefon 56*bb02e0acSNicolas Bonnefon // Initialise internal data (with empty file and search) 57*bb02e0acSNicolas Bonnefon logData_ = new LogData(); 58*bb02e0acSNicolas Bonnefon logFilteredData_ = logData_->getNewFilteredData(); 59*bb02e0acSNicolas Bonnefon 60*bb02e0acSNicolas Bonnefon // The matches overview 61*bb02e0acSNicolas Bonnefon overview_ = new Overview(); 62*bb02e0acSNicolas Bonnefon 63*bb02e0acSNicolas Bonnefon // Initialise the QF Mux to send requests from the QFWidget 64*bb02e0acSNicolas Bonnefon // to the right window 65*bb02e0acSNicolas Bonnefon quickFindMux_ = new QuickFindMux( this ); 66*bb02e0acSNicolas Bonnefon 67*bb02e0acSNicolas Bonnefon // The views 68*bb02e0acSNicolas Bonnefon bottomWindow = new QWidget; 69*bb02e0acSNicolas Bonnefon overviewWidget_ = new OverviewWidget(); 70*bb02e0acSNicolas Bonnefon logMainView = new LogMainView( 71*bb02e0acSNicolas Bonnefon logData_, quickFindMux_->getPattern(), overview_, overviewWidget_ ); 72*bb02e0acSNicolas Bonnefon filteredView = new FilteredView( 73*bb02e0acSNicolas Bonnefon logFilteredData_, quickFindMux_->getPattern() ); 74*bb02e0acSNicolas Bonnefon 75*bb02e0acSNicolas Bonnefon overviewWidget_->setOverview( overview_ ); 76*bb02e0acSNicolas Bonnefon overviewWidget_->setParent( logMainView ); 77*bb02e0acSNicolas Bonnefon 78*bb02e0acSNicolas Bonnefon savedSearches = searches; 79*bb02e0acSNicolas Bonnefon 80*bb02e0acSNicolas Bonnefon quickFindMux_->registerSearchable( logMainView ); 81*bb02e0acSNicolas Bonnefon quickFindMux_->registerSearchable( filteredView ); 82*bb02e0acSNicolas Bonnefon 83*bb02e0acSNicolas Bonnefon // Construct the visibility button 84*bb02e0acSNicolas Bonnefon visibilityModel_ = new QStandardItemModel( this ); 85*bb02e0acSNicolas Bonnefon 86*bb02e0acSNicolas Bonnefon QStandardItem *marksAndMatchesItem = new QStandardItem( tr( "Marks and matches" ) ); 87*bb02e0acSNicolas Bonnefon QPixmap marksAndMatchesPixmap( 16, 10 ); 88*bb02e0acSNicolas Bonnefon marksAndMatchesPixmap.fill( Qt::gray ); 89*bb02e0acSNicolas Bonnefon marksAndMatchesItem->setIcon( QIcon( marksAndMatchesPixmap ) ); 90*bb02e0acSNicolas Bonnefon marksAndMatchesItem->setData( FilteredView::MarksAndMatches ); 91*bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksAndMatchesItem ); 92*bb02e0acSNicolas Bonnefon 93*bb02e0acSNicolas Bonnefon QStandardItem *marksItem = new QStandardItem( tr( "Marks" ) ); 94*bb02e0acSNicolas Bonnefon QPixmap marksPixmap( 16, 10 ); 95*bb02e0acSNicolas Bonnefon marksPixmap.fill( Qt::blue ); 96*bb02e0acSNicolas Bonnefon marksItem->setIcon( QIcon( marksPixmap ) ); 97*bb02e0acSNicolas Bonnefon marksItem->setData( FilteredView::MarksOnly ); 98*bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksItem ); 99*bb02e0acSNicolas Bonnefon 100*bb02e0acSNicolas Bonnefon QStandardItem *matchesItem = new QStandardItem( tr( "Matches" ) ); 101*bb02e0acSNicolas Bonnefon QPixmap matchesPixmap( 16, 10 ); 102*bb02e0acSNicolas Bonnefon matchesPixmap.fill( Qt::red ); 103*bb02e0acSNicolas Bonnefon matchesItem->setIcon( QIcon( matchesPixmap ) ); 104*bb02e0acSNicolas Bonnefon matchesItem->setData( FilteredView::MatchesOnly ); 105*bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( matchesItem ); 106*bb02e0acSNicolas Bonnefon 107*bb02e0acSNicolas Bonnefon QListView *visibilityView = new QListView( this ); 108*bb02e0acSNicolas Bonnefon visibilityView->setMovement( QListView::Static ); 109*bb02e0acSNicolas Bonnefon visibilityView->setMinimumWidth( 170 ); // Only needed with custom style-sheet 110*bb02e0acSNicolas Bonnefon 111*bb02e0acSNicolas Bonnefon visibilityBox = new QComboBox(); 112*bb02e0acSNicolas Bonnefon visibilityBox->setModel( visibilityModel_ ); 113*bb02e0acSNicolas Bonnefon visibilityBox->setView( visibilityView ); 114*bb02e0acSNicolas Bonnefon 115*bb02e0acSNicolas Bonnefon // Select "Marks and matches" by default (same default as the filtered view) 116*bb02e0acSNicolas Bonnefon visibilityBox->setCurrentIndex( 0 ); 117*bb02e0acSNicolas Bonnefon 118*bb02e0acSNicolas Bonnefon // TODO: Maybe there is some way to set the popup width to be 119*bb02e0acSNicolas Bonnefon // sized-to-content (as it is when the stylesheet is not overriden) in the 120*bb02e0acSNicolas Bonnefon // stylesheet as opposed to setting a hard min-width on the view above. 121*bb02e0acSNicolas Bonnefon visibilityBox->setStyleSheet( " \ 122*bb02e0acSNicolas Bonnefon QComboBox:on {\ 123*bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 6px;\ 124*bb02e0acSNicolas Bonnefon width: 19px;\ 125*bb02e0acSNicolas Bonnefon } \ 126*bb02e0acSNicolas Bonnefon QComboBox:!on {\ 127*bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 7px;\ 128*bb02e0acSNicolas Bonnefon width: 19px;\ 129*bb02e0acSNicolas Bonnefon height: 16px;\ 130*bb02e0acSNicolas Bonnefon border: 1px solid gray;\ 131*bb02e0acSNicolas Bonnefon } \ 132*bb02e0acSNicolas Bonnefon QComboBox::drop-down::down-arrow {\ 133*bb02e0acSNicolas Bonnefon width: 0px;\ 134*bb02e0acSNicolas Bonnefon border-width: 0px;\ 135*bb02e0acSNicolas Bonnefon } \ 136*bb02e0acSNicolas Bonnefon " ); 137*bb02e0acSNicolas Bonnefon 138*bb02e0acSNicolas Bonnefon // Construct the Search Info line 139*bb02e0acSNicolas Bonnefon searchInfoLine = new InfoLine(); 140*bb02e0acSNicolas Bonnefon searchInfoLine->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 141*bb02e0acSNicolas Bonnefon searchInfoLine->setLineWidth( 1 ); 142*bb02e0acSNicolas Bonnefon searchInfoLineDefaultPalette = searchInfoLine->palette(); 143*bb02e0acSNicolas Bonnefon 144*bb02e0acSNicolas Bonnefon ignoreCaseCheck = new QCheckBox( "Ignore &case" ); 145*bb02e0acSNicolas Bonnefon searchRefreshCheck = new QCheckBox( "Auto-&refresh" ); 146*bb02e0acSNicolas Bonnefon 147*bb02e0acSNicolas Bonnefon // Construct the Search line 148*bb02e0acSNicolas Bonnefon searchLabel = new QLabel(tr("&Text: ")); 149*bb02e0acSNicolas Bonnefon searchLineEdit = new QComboBox; 150*bb02e0acSNicolas Bonnefon searchLineEdit->setEditable( true ); 151*bb02e0acSNicolas Bonnefon searchLineEdit->setCompleter( 0 ); 152*bb02e0acSNicolas Bonnefon searchLineEdit->addItems( savedSearches->recentSearches() ); 153*bb02e0acSNicolas Bonnefon searchLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); 154*bb02e0acSNicolas Bonnefon searchLineEdit->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon ); 155*bb02e0acSNicolas Bonnefon 156*bb02e0acSNicolas Bonnefon searchLabel->setBuddy( searchLineEdit ); 157*bb02e0acSNicolas Bonnefon 158*bb02e0acSNicolas Bonnefon searchButton = new QToolButton(); 159*bb02e0acSNicolas Bonnefon searchButton->setText( tr("&Search") ); 160*bb02e0acSNicolas Bonnefon searchButton->setAutoRaise( true ); 161*bb02e0acSNicolas Bonnefon 162*bb02e0acSNicolas Bonnefon stopButton = new QToolButton(); 163*bb02e0acSNicolas Bonnefon stopButton->setIcon( QIcon(":/images/stop16.png") ); 164*bb02e0acSNicolas Bonnefon stopButton->setAutoRaise( true ); 165*bb02e0acSNicolas Bonnefon stopButton->setEnabled( false ); 166*bb02e0acSNicolas Bonnefon 167*bb02e0acSNicolas Bonnefon // Construct the QuickFind bar 168*bb02e0acSNicolas Bonnefon quickFindWidget_ = new QuickFindWidget(); 169*bb02e0acSNicolas Bonnefon 170*bb02e0acSNicolas Bonnefon QHBoxLayout* searchLineLayout = new QHBoxLayout; 171*bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLabel); 172*bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLineEdit); 173*bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchButton); 174*bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(stopButton); 175*bb02e0acSNicolas Bonnefon searchLineLayout->setContentsMargins(6, 0, 6, 0); 176*bb02e0acSNicolas Bonnefon stopButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 177*bb02e0acSNicolas Bonnefon searchButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); 178*bb02e0acSNicolas Bonnefon 179*bb02e0acSNicolas Bonnefon QHBoxLayout* searchInfoLineLayout = new QHBoxLayout; 180*bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( visibilityBox ); 181*bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchInfoLine ); 182*bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( ignoreCaseCheck ); 183*bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchRefreshCheck ); 184*bb02e0acSNicolas Bonnefon 185*bb02e0acSNicolas Bonnefon // Construct the bottom window 186*bb02e0acSNicolas Bonnefon quickFindWidget_->hide(); 187*bb02e0acSNicolas Bonnefon QVBoxLayout* bottomMainLayout = new QVBoxLayout; 188*bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchLineLayout); 189*bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchInfoLineLayout); 190*bb02e0acSNicolas Bonnefon bottomMainLayout->addWidget(filteredView); 191*bb02e0acSNicolas Bonnefon bottomMainLayout->addWidget(quickFindWidget_); 192*bb02e0acSNicolas Bonnefon bottomMainLayout->setContentsMargins(2, 1, 2, 1); 193*bb02e0acSNicolas Bonnefon bottomWindow->setLayout(bottomMainLayout); 194*bb02e0acSNicolas Bonnefon 195*bb02e0acSNicolas Bonnefon addWidget( logMainView ); 196*bb02e0acSNicolas Bonnefon addWidget( bottomWindow ); 197*bb02e0acSNicolas Bonnefon 198*bb02e0acSNicolas Bonnefon // Default splitter position (usually overridden by the config file) 199*bb02e0acSNicolas Bonnefon QList<int> splitterSizes; 200*bb02e0acSNicolas Bonnefon splitterSizes += 400; 201*bb02e0acSNicolas Bonnefon splitterSizes += 100; 202*bb02e0acSNicolas Bonnefon setSizes( splitterSizes ); 203*bb02e0acSNicolas Bonnefon 204*bb02e0acSNicolas Bonnefon // Connect the signals 205*bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( returnPressed() ), 206*bb02e0acSNicolas Bonnefon searchButton, SIGNAL( clicked() )); 207*bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( textEdited( const QString& ) ), 208*bb02e0acSNicolas Bonnefon this, SLOT( searchTextChangeHandler() )); 209*bb02e0acSNicolas Bonnefon connect(searchButton, SIGNAL( clicked() ), 210*bb02e0acSNicolas Bonnefon this, SLOT( startNewSearch() ) ); 211*bb02e0acSNicolas Bonnefon connect(stopButton, SIGNAL( clicked() ), 212*bb02e0acSNicolas Bonnefon this, SLOT( stopSearch() ) ); 213*bb02e0acSNicolas Bonnefon 214*bb02e0acSNicolas Bonnefon connect(visibilityBox, SIGNAL( currentIndexChanged( int ) ), 215*bb02e0acSNicolas Bonnefon this, SLOT( changeFilteredViewVisibility( int ) ) ); 216*bb02e0acSNicolas Bonnefon 217*bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( newSelection( int ) ), 218*bb02e0acSNicolas Bonnefon logMainView, SLOT( update() ) ); 219*bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 220*bb02e0acSNicolas Bonnefon this, SLOT( jumpToMatchingLine( int ) ) ); 221*bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ), 222*bb02e0acSNicolas Bonnefon filteredView, SLOT( update() ) ); 223*bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( updateLineNumber( int ) ), 224*bb02e0acSNicolas Bonnefon this, SIGNAL( updateLineNumber( int ) ) ); 225*bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( markLine( qint64 ) ), 226*bb02e0acSNicolas Bonnefon this, SLOT( markLineFromMain( qint64 ) ) ); 227*bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( markLine( qint64 ) ), 228*bb02e0acSNicolas Bonnefon this, SLOT( markLineFromFiltered( qint64 ) ) ); 229*bb02e0acSNicolas Bonnefon 230*bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( addToSearch( const QString& ) ), 231*bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 232*bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( addToSearch( const QString& ) ), 233*bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) ); 234*bb02e0acSNicolas Bonnefon 235*bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseHoveredOverLine( qint64 ) ), 236*bb02e0acSNicolas Bonnefon this, SLOT( mouseHoveredOverMatch( qint64 ) ) ); 237*bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseLeftHoveringZone() ), 238*bb02e0acSNicolas Bonnefon overviewWidget_, SLOT( removeHighlight() ) ); 239*bb02e0acSNicolas Bonnefon 240*bb02e0acSNicolas Bonnefon // Follow option (up and down) 241*bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 242*bb02e0acSNicolas Bonnefon logMainView, SLOT( followSet( bool ) ) ); 243*bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ), 244*bb02e0acSNicolas Bonnefon filteredView, SLOT( followSet( bool ) ) ); 245*bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( followDisabled() ), 246*bb02e0acSNicolas Bonnefon this, SIGNAL( followDisabled() ) ); 247*bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( followDisabled() ), 248*bb02e0acSNicolas Bonnefon this, SIGNAL( followDisabled() ) ); 249*bb02e0acSNicolas Bonnefon 250*bb02e0acSNicolas Bonnefon connect( logFilteredData_, SIGNAL( searchProgressed( int, int ) ), 251*bb02e0acSNicolas Bonnefon this, SLOT( updateFilteredView( int, int ) ) ); 252*bb02e0acSNicolas Bonnefon 253*bb02e0acSNicolas Bonnefon // QuickFind 254*bb02e0acSNicolas Bonnefon connect( quickFindWidget_, SIGNAL( close() ), 255*bb02e0acSNicolas Bonnefon this, SLOT( hideQuickFindBar() ) ); 256*bb02e0acSNicolas Bonnefon connect( quickFindWidget_, SIGNAL( patternConfirmed( const QString&, bool ) ), 257*bb02e0acSNicolas Bonnefon quickFindMux_, SLOT( confirmPattern( const QString&, bool ) ) ); 258*bb02e0acSNicolas Bonnefon connect( quickFindWidget_, SIGNAL( patternUpdated( const QString&, bool ) ), 259*bb02e0acSNicolas Bonnefon quickFindMux_, SLOT( setNewPattern( const QString&, bool ) ) ); 260*bb02e0acSNicolas Bonnefon connect( quickFindWidget_, SIGNAL( cancelSearch() ), 261*bb02e0acSNicolas Bonnefon quickFindMux_, SLOT( cancelSearch() ) ); 262*bb02e0acSNicolas Bonnefon connect( quickFindWidget_, SIGNAL( searchForward() ), 263*bb02e0acSNicolas Bonnefon quickFindMux_, SLOT( searchForward() ) ); 264*bb02e0acSNicolas Bonnefon connect( quickFindWidget_, SIGNAL( searchBackward() ), 265*bb02e0acSNicolas Bonnefon quickFindMux_, SLOT( searchBackward() ) ); 266*bb02e0acSNicolas Bonnefon connect( quickFindWidget_, SIGNAL( searchNext() ), 267*bb02e0acSNicolas Bonnefon quickFindMux_, SLOT( searchNext() ) ); 268*bb02e0acSNicolas Bonnefon 269*bb02e0acSNicolas Bonnefon // QuickFind changes coming from the views 270*bb02e0acSNicolas Bonnefon connect( quickFindMux_, SIGNAL( patternChanged( const QString& ) ), 271*bb02e0acSNicolas Bonnefon this, SLOT( changeQFPattern( const QString& ) ) ); 272*bb02e0acSNicolas Bonnefon connect( quickFindMux_, SIGNAL( notify( const QFNotification& ) ), 273*bb02e0acSNicolas Bonnefon quickFindWidget_, SLOT( notify( const QFNotification& ) ) ); 274*bb02e0acSNicolas Bonnefon connect( quickFindMux_, SIGNAL( clearNotification() ), 275*bb02e0acSNicolas Bonnefon quickFindWidget_, SLOT( clearNotification() ) ); 276*bb02e0acSNicolas Bonnefon 277*bb02e0acSNicolas Bonnefon // Sent load file update to MainWindow (for status update) 278*bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( loadingProgressed( int ) ), 279*bb02e0acSNicolas Bonnefon this, SIGNAL( loadingProgressed( int ) ) ); 280*bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( loadingFinished( bool ) ), 281*bb02e0acSNicolas Bonnefon this, SLOT( loadingFinishedHandler( bool ) ) ); 282*bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( fileChanged( LogData::MonitoredFileStatus ) ), 283*bb02e0acSNicolas Bonnefon this, SLOT( fileChangedHandler( LogData::MonitoredFileStatus ) ) ); 284*bb02e0acSNicolas Bonnefon 285*bb02e0acSNicolas Bonnefon // Search auto-refresh 286*bb02e0acSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ), 287*bb02e0acSNicolas Bonnefon this, SLOT( searchRefreshChangedHandler( int ) ) ); 288*bb02e0acSNicolas Bonnefon } 289*bb02e0acSNicolas Bonnefon 290*bb02e0acSNicolas Bonnefon // Start the asynchronous loading of a file. 291*bb02e0acSNicolas Bonnefon bool CrawlerWidget::readFile( const QString& fileName, int ) 292*bb02e0acSNicolas Bonnefon { 293*bb02e0acSNicolas Bonnefon QFileInfo fileInfo( fileName ); 294*bb02e0acSNicolas Bonnefon if ( fileInfo.isReadable() ) 295*bb02e0acSNicolas Bonnefon { 296*bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Entering readFile " << fileName.toStdString(); 297*bb02e0acSNicolas Bonnefon 298*bb02e0acSNicolas Bonnefon // First we cancel any in progress search and loading 299*bb02e0acSNicolas Bonnefon stopLoading(); 300*bb02e0acSNicolas Bonnefon 301*bb02e0acSNicolas Bonnefon // The file exist, so we invalidate the search, remove all marks 302*bb02e0acSNicolas Bonnefon // and redraw the screen. 303*bb02e0acSNicolas Bonnefon replaceCurrentSearch( "" ); 304*bb02e0acSNicolas Bonnefon logFilteredData_->clearMarks(); 305*bb02e0acSNicolas Bonnefon logData_->attachFile( fileName ); 306*bb02e0acSNicolas Bonnefon logMainView->updateData(); 307*bb02e0acSNicolas Bonnefon 308*bb02e0acSNicolas Bonnefon // Forbid starting a search when loading in progress 309*bb02e0acSNicolas Bonnefon // searchButton->setEnabled( false ); 310*bb02e0acSNicolas Bonnefon 311*bb02e0acSNicolas Bonnefon return true; 312*bb02e0acSNicolas Bonnefon } 313*bb02e0acSNicolas Bonnefon else { 314*bb02e0acSNicolas Bonnefon return false; 315*bb02e0acSNicolas Bonnefon } 316*bb02e0acSNicolas Bonnefon } 317*bb02e0acSNicolas Bonnefon 318*bb02e0acSNicolas Bonnefon void CrawlerWidget::stopLoading() 319*bb02e0acSNicolas Bonnefon { 320*bb02e0acSNicolas Bonnefon logFilteredData_->interruptSearch(); 321*bb02e0acSNicolas Bonnefon logData_->interruptLoading(); 322*bb02e0acSNicolas Bonnefon } 323*bb02e0acSNicolas Bonnefon 324*bb02e0acSNicolas Bonnefon void CrawlerWidget::getFileInfo( qint64* fileSize, int* fileNbLine, 325*bb02e0acSNicolas Bonnefon QDateTime* lastModified ) const 326*bb02e0acSNicolas Bonnefon { 327*bb02e0acSNicolas Bonnefon *fileSize = logData_->getFileSize(); 328*bb02e0acSNicolas Bonnefon *fileNbLine = logData_->getNbLine(); 329*bb02e0acSNicolas Bonnefon *lastModified = logData_->getLastModifiedDate(); 330*bb02e0acSNicolas Bonnefon } 331*bb02e0acSNicolas Bonnefon 332*bb02e0acSNicolas Bonnefon // The top line is first one on the main display 333*bb02e0acSNicolas Bonnefon int CrawlerWidget::getTopLine() const 334*bb02e0acSNicolas Bonnefon { 335*bb02e0acSNicolas Bonnefon return logMainView->getTopLine(); 336*bb02e0acSNicolas Bonnefon } 337*bb02e0acSNicolas Bonnefon 338*bb02e0acSNicolas Bonnefon QString CrawlerWidget::getSelectedText() const 339*bb02e0acSNicolas Bonnefon { 340*bb02e0acSNicolas Bonnefon if ( filteredView->hasFocus() ) 341*bb02e0acSNicolas Bonnefon return filteredView->getSelection(); 342*bb02e0acSNicolas Bonnefon else 343*bb02e0acSNicolas Bonnefon return logMainView->getSelection(); 344*bb02e0acSNicolas Bonnefon } 345*bb02e0acSNicolas Bonnefon 346*bb02e0acSNicolas Bonnefon void CrawlerWidget::selectAll() 347*bb02e0acSNicolas Bonnefon { 348*bb02e0acSNicolas Bonnefon activeView()->selectAll(); 349*bb02e0acSNicolas Bonnefon } 350*bb02e0acSNicolas Bonnefon 351*bb02e0acSNicolas Bonnefon // Return a pointer to the view in which we should do the QuickFind 352*bb02e0acSNicolas Bonnefon SearchableWidgetInterface* CrawlerWidget::getActiveSearchable() const 353*bb02e0acSNicolas Bonnefon { 354*bb02e0acSNicolas Bonnefon QWidget* searchableWidget; 355*bb02e0acSNicolas Bonnefon 356*bb02e0acSNicolas Bonnefon // Search in the window that has focus, or the window where 'Find' was 357*bb02e0acSNicolas Bonnefon // called from, or the main window. 358*bb02e0acSNicolas Bonnefon if ( filteredView->hasFocus() || logMainView->hasFocus() ) 359*bb02e0acSNicolas Bonnefon searchableWidget = QApplication::focusWidget(); 360*bb02e0acSNicolas Bonnefon else 361*bb02e0acSNicolas Bonnefon searchableWidget = qfSavedFocus_; 362*bb02e0acSNicolas Bonnefon 363*bb02e0acSNicolas Bonnefon if ( AbstractLogView* view = qobject_cast<AbstractLogView*>( searchableWidget ) ) 364*bb02e0acSNicolas Bonnefon return view; 365*bb02e0acSNicolas Bonnefon else 366*bb02e0acSNicolas Bonnefon return logMainView; 367*bb02e0acSNicolas Bonnefon } 368*bb02e0acSNicolas Bonnefon 369*bb02e0acSNicolas Bonnefon // 370*bb02e0acSNicolas Bonnefon // Events handlers 371*bb02e0acSNicolas Bonnefon // 372*bb02e0acSNicolas Bonnefon 373*bb02e0acSNicolas Bonnefon void CrawlerWidget::keyPressEvent( QKeyEvent* keyEvent ) 374*bb02e0acSNicolas Bonnefon { 375*bb02e0acSNicolas Bonnefon LOG(logDEBUG4) << "keyPressEvent received"; 376*bb02e0acSNicolas Bonnefon 377*bb02e0acSNicolas Bonnefon switch ( (keyEvent->text())[0].toAscii() ) { 378*bb02e0acSNicolas Bonnefon case '/': 379*bb02e0acSNicolas Bonnefon displayQuickFindBar( QuickFindMux::Forward ); 380*bb02e0acSNicolas Bonnefon break; 381*bb02e0acSNicolas Bonnefon case '?': 382*bb02e0acSNicolas Bonnefon displayQuickFindBar( QuickFindMux::Backward ); 383*bb02e0acSNicolas Bonnefon break; 384*bb02e0acSNicolas Bonnefon default: 385*bb02e0acSNicolas Bonnefon keyEvent->ignore(); 386*bb02e0acSNicolas Bonnefon } 387*bb02e0acSNicolas Bonnefon 388*bb02e0acSNicolas Bonnefon if ( !keyEvent->isAccepted() ) 389*bb02e0acSNicolas Bonnefon QSplitter::keyPressEvent( keyEvent ); 390*bb02e0acSNicolas Bonnefon } 391*bb02e0acSNicolas Bonnefon 392*bb02e0acSNicolas Bonnefon // 393*bb02e0acSNicolas Bonnefon // Slots 394*bb02e0acSNicolas Bonnefon // 395*bb02e0acSNicolas Bonnefon 396*bb02e0acSNicolas Bonnefon void CrawlerWidget::startNewSearch() 397*bb02e0acSNicolas Bonnefon { 398*bb02e0acSNicolas Bonnefon // Record the search line in the recent list 399*bb02e0acSNicolas Bonnefon // (reload the list first in case another glogg changed it) 400*bb02e0acSNicolas Bonnefon GetPersistentInfo().retrieve( "savedSearches" ); 401*bb02e0acSNicolas Bonnefon savedSearches->addRecent( searchLineEdit->currentText() ); 402*bb02e0acSNicolas Bonnefon GetPersistentInfo().save( "savedSearches" ); 403*bb02e0acSNicolas Bonnefon 404*bb02e0acSNicolas Bonnefon // Update the SearchLine (history) 405*bb02e0acSNicolas Bonnefon updateSearchCombo(); 406*bb02e0acSNicolas Bonnefon // Call the private function to do the search 407*bb02e0acSNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() ); 408*bb02e0acSNicolas Bonnefon } 409*bb02e0acSNicolas Bonnefon 410*bb02e0acSNicolas Bonnefon void CrawlerWidget::stopSearch() 411*bb02e0acSNicolas Bonnefon { 412*bb02e0acSNicolas Bonnefon logFilteredData_->interruptSearch(); 413*bb02e0acSNicolas Bonnefon searchState_.stopSearch(); 414*bb02e0acSNicolas Bonnefon printSearchInfoMessage(); 415*bb02e0acSNicolas Bonnefon } 416*bb02e0acSNicolas Bonnefon 417*bb02e0acSNicolas Bonnefon // When receiving the 'newDataAvailable' signal from LogFilteredData 418*bb02e0acSNicolas Bonnefon void CrawlerWidget::updateFilteredView( int nbMatches, int progress ) 419*bb02e0acSNicolas Bonnefon { 420*bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "updateFilteredView received."; 421*bb02e0acSNicolas Bonnefon 422*bb02e0acSNicolas Bonnefon if ( progress == 100 ) { 423*bb02e0acSNicolas Bonnefon // Searching done 424*bb02e0acSNicolas Bonnefon printSearchInfoMessage( nbMatches ); 425*bb02e0acSNicolas Bonnefon searchInfoLine->hideGauge(); 426*bb02e0acSNicolas Bonnefon // De-activate the stop button 427*bb02e0acSNicolas Bonnefon stopButton->setEnabled( false ); 428*bb02e0acSNicolas Bonnefon } 429*bb02e0acSNicolas Bonnefon else { 430*bb02e0acSNicolas Bonnefon // Search in progress 431*bb02e0acSNicolas Bonnefon // We ignore 0% and 100% to avoid a flash when the search is very short 432*bb02e0acSNicolas Bonnefon if ( progress > 0 ) { 433*bb02e0acSNicolas Bonnefon searchInfoLine->setText( 434*bb02e0acSNicolas Bonnefon tr("Search in progress (%1 %)... %2 match%3 found so far.") 435*bb02e0acSNicolas Bonnefon .arg( progress ) 436*bb02e0acSNicolas Bonnefon .arg( nbMatches ) 437*bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ) ); 438*bb02e0acSNicolas Bonnefon searchInfoLine->displayGauge( progress ); 439*bb02e0acSNicolas Bonnefon } 440*bb02e0acSNicolas Bonnefon } 441*bb02e0acSNicolas Bonnefon 442*bb02e0acSNicolas Bonnefon // Recompute the content of the filtered window. 443*bb02e0acSNicolas Bonnefon filteredView->updateData(); 444*bb02e0acSNicolas Bonnefon 445*bb02e0acSNicolas Bonnefon // Update the match overview 446*bb02e0acSNicolas Bonnefon overview_->updateData( logData_->getNbLine() ); 447*bb02e0acSNicolas Bonnefon 448*bb02e0acSNicolas Bonnefon // Also update the top window for the coloured bullets. 449*bb02e0acSNicolas Bonnefon update(); 450*bb02e0acSNicolas Bonnefon } 451*bb02e0acSNicolas Bonnefon 452*bb02e0acSNicolas Bonnefon void CrawlerWidget::jumpToMatchingLine(int filteredLineNb) 453*bb02e0acSNicolas Bonnefon { 454*bb02e0acSNicolas Bonnefon int mainViewLine = logFilteredData_->getMatchingLineNumber(filteredLineNb); 455*bb02e0acSNicolas Bonnefon logMainView->selectAndDisplayLine(mainViewLine); // FIXME: should be done with a signal. 456*bb02e0acSNicolas Bonnefon } 457*bb02e0acSNicolas Bonnefon 458*bb02e0acSNicolas Bonnefon void CrawlerWidget::markLineFromMain( qint64 line ) 459*bb02e0acSNicolas Bonnefon { 460*bb02e0acSNicolas Bonnefon if ( logFilteredData_->isLineMarked( line ) ) 461*bb02e0acSNicolas Bonnefon logFilteredData_->deleteMark( line ); 462*bb02e0acSNicolas Bonnefon else 463*bb02e0acSNicolas Bonnefon logFilteredData_->addMark( line ); 464*bb02e0acSNicolas Bonnefon 465*bb02e0acSNicolas Bonnefon // Recompute the content of the filtered window. 466*bb02e0acSNicolas Bonnefon filteredView->updateData(); 467*bb02e0acSNicolas Bonnefon 468*bb02e0acSNicolas Bonnefon // Update the match overview 469*bb02e0acSNicolas Bonnefon overview_->updateData( logData_->getNbLine() ); 470*bb02e0acSNicolas Bonnefon 471*bb02e0acSNicolas Bonnefon // Also update the top window for the coloured bullets. 472*bb02e0acSNicolas Bonnefon update(); 473*bb02e0acSNicolas Bonnefon } 474*bb02e0acSNicolas Bonnefon 475*bb02e0acSNicolas Bonnefon void CrawlerWidget::markLineFromFiltered( qint64 line ) 476*bb02e0acSNicolas Bonnefon { 477*bb02e0acSNicolas Bonnefon qint64 line_in_file = logFilteredData_->getMatchingLineNumber( line ); 478*bb02e0acSNicolas Bonnefon if ( logFilteredData_->filteredLineTypeByIndex( line ) 479*bb02e0acSNicolas Bonnefon == LogFilteredData::Mark ) 480*bb02e0acSNicolas Bonnefon logFilteredData_->deleteMark( line_in_file ); 481*bb02e0acSNicolas Bonnefon else 482*bb02e0acSNicolas Bonnefon logFilteredData_->addMark( line_in_file ); 483*bb02e0acSNicolas Bonnefon 484*bb02e0acSNicolas Bonnefon // Recompute the content of the filtered window. 485*bb02e0acSNicolas Bonnefon filteredView->updateData(); 486*bb02e0acSNicolas Bonnefon 487*bb02e0acSNicolas Bonnefon // Update the match overview 488*bb02e0acSNicolas Bonnefon overview_->updateData( logData_->getNbLine() ); 489*bb02e0acSNicolas Bonnefon 490*bb02e0acSNicolas Bonnefon // Also update the top window for the coloured bullets. 491*bb02e0acSNicolas Bonnefon update(); 492*bb02e0acSNicolas Bonnefon } 493*bb02e0acSNicolas Bonnefon 494*bb02e0acSNicolas Bonnefon void CrawlerWidget::applyConfiguration() 495*bb02e0acSNicolas Bonnefon { 496*bb02e0acSNicolas Bonnefon Configuration& config = Persistent<Configuration>( "settings" ); 497*bb02e0acSNicolas Bonnefon QFont font = config.mainFont(); 498*bb02e0acSNicolas Bonnefon 499*bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::applyConfiguration"; 500*bb02e0acSNicolas Bonnefon 501*bb02e0acSNicolas Bonnefon // Whatever font we use, we should NOT use kerning 502*bb02e0acSNicolas Bonnefon font.setKerning( false ); 503*bb02e0acSNicolas Bonnefon font.setFixedPitch( true ); 504*bb02e0acSNicolas Bonnefon #if QT_VERSION > 0x040700 505*bb02e0acSNicolas Bonnefon // Necessary on systems doing subpixel positionning (e.g. Ubuntu 12.04) 506*bb02e0acSNicolas Bonnefon font.setStyleStrategy( QFont::ForceIntegerMetrics ); 507*bb02e0acSNicolas Bonnefon #endif 508*bb02e0acSNicolas Bonnefon logMainView->setFont(font); 509*bb02e0acSNicolas Bonnefon filteredView->setFont(font); 510*bb02e0acSNicolas Bonnefon 511*bb02e0acSNicolas Bonnefon logMainView->setLineNumbersVisible( config.mainLineNumbersVisible() ); 512*bb02e0acSNicolas Bonnefon filteredView->setLineNumbersVisible( config.filteredLineNumbersVisible() ); 513*bb02e0acSNicolas Bonnefon 514*bb02e0acSNicolas Bonnefon overview_->setVisible( config.isOverviewVisible() ); 515*bb02e0acSNicolas Bonnefon logMainView->refreshOverview(); 516*bb02e0acSNicolas Bonnefon 517*bb02e0acSNicolas Bonnefon logMainView->updateDisplaySize(); 518*bb02e0acSNicolas Bonnefon logMainView->update(); 519*bb02e0acSNicolas Bonnefon filteredView->updateDisplaySize(); 520*bb02e0acSNicolas Bonnefon filteredView->update(); 521*bb02e0acSNicolas Bonnefon 522*bb02e0acSNicolas Bonnefon // Update the SearchLine (history) 523*bb02e0acSNicolas Bonnefon updateSearchCombo(); 524*bb02e0acSNicolas Bonnefon } 525*bb02e0acSNicolas Bonnefon 526*bb02e0acSNicolas Bonnefon void CrawlerWidget::loadingFinishedHandler( bool success ) 527*bb02e0acSNicolas Bonnefon { 528*bb02e0acSNicolas Bonnefon // We need to refresh the main window because the view lines on the 529*bb02e0acSNicolas Bonnefon // overview have probably changed. 530*bb02e0acSNicolas Bonnefon overview_->updateData( logData_->getNbLine() ); 531*bb02e0acSNicolas Bonnefon 532*bb02e0acSNicolas Bonnefon // FIXME, handle topLine 533*bb02e0acSNicolas Bonnefon // logMainView->updateData( logData_, topLine ); 534*bb02e0acSNicolas Bonnefon logMainView->updateData(); 535*bb02e0acSNicolas Bonnefon 536*bb02e0acSNicolas Bonnefon // searchButton->setEnabled( true ); 537*bb02e0acSNicolas Bonnefon 538*bb02e0acSNicolas Bonnefon // See if we need to auto-refresh the search 539*bb02e0acSNicolas Bonnefon if ( searchState_.isAutorefreshAllowed() ) { 540*bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Refreshing the search"; 541*bb02e0acSNicolas Bonnefon logFilteredData_->updateSearch(); 542*bb02e0acSNicolas Bonnefon } 543*bb02e0acSNicolas Bonnefon 544*bb02e0acSNicolas Bonnefon emit loadingFinished( success ); 545*bb02e0acSNicolas Bonnefon } 546*bb02e0acSNicolas Bonnefon 547*bb02e0acSNicolas Bonnefon void CrawlerWidget::fileChangedHandler( LogData::MonitoredFileStatus status ) 548*bb02e0acSNicolas Bonnefon { 549*bb02e0acSNicolas Bonnefon // Handle the case where the file has been truncated 550*bb02e0acSNicolas Bonnefon if ( status == LogData::Truncated ) { 551*bb02e0acSNicolas Bonnefon // Clear all marks (TODO offer the option to keep them) 552*bb02e0acSNicolas Bonnefon logFilteredData_->clearMarks(); 553*bb02e0acSNicolas Bonnefon if ( ! searchInfoLine->text().isEmpty() ) { 554*bb02e0acSNicolas Bonnefon // Invalidate the search 555*bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 556*bb02e0acSNicolas Bonnefon filteredView->updateData(); 557*bb02e0acSNicolas Bonnefon searchState_.truncateFile(); 558*bb02e0acSNicolas Bonnefon printSearchInfoMessage(); 559*bb02e0acSNicolas Bonnefon } 560*bb02e0acSNicolas Bonnefon } 561*bb02e0acSNicolas Bonnefon } 562*bb02e0acSNicolas Bonnefon 563*bb02e0acSNicolas Bonnefon void CrawlerWidget::displayQuickFindBar( QuickFindMux::QFDirection direction ) 564*bb02e0acSNicolas Bonnefon { 565*bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::displayQuickFindBar"; 566*bb02e0acSNicolas Bonnefon 567*bb02e0acSNicolas Bonnefon // Remember who had the focus 568*bb02e0acSNicolas Bonnefon qfSavedFocus_ = QApplication::focusWidget(); 569*bb02e0acSNicolas Bonnefon 570*bb02e0acSNicolas Bonnefon quickFindMux_->setDirection( direction ); 571*bb02e0acSNicolas Bonnefon quickFindWidget_->userActivate(); 572*bb02e0acSNicolas Bonnefon } 573*bb02e0acSNicolas Bonnefon 574*bb02e0acSNicolas Bonnefon void CrawlerWidget::hideQuickFindBar() 575*bb02e0acSNicolas Bonnefon { 576*bb02e0acSNicolas Bonnefon // Restore the focus once the QFBar has been hidden 577*bb02e0acSNicolas Bonnefon qfSavedFocus_->setFocus(); 578*bb02e0acSNicolas Bonnefon } 579*bb02e0acSNicolas Bonnefon 580*bb02e0acSNicolas Bonnefon void CrawlerWidget::changeQFPattern( const QString& newPattern ) 581*bb02e0acSNicolas Bonnefon { 582*bb02e0acSNicolas Bonnefon quickFindWidget_->changeDisplayedPattern( newPattern ); 583*bb02e0acSNicolas Bonnefon } 584*bb02e0acSNicolas Bonnefon 585*bb02e0acSNicolas Bonnefon // Returns a pointer to the window in which the search should be done 586*bb02e0acSNicolas Bonnefon AbstractLogView* CrawlerWidget::activeView() const 587*bb02e0acSNicolas Bonnefon { 588*bb02e0acSNicolas Bonnefon QWidget* activeView; 589*bb02e0acSNicolas Bonnefon 590*bb02e0acSNicolas Bonnefon // Search in the window that has focus, or the window where 'Find' was 591*bb02e0acSNicolas Bonnefon // called from, or the main window. 592*bb02e0acSNicolas Bonnefon if ( filteredView->hasFocus() || logMainView->hasFocus() ) 593*bb02e0acSNicolas Bonnefon activeView = QApplication::focusWidget(); 594*bb02e0acSNicolas Bonnefon else 595*bb02e0acSNicolas Bonnefon activeView = qfSavedFocus_; 596*bb02e0acSNicolas Bonnefon 597*bb02e0acSNicolas Bonnefon if ( AbstractLogView* view = qobject_cast<AbstractLogView*>( activeView ) ) 598*bb02e0acSNicolas Bonnefon return view; 599*bb02e0acSNicolas Bonnefon else 600*bb02e0acSNicolas Bonnefon return logMainView; 601*bb02e0acSNicolas Bonnefon } 602*bb02e0acSNicolas Bonnefon 603*bb02e0acSNicolas Bonnefon void CrawlerWidget::searchForward() 604*bb02e0acSNicolas Bonnefon { 605*bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchForward"; 606*bb02e0acSNicolas Bonnefon 607*bb02e0acSNicolas Bonnefon activeView()->searchForward(); 608*bb02e0acSNicolas Bonnefon } 609*bb02e0acSNicolas Bonnefon 610*bb02e0acSNicolas Bonnefon void CrawlerWidget::searchBackward() 611*bb02e0acSNicolas Bonnefon { 612*bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchBackward"; 613*bb02e0acSNicolas Bonnefon 614*bb02e0acSNicolas Bonnefon activeView()->searchBackward(); 615*bb02e0acSNicolas Bonnefon } 616*bb02e0acSNicolas Bonnefon 617*bb02e0acSNicolas Bonnefon void CrawlerWidget::searchRefreshChangedHandler( int state ) 618*bb02e0acSNicolas Bonnefon { 619*bb02e0acSNicolas Bonnefon searchState_.setAutorefresh( state == Qt::Checked ); 620*bb02e0acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 621*bb02e0acSNicolas Bonnefon } 622*bb02e0acSNicolas Bonnefon 623*bb02e0acSNicolas Bonnefon void CrawlerWidget::searchTextChangeHandler() 624*bb02e0acSNicolas Bonnefon { 625*bb02e0acSNicolas Bonnefon // We suspend auto-refresh 626*bb02e0acSNicolas Bonnefon searchState_.changeExpression(); 627*bb02e0acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() ); 628*bb02e0acSNicolas Bonnefon } 629*bb02e0acSNicolas Bonnefon 630*bb02e0acSNicolas Bonnefon void CrawlerWidget::changeFilteredViewVisibility( int index ) 631*bb02e0acSNicolas Bonnefon { 632*bb02e0acSNicolas Bonnefon QStandardItem* item = visibilityModel_->item( index ); 633*bb02e0acSNicolas Bonnefon FilteredView::Visibility visibility = 634*bb02e0acSNicolas Bonnefon static_cast< FilteredView::Visibility>( item->data().toInt() ); 635*bb02e0acSNicolas Bonnefon 636*bb02e0acSNicolas Bonnefon filteredView->setVisibility( visibility ); 637*bb02e0acSNicolas Bonnefon } 638*bb02e0acSNicolas Bonnefon 639*bb02e0acSNicolas Bonnefon void CrawlerWidget::addToSearch( const QString& string ) 640*bb02e0acSNicolas Bonnefon { 641*bb02e0acSNicolas Bonnefon QString text = searchLineEdit->currentText(); 642*bb02e0acSNicolas Bonnefon 643*bb02e0acSNicolas Bonnefon if ( text.isEmpty() ) 644*bb02e0acSNicolas Bonnefon text = string; 645*bb02e0acSNicolas Bonnefon else { 646*bb02e0acSNicolas Bonnefon // Escape the regexp chars from the string before adding it. 647*bb02e0acSNicolas Bonnefon text += ( '|' + QRegExp::escape( string ) ); 648*bb02e0acSNicolas Bonnefon } 649*bb02e0acSNicolas Bonnefon 650*bb02e0acSNicolas Bonnefon searchLineEdit->setEditText( text ); 651*bb02e0acSNicolas Bonnefon 652*bb02e0acSNicolas Bonnefon // Set the focus to lineEdit so that the user can press 'Return' immediately 653*bb02e0acSNicolas Bonnefon searchLineEdit->lineEdit()->setFocus(); 654*bb02e0acSNicolas Bonnefon } 655*bb02e0acSNicolas Bonnefon 656*bb02e0acSNicolas Bonnefon void CrawlerWidget::mouseHoveredOverMatch( qint64 line ) 657*bb02e0acSNicolas Bonnefon { 658*bb02e0acSNicolas Bonnefon qint64 line_in_mainview = logFilteredData_->getMatchingLineNumber( line ); 659*bb02e0acSNicolas Bonnefon 660*bb02e0acSNicolas Bonnefon overviewWidget_->highlightLine( line_in_mainview ); 661*bb02e0acSNicolas Bonnefon } 662*bb02e0acSNicolas Bonnefon 663*bb02e0acSNicolas Bonnefon // 664*bb02e0acSNicolas Bonnefon // Private functions 665*bb02e0acSNicolas Bonnefon // 666*bb02e0acSNicolas Bonnefon 667*bb02e0acSNicolas Bonnefon // Create a new search using the text passed, replace the currently 668*bb02e0acSNicolas Bonnefon // used one and destroy the old one. 669*bb02e0acSNicolas Bonnefon void CrawlerWidget::replaceCurrentSearch( const QString& searchText ) 670*bb02e0acSNicolas Bonnefon { 671*bb02e0acSNicolas Bonnefon // Interrupt the search if it's ongoing 672*bb02e0acSNicolas Bonnefon logFilteredData_->interruptSearch(); 673*bb02e0acSNicolas Bonnefon 674*bb02e0acSNicolas Bonnefon // We have to wait for the last search update (100%) 675*bb02e0acSNicolas Bonnefon // before clearing/restarting to avoid having remaining results. 676*bb02e0acSNicolas Bonnefon 677*bb02e0acSNicolas Bonnefon // FIXME: this is a bit of a hack, we call processEvents 678*bb02e0acSNicolas Bonnefon // for Qt to empty its event queue, including (hopefully) 679*bb02e0acSNicolas Bonnefon // the search update event sent by logFilteredData_. It saves 680*bb02e0acSNicolas Bonnefon // us the overhead of having proper sync. 681*bb02e0acSNicolas Bonnefon QApplication::processEvents( QEventLoop::ExcludeUserInputEvents ); 682*bb02e0acSNicolas Bonnefon 683*bb02e0acSNicolas Bonnefon if ( !searchText.isEmpty() ) { 684*bb02e0acSNicolas Bonnefon // Determine the type of regexp depending on the config 685*bb02e0acSNicolas Bonnefon QRegExp::PatternSyntax syntax; 686*bb02e0acSNicolas Bonnefon static Configuration& config = Persistent<Configuration>( "settings" ); 687*bb02e0acSNicolas Bonnefon switch ( config.mainRegexpType() ) { 688*bb02e0acSNicolas Bonnefon case Wildcard: 689*bb02e0acSNicolas Bonnefon syntax = QRegExp::Wildcard; 690*bb02e0acSNicolas Bonnefon break; 691*bb02e0acSNicolas Bonnefon case FixedString: 692*bb02e0acSNicolas Bonnefon syntax = QRegExp::FixedString; 693*bb02e0acSNicolas Bonnefon break; 694*bb02e0acSNicolas Bonnefon default: 695*bb02e0acSNicolas Bonnefon syntax = QRegExp::RegExp2; 696*bb02e0acSNicolas Bonnefon break; 697*bb02e0acSNicolas Bonnefon } 698*bb02e0acSNicolas Bonnefon 699*bb02e0acSNicolas Bonnefon // Set the pattern case insensitive if needed 700*bb02e0acSNicolas Bonnefon Qt::CaseSensitivity case_sensitivity = Qt::CaseSensitive; 701*bb02e0acSNicolas Bonnefon if ( ignoreCaseCheck->checkState() == Qt::Checked ) 702*bb02e0acSNicolas Bonnefon case_sensitivity = Qt::CaseInsensitive; 703*bb02e0acSNicolas Bonnefon 704*bb02e0acSNicolas Bonnefon // Constructs the regexp 705*bb02e0acSNicolas Bonnefon QRegExp regexp( searchText, case_sensitivity, syntax ); 706*bb02e0acSNicolas Bonnefon 707*bb02e0acSNicolas Bonnefon if ( regexp.isValid() ) { 708*bb02e0acSNicolas Bonnefon // Activate the stop button 709*bb02e0acSNicolas Bonnefon stopButton->setEnabled( true ); 710*bb02e0acSNicolas Bonnefon // Start a new asynchronous search 711*bb02e0acSNicolas Bonnefon logFilteredData_->runSearch( regexp ); 712*bb02e0acSNicolas Bonnefon // Accept auto-refresh of the search 713*bb02e0acSNicolas Bonnefon searchState_.startSearch(); 714*bb02e0acSNicolas Bonnefon } 715*bb02e0acSNicolas Bonnefon else { 716*bb02e0acSNicolas Bonnefon // The regexp is wrong 717*bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 718*bb02e0acSNicolas Bonnefon filteredView->updateData(); 719*bb02e0acSNicolas Bonnefon searchState_.resetState(); 720*bb02e0acSNicolas Bonnefon 721*bb02e0acSNicolas Bonnefon // Inform the user 722*bb02e0acSNicolas Bonnefon QString errorMessage = tr("Error in expression: "); 723*bb02e0acSNicolas Bonnefon errorMessage += regexp.errorString(); 724*bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( errorPalette ); 725*bb02e0acSNicolas Bonnefon searchInfoLine->setText( errorMessage ); 726*bb02e0acSNicolas Bonnefon } 727*bb02e0acSNicolas Bonnefon } 728*bb02e0acSNicolas Bonnefon else { 729*bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch(); 730*bb02e0acSNicolas Bonnefon filteredView->updateData(); 731*bb02e0acSNicolas Bonnefon searchState_.resetState(); 732*bb02e0acSNicolas Bonnefon printSearchInfoMessage(); 733*bb02e0acSNicolas Bonnefon } 734*bb02e0acSNicolas Bonnefon // Connect the search to the top view 735*bb02e0acSNicolas Bonnefon logMainView->useNewFiltering( logFilteredData_ ); 736*bb02e0acSNicolas Bonnefon } 737*bb02e0acSNicolas Bonnefon 738*bb02e0acSNicolas Bonnefon // Updates the content of the drop down list for the saved searches, 739*bb02e0acSNicolas Bonnefon // called when the SavedSearch has been changed. 740*bb02e0acSNicolas Bonnefon void CrawlerWidget::updateSearchCombo() 741*bb02e0acSNicolas Bonnefon { 742*bb02e0acSNicolas Bonnefon const QString text = searchLineEdit->lineEdit()->text(); 743*bb02e0acSNicolas Bonnefon searchLineEdit->clear(); 744*bb02e0acSNicolas Bonnefon searchLineEdit->addItems( savedSearches->recentSearches() ); 745*bb02e0acSNicolas Bonnefon // In case we had something that wasn't added to the list (blank...): 746*bb02e0acSNicolas Bonnefon searchLineEdit->lineEdit()->setText( text ); 747*bb02e0acSNicolas Bonnefon } 748*bb02e0acSNicolas Bonnefon 749*bb02e0acSNicolas Bonnefon // Print the search info message. 750*bb02e0acSNicolas Bonnefon void CrawlerWidget::printSearchInfoMessage( int nbMatches ) 751*bb02e0acSNicolas Bonnefon { 752*bb02e0acSNicolas Bonnefon QString text; 753*bb02e0acSNicolas Bonnefon 754*bb02e0acSNicolas Bonnefon switch ( searchState_.getState() ) { 755*bb02e0acSNicolas Bonnefon case SearchState::NoSearch: 756*bb02e0acSNicolas Bonnefon // Blank text is fine 757*bb02e0acSNicolas Bonnefon break; 758*bb02e0acSNicolas Bonnefon case SearchState::Static: 759*bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found.").arg( nbMatches ) 760*bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 761*bb02e0acSNicolas Bonnefon break; 762*bb02e0acSNicolas Bonnefon case SearchState::Autorefreshing: 763*bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found. Search is auto-refreshing...").arg( nbMatches ) 764*bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ); 765*bb02e0acSNicolas Bonnefon break; 766*bb02e0acSNicolas Bonnefon case SearchState::FileTruncated: 767*bb02e0acSNicolas Bonnefon text = tr("File truncated on disk, previous search results are not valid anymore."); 768*bb02e0acSNicolas Bonnefon break; 769*bb02e0acSNicolas Bonnefon } 770*bb02e0acSNicolas Bonnefon 771*bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( searchInfoLineDefaultPalette ); 772*bb02e0acSNicolas Bonnefon searchInfoLine->setText( text ); 773*bb02e0acSNicolas Bonnefon } 774*bb02e0acSNicolas Bonnefon 775*bb02e0acSNicolas Bonnefon // 776*bb02e0acSNicolas Bonnefon // SearchState implementation 777*bb02e0acSNicolas Bonnefon // 778*bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::resetState() 779*bb02e0acSNicolas Bonnefon { 780*bb02e0acSNicolas Bonnefon state_ = NoSearch; 781*bb02e0acSNicolas Bonnefon } 782*bb02e0acSNicolas Bonnefon 783*bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::setAutorefresh( bool refresh ) 784*bb02e0acSNicolas Bonnefon { 785*bb02e0acSNicolas Bonnefon autoRefreshRequested_ = refresh; 786*bb02e0acSNicolas Bonnefon 787*bb02e0acSNicolas Bonnefon if ( refresh ) { 788*bb02e0acSNicolas Bonnefon if ( state_ == Static ) 789*bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 790*bb02e0acSNicolas Bonnefon } 791*bb02e0acSNicolas Bonnefon else { 792*bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 793*bb02e0acSNicolas Bonnefon state_ = Static; 794*bb02e0acSNicolas Bonnefon } 795*bb02e0acSNicolas Bonnefon } 796*bb02e0acSNicolas Bonnefon 797*bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::truncateFile() 798*bb02e0acSNicolas Bonnefon { 799*bb02e0acSNicolas Bonnefon state_ = FileTruncated; 800*bb02e0acSNicolas Bonnefon } 801*bb02e0acSNicolas Bonnefon 802*bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::changeExpression() 803*bb02e0acSNicolas Bonnefon { 804*bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 805*bb02e0acSNicolas Bonnefon state_ = Static; 806*bb02e0acSNicolas Bonnefon } 807*bb02e0acSNicolas Bonnefon 808*bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::stopSearch() 809*bb02e0acSNicolas Bonnefon { 810*bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing ) 811*bb02e0acSNicolas Bonnefon state_ = Static; 812*bb02e0acSNicolas Bonnefon } 813*bb02e0acSNicolas Bonnefon 814*bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::startSearch() 815*bb02e0acSNicolas Bonnefon { 816*bb02e0acSNicolas Bonnefon if ( autoRefreshRequested_ ) 817*bb02e0acSNicolas Bonnefon state_ = Autorefreshing; 818*bb02e0acSNicolas Bonnefon else 819*bb02e0acSNicolas Bonnefon state_ = Static; 820*bb02e0acSNicolas Bonnefon } 821