Merge pull request #1525 from badosu/show-errors-on-cli

[WIP] Refactor errors notification system
This commit is contained in:
Tres Finocchiaro
2015-01-12 21:45:23 -05:00
10 changed files with 60 additions and 90 deletions

View File

@@ -40,8 +40,6 @@
#include "GuiApplication.h"
bool Engine::s_suppressMessages = false;
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

@@ -126,8 +126,6 @@ PresetPreviewPlayHandle::PresetPreviewPlayHandle( const QString & _preset_file,
const bool j = Engine::projectJournal()->isJournalling();
Engine::projectJournal()->setJournalling( false );
Engine::setSuppressMessages( true );
if( _load_by_plugin )
{
Instrument * i = s_previewTC->previewInstrumentTrack()->instrument();
@@ -162,8 +160,6 @@ PresetPreviewPlayHandle::PresetPreviewPlayHandle( const QString & _preset_file,
}
}
Engine::setSuppressMessages( false );
// make sure, our preset-preview-track does not appear in any MIDI-
// devices list, so just disable receiving/sending MIDI-events at all
s_previewTC->previewInstrumentTrack()->

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 );
}
}