/** * App::onImageLoaded(QString url, bool success, QString response) * * Handle the result of a loading image request. * * Basing on the result, we will update UI accordingly. * * --url, the url of the previous url * --success, the flag to indicate if the request was successful. * --response, this will carry some error information if the operation was not successful. * */ void App::onImageLoaded(QString url, bool success, QString response) { //get the LoadImage object LoadImage* img = qobject_cast<LoadImage*>(sender()); if (!img) { return; } connect(this, SIGNAL(finishUpdateImage()), img, SIGNAL(finishThread())); qDebug() << "Download complete: " << url; //find the url to photo index mapping QMap<QString, int>::iterator it = m_imageMap.find(url); if (it != m_imageMap.end()) { //stop indicator ActivityIndicator* activityId = m_root->findChild<ActivityIndicator*>(QString("image%1Indicator").arg(it.value())); if (activityId) { activityId->stop(); activityId->setVisible(false); } if (success) { //show the image ImageView* imageView = m_root->findChild<ImageView*>(QString("image%1").arg(it.value())); if (imageView) { QImage qm = img->getImage().rgbSwapped().scaled(768, 500, Qt::KeepAspectRatioByExpanding); //resize image to fit container bb::cascades::PixelBufferData pb = bb::cascades::PixelBufferData(PixelBufferData::RGBX, qm.width(), qm.height(), qm.width(), qm.bits()); bb::cascades::Image image(pb); imageView->setImage(image); imageView->setVisible(true); } } else { //show the label with the error from the retrieval Label* imageLabel = m_root->findChild<Label*>(QString("image%1Label").arg(it.value())); if (imageLabel) { imageLabel->setText(response); imageLabel->setVisible(true); } } m_imageMap.erase(it); } emit finishUpdateImage(); // no need to explicitly delete img, it has been destroyed when receiving the "finishThread" signal }