Exemple #1
0
QString ContactsModel::getAvatar(KABC::Addressee contact) const
{
    KABC::Picture pic = contact.photo();
    qDebug() << "Picture url: " << pic.url();

    if (pic.isIntern()) {
        QString url = "contacts/"+contact.uid();
        ImageProvider::getInstance()->registerImage(url, pic.data());
        return "image://images/"+url;
    } else
        return pic.url();
}
Exemple #2
0
void PictureTest::storeTestExtern()
{
  KABC::Picture picture;

  picture.setUrl( QLatin1String( "http://myhomepage.com/foto.png" ), QLatin1String( "png" ) );

  QVERIFY( picture.isEmpty() == false );
  QVERIFY( picture.isIntern() == false );
  QVERIFY( picture.type() == QLatin1String( "png" ) );
  QVERIFY( picture.url() == QLatin1String( "http://myhomepage.com/foto.png" ) );
}
Exemple #3
0
std::string fromPicture(const KABC::Picture &pic, std::string &mimetype)
{    
    QByteArray input;
    QBuffer buffer( &input );
    buffer.open( QIODevice::WriteOnly );
    QImage img;
        
    
    if ( pic.isIntern() ) {
        if ( !pic.data().isNull() ) {
            img = pic.data();
        }
    } else if ( !pic.url().isEmpty() ) {
        QString tmpFile;
        kWarning() << "external pictures are currently not supported";
        //FIXME add kio support to libcalendaring or use libcurl
//         if ( KIO::NetAccess::download( pic.url(), tmpFile, 0 /*no widget known*/ ) ) {
//             img.load( tmpFile );
//             KIO::NetAccess::removeTempFile( tmpFile );
//         }
    }
    if (img.isNull()) {
        Error() << "invalid picture";
        return std::string();
    }
    if ( !img.hasAlphaChannel() ) {
        if (!img.save( &buffer, "JPEG" )) {
            Error() << "error on jpeg save";
            return std::string();
        }
        mimetype = "image/jpeg";
    } else {
        if (!img.save( &buffer, "PNG" )) {
            Error() << "error on png save";
            return std::string();
        }
        mimetype = "image/png";
    }
    return std::string(input.data(), input.size());
}