Skip to content

Commit

Permalink
Fixes for project loading progress display (LMMS#3672)
Browse files Browse the repository at this point in the history
Fix project loading progress jumping back.

Show the name of the track currently being loaded.
  • Loading branch information
PhysSong committed Jul 8, 2017
1 parent 9c6cde1 commit 1c21eae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
5 changes: 5 additions & 0 deletions include/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class EXPORT Song : public TrackContainer

void processNextBuffer();

inline int getLoadingTrackCount() const
{
return m_nLoadingTrack;
}
inline int getMilliseconds() const
{
return m_elapsedMilliSeconds;
Expand Down Expand Up @@ -339,6 +343,7 @@ private slots:

ControllerVector m_controllers;

int m_nLoadingTrack;

QString m_fileName;
QString m_oldFileName;
Expand Down
21 changes: 21 additions & 0 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,27 @@ void Song::loadProject( const QString & fileName )
}

node = dataFile.content().firstChild();

QDomNodeList tclist=dataFile.content().elementsByTagName("trackcontainer");
m_nLoadingTrack=0;
for( int i=0,n=tclist.count(); i<n; ++i )
{
QDomNode nd=tclist.at(i).firstChild();
while(!nd.isNull())
{
if( nd.isElement() && nd.nodeName() == "track" )
{
++m_nLoadingTrack;
if( nd.toElement().attribute("type").toInt() == Track::BBTrack )
{
n += nd.toElement().elementsByTagName("bbtrack").at(0)
.toElement().firstChildElement().childNodes().count();
}
nd=nd.nextSibling();
}
}
}

while( !node.isNull() )
{
if( node.isElement() )
Expand Down
18 changes: 9 additions & 9 deletions src/core/TrackContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,18 @@ void TrackContainer::loadSettings( const QDomElement & _this )

static QProgressDialog * pd = NULL;
bool was_null = ( pd == NULL );
int start_val = 0;
if( !journalRestore && gui != nullptr )
{
if( pd == NULL )
{
pd = new QProgressDialog( tr( "Loading project..." ),
tr( "Cancel" ), 0,
_this.childNodes().count(),
Engine::getSong()->getLoadingTrackCount(),
gui->mainWindow() );
pd->setWindowModality( Qt::ApplicationModal );
pd->setWindowTitle( tr( "Please wait..." ) );
pd->show();
}
else
{
start_val = pd->value();
pd->setMaximum( pd->maximum() +
_this.childNodes().count() );
}
}

QDomNode node = _this.firstChild();
Expand All @@ -124,14 +117,21 @@ void TrackContainer::loadSettings( const QDomElement & _this )
if( node.isElement() &&
!node.toElement().attribute( "metadata" ).toInt() )
{
QString trackName = node.toElement().hasAttribute( "name" ) ?
node.toElement().attribute( "name" ) :
node.firstChild().toElement().attribute( "name" );
if( pd != NULL )
{
pd->setLabelText( tr("Loading Track %1 (%2/Total %3)").arg( trackName ).
arg( pd->value() + 1 ).arg( Engine::getSong()->getLoadingTrackCount() ) );
}
Track::create( node.toElement(), this );
}
node = node.nextSibling();
}

if( pd != NULL )
{
pd->setValue( start_val + _this.childNodes().count() );
if( was_null )
{
delete pd;
Expand Down

0 comments on commit 1c21eae

Please sign in to comment.