~ubuntu-branches/ubuntu/maverick/amarok/maverick-backports

« back to all changes in this revision

Viewing changes to src/core-impl/podcasts/sql/SqlPodcastMeta.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2011-03-03 10:20:39 UTC
  • mfrom: (126.1.8 natty)
  • Revision ID: james.westby@ubuntu.com-20110303102039-a408rug513n4qbin
Tags: 2:2.4.0-0ubuntu4~maverick1
* Source backprt to maverick (LP: #728447)
  - Drop version requirement on libindicate-qt-dev build-dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "core-impl/collections/support/CollectionManager.h"
22
22
#include "core/support/Debug.h"
23
23
#include "core/capabilities/EditCapability.h"
24
 
#include "core/capabilities/CurrentTrackActionsCapability.h"
 
24
#include "core/capabilities/ActionsCapability.h"
25
25
#include "core-impl/capabilities/timecode/TimecodeLoadCapability.h"
26
26
#include "core-impl/capabilities/timecode/TimecodeWriteCapability.h"
27
27
#include "SqlPodcastProvider.h"
235
235
{
236
236
    switch( type )
237
237
    {
238
 
        case Capabilities::Capability::CurrentTrackActions:
 
238
        case Capabilities::Capability::Actions:
239
239
        case Capabilities::Capability::WriteTimecode:
240
240
        case Capabilities::Capability::LoadTimecode:
241
241
            //only downloaded episodes can be position marked
255
255
{
256
256
    switch( type )
257
257
    {
258
 
        case Capabilities::Capability::CurrentTrackActions:
 
258
        case Capabilities::Capability::Actions:
259
259
        {
260
260
            QList< QAction * > actions;
261
 
            QAction* flag = new BookmarkCurrentTrackPositionAction( 0 );
262
 
            actions << flag;
263
 
            return new Capabilities::CurrentTrackActionsCapability( actions );
 
261
            actions << new BookmarkCurrentTrackPositionAction( 0 );
 
262
            return new Capabilities::ActionsCapability( actions );
264
263
        }
265
264
        case Capabilities::Capability::WriteTimecode:
266
265
            return new TimecodeWriteCapabilityPodcastImpl( this );
363
362
    if( m_localFile.isNull() )
364
363
        return false;
365
364
 
366
 
    Capabilities::EditCapability *ec = m_localFile->create<Capabilities::EditCapability>();
367
 
    if( ec == 0 )
 
365
    QScopedPointer<Capabilities::EditCapability> ec( m_localFile->create<Capabilities::EditCapability>() );
 
366
    if( !ec )
368
367
        return false;
369
368
 
370
369
    debug() << "writing tags for podcast episode " << title() << "to " << m_localUrl.url();
378
377
    ec->setAlbum( m_channel->title() );
379
378
    ec->setArtist( m_channel->author() );
380
379
    ec->setGenre( i18n( "Podcast" ) );
381
 
    ec->setYear( QString::number( m_pubDate.date().year() ) );
 
380
    ec->setYear( m_pubDate.date().year() );
382
381
    ec->endMetaDataUpdate();
383
382
 
384
383
    notifyObservers();
479
478
SqlPodcastChannel::SqlPodcastChannel( SqlPodcastProvider *provider,
480
479
                                            const QStringList &result )
481
480
    : Podcasts::PodcastChannel()
 
481
    , m_episodesLoaded( false )
482
482
    , m_provider( provider )
483
483
{
484
484
    SqlStorage *sqlStorage = CollectionManager::instance()->sqlStorage();
498
498
    m_purge = sqlStorage->boolTrue() == *(iter++);
499
499
    m_purgeCount = (*(iter++)).toInt();
500
500
    m_writeTags = sqlStorage->boolTrue() == *(iter++);
501
 
    loadEpisodes();
502
501
}
503
502
 
504
503
SqlPodcastChannel::SqlPodcastChannel( Podcasts::SqlPodcastProvider *provider,
524
523
    m_copyright = channel->copyright();
525
524
    
526
525
    if( channel->hasImage() )
527
 
        m_image = channel->image();
 
526
        m_image = channel->image().toImage();
528
527
 
529
528
    //Default Settings
530
529
 
545
544
 
546
545
        m_episodes << SqlPodcastEpisodePtr( sqlEpisode );
547
546
    }
 
547
    m_episodesLoaded = true;
 
548
}
 
549
 
 
550
int
 
551
SqlPodcastChannel::trackCount() const
 
552
{
 
553
    if( m_episodesLoaded )
 
554
        return m_episodes.count();
 
555
 
 
556
    QString query = "SELECT COUNT(id) FROM podcastepisodes WHERE channel = %1";
 
557
 
 
558
    SqlStorage *sql = CollectionManager::instance()->sqlStorage();
 
559
    Q_ASSERT( sql );
 
560
 
 
561
    QStringList results = sql->query( query.arg( m_dbId ) );
 
562
    if( results.isEmpty() )
 
563
    {
 
564
        error() << "no results for COUNT query on playlist_tracks table!";
 
565
        return -1;
 
566
    }
 
567
    int trackCount = results.first().toInt();
 
568
    return m_purge ? qMin( m_purgeCount, trackCount ): trackCount;
 
569
}
 
570
 
 
571
void
 
572
SqlPodcastChannel::triggerTrackLoad()
 
573
{
 
574
    if( !m_episodesLoaded )
 
575
        loadEpisodes();
548
576
}
549
577
 
550
578
Playlists::PlaylistProvider *
593
621
}
594
622
 
595
623
void
596
 
SqlPodcastChannel::setImage( const QPixmap &image )
 
624
SqlPodcastChannel::setImage( const QImage &image )
597
625
{
598
626
    DEBUG_BLOCK
599
627
 
609
637
 
610
638
    if( imageUrl.isLocalFile() )
611
639
    {
612
 
        m_image = QPixmap( imageUrl.path() );
 
640
        m_image = QImage( imageUrl.path() );
613
641
        return;
614
642
    }
615
643
 
629
657
    if( !episode->guid().isEmpty() && m_provider->possiblyContainsTrack( episode->guid() ) )
630
658
        return PodcastEpisodePtr::dynamicCast( m_provider->trackForUrl( episode->guid() ) );
631
659
 
 
660
    //force episodes load.
 
661
    if( !m_episodesLoaded )
 
662
        loadEpisodes();
 
663
 
632
664
    SqlPodcastEpisodePtr sqlEpisode = SqlPodcastEpisodePtr( new SqlPodcastEpisode( episode ) );
633
665
 
634
666
    //episodes are sorted on pubDate high to low
635
 
    SqlPodcastEpisodeList::iterator i;
636
 
    for( i = m_episodes.begin() ; i != m_episodes.end() ; ++i )
 
667
    int i;
 
668
    for( i = 0; i < m_episodes.count() ; i++ )
637
669
    {
638
 
        if( sqlEpisode->pubDate() > (*i)->pubDate() )
 
670
        if( sqlEpisode->pubDate() > m_episodes[i]->pubDate() )
639
671
        {
640
672
            m_episodes.insert( i, sqlEpisode );
641
673
            break;
643
675
    }
644
676
 
645
677
    //insert in case the list is empty or at the end of the list
646
 
    if( i == m_episodes.end() )
 
678
    if( i == m_episodes.count() )
647
679
        m_episodes << sqlEpisode;
648
680
 
649
 
    if( hasPurge() && m_episodes.count() > purgeCount() )
 
681
    notifyObserversTrackAdded( Meta::TrackPtr::dynamicCast( sqlEpisode ), i );
 
682
 
 
683
    applyPurge();
 
684
 
 
685
    return PodcastEpisodePtr::dynamicCast( sqlEpisode );
 
686
}
 
687
 
 
688
void
 
689
SqlPodcastChannel::applyPurge()
 
690
{
 
691
    if( !hasPurge() )
 
692
        return;
 
693
 
 
694
    while( m_episodes.count() > purgeCount() )
650
695
    {
651
 
        debug() << "removing last episode from the list since we are limited to " << purgeCount();
652
696
        SqlPodcastEpisodePtr removedEpisode = m_episodes.takeLast();
653
697
        m_provider->deleteDownloadedEpisode( removedEpisode );
654
698
 
655
 
        notifyObserversTrackRemoved( purgeCount() );
 
699
        notifyObserversTrackRemoved( m_episodes.count() );
656
700
    }
657
701
 
658
 
    return PodcastEpisodePtr::dynamicCast( sqlEpisode );
 
702
    //TODO: load missing episodes in case m_episodes.count() <= purgeCount()
659
703
}
660
704
 
661
705
void
743
787
    for(int i=0; i < results.size(); i+=rowLength)
744
788
    {
745
789
        QStringList episodesResult = results.mid( i, rowLength );
746
 
        SqlPodcastEpisode *episode = new SqlPodcastEpisode( episodesResult, SqlPodcastChannelPtr( this ) );
747
 
        m_episodes << SqlPodcastEpisodePtr( episode );
 
790
        SqlPodcastEpisodePtr sqlEpisode = SqlPodcastEpisodePtr(
 
791
                new SqlPodcastEpisode( episodesResult, SqlPodcastChannelPtr( this ) ) );
 
792
        m_episodes <<  sqlEpisode;
748
793
    }
 
794
 
 
795
    m_episodesLoaded = true;
749
796
}
750
797