diff --git a/include/MainWindow.h b/include/MainWindow.h index 845a872ce..ee0804b22 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -253,6 +253,7 @@ private slots: void onExportProjectTracks(); void onImportProject(); void onSongStopped(); + void onSongModified(); signals: void periodicUpdate(); diff --git a/include/Song.h b/include/Song.h index fc4625eed..c1ca62688 100644 --- a/include/Song.h +++ b/include/Song.h @@ -370,6 +370,8 @@ private: void processAutomations(const TrackList& tracks, MidiTime timeStart, fpp_t frames); + void setModified(bool value); + AutomationTrack * m_globalAutomationTrack; IntModel m_tempoModel; @@ -429,6 +431,7 @@ signals: void controllerRemoved( Controller * ); void updateSampleTracks(); void stopped(); + void modified(); } ; diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 9dc37a0b4..a7f81bf46 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -451,6 +451,18 @@ void Song::processAutomations(const TrackList &tracklist, MidiTime timeStart, fp } } +void Song::setModified(bool value) +{ + if( !m_loadingProject ) + { + if (m_modified != value) + { + m_modified = value; + emit modified(); + } + } +} + std::pair Song::getExportEndpoints() const { if ( m_renderBetweenMarkers ) @@ -933,13 +945,8 @@ void Song::createNewProject() QCoreApplication::sendPostedEvents(); - m_modified = false; + setModified(false); m_loadOnLaunch = false; - - if( gui->mainWindow() ) - { - gui->mainWindow()->resetWindowTitle(); - } } @@ -1132,13 +1139,8 @@ void Song::loadProject( const QString & fileName ) } m_loadingProject = false; - m_modified = false; + setModified(false); m_loadOnLaunch = false; - - if( gui && gui->mainWindow() ) - { - gui->mainWindow()->resetWindowTitle(); - } } @@ -1184,7 +1186,7 @@ bool Song::guiSaveProject() if( saveResult ) { - m_modified = false; + setModified(false); } return saveResult; @@ -1289,15 +1291,7 @@ void Song::updateFramesPerTick() void Song::setModified() { - if( !m_loadingProject ) - { - m_modified = true; - if( gui != nullptr && gui->mainWindow() && - QThread::currentThread() == gui->mainWindow()->thread() ) - { - gui->mainWindow()->resetWindowTitle(); - } - } + setModified(true); } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 954d9a5e8..651de1177 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -236,6 +236,8 @@ MainWindow::MainWindow() : this, SLOT( updatePlayPauseIcons() ) ); connect(Engine::getSong(), SIGNAL(stopped()), SLOT(onSongStopped())); + + connect(Engine::getSong(), SIGNAL(modified()), SLOT(onSongModified())); } @@ -672,24 +674,24 @@ SubWindow* MainWindow::addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags void MainWindow::resetWindowTitle() { - QString title = ""; + QString title(tr( "Untitled" )); + if( Engine::getSong()->projectFileName() != "" ) { title = QFileInfo( Engine::getSong()->projectFileName() ).completeBaseName(); } - if( title == "" ) - { - title = tr( "Untitled" ); - } + if( Engine::getSong()->isModified() ) { title += '*'; } + if( getSession() == Recover ) { title += " - " + tr( "Recover session. Please save your work!" ); } + setWindowTitle( title + " - " + tr( "LMMS %1" ).arg( LMMS_VERSION ) ); } @@ -1803,3 +1805,15 @@ void MainWindow::onSongStopped() } } } + +void MainWindow::onSongModified() +{ + // Only update the window title if the code is executed from the GUI main thread. + // The assumption seems to be that the Song can also be set as modified from other + // threads. This is not a good design! Copied from the original implementation of + // Song::setModified. + if(QThread::currentThread() == this->thread()) + { + this->resetWindowTitle(); + } +}