Commit fcb69ca3 authored by Matěj Laitl's avatar Matěj Laitl
Browse files

Podcasts: begin of cleanup and sanitization

...as they are another can of worms. This patch is best views with git
diff -b (ignore space change) option.
parent 08daea8e
......@@ -79,200 +79,194 @@ PlaylistBrowserNS::PodcastModel::PodcastModel()
connect( m_setNewAction, SIGNAL(triggered(bool)), SLOT(slotSetNew(bool)) );
}
PlaylistBrowserNS::PodcastModel::~PodcastModel()
{
}
bool
PlaylistBrowserNS::PodcastModel::isOnDisk( Podcasts::PodcastMetaCommon *pmc ) const
PlaylistBrowserNS::PodcastModel::isOnDisk( PodcastEpisodePtr episode ) const
{
bool isOnDisk = false;
if( pmc->podcastType() == Podcasts::EpisodeType )
{
Podcasts::PodcastEpisode *episode = static_cast<Podcasts::PodcastEpisode *>( pmc );
KUrl episodeFile( episode->localUrl() );
KUrl episodeFile( episode->localUrl() );
if( !episodeFile.isEmpty() )
{
isOnDisk = QFileInfo( episodeFile.toLocalFile() ).exists();
//reset localUrl because the file is not there.
if( !isOnDisk )
episode->setLocalUrl( KUrl() );
}
if( !episodeFile.isEmpty() )
{
isOnDisk = QFileInfo( episodeFile.toLocalFile() ).exists();
// reset localUrl because the file is not there.
// FIXME: changing a podcast in innoncent-looking getter method is convoluted
if( !isOnDisk )
episode->setLocalUrl( KUrl() );
}
return isOnDisk;
}
QVariant
PlaylistBrowserNS::PodcastModel::icon( Podcasts::PodcastMetaCommon *pmc ) const
PlaylistBrowserNS::PodcastModel::icon( const PodcastChannelPtr &channel ) const
{
Podcasts::PodcastChannel *channel = 0;
Podcasts::PodcastEpisode *episode = 0;
QStringList emblems;
// I hope we are caching this icon somehow and not creating it every time new (Ralf)
switch( pmc->podcastType() )
//TODO: only check visible episodes. For now those are all returned by episodes().
foreach( const Podcasts::PodcastEpisodePtr ep, channel->episodes() )
{
case Podcasts::ChannelType:
channel = static_cast<Podcasts::PodcastChannel *>( pmc );
//TODO: only check visible episodes. For now those are all returned by episodes().
foreach( const Podcasts::PodcastEpisodePtr ep, channel->episodes() )
{
if( ep->isNew() )
{
emblems << "rating";
break;
}
}
if( channel->hasImage() )
{
QSize size( channel->image().size() );
QPixmap pixmap( 32, 32 );
pixmap.fill( Qt::transparent );
size.scale( 32, 32, Qt::KeepAspectRatio );
int x = 32 / 2 - size.width() / 2;
int y = 32 / 2 - size.height() / 2;
QPainter p( &pixmap );
p.drawPixmap( x, y,
QPixmap::fromImage( channel->image().scaled( size,
Qt::KeepAspectRatio,
Qt::SmoothTransformation ) ) );
if( ep->isNew() )
{
emblems << "rating";
break;
}
}
// if it's a new episode draw the overlay:
if( !emblems.isEmpty() )
{
// draw the overlay the same way KIconLoader does:
p.drawPixmap( 2, 32 - 16 - 2, KIcon( "rating" ).pixmap( 16, 16 ) );
}
if( channel->hasImage() )
{
QSize size( channel->image().size() );
QPixmap pixmap( 32, 32 );
pixmap.fill( Qt::transparent );
p.end();
size.scale( 32, 32, Qt::KeepAspectRatio );
return pixmap;
}
else
{
return KIcon( "podcast-amarok", 0, emblems ).pixmap( 32, 32 );
}
int x = 32 / 2 - size.width() / 2;
int y = 32 / 2 - size.height() / 2;
case Podcasts::EpisodeType:
episode = static_cast<Podcasts::PodcastEpisode *>( pmc );
QPainter p( &pixmap );
p.drawPixmap( x, y, QPixmap::fromImage( channel->image().scaled( size,
Qt::KeepAspectRatio, Qt::SmoothTransformation ) ) );
if( isOnDisk( pmc ) )
emblems << "go-down";
// if it's a new episode draw the overlay:
if( !emblems.isEmpty() )
// draw the overlay the same way KIconLoader does:
p.drawPixmap( 2, 32 - 16 - 2, KIcon( "rating" ).pixmap( 16, 16 ) );
p.end();
if( episode->isNew() )
return KIcon( "rating", 0, emblems ).pixmap( 24, 24 );
else
return KIcon( "podcast-amarok", 0, emblems ).pixmap( 24, 24 );
return pixmap;
}
else
return KIcon( "podcast-amarok", 0, emblems ).pixmap( 32, 32 );
}
return QVariant();
QVariant
PlaylistBrowserNS::PodcastModel::icon( const PodcastEpisodePtr &episode ) const
{
QStringList emblems;
if( isOnDisk( episode ) )
emblems << "go-down";
if( episode->isNew() )
return KIcon( "rating", 0, emblems ).pixmap( 24, 24 );
else
return KIcon( "podcast-amarok", 0, emblems ).pixmap( 24, 24 );
}
QVariant
PlaylistBrowserNS::PodcastModel::data( const QModelIndex &idx, int role ) const
{
if( idx.isValid() )
{
Podcasts::PodcastMetaCommon *pmc;
if( IS_TRACK(idx) )
pmc = dynamic_cast<Podcasts::PodcastMetaCommon *>( trackFromIndex( idx ).data() );
else
//HACK: get rid of getPlaylist()
pmc = dynamic_cast<Podcasts::PodcastMetaCommon *>( playlistFromIndex( idx ).data() );
if( !idx.isValid() )
return PlaylistBrowserModel::data( idx, role );
if( !pmc )
return QVariant();
if( IS_TRACK(idx) )
return episodeData( episodeForIndex( idx ), idx, role );
else
return channelData( channelForIndex( idx ), idx, role );
}
switch( role )
{
case Qt::DisplayRole:
case Qt::ToolTipRole:
QVariant
PlaylistBrowserNS::PodcastModel::channelData( const PodcastChannelPtr &channel,
const QModelIndex &idx, int role ) const
{
if( !channel )
return QVariant();
switch( role )
{
case Qt::DisplayRole:
case Qt::ToolTipRole:
switch( idx.column() )
{
switch( idx.column() )
case PlaylistBrowserModel::PlaylistItemColumn:
return channel->title();
case SubtitleColumn:
return channel->subtitle();
case AuthorColumn:
return channel->author();
case KeywordsColumn:
return channel->keywords();
case ImageColumn:
{
case PlaylistBrowserModel::PlaylistItemColumn:
return pmc->title();
case SubtitleColumn:
return pmc->subtitle();
case AuthorColumn:
return pmc->author();
case KeywordsColumn:
return pmc->keywords();
case FilesizeColumn:
if( pmc->podcastType() == Podcasts::EpisodeType )
return static_cast<Podcasts::PodcastEpisode *>( pmc )
->filesize();
break;
case ImageColumn:
if( pmc->podcastType() == Podcasts::ChannelType )
{
Podcasts::PodcastChannel *pc =
static_cast<Podcasts::PodcastChannel *>( pmc );
KUrl imageUrl( PodcastImageFetcher::cachedImagePath( pc ) );
if( !QFile( imageUrl.toLocalFile() ).exists() )
{
imageUrl = pc->imageUrl();
}
return imageUrl;
}
break;
case DateColumn:
if( pmc->podcastType() == Podcasts::EpisodeType )
return static_cast<Podcasts::PodcastEpisode *>( pmc )
->pubDate();
else
return static_cast<Podcasts::PodcastChannel *>( pmc )
->subscribeDate();
case IsEpisodeColumn:
return bool( pmc->podcastType() == Podcasts::EpisodeType );
KUrl imageUrl( PodcastImageFetcher::cachedImagePath( channel ) );
if( !QFile( imageUrl.toLocalFile() ).exists() )
imageUrl = channel->imageUrl();
return imageUrl;
}
break;
case DateColumn:
channel->subscribeDate();
case IsEpisodeColumn:
return false;
}
case PrettyTreeRoles::ByLineRole:
break;
case PrettyTreeRoles::ByLineRole:
if( idx.column() == PlaylistBrowserModel::ProviderColumn )
{
if( idx.column() == PlaylistBrowserModel::ProviderColumn )
{
Playlists::PlaylistProvider *provider = providerForIndex( idx );
if( provider )
return i18ncp( "number of podcasts from one source",
"One Channel", "%1 channels",
provider->playlists().count() );
}
if( idx.column() == PlaylistBrowserModel::PlaylistItemColumn )
return pmc->description();
break;
Playlists::PlaylistProvider *provider = providerForIndex( idx );
if( provider )
return i18ncp( "number of podcasts from one source",
"One Channel", "%1 channels",
provider->playlists().count() );
}
if( idx.column() == PlaylistBrowserModel::PlaylistItemColumn )
return channel->description();
break;
case PrettyTreeRoles::HasCoverRole:
return idx.column() == PlaylistBrowserModel::PlaylistItemColumn;
case Qt::DecorationRole:
if( idx.column() == PlaylistBrowserModel::PlaylistItemColumn )
return icon( channel );
break;
}
return PlaylistBrowserModel::data( idx, role );
}
case PrettyTreeRoles::HasCoverRole:
return ( idx.column() == PlaylistBrowserModel::PlaylistItemColumn );
QVariant
PlaylistBrowserNS::PodcastModel::episodeData( const PodcastEpisodePtr &episode,
const QModelIndex &idx, int role ) const
{
if( !episode )
return QVariant();
case Qt::DecorationRole:
switch( role )
{
case Qt::DisplayRole:
case Qt::ToolTipRole:
switch( idx.column() )
{
if( idx.column() == PlaylistBrowserModel::PlaylistItemColumn )
return icon( pmc );
break;
case PlaylistBrowserModel::PlaylistItemColumn:
return episode->title();
case SubtitleColumn:
return episode->subtitle();
case AuthorColumn:
return episode->author();
case KeywordsColumn:
return episode->keywords();
case FilesizeColumn:
return episode->filesize();
case DateColumn:
return episode->pubDate();
case IsEpisodeColumn:
return true;
}
case PrettyTreeRoles::DecoratorRole:
case PrettyTreeRoles::DecoratorRoleCount:
return PlaylistBrowserModel::data( idx, role );
}
break;
case PrettyTreeRoles::ByLineRole:
if( idx.column() == PlaylistBrowserModel::ProviderColumn )
{
Playlists::PlaylistProvider *provider = providerForIndex( idx );
if( provider )
return i18ncp( "number of podcasts from one source",
"One Channel", "%1 channels",
provider->playlists().count() );
}
if( idx.column() == PlaylistBrowserModel::PlaylistItemColumn )
return episode->description();
break;
case PrettyTreeRoles::HasCoverRole:
return ( idx.column() == PlaylistBrowserModel::PlaylistItemColumn );
case Qt::DecorationRole:
if( idx.column() == PlaylistBrowserModel::PlaylistItemColumn )
return icon( episode );
break;
}
return PlaylistBrowserModel::data( idx, role );
......@@ -294,31 +288,6 @@ PlaylistBrowserNS::PodcastModel::columnCount( const QModelIndex &parent ) const
return ColumnCount;
}
//Qt::ItemFlags
//PlaylistBrowserNS::PodcastModel::flags( const QModelIndex &idx ) const
//{
// if( idx.row() == -1 )
// {
// switch( idx.column() )
// {
// case ProviderColumn:
// return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
// default: break;
// }
// }
//
// Qt::ItemFlags channelFlags;
// if( podcastItemType( idx ) == Podcasts::ChannelType )
// {
// channelFlags = Qt::ItemIsDropEnabled;
// if( idx.column() == ProviderColumn )
// channelFlags |= Qt::ItemIsEditable;
// }
//
// return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled
// | channelFlags );
//}
QVariant
PlaylistBrowserNS::PodcastModel::headerData( int section, Qt::Orientation orientation,
int role) const
......@@ -440,18 +409,6 @@ PlaylistBrowserNS::PodcastModel::slotSetNew( bool newState )
}
}
int
PlaylistBrowserNS::PodcastModel::podcastItemType( const QModelIndex &idx ) const
{
if( !idx.isValid() )
return NoType;
if( IS_TRACK(idx) )
return EpisodeType;
else
return ChannelType;
}
Podcasts::PodcastChannelPtr
PlaylistBrowserNS::PodcastModel::channelForIndex( const QModelIndex &idx ) const
{
......@@ -472,5 +429,3 @@ PlaylistBrowserNS::PodcastModel::podcastEpisodesToTracks( Podcasts::PodcastEpiso
tracks << Meta::TrackPtr::staticCast( episode );
return tracks;
}
#include "PodcastModel.moc"
......@@ -45,8 +45,8 @@ enum
};
/**
@author Bart Cerneels
*/
* @author Bart Cerneels
*/
class PodcastModel : public PlaylistBrowserModel
{
Q_OBJECT
......@@ -58,7 +58,6 @@ class PodcastModel : public PlaylistBrowserModel
virtual QVariant data(const QModelIndex &index, int role) const;
virtual bool setData( const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole );
// virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
......@@ -87,9 +86,11 @@ class PodcastModel : public PlaylistBrowserModel
private:
static PodcastModel* s_instance;
PodcastModel();
~PodcastModel();
int podcastItemType( const QModelIndex &idx ) const;
QVariant channelData( const Podcasts::PodcastChannelPtr &channel,
const QModelIndex &idx, int role ) const;
QVariant episodeData( const Podcasts::PodcastEpisodePtr &episode,
const QModelIndex &idx, int role ) const;
Podcasts::PodcastChannelPtr channelForIndex( const QModelIndex &index ) const;
Podcasts::PodcastEpisodePtr episodeForIndex( const QModelIndex &index ) const;
......@@ -98,19 +99,14 @@ class PodcastModel : public PlaylistBrowserModel
QAction *m_setNewAction;
/** A convenience function to convert a PodcastEpisodeList into a TrackList.
**/
static Meta::TrackList
podcastEpisodesToTracks(
Podcasts::PodcastEpisodeList episodes );
/**
* A convenience function to convert a PodcastEpisodeList into a TrackList.
*/
static Meta::TrackList podcastEpisodesToTracks( Podcasts::PodcastEpisodeList episodes );
//TODO: get rid of these 2 functions used as a HACK to get to master data.
//Use correct accessors in SyncedPodcast instead.
Playlists::PlaylistPtr getPlaylist( Playlists::PlaylistPtr playlist ) const;
Playlists::Playlist* getPlaylist( Playlists::Playlist* playlist ) const;
bool isOnDisk( Podcasts::PodcastMetaCommon *pmc ) const;
QVariant icon( Podcasts::PodcastMetaCommon *pmc ) const;
bool isOnDisk( Podcasts::PodcastEpisodePtr episode ) const;
QVariant icon( const Podcasts::PodcastChannelPtr &channel ) const;
QVariant icon( const Podcasts::PodcastEpisodePtr &episode ) const;
};
}
......
......@@ -97,7 +97,7 @@ class UmsPodcastChannel : public Podcasts::PodcastChannel
void setPlaylistFileSource( const KUrl &playlistFilePath );
KUrl playlistFilePath() const { return m_playlistFilePath; }
virtual Podcasts::PodcastEpisodeList episodes()
virtual Podcasts::PodcastEpisodeList episodes() const
{ return UmsPodcastEpisode::toPodcastEpisodeList( m_umsEpisodes ); }
virtual Playlists::PlaylistProvider *provider() const;
......
......@@ -685,7 +685,7 @@ SqlPodcastChannel::setTitle( const QString &title )
}
Podcasts::PodcastEpisodeList
SqlPodcastChannel::episodes()
SqlPodcastChannel::episodes() const
{
return SqlPodcastEpisode::toPodcastEpisodeList( m_episodes );
}
......
......@@ -126,7 +126,7 @@ class SqlPodcastChannel : public Podcasts::PodcastChannel
//Podcasts::PodcastChannel methods
virtual KUrl uidUrl() const;
virtual void setTitle( const QString &title );
virtual Podcasts::PodcastEpisodeList episodes();
virtual Podcasts::PodcastEpisodeList episodes() const;
virtual bool hasImage() const { return !m_image.isNull(); }
virtual void setImage( const QImage &image );
virtual QImage image() const { return m_image; }
......
......@@ -33,8 +33,6 @@
namespace Podcasts
{
class PodcastMetaCommon;
class PodcastEpisode;
class PodcastChannel;
......@@ -44,21 +42,12 @@ class PodcastComposer;
class PodcastGenre;
class PodcastYear;
// typedef KSharedPtr<PodcastMetaCommon> PodcastMetaCommonPtr;
typedef KSharedPtr<PodcastEpisode> PodcastEpisodePtr;
typedef KSharedPtr<PodcastChannel> PodcastChannelPtr;
// typedef QList<PodcastMetaCommon> PodcastMetaCommonList;
typedef QList<PodcastEpisodePtr> PodcastEpisodeList;
typedef QList<PodcastChannelPtr> PodcastChannelList;
enum PodcastType
{
NoType = 0,
ChannelType,
EpisodeType
};
class AMAROK_CORE_EXPORT PodcastMetaCommon
{
public:
......@@ -71,7 +60,6 @@ class AMAROK_CORE_EXPORT PodcastMetaCommon
virtual QString subtitle() const { return m_subtitle; }
virtual QString summary() const { return m_summary; }
virtual QString author() const { return m_author; }
virtual int podcastType() const = 0; //{ return NoType; }
virtual void setTitle( const QString &title ) { m_title = title; }
virtual void setDescription( const QString &description ) { m_description = description; }
......@@ -142,8 +130,6 @@ class AMAROK_CORE_EXPORT PodcastEpisode : public PodcastMetaCommon, public Meta:
virtual bool operator==( const Meta::Track &track ) const;
//PodcastMetaCommon methods
virtual int podcastType() const { return EpisodeType; }
virtual void setTitle( const QString &title ) { m_title = title; }
//PodcastEpisode methods
......@@ -221,8 +207,7 @@ class AMAROK_CORE_EXPORT PodcastChannel : public PodcastMetaCommon, public Playl
virtual void addTrack( Meta::TrackPtr track, int position = -1 );
//PodcastMetaCommon methods
virtual int podcastType() const { return ChannelType; }
//override this since it's ambigous in PodcastMetaCommon and Playlist
// override this since it's ambigous in PodcastMetaCommon and Playlist
virtual QString description() const { return m_description; }
//PodcastChannel methods
......@@ -246,7 +231,7 @@ class AMAROK_CORE_EXPORT PodcastChannel : public PodcastMetaCommon, public Playl
virtual void setSubscribeDate( const QDate &date ) { m_subscribeDate = date; }
virtual Podcasts::PodcastEpisodePtr addEpisode( PodcastEpisodePtr episode );
virtual PodcastEpisodeList episodes() { return m_episodes; }
virtual PodcastEpisodeList episodes() const { return m_episodes; }
bool load( QTextStream &stream ) { Q_UNUSED( stream ); return false; }
......
......@@ -36,7 +36,6 @@ class SyncedPodcast : public SyncedPlaylist, public Podcasts::PodcastChannel
virtual QString subtitle() const { return m_master->subtitle(); }
virtual QString summary() const { return m_master->summary(); }
virtual QString author() const { return m_master->author(); }
virtual int podcastType() const { return m_master->podcastType(); }
//Podcasts::PodcastChannel methods
virtual KUrl url() const { return m_master->url(); }
......@@ -61,7 +60,7 @@ class SyncedPodcast : public SyncedPlaylist, public Podcasts::PodcastChannel
{
return m_master->addEpisode( episode );
}
virtual Podcasts::PodcastEpisodeList episodes() { return m_master->episodes(); }
virtual Podcasts::PodcastEpisodeList episodes() const { return m_master->episodes(); }
bool load( QTextStream &stream ) { return m_master->load( stream ); }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment