From 408ab3fea50a9cbb8ff8fc5ee9bfb10d09f8cbdb Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sun, 7 Sep 2008 12:54:23 +0000 Subject: [PATCH] display message if project is empty and user tries to export it (closes #2091056) git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1571 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 6 ++++++ include/track_container.h | 5 ++++- src/core/song.cpp | 10 ++++++++++ src/core/track_container.cpp | 34 ++++++++++++++++++++++++---------- src/gui/main_window.cpp | 2 +- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index f73ae1f65..a24813297 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-09-07 Tobias Doerffel + * include/track_container.h: + * src/core/song.cpp: + * src/core/track_container.cpp: + display message if project is empty and user tries to export + it (closes #2091056) + * src/core/song.cpp: - fixed freeze after adding BB-tracks (closes #2089337) - replaced bad cast for calling projectNotes::save/restoreState by diff --git a/include/track_container.h b/include/track_container.h index 0914fb423..2e02635e9 100644 --- a/include/track_container.h +++ b/include/track_container.h @@ -60,10 +60,11 @@ public: int countTracks( track::TrackTypes _tt = track::NumTrackTypes ) const; - virtual void updateAfterTrackAdd( void ); void addTrack( track * _track ); void removeTrack( track * _track ); + virtual void updateAfterTrackAdd( void ); + void clearAllTracks( void ); const trackList & tracks( void ) const @@ -71,6 +72,8 @@ public: return( m_tracks ); } + bool isEmpty( void ) const; + static const QString classNodeName( void ) { return( "trackcontainer" ); diff --git a/src/core/song.cpp b/src/core/song.cpp index d2d6f7bca..6a2013b24 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -1110,6 +1110,16 @@ void song::restoreControllerStates( const QDomElement & _this ) void song::exportProject( void ) { + if( isEmpty() ) + { + QMessageBox::information( engine::getMainWindow(), + tr( "Empty project" ), + tr( "This project is empty so exporting makes " + "no sense. Please put some items into " + "Song Editor first!" ) ); + return; + } + QString base_filename; if( m_fileName != "" ) diff --git a/src/core/track_container.cpp b/src/core/track_container.cpp index 465fec5b2..dfc9ca2b6 100644 --- a/src/core/track_container.cpp +++ b/src/core/track_container.cpp @@ -130,6 +130,24 @@ void trackContainer::loadSettings( const QDomElement & _this ) +int trackContainer::countTracks( track::TrackTypes _tt ) const +{ + int cnt = 0; + m_tracksMutex.lockForRead(); + for( int i = 0; i < m_tracks.size(); ++i ) + { + if( m_tracks[i]->type() == _tt || _tt == track::NumTrackTypes ) + { + ++cnt; + } + } + m_tracksMutex.unlock(); + return( cnt ); +} + + + + void trackContainer::addTrack( track * _track ) { if( _track->type() != track::HiddenAutomationTrack ) @@ -163,7 +181,6 @@ void trackContainer::removeTrack( track * _track ) - void trackContainer::updateAfterTrackAdd( void ) { } @@ -171,7 +188,6 @@ void trackContainer::updateAfterTrackAdd( void ) - void trackContainer::clearAllTracks( void ) { //m_tracksMutex.lockForWrite(); @@ -185,19 +201,17 @@ void trackContainer::clearAllTracks( void ) -int trackContainer::countTracks( track::TrackTypes _tt ) const +bool trackContainer::isEmpty( void ) const { - int cnt = 0; - m_tracksMutex.lockForRead(); - for( int i = 0; i < m_tracks.size(); ++i ) + for( trackList::const_iterator it = m_tracks.begin(); + it != m_tracks.end(); ++it ) { - if( m_tracks[i]->type() == _tt || _tt == track::NumTrackTypes ) + if( !( *it )->getTCOs().isEmpty() ) { - ++cnt; + return false; } } - m_tracksMutex.unlock(); - return( cnt ); + return true; } diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp index 7a891cf64..ec7af69cf 100644 --- a/src/gui/main_window.cpp +++ b/src/gui/main_window.cpp @@ -531,7 +531,7 @@ bool mainWindow::mayChangeProject( void ) return( TRUE ); } - QMessageBox mb ( tr( "Project not saved" ), + QMessageBox mb( tr( "Project not saved" ), tr( "The current project was modified since " "last saving. Do you want to save it " "now?" ),