From edebf5d7da416b07ce77c7b465049b71e68df4e2 Mon Sep 17 00:00:00 2001 From: Amadeus Folego Date: Mon, 29 Dec 2014 03:56:46 -0200 Subject: [PATCH] Refactor loading song errors notification --- include/Engine.h | 1 - include/MainWindow.h | 13 +---- include/Song.h | 6 +++ plugins/LadspaEffect/LadspaEffect.cpp | 10 ++-- .../audio_file_processor.cpp | 4 +- src/core/Engine.cpp | 1 - src/core/Plugin.cpp | 4 +- src/core/Song.cpp | 54 ++++++++++++++++--- src/gui/MainWindow.cpp | 42 --------------- 9 files changed, 60 insertions(+), 75 deletions(-) diff --git a/include/Engine.h b/include/Engine.h index 03314a5d8..55dd9021e 100644 --- a/include/Engine.h +++ b/include/Engine.h @@ -117,7 +117,6 @@ private: delete tmp; } - static bool s_hasGUI; static float s_framesPerTick; // core diff --git a/include/MainWindow.h b/include/MainWindow.h index d02b68494..82f3cd365 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -30,8 +30,6 @@ #include #include -#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* 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* m_errors; - friend class GuiApplication; @@ -199,4 +189,3 @@ signals: } ; #endif - diff --git a/include/Song.h b/include/Song.h index 90f29cf24..5da09818a 100644 --- a/include/Song.h +++ b/include/Song.h @@ -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 * m_errors; + PlayModes m_playMode; playPos m_playPos[Mode_Count]; tact_t m_length; diff --git a/plugins/LadspaEffect/LadspaEffect.cpp b/plugins/LadspaEffect/LadspaEffect.cpp index 8906b9578..5fb89df2d 100644 --- a/plugins/LadspaEffect/LadspaEffect.cpp +++ b/plugins/LadspaEffect/LadspaEffect.cpp @@ -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; } diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index 2caf210ae..be7519179 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -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" ) != "" ) diff --git a/src/core/Engine.cpp b/src/core/Engine.cpp index 2f2b3ba1c..b11ad1e47 100644 --- a/src/core/Engine.cpp +++ b/src/core/Engine.cpp @@ -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; diff --git a/src/core/Plugin.cpp b/src/core/Plugin.cpp index ebfb62cb1..abdc44a96 100644 --- a/src/core/Plugin.cpp +++ b/src/core/Plugin.cpp @@ -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 ); } diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 07d55a0dd..4c62a1062 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -23,7 +23,7 @@ */ #include "Song.h" - +#include #include #include #include @@ -90,6 +90,7 @@ Song::Song() : m_playing( false ), m_paused( false ), m_loadingProject( false ), + m_errors( new QList() ), 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; +} diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 7211bd2e1..048476a4d 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -190,8 +190,6 @@ MainWindow::MainWindow() : vbox->addWidget( w ); setCentralWidget( main_widget ); - m_errors = new QList(); - 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* 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 ); - } -}