~ci-train-bot/qtubuntu-media/qtubuntu-media-ubuntu-yakkety-landing-056

« back to all changes in this revision

Viewing changes to src/aal/aalmediaplaylistcontrol.cpp

  • Committer: CI Train Bot
  • Author(s): Jim Hodapp
  • Date: 2016-01-12 15:55:53 UTC
  • mfrom: (83.1.17 qtubuntu-media-1528898)
  • Revision ID: ci-train-bot@canonical.com-20160112155553-a9a73lqaktpkj500
Fix bug #1528898 Fixes: #1528898
Approved by: Andrew Hayzen

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
      m_trackChangedConnection(the_void.connect([](){})),
45
45
      m_trackMovedConnection(the_void.connect([](){}))
46
46
{
47
 
    qDebug() << Q_FUNC_INFO;
48
47
    qRegisterMetaType<core::ubuntu::media::Track::Id>();
49
48
}
50
49
 
277
276
    m_currentId = aalMediaPlaylistProvider()->trackOfIndex(m_currentIndex);
278
277
}
279
278
 
 
279
void AalMediaPlaylistControl::onMediaRemoved(int start, int end)
 
280
{
 
281
    Q_UNUSED(start);
 
282
    Q_UNUSED(end);
 
283
 
 
284
    // If the entire playlist is cleared, we need to reset the currentIndex
 
285
    // to just before the beginning of the list, otherwise if the user selects
 
286
    // a random track in the tracklist for a second time, track 0 is always
 
287
    // selected instead of the desired track index
 
288
    if (aalMediaPlaylistProvider()->mediaCount() == 0)
 
289
    {
 
290
        qDebug() << "Tracklist was cleared, resetting m_currentIndex to 0";
 
291
        m_currentIndex = 0;
 
292
        m_currentId.clear();
 
293
    }
 
294
}
 
295
 
 
296
void AalMediaPlaylistControl::onRemoveTracks(int start, int end)
 
297
{
 
298
    // If the current track and everything after has been removed
 
299
    // then we need to set the currentIndex to 0 otherwise it is
 
300
    // left at the position it was before removing
 
301
    if (start <= m_currentIndex
 
302
            and m_currentIndex <= end
 
303
            and (end + 1) == m_playlistProvider->mediaCount()
 
304
            and start != 0)
 
305
    {
 
306
        m_currentIndex = 0;
 
307
        setCurrentIndex(0);
 
308
 
 
309
        // When repeat is off we have reached the end of playback so stop
 
310
        if (playbackMode() == QMediaPlaylist::Sequential)
 
311
        {
 
312
            qDebug() << "Repeat is off, so stopping playback";
 
313
            m_hubPlayerSession->stop();
 
314
        }
 
315
    }
 
316
}
 
317
 
280
318
void AalMediaPlaylistControl::onCurrentIndexChanged()
281
319
{
282
 
    int index = aalMediaPlaylistProvider()->indexOfTrack(m_currentId);
283
 
 
 
320
    const int index = aalMediaPlaylistProvider()->indexOfTrack(m_currentId);
284
321
    if (index != m_currentIndex) {
285
 
        qDebug() << "Index changed to " << index;
 
322
        qDebug() << "Index changed to" << index;
286
323
        m_currentIndex = index;
287
324
        Q_EMIT currentIndexChanged(m_currentIndex);
288
325
    }
343
380
 
344
381
    connect(aalMediaPlaylistProvider(), &AalMediaPlaylistProvider::startMoveTrack,
345
382
            this, &AalMediaPlaylistControl::onStartMoveTrack);
 
383
 
 
384
    connect(aalMediaPlaylistProvider(), &AalMediaPlaylistProvider::mediaRemoved,
 
385
            this, &AalMediaPlaylistControl::onMediaRemoved);
 
386
 
 
387
    connect(aalMediaPlaylistProvider(), &AalMediaPlaylistProvider::removeTracks,
 
388
            this, &AalMediaPlaylistControl::onRemoveTracks);
346
389
}
347
390
 
348
391
void AalMediaPlaylistControl::disconnect_signals()