Commit 1d6d2e9f authored by Scott Wheeler's avatar Scott Wheeler

Quite a few issues here:

*) Now getting a bit closer to properly quoting query items

*) Proper capitalization in string

*) Don't initialize new QPixmaps explicitly (it's silly, that's their value anyway)

*) TRUE and FALSE are evil C-isms.  true and false are our friends.

*) Fix a memory leak large enough to drive a truck (Texas sized, even) through
   - a) Qt gives us a nice QByteArray, we don't need to roll our own
   - b) char *foo = new char[someSize] isn't deleted with deleted with delete foo
        but rather delete [] foo
   - c) This is the 4th memory leak that I've fixed in this code; be a bit more
        carefule with new.

*) Pass the parent pointer into the QObject constructor

*) Style stuff

CCMAIL:Nathan Toone <nathan@toonetown.com>

svn path=/trunk/kdemultimedia/juk/; revision=362341
parent 9850d582
......@@ -33,7 +33,7 @@ GoogleImage::GoogleImage(QString thumbURL, QString size) :
// images?q=tbn:hKSEWNB8aNcJ:www.styxnet.com/deyoung/styx/stygians/cp_portrait.jpg
m_imageURL = "http://" + thumbURL.remove(QRegExp("^.*q=tbn:[^:]*:"));
m_size = size.replace("pixels - ", "\n(")+")";
m_size = size.replace("pixels - ", "\n(") + ")";
}
......@@ -51,8 +51,9 @@ void GoogleFetcher::loadImageURLs()
m_imageList.clear();
KURL url = "http://images.google.com/images?q=" +
KURL::encode_string_no_slash(m_searchString);
KURL url("http://images.google.com/images");
url.addQueryItem("q", m_searchString);
m_loadedQuery = m_searchString;
DOM::HTMLDocument search;
......
......@@ -83,15 +83,19 @@ int GoogleFetcherDialog::exec()
void GoogleFetcherDialog::slotOk()
{
uint selectedIndex=m_iconWidget->index(m_iconWidget->currentItem());
m_pixmap=pixmapFromURL(m_imageList[selectedIndex].imageURL());
if (m_pixmap.isNull()) {
KMessageBox::sorry(this, i18n("The cover you have selected is unavailable. Please select another."), i18n("Cover unavailable"));
QPixmap blankPix=QPixmap();
blankPix.resize(80,80);
m_pixmap = pixmapFromURL(m_imageList[selectedIndex].imageURL());
if(m_pixmap.isNull()) {
KMessageBox::sorry(this,
i18n("The cover you have selected is unavailable. Please select another."),
i18n("Cover Unavailable"));
QPixmap blankPix;
blankPix.resize(80, 80);
blankPix.fill();
m_iconWidget->currentItem()->setPixmap(blankPix, TRUE, TRUE);
m_iconWidget->currentItem()->setPixmap(blankPix, true, true);
return;
}
m_takeIt = true;
m_newSearch = false;
hide();
......@@ -136,39 +140,36 @@ QPixmap GoogleFetcherDialog::pixmapFromURL(const KURL &url) const
// CoverIconViewItem
////////////////////////////////////////////////////////////////////////////////
CoverIconViewItem::CoverIconViewItem(QIconView *parent, GoogleImage image) :
QObject(),m_buffer(0),m_bufferIndex(0)
CoverIconViewItem::CoverIconViewItem(QIconView *parent, const GoogleImage &image) :
QObject(parent)
{
//Set up the iconViewItem
// Set up the iconViewItem
m_iconViewItem=new KIconViewItem(parent, parent->lastItem(), image.size());
QPixmap mainMap=QPixmap();
mainMap.resize(80,80);
m_iconViewItem = new KIconViewItem(parent, parent->lastItem(), image.size());
QPixmap mainMap;
mainMap.resize(80, 80);
mainMap.fill();
m_iconViewItem->setPixmap(mainMap, TRUE, TRUE);
m_iconViewItem->setPixmap(mainMap, true, true);
//Start downloading the image.
// Start downloading the image.
m_buffer = new uchar[BUFFER_SIZE];
KIO::TransferJob* job = KIO::get(image.thumbURL(), false, false);
connect(job, SIGNAL(result(KIO::Job*)), this, SLOT(imageResult(KIO::Job*)));
connect(job, SIGNAL(data(KIO::Job*, const QByteArray&)), this, SLOT(imageData(KIO::Job*, const QByteArray&)));
KIO::TransferJob *job = KIO::get(image.thumbURL(), false, false);
connect(job, SIGNAL(result(KIO::Job *)), this, SLOT(imageResult(KIO::Job *)));
connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)),
this, SLOT(imageData(KIO::Job *, const QByteArray &)));
}
CoverIconViewItem::~CoverIconViewItem()
{
delete m_buffer;
}
void CoverIconViewItem::imageData(KIO::Job *, const QByteArray &data)
{
if(m_bufferIndex + (uint) data.size() >= BUFFER_SIZE)
return;
memcpy(m_buffer + m_bufferIndex, data.data(), data.size());
m_bufferIndex += data.size();
int currentSize = m_buffer.size();
m_buffer.resize(currentSize + data.size(), QGArray::SpeedOptim);
memcpy(&(m_buffer.data()[currentSize]), data.data(), data.size());
}
void CoverIconViewItem::imageResult(KIO::Job *job)
......@@ -176,10 +177,9 @@ void CoverIconViewItem::imageResult(KIO::Job *job)
if(job->error())
return;
QPixmap iconImage=QPixmap();
iconImage.loadFromData(m_buffer, m_bufferIndex);
iconImage=QImage(iconImage.convertToImage()).smoothScale(80,80);
m_iconViewItem->setPixmap(iconImage, TRUE, TRUE);
QPixmap iconImage(m_buffer);
iconImage = QImage(iconImage.convertToImage()).smoothScale(80, 80);
m_iconViewItem->setPixmap(iconImage, true, true);
}
#include "googlefetcherdialog.moc"
......@@ -71,20 +71,17 @@ class CoverIconViewItem : public QObject
{
Q_OBJECT
public:
CoverIconViewItem(QIconView *parent, GoogleImage image);
~CoverIconViewItem();
private slots:
void imageData(KIO::Job* job, const QByteArray& data);
void imageResult(KIO::Job* job);
public:
CoverIconViewItem(QIconView *parent, const GoogleImage &image);
~CoverIconViewItem();
private:
static const uint BUFFER_SIZE = 2000000;
private slots:
void imageData(KIO::Job *job, const QByteArray &data);
void imageResult(KIO::Job* job);
KIconViewItem *m_iconViewItem;
uchar* m_buffer;
uint m_bufferIndex;
private:
QByteArray m_buffer;
KIconViewItem *m_iconViewItem;
};
#endif
Markdown is supported
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