Skip to content

Commit

Permalink
Persist the "follow" mode across sessions.
Browse files Browse the repository at this point in the history
Fixes #183
  • Loading branch information
nickbnf committed Feb 14, 2018
1 parent 7db18f1 commit af94bdd
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/crawlerwidget.cpp
Expand Up @@ -56,10 +56,12 @@ class CrawlerWidgetContext : public ViewContextInterface {
// Construct from the value passsed
CrawlerWidgetContext( QList<int> sizes,
bool ignore_case,
bool auto_refresh )
bool auto_refresh,
bool follow_file )
: sizes_( sizes ),
ignore_case_( ignore_case ),
auto_refresh_( auto_refresh ) {}
auto_refresh_( auto_refresh ),
follow_file_( follow_file ) {}

// Implementation of the ViewContextInterface function
std::string toString() const;
Expand All @@ -69,12 +71,14 @@ class CrawlerWidgetContext : public ViewContextInterface {

bool ignoreCase() const { return ignore_case_; }
bool autoRefresh() const { return auto_refresh_; }
bool followFile() const { return follow_file_; }

private:
QList<int> sizes_;

bool ignore_case_;
bool auto_refresh_;
bool follow_file_;
};

// Constructor only does trivial construction. The real work is done once
Expand Down Expand Up @@ -250,6 +254,8 @@ void CrawlerWidget::doSetViewContext(
searchRefreshCheck->setCheckState( auto_refresh_check_state );
// Manually call the handler as it is not called when changing the state programmatically
searchRefreshChangedHandler( auto_refresh_check_state );

emit followSet( context.followFile() );
}

std::shared_ptr<const ViewContextInterface>
Expand All @@ -258,7 +264,8 @@ CrawlerWidget::doGetViewContext() const
auto context = std::make_shared<const CrawlerWidgetContext>(
sizes(),
( ignoreCaseCheck->checkState() == Qt::Checked ),
( searchRefreshCheck->checkState() == Qt::Checked ) );
( searchRefreshCheck->checkState() == Qt::Checked ),
logMainView->isFollowEnabled() );

return static_cast<std::shared_ptr<const ViewContextInterface>>( context );
}
Expand Down Expand Up @@ -1125,15 +1132,27 @@ CrawlerWidgetContext::CrawlerWidgetContext( const char* string )
ignore_case_ = false;
auto_refresh_ = false;
}

QRegularExpression follow_regex( "FF(\\d+)" );
match = follow_regex.match( string );
if ( match.hasMatch() ) {
follow_file_ = ( match.captured(1).toInt() == 1 );

LOG(logDEBUG) << "follow_file_: " << follow_file_;
}
else {
LOG(logWARNING) << "Unrecognised follow: " << string;
follow_file_ = false;
}
}

std::string CrawlerWidgetContext::toString() const
{
char string[160];

snprintf( string, sizeof string, "S%d:%d:IC%d:AR%d",
snprintf( string, sizeof string, "S%d:%d:IC%d:AR%d:FF%d",
sizes_[0], sizes_[1],
ignore_case_, auto_refresh_ );
ignore_case_, auto_refresh_, follow_file_ );

return { string };
}

0 comments on commit af94bdd

Please sign in to comment.