# HG changeset patch # User John Kern # Date 1281051647 25200 # Node ID e4b6ee3295018029ef14cc29ede3c4c0e4446517 # Parent 5707b75503d59ee307200be9de3bfb381c3d12c8 WIP: first draft of contact engine diff -r 5707b75503d5 -r e4b6ee329501 contactengine/.make.cache --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/.make.cache Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,11 @@ +# ============================================================================== +# This file is generated by make and should not be modified by the user +# Name : .make.cache +# Part of : contact215 +# Description : This file is used to cache last build target for +# make sis target. +# Version : +# +# ============================================================================== + +QT_SIS_TARGET ?= DEBUG-GCCE diff -r 5707b75503d5 -r e4b6ee329501 contactengine/contactengine.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/contactengine.pro Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,31 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-08-03T16:15:24 +# +#------------------------------------------------- + +QT += core gui webkit + +TARGET = contactengine +TEMPLATE = app + +CONFIG += debug + +SOURCES += main.cpp\ + mainwindow.cpp \ + contactsengine.cpp + +HEADERS += mainwindow.h \ + contactsengine.h + +FORMS += mainwindow.ui + +CONFIG += mobility +MOBILITY = contacts + +symbian { + TARGET.UID3 = 0xec200759 + # TARGET.CAPABILITY += + TARGET.EPOCSTACKSIZE = 0x14000 + TARGET.EPOCHEAPSIZE = 0x020000 0x800000 +} diff -r 5707b75503d5 -r e4b6ee329501 contactengine/contactengine.pro.user --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/contactengine.pro.user Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,395 @@ + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + System + + + + ProjectExplorer.Project.Target.0 + + Qt Simulator + Qt4ProjectManager.Target.QtSimulatorTarget + 0 + 0 + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + C:/workspace/QtExamples/contactengine-build-simulator + 28 + 2 + true + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + C:/workspace/QtExamples/contactengine-build-simulator + 28 + 2 + true + + 2 + + contactengine + Qt4ProjectManager.Qt4RunConfiguration + 2 + + contactengine.pro + false + false + + false + false + + + 1 + + + + ProjectExplorer.Project.Target.1 + + Symbian Device + Qt4ProjectManager.Target.S60DeviceTarget + 0 + 0 + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + + Create SIS Package + Qt4ProjectManager.S60SignBuildStep + false + + + + + 0 + + 3 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + 4.6.3 Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + C:/workspace/QtExamples/contactengine + 34 + 6 + false + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + + Create SIS Package + Qt4ProjectManager.S60SignBuildStep + false + + + + + 0 + + 3 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + 4.6.3 Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + C:/workspace/QtExamples/contactengine + 34 + 6 + false + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + + Create SIS Package + Qt4ProjectManager.S60SignBuildStep + false + + + + + 0 + + 3 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + S60_5th_Edition_SDK_v1.0 (Qt 4.6.3) Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + C:/workspace/QtExamples/contactengine + 42 + 6 + false + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + + Create SIS Package + Qt4ProjectManager.S60SignBuildStep + false + + + + + 0 + + 3 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + S60_5th_Edition_SDK_v1.0 (Qt 4.6.3) Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + C:/workspace/QtExamples/contactengine + 42 + 6 + false + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + + Create SIS Package + Qt4ProjectManager.S60SignBuildStep + false + + + + + 0 + + 3 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + S60_3rd_FP2_SDK_v1.1 (Qt 4.6.3) Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + C:/workspace/QtExamples/contactengine + 44 + 6 + false + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + + Create SIS Package + Qt4ProjectManager.S60SignBuildStep + false + + + + + 0 + + 3 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + S60_3rd_FP2_SDK_v1.1 (Qt 4.6.3) Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + C:/workspace/QtExamples/contactengine + 44 + 6 + false + + 6 + + contactengine on Symbian Device + Qt4ProjectManager.S60DeviceRunConfiguration + + contactengine.pro + COM5 + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 4 + + diff -r 5707b75503d5 -r e4b6ee329501 contactengine/contactsengine.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/contactsengine.cpp Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,287 @@ +#include +#include +#include +#include + +#include "contactsengine.h" + +using namespace QtMobility; + +ContactsEngine::ContactsEngine(QObject *parent) : + QAbstractListModel(parent) +{ + 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) +{ + QString managerUri = m_availableManagers.value(aMgrName); + + // first, check to see if they reselected the same backend. + if (m_manager && m_manager->managerUri() == managerUri) + return; + + // the change is real. update. + if (m_initialisedManagers.contains(managerUri)) { + m_manager = m_initialisedManagers.value(managerUri); + } else { + m_manager = QContactManager::fromUri(managerUri); + if (m_manager->error()) { + // todo switch to qDebug() + // QMessageBox::information(this, tr("Failed!"), QString("Failed to open store!\n(error code %1)").arg(m_manager->error())); + delete m_manager; + m_manager = 0; + return; + } + 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); +} + +void ContactsEngine::populateAddresses() +{ + QContact *contact; + QContactOrganization *dept; + QStringList departmentName; + QContactPhoneNumber *number; + QContactAddress *address; + + // this source is open source. Do not put private numbers in here. + + // emergency numbers + // fire Foster City + contact = new QContact(); + + dept = new QContactOrganization(); + departmentName << "Foster City Fire department"; + dept->setDepartment(departmentName); + contact->saveDetail(dept); + + number = new QContactPhoneNumber(); + number->setContexts(QContactDetail::ContextWork); + number->setNumber("+1-650-286-3350?"); + contact->saveDetail(number); + //fire.setPreferredDetail("DialAction",number); //doesn't compile. Has it been depreciated? + + // create address detail + address = new QContactAddress(); + address->setCountry("USA"); + address->setRegion("CA"); + address->setLocality("Foster City"); // RFC 2426 - defines the difference locality and region. + address->setStreet("1040 East Hillsdale Boulevard"); + address->setPostcode("94404"); + contact->saveDetail(address); + + this->m_manager->saveContact(contact); + // Note that the caller retains ownership of the detail. + delete dept; + while (!departmentName.isEmpty()) + departmentName.takeFirst(); + delete number; + delete address; + delete contact; + + // police - foster city + contact = new QContact(); + + dept = new QContactOrganization(); + + departmentName << "Foster City Police department"; + dept->setDepartment(departmentName); + contact->saveDetail(dept); + + number = new QContactPhoneNumber(); + number->setContexts(QContactDetail::ContextWork); + number->setNumber("+1(650)286-3300?"); + contact->saveDetail(number); + + // create address detail + address = new QContactAddress(); + address->setCountry("USA"); + address->setRegion("CA"); + address->setLocality("Foster City"); + address->setStreet("1030 East Hillsdale Boulevard"); + address->setPostcode("94404"); + contact->saveDetail(address); + + this->m_manager->saveContact(contact); + delete dept; + while (!departmentName.isEmpty()) + departmentName.takeFirst(); + delete number; + delete address; + delete contact; + + // taxi - Foster City + contact = new QContact(); + + dept = new QContactOrganization(); + departmentName << "Foster City Yellow Cab"; + dept->setDepartment(departmentName); + contact->saveDetail(dept); + + number = new QContactPhoneNumber(); + number->setContexts(QContactDetail::ContextWork); + number->setNumber("+1(650)367-9999?"); + contact->saveDetail(number); + + // create address detail + address = new QContactAddress(); + address->setCountry("USA"); + address->setRegion("CA"); + address->setLocality("Foster City"); + address->setStreet("1055 foster city blvd"); + address->setPostcode("94404"); + contact->saveDetail(address); + + this->m_manager->saveContact(contact); + delete dept; + while (!departmentName.isEmpty()) + departmentName.takeFirst(); + delete number; + delete address; + delete contact; + + // fire - Menlo Park + contact = new QContact(); + + dept = new QContactOrganization(); + departmentName << "Menlo Park fire department"; + dept->setDepartment(departmentName); + contact->saveDetail(dept); + + number = new QContactPhoneNumber(); + number->setContexts(QContactDetail::ContextWork); + number->setNumber("+1(650)688-8400??"); + contact->saveDetail(number); + + // create address detail + address = new QContactAddress(); + address->setCountry("USA"); + address->setRegion("CA"); + address->setLocality("Menlo Park"); + address->setStreet("170 Middlefield Road"); + address->setPostcode("94025"); + contact->saveDetail(address); + + this->m_manager->saveContact(contact); + delete dept; + while (!departmentName.isEmpty()) + departmentName.takeFirst(); + delete number; + delete address; + delete contact; + + //701 Laurel Street, Menlo Park, CA? - + // police - Menlo Park + contact = new QContact(); + + dept = new QContactOrganization(); + departmentName << "Menlo Park police department"; + dept->setDepartment(departmentName); + contact->saveDetail(dept); + + number = new QContactPhoneNumber(); + number->setContexts(QContactDetail::ContextWork); + number->setNumber("+1(650)858-3328???"); + contact->saveDetail(number); + + // create address detail + address = new QContactAddress(); + address->setCountry("USA"); + address->setRegion("CA"); + address->setLocality("Menlo Park"); + address->setStreet("701 Laurel Street"); + address->setPostcode("94025"); + contact->saveDetail(address); + + this->m_manager->saveContact(contact); + delete dept; + while (!departmentName.isEmpty()) + departmentName.takeFirst(); + delete number; + delete address; + delete contact; +} + + + +QStringList ContactsEngine::dataSources() +{ + QStringList availableManagers = QContactManager::availableManagers(); + availableManagers.removeAll("invalid"); + foreach(QString managerName, availableManagers) { + + QMap params; + QString managerUri = QContactManager::buildUri(managerName, params); + + // Add some parameters to SIM backend so that we can use + // all the stores. + if (managerName == "symbiansim") { + availableManagers.removeAll("symbiansim"); + + availableManagers.append("symbiansim:adn"); + params.insert("store", "ADN"); + managerUri = QContactManager::buildUri(managerName, params); + m_availableManagers.insert(availableManagers.last(), managerUri); + + availableManagers.append("symbiansim:fdn"); + params.clear(); + params.insert("store", "FDN"); + managerUri = QContactManager::buildUri(managerName, params); + m_availableManagers.insert(availableManagers.last(), managerUri); + + availableManagers.append("symbiansim:sdn"); + params.clear(); + params.insert("store", "SDN"); + managerUri = QContactManager::buildUri(managerName, params); + m_availableManagers.insert(availableManagers.last(), managerUri); + } + else { + m_availableManagers.insert(managerName, managerUri); + } + } + return (availableManagers); +} + +int ContactsEngine::rowCount(const QModelIndex &parent) const + { + QList allContacts; + allContacts = this->m_manager->contacts(); + // return stringList.count(); + return allContacts.count(); + } + +QVariant ContactsEngine::data(const QModelIndex &index, int role) const + { + QVariant rc; + QList allContacts; + + allContacts = this->m_manager->contacts(); + + if (!index.isValid() || index.row() >= allContacts.size()) { + return rc; + } + if (role == Qt::DisplayRole) { + rc = QVariant(allContacts.at(index.row()).displayLabel()); + } + return rc; + } diff -r 5707b75503d5 -r e4b6ee329501 contactengine/contactsengine.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/contactsengine.h Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,40 @@ +#ifndef CONTACTSENGINE_H +#define CONTACTSENGINE_H + +#include + +#include + +#include "contactsengine.h" + +using namespace QtMobility; + +class ContactsEngine : public QAbstractListModel +{ + Q_OBJECT +public: + explicit ContactsEngine(QObject *parent = 0); + ~ContactsEngine(); + + // 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(); + +signals: + void managerChanged(QStringList containNames); + +public slots: + +private: + QContactManager *m_manager; + QMap m_availableManagers; + QMap m_initialisedManagers; +}; + +#endif // CONTACTSENGINE_H diff -r 5707b75503d5 -r e4b6ee329501 contactengine/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/main.cpp Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,16 @@ +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + +#if defined(Q_WS_S60) + w.showMaximized(); +#else + w.show(); +#endif + + return a.exec(); +} diff -r 5707b75503d5 -r e4b6ee329501 contactengine/mainwindow.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/mainwindow.cpp Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,25 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "contactsengine.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + this->ce = new ContactsEngine(this); + + ui->comboBox->addItems(this->ce->dataSources()); + +} + +void MainWindow::backendSelected(QString txt) +{ + // based on this string create a contact manager. + this->ce->setManager(txt); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff -r 5707b75503d5 -r e4b6ee329501 contactengine/mainwindow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/mainwindow.h Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,27 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "contactsengine.h" + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +public slots: + void backendSelected(QString ); + +private: + Ui::MainWindow *ui; + ContactsEngine *ce; +}; + +#endif // MAINWINDOW_H diff -r 5707b75503d5 -r e4b6ee329501 contactengine/mainwindow.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/mainwindow.ui Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,46 @@ + + + MainWindow + + + + 0 + 0 + 360 + 640 + + + + MainWindow + + + + + + 0 + 0 + 361 + 641 + + + + + + + + 12 + + + + + + + + + + + + + + + diff -r 5707b75503d5 -r e4b6ee329501 contactengine/ui_mainwindow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/ui_mainwindow.h Thu Aug 05 16:40:47 2010 -0700 @@ -0,0 +1,83 @@ +/******************************************************************************** +** Form generated from reading UI file 'mainwindow.ui' +** +** Created: Thu Aug 5 16:24:17 2010 +** by: Qt User Interface Compiler version 4.6.3 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_MAINWINDOW_H +#define UI_MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_MainWindow +{ +public: + QWidget *centralWidget; + QWidget *widget; + QVBoxLayout *verticalLayout; + QComboBox *comboBox; + QListView *listView; + + void setupUi(QMainWindow *MainWindow) + { + if (MainWindow->objectName().isEmpty()) + MainWindow->setObjectName(QString::fromUtf8("MainWindow")); + MainWindow->resize(360, 640); + centralWidget = new QWidget(MainWindow); + centralWidget->setObjectName(QString::fromUtf8("centralWidget")); + widget = new QWidget(centralWidget); + widget->setObjectName(QString::fromUtf8("widget")); + widget->setGeometry(QRect(0, 0, 361, 641)); + verticalLayout = new QVBoxLayout(widget); + verticalLayout->setSpacing(6); + verticalLayout->setContentsMargins(11, 11, 11, 11); + verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); + verticalLayout->setContentsMargins(0, 0, 0, 0); + comboBox = new QComboBox(widget); + comboBox->setObjectName(QString::fromUtf8("comboBox")); + QFont font; + font.setPointSize(12); + comboBox->setFont(font); + + verticalLayout->addWidget(comboBox); + + listView = new QListView(widget); + listView->setObjectName(QString::fromUtf8("listView")); + + verticalLayout->addWidget(listView); + + MainWindow->setCentralWidget(centralWidget); + + retranslateUi(MainWindow); + + QMetaObject::connectSlotsByName(MainWindow); + } // setupUi + + void retranslateUi(QMainWindow *MainWindow) + { + MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8)); + } // retranslateUi + +}; + +namespace Ui { + class MainWindow: public Ui_MainWindow {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_MAINWINDOW_H