best place for a helper function

Martin Klapetek martin.klapetek at gmail.com
Fri Mar 1 13:15:26 UTC 2013


On Fri, Mar 1, 2013 at 1:34 PM, Alin M Elena <alinm.elena at gmail.com> wrote:

> > It looks like the right place to me, but I don't remember a
> > {Tp/KTp}::Contact::avatar() method to reimplement, I think that we have
> > just a "QString Tp::Contact::avatarToken()" that returns just a string.
> > We could add a KTp::contact::avatar() that does the magic though, but
> > I'm not sure if we want it grayed wherever it is used, so I'd suggest to
> > add a "bool KTp::Contact::avatar(grayIfUnavailable = false)".
> there is no avatar() method so I need to add it... and shall return a
> QPixmap...
>
> the issue I see is that
>
> this is a snap of code from the tooltip (changed a little bit by me but
> keeps
> the spirit)
>
>     QString avatar = index.data(KTp::ContactAvatarPathRole).toString();
>     if (avatar.isEmpty()) {
>         QPixmap avatarPixmap(KIconLoader::global()->loadIcon("im-user",
> KIconLoader::NoGroup, 96));
>         if
> (index.data(KTp::ContactPresenceTypeRole)==Tp::ConnectionPresenceTypeOffline)
> {
>             avatarToGray(avatarPixmap);
>         }
>         ui->avatarLabel->setPixmap(avatarPixmap);
>     } else {
>         QPixmap avatarPixmap(avatar);
>         if
> (index.data(KTp::ContactPresenceTypeRole)==Tp::ConnectionPresenceTypeOffline)
> {
>              avatarToGray(avatarPixmap);
>         }
>         ui->avatarLabel->setPixmap(avatarPixmap.scaled(ui->avatarLabel-
> >size(), Qt::KeepAspectRatio));
>     }
>

If you're loading the icon using KIconLoader (the pawn), you can use just
KIconLoader::global()->loadIcon("im-user",
KIconLoader::NoGroup, 96, KIconLoader::DisabledState) and don't have to go
through your method.


> so my idea is that what my method shall do..
> is to return the proper Qpixmap (that is a proper image or the pawn) and
> grayed if the contact is offline...
> of course that will imply  that in contact list and everywhere we use
> complicated code to set the avatar we can simply call the avatar method.
>
>
>  ui->avatarLabel->setPixmap(avatarPixmap.scaled(ui->avatarLabel->size(),
> Qt::KeepAspectRatio));
>
> Do we agree on this?
>

I'm happy to have a method in KTp::Contact returning the pixmap. But that
also requires adding a role to the models and changing all the code to
either use the new role or the avatar() method.

Cheers
-- 
Martin Klapetek | KDE Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-telepathy/attachments/20130301/a46100ba/attachment.html>


More information about the KDE-Telepathy mailing list