Skip to content

Commit

Permalink
Auto-save - Fix double negations and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zonkmachine committed Feb 13, 2017
1 parent f244d9a commit 901fea5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions include/SetupDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ private slots:
QString m_backgroundArtwork;

bool m_smoothScroll;
bool m_disableAutoSave;
bool m_disableRunningAutoSave;
bool m_enableAutoSave;
bool m_enableRunningAutoSave;
int m_saveInterval;
QSlider * m_saveIntervalSlider;
QLabel * m_saveIntervalLbl;
Expand Down
2 changes: 1 addition & 1 deletion src/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ int main( int argc, char * * argv )
bool recoveryFilePresent = QFileInfo( recoveryFile ).exists() &&
QFileInfo( recoveryFile ).isFile();
bool autoSaveEnabled =
!ConfigManager::inst()->value( "ui", "disableautosave" ).toInt();
ConfigManager::inst()->value( "ui", "enableautosave" ).toInt();
if( recoveryFilePresent )
{
QMessageBox mb;
Expand Down
15 changes: 8 additions & 7 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ MainWindow::MainWindow() :

m_updateTimer.start( 1000 / 20, this ); // 20 fps

if( !ConfigManager::inst()->value( "ui", "disableautosave" ).toInt() )
if( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt() )
{
// connect auto save
connect(&m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
Expand Down Expand Up @@ -1373,7 +1373,7 @@ void MainWindow::closeEvent( QCloseEvent * _ce )
if( mayChangeProject(true) )
{
// delete recovery file
if( !ConfigManager::inst()->value( "ui", "disableautosave" ).toInt()
if( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt()
&& getSession() != Limited )
{
sessionCleanup();
Expand Down Expand Up @@ -1529,10 +1529,11 @@ void MainWindow::browseHelp()

void MainWindow::autoSave()
{
if( ( !ConfigManager::inst()->value( "ui", "disablerunningautosave" ).toInt() ||
! Engine::getSong()->isPlaying() ) &&
!( Engine::getSong()->isExporting() ||
QApplication::mouseButtons() ) )
if( !Engine::getSong()->isExporting() &&
!QApplication::mouseButtons() &&
( ConfigManager::inst()->value( "ui",
"enablerunningautosave" ).toInt() ||
! Engine::getSong()->isPlaying() ) )
{
Engine::getSong()->saveProjectFile(ConfigManager::inst()->recoveryFile());
autoSaveTimerReset(); // Reset timer
Expand All @@ -1552,7 +1553,7 @@ void MainWindow::autoSave()
// from the timer where we need to do extra tests.
void MainWindow::runAutoSave()
{
if( !ConfigManager::inst()->value( "ui", "disableautosave" ).toInt() &&
if( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt() &&
getSession() != Limited )
{
autoSave();
Expand Down
30 changes: 14 additions & 16 deletions src/gui/SetupDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "Engine.h"
#include "debug.h"
#include "ToolTip.h"

#include "LcdSpinBox.h"
#include "FileDialog.h"

Expand Down Expand Up @@ -124,8 +123,8 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) :
#endif
m_backgroundArtwork( QDir::toNativeSeparators( ConfigManager::inst()->backgroundArtwork() ) ),
m_smoothScroll( ConfigManager::inst()->value( "ui", "smoothscroll" ).toInt() ),
m_disableAutoSave( !ConfigManager::inst()->value( "ui", "disableautosave" ).toInt() ),
m_disableRunningAutoSave( !ConfigManager::inst()->value( "ui", "disablerunningautosave" ).toInt() ),
m_enableAutoSave( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt() ),
m_enableRunningAutoSave( ConfigManager::inst()->value( "ui", "enablerunningautosave" ).toInt() ),
m_saveInterval( ConfigManager::inst()->value( "ui", "saveinterval" ).toInt() < 1 ?
MainWindow::DEFAULT_SAVE_INTERVAL_MINUTES :
ConfigManager::inst()->value( "ui", "saveinterval" ).toInt() ),
Expand Down Expand Up @@ -666,14 +665,14 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) :
m_autoSave = new LedCheckBox(
tr( "Enable auto-save" ), auto_save_tw );
m_autoSave->move( 10, 70 );
m_autoSave->setChecked( m_disableAutoSave );
m_autoSave->setChecked( m_enableAutoSave );
connect( m_autoSave, SIGNAL( toggled( bool ) ),
this, SLOT( toggleAutoSave( bool ) ) );

m_runningAutoSave = new LedCheckBox(
tr( "Allow auto-save while playing" ), auto_save_tw );
m_runningAutoSave->move( 20, 90 );
m_runningAutoSave->setChecked( m_disableRunningAutoSave );
m_runningAutoSave->setChecked( m_enableRunningAutoSave );
connect( m_runningAutoSave, SIGNAL( toggled( bool ) ),
this, SLOT( toggleRunningAutoSave( bool ) ) );

Expand All @@ -690,8 +689,8 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) :
connect( saveIntervalBtn, SIGNAL( clicked() ), this,
SLOT( displaySaveIntervalHelp() ) );

m_saveIntervalSlider->setEnabled( m_disableAutoSave );
m_runningAutoSave->setVisible( m_disableAutoSave );
m_saveIntervalSlider->setEnabled( m_enableAutoSave );
m_runningAutoSave->setVisible( m_enableAutoSave );


perf_layout->addWidget( auto_save_tw );
Expand Down Expand Up @@ -1027,12 +1026,12 @@ void SetupDialog::accept()
QString::number( m_hqAudioDev ) );
ConfigManager::inst()->setValue( "ui", "smoothscroll",
QString::number( m_smoothScroll ) );
ConfigManager::inst()->setValue( "ui", "disableautosave",
QString::number( !m_disableAutoSave ) );
ConfigManager::inst()->setValue( "ui", "enableautosave",
QString::number( m_enableAutoSave ) );
ConfigManager::inst()->setValue( "ui", "saveinterval",
QString::number( m_saveInterval ) );
ConfigManager::inst()->setValue( "ui", "disablerunningautosave",
QString::number( !m_disableRunningAutoSave ) );
ConfigManager::inst()->setValue( "ui", "enablerunningautosave",
QString::number( m_enableRunningAutoSave ) );
ConfigManager::inst()->setValue( "ui", "oneinstrumenttrackwindow",
QString::number( m_oneInstrumentTrackWindow ) );
ConfigManager::inst()->setValue( "ui", "compacttrackbuttons",
Expand Down Expand Up @@ -1215,7 +1214,7 @@ void SetupDialog::toggleSmoothScroll( bool _enabled )

void SetupDialog::toggleAutoSave( bool _enabled )
{
m_disableAutoSave = _enabled;
m_enableAutoSave = _enabled;
m_saveIntervalSlider->setEnabled( _enabled );
m_runningAutoSave->setVisible( _enabled );
setAutoSaveInterval( m_saveIntervalSlider->value() );
Expand All @@ -1226,13 +1225,12 @@ void SetupDialog::toggleAutoSave( bool _enabled )

void SetupDialog::toggleRunningAutoSave( bool _enabled )
{
m_disableRunningAutoSave = _enabled;
m_enableRunningAutoSave = _enabled;
}





void SetupDialog::toggleCompactTrackButtons( bool _enabled )
{
m_compactTrackButtons = _enabled;
Expand Down Expand Up @@ -1512,7 +1510,7 @@ void SetupDialog::setAutoSaveInterval( int value )
m_saveIntervalSlider->setValue( m_saveInterval );
QString minutes = m_saveInterval > 1 ? tr( "minutes" ) : tr( "minute" );
minutes = QString( "%1 %2" ).arg( QString::number( m_saveInterval ), minutes );
minutes = m_disableAutoSave ? minutes : tr( "Disabled" );
minutes = m_enableAutoSave ? minutes : tr( "Disabled" );
m_saveIntervalLbl->setText( tr( "Auto-save interval: %1" ).arg( minutes ) );
}

Expand All @@ -1534,7 +1532,7 @@ void SetupDialog::displaySaveIntervalHelp()
QWhatsThis::showText( QCursor::pos(),
tr( "Set the time between automatic backup to %1.\n"
"Remember to also save your project manually. "
"You can also choose to disable saving while playing, "
"You can choose to disable saving while playing, "
"something some older systems find difficult." ).arg(
ConfigManager::inst()->recoveryFile() ) );
}
Expand Down

0 comments on commit 901fea5

Please sign in to comment.