/* Copyright (c) 2006 Nikolaj Hald Nielsen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "debug.h" #include "magnatuneartistinfobox.h" #include "magnatunedatabasehandler.h" #include #include MagnatuneArtistInfoBox::MagnatuneArtistInfoBox( TQWidget *parentWidget, const char *widgetname ) : TDEHTMLPart( parentWidget, widgetname ) {} MagnatuneArtistInfoBox::~MagnatuneArtistInfoBox() {} bool MagnatuneArtistInfoBox::displayArtistInfo( KURL url ) { debug() << "displayArtistInfo started" << endl; // first get the entire artist html page TQString tempFile; TQString orgHtml; m_infoDownloadJob = TDEIO::storedGet( url, false, false ); Amarok::StatusBar::instance() ->newProgressOperation( m_infoDownloadJob ).setDescription( i18n( "Fetching Artist Info" ) ); connect( m_infoDownloadJob, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( infoDownloadComplete( TDEIO::Job* ) ) ); return true; } bool MagnatuneArtistInfoBox::displayAlbumInfo( MagnatuneAlbum *album ) { const MagnatuneArtist artist = MagnatuneDatabaseHandler::instance()->getArtistById( album->getArtistId() ); const TQString artistName = artist.getName(); TQString infoHtml = ""; infoHtml += "
"; infoHtml += artistName; infoHtml += "
"; infoHtml += album->getName(); infoHtml += "

"; infoHtml += "getCoverURL() + "\" align=\"middle\" border=\"1\">"; infoHtml += "

Genre: " + album->getMp3Genre(); infoHtml += "
Release Year: " + TQString::number( album->getLaunchDate().year() ); infoHtml += "

From Magnatune.com
"; infoHtml += ""; resetScrollBars(); begin(); write( infoHtml ); end(); show(); return true; } void MagnatuneArtistInfoBox::infoDownloadComplete( TDEIO::Job * downLoadJob ) { if ( !downLoadJob->error() == 0 ) { //TODO: error handling here return ; } if ( downLoadJob != m_infoDownloadJob ) return ; //not the right job, so let's ignore it TDEIO::StoredTransferJob* const storedJob = static_cast( downLoadJob ); TQString info = TQString( storedJob->data() ); TQString trimmedInfo = extractArtistInfo( info ); //debug() << "html: " << trimmedInfo << endl; resetScrollBars(); this->begin(); this->write( trimmedInfo ); this->end(); this->show(); } TQString MagnatuneArtistInfoBox::extractArtistInfo( TQString artistPage ) { TQString trimmedHtml; int sectionStart = artistPage.find( "" ); int sectionEnd = artistPage.find( "", sectionStart ); trimmedHtml = artistPage.mid( sectionStart, sectionEnd - sectionStart ); int buyStartIndex = trimmedHtml.find( "" ); int buyEndIndex; //we are going to integrate the buying of music (I hope) so remove these links while ( buyStartIndex != -1 ) { buyEndIndex = trimmedHtml.find( "", buyStartIndex ) + 18; trimmedHtml.remove( buyStartIndex, buyEndIndex - buyStartIndex ); buyStartIndex = trimmedHtml.find( "", buyStartIndex ); } TQString infoHtml = ""; infoHtml += trimmedHtml; infoHtml += ""; return infoHtml; } void MagnatuneArtistInfoBox::resetScrollBars( ) { //note: the scrollbar methods never return 0 view()->horizontalScrollBar()->setValue(0); view()->verticalScrollBar()->setValue(0); } #include "magnatuneartistinfobox.moc"