Auto save timer setting

This commit is contained in:
Oskar Wallgren
2016-01-23 06:11:49 +01:00
parent adb25eccad
commit cfb2c7201f
5 changed files with 141 additions and 22 deletions

View File

@@ -30,6 +30,7 @@
#include <QtCore/QList>
#include <QMainWindow>
#include "ConfigManager.h"
#include "SubWindow.h"
class QAction;
@@ -81,11 +82,31 @@ public:
///
bool mayChangeProject(bool stopPlayback);
void autoSaveTimerStart()
// Auto save timer intervals. The slider in SetupDialog.cpp wants
// minutes and the rest milliseconds.
static const int DEFAULT_SAVE_INTERVAL_MINUTES = 2;
static const int DEFAULT_AUTO_SAVE_INTERVAL = DEFAULT_SAVE_INTERVAL_MINUTES * 60 * 1000;
static const int m_autoSaveShortTime = 10 * 1000; // 10s short loop
void autoSaveTimerReset( int msec = ConfigManager::inst()->
value( "ui", "saveinterval" ).toInt()
* 60 * 1000 )
{
m_autoSaveTimer.start( 1000 * 60 ); // 1 minute
if( msec < m_autoSaveShortTime ) // No 'saveinterval' in .lmmsrc.xml
{
msec = DEFAULT_AUTO_SAVE_INTERVAL;
}
m_autoSaveTimer.start( msec );
}
int getAutoSaveTimerInterval()
{
return m_autoSaveTimer.interval();
}
void runAutoSave();
enum SessionState
{
Normal,
@@ -155,7 +176,6 @@ public slots:
void redo();
void autoSave();
void runAutoSave();
protected:
virtual void closeEvent( QCloseEvent * _ce );
@@ -204,6 +224,7 @@ private:
QBasicTimer m_updateTimer;
QTimer m_autoSaveTimer;
int m_autoSaveInterval;
friend class GuiApplication;

View File

@@ -44,7 +44,6 @@ class QSlider;
class TabBar;
class SetupDialog : public QDialog
{
Q_OBJECT
@@ -84,6 +83,11 @@ private slots:
void setDefaultSoundfont( const QString & _sf );
void setBackgroundArtwork( const QString & _ba );
// performance settings widget
void setAutoSaveInterval( int time );
void resetAutoSaveInterval();
void displaySaveIntervalHelp();
// audio settings widget
void audioInterfaceChanged( const QString & _driver );
void displayAudioHelp();
@@ -175,6 +179,10 @@ private:
bool m_smoothScroll;
bool m_enableAutoSave;
int m_saveInterval;
QSlider * m_saveIntervalSlider;
QLabel * m_saveIntervalLbl;
bool m_oneInstrumentTrackWindow;
bool m_compactTrackButtons;
bool m_syncVSTPlugins;

View File

@@ -799,8 +799,8 @@ int main( int argc, char * * argv )
if( autoSaveEnabled &&
gui->mainWindow()->getSession() != MainWindow::SessionState::Limited )
{
gui->mainWindow()->runAutoSave();
gui->mainWindow()->autoSaveTimerStart();
gui->mainWindow()->autoSaveTimerReset();
gui->mainWindow()->autoSave();
}
}

View File

@@ -203,10 +203,16 @@ MainWindow::MainWindow() :
{
// connect auto save
connect(&m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
m_autoSaveInterval = ConfigManager::inst()->value(
"ui", "saveinterval" ).toInt() < 1 ?
DEFAULT_AUTO_SAVE_INTERVAL :
ConfigManager::inst()->value(
"ui", "saveinterval" ).toInt();
// The auto save function mustn't run until there is a project
// to save or it will run over recover.mmp if you hesitate at the
// recover messagebox for a minute. It is now started in main.
// See autoSaveTimerStart() in MainWindow.h
// See autoSaveTimerReset() in MainWindow.h
}
connect( Engine::getSong(), SIGNAL( playbackStateChanged() ),
@@ -1507,14 +1513,19 @@ void MainWindow::browseHelp()
void MainWindow::autoSave()
{
if( !( Engine::getSong()->isPlaying() ||
Engine::getSong()->isExporting() ) )
Engine::getSong()->isExporting() ||
QApplication::mouseButtons() ) )
{
Engine::getSong()->saveProjectFile(ConfigManager::inst()->recoveryFile());
autoSaveTimerReset(); // Reset timer
}
else
{
// try again in 10 seconds
QTimer::singleShot( 10*1000, this, SLOT( autoSave() ) );
if( getAutoSaveTimerInterval() != m_autoSaveShortTime )
{
autoSaveTimerReset( m_autoSaveShortTime );
}
}
}
@@ -1527,5 +1538,6 @@ void MainWindow::runAutoSave()
getSession() != Limited )
{
autoSave();
autoSaveTimerReset(); // Reset timer
}
}

