1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
Copyright (c) 2006 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>
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 <khtmlview.h>
#include <tqfile.h>
MagnatuneArtistInfoBox::MagnatuneArtistInfoBox( TQWidget *parentWidget, const char *widgetname )
: KHTMLPart( 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 = KIO::storedGet( url, false, false );
Amarok::StatusBar::instance() ->newProgressOperation( m_infoDownloadJob ).setDescription( i18n( "Fetching Artist Info" ) );
connect( m_infoDownloadJob, TQT_SIGNAL( result( KIO::Job* ) ), TQT_SLOT( infoDownloadComplete( KIO::Job* ) ) );
return true;
}
bool
MagnatuneArtistInfoBox::displayAlbumInfo( MagnatuneAlbum *album )
{
const MagnatuneArtist artist = MagnatuneDatabaseHandler::instance()->getArtistById( album->getArtistId() );
const TQString artistName = artist.getName();
TQString infoHtml = "<HTML><HEAD><META HTTP-EQUIV=\"Content-Type\" "
"CONTENT=\"text/html; charset=iso-8859-1\"></HEAD><BODY>";
infoHtml += "<div align=\"center\"><strong>";
infoHtml += artistName;
infoHtml += "</strong><br><em>";
infoHtml += album->getName();
infoHtml += "</em><br><br>";
infoHtml += "<img src=\"" + album->getCoverURL() +
"\" align=\"middle\" border=\"1\">";
infoHtml += "<br><br>Genre: " + album->getMp3Genre();
infoHtml += "<br>Release Year: " + TQString::number( album->getLaunchDate().year() );
infoHtml += "<br><br>From Magnatune.com</div>";
infoHtml += "</BODY></HTML>";
resetScrollBars();
begin();
write( infoHtml );
end();
show();
return true;
}
void
MagnatuneArtistInfoBox::infoDownloadComplete( KIO::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
KIO::StoredTransferJob* const storedJob = static_cast<KIO::StoredTransferJob*>( 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( "<!-- ARTISTBODY -->" );
int sectionEnd = artistPage.find( "<!-- /ARTISTBODY -->", sectionStart );
trimmedHtml = artistPage.mid( sectionStart, sectionEnd - sectionStart );
int buyStartIndex = trimmedHtml.find( "<!-- PURCHASE -->" );
int buyEndIndex;
//we are going to integrate the buying of music (I hope) so remove these links
while ( buyStartIndex != -1 )
{
buyEndIndex = trimmedHtml.find( "<!-- /PURCHASE -->", buyStartIndex ) + 18;
trimmedHtml.remove( buyStartIndex, buyEndIndex - buyStartIndex );
buyStartIndex = trimmedHtml.find( "<!-- PURCHASE -->", buyStartIndex );
}
TQString infoHtml = "<HTML><HEAD><META HTTP-EQUIV=\"Content-Type\" "
"CONTENT=\"text/html; charset=iso-8859-1\"></HEAD><BODY>";
infoHtml += trimmedHtml;
infoHtml += "</BODY></HTML>";
return infoHtml;
}
void MagnatuneArtistInfoBox::resetScrollBars( )
{
//note: the scrollbar methods never return 0
view()->horizontalScrollBar()->setValue(0);
view()->verticalScrollBar()->setValue(0);
}
#include "magnatuneartistinfobox.moc"
|