KABC::Picture ImageLoader::loadPicture(const KURL &url, bool *ok) { KABC::Picture picture; QString tempFile; if(url.isEmpty()) return picture; (*ok) = false; QImage image; if(url.isLocalFile()) { image.load(url.path()); picture.setData(image); (*ok) = true; } else if(KIO::NetAccess::download(url, tempFile, mParent)) { image.load(tempFile); picture.setData(image); (*ok) = true; KIO::NetAccess::removeTempFile(tempFile); } if(!(*ok)) { // image does not exist (any more) KMessageBox::sorry(mParent, i18n("This contact's image cannot be found.")); return picture; } QPixmap pixmap = picture.data(); QPixmap selectedPixmap = KPIM::KPixmapRegionSelectorDialog::getSelectedImage(pixmap, 100, 140, mParent); if(selectedPixmap.isNull()) { (*ok) = false; return picture; } image = selectedPixmap; if(image.height() != 140 || image.width() != 100) { if(image.height() > image.width()) image = image.scaleHeight(140); else image = image.scaleWidth(100); } picture.setData(image); (*ok) = true; return picture; }
void PictureTest::storeTestInternImage() { KABC::Picture picture; picture.setData( testImage() ); QVERIFY( picture.isEmpty() == false ); QVERIFY( picture.isIntern() == true ); QVERIFY( picture.type() == QLatin1String( "jpeg" ) ); QVERIFY( picture.data() == testImage() ); QVERIFY( picture.rawData() == testImageRawJPEG() ); }