Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/crawlerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ void CrawlerWidget::startNewSearch()
{
// Record the search line in the recent list
// (reload the list first in case another glogg changed it)
GetPersistentInfo().retrieve( "savedSearches" );
GetPersistentInfo().retrieve( *savedSearches_ );
savedSearches_->addRecent( searchLineEdit->currentText() );
GetPersistentInfo().save( "savedSearches" );
GetPersistentInfo().save( *savedSearches_ );

// Update the SearchLine (history)
updateSearchCombo();
Expand Down
28 changes: 16 additions & 12 deletions src/filtersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "log.h"

#include <utility>

#include "configuration.h"
#include "persistentinfo.h"
#include "filterset.h"
Expand All @@ -38,8 +40,9 @@ FiltersDialog::FiltersDialog( QWidget* parent ) : QDialog( parent )

// Reload the filter list from disk (in case it has been changed
// by another glogg instance) and copy it to here.
GetPersistentInfo().retrieve( "filterSet" );
filterSet = PersistentCopy<FilterSet>( "filterSet" );
auto persistentFilterSet = Persistent<FilterSet>( "filterSet" );
GetPersistentInfo().retrieve( *persistentFilterSet );
filterSet = *persistentFilterSet;

populateColors();
populateFilterList();
Expand Down Expand Up @@ -69,7 +72,7 @@ FiltersDialog::FiltersDialog( QWidget* parent ) : QDialog( parent )
connect( backColorBox, SIGNAL( activated( int ) ),
this, SLOT( updateFilterProperties() ) );

if ( !filterSet->filterList.empty() ) {
if ( !filterSet.filterList.empty() ) {
filterListWidget->setCurrentItem( filterListWidget->item( 0 ) );
}
}
Expand All @@ -84,7 +87,7 @@ void FiltersDialog::on_addFilterButton_clicked()

Filter newFilter = Filter( DEFAULT_PATTERN, DEFAULT_IGNORE_CASE,
DEFAULT_FORE_COLOUR, DEFAULT_BACK_COLOUR );
filterSet->filterList << newFilter;
filterSet.filterList << newFilter;

// Add and select the newly created filter
filterListWidget->addItem( DEFAULT_PATTERN );
Expand All @@ -97,7 +100,7 @@ void FiltersDialog::on_removeFilterButton_clicked()
LOG(logDEBUG) << "on_removeFilterButton_clicked() index " << index;

if ( index >= 0 ) {
filterSet->filterList.removeAt( index );
filterSet.filterList.removeAt( index );
filterListWidget->setCurrentRow( -1 );
delete filterListWidget->takeItem( index );

Expand All @@ -112,7 +115,7 @@ void FiltersDialog::on_upFilterButton_clicked()
LOG(logDEBUG) << "on_upFilterButton_clicked() index " << index;

if ( index > 0 ) {
filterSet->filterList.move( index, index - 1 );
filterSet.filterList.move( index, index - 1 );

QListWidgetItem* item = filterListWidget->takeItem( index );
filterListWidget->insertItem( index - 1, item );
Expand All @@ -126,7 +129,7 @@ void FiltersDialog::on_downFilterButton_clicked()
LOG(logDEBUG) << "on_downFilterButton_clicked() index " << index;

if ( ( index >= 0 ) && ( index < ( filterListWidget->count() - 1 ) ) ) {
filterSet->filterList.move( index, index + 1 );
filterSet.filterList.move( index, index + 1 );

QListWidgetItem* item = filterListWidget->takeItem( index );
filterListWidget->insertItem( index + 1, item );
Expand All @@ -142,8 +145,9 @@ void FiltersDialog::on_buttonBox_clicked( QAbstractButton* button )
if ( ( role == QDialogButtonBox::AcceptRole )
|| ( role == QDialogButtonBox::ApplyRole ) ) {
// Copy the filter set and persist it to disk
*( Persistent<FilterSet>( "filterSet" ) ) = *filterSet;
GetPersistentInfo().save( "filterSet" );
auto persistentFilterSet = Persistent<FilterSet>( "filterSet" );
*persistentFilterSet = std::move( filterSet );
GetPersistentInfo().save( *persistentFilterSet );
emit optionsChanged();
}

Expand All @@ -164,7 +168,7 @@ void FiltersDialog::updatePropertyFields()
LOG(logDEBUG) << "updatePropertyFields(), row = " << selectedRow_;

if ( selectedRow_ >= 0 ) {
const Filter& currentFilter = filterSet->filterList.at( selectedRow_ );
const Filter& currentFilter = filterSet.filterList.at( selectedRow_ );

patternEdit->setText( currentFilter.pattern() );
patternEdit->setEnabled( true );
Expand Down Expand Up @@ -206,7 +210,7 @@ void FiltersDialog::updateFilterProperties()

// If a row is selected
if ( selectedRow_ >= 0 ) {
Filter& currentFilter = filterSet->filterList[selectedRow_];
Filter& currentFilter = filterSet.filterList[selectedRow_];

// Update the internal data
currentFilter.setPattern( patternEdit->text() );
Expand Down Expand Up @@ -292,7 +296,7 @@ void FiltersDialog::populateColors()
void FiltersDialog::populateFilterList()
{
filterListWidget->clear();
foreach ( Filter filter, filterSet->filterList ) {
foreach ( Filter filter, filterSet.filterList ) {
QListWidgetItem* new_item = new QListWidgetItem( filter.pattern() );
// new_item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
new_item->setForeground( QBrush( QColor( filter.foreColorName() ) ) );
Expand Down
2 changes: 1 addition & 1 deletion src/filtersdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FiltersDialog : public QDialog, public Ui::FiltersDialog
private:
// Temporary filterset modified by the dialog
// it is copied from the one in Config()
std::shared_ptr<FilterSet> filterSet;
FilterSet filterSet;

// Index of the row currently selected or -1 if none.
int selectedRow_;
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ int main(int argc, char *argv[])
app.setAttribute( Qt::AA_DontShowIconsInMenus );

// FIXME: should be replaced by a two staged init of MainWindow
GetPersistentInfo().retrieve( QString( "settings" ) );
std::shared_ptr<Configuration> config =
Persistent<Configuration>( "settings" );
GetPersistentInfo().retrieve( *config );

std::unique_ptr<Session> session( new Session() );
MainWindow mw( std::move( session ), externalCommunicator );
Expand All @@ -258,8 +260,6 @@ int main(int argc, char *argv[])
mw.reloadGeometry();

// Load the existing session if needed
std::shared_ptr<Configuration> config =
Persistent<Configuration>( "settings" );
if ( load_session || ( filenames.empty() && !new_session && config->loadLastSession() ) )
mw.reloadSession();

Expand Down
6 changes: 3 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,9 @@ bool MainWindow::loadFile( const QString& fileName )

// Update the recent files list
// (reload the list first in case another glogg changed it)
GetPersistentInfo().retrieve( "recentFiles" );
GetPersistentInfo().retrieve( *recentFiles_ );
recentFiles_->addRecent( fileName );
GetPersistentInfo().save( "recentFiles" );
GetPersistentInfo().save( *recentFiles_ );
updateRecentFileActions();
}
catch ( FileUnreadableErr ) {
Expand Down Expand Up @@ -997,7 +997,7 @@ void MainWindow::readSettings()
*/

// History of recent files
GetPersistentInfo().retrieve( QString( "recentFiles" ) );
GetPersistentInfo().retrieve( *recentFiles_ );
updateRecentFileActions();

// GetPersistentInfo().retrieve( QString( "settings" ) );
Expand Down
28 changes: 22 additions & 6 deletions src/persistentinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ void PersistentInfo::save( const QString& name )
{
assert( initialised_ );

if ( objectList_.contains( name ) )
objectList_.value( name )->saveToStorage( *settings_ );
auto object = objectList_.value( name );
if ( object )
save( *object );
else
LOG(logERROR) << "Unregistered persistable " << name.toStdString();
}

void PersistentInfo::save( const Persistable& persistable )
{
assert( initialised_ );

persistable.saveToStorage( *settings_ );

// Sync to ensure it is propagated to other processes
settings_->sync();
Expand All @@ -99,13 +107,21 @@ void PersistentInfo::retrieve( const QString& name )
{
assert( initialised_ );

auto object = objectList_.value( name );
if ( object )
retrieve( *object );
else
LOG(logERROR) << "Unregistered persistable " << name.toStdString();
}

void PersistentInfo::retrieve( Persistable& persistable )
{
assert( initialised_ );

// Sync to ensure it has been propagated from other processes
settings_->sync();

if ( objectList_.contains( name ) )
objectList_.value( name )->retrieveFromStorage( *settings_ );
else
LOG(logERROR) << "Unregistered persistable " << name.toStdString();
persistable.retrieveFromStorage( *settings_ );
}

// Friend function to construct/get the singleton
Expand Down
10 changes: 2 additions & 8 deletions src/persistentinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ class PersistentInfo {
std::shared_ptr<Persistable> getPersistable( const QString& name );
// Save a persistable to its permanent storage
void save( const QString& name );
void save( const Persistable& persistable );
// Retrieve a persistable from permanent storage
void retrieve( const QString& name );
void retrieve( Persistable& persistable );

private:
// Can't be constructed or copied (singleton)
Expand Down Expand Up @@ -75,12 +77,4 @@ std::shared_ptr<T> Persistent( const char* name )
GetPersistentInfo().getPersistable( QString( name ) );
return std::dynamic_pointer_cast<T>(p);
}

template<typename T>
std::shared_ptr<T> PersistentCopy( const char* name )
{
std::shared_ptr<Persistable> p =
GetPersistentInfo().getPersistable( QString( name ) );
return std::make_shared<T>( *( std::dynamic_pointer_cast<T>(p) ) );
}
#endif
8 changes: 4 additions & 4 deletions src/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

Session::Session()
{
GetPersistentInfo().retrieve( QString( "savedSearches" ) );

// Get the global search history (it remains the property
// of the Persistent)
savedSearches_ = Persistent<SavedSearches>( "savedSearches" );

GetPersistentInfo().retrieve( *savedSearches_ );

quickFindPattern_ = std::make_shared<QuickFindPattern>();
}

Expand Down Expand Up @@ -109,16 +109,16 @@ void Session::save( std::vector<
Persistent<SessionInfo>( "session" );
session->setOpenFiles( session_files );
session->setGeometry( geometry );
GetPersistentInfo().save( QString( "session" ) );
GetPersistentInfo().save( *session );
}

std::vector<std::pair<std::string, ViewInterface*>> Session::restore(
std::function<ViewInterface*()> view_factory,
int *current_file_index )
{
GetPersistentInfo().retrieve( QString( "session" ) );
std::shared_ptr<SessionInfo> session =
Persistent<SessionInfo>( "session" );
GetPersistentInfo().retrieve( *session );

std::vector<SessionInfo::OpenFile> session_files = session->openFiles();
LOG(logDEBUG) << "Session returned " << session_files.size();
Expand Down
6 changes: 3 additions & 3 deletions src/versionchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ void VersionChecker::startCheck()
{
LOG(logDEBUG) << "VersionChecker::startCheck()";

GetPersistentInfo().retrieve( "versionChecker" );

auto config = Persistent<VersionCheckerConfig>( "versionChecker" );

GetPersistentInfo().retrieve( *config );

if ( config->versionCheckingEnabled() )
{
// Check the deadline has been reached
Expand Down Expand Up @@ -130,7 +130,7 @@ void VersionChecker::downloadFinished( QNetworkReply* reply )

config->setNextDeadline( std::time( nullptr ) + CHECK_INTERVAL_S );

GetPersistentInfo().save( "versionChecker" );
GetPersistentInfo().save( *config );
}

namespace {
Expand Down