--- 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
--- 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 <QContact>
#include <QContactAddress>
+#include <QContactName>
#include <QContactOrganization>
#include <QContactPhoneNumber>
#include "contactsengine.h"
+#include <QDebug>
+
using namespace QtMobility;
ContactsEngine::ContactsEngine(QObject *parent) :
QAbstractListModel(parent)
{
- this->m_manager = 0;
+ this->m_manager =0 ;
}
+
ContactsEngine::~ContactsEngine()
{
- QList<QContactManager*> 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<QContact> 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<QContact> 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<QContact> 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;
}
--- 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<QString, QString> m_availableManagers;
QMap<QString, QContactManager*> m_initialisedManagers;
+
};
#endif // CONTACTSENGINE_H
--- 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 <QComboBox>
+
#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()
{
--- 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;