1 /*
2     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19 
20 #include "addresseeitem.h"
21 
22 #include <qlayout.h>
23 #include <qpushbutton.h>
24 #include <qregexp.h>
25 #include <QPixmap>
26 #include <QIcon>
27 
28 #include "libkopete_debug.h"
29 
AddresseeItem(QTreeWidget * parent,const KContacts::Addressee & addressee)30 AddresseeItem::AddresseeItem(QTreeWidget *parent, const KContacts::Addressee &addressee)
31     : QTreeWidgetItem(parent)
32     , mAddressee(addressee)
33 {
34     //We can't save showphoto because we don't have a d pointer
35     KContacts::Picture pic = mAddressee.photo();
36     if (!pic.isIntern()) {
37         pic = mAddressee.logo();
38     }
39     if (pic.isIntern()) {
40         QPixmap qpixmap = QPixmap::fromImage(pic.data().scaledToWidth(60)); //60 pixels seems okay.. kmail uses 60 btw
41         setIcon(Photo, QIcon(qpixmap));
42     }
43 
44     setText(Name, addressee.realName());
45     setText(Email, addressee.preferredEmail());
46 }
47 
key(int column,bool) const48 QString AddresseeItem::key(int column, bool) const
49 {
50     if (column == Email) {
51         QString value = text(Email);
52         QRegExp emailRe(QLatin1String("<\\S*>"));
53         int match = emailRe.indexIn(value);
54         if (match > -1) {
55             value = value.mid(match + 1, emailRe.matchedLength() - 2);
56         }
57 
58         return value.toLower();
59     }
60 
61     return text(column).toLower();
62 }
63