# HG changeset patch # User John Kern # Date 1281474355 25200 # Node ID 51fcdd1558d8b0a973b2e6963ad37cce2b497aab # Parent d5911f90500dc6b8de4b43b7a6609ef7db746f6c clean up diff -r d5911f90500d -r 51fcdd1558d8 contactengine/contactengine.pro --- a/contactengine/contactengine.pro Tue Aug 10 19:10:57 2010 +0100 +++ b/contactengine/contactengine.pro Tue Aug 10 14:05:55 2010 -0700 @@ -19,7 +19,8 @@ HEADERS += mainwindow.h \ contactsengine.h \ database.h \ - dbtools.h + dbtools.h \ + database.h FORMS += mainwindow.ui diff -r d5911f90500d -r 51fcdd1558d8 contactengine/contactsengine.cpp --- a/contactengine/contactsengine.cpp Tue Aug 10 19:10:57 2010 +0100 +++ b/contactengine/contactsengine.cpp Tue Aug 10 14:05:55 2010 -0700 @@ -1,27 +1,27 @@ #include #include +#include #include #include #include "contactsengine.h" +#include + using namespace QtMobility; ContactsEngine::ContactsEngine(QObject *parent) : QAbstractListModel(parent) { - this->m_manager = 0; + this->m_manager =0 ; } + ContactsEngine::~ContactsEngine() { - QList initialisedManagers = m_initialisedManagers.values(); - while (!initialisedManagers.isEmpty()) { - QContactManager *deleteMe = initialisedManagers.takeFirst(); - delete deleteMe; - } + } -void ContactsEngine::setManager(QString aMgrName) +void ContactsEngine::setManager(const QString & aMgrName) { QString managerUri = m_availableManagers.value(aMgrName); @@ -43,17 +43,9 @@ } m_initialisedManagers.insert(managerUri, m_manager); } - - // compute a new list of contact names - QStringList displayNames; - QList c = this->m_manager->contacts(); - - // signal that the manager has changed. - - // emit managerChanged(m_manager); - - // and... rebuild the list. - // rebuildList(m_currentFilter); +// qDebug() << "Dump Object: " << endl; +// m_manager->dumpObjectInfo(); // from QObject + this->dumpContactMgr(); // private helper function } void ContactsEngine::populateAddresses() @@ -265,15 +257,42 @@ int ContactsEngine::rowCount(const QModelIndex &parent) const { QList allContacts; - allContacts = this->m_manager->contacts(); - // return stringList.count(); - return allContacts.count(); + int rc = 0; + if (this->m_manager) + { + allContacts = this->m_manager->contacts(); + // return stringList.count(); + if (!allContacts.isEmpty()) + rc = allContacts.count(); + } + return rc; } +void ContactsEngine::enumerateMgrs() +{ + QStringList mgrs = QContactManager::availableManagers(); + qDebug() << "Enumerate available Contact Managers:" << endl; + foreach(QString m, mgrs) + qDebug() << "\tmgr: " << m << endl; + qDebug() << endl; +} + +// dump the current contact manager. +void ContactsEngine::dumpContactMgr() +{ + qDebug() << "Dump Contact Manager:" << endl; + qDebug() << "\tname: " << this->m_manager->managerName() << endl; + qDebug() << "\tURI: " << this->m_manager->managerUri() << endl; + qDebug() << "\tVersion: " << this->m_manager->managerVersion() << endl; + qDebug() << "\tCount:" << this->m_manager->contacts().count() << endl; + qDebug() << endl; +} + QVariant ContactsEngine::data(const QModelIndex &index, int role) const { QVariant rc; QList allContacts; + QContact c; allContacts = this->m_manager->contacts(); @@ -281,7 +300,15 @@ return rc; } if (role == Qt::DisplayRole) { - rc = QVariant(allContacts.at(index.row()).displayLabel()); + //rc = QVariant(allContacts.at(index.row()).displayLabel()); + c = allContacts.at(index.row()); + // organizations do not have first and last names. So the displayLabel() is empty. + QContactDetail cd = c.detail(QContactName::DefinitionName); + if (cd.isEmpty()) { + rc = QVariant (c.detail(QContactOrganization::DefinitionName).value(QContactOrganization::FieldDepartment) ); + } else { + rc = QVariant ( c.displayLabel()); + } } return rc; } diff -r d5911f90500d -r 51fcdd1558d8 contactengine/contactsengine.h --- a/contactengine/contactsengine.h Tue Aug 10 19:10:57 2010 +0100 +++ b/contactengine/contactsengine.h Tue Aug 10 14:05:55 2010 -0700 @@ -16,25 +16,30 @@ explicit ContactsEngine(QObject *parent = 0); ~ContactsEngine(); + // index() and parent() are defined by QAbstractListModel. So we do not + // need to define the QModelIndex // required by list model interface. int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; QStringList dataSources(); - void setManager(QString aMgr); public: void populateAddresses(); + void dumpContactMgr(); // use for debugging. Hard to inspect it via Qt Creator. + void enumerateMgrs(); signals: void managerChanged(QStringList containNames); public slots: + void setManager(const QString &aMgr); private: QContactManager *m_manager; QMap m_availableManagers; QMap m_initialisedManagers; + }; #endif // CONTACTSENGINE_H diff -r d5911f90500d -r 51fcdd1558d8 contactengine/mainwindow.cpp --- a/contactengine/mainwindow.cpp Tue Aug 10 19:10:57 2010 +0100 +++ b/contactengine/mainwindow.cpp Tue Aug 10 14:05:55 2010 -0700 @@ -1,3 +1,5 @@ +#include + #include "mainwindow.h" #include "ui_mainwindow.h" #include "contactsengine.h" @@ -8,16 +10,20 @@ { ui->setupUi(this); this->ce = new ContactsEngine(this); + // this->ce->enumerateMgrs(); + this->ce->setManager(QString("memory")); + + connect(ui->comboBox, SIGNAL( activated ( const QString & )), + this->ce, SLOT(setManager(const QString &) )); ui->comboBox->addItems(this->ce->dataSources()); - + this->ce->populateAddresses(); + // this->ce->enumerateMgrs(); + // this->ce->dumpContactMgr(); + ui->listView->setModel(this->ce); } -void MainWindow::backendSelected(QString txt) -{ - // based on this string create a contact manager. - this->ce->setManager(txt); -} + MainWindow::~MainWindow() { diff -r d5911f90500d -r 51fcdd1558d8 contactengine/mainwindow.h --- a/contactengine/mainwindow.h Tue Aug 10 19:10:57 2010 +0100 +++ b/contactengine/mainwindow.h Tue Aug 10 14:05:55 2010 -0700 @@ -17,7 +17,6 @@ ~MainWindow(); public slots: - void backendSelected(QString ); private: Ui::MainWindow *ui;