mirror of
https://github.com/LMMS/lmms.git
synced 2026-03-14 12:08:33 -04:00
Recovery file fixes
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include <QTranslator>
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QTextStream>
|
||||
|
||||
#ifdef LMMS_BUILD_WIN32
|
||||
@@ -61,6 +62,7 @@
|
||||
#include "MemoryManager.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "NotePlayHandle.h"
|
||||
#include "embed.h"
|
||||
#include "Engine.h"
|
||||
#include "GuiApplication.h"
|
||||
#include "ImportFilter.h"
|
||||
@@ -644,13 +646,102 @@ 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 )
|
||||
{
|
||||
fileToLoad = 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( "There is a recovery file present. "
|
||||
"It looks like the last session did not end "
|
||||
"properly or another instance of LMMS is "
|
||||
"already running. 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()->sessionCleanup();
|
||||
}
|
||||
else if( mb.clickedButton() == recover ) // ::Recover
|
||||
{
|
||||
fileToLoad = recoveryFile;
|
||||
gui->mainWindow()->setSession( MainWindow::SessionState::Recover );
|
||||
}
|
||||
else if( mb.clickedButton() == ignore )
|
||||
{
|
||||
if( autoSaveEnabled )
|
||||
{
|
||||
gui->mainWindow()->setSession( MainWindow::SessionState::Limited );
|
||||
}
|
||||
}
|
||||
else // Exit
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// we try to load given file
|
||||
@@ -689,10 +780,13 @@ int main( int argc, char * * argv )
|
||||
{
|
||||
|
||||
// If enabled, open last project if there is one. Else, create
|
||||
// a new one.
|
||||
// a new one. Also skip recently opened file if limited session to
|
||||
// lower the chance of opening an already opened file.
|
||||
if( ConfigManager::inst()->
|
||||
value( "app", "openlastproject" ).toInt() &&
|
||||
!ConfigManager::inst()->recentlyOpenedProjects().isEmpty() )
|
||||
!ConfigManager::inst()->recentlyOpenedProjects().isEmpty() &&
|
||||
gui->mainWindow()->getSession()
|
||||
!= MainWindow::SessionState::Limited )
|
||||
{
|
||||
QString f = ConfigManager::inst()->
|
||||
recentlyOpenedProjects().first();
|
||||
@@ -720,6 +814,15 @@ int main( int argc, char * * argv )
|
||||
gui->mainWindow()->showMaximized();
|
||||
}
|
||||
}
|
||||
// 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()->getSession() != MainWindow::SessionState::Limited )
|
||||
{
|
||||
gui->mainWindow()->runAutoSave();
|
||||
gui->mainWindow()->autoSaveTimerStart();
|
||||
}
|
||||
}
|
||||
|
||||
const int ret = app->exec();
|
||||
|
||||
Reference in New Issue
Block a user