mirror of
https://github.com/LMMS/lmms.git
synced 2026-04-01 12:53:49 -04:00
Move some window title updates from Song into MainWindow
Move the window title updates which are triggered due to a changed modify state from Song to MainWindow. Implementation details: Add a new signal modified to Song and connect the new slot method MainWindow::onSongModified to it. Currently only the window title is updated in the slot. It is only updated if the code is executed from the GUI main thread. This implementation was taken over from the original implementation of Song::setModified. The assumption here seems to be that the Song might also be set as modified from other threads (which is a bad design). Add a new private method Song::setModified(bool) and replace all direct manipulations of m_modified in Song by calls to this method. This is done to ensure that the signal can be emitted in all these cases. Make Song::setModified() delegates to Song::setModified(bool) for the same reason. Other changes: Slightly refactor MainWindow::resetWindowTitle to get rid of an unnecessary if statement.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user