Refactor loading song errors notification

This commit is contained in:
Amadeus Folego
2014-12-29 03:56:46 -02:00
parent 3dd1da4e25
commit edebf5d7da
9 changed files with 60 additions and 75 deletions

View File

@@ -117,7 +117,6 @@ private:
delete tmp;
}
static bool s_hasGUI;
static float s_framesPerTick;
// core

View File

@@ -30,8 +30,6 @@
#include <QtCore/QList>
#include <QMainWindow>
#include "export.h"
class QAction;
class QDomElement;
class QGridLayout;
@@ -42,7 +40,7 @@ class PluginView;
class ToolButton;
class EXPORT MainWindow : public QMainWindow
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
@@ -97,12 +95,6 @@ public:
static void saveWidgetState( QWidget * _w, QDomElement & _de );
static void restoreWidgetState( QWidget * _w, const QDomElement & _de );
void collectErrors( const QList<QString>* errors );
void collectError( const QString & error );
void clearErrors();
void showErrors( const QString & reason );
public slots:
void resetWindowTitle();
@@ -178,8 +170,6 @@ private:
QBasicTimer m_updateTimer;
QTimer m_autoSaveTimer;
QList<QString>* m_errors;
friend class GuiApplication;
@@ -199,4 +189,3 @@ signals:
} ;
#endif

View File

@@ -65,6 +65,10 @@ public:
Mode_Count
} ;
void clearErrors();
void collectError( const QString error );
bool hasErrors();
QString* errorSummary();
class playPos : public MidiTime
{
@@ -344,6 +348,8 @@ private:
bool m_loadingProject;
QList<QString> * m_errors;
PlayModes m_playMode;
playPos m_playPos[Mode_Count];
tact_t m_length;

View File

@@ -39,7 +39,7 @@
#include "ControllerConnection.h"
#include "MemoryManager.h"
#include "ValueBuffer.h"
#include "MainWindow.h"
#include "Song.h"
#include "embed.cpp"
@@ -75,12 +75,8 @@ LadspaEffect::LadspaEffect( Model * _parent,
Ladspa2LMMS * manager = Engine::getLADSPAManager();
if( manager->getDescription( m_key ) == NULL )
{
if ( Engine::hasGUI() )
{
Engine::mainWindow()->collectError(
tr( "Unknown LADSPA plugin %1 requested." ).arg(
m_key.second ) );
}
Engine::getSong()->collectError(tr( "Unknown LADSPA plugin %1 requested." ).arg(
m_key.second ) );
setOkay( false );
return;
}

View File

@@ -34,8 +34,6 @@
#include "audio_file_processor.h"
#include "Engine.h"
#include "Song.h"
#include "MainWindow.h"
#include "GuiApplication.h"
#include "InstrumentTrack.h"
#include "NotePlayHandle.h"
#include "interpolation.h"
@@ -242,7 +240,7 @@ void audioFileProcessor::loadSettings( const QDomElement & _this )
{
QString message = tr( "Sample not found: %1" ).arg( m_sampleBuffer.audioFile() );
gui->mainWindow()->collectError( message );
Engine::getSong()->collectError( message );
}
}
else if( _this.attribute( "sampledata" ) != "" )

View File

@@ -40,7 +40,6 @@
#include "GuiApplication.h"
bool Engine::s_hasGUI = true;
float Engine::s_framesPerTick;
Mixer* Engine::s_mixer = NULL;
FxMixer * Engine::s_fxMixer = NULL;

View File

@@ -35,7 +35,7 @@
#include "ConfigManager.h"
#include "DummyPlugin.h"
#include "AutomatableModel.h"
#include "MainWindow.h"
#include "Song.h"
static PixmapLoader __dummy_loader;
@@ -128,7 +128,7 @@ Plugin * Plugin::instantiate( const QString & pluginName, Model * parent,
void Plugin::collectErrorForUI( QString err_msg )
{
gui->mainWindow()->collectError( err_msg );
Engine::getSong()->collectError( err_msg );
}

View File

@@ -23,7 +23,7 @@
*/
#include "Song.h"
#include <QTextStream>
#include <QCoreApplication>
#include <QFile>
#include <QFileInfo>
@@ -90,6 +90,7 @@ Song::Song() :
m_playing( false ),
m_paused( false ),
m_loadingProject( false ),
m_errors( new QList<QString>() ),
m_playMode( Mode_None ),
m_length( 0 ),
m_trackToPlay( NULL ),
@@ -914,10 +915,6 @@ void Song::loadProject( const QString & _file_name )
m_loadingProject = true;
Engine::projectJournal()->setJournalling( false );
if( gui )
{
gui->mainWindow()->clearErrors();
}
m_fileName = _file_name;
m_oldFileName = _file_name;
@@ -932,6 +929,8 @@ void Song::loadProject( const QString & _file_name )
clearProject();
clearErrors();
DataFile::LocaleHelper localeHelper( DataFile::LocaleHelper::ModeLoad );
Engine::mixer()->lock();
@@ -1029,9 +1028,17 @@ void Song::loadProject( const QString & _file_name )
emit projectLoaded();
if( gui )
if ( hasErrors())
{
gui->mainWindow()->showErrors( tr( "The following errors occured while loading: " ) );
if ( Engine::hasGUI() )
{
QMessageBox::warning( NULL, "LMMS Error report", *errorSummary(),
QMessageBox::Ok );
}
else
{
QTextStream(stderr) << *Engine::getSong()->errorSummary() << endl;
}
}
m_loadingProject = false;
@@ -1322,5 +1329,38 @@ void Song::removeController( Controller * _controller )
void Song::clearErrors()
{
m_errors->clear();
}
void Song::collectError( const QString error )
{
m_errors->append( error );
}
bool Song::hasErrors()
{
return ( m_errors->length() > 0 );
}
QString* Song::errorSummary()
{
QString* errors = new QString();
for ( int i = 0 ; i < m_errors->length() ; i++ )
{
errors->append( m_errors->value( i ) + "\n" );
}
errors->prepend( "\n\n" );
errors->prepend( tr( "The following errors occured while loading: " ) );
return errors;
}

View File

@@ -190,8 +190,6 @@ MainWindow::MainWindow() :
vbox->addWidget( w );
setCentralWidget( main_widget );
m_errors = new QList<QString>();
m_updateTimer.start( 1000 / 20, this ); // 20 fps
if( ConfigManager::inst()->value( "ui", "enableautosave" ).toInt() )
@@ -1225,43 +1223,3 @@ void MainWindow::autoSave()
QTimer::singleShot( 10*1000, this, SLOT( autoSave() ) );
}
}
void MainWindow::collectErrors(const QList<QString>* errors )
{
m_errors->append( *errors );
}
void MainWindow::collectError( const QString & error )
{
m_errors->append( error );
}
void MainWindow::clearErrors()
{
m_errors->clear();
}
void MainWindow::showErrors( const QString & message )
{
if ( m_errors->length() != 0 )
{ QString* errors = new QString();
for ( int i = 0 ; i < m_errors->length() ; i++ )
{
errors->append( m_errors->value( i ) + "\n" );
}
errors->prepend( "\n\n" );
errors->prepend( message );
QMessageBox::warning( NULL,
"LMMS Error report",
*errors,
QMessageBox::Ok );
}
}