File indexing completed on 2024-05-19 04:50:23
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "OpmlDirectoryInfoParser.h" 0018 0019 #include "core/support/Debug.h" 0020 #include "core/support/Components.h" 0021 #include "core/logger/Logger.h" 0022 #include "OpmlDirectoryMeta.h" 0023 0024 #include <QDomDocument> 0025 0026 #include <KLocalizedString> 0027 0028 using namespace Meta; 0029 0030 OpmlDirectoryInfoParser::OpmlDirectoryInfoParser() 0031 : InfoParserBase() 0032 , m_rssDownloadJob( nullptr ) 0033 { 0034 } 0035 0036 0037 OpmlDirectoryInfoParser::~OpmlDirectoryInfoParser() 0038 { 0039 } 0040 0041 void OpmlDirectoryInfoParser::getInfo(const ArtistPtr &artist) 0042 { 0043 AMAROK_NOTIMPLEMENTED 0044 Q_UNUSED( artist ); 0045 } 0046 0047 void OpmlDirectoryInfoParser::getInfo(const AlbumPtr &album) 0048 { 0049 AMAROK_NOTIMPLEMENTED 0050 Q_UNUSED( album ); 0051 } 0052 0053 void OpmlDirectoryInfoParser::getInfo(const TrackPtr &track ) 0054 { 0055 DEBUG_BLOCK 0056 showLoading( i18n( "Loading Podcast Info..." ) ); 0057 0058 OpmlDirectoryFeed * feed = dynamic_cast<OpmlDirectoryFeed *>( track.data() ); 0059 0060 if ( !feed ) return; 0061 0062 debug() << "OpmlDirectoryInfoParser: getInfo about feed: " << feed->uidUrl(); 0063 0064 m_rssDownloadJob = KIO::storedGet( QUrl( feed->uidUrl() ), KIO::Reload, KIO::HideProgressInfo ); 0065 Amarok::Logger::newProgressOperation( m_rssDownloadJob, 0066 i18n( "Fetching Podcast Info" ) ); 0067 connect( m_rssDownloadJob, &KJob::result, this, &OpmlDirectoryInfoParser::rssDownloadComplete ); 0068 } 0069 0070 void OpmlDirectoryInfoParser::rssDownloadComplete(KJob * downLoadJob) 0071 { 0072 0073 if ( downLoadJob->error() ) 0074 { 0075 //TODO: error handling here 0076 return ; 0077 } 0078 0079 if ( downLoadJob != m_rssDownloadJob ) 0080 return ; //not the right job, so let's ignore it 0081 0082 QString rssString = ((KIO::StoredTransferJob* ) downLoadJob)->data(); 0083 0084 debug() << "rss: " << rssString; 0085 0086 QDomDocument doc( "reply" ); 0087 if ( !doc.setContent( rssString ) ) 0088 { 0089 debug() << "could not set reply document to given RSS string"; 0090 return; 0091 } 0092 0093 //there might be an rss node, there might not... 0094 0095 QDomElement element = doc.firstChildElement( "rss" ); 0096 if ( !element.isNull() ) { 0097 element = element.firstChildElement( "channel" ); 0098 } else { 0099 element = doc.firstChildElement( "channel" ); 0100 } 0101 0102 QString description = element.firstChildElement( "description" ).text(); 0103 QString title = element.firstChildElement( "title" ).text(); 0104 0105 QString imageUrl; 0106 QDomElement image = element.firstChildElement( "image" ); 0107 0108 if ( !image.isNull() ) 0109 imageUrl = image.firstChildElement( "url" ).text(); 0110 0111 QString infoHtml = "<HTML><HEAD><META HTTP-EQUIV=\"Content-Type\" " 0112 "CONTENT=\"text/html; charset=iso-8859-1\"></HEAD><BODY>"; 0113 0114 infoHtml += "<div align=\"center\"><strong>"; 0115 infoHtml += title; 0116 infoHtml += "</strong><br><br>"; 0117 0118 if ( !imageUrl.isEmpty() ) 0119 infoHtml += "<img src=\"" + imageUrl + "\" align=\"middle\" border=\"1\">"; 0120 0121 infoHtml += "<br><p align=\"left\" >" + description; 0122 infoHtml += "</BODY></HTML>"; 0123 0124 Q_EMIT ( info( infoHtml ) ); 0125 0126 downLoadJob->deleteLater(); 0127 } 0128