1bb02e0acSNicolas Bonnefon /*
245ef183cSNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicolas Bonnefon and other contributors
3bb02e0acSNicolas Bonnefon *
4bb02e0acSNicolas Bonnefon * This file is part of glogg.
5bb02e0acSNicolas Bonnefon *
6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify
7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by
8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or
9bb02e0acSNicolas Bonnefon * (at your option) any later version.
10bb02e0acSNicolas Bonnefon *
11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful,
12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of
13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14bb02e0acSNicolas Bonnefon * GNU General Public License for more details.
15bb02e0acSNicolas Bonnefon *
16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License
17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>.
18bb02e0acSNicolas Bonnefon */
19bb02e0acSNicolas Bonnefon
20bb02e0acSNicolas Bonnefon // This file implements the CrawlerWidget class.
21bb02e0acSNicolas Bonnefon // It is responsible for creating and managing the two views and all
22bb02e0acSNicolas Bonnefon // the UI elements. It implements the connection between the UI elements.
2332e44cfdSNicolas Bonnefon // It also interacts with the sets of data (full and filtered).
24bb02e0acSNicolas Bonnefon
25bb02e0acSNicolas Bonnefon #include "log.h"
26bb02e0acSNicolas Bonnefon
27039481acSNicolas Bonnefon #include <cassert>
28039481acSNicolas Bonnefon
29bb02e0acSNicolas Bonnefon #include <Qt>
30bb02e0acSNicolas Bonnefon #include <QApplication>
31bb02e0acSNicolas Bonnefon #include <QFile>
32bb02e0acSNicolas Bonnefon #include <QLineEdit>
33bb02e0acSNicolas Bonnefon #include <QFileInfo>
34bb02e0acSNicolas Bonnefon #include <QStandardItemModel>
35bb02e0acSNicolas Bonnefon #include <QHeaderView>
36bb02e0acSNicolas Bonnefon #include <QListView>
37bb02e0acSNicolas Bonnefon
38bb02e0acSNicolas Bonnefon #include "crawlerwidget.h"
39bb02e0acSNicolas Bonnefon
40bb02e0acSNicolas Bonnefon #include "quickfindpattern.h"
41bb02e0acSNicolas Bonnefon #include "overview.h"
42bb02e0acSNicolas Bonnefon #include "infoline.h"
43bb02e0acSNicolas Bonnefon #include "savedsearches.h"
44bb02e0acSNicolas Bonnefon #include "quickfindwidget.h"
45bb02e0acSNicolas Bonnefon #include "persistentinfo.h"
46bb02e0acSNicolas Bonnefon #include "configuration.h"
47bb02e0acSNicolas Bonnefon
48bb02e0acSNicolas Bonnefon // Palette for error signaling (yellow background)
49bb02e0acSNicolas Bonnefon const QPalette CrawlerWidget::errorPalette( QColor( "yellow" ) );
50bb02e0acSNicolas Bonnefon
51a44d09bcSNicolas Bonnefon // Implementation of the view context for the CrawlerWidget
52a44d09bcSNicolas Bonnefon class CrawlerWidgetContext : public ViewContextInterface {
53a44d09bcSNicolas Bonnefon public:
54a44d09bcSNicolas Bonnefon // Construct from the stored string representation
55a44d09bcSNicolas Bonnefon CrawlerWidgetContext( const char* string );
56a44d09bcSNicolas Bonnefon // Construct from the value passsed
CrawlerWidgetContext(QList<int> sizes,bool ignore_case,bool auto_refresh,bool follow_file)57f688be2eSNicolas Bonnefon CrawlerWidgetContext( QList<int> sizes,
58f688be2eSNicolas Bonnefon bool ignore_case,
59af94bdd6SNicolas Bonnefon bool auto_refresh,
60af94bdd6SNicolas Bonnefon bool follow_file )
61f688be2eSNicolas Bonnefon : sizes_( sizes ),
62f688be2eSNicolas Bonnefon ignore_case_( ignore_case ),
63af94bdd6SNicolas Bonnefon auto_refresh_( auto_refresh ),
64af94bdd6SNicolas Bonnefon follow_file_( follow_file ) {}
65a44d09bcSNicolas Bonnefon
66a44d09bcSNicolas Bonnefon // Implementation of the ViewContextInterface function
67a44d09bcSNicolas Bonnefon std::string toString() const;
68a44d09bcSNicolas Bonnefon
69a44d09bcSNicolas Bonnefon // Access the Qt sizes array for the QSplitter
sizes() const70a44d09bcSNicolas Bonnefon QList<int> sizes() const { return sizes_; }
71a44d09bcSNicolas Bonnefon
ignoreCase() const72f688be2eSNicolas Bonnefon bool ignoreCase() const { return ignore_case_; }
autoRefresh() const73f688be2eSNicolas Bonnefon bool autoRefresh() const { return auto_refresh_; }
followFile() const74af94bdd6SNicolas Bonnefon bool followFile() const { return follow_file_; }
75f688be2eSNicolas Bonnefon
76a44d09bcSNicolas Bonnefon private:
77a44d09bcSNicolas Bonnefon QList<int> sizes_;
78f688be2eSNicolas Bonnefon
79f688be2eSNicolas Bonnefon bool ignore_case_;
80f688be2eSNicolas Bonnefon bool auto_refresh_;
81af94bdd6SNicolas Bonnefon bool follow_file_;
82a44d09bcSNicolas Bonnefon };
83a44d09bcSNicolas Bonnefon
84039481acSNicolas Bonnefon // Constructor only does trivial construction. The real work is done once
85039481acSNicolas Bonnefon // the data is attached.
CrawlerWidget(QWidget * parent)861b5e406eSNicolas Bonnefon CrawlerWidget::CrawlerWidget( QWidget *parent )
870f9fd9edSNicolas Bonnefon : QSplitter( parent ), overview_()
88bb02e0acSNicolas Bonnefon {
89039481acSNicolas Bonnefon logData_ = nullptr;
90039481acSNicolas Bonnefon logFilteredData_ = nullptr;
91039481acSNicolas Bonnefon
92b423cd88SNicolas Bonnefon quickFindPattern_ = nullptr;
931b5e406eSNicolas Bonnefon savedSearches_ = nullptr;
948570d8d2SNicolas Bonnefon qfSavedFocus_ = nullptr;
959cacd6a9SNicolas Bonnefon
9660864ff5SNicolas Bonnefon // Until we have received confirmation loading is finished, we
9760864ff5SNicolas Bonnefon // should consider we are loading something.
9860864ff5SNicolas Bonnefon loadingInProgress_ = true;
9945ef183cSNicolas Bonnefon // and it's the first time
10045ef183cSNicolas Bonnefon firstLoadDone_ = false;
1017999f43eSNicolas Bonnefon nbMatches_ = 0;
10245ef183cSNicolas Bonnefon dataStatus_ = DataStatus::OLD_DATA;
10360864ff5SNicolas Bonnefon
1049cacd6a9SNicolas Bonnefon currentLineNumber_ = 0;
105039481acSNicolas Bonnefon }
106039481acSNicolas Bonnefon
107039481acSNicolas Bonnefon // The top line is first one on the main display
getTopLine() const108039481acSNicolas Bonnefon int CrawlerWidget::getTopLine() const
109039481acSNicolas Bonnefon {
110039481acSNicolas Bonnefon return logMainView->getTopLine();
111039481acSNicolas Bonnefon }
112039481acSNicolas Bonnefon
getSelectedText() const113039481acSNicolas Bonnefon QString CrawlerWidget::getSelectedText() const
114039481acSNicolas Bonnefon {
115039481acSNicolas Bonnefon if ( filteredView->hasFocus() )
116039481acSNicolas Bonnefon return filteredView->getSelection();
117039481acSNicolas Bonnefon else
118039481acSNicolas Bonnefon return logMainView->getSelection();
119039481acSNicolas Bonnefon }
120039481acSNicolas Bonnefon
selectAll()121039481acSNicolas Bonnefon void CrawlerWidget::selectAll()
122039481acSNicolas Bonnefon {
123039481acSNicolas Bonnefon activeView()->selectAll();
124039481acSNicolas Bonnefon }
125039481acSNicolas Bonnefon
encodingSetting() const126209000a6SNicolas Bonnefon Encoding CrawlerWidget::encodingSetting() const
1275fa25391SNicolas Bonnefon {
1285fa25391SNicolas Bonnefon return encodingSetting_;
1295fa25391SNicolas Bonnefon }
1305fa25391SNicolas Bonnefon
isFollowEnabled() const13178dc0425SNicolas Bonnefon bool CrawlerWidget::isFollowEnabled() const
13278dc0425SNicolas Bonnefon {
13378dc0425SNicolas Bonnefon return logMainView->isFollowEnabled();
13478dc0425SNicolas Bonnefon }
13578dc0425SNicolas Bonnefon
encodingText() const1365fa25391SNicolas Bonnefon QString CrawlerWidget::encodingText() const
1375fa25391SNicolas Bonnefon {
1385fa25391SNicolas Bonnefon return encoding_text_;
1395fa25391SNicolas Bonnefon }
1405fa25391SNicolas Bonnefon
141039481acSNicolas Bonnefon // Return a pointer to the view in which we should do the QuickFind
doGetActiveSearchable() const142b423cd88SNicolas Bonnefon SearchableWidgetInterface* CrawlerWidget::doGetActiveSearchable() const
143039481acSNicolas Bonnefon {
144b423cd88SNicolas Bonnefon return activeView();
145b423cd88SNicolas Bonnefon }
146039481acSNicolas Bonnefon
147b423cd88SNicolas Bonnefon // Return all the searchable widgets (views)
doGetAllSearchables() const148b423cd88SNicolas Bonnefon std::vector<QObject*> CrawlerWidget::doGetAllSearchables() const
149b423cd88SNicolas Bonnefon {
150b423cd88SNicolas Bonnefon std::vector<QObject*> searchables =
151b423cd88SNicolas Bonnefon { logMainView, filteredView };
152039481acSNicolas Bonnefon
153b423cd88SNicolas Bonnefon return searchables;
154039481acSNicolas Bonnefon }
155039481acSNicolas Bonnefon
1569cacd6a9SNicolas Bonnefon // Update the state of the parent
doSendAllStateSignals()1579cacd6a9SNicolas Bonnefon void CrawlerWidget::doSendAllStateSignals()
1589cacd6a9SNicolas Bonnefon {
1599cacd6a9SNicolas Bonnefon emit updateLineNumber( currentLineNumber_ );
16060864ff5SNicolas Bonnefon if ( !loadingInProgress_ )
161812146a8SNicolas Bonnefon emit loadingFinished( LoadingStatus::Successful );
1629cacd6a9SNicolas Bonnefon }
1639cacd6a9SNicolas Bonnefon
keyPressEvent(QKeyEvent * keyEvent)164aa0a9454SNicolas Bonnefon void CrawlerWidget::keyPressEvent( QKeyEvent* keyEvent )
165aa0a9454SNicolas Bonnefon {
166aa0a9454SNicolas Bonnefon bool noModifier = keyEvent->modifiers() == Qt::NoModifier;
167aa0a9454SNicolas Bonnefon
168aa0a9454SNicolas Bonnefon if ( keyEvent->key() == Qt::Key_V && noModifier )
169aa0a9454SNicolas Bonnefon visibilityBox->setCurrentIndex(
170aa0a9454SNicolas Bonnefon ( visibilityBox->currentIndex() + 1 ) % visibilityBox->count() );
171aa0a9454SNicolas Bonnefon else {
172aa0a9454SNicolas Bonnefon const char character = (keyEvent->text())[0].toLatin1();
173aa0a9454SNicolas Bonnefon
174aa0a9454SNicolas Bonnefon if ( character == '+' )
175aa0a9454SNicolas Bonnefon changeTopViewSize( 1 );
176aa0a9454SNicolas Bonnefon else if ( character == '-' )
177aa0a9454SNicolas Bonnefon changeTopViewSize( -1 );
178aa0a9454SNicolas Bonnefon else
179aa0a9454SNicolas Bonnefon QSplitter::keyPressEvent( keyEvent );
180aa0a9454SNicolas Bonnefon }
181aa0a9454SNicolas Bonnefon }
182aa0a9454SNicolas Bonnefon
1837847299cSNicolas Bonnefon //
1847847299cSNicolas Bonnefon // Public slots
1857847299cSNicolas Bonnefon //
1867847299cSNicolas Bonnefon
stopLoading()1877847299cSNicolas Bonnefon void CrawlerWidget::stopLoading()
1887847299cSNicolas Bonnefon {
1897847299cSNicolas Bonnefon logFilteredData_->interruptSearch();
1907847299cSNicolas Bonnefon logData_->interruptLoading();
1917847299cSNicolas Bonnefon }
1927847299cSNicolas Bonnefon
reload()19332e44cfdSNicolas Bonnefon void CrawlerWidget::reload()
19432e44cfdSNicolas Bonnefon {
19532e44cfdSNicolas Bonnefon searchState_.resetState();
19632e44cfdSNicolas Bonnefon logFilteredData_->clearSearch();
1973d745936SDan Berindei logFilteredData_->clearMarks();
19832e44cfdSNicolas Bonnefon filteredView->updateData();
19932e44cfdSNicolas Bonnefon printSearchInfoMessage();
20032e44cfdSNicolas Bonnefon
20132e44cfdSNicolas Bonnefon logData_->reload();
20245ef183cSNicolas Bonnefon
20345ef183cSNicolas Bonnefon // A reload is considered as a first load,
20445ef183cSNicolas Bonnefon // this is to prevent the "new data" icon to be triggered.
20545ef183cSNicolas Bonnefon firstLoadDone_ = false;
20632e44cfdSNicolas Bonnefon }
20732e44cfdSNicolas Bonnefon
setEncoding(Encoding encoding)2085fa25391SNicolas Bonnefon void CrawlerWidget::setEncoding( Encoding encoding )
2095fa25391SNicolas Bonnefon {
2105fa25391SNicolas Bonnefon encodingSetting_ = encoding;
2115fa25391SNicolas Bonnefon updateEncoding();
2125fa25391SNicolas Bonnefon
2135fa25391SNicolas Bonnefon update();
2145fa25391SNicolas Bonnefon }
2155fa25391SNicolas Bonnefon
216039481acSNicolas Bonnefon //
217039481acSNicolas Bonnefon // Protected functions
218039481acSNicolas Bonnefon //
doSetData(std::shared_ptr<LogData> log_data,std::shared_ptr<LogFilteredData> filtered_data)219039481acSNicolas Bonnefon void CrawlerWidget::doSetData(
220039481acSNicolas Bonnefon std::shared_ptr<LogData> log_data,
221039481acSNicolas Bonnefon std::shared_ptr<LogFilteredData> filtered_data )
222039481acSNicolas Bonnefon {
223039481acSNicolas Bonnefon logData_ = log_data.get();
224039481acSNicolas Bonnefon logFilteredData_ = filtered_data.get();
2251b5e406eSNicolas Bonnefon }
226039481acSNicolas Bonnefon
doSetQuickFindPattern(std::shared_ptr<QuickFindPattern> qfp)227b423cd88SNicolas Bonnefon void CrawlerWidget::doSetQuickFindPattern(
228b423cd88SNicolas Bonnefon std::shared_ptr<QuickFindPattern> qfp )
229b423cd88SNicolas Bonnefon {
230b423cd88SNicolas Bonnefon quickFindPattern_ = qfp;
231b423cd88SNicolas Bonnefon }
232b423cd88SNicolas Bonnefon
doSetSavedSearches(std::shared_ptr<SavedSearches> saved_searches)2331b5e406eSNicolas Bonnefon void CrawlerWidget::doSetSavedSearches(
2341b5e406eSNicolas Bonnefon std::shared_ptr<SavedSearches> saved_searches )
2351b5e406eSNicolas Bonnefon {
2361b5e406eSNicolas Bonnefon savedSearches_ = saved_searches;
2371b5e406eSNicolas Bonnefon
2381b5e406eSNicolas Bonnefon // We do setup now, assuming doSetData has been called before
2391b5e406eSNicolas Bonnefon // us, that's not great really...
240039481acSNicolas Bonnefon setup();
241039481acSNicolas Bonnefon }
242039481acSNicolas Bonnefon
doSetViewContext(const char * view_context)243a44d09bcSNicolas Bonnefon void CrawlerWidget::doSetViewContext(
244a44d09bcSNicolas Bonnefon const char* view_context )
245a44d09bcSNicolas Bonnefon {
246a44d09bcSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::doSetViewContext: " << view_context;
247a44d09bcSNicolas Bonnefon
248a44d09bcSNicolas Bonnefon CrawlerWidgetContext context = { view_context };
249a44d09bcSNicolas Bonnefon
250a44d09bcSNicolas Bonnefon setSizes( context.sizes() );
251f688be2eSNicolas Bonnefon ignoreCaseCheck->setCheckState( context.ignoreCase() ? Qt::Checked : Qt::Unchecked );
252240a4b5eSNicolas Bonnefon
253240a4b5eSNicolas Bonnefon auto auto_refresh_check_state = context.autoRefresh() ? Qt::Checked : Qt::Unchecked;
254240a4b5eSNicolas Bonnefon searchRefreshCheck->setCheckState( auto_refresh_check_state );
255240a4b5eSNicolas Bonnefon // Manually call the handler as it is not called when changing the state programmatically
256240a4b5eSNicolas Bonnefon searchRefreshChangedHandler( auto_refresh_check_state );
257af94bdd6SNicolas Bonnefon
258af94bdd6SNicolas Bonnefon emit followSet( context.followFile() );
259a44d09bcSNicolas Bonnefon }
260a44d09bcSNicolas Bonnefon
261a44d09bcSNicolas Bonnefon std::shared_ptr<const ViewContextInterface>
doGetViewContext() const262a44d09bcSNicolas Bonnefon CrawlerWidget::doGetViewContext() const
263a44d09bcSNicolas Bonnefon {
264f688be2eSNicolas Bonnefon auto context = std::make_shared<const CrawlerWidgetContext>(
265f688be2eSNicolas Bonnefon sizes(),
266f688be2eSNicolas Bonnefon ( ignoreCaseCheck->checkState() == Qt::Checked ),
267af94bdd6SNicolas Bonnefon ( searchRefreshCheck->checkState() == Qt::Checked ),
268af94bdd6SNicolas Bonnefon logMainView->isFollowEnabled() );
269a44d09bcSNicolas Bonnefon
270a44d09bcSNicolas Bonnefon return static_cast<std::shared_ptr<const ViewContextInterface>>( context );
271a44d09bcSNicolas Bonnefon }
272a44d09bcSNicolas Bonnefon
273039481acSNicolas Bonnefon //
274039481acSNicolas Bonnefon // Slots
275039481acSNicolas Bonnefon //
276039481acSNicolas Bonnefon
startNewSearch()277039481acSNicolas Bonnefon void CrawlerWidget::startNewSearch()
278039481acSNicolas Bonnefon {
279039481acSNicolas Bonnefon // Record the search line in the recent list
280039481acSNicolas Bonnefon // (reload the list first in case another glogg changed it)
281039481acSNicolas Bonnefon GetPersistentInfo().retrieve( "savedSearches" );
2821b5e406eSNicolas Bonnefon savedSearches_->addRecent( searchLineEdit->currentText() );
283039481acSNicolas Bonnefon GetPersistentInfo().save( "savedSearches" );
284039481acSNicolas Bonnefon
285039481acSNicolas Bonnefon // Update the SearchLine (history)
286039481acSNicolas Bonnefon updateSearchCombo();
287039481acSNicolas Bonnefon // Call the private function to do the search
288039481acSNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() );
289039481acSNicolas Bonnefon }
290039481acSNicolas Bonnefon
stopSearch()291039481acSNicolas Bonnefon void CrawlerWidget::stopSearch()
292039481acSNicolas Bonnefon {
293039481acSNicolas Bonnefon logFilteredData_->interruptSearch();
294039481acSNicolas Bonnefon searchState_.stopSearch();
295039481acSNicolas Bonnefon printSearchInfoMessage();
296039481acSNicolas Bonnefon }
297039481acSNicolas Bonnefon
298039481acSNicolas Bonnefon // When receiving the 'newDataAvailable' signal from LogFilteredData
updateFilteredView(int nbMatches,int progress,qint64 initial_position)299c59cadb3SNicolas Bonnefon void CrawlerWidget::updateFilteredView( int nbMatches, int progress, qint64 initial_position )
300039481acSNicolas Bonnefon {
301039481acSNicolas Bonnefon LOG(logDEBUG) << "updateFilteredView received.";
302039481acSNicolas Bonnefon
303039481acSNicolas Bonnefon if ( progress == 100 ) {
304039481acSNicolas Bonnefon // Searching done
305039481acSNicolas Bonnefon printSearchInfoMessage( nbMatches );
306039481acSNicolas Bonnefon searchInfoLine->hideGauge();
307039481acSNicolas Bonnefon // De-activate the stop button
308039481acSNicolas Bonnefon stopButton->setEnabled( false );
309039481acSNicolas Bonnefon }
310039481acSNicolas Bonnefon else {
311039481acSNicolas Bonnefon // Search in progress
312039481acSNicolas Bonnefon // We ignore 0% and 100% to avoid a flash when the search is very short
313039481acSNicolas Bonnefon if ( progress > 0 ) {
314039481acSNicolas Bonnefon searchInfoLine->setText(
315039481acSNicolas Bonnefon tr("Search in progress (%1 %)... %2 match%3 found so far.")
316039481acSNicolas Bonnefon .arg( progress )
317039481acSNicolas Bonnefon .arg( nbMatches )
318039481acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" ) );
319039481acSNicolas Bonnefon searchInfoLine->displayGauge( progress );
320039481acSNicolas Bonnefon }
321039481acSNicolas Bonnefon }
322039481acSNicolas Bonnefon
3238ea5bc4cSNicolas Bonnefon // If more (or less, e.g. come back to 0) matches have been found
3248ea5bc4cSNicolas Bonnefon if ( nbMatches != nbMatches_ ) {
3257999f43eSNicolas Bonnefon nbMatches_ = nbMatches;
3267999f43eSNicolas Bonnefon
327039481acSNicolas Bonnefon // Recompute the content of the filtered window.
328039481acSNicolas Bonnefon filteredView->updateData();
329039481acSNicolas Bonnefon
330039481acSNicolas Bonnefon // Update the match overview
3310f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() );
332039481acSNicolas Bonnefon
333c59cadb3SNicolas Bonnefon // New data found icon (only for "update" search)
334c59cadb3SNicolas Bonnefon if ( initial_position > 0 )
3357999f43eSNicolas Bonnefon changeDataStatus( DataStatus::NEW_FILTERED_DATA );
3367999f43eSNicolas Bonnefon
337039481acSNicolas Bonnefon // Also update the top window for the coloured bullets.
338039481acSNicolas Bonnefon update();
339039481acSNicolas Bonnefon }
3403ff6c941SAnton Filimonov
3418b54586cSNicolas Bonnefon // Try to restore the filtered window selection close to where it was
3428b54586cSNicolas Bonnefon // only for full searches to avoid disconnecting follow mode!
3438b54586cSNicolas Bonnefon if ( ( progress == 100 ) && ( initial_position == 0 ) && ( !isFollowEnabled() ) ) {
3443ff6c941SAnton Filimonov const int currenLineIndex = logFilteredData_->getLineIndexNumber(currentLineNumber_);
3453ff6c941SAnton Filimonov LOG(logDEBUG) << "updateFilteredView: restoring selection: "
3463ff6c941SAnton Filimonov << " absolute line number (0based) " << currentLineNumber_
3473ff6c941SAnton Filimonov << " index " << currenLineIndex;
3483ff6c941SAnton Filimonov filteredView->selectAndDisplayLine(currenLineIndex);
3493ff6c941SAnton Filimonov }
3507999f43eSNicolas Bonnefon }
351039481acSNicolas Bonnefon
jumpToMatchingLine(int filteredLineNb)352039481acSNicolas Bonnefon void CrawlerWidget::jumpToMatchingLine(int filteredLineNb)
353039481acSNicolas Bonnefon {
354039481acSNicolas Bonnefon int mainViewLine = logFilteredData_->getMatchingLineNumber(filteredLineNb);
355039481acSNicolas Bonnefon logMainView->selectAndDisplayLine(mainViewLine); // FIXME: should be done with a signal.
356039481acSNicolas Bonnefon }
357039481acSNicolas Bonnefon
updateLineNumberHandler(int line)3589cacd6a9SNicolas Bonnefon void CrawlerWidget::updateLineNumberHandler( int line )
3599cacd6a9SNicolas Bonnefon {
3609cacd6a9SNicolas Bonnefon currentLineNumber_ = line;
3619cacd6a9SNicolas Bonnefon emit updateLineNumber( line );
3629cacd6a9SNicolas Bonnefon }
3639cacd6a9SNicolas Bonnefon
markLineFromMain(qint64 line)364039481acSNicolas Bonnefon void CrawlerWidget::markLineFromMain( qint64 line )
365039481acSNicolas Bonnefon {
3662493b508SNicolas Bonnefon if ( line < logData_->getNbLine() ) {
367039481acSNicolas Bonnefon if ( logFilteredData_->isLineMarked( line ) )
368039481acSNicolas Bonnefon logFilteredData_->deleteMark( line );
369039481acSNicolas Bonnefon else
370039481acSNicolas Bonnefon logFilteredData_->addMark( line );
371039481acSNicolas Bonnefon
3727552c461SNicolas Bonnefon // Recompute the content of both window.
373039481acSNicolas Bonnefon filteredView->updateData();
3747552c461SNicolas Bonnefon logMainView->updateData();
375039481acSNicolas Bonnefon
376039481acSNicolas Bonnefon // Update the match overview
3770f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() );
378039481acSNicolas Bonnefon
379039481acSNicolas Bonnefon // Also update the top window for the coloured bullets.
380039481acSNicolas Bonnefon update();
381039481acSNicolas Bonnefon }
3822493b508SNicolas Bonnefon }
383039481acSNicolas Bonnefon
markLineFromFiltered(qint64 line)384039481acSNicolas Bonnefon void CrawlerWidget::markLineFromFiltered( qint64 line )
385039481acSNicolas Bonnefon {
3862493b508SNicolas Bonnefon if ( line < logFilteredData_->getNbLine() ) {
387039481acSNicolas Bonnefon qint64 line_in_file = logFilteredData_->getMatchingLineNumber( line );
388039481acSNicolas Bonnefon if ( logFilteredData_->filteredLineTypeByIndex( line )
389039481acSNicolas Bonnefon == LogFilteredData::Mark )
390039481acSNicolas Bonnefon logFilteredData_->deleteMark( line_in_file );
391039481acSNicolas Bonnefon else
392039481acSNicolas Bonnefon logFilteredData_->addMark( line_in_file );
393039481acSNicolas Bonnefon
3947552c461SNicolas Bonnefon // Recompute the content of both window.
395039481acSNicolas Bonnefon filteredView->updateData();
3967552c461SNicolas Bonnefon logMainView->updateData();
397039481acSNicolas Bonnefon
398039481acSNicolas Bonnefon // Update the match overview
3990f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() );
400039481acSNicolas Bonnefon
401039481acSNicolas Bonnefon // Also update the top window for the coloured bullets.
402039481acSNicolas Bonnefon update();
403039481acSNicolas Bonnefon }
4042493b508SNicolas Bonnefon }
405039481acSNicolas Bonnefon
applyConfiguration()406039481acSNicolas Bonnefon void CrawlerWidget::applyConfiguration()
407039481acSNicolas Bonnefon {
40811582726SNicolas Bonnefon std::shared_ptr<Configuration> config =
40911582726SNicolas Bonnefon Persistent<Configuration>( "settings" );
41011582726SNicolas Bonnefon QFont font = config->mainFont();
411039481acSNicolas Bonnefon
412039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::applyConfiguration";
413039481acSNicolas Bonnefon
414039481acSNicolas Bonnefon // Whatever font we use, we should NOT use kerning
415039481acSNicolas Bonnefon font.setKerning( false );
416039481acSNicolas Bonnefon font.setFixedPitch( true );
417039481acSNicolas Bonnefon #if QT_VERSION > 0x040700
418039481acSNicolas Bonnefon // Necessary on systems doing subpixel positionning (e.g. Ubuntu 12.04)
419039481acSNicolas Bonnefon font.setStyleStrategy( QFont::ForceIntegerMetrics );
420039481acSNicolas Bonnefon #endif
421039481acSNicolas Bonnefon logMainView->setFont(font);
422039481acSNicolas Bonnefon filteredView->setFont(font);
423039481acSNicolas Bonnefon
42411582726SNicolas Bonnefon logMainView->setLineNumbersVisible( config->mainLineNumbersVisible() );
42511582726SNicolas Bonnefon filteredView->setLineNumbersVisible( config->filteredLineNumbersVisible() );
426039481acSNicolas Bonnefon
42711582726SNicolas Bonnefon overview_.setVisible( config->isOverviewVisible() );
428039481acSNicolas Bonnefon logMainView->refreshOverview();
429039481acSNicolas Bonnefon
430039481acSNicolas Bonnefon logMainView->updateDisplaySize();
431039481acSNicolas Bonnefon logMainView->update();
432039481acSNicolas Bonnefon filteredView->updateDisplaySize();
433039481acSNicolas Bonnefon filteredView->update();
434039481acSNicolas Bonnefon
43580bca0a3SNicolas Bonnefon // Polling interval
43680bca0a3SNicolas Bonnefon logData_->setPollingInterval(
43780bca0a3SNicolas Bonnefon config->pollingEnabled() ? config->pollIntervalMs() : 0 );
43880bca0a3SNicolas Bonnefon
439039481acSNicolas Bonnefon // Update the SearchLine (history)
440039481acSNicolas Bonnefon updateSearchCombo();
441039481acSNicolas Bonnefon }
442039481acSNicolas Bonnefon
enteringQuickFind()4438570d8d2SNicolas Bonnefon void CrawlerWidget::enteringQuickFind()
4448570d8d2SNicolas Bonnefon {
4458570d8d2SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::enteringQuickFind";
4468570d8d2SNicolas Bonnefon
4478570d8d2SNicolas Bonnefon // Remember who had the focus (only if it is one of our views)
4488570d8d2SNicolas Bonnefon QWidget* focus_widget = QApplication::focusWidget();
4498570d8d2SNicolas Bonnefon
4508570d8d2SNicolas Bonnefon if ( ( focus_widget == logMainView ) || ( focus_widget == filteredView ) )
4518570d8d2SNicolas Bonnefon qfSavedFocus_ = focus_widget;
4528570d8d2SNicolas Bonnefon else
4538570d8d2SNicolas Bonnefon qfSavedFocus_ = nullptr;
4548570d8d2SNicolas Bonnefon }
4558570d8d2SNicolas Bonnefon
exitingQuickFind()4568570d8d2SNicolas Bonnefon void CrawlerWidget::exitingQuickFind()
4578570d8d2SNicolas Bonnefon {
4588570d8d2SNicolas Bonnefon // Restore the focus once the QFBar has been hidden
4598570d8d2SNicolas Bonnefon if ( qfSavedFocus_ )
4608570d8d2SNicolas Bonnefon qfSavedFocus_->setFocus();
4618570d8d2SNicolas Bonnefon }
4628570d8d2SNicolas Bonnefon
loadingFinishedHandler(LoadingStatus status)463812146a8SNicolas Bonnefon void CrawlerWidget::loadingFinishedHandler( LoadingStatus status )
464039481acSNicolas Bonnefon {
46560864ff5SNicolas Bonnefon loadingInProgress_ = false;
46660864ff5SNicolas Bonnefon
467039481acSNicolas Bonnefon // We need to refresh the main window because the view lines on the
468039481acSNicolas Bonnefon // overview have probably changed.
4690f9fd9edSNicolas Bonnefon overview_.updateData( logData_->getNbLine() );
470039481acSNicolas Bonnefon
471039481acSNicolas Bonnefon // FIXME, handle topLine
472039481acSNicolas Bonnefon // logMainView->updateData( logData_, topLine );
473039481acSNicolas Bonnefon logMainView->updateData();
474039481acSNicolas Bonnefon
475039481acSNicolas Bonnefon // Shall we Forbid starting a search when loading in progress?
476039481acSNicolas Bonnefon // searchButton->setEnabled( false );
477039481acSNicolas Bonnefon
478039481acSNicolas Bonnefon // searchButton->setEnabled( true );
479039481acSNicolas Bonnefon
480039481acSNicolas Bonnefon // See if we need to auto-refresh the search
481039481acSNicolas Bonnefon if ( searchState_.isAutorefreshAllowed() ) {
48259d4e393SNicolas Bonnefon if ( searchState_.isFileTruncated() )
48359d4e393SNicolas Bonnefon // We need to restart the search
48459d4e393SNicolas Bonnefon replaceCurrentSearch( searchLineEdit->currentText() );
48559d4e393SNicolas Bonnefon else
486039481acSNicolas Bonnefon logFilteredData_->updateSearch();
487039481acSNicolas Bonnefon }
488039481acSNicolas Bonnefon
4895fa25391SNicolas Bonnefon // Set the encoding for the views
4905fa25391SNicolas Bonnefon updateEncoding();
4915fa25391SNicolas Bonnefon
492812146a8SNicolas Bonnefon emit loadingFinished( status );
49345ef183cSNicolas Bonnefon
49445ef183cSNicolas Bonnefon // Also change the data available icon
49545ef183cSNicolas Bonnefon if ( firstLoadDone_ )
49645ef183cSNicolas Bonnefon changeDataStatus( DataStatus::NEW_DATA );
49745ef183cSNicolas Bonnefon else
49845ef183cSNicolas Bonnefon firstLoadDone_ = true;
499039481acSNicolas Bonnefon }
500039481acSNicolas Bonnefon
fileChangedHandler(LogData::MonitoredFileStatus status)501039481acSNicolas Bonnefon void CrawlerWidget::fileChangedHandler( LogData::MonitoredFileStatus status )
502039481acSNicolas Bonnefon {
503039481acSNicolas Bonnefon // Handle the case where the file has been truncated
504039481acSNicolas Bonnefon if ( status == LogData::Truncated ) {
505039481acSNicolas Bonnefon // Clear all marks (TODO offer the option to keep them)
506039481acSNicolas Bonnefon logFilteredData_->clearMarks();
507039481acSNicolas Bonnefon if ( ! searchInfoLine->text().isEmpty() ) {
508039481acSNicolas Bonnefon // Invalidate the search
509039481acSNicolas Bonnefon logFilteredData_->clearSearch();
510039481acSNicolas Bonnefon filteredView->updateData();
511039481acSNicolas Bonnefon searchState_.truncateFile();
512039481acSNicolas Bonnefon printSearchInfoMessage();
5137999f43eSNicolas Bonnefon nbMatches_ = 0;
514039481acSNicolas Bonnefon }
515039481acSNicolas Bonnefon }
516039481acSNicolas Bonnefon }
517039481acSNicolas Bonnefon
518039481acSNicolas Bonnefon // Returns a pointer to the window in which the search should be done
activeView() const519039481acSNicolas Bonnefon AbstractLogView* CrawlerWidget::activeView() const
520039481acSNicolas Bonnefon {
521039481acSNicolas Bonnefon QWidget* activeView;
522039481acSNicolas Bonnefon
523039481acSNicolas Bonnefon // Search in the window that has focus, or the window where 'Find' was
524039481acSNicolas Bonnefon // called from, or the main window.
525039481acSNicolas Bonnefon if ( filteredView->hasFocus() || logMainView->hasFocus() )
526039481acSNicolas Bonnefon activeView = QApplication::focusWidget();
527039481acSNicolas Bonnefon else
5288570d8d2SNicolas Bonnefon activeView = qfSavedFocus_;
529039481acSNicolas Bonnefon
530b423cd88SNicolas Bonnefon if ( activeView ) {
531b423cd88SNicolas Bonnefon AbstractLogView* view = qobject_cast<AbstractLogView*>( activeView );
532039481acSNicolas Bonnefon return view;
533b423cd88SNicolas Bonnefon }
534b423cd88SNicolas Bonnefon else {
535b423cd88SNicolas Bonnefon LOG(logWARNING) << "No active view, defaulting to logMainView";
536039481acSNicolas Bonnefon return logMainView;
537039481acSNicolas Bonnefon }
538b423cd88SNicolas Bonnefon }
539039481acSNicolas Bonnefon
searchForward()540039481acSNicolas Bonnefon void CrawlerWidget::searchForward()
541039481acSNicolas Bonnefon {
542039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchForward";
543039481acSNicolas Bonnefon
544039481acSNicolas Bonnefon activeView()->searchForward();
545039481acSNicolas Bonnefon }
546039481acSNicolas Bonnefon
searchBackward()547039481acSNicolas Bonnefon void CrawlerWidget::searchBackward()
548039481acSNicolas Bonnefon {
549039481acSNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::searchBackward";
550039481acSNicolas Bonnefon
551039481acSNicolas Bonnefon activeView()->searchBackward();
552039481acSNicolas Bonnefon }
553039481acSNicolas Bonnefon
searchRefreshChangedHandler(int state)554039481acSNicolas Bonnefon void CrawlerWidget::searchRefreshChangedHandler( int state )
555039481acSNicolas Bonnefon {
556039481acSNicolas Bonnefon searchState_.setAutorefresh( state == Qt::Checked );
557039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() );
558039481acSNicolas Bonnefon }
559039481acSNicolas Bonnefon
searchTextChangeHandler()560039481acSNicolas Bonnefon void CrawlerWidget::searchTextChangeHandler()
561039481acSNicolas Bonnefon {
562039481acSNicolas Bonnefon // We suspend auto-refresh
563039481acSNicolas Bonnefon searchState_.changeExpression();
564039481acSNicolas Bonnefon printSearchInfoMessage( logFilteredData_->getNbMatches() );
565039481acSNicolas Bonnefon }
566039481acSNicolas Bonnefon
changeFilteredViewVisibility(int index)567039481acSNicolas Bonnefon void CrawlerWidget::changeFilteredViewVisibility( int index )
568039481acSNicolas Bonnefon {
569039481acSNicolas Bonnefon QStandardItem* item = visibilityModel_->item( index );
570039481acSNicolas Bonnefon FilteredView::Visibility visibility =
571039481acSNicolas Bonnefon static_cast< FilteredView::Visibility>( item->data().toInt() );
572039481acSNicolas Bonnefon
573039481acSNicolas Bonnefon filteredView->setVisibility( visibility );
5743ff6c941SAnton Filimonov
5753ff6c941SAnton Filimonov const int lineIndex = logFilteredData_->getLineIndexNumber( currentLineNumber_ );
5763ff6c941SAnton Filimonov filteredView->selectAndDisplayLine( lineIndex );
577039481acSNicolas Bonnefon }
578039481acSNicolas Bonnefon
addToSearch(const QString & string)579039481acSNicolas Bonnefon void CrawlerWidget::addToSearch( const QString& string )
580039481acSNicolas Bonnefon {
581039481acSNicolas Bonnefon QString text = searchLineEdit->currentText();
582039481acSNicolas Bonnefon
583039481acSNicolas Bonnefon if ( text.isEmpty() )
584039481acSNicolas Bonnefon text = string;
585039481acSNicolas Bonnefon else {
586039481acSNicolas Bonnefon // Escape the regexp chars from the string before adding it.
5874fb0346eSAnton Filimonov text += ( '|' + QRegularExpression::escape( string ) );
588039481acSNicolas Bonnefon }
589039481acSNicolas Bonnefon
590039481acSNicolas Bonnefon searchLineEdit->setEditText( text );
591039481acSNicolas Bonnefon
592039481acSNicolas Bonnefon // Set the focus to lineEdit so that the user can press 'Return' immediately
593039481acSNicolas Bonnefon searchLineEdit->lineEdit()->setFocus();
594039481acSNicolas Bonnefon }
595039481acSNicolas Bonnefon
mouseHoveredOverMatch(qint64 line)596039481acSNicolas Bonnefon void CrawlerWidget::mouseHoveredOverMatch( qint64 line )
597039481acSNicolas Bonnefon {
598039481acSNicolas Bonnefon qint64 line_in_mainview = logFilteredData_->getMatchingLineNumber( line );
599039481acSNicolas Bonnefon
600039481acSNicolas Bonnefon overviewWidget_->highlightLine( line_in_mainview );
601039481acSNicolas Bonnefon }
602039481acSNicolas Bonnefon
activityDetected()60345ef183cSNicolas Bonnefon void CrawlerWidget::activityDetected()
60445ef183cSNicolas Bonnefon {
60545ef183cSNicolas Bonnefon changeDataStatus( DataStatus::OLD_DATA );
60645ef183cSNicolas Bonnefon }
60745ef183cSNicolas Bonnefon
608039481acSNicolas Bonnefon //
609039481acSNicolas Bonnefon // Private functions
610039481acSNicolas Bonnefon //
611039481acSNicolas Bonnefon
612039481acSNicolas Bonnefon // Build the widget and connect all the signals, this must be done once
613039481acSNicolas Bonnefon // the data are attached.
setup()614039481acSNicolas Bonnefon void CrawlerWidget::setup()
615039481acSNicolas Bonnefon {
616bb02e0acSNicolas Bonnefon setOrientation(Qt::Vertical);
617bb02e0acSNicolas Bonnefon
618039481acSNicolas Bonnefon assert( logData_ );
619039481acSNicolas Bonnefon assert( logFilteredData_ );
620bb02e0acSNicolas Bonnefon
621bb02e0acSNicolas Bonnefon // The views
622bb02e0acSNicolas Bonnefon bottomWindow = new QWidget;
623bb02e0acSNicolas Bonnefon overviewWidget_ = new OverviewWidget();
624bb02e0acSNicolas Bonnefon logMainView = new LogMainView(
6250f9fd9edSNicolas Bonnefon logData_, quickFindPattern_.get(), &overview_, overviewWidget_ );
626bb02e0acSNicolas Bonnefon filteredView = new FilteredView(
627b423cd88SNicolas Bonnefon logFilteredData_, quickFindPattern_.get() );
628bb02e0acSNicolas Bonnefon
6290f9fd9edSNicolas Bonnefon overviewWidget_->setOverview( &overview_ );
630bb02e0acSNicolas Bonnefon overviewWidget_->setParent( logMainView );
631bb02e0acSNicolas Bonnefon
63258ab9c53SNicolas Bonnefon // Connect the search to the top view
63358ab9c53SNicolas Bonnefon logMainView->useNewFiltering( logFilteredData_ );
63458ab9c53SNicolas Bonnefon
635bb02e0acSNicolas Bonnefon // Construct the visibility button
636bb02e0acSNicolas Bonnefon visibilityModel_ = new QStandardItemModel( this );
637bb02e0acSNicolas Bonnefon
638bb02e0acSNicolas Bonnefon QStandardItem *marksAndMatchesItem = new QStandardItem( tr( "Marks and matches" ) );
639bb02e0acSNicolas Bonnefon QPixmap marksAndMatchesPixmap( 16, 10 );
640bb02e0acSNicolas Bonnefon marksAndMatchesPixmap.fill( Qt::gray );
641bb02e0acSNicolas Bonnefon marksAndMatchesItem->setIcon( QIcon( marksAndMatchesPixmap ) );
642bb02e0acSNicolas Bonnefon marksAndMatchesItem->setData( FilteredView::MarksAndMatches );
643bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksAndMatchesItem );
644bb02e0acSNicolas Bonnefon
645bb02e0acSNicolas Bonnefon QStandardItem *marksItem = new QStandardItem( tr( "Marks" ) );
646bb02e0acSNicolas Bonnefon QPixmap marksPixmap( 16, 10 );
647bb02e0acSNicolas Bonnefon marksPixmap.fill( Qt::blue );
648bb02e0acSNicolas Bonnefon marksItem->setIcon( QIcon( marksPixmap ) );
649bb02e0acSNicolas Bonnefon marksItem->setData( FilteredView::MarksOnly );
650bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( marksItem );
651bb02e0acSNicolas Bonnefon
652bb02e0acSNicolas Bonnefon QStandardItem *matchesItem = new QStandardItem( tr( "Matches" ) );
653bb02e0acSNicolas Bonnefon QPixmap matchesPixmap( 16, 10 );
654bb02e0acSNicolas Bonnefon matchesPixmap.fill( Qt::red );
655bb02e0acSNicolas Bonnefon matchesItem->setIcon( QIcon( matchesPixmap ) );
656bb02e0acSNicolas Bonnefon matchesItem->setData( FilteredView::MatchesOnly );
657bb02e0acSNicolas Bonnefon visibilityModel_->appendRow( matchesItem );
658bb02e0acSNicolas Bonnefon
659bb02e0acSNicolas Bonnefon QListView *visibilityView = new QListView( this );
660bb02e0acSNicolas Bonnefon visibilityView->setMovement( QListView::Static );
661bb02e0acSNicolas Bonnefon visibilityView->setMinimumWidth( 170 ); // Only needed with custom style-sheet
662bb02e0acSNicolas Bonnefon
663bb02e0acSNicolas Bonnefon visibilityBox = new QComboBox();
664bb02e0acSNicolas Bonnefon visibilityBox->setModel( visibilityModel_ );
665bb02e0acSNicolas Bonnefon visibilityBox->setView( visibilityView );
666bb02e0acSNicolas Bonnefon
667bb02e0acSNicolas Bonnefon // Select "Marks and matches" by default (same default as the filtered view)
668bb02e0acSNicolas Bonnefon visibilityBox->setCurrentIndex( 0 );
669bb02e0acSNicolas Bonnefon
670bb02e0acSNicolas Bonnefon // TODO: Maybe there is some way to set the popup width to be
671bb02e0acSNicolas Bonnefon // sized-to-content (as it is when the stylesheet is not overriden) in the
672bb02e0acSNicolas Bonnefon // stylesheet as opposed to setting a hard min-width on the view above.
673bb02e0acSNicolas Bonnefon visibilityBox->setStyleSheet( " \
674bb02e0acSNicolas Bonnefon QComboBox:on {\
675bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 6px;\
676bb02e0acSNicolas Bonnefon width: 19px;\
677bb02e0acSNicolas Bonnefon } \
678bb02e0acSNicolas Bonnefon QComboBox:!on {\
679bb02e0acSNicolas Bonnefon padding: 1px 2px 1px 7px;\
680bb02e0acSNicolas Bonnefon width: 19px;\
681bb02e0acSNicolas Bonnefon height: 16px;\
682bb02e0acSNicolas Bonnefon border: 1px solid gray;\
683bb02e0acSNicolas Bonnefon } \
684bb02e0acSNicolas Bonnefon QComboBox::drop-down::down-arrow {\
685bb02e0acSNicolas Bonnefon width: 0px;\
686bb02e0acSNicolas Bonnefon border-width: 0px;\
687bb02e0acSNicolas Bonnefon } \
688bb02e0acSNicolas Bonnefon " );
689bb02e0acSNicolas Bonnefon
690bb02e0acSNicolas Bonnefon // Construct the Search Info line
691bb02e0acSNicolas Bonnefon searchInfoLine = new InfoLine();
692bb02e0acSNicolas Bonnefon searchInfoLine->setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
693bb02e0acSNicolas Bonnefon searchInfoLine->setLineWidth( 1 );
694bb02e0acSNicolas Bonnefon searchInfoLineDefaultPalette = searchInfoLine->palette();
695bb02e0acSNicolas Bonnefon
696bb02e0acSNicolas Bonnefon ignoreCaseCheck = new QCheckBox( "Ignore &case" );
697bb02e0acSNicolas Bonnefon searchRefreshCheck = new QCheckBox( "Auto-&refresh" );
698bb02e0acSNicolas Bonnefon
699bb02e0acSNicolas Bonnefon // Construct the Search line
700bb02e0acSNicolas Bonnefon searchLabel = new QLabel(tr("&Text: "));
701bb02e0acSNicolas Bonnefon searchLineEdit = new QComboBox;
702bb02e0acSNicolas Bonnefon searchLineEdit->setEditable( true );
703bb02e0acSNicolas Bonnefon searchLineEdit->setCompleter( 0 );
7041b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() );
705bb02e0acSNicolas Bonnefon searchLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
706bb02e0acSNicolas Bonnefon searchLineEdit->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
707bb02e0acSNicolas Bonnefon
708bb02e0acSNicolas Bonnefon searchLabel->setBuddy( searchLineEdit );
709bb02e0acSNicolas Bonnefon
710bb02e0acSNicolas Bonnefon searchButton = new QToolButton();
711bb02e0acSNicolas Bonnefon searchButton->setText( tr("&Search") );
712bb02e0acSNicolas Bonnefon searchButton->setAutoRaise( true );
713bb02e0acSNicolas Bonnefon
714bb02e0acSNicolas Bonnefon stopButton = new QToolButton();
71528c802baSNicolas Bonnefon stopButton->setIcon( QIcon(":/images/stop14.png") );
716bb02e0acSNicolas Bonnefon stopButton->setAutoRaise( true );
717bb02e0acSNicolas Bonnefon stopButton->setEnabled( false );
718bb02e0acSNicolas Bonnefon
719bb02e0acSNicolas Bonnefon QHBoxLayout* searchLineLayout = new QHBoxLayout;
720bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLabel);
721bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchLineEdit);
722bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(searchButton);
723bb02e0acSNicolas Bonnefon searchLineLayout->addWidget(stopButton);
724bb02e0acSNicolas Bonnefon searchLineLayout->setContentsMargins(6, 0, 6, 0);
725bb02e0acSNicolas Bonnefon stopButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) );
726bb02e0acSNicolas Bonnefon searchButton->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) );
727bb02e0acSNicolas Bonnefon
728bb02e0acSNicolas Bonnefon QHBoxLayout* searchInfoLineLayout = new QHBoxLayout;
729bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( visibilityBox );
730bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchInfoLine );
731bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( ignoreCaseCheck );
732bb02e0acSNicolas Bonnefon searchInfoLineLayout->addWidget( searchRefreshCheck );
733bb02e0acSNicolas Bonnefon
734bb02e0acSNicolas Bonnefon // Construct the bottom window
735bb02e0acSNicolas Bonnefon QVBoxLayout* bottomMainLayout = new QVBoxLayout;
736bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchLineLayout);
737bb02e0acSNicolas Bonnefon bottomMainLayout->addLayout(searchInfoLineLayout);
738bb02e0acSNicolas Bonnefon bottomMainLayout->addWidget(filteredView);
739bb02e0acSNicolas Bonnefon bottomMainLayout->setContentsMargins(2, 1, 2, 1);
740bb02e0acSNicolas Bonnefon bottomWindow->setLayout(bottomMainLayout);
741bb02e0acSNicolas Bonnefon
742bb02e0acSNicolas Bonnefon addWidget( logMainView );
743bb02e0acSNicolas Bonnefon addWidget( bottomWindow );
744bb02e0acSNicolas Bonnefon
745bb02e0acSNicolas Bonnefon // Default splitter position (usually overridden by the config file)
746bb02e0acSNicolas Bonnefon QList<int> splitterSizes;
747bb02e0acSNicolas Bonnefon splitterSizes += 400;
748bb02e0acSNicolas Bonnefon splitterSizes += 100;
749bb02e0acSNicolas Bonnefon setSizes( splitterSizes );
750bb02e0acSNicolas Bonnefon
751f688be2eSNicolas Bonnefon // Default search checkboxes
752f688be2eSNicolas Bonnefon auto config = Persistent<Configuration>( "settings" );
753f688be2eSNicolas Bonnefon searchRefreshCheck->setCheckState( config->isSearchAutoRefreshDefault() ?
754f688be2eSNicolas Bonnefon Qt::Checked : Qt::Unchecked );
755c580560cSNicolas Bonnefon // Manually call the handler as it is not called when changing the state programmatically
756c580560cSNicolas Bonnefon searchRefreshChangedHandler( searchRefreshCheck->checkState() );
757f688be2eSNicolas Bonnefon ignoreCaseCheck->setCheckState( config->isSearchIgnoreCaseDefault() ?
758f688be2eSNicolas Bonnefon Qt::Checked : Qt::Unchecked );
759f688be2eSNicolas Bonnefon
760bb02e0acSNicolas Bonnefon // Connect the signals
761bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( returnPressed() ),
762bb02e0acSNicolas Bonnefon searchButton, SIGNAL( clicked() ));
763bb02e0acSNicolas Bonnefon connect(searchLineEdit->lineEdit(), SIGNAL( textEdited( const QString& ) ),
764bb02e0acSNicolas Bonnefon this, SLOT( searchTextChangeHandler() ));
765bb02e0acSNicolas Bonnefon connect(searchButton, SIGNAL( clicked() ),
766bb02e0acSNicolas Bonnefon this, SLOT( startNewSearch() ) );
767bb02e0acSNicolas Bonnefon connect(stopButton, SIGNAL( clicked() ),
768bb02e0acSNicolas Bonnefon this, SLOT( stopSearch() ) );
769bb02e0acSNicolas Bonnefon
770bb02e0acSNicolas Bonnefon connect(visibilityBox, SIGNAL( currentIndexChanged( int ) ),
771bb02e0acSNicolas Bonnefon this, SLOT( changeFilteredViewVisibility( int ) ) );
772bb02e0acSNicolas Bonnefon
773bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( newSelection( int ) ),
774bb02e0acSNicolas Bonnefon logMainView, SLOT( update() ) );
775bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ),
776bb02e0acSNicolas Bonnefon this, SLOT( jumpToMatchingLine( int ) ) );
777bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( newSelection( int ) ),
778bb02e0acSNicolas Bonnefon filteredView, SLOT( update() ) );
779bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( updateLineNumber( int ) ),
7809cacd6a9SNicolas Bonnefon this, SLOT( updateLineNumberHandler( int ) ) );
781bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( markLine( qint64 ) ),
782bb02e0acSNicolas Bonnefon this, SLOT( markLineFromMain( qint64 ) ) );
783bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( markLine( qint64 ) ),
784bb02e0acSNicolas Bonnefon this, SLOT( markLineFromFiltered( qint64 ) ) );
785bb02e0acSNicolas Bonnefon
786bb02e0acSNicolas Bonnefon connect(logMainView, SIGNAL( addToSearch( const QString& ) ),
787bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) );
788bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( addToSearch( const QString& ) ),
789bb02e0acSNicolas Bonnefon this, SLOT( addToSearch( const QString& ) ) );
790bb02e0acSNicolas Bonnefon
791bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseHoveredOverLine( qint64 ) ),
792bb02e0acSNicolas Bonnefon this, SLOT( mouseHoveredOverMatch( qint64 ) ) );
793bb02e0acSNicolas Bonnefon connect(filteredView, SIGNAL( mouseLeftHoveringZone() ),
794bb02e0acSNicolas Bonnefon overviewWidget_, SLOT( removeHighlight() ) );
795bb02e0acSNicolas Bonnefon
796bb02e0acSNicolas Bonnefon // Follow option (up and down)
797bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ),
798bb02e0acSNicolas Bonnefon logMainView, SLOT( followSet( bool ) ) );
799bb02e0acSNicolas Bonnefon connect(this, SIGNAL( followSet( bool ) ),
800bb02e0acSNicolas Bonnefon filteredView, SLOT( followSet( bool ) ) );
801b297d2f4SNicolas Bonnefon connect(logMainView, SIGNAL( followModeChanged( bool ) ),
802b297d2f4SNicolas Bonnefon this, SIGNAL( followModeChanged( bool ) ) );
803b297d2f4SNicolas Bonnefon connect(filteredView, SIGNAL( followModeChanged( bool ) ),
804b297d2f4SNicolas Bonnefon this, SIGNAL( followModeChanged( bool ) ) );
805bb02e0acSNicolas Bonnefon
80645ef183cSNicolas Bonnefon // Detect activity in the views
80745ef183cSNicolas Bonnefon connect(logMainView, SIGNAL( activity() ),
80845ef183cSNicolas Bonnefon this, SLOT( activityDetected() ) );
80945ef183cSNicolas Bonnefon connect(filteredView, SIGNAL( activity() ),
81045ef183cSNicolas Bonnefon this, SLOT( activityDetected() ) );
81145ef183cSNicolas Bonnefon
812c59cadb3SNicolas Bonnefon connect( logFilteredData_, SIGNAL( searchProgressed( int, int, qint64 ) ),
813c59cadb3SNicolas Bonnefon this, SLOT( updateFilteredView( int, int, qint64 ) ) );
814bb02e0acSNicolas Bonnefon
815bb02e0acSNicolas Bonnefon // Sent load file update to MainWindow (for status update)
816bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( loadingProgressed( int ) ),
817bb02e0acSNicolas Bonnefon this, SIGNAL( loadingProgressed( int ) ) );
818812146a8SNicolas Bonnefon connect( logData_, SIGNAL( loadingFinished( LoadingStatus ) ),
819812146a8SNicolas Bonnefon this, SLOT( loadingFinishedHandler( LoadingStatus ) ) );
820bb02e0acSNicolas Bonnefon connect( logData_, SIGNAL( fileChanged( LogData::MonitoredFileStatus ) ),
821bb02e0acSNicolas Bonnefon this, SLOT( fileChangedHandler( LogData::MonitoredFileStatus ) ) );
822bb02e0acSNicolas Bonnefon
823bb02e0acSNicolas Bonnefon // Search auto-refresh
824bb02e0acSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ),
825bb02e0acSNicolas Bonnefon this, SLOT( searchRefreshChangedHandler( int ) ) );
826f688be2eSNicolas Bonnefon
827f688be2eSNicolas Bonnefon // Advise the parent the checkboxes have been changed
828f688be2eSNicolas Bonnefon // (for maintaining default config)
829f688be2eSNicolas Bonnefon connect( searchRefreshCheck, SIGNAL( stateChanged( int ) ),
830f688be2eSNicolas Bonnefon this, SIGNAL( searchRefreshChanged( int ) ) );
831f688be2eSNicolas Bonnefon connect( ignoreCaseCheck, SIGNAL( stateChanged( int ) ),
832f688be2eSNicolas Bonnefon this, SIGNAL( ignoreCaseChanged( int ) ) );
8337552c461SNicolas Bonnefon
8347552c461SNicolas Bonnefon // Switch between views
8357552c461SNicolas Bonnefon connect( logMainView, SIGNAL( exitView() ),
8367552c461SNicolas Bonnefon filteredView, SLOT( setFocus() ) );
8377552c461SNicolas Bonnefon connect( filteredView, SIGNAL( exitView() ),
8387552c461SNicolas Bonnefon logMainView, SLOT( setFocus() ) );
839bb02e0acSNicolas Bonnefon }
840bb02e0acSNicolas Bonnefon
841bb02e0acSNicolas Bonnefon // Create a new search using the text passed, replace the currently
842bb02e0acSNicolas Bonnefon // used one and destroy the old one.
replaceCurrentSearch(const QString & searchText)843bb02e0acSNicolas Bonnefon void CrawlerWidget::replaceCurrentSearch( const QString& searchText )
844bb02e0acSNicolas Bonnefon {
845bb02e0acSNicolas Bonnefon // Interrupt the search if it's ongoing
846bb02e0acSNicolas Bonnefon logFilteredData_->interruptSearch();
847bb02e0acSNicolas Bonnefon
848bb02e0acSNicolas Bonnefon // We have to wait for the last search update (100%)
849bb02e0acSNicolas Bonnefon // before clearing/restarting to avoid having remaining results.
850bb02e0acSNicolas Bonnefon
851bb02e0acSNicolas Bonnefon // FIXME: this is a bit of a hack, we call processEvents
852bb02e0acSNicolas Bonnefon // for Qt to empty its event queue, including (hopefully)
853bb02e0acSNicolas Bonnefon // the search update event sent by logFilteredData_. It saves
854bb02e0acSNicolas Bonnefon // us the overhead of having proper sync.
855bb02e0acSNicolas Bonnefon QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
856bb02e0acSNicolas Bonnefon
8578ea5bc4cSNicolas Bonnefon nbMatches_ = 0;
8588ea5bc4cSNicolas Bonnefon
8598ea5bc4cSNicolas Bonnefon // Clear and recompute the content of the filtered window.
8608ea5bc4cSNicolas Bonnefon logFilteredData_->clearSearch();
8618ea5bc4cSNicolas Bonnefon filteredView->updateData();
8628ea5bc4cSNicolas Bonnefon
8638ea5bc4cSNicolas Bonnefon // Update the match overview
8648ea5bc4cSNicolas Bonnefon overview_.updateData( logData_->getNbLine() );
8658ea5bc4cSNicolas Bonnefon
866bb02e0acSNicolas Bonnefon if ( !searchText.isEmpty() ) {
8674fb0346eSAnton Filimonov
8684fb0346eSAnton Filimonov QString pattern;
8694fb0346eSAnton Filimonov
870bb02e0acSNicolas Bonnefon // Determine the type of regexp depending on the config
87111582726SNicolas Bonnefon static std::shared_ptr<Configuration> config =
87211582726SNicolas Bonnefon Persistent<Configuration>( "settings" );
87311582726SNicolas Bonnefon switch ( config->mainRegexpType() ) {
874bb02e0acSNicolas Bonnefon case FixedString:
8754fb0346eSAnton Filimonov pattern = QRegularExpression::escape(searchText);
876bb02e0acSNicolas Bonnefon break;
877bb02e0acSNicolas Bonnefon default:
8784fb0346eSAnton Filimonov pattern = searchText;
879bb02e0acSNicolas Bonnefon break;
880bb02e0acSNicolas Bonnefon }
881bb02e0acSNicolas Bonnefon
882bb02e0acSNicolas Bonnefon // Set the pattern case insensitive if needed
8834fb0346eSAnton Filimonov QRegularExpression::PatternOptions patternOptions =
8844fb0346eSAnton Filimonov QRegularExpression::UseUnicodePropertiesOption
8854fb0346eSAnton Filimonov | QRegularExpression::OptimizeOnFirstUsageOption;
8864fb0346eSAnton Filimonov
887bb02e0acSNicolas Bonnefon if ( ignoreCaseCheck->checkState() == Qt::Checked )
8884fb0346eSAnton Filimonov patternOptions |= QRegularExpression::CaseInsensitiveOption;
889bb02e0acSNicolas Bonnefon
890bb02e0acSNicolas Bonnefon // Constructs the regexp
8914fb0346eSAnton Filimonov QRegularExpression regexp( pattern, patternOptions );
892bb02e0acSNicolas Bonnefon
893bb02e0acSNicolas Bonnefon if ( regexp.isValid() ) {
894bb02e0acSNicolas Bonnefon // Activate the stop button
895bb02e0acSNicolas Bonnefon stopButton->setEnabled( true );
896bb02e0acSNicolas Bonnefon // Start a new asynchronous search
897bb02e0acSNicolas Bonnefon logFilteredData_->runSearch( regexp );
898bb02e0acSNicolas Bonnefon // Accept auto-refresh of the search
899bb02e0acSNicolas Bonnefon searchState_.startSearch();
900bb02e0acSNicolas Bonnefon }
901bb02e0acSNicolas Bonnefon else {
902bb02e0acSNicolas Bonnefon // The regexp is wrong
903bb02e0acSNicolas Bonnefon logFilteredData_->clearSearch();
904bb02e0acSNicolas Bonnefon filteredView->updateData();
905bb02e0acSNicolas Bonnefon searchState_.resetState();
906bb02e0acSNicolas Bonnefon
907bb02e0acSNicolas Bonnefon // Inform the user
9084fb0346eSAnton Filimonov QString errorMessage = tr("Error in expression");
9094fb0346eSAnton Filimonov const int offset = regexp.patternErrorOffset();
9104fb0346eSAnton Filimonov if (offset != -1) {
9114fb0346eSAnton Filimonov errorMessage += " at position ";
9124fb0346eSAnton Filimonov errorMessage += QString::number(offset);
9134fb0346eSAnton Filimonov }
9144fb0346eSAnton Filimonov errorMessage += ": ";
915bb02e0acSNicolas Bonnefon errorMessage += regexp.errorString();
916bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( errorPalette );
917bb02e0acSNicolas Bonnefon searchInfoLine->setText( errorMessage );
918bb02e0acSNicolas Bonnefon }
919bb02e0acSNicolas Bonnefon }
920bb02e0acSNicolas Bonnefon else {
921bb02e0acSNicolas Bonnefon searchState_.resetState();
922bb02e0acSNicolas Bonnefon printSearchInfoMessage();
923bb02e0acSNicolas Bonnefon }
924bb02e0acSNicolas Bonnefon }
925bb02e0acSNicolas Bonnefon
926bb02e0acSNicolas Bonnefon // Updates the content of the drop down list for the saved searches,
927bb02e0acSNicolas Bonnefon // called when the SavedSearch has been changed.
updateSearchCombo()928bb02e0acSNicolas Bonnefon void CrawlerWidget::updateSearchCombo()
929bb02e0acSNicolas Bonnefon {
930bb02e0acSNicolas Bonnefon const QString text = searchLineEdit->lineEdit()->text();
931bb02e0acSNicolas Bonnefon searchLineEdit->clear();
9321b5e406eSNicolas Bonnefon searchLineEdit->addItems( savedSearches_->recentSearches() );
933bb02e0acSNicolas Bonnefon // In case we had something that wasn't added to the list (blank...):
934bb02e0acSNicolas Bonnefon searchLineEdit->lineEdit()->setText( text );
935bb02e0acSNicolas Bonnefon }
936bb02e0acSNicolas Bonnefon
937bb02e0acSNicolas Bonnefon // Print the search info message.
printSearchInfoMessage(int nbMatches)938bb02e0acSNicolas Bonnefon void CrawlerWidget::printSearchInfoMessage( int nbMatches )
939bb02e0acSNicolas Bonnefon {
940bb02e0acSNicolas Bonnefon QString text;
941bb02e0acSNicolas Bonnefon
942bb02e0acSNicolas Bonnefon switch ( searchState_.getState() ) {
943bb02e0acSNicolas Bonnefon case SearchState::NoSearch:
944bb02e0acSNicolas Bonnefon // Blank text is fine
945bb02e0acSNicolas Bonnefon break;
946bb02e0acSNicolas Bonnefon case SearchState::Static:
947bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found.").arg( nbMatches )
948bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" );
949bb02e0acSNicolas Bonnefon break;
950bb02e0acSNicolas Bonnefon case SearchState::Autorefreshing:
951bb02e0acSNicolas Bonnefon text = tr("%1 match%2 found. Search is auto-refreshing...").arg( nbMatches )
952bb02e0acSNicolas Bonnefon .arg( nbMatches > 1 ? "es" : "" );
953bb02e0acSNicolas Bonnefon break;
954bb02e0acSNicolas Bonnefon case SearchState::FileTruncated:
95559d4e393SNicolas Bonnefon case SearchState::TruncatedAutorefreshing:
956bb02e0acSNicolas Bonnefon text = tr("File truncated on disk, previous search results are not valid anymore.");
957bb02e0acSNicolas Bonnefon break;
958bb02e0acSNicolas Bonnefon }
959bb02e0acSNicolas Bonnefon
960bb02e0acSNicolas Bonnefon searchInfoLine->setPalette( searchInfoLineDefaultPalette );
961bb02e0acSNicolas Bonnefon searchInfoLine->setText( text );
962bb02e0acSNicolas Bonnefon }
963bb02e0acSNicolas Bonnefon
96445ef183cSNicolas Bonnefon // Change the data status and, if needed, advise upstream.
changeDataStatus(DataStatus status)96545ef183cSNicolas Bonnefon void CrawlerWidget::changeDataStatus( DataStatus status )
96645ef183cSNicolas Bonnefon {
9677999f43eSNicolas Bonnefon if ( ( status != dataStatus_ )
9687999f43eSNicolas Bonnefon && (! ( dataStatus_ == DataStatus::NEW_FILTERED_DATA
9697999f43eSNicolas Bonnefon && status == DataStatus::NEW_DATA ) ) ) {
97045ef183cSNicolas Bonnefon dataStatus_ = status;
97145ef183cSNicolas Bonnefon emit dataStatusChanged( dataStatus_ );
97245ef183cSNicolas Bonnefon }
97345ef183cSNicolas Bonnefon }
97445ef183cSNicolas Bonnefon
9755fa25391SNicolas Bonnefon // Determine the right encoding and set the views.
updateEncoding()9765fa25391SNicolas Bonnefon void CrawlerWidget::updateEncoding()
9775fa25391SNicolas Bonnefon {
978209000a6SNicolas Bonnefon Encoding encoding = Encoding::ENCODING_MAX;
9795fa25391SNicolas Bonnefon
9805fa25391SNicolas Bonnefon switch ( encodingSetting_ ) {
981209000a6SNicolas Bonnefon case Encoding::ENCODING_AUTO:
9825fa25391SNicolas Bonnefon switch ( logData_->getDetectedEncoding() ) {
9835fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::ASCII7:
984209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_ISO_8859_1;
9855fa25391SNicolas Bonnefon encoding_text_ = tr( "US-ASCII" );
9865fa25391SNicolas Bonnefon break;
9875fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::ASCII8:
988209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_ISO_8859_1;
9895fa25391SNicolas Bonnefon encoding_text_ = tr( "ISO-8859-1" );
9905fa25391SNicolas Bonnefon break;
9915fa25391SNicolas Bonnefon case EncodingSpeculator::Encoding::UTF8:
992209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_UTF8;
9935fa25391SNicolas Bonnefon encoding_text_ = tr( "UTF-8" );
9945fa25391SNicolas Bonnefon break;
9950faa4758SNicolas Bonnefon case EncodingSpeculator::Encoding::UTF16LE:
996209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_UTF16LE;
9970faa4758SNicolas Bonnefon encoding_text_ = tr( "UTF-16LE" );
9980faa4758SNicolas Bonnefon break;
9990faa4758SNicolas Bonnefon case EncodingSpeculator::Encoding::UTF16BE:
1000209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_UTF16BE;
10010faa4758SNicolas Bonnefon encoding_text_ = tr( "UTF-16BE" );
10020faa4758SNicolas Bonnefon break;
10035fa25391SNicolas Bonnefon }
10045fa25391SNicolas Bonnefon break;
1005209000a6SNicolas Bonnefon case Encoding::ENCODING_UTF8:
1006209000a6SNicolas Bonnefon encoding = encodingSetting_;
10075fa25391SNicolas Bonnefon encoding_text_ = tr( "Displayed as UTF-8" );
10085fa25391SNicolas Bonnefon break;
1009209000a6SNicolas Bonnefon case Encoding::ENCODING_UTF16LE:
1010209000a6SNicolas Bonnefon encoding = encodingSetting_;
10114a4a124eSNicolas Bonnefon encoding_text_ = tr( "Displayed as UTF-16LE" );
10124a4a124eSNicolas Bonnefon break;
1013209000a6SNicolas Bonnefon case Encoding::ENCODING_UTF16BE:
1014209000a6SNicolas Bonnefon encoding = encodingSetting_;
10154a4a124eSNicolas Bonnefon encoding_text_ = tr( "Displayed as UTF-16BE" );
10164a4a124eSNicolas Bonnefon break;
1017209000a6SNicolas Bonnefon case Encoding::ENCODING_CP1251:
1018209000a6SNicolas Bonnefon encoding = encodingSetting_;
1019f25e35f2SNicolas Bonnefon encoding_text_ = tr( "Displayed as CP1251" );
1020f25e35f2SNicolas Bonnefon break;
1021209000a6SNicolas Bonnefon case Encoding::ENCODING_CP1252:
1022209000a6SNicolas Bonnefon encoding = encodingSetting_;
1023f25e35f2SNicolas Bonnefon encoding_text_ = tr( "Displayed as CP1252" );
1024f25e35f2SNicolas Bonnefon break;
1025*048334c9SSeerauber case Encoding::ENCODING_BIG5:
1026*048334c9SSeerauber encoding = encodingSetting_;
1027*048334c9SSeerauber encoding_text_ = tr( "Displayed as Big5" );
1028*048334c9SSeerauber break;
1029*048334c9SSeerauber case Encoding::ENCODING_GB18030:
1030*048334c9SSeerauber encoding = encodingSetting_;
1031*048334c9SSeerauber encoding_text_ = tr( "Displayed as GB18030/GB2312" );
1032*048334c9SSeerauber break;
1033*048334c9SSeerauber case Encoding::ENCODING_SHIFT_JIS:
1034*048334c9SSeerauber encoding = encodingSetting_;
1035*048334c9SSeerauber encoding_text_ = tr( "Displayed as Shift_JIS" );
1036*048334c9SSeerauber break;
1037*048334c9SSeerauber case Encoding::ENCODING_KOI8R:
1038*048334c9SSeerauber encoding = encodingSetting_;
1039*048334c9SSeerauber encoding_text_ = tr( "Displayed as KOI8-R" );
1040*048334c9SSeerauber break;
1041209000a6SNicolas Bonnefon case Encoding::ENCODING_ISO_8859_1:
10425fa25391SNicolas Bonnefon default:
1043209000a6SNicolas Bonnefon encoding = Encoding::ENCODING_ISO_8859_1;
10445fa25391SNicolas Bonnefon encoding_text_ = tr( "Displayed as ISO-8859-1" );
10455fa25391SNicolas Bonnefon break;
10465fa25391SNicolas Bonnefon }
10475fa25391SNicolas Bonnefon
10485fa25391SNicolas Bonnefon logData_->setDisplayEncoding( encoding );
10495fa25391SNicolas Bonnefon logMainView->forceRefresh();
10505fa25391SNicolas Bonnefon logFilteredData_->setDisplayEncoding( encoding );
10515fa25391SNicolas Bonnefon filteredView->forceRefresh();
10525fa25391SNicolas Bonnefon }
10535fa25391SNicolas Bonnefon
1054aa0a9454SNicolas Bonnefon // Change the respective size of the two views
changeTopViewSize(int32_t delta)1055aa0a9454SNicolas Bonnefon void CrawlerWidget::changeTopViewSize( int32_t delta )
1056aa0a9454SNicolas Bonnefon {
1057aa0a9454SNicolas Bonnefon int min, max;
1058aa0a9454SNicolas Bonnefon getRange( 1, &min, &max );
1059aa0a9454SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::changeTopViewSize " << sizes()[0] << " " << min << " " << max;
1060aa0a9454SNicolas Bonnefon moveSplitter( closestLegalPosition( sizes()[0] + ( delta * 10 ), 1 ), 1 );
1061aa0a9454SNicolas Bonnefon LOG(logDEBUG) << "CrawlerWidget::changeTopViewSize " << sizes()[0];
1062aa0a9454SNicolas Bonnefon }
1063aa0a9454SNicolas Bonnefon
1064bb02e0acSNicolas Bonnefon //
1065bb02e0acSNicolas Bonnefon // SearchState implementation
1066bb02e0acSNicolas Bonnefon //
resetState()1067bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::resetState()
1068bb02e0acSNicolas Bonnefon {
1069bb02e0acSNicolas Bonnefon state_ = NoSearch;
1070bb02e0acSNicolas Bonnefon }
1071bb02e0acSNicolas Bonnefon
setAutorefresh(bool refresh)1072bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::setAutorefresh( bool refresh )
1073bb02e0acSNicolas Bonnefon {
1074bb02e0acSNicolas Bonnefon autoRefreshRequested_ = refresh;
1075bb02e0acSNicolas Bonnefon
1076bb02e0acSNicolas Bonnefon if ( refresh ) {
1077bb02e0acSNicolas Bonnefon if ( state_ == Static )
1078bb02e0acSNicolas Bonnefon state_ = Autorefreshing;
107959d4e393SNicolas Bonnefon /*
108059d4e393SNicolas Bonnefon else if ( state_ == FileTruncated )
108159d4e393SNicolas Bonnefon state_ = TruncatedAutorefreshing;
108259d4e393SNicolas Bonnefon */
1083bb02e0acSNicolas Bonnefon }
1084bb02e0acSNicolas Bonnefon else {
1085bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing )
1086bb02e0acSNicolas Bonnefon state_ = Static;
108759d4e393SNicolas Bonnefon else if ( state_ == TruncatedAutorefreshing )
108859d4e393SNicolas Bonnefon state_ = FileTruncated;
1089bb02e0acSNicolas Bonnefon }
1090bb02e0acSNicolas Bonnefon }
1091bb02e0acSNicolas Bonnefon
truncateFile()1092bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::truncateFile()
1093bb02e0acSNicolas Bonnefon {
109459d4e393SNicolas Bonnefon if ( state_ == Autorefreshing || state_ == TruncatedAutorefreshing ) {
109559d4e393SNicolas Bonnefon state_ = TruncatedAutorefreshing;
109659d4e393SNicolas Bonnefon }
109759d4e393SNicolas Bonnefon else {
1098bb02e0acSNicolas Bonnefon state_ = FileTruncated;
1099bb02e0acSNicolas Bonnefon }
110059d4e393SNicolas Bonnefon }
1101bb02e0acSNicolas Bonnefon
changeExpression()1102bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::changeExpression()
1103bb02e0acSNicolas Bonnefon {
1104bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing )
1105bb02e0acSNicolas Bonnefon state_ = Static;
1106bb02e0acSNicolas Bonnefon }
1107bb02e0acSNicolas Bonnefon
stopSearch()1108bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::stopSearch()
1109bb02e0acSNicolas Bonnefon {
1110bb02e0acSNicolas Bonnefon if ( state_ == Autorefreshing )
1111bb02e0acSNicolas Bonnefon state_ = Static;
1112bb02e0acSNicolas Bonnefon }
1113bb02e0acSNicolas Bonnefon
startSearch()1114bb02e0acSNicolas Bonnefon void CrawlerWidget::SearchState::startSearch()
1115bb02e0acSNicolas Bonnefon {
1116bb02e0acSNicolas Bonnefon if ( autoRefreshRequested_ )
1117bb02e0acSNicolas Bonnefon state_ = Autorefreshing;
1118bb02e0acSNicolas Bonnefon else
1119bb02e0acSNicolas Bonnefon state_ = Static;
1120bb02e0acSNicolas Bonnefon }
1121a44d09bcSNicolas Bonnefon
1122a44d09bcSNicolas Bonnefon /*
1123a44d09bcSNicolas Bonnefon * CrawlerWidgetContext
1124a44d09bcSNicolas Bonnefon */
CrawlerWidgetContext(const char * string)1125a44d09bcSNicolas Bonnefon CrawlerWidgetContext::CrawlerWidgetContext( const char* string )
1126a44d09bcSNicolas Bonnefon {
11274fb0346eSAnton Filimonov QRegularExpression regex( "S(\\d+):(\\d+)" );
11284fb0346eSAnton Filimonov QRegularExpressionMatch match = regex.match( string );
11294fb0346eSAnton Filimonov if ( match.hasMatch() ) {
11304fb0346eSAnton Filimonov sizes_ = { match.captured(1).toInt(), match.captured(2).toInt() };
1131a44d09bcSNicolas Bonnefon LOG(logDEBUG) << "sizes_: " << sizes_[0] << " " << sizes_[1];
1132a44d09bcSNicolas Bonnefon }
1133f688be2eSNicolas Bonnefon else {
1134f688be2eSNicolas Bonnefon LOG(logWARNING) << "Unrecognised view size: " << string;
1135a44d09bcSNicolas Bonnefon
1136a44d09bcSNicolas Bonnefon // Default values;
1137a44d09bcSNicolas Bonnefon sizes_ = { 100, 400 };
1138a44d09bcSNicolas Bonnefon }
1139f688be2eSNicolas Bonnefon
11404fb0346eSAnton Filimonov QRegularExpression case_refresh_regex( "IC(\\d+):AR(\\d+)" );
11414fb0346eSAnton Filimonov match = case_refresh_regex.match( string );
11424fb0346eSAnton Filimonov if ( match.hasMatch() ) {
11434fb0346eSAnton Filimonov ignore_case_ = ( match.captured(1).toInt() == 1 );
11444fb0346eSAnton Filimonov auto_refresh_ = ( match.captured(2).toInt() == 1 );
1145f688be2eSNicolas Bonnefon
1146f688be2eSNicolas Bonnefon LOG(logDEBUG) << "ignore_case_: " << ignore_case_ << " auto_refresh_: "
1147f688be2eSNicolas Bonnefon << auto_refresh_;
1148f688be2eSNicolas Bonnefon }
1149f688be2eSNicolas Bonnefon else {
1150f688be2eSNicolas Bonnefon LOG(logWARNING) << "Unrecognised case/refresh: " << string;
1151f688be2eSNicolas Bonnefon ignore_case_ = false;
1152f688be2eSNicolas Bonnefon auto_refresh_ = false;
1153f688be2eSNicolas Bonnefon }
1154af94bdd6SNicolas Bonnefon
1155af94bdd6SNicolas Bonnefon QRegularExpression follow_regex( "FF(\\d+)" );
1156af94bdd6SNicolas Bonnefon match = follow_regex.match( string );
1157af94bdd6SNicolas Bonnefon if ( match.hasMatch() ) {
1158af94bdd6SNicolas Bonnefon follow_file_ = ( match.captured(1).toInt() == 1 );
1159af94bdd6SNicolas Bonnefon
1160af94bdd6SNicolas Bonnefon LOG(logDEBUG) << "follow_file_: " << follow_file_;
1161af94bdd6SNicolas Bonnefon }
1162af94bdd6SNicolas Bonnefon else {
1163af94bdd6SNicolas Bonnefon LOG(logWARNING) << "Unrecognised follow: " << string;
1164af94bdd6SNicolas Bonnefon follow_file_ = false;
1165af94bdd6SNicolas Bonnefon }
1166a44d09bcSNicolas Bonnefon }
1167a44d09bcSNicolas Bonnefon
toString() const1168a44d09bcSNicolas Bonnefon std::string CrawlerWidgetContext::toString() const
1169a44d09bcSNicolas Bonnefon {
1170a44d09bcSNicolas Bonnefon char string[160];
1171a44d09bcSNicolas Bonnefon
1172af94bdd6SNicolas Bonnefon snprintf( string, sizeof string, "S%d:%d:IC%d:AR%d:FF%d",
1173f688be2eSNicolas Bonnefon sizes_[0], sizes_[1],
1174af94bdd6SNicolas Bonnefon ignore_case_, auto_refresh_, follow_file_ );
1175a44d09bcSNicolas Bonnefon
1176f688be2eSNicolas Bonnefon return { string };
1177a44d09bcSNicolas Bonnefon }
1178