Skip to content

Commit

Permalink
Recover file fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zonkmachine committed Aug 3, 2015
1 parent 87c1558 commit ff08551
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 18 deletions.
Binary file added data/themes/default/no_entry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 40 additions & 2 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,42 @@ class MainWindow : public QMainWindow
///
bool mayChangeProject(bool stopPlayback);

void autoSaveTimerStart()
{
m_autoSaveTimer.start( 1000 * 60 ); // 1 minute
}

bool isRecoverSession()
{
return m_recoverSession;
}

void setRecoverSession()
{
m_recoverSession = true;
}

void resetRecoverSession()
{
m_recoverSession = false;
}

void recoverSessionCleanup();

bool isLimitedSession()
{
return m_limitedSession;
}

void setLimitedSession()
{
m_limitedSession = true;
}

void resetLimitedSession()
{
m_limitedSession = false;
}

void clearKeyModifiers();

Expand Down Expand Up @@ -130,6 +166,8 @@ public slots:
void undo();
void redo();

void autoSave();
void runAutoSave();

protected:
virtual void closeEvent( QCloseEvent * _ce );
Expand All @@ -149,6 +187,8 @@ public slots:
void toggleWindow( QWidget *window, bool forceShow = false );
void refocus();

bool m_recoverSession;
bool m_limitedSession;

QMdiArea * m_workspace;

Expand Down Expand Up @@ -194,8 +234,6 @@ private slots:
void updateConfig( QAction * _who );


void autoSave();

signals:
void periodicUpdate();
void initProgress(const QString &msg);
Expand Down
112 changes: 105 additions & 7 deletions src/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QTranslator>
#include <QApplication>
#include <QMessageBox>
#include <QPushButton>
#include <QTextStream>

#ifdef LMMS_BUILD_WIN32
Expand All @@ -60,6 +61,7 @@
#include "MemoryManager.h"
#include "ConfigManager.h"
#include "NotePlayHandle.h"
#include "embed.h"
#include "Engine.h"
#include "GuiApplication.h"
#include "ImportFilter.h"
Expand Down Expand Up @@ -451,14 +453,100 @@ int main( int argc, char * * argv )

// recover a file?
QString recoveryFile = ConfigManager::inst()->recoveryFile();

if( QFileInfo(recoveryFile).exists() &&
QMessageBox::question( gui->mainWindow(), MainWindow::tr( "Project recovery" ),
MainWindow::tr( "It looks like the last session did not end properly. "
"Do you want to recover the project of this session?" ),
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes )
bool recoveryFilePresent = QFileInfo( recoveryFile ).exists() &&
QFileInfo( recoveryFile ).isFile();
bool autoSaveEnabled =
ConfigManager::inst()->value( "ui", "enableautosave" ).toInt();
if( recoveryFilePresent )
{
file_to_load = recoveryFile;
QMessageBox mb;
mb.setWindowTitle( MainWindow::tr( "Project recovery" ) );
mb.setText( QString(
"<html>"
"<p style=\"margin-left:6\">%1</p>"
"<table cellpadding=\"3\">"
" <tr>"
" <td><b>%2</b></td>"
" <td>%3</td>"
" </tr>"
" <tr>"
" <td><b>%4</b></td>"
" <td>%5</td>"
" </tr>"
" <tr>"
" <td><b>%6</b></td>"
" <td>%7</td>"
" </tr>"
" <tr>"
" <td><b>%8</b></td>"
" <td>%9</td>"
" </tr>"
"</table>"
"</html>" ).arg(
MainWindow::tr( "It looks like the last session did "
"not end properly. Do you want to recover the "
"project of this session?" ),
MainWindow::tr( "Recover" ),
MainWindow::tr( "Recover the file. Please don't run "
"multiple instances of LMMS when you do this." ),
MainWindow::tr( "Ignore" ),
MainWindow::tr( "Launch LMMS as usual but with "
"automatic backup disabled to prevent the "
"present recover file from being overwritten." ),
MainWindow::tr( "Discard" ),
MainWindow::tr( "Launch a default session and delete "
"the restored files. This is not reversible." ),
MainWindow::tr( "Quit" ),
MainWindow::tr( "Shut down LMMS with no further action." )
) );

mb.setIcon( QMessageBox::Warning );
mb.setWindowIcon( embed::getIconPixmap( "icon" ) );

mb.setStandardButtons( QMessageBox::Ok |
QMessageBox::Discard );

mb.setButtonText( QMessageBox::Ok,
MainWindow::tr( "Recover" ) );

QAbstractButton * recover;
QAbstractButton * discard;
QPushButton * ignore;
QPushButton * exit;

recover = mb.QMessageBox::button( QMessageBox::Ok );
discard = mb.QMessageBox::button( QMessageBox::Discard );
ignore = mb.addButton( MainWindow::tr( "Ignore" ),
QMessageBox::NoRole );
ignore->setIcon( embed::getIconPixmap( "no_entry" ) );
exit = mb.addButton( MainWindow::tr( "Exit" ),
QMessageBox::RejectRole );
exit->setIcon( embed::getIconPixmap( "exit" ) );

mb.setDefaultButton( QMessageBox::Ok );
mb.setEscapeButton( exit );

mb.exec();
if( mb.clickedButton() == discard )
{
gui->mainWindow()->recoverSessionCleanup();
}
else if( mb.clickedButton() == recover ) // ::Recover
{
file_to_load = recoveryFile;
gui->mainWindow()->setRecoverSession();
}
else if( mb.clickedButton() == ignore )
{
if( autoSaveEnabled )
{
gui->mainWindow()->setLimitedSession();
}
}
else // Exit
{
return 0;
}
}

// we try to load given file
Expand Down Expand Up @@ -505,6 +593,16 @@ int main( int argc, char * * argv )
}
}

// Finally we start the auto save timer and also trigger the
// autosave one time as recover.mmp is a signal to possible other
// instances of LMMS.
if( autoSaveEnabled &&
! gui->mainWindow()->isLimitedSession() )
{
gui->mainWindow()->runAutoSave();
gui->mainWindow()->autoSaveTimerStart();
}

}
else
{
Expand Down
Loading

0 comments on commit ff08551

Please sign in to comment.