Commit 0b4c0216 authored by Emmanuel Lepage's avatar Emmanuel Lepage

Some progress on contact support

parent c2b1c028
#include "ContactDock.h"
#include <QtGui/QVBoxLayout>
#include <QtGui/QTableWidget>
#include <QtGui/QTreeWidget>
#include <QtGui/QHeaderView>
#include <akonadi/collectionfilterproxymodel.h>
#include <akonadi/contact/contactstreemodel.h>
......@@ -15,32 +19,65 @@
#include <kabc/field.h>
#include <kabc/vcardline.h>
#include <kabc/contactgroup.h>
#include <kabc/phonenumber.h>
#include <akonadi/itemfetchscope.h>
#include <akonadi/entitydisplayattribute.h>
#include <akonadi/recursiveitemfetchjob.h>
#include <kicon.h>
#include "ContactItemWidget.h"
class QNumericTreeWidgetItem : public QTreeWidgetItem {
public:
QNumericTreeWidgetItem(QTreeWidget* parent):QTreeWidgetItem(parent),widget(0),weight(-1){}
QNumericTreeWidgetItem(QTreeWidgetItem* parent):QTreeWidgetItem(parent),widget(0),weight(-1){}
ContactItemWidget* widget;
int weight;
private:
bool operator<(const QTreeWidgetItem & other) const {
int column = treeWidget()->sortColumn();
//if (dynamic_cast<QNumericTreeWidgetItem*>((QTreeWidgetItem*)&other)) {
//if (widget !=0 && dynamic_cast<QNumericTreeWidgetItem*>((QTreeWidgetItem*)&other)->widget != 0)
// return widget->getTimeStamp() < dynamic_cast<QNumericTreeWidgetItem*>((QTreeWidgetItem*)&other)->widget->getTimeStamp();
//else if (weight > 0 && dynamic_cast<QNumericTreeWidgetItem*>((QTreeWidgetItem*)&other)->weight > 0)
// return weight > dynamic_cast<QNumericTreeWidgetItem*>((QTreeWidgetItem*)&other)->weight;
//}
return text(column) < other.text(column);
}
};
ContactDock::ContactDock(QWidget* parent) : QDockWidget(parent)
{
setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
setMinimumSize(250,0);
m_pCollViewCV = new Akonadi::EntityTreeView();
m_pItemView = new Akonadi::ItemView();
m_pFilterLE = new KLineEdit();
m_pCollCCB = new Akonadi::CollectionComboBox;
m_pSplitter = new QSplitter(Qt::Vertical,this);
m_pSortByCBB = new QComboBox(this);
m_pContactView = new QTreeWidget(this);
m_pCallView = new QTableWidget(this);
QStringList sortType;
sortType << "Name" << "Organisation" << "Phone number type" << "Rencently used" << "Group";
m_pSortByCBB->addItems(sortType);
QWidget* mainWidget = new QWidget(this);
setWidget(mainWidget);
m_pContactView->headerItem()->setText(0,"Contacts");
m_pContactView->header()->setClickable(true);
m_pContactView->header()->setSortIndicatorShown(true);
m_pContactView->setAlternatingRowColors(true);
m_pFilterLE->setPlaceholderText("Filter");
m_pFilterLE->setClearButtonShown(true);
QVBoxLayout* mainLayout = new QVBoxLayout(mainWidget);
mainLayout->addWidget(m_pCollCCB);
mainLayout->addWidget(m_pSortByCBB);
mainLayout->addWidget(m_pSplitter);
m_pSplitter->addWidget(m_pCollViewCV);
m_pSplitter->addWidget(m_pItemView);
m_pSplitter->addWidget(m_pContactView);
m_pSplitter->addWidget(m_pCallView);
mainLayout->addWidget(m_pFilterLE);
m_pSplitter->setChildrenCollapsible(true);
......@@ -49,58 +86,10 @@ ContactDock::ContactDock(QWidget* parent) : QDockWidget(parent)
m_pCollCCB->setMimeTypeFilter( QStringList() << KABC::Addressee::mimeType() );
m_pCollCCB->setAccessRightsFilter( Akonadi::Collection::ReadOnly );
/////////////
// use a separated session for this model
Akonadi::Session *session = new Akonadi::Session( "SFLPhone::instance" );
Akonadi::ItemFetchScope scope;
// fetch all content of the contacts, including images
scope.fetchFullPayload( true );
// fetch the EntityDisplayAttribute, which contains custom names and icons
scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
Akonadi::ChangeRecorder *changeRecorder = new Akonadi::ChangeRecorder;
changeRecorder->setSession( session );
// include fetching the collection tree
changeRecorder->fetchCollection( true );
// set the fetch scope that shall be used
changeRecorder->setItemFetchScope( scope );
// monitor all collections below the root collection for changes
changeRecorder->setCollectionMonitored( Akonadi::Collection::root() );
// list only contacts and contact groups
changeRecorder->setMimeTypeMonitored( KABC::Addressee::mimeType(), true );
changeRecorder->setMimeTypeMonitored( KABC::ContactGroup::mimeType(), true );
Akonadi::ContactsTreeModel *model = new Akonadi::ContactsTreeModel( changeRecorder );
Akonadi::ContactsTreeModel::Columns columns;
columns << Akonadi::ContactsTreeModel::FullName;
columns << Akonadi::ContactsTreeModel::AllEmails;
model->setColumns( columns );
//////////////
for (int i=0;i<model->rowCount();i++) {
qDebug() << "\n\n\nChild:" << model->hasChildren(model->index(i,0)) << "Model:" << model->rowCount(model->index(i,0));
}
qDebug() << "\n\n\nChild:" << model->hasChildren(model->index(0,0)) << "Model:" << model->rowCount(model->index(0,0));
qDebug() << "\n\n\nChild:" << model->hasChildren(model->index(1,0)) << "Model:" << model->rowCount(model->index(1,0));
//qDebug() << "Model:" << *model;
m_pCollViewCV->setModel( model );
m_pItemView->setModel( model );
connect (m_pCollCCB, SIGNAL(currentChanged(Akonadi::Collection)),this,SLOT(collectAddressBookContacts()));
//collectAllContacts(model);
collectAddressBookContacts();
connect (m_pCollCCB, SIGNAL(currentChanged(Akonadi::Collection)),this,SLOT(reloadContact()));
setWindowTitle("Contact");
//setDockIcon(KIcon("resource-group"));
}
ContactDock::~ContactDock()
......@@ -108,75 +97,60 @@ ContactDock::~ContactDock()
}
KABC::Addressee::List ContactDock::collectAllContacts(Akonadi::ContactsTreeModel *mModel) const
{
KABC::Addressee::List contacts;
for ( int i = 0; i < mModel->rowCount(); ++i ) {
const QModelIndex index = mModel->index( i, 0 );
if ( index.isValid() ) {
const Akonadi::Item item = index.data( Akonadi::EntityTreeModel::ItemRole ).value<Akonadi::Item>();
if ( item.isValid() && item.hasPayload<KABC::Addressee>() ) {
contacts.append( item.payload<KABC::Addressee>() );
qDebug() << item.payload<KABC::Addressee>().toString();
}
}
}
return contacts;
}
KABC::Addressee::List ContactDock::collectAddressBookContacts() const
{
qDebug() << "In colect\n\n\n\n\n";
KABC::Addressee::List contacts;
const Akonadi::Collection collection = m_pCollCCB->currentCollection();
if ( !collection.isValid() ) {
qDebug() << "The current collection is not valid";
return contacts;
}
qDebug() << "Valid collection";
//if ( mAddressBookSelectionRecursive->isChecked() ) {
Akonadi::RecursiveItemFetchJob *job = new Akonadi::RecursiveItemFetchJob( collection, QStringList() << KABC::Addressee::mimeType() << KABC::ContactGroup::mimeType());
job->fetchScope().fetchFullPayload();
//qDebug() << "Begin \n\n\n";
if ( job->exec() ) {
const Akonadi::Item::List items = job->items();
foreach ( const Akonadi::Item &item, items ) {
//qDebug() << "In for" << item.payloadData() << item.mimeType();
if ( item.hasPayload<KABC::ContactGroup>() ) {
//contacts.append( item.payload<KABC::ContactGroup>() );
qDebug() << "Group:" << item.payload<KABC::ContactGroup>().name();
}
if ( item.hasPayload<KABC::Addressee>() ) {
//contacts.append( item.payload<KABC::ContactGroup>() );
qDebug() << "Addressee:" << item.payload<KABC::Addressee>().name();
contacts << item.payload<KABC::Addressee>();
qDebug() << "Addressee:" << item.payload<KABC::Addressee>().givenName();
}
// if ( item.hasPayload<KABC::Field>() ) {
// //contacts.append( item.payload<KABC::VCard>() );
// qDebug() << "VCard:" << item.payload<KABC::VCardFormat>().identifiers();
// }
}
}
// } else {
// Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( collection );
// job->fetchScope().fetchFullPayload();
//
// if ( job->exec() ) {
// const Akonadi::Item::List items = job->items();
//
// foreach ( const Akonadi::Item &item, items ) {
// if ( item.hasPayload<KABC::Addressee>() ) {
// contacts.append( item.payload<KABC::Addressee>() );
// }
// }
// }
// }
qDebug() << "End collect \n\n\n";
qDebug() << "End collect "<< contacts.size() << "\n\n\n";
return contacts;
}
void ContactDock::reloadContact()
{
KABC::Addressee::List list = collectAddressBookContacts();
qDebug() << "About to display items" << list.size();
foreach (KABC::Addressee addr, list) {
qDebug() << "In list:";
ContactItemWidget* aContact = new ContactItemWidget(m_pContactView);
QNumericTreeWidgetItem* item = new QNumericTreeWidgetItem(m_pContactView);
item->widget = aContact;
aContact->setItem(item);
aContact->setContact(addr);
KABC::PhoneNumber::List numbers = aContact->getCallNumbers();
if (aContact->getCallNumbers().count() > 1) {
foreach (KABC::PhoneNumber number, numbers) {
QNumericTreeWidgetItem* item2 = new QNumericTreeWidgetItem(item);
QLabel* numberL = new QLabel("<b>"+number.typeLabel()+":</b>"+number.number());
m_pContactView->setItemWidget(item2,0,numberL);
}
}
m_pContactView->addTopLevelItem(item);
m_pContactView->setItemWidget(item,0,aContact);
}
}
\ No newline at end of file
......@@ -6,12 +6,14 @@
#include <akonadi/entitytreeview.h>
#include <akonadi/itemview.h>
//#include <akonadi/contactgroupviewer.h>
#include <klineedit.h>
#include <kabc/addressee.h>
#include <akonadi/contact/contactstreemodel.h>
#include <akonadi/collectioncombobox.h>
class QTreeWidget;
class QTableWidget;
class QComboBox;
class ContactDock : public QDockWidget {
Q_OBJECT
......@@ -19,15 +21,17 @@ public:
ContactDock(QWidget* parent);
virtual ~ContactDock();
private:
KABC::Addressee::List collectAllContacts(Akonadi::ContactsTreeModel *mModel) const;
Akonadi::EntityTreeView* m_pCollViewCV;
Akonadi::ItemView* m_pItemView;
KLineEdit* m_pFilterLE;
Akonadi::CollectionComboBox* m_pCollCCB;
QSplitter* m_pSplitter;
QTreeWidget* m_pContactView;
QTableWidget* m_pCallView;
QComboBox* m_pSortByCBB;
public slots:
KABC::Addressee::List collectAddressBookContacts() const;
private slots:
void reloadContact();
};
#endif
\ No newline at end of file
/***************************************************************************
* Copyright (C) 2009-2010 by Savoir-Faire Linux *
* Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> *
* Author : Mathieu Leduc-Hamel mathieu.leduc-hamel@savoirfairelinux.com *
* Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
......@@ -18,84 +17,132 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "ContactItemWidget.h"
#include <QtCore/QString>
#include <QtGui/QVBoxLayout>
#include <QtCore/QDebug>
#include <QtGui/QSpacerItem>
#include <QtCore/QStringList>
#include <QtGui/QGridLayout>
#include <klocale.h>
#include <kdebug.h>
#include <unistd.h>
#include "lib/sflphone_const.h"
#include "ContactItemWidget.h"
ContactItemWidget::ContactItemWidget(const Contact * contact, bool displayPhoto, QWidget *parent)
: QWidget(parent)
ContactItemWidget::ContactItemWidget(QWidget *parent)
: QWidget(parent), init(false)
{
Q_UNUSED(contact);
Q_UNUSED(displayPhoto);
// if(!contact->getNickName().isEmpty()) {
// contactName = new QLabel(contact->getNickName());
// }
// else {
// contactName = new QLabel(contact->getFirstName());
// }
// if(displayPhoto) {
// if(!contact->getPhoto()->isEmpty()) {
// QPixmap pixmap;
// if(contact->getPhoto()->isIntern()) {
// contactPhoto = new QLabel();
// pixmap = QPixmap::fromImage(contact->getPhoto()->data());
// }
// else {
// contactPhoto = new QLabel();
// pixmap = QPixmap(contact->getPhoto()->url());
// }
// if(pixmap.height() > pixmap.width())
// contactPhoto->setPixmap(pixmap.scaledToHeight(CONTACT_ITEM_HEIGHT-4));
// else
// contactPhoto->setPixmap(pixmap.scaledToWidth(CONTACT_ITEM_HEIGHT-4));
// }
// else {
// contactPhoto = new QLabel();
// contactPhoto->setMinimumSize(CONTACT_ITEM_HEIGHT-4, 0);
// }
// }
// contactType = new QLabel(PhoneNumber::typeLabel(contact->getType()));
// contactNumber = new QLabel(contact->getPhoneNumber());
// QSpacerItem * horizontalSpacer = new QSpacerItem(16777215, 20, QSizePolicy::Preferred, QSizePolicy::Minimum);
// QHBoxLayout * hlayout = new QHBoxLayout(this);
// QVBoxLayout * vlayout = new QVBoxLayout();
// hlayout->setMargin(1);
// hlayout->setSpacing(4);
// vlayout->setMargin(1);
// vlayout->setSpacing(2);
// vlayout->addWidget(contactName);
// vlayout->addWidget(contactNumber);
// if(displayPhoto) {
// hlayout->addWidget(contactPhoto);
// }
// hlayout->addLayout(vlayout);
// hlayout->addItem(horizontalSpacer);
// hlayout->addWidget(contactType);
// this->setLayout(hlayout);
}
}
ContactItemWidget::~ContactItemWidget()
{
delete contactName;
delete contactNumber;
// delete contactPhoto;
delete contactType;
}
void ContactItemWidget::setContact(KABC::Addressee& contact)
{
m_pContactKA = contact;
m_pIconL = new QLabel(this);
m_pContactNameL = new QLabel();
m_pOrganizationL = new QLabel(this);
m_pEmailL = new QLabel();
m_pCallNumberL = new QLabel(this);
m_pIconL->setMinimumSize(70,48);
m_pIconL->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
QSpacerItem* verticalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
m_pIconL->setMaximumSize(48,9999);
m_pIconL->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_pIconL->setPixmap(QPixmap(KIcon("user-identity").pixmap(QSize(48,48))));
QGridLayout* mainLayout = new QGridLayout(this);
mainLayout->setContentsMargins(0,0,0,0);
mainLayout->addWidget(m_pIconL,0,0,4,1);
mainLayout->addWidget(m_pContactNameL,0,1);
mainLayout->addWidget(m_pOrganizationL,1,1);
mainLayout->addWidget(m_pCallNumberL,2,1);
mainLayout->addWidget(m_pEmailL,3,1);
mainLayout->addItem(verticalSpacer,4,1);
setLayout(mainLayout);
setMinimumSize(QSize(50, 30));
updated();
}
void ContactItemWidget::updated()
{
m_pContactNameL->setText("<b>"+m_pContactKA.formattedName()+"</b>");
if (!m_pContactKA.organization().isEmpty()) {
m_pOrganizationL->setText(m_pContactKA.organization());
}
else {
m_pOrganizationL->setVisible(false);
}
if (!getEmail().isEmpty()) {
m_pEmailL->setText(getEmail());
}
else {
m_pEmailL->setVisible(false);
}
KABC::PhoneNumber::List numbers = m_pContactKA.phoneNumbers();
foreach (KABC::PhoneNumber number, numbers) {
qDebug() << "Phone:" << number.number() << number.typeLabel();
}
if (getCallNumbers().count() == 1)
m_pCallNumberL->setText(getCallNumbers()[0].number());
else
m_pCallNumberL->setText(QString::number(getCallNumbers().count())+" numbers");
QImage photo = m_pContactKA.photo().data();
if (photo.isNull())
m_pIconL->setPixmap(QPixmap(KIcon("user-identity").pixmap(QSize(48,48))));
else
m_pIconL->setPixmap(QPixmap::fromImage( m_pContactKA.photo().data()).scaled(QSize(48,48)));;
}
QPixmap* ContactItemWidget::getIcon()
{
return new QPixmap();
}
QString ContactItemWidget::getContactName()
{
return contactName->text();
return m_pContactKA.formattedName();
}
QString ContactItemWidget::getContactNumber()
KABC::PhoneNumber::List ContactItemWidget::getCallNumbers()
{
return contactNumber->text();
return m_pContactKA.phoneNumbers();
}
QString ContactItemWidget::getOrganization()
{
return m_pContactKA.organization();
}
QString ContactItemWidget::getEmail()
{
return m_pContactKA.fullEmail();
}
QString ContactItemWidget::getPicture()
{
return m_pContactKA.photo().url();
}
QTreeWidgetItem* ContactItemWidget::getItem()
{
return m_pItem;
}
void ContactItemWidget::setItem(QTreeWidgetItem* item)
{
m_pItem = item;
}
\ No newline at end of file
/***************************************************************************
* Copyright (C) 2009-2010 by Savoir-Faire Linux *
* Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> *
* Author : Mathieu Leduc-Hamel mathieu.leduc-hamel@savoirfairelinux.com *
* Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
......@@ -18,38 +17,62 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef CONTACTITEMWIDGET_H
#define CONTACTITEMWIDGET_H
#include <QWidget>
#include <QtCore/QList>
#include <QtCore/QVariant>
#include <QtCore/QVector>
#include <QtGui/QWidget>
#include <QtGui/QLabel>
#include "lib/Contact.h"
#include <QtGui/QSpacerItem>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <KIcon>
#include <kabc/addressee.h>
#include <kabc/picture.h>
#include <kabc/phonenumber.h>
class Contact;
class QTreeWidgetItem;
/**
@author Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>
*/
class ContactItemWidget : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
ContactItemWidget(QWidget* parent =0);
~ContactItemWidget();
private:
QLabel * contactName;
QLabel * contactNumber;
QLabel * contactPhoto;
QLabel * contactType;
KABC::Addressee* contact() const;
void setContact(KABC::Addressee& contact);
static const char * callStateIcons[12];
public:
QPixmap* getIcon();
QString getContactName();
KABC::PhoneNumber::List getCallNumbers();
QString getOrganization();
QString getEmail();
QString getPicture();
QTreeWidgetItem* getItem();
//Constructors & Destructors
ContactItemWidget(const Contact * contact, bool displayPhoto, QWidget *parent = 0);
~ContactItemWidget();
void setItem(QTreeWidgetItem* item);
//Getters
QString getContactName();
QString getContactNumber();
private:
KABC::Addressee m_pContactKA;
QLabel* m_pIconL;
QLabel* m_pContactNameL;
QLabel* m_pCallNumberL;
QLabel* m_pOrganizationL;
QLabel* m_pEmailL;
QTreeWidgetItem* m_pItem;
bool init;
};
public slots:
void updated();
};
#endif
#endif // CALLTREE_ITEM_H
......@@ -59,6 +59,10 @@ HistoryDock::HistoryDock(QWidget* parent) : QDockWidget(parent)
m_pItemView->headerItem()->setText(0,"Calls");
m_pItemView->header()->setClickable(true);
m_pItemView->header()->setSortIndicatorShown(true);
m_pItemView->setAlternatingRowColors(true);
m_pFilterLE->setPlaceholderText("Filter");
m_pFilterLE->setClearButtonShown(true);
QStringList sortBy;
sortBy << "Date" << "Name" << "Popularity" << "Duration";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment