From 6a716ef9854e55f74d564812ca5594783b51d688 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Fri, 8 Dec 2017 20:05:24 +0100 Subject: [PATCH] Move import functionality from Song to MainWindow Move the functionality of the method Song::importProject into the MainWindow as it mainly consists of GUI related actions. Add a new method Song::setLoadOnLauch to ensure that the boolean Song::m_loadOnLaunch is still set at the end of the import. --- include/MainWindow.h | 1 + include/Song.h | 4 ++-- src/core/Song.cpp | 25 ------------------------- src/gui/MainWindow.cpp | 30 ++++++++++++++++++++++++++++-- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index 32f9e4a0b..bd2d8f28d 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -248,6 +248,7 @@ private slots: void onToggleMetronome(); void onExportProject(); void onExportProjectTracks(); + void onImportProject(); signals: diff --git a/include/Song.h b/include/Song.h index 630d9726e..b972761e3 100644 --- a/include/Song.h +++ b/include/Song.h @@ -300,6 +300,8 @@ public: void exportProjectMidi(QString const & exportFileName) const; + inline void setLoadOnLauch(bool value) { m_loadOnLaunch = value; } + public slots: void playSong(); void record(); @@ -309,8 +311,6 @@ public slots: void togglePause(); void stop(); - void importProject(); - void startExport(); void stopExport(); diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 995e0c574..ef4e1da16 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -37,7 +37,6 @@ #include "BBEditor.h" #include "BBTrack.h" #include "BBTrackContainer.h" -#include "ConfigManager.h" #include "ControllerRackView.h" #include "ControllerConnection.h" #include "embed.h" @@ -45,10 +44,8 @@ #include "FxMixer.h" #include "FxMixerView.h" #include "GuiApplication.h" -#include "ImportFilter.h" #include "ExportFilter.h" #include "MainWindow.h" -#include "FileDialog.h" #include "Pattern.h" #include "PianoRoll.h" #include "ProjectJournal.h" @@ -1239,28 +1236,6 @@ bool Song::guiSaveProjectAs( const QString & _file_name ) -void Song::importProject() -{ - FileDialog ofd( NULL, tr( "Import file" ), - ConfigManager::inst()->userProjectsDir(), - tr("MIDI sequences") + - " (*.mid *.midi *.rmi);;" + - tr("Hydrogen projects") + - " (*.h2song);;" + - tr("All file types") + - " (*.*)"); - - ofd.setFileMode( FileDialog::ExistingFiles ); - if( ofd.exec () == QDialog::Accepted && !ofd.selectedFiles().isEmpty() ) - { - ImportFilter::import( ofd.selectedFiles()[0], this ); - } - m_loadOnLaunch = false; -} - - - - void Song::saveControllerStates( QDomDocument & doc, QDomElement & element ) { // save settings of controllers diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 50e79db4d..3818543d2 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -50,6 +50,7 @@ #include "FileDialog.h" #include "FxMixerView.h" #include "GuiApplication.h" +#include "ImportFilter.h" #include "PianoRoll.h" #include "PluginBrowser.h" #include "PluginFactory.h" @@ -309,8 +310,8 @@ void MainWindow::finalize() project_menu->addSeparator(); project_menu->addAction( embed::getIconPixmap( "project_import" ), tr( "Import..." ), - Engine::getSong(), - SLOT( importProject() ) ); + this, + SLOT( onImportProject() ) ); project_menu->addAction( embed::getIconPixmap( "project_export" ), tr( "E&xport..." ), this, @@ -1703,3 +1704,28 @@ void MainWindow::onExportProjectTracks() { this->exportProject(true); } + +void MainWindow::onImportProject() +{ + Song * song = Engine::getSong(); + + if (song) + { + FileDialog ofd( nullptr, tr( "Import file" ), + ConfigManager::inst()->userProjectsDir(), + tr("MIDI sequences") + + " (*.mid *.midi *.rmi);;" + + tr("Hydrogen projects") + + " (*.h2song);;" + + tr("All file types") + + " (*.*)"); + + ofd.setFileMode( FileDialog::ExistingFiles ); + if( ofd.exec () == QDialog::Accepted && !ofd.selectedFiles().isEmpty() ) + { + ImportFilter::import( ofd.selectedFiles()[0], song ); + } + + song->setLoadOnLauch(false); + } +}