예제 #1
0
    void refresh()
    {
        mAddressee = mDocument->findByUid(mAddressee.uid());

        if(!mAddressee.isEmpty())
            setText(mAddressee.givenName() + " " + mAddressee.familyName());

        QPixmap icon;
        QPixmap defaultIcon(KGlobal::iconLoader()->loadIcon("vcard", KIcon::Desktop));
        KABC::Picture pic = mAddressee.photo();
        if(pic.data().isNull())
            pic = mAddressee.logo();

        if(pic.isIntern() && !pic.data().isNull())
        {
            QImage img = pic.data();
            if(img.width() > img.height())
                icon = img.scaleWidth(32);
            else
                icon = img.scaleHeight(32);
        }
        else
            icon = defaultIcon;

        setPixmap(icon);
    }
예제 #2
0
AddresseeItem::AddresseeItem( QTreeWidget *parent, const KABC::Addressee &addressee) :
QTreeWidgetItem( parent ),
mAddressee( addressee )
{
    //We can't save showphoto because we don't have a d pointer
    KABC::Picture pic = mAddressee.photo();
    if(!pic.isIntern())
        pic = mAddressee.logo();
    if(pic.isIntern())
    {
                                                  //60 pixels seems okay.. kmail uses 60 btw
        QIcon icon( QPixmap::fromImage( pic.data().scaledToWidth(60) ) );
        setIcon( Photo, icon );
    }

    setText( Name, addressee.realName() );
    setText( Email, addressee.preferredEmail() );
}
예제 #3
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" ) );
}
예제 #4
0
void PictureTest::storeTestInternRawData()
{
  KABC::Picture picture;

  picture.setRawData( testImageRawPNG(), QLatin1String( "png" ) );

  QVERIFY( picture.isEmpty() == false );
  QVERIFY( picture.isIntern() == true );
  QVERIFY( picture.type() == QLatin1String( "png" ) );
  QVERIFY( picture.rawData() == testImageRawPNG() );
  QVERIFY( picture.data() == testImage() );
}
예제 #5
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();
}
예제 #6
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());
}
QVariant ContactsTreeModel::entityData( const Item &item, int column, int role ) const
{
  if ( item.mimeType() == KABC::Addressee::mimeType() ) {
    if ( !item.hasPayload<KABC::Addressee>() ) {

      // Pass modeltest
      if ( role == Qt::DisplayRole )
        return item.remoteId();

      return QVariant();
    }

    const KABC::Addressee contact = item.payload<KABC::Addressee>();

    if ( role == Qt::DecorationRole ) {
      if ( column == 0 ) {
        const KABC::Picture picture = contact.photo();
        if ( picture.isIntern() ) {
          return picture.data().scaled( QSize( 16, 16 ), Qt::KeepAspectRatio );
        } else {
          return KIcon( QLatin1String( "x-office-contact" ) );
        }
      }
      return QVariant();
    } else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) {
      switch ( mColumns.at( column ) ) {
        case FullName:
          return contact.realName();
          break;
        case Birthday:
          if ( contact.birthday().isValid() )
            return KGlobal::locale()->formatDate( contact.birthday().date() );
          break;
        case HomeAddress:
          {
            const KABC::Address address = contact.address( KABC::Address::Home );
            if ( !address.isEmpty() )
              return address.formattedAddress();
          }
          break;
        case BusinessAddress:
          {
            const KABC::Address address = contact.address( KABC::Address::Work );
            if ( !address.isEmpty() )
              return address.formattedAddress();
          }
          break;
        case PhoneNumbers:
          {
            QStringList values;

            const KABC::PhoneNumber::List numbers = contact.phoneNumbers();
            foreach ( const KABC::PhoneNumber &number, numbers )
              values += number.number();

            return values.join( "\n" );
          }
          break;
        case PreferredEmail:
          return contact.preferredEmail();
          break;
        case AllEmails:
          return contact.emails().join( "\n" );
          break;
        case Organization:
          return contact.organization();
          break;
        case Homepage:
          return contact.url().url();
          break;
        case Note:
          return contact.note();
          break;
      }
    }
  } else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
예제 #8
0
void Nick::refresh()
{
    int flags = 0;
    NickInfo* nickInfo = getChannelNick()->getNickInfo();
    bool away = false;

    if ( nickInfo )
        away = nickInfo->isAway();

    if(away)
        flags=1;

    Images* images = KonversationApplication::instance()->images();
    QPixmap icon;

    if ( getChannelNick()->isOwner() )
    {
        flags += 64;
        icon = images->getNickIcon( Images::Owner, away );
    }
    else if ( getChannelNick()->isAdmin() )
    {
        flags += 128;
        icon = images->getNickIcon( Images::Admin, away );
    }
    else if ( getChannelNick()->isOp() )
    {
        flags += 32;
        icon = images->getNickIcon( Images::Op, away );
    }
    else if ( getChannelNick()->isHalfOp() )
    {
        flags += 16;
        icon = images->getNickIcon( Images::HalfOp, away );
    }
    else if ( getChannelNick()->hasVoice() )
    {
        flags += 8;
        icon = images->getNickIcon( Images::Voice, away );
    }
    else
    {
        flags += 4;
        icon = images->getNickIcon( Images::Normal, away );
    }

    setPixmap( 0, icon );

    KABC::Picture pic = nickInfo->getAddressee().photo();

    if(!pic.isIntern())
    {
        pic = nickInfo->getAddressee().logo();
    }

    if(pic.isIntern())
    {
        QPixmap qpixmap(pic.data().scaleHeight(m_height));
        setPixmap(1,qpixmap);
    }

    QString newtext1 = calculateLabel1();
    if(newtext1 != text(1))
    {
        setText(1, newtext1);
        flags += 2;
    }

    setText(2, calculateLabel2());
    repaint();

    if(m_flags != flags)
    {
        m_flags = flags;
        emit refreshed();                         // Resort nick list
    }
}