View File

@@ -38,6 +38,7 @@
#include "TabWidget.h"
#include "gui_templates.h"
#include "Mixer.h"
#include "MainWindow.h"
#include "ProjectJournal.h"
#include "ConfigManager.h"
#include "embed.h"
@@ -121,7 +122,10 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) :
#endif
m_backgroundArtwork( QDir::toNativeSeparators( ConfigManager::inst()->backgroundArtwork() ) ),
m_smoothScroll( ConfigManager::inst()->value( "ui", "smoothscroll" ).toInt() ),
m_enableAutoSave( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt() ),
m_enableAutoSave( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt() ),
m_saveInterval( ConfigManager::inst()->value( "ui", "saveinterval" ).toInt() < 1 ?
MainWindow::DEFAULT_SAVE_INTERVAL_MINUTES :
ConfigManager::inst()->value( "ui", "saveinterval" ).toInt() ),
m_oneInstrumentTrackWindow( ConfigManager::inst()->value( "ui",
"oneinstrumenttrackwindow" ).toInt() ),
m_compactTrackButtons( ConfigManager::inst()->value( "ui",
@@ -654,16 +658,61 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) :
QWidget * performance = new QWidget( ws );
performance->setFixedSize( 360, 240 );
performance->setFixedSize( 360, 200 );
QVBoxLayout * perf_layout = new QVBoxLayout( performance );
perf_layout->setSpacing( 0 );
perf_layout->setMargin( 0 );
labelWidget( performance, tr( "Performance settings" ) );
TabWidget * auto_save_tw = new TabWidget(
tr( "Auto save" ).toUpper(), performance );
auto_save_tw->setFixedHeight( 100 );
m_saveIntervalSlider = new QSlider( Qt::Horizontal, auto_save_tw );
m_saveIntervalSlider->setRange( 1, 20 );
m_saveIntervalSlider->setTickPosition( QSlider::TicksBelow );
m_saveIntervalSlider->setPageStep( 1 );
m_saveIntervalSlider->setTickInterval( 1 );
m_saveIntervalSlider->setGeometry( 10, 16, 340, 18 );
m_saveIntervalSlider->setValue( m_saveInterval );
connect( m_saveIntervalSlider, SIGNAL( valueChanged( int ) ), this,
SLOT( setAutoSaveInterval( int ) ) );
m_saveIntervalLbl = new QLabel( auto_save_tw );
m_saveIntervalLbl->setGeometry( 10, 40, 200, 24 );
setAutoSaveInterval( m_saveIntervalSlider->value() );
LedCheckBox * autoSave = new LedCheckBox(
tr( "Enable auto save feature" ), auto_save_tw );
autoSave->move( 10, 70 );
autoSave->setChecked( m_enableAutoSave );
connect( autoSave, SIGNAL( toggled( bool ) ),
this, SLOT( toggleAutoSave( bool ) ) );
if( ! m_enableAutoSave ){ m_saveIntervalSlider->setEnabled( false ); }
QPushButton * saveIntervalResetBtn = new QPushButton(
embed::getIconPixmap( "reload" ), "", auto_save_tw );
saveIntervalResetBtn->setGeometry( 290, 50, 28, 28 );
connect( saveIntervalResetBtn, SIGNAL( clicked() ), this,
SLOT( resetAutoSaveInterval() ) );
ToolTip::add( bufsize_reset_btn, tr( "Reset to default-value" ) );
QPushButton * saventervalBtn = new QPushButton(
embed::getIconPixmap( "help" ), "", auto_save_tw );
saventervalBtn->setGeometry( 320, 50, 28, 28 );
connect( saventervalBtn, SIGNAL( clicked() ), this,
SLOT( displaySaveIntervalHelp() ) );
perf_layout->addWidget( auto_save_tw );
perf_layout->addSpacing( 10 );
TabWidget * ui_fx_tw = new TabWidget( tr( "UI effects vs. "
"performance" ).toUpper(),
performance );
ui_fx_tw->setFixedHeight( 80 );
ui_fx_tw->setFixedHeight( 70 );
LedCheckBox * smoothScroll = new LedCheckBox(
tr( "Smooth scroll in Song Editor" ), ui_fx_tw );
@@ -672,19 +721,10 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) :
connect( smoothScroll, SIGNAL( toggled( bool ) ),
this, SLOT( toggleSmoothScroll( bool ) ) );
LedCheckBox * autoSave = new LedCheckBox(
tr( "Enable auto save feature" ), ui_fx_tw );
autoSave->move( 10, 40 );
autoSave->setChecked( m_enableAutoSave );
connect( autoSave, SIGNAL( toggled( bool ) ),
this, SLOT( toggleAutoSave( bool ) ) );
LedCheckBox * animAFP = new LedCheckBox(
tr( "Show playback cursor in AudioFileProcessor" ),
ui_fx_tw );
animAFP->move( 10, 60 );
animAFP->move( 10, 40 );
animAFP->setChecked( m_animateAFP );
connect( animAFP, SIGNAL( toggled( bool ) ),
this, SLOT( toggleAnimateAFP( bool ) ) );
@@ -986,6 +1026,8 @@ void SetupDialog::accept()
QString::number( m_smoothScroll ) );
ConfigManager::inst()->setValue( "ui", "enableautosave",
QString::number( m_enableAutoSave ) );
ConfigManager::inst()->setValue( "ui", "saveinterval",
QString::number( m_saveInterval ) );
ConfigManager::inst()->setValue( "ui", "oneinstrumenttrackwindow",
QString::number( m_oneInstrumentTrackWindow ) );
ConfigManager::inst()->setValue( "ui", "compacttrackbuttons",
@@ -1169,6 +1211,7 @@ void SetupDialog::toggleSmoothScroll( bool _enabled )
void SetupDialog::toggleAutoSave( bool _enabled )
{
m_enableAutoSave = _enabled;
m_saveIntervalSlider->setEnabled( _enabled );
}
@@ -1471,6 +1514,41 @@ void SetupDialog::setBackgroundArtwork( const QString & _ba )
void SetupDialog::setAutoSaveInterval( int value )
{
m_saveInterval = value;
m_saveIntervalSlider->setValue( m_saveInterval );
QString minutes = m_saveInterval > 1 ? tr( "minutes" ) : tr( "minute" );
m_saveIntervalLbl->setText( tr( "Auto save interval: %1 %2" ).arg(
QString::number( m_saveInterval ), minutes ) );
}
void SetupDialog::resetAutoSaveInterval()
{
if( m_enableAutoSave )
{
setAutoSaveInterval( MainWindow::DEFAULT_SAVE_INTERVAL_MINUTES );
}
}
void SetupDialog::displaySaveIntervalHelp()
{
QWhatsThis::showText( QCursor::pos(),
tr( "Set the time between automatic backup to %1.\n"
"Remember to also save your project manually." ).arg(
ConfigManager::inst()->recoveryFile() ) );
}
void SetupDialog::audioInterfaceChanged( const QString & _iface )
{
for( AswMap::iterator it = m_audioIfaceSetupWidgets.begin();