author | John Kern <johnk@symbian.org> |
Tue, 10 Aug 2010 14:05:55 -0700 | |
changeset 23 | 51fcdd1558d8 |
parent 19 | e4b6ee329501 |
child 25 | adbe71832e2b |
permissions | -rwxr-xr-x |
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
1 |
#include <QContact> |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
2 |
#include <QContactAddress> |
23 | 3 |
#include <QContactName> |
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
4 |
#include <QContactOrganization> |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
5 |
#include <QContactPhoneNumber> |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
6 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
7 |
#include "contactsengine.h" |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
8 |
|
23 | 9 |
#include <QDebug> |
10 |
||
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
11 |
using namespace QtMobility; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
12 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
13 |
ContactsEngine::ContactsEngine(QObject *parent) : |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
14 |
QAbstractListModel(parent) |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
15 |
{ |
23 | 16 |
this->m_manager =0 ; |
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
17 |
} |
23 | 18 |
|
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
19 |
ContactsEngine::~ContactsEngine() |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
20 |
{ |
23 | 21 |
|
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
22 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
23 |
|
23 | 24 |
void ContactsEngine::setManager(const QString & aMgrName) |
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
25 |
{ |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
26 |
QString managerUri = m_availableManagers.value(aMgrName); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
27 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
28 |
// first, check to see if they reselected the same backend. |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
29 |
if (m_manager && m_manager->managerUri() == managerUri) |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
30 |
return; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
31 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
32 |
// the change is real. update. |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
33 |
if (m_initialisedManagers.contains(managerUri)) { |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
34 |
m_manager = m_initialisedManagers.value(managerUri); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
35 |
} else { |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
36 |
m_manager = QContactManager::fromUri(managerUri); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
37 |
if (m_manager->error()) { |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
38 |
// todo switch to qDebug() |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
39 |
// QMessageBox::information(this, tr("Failed!"), QString("Failed to open store!\n(error code %1)").arg(m_manager->error())); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
40 |
delete m_manager; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
41 |
m_manager = 0; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
42 |
return; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
43 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
44 |
m_initialisedManagers.insert(managerUri, m_manager); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
45 |
} |
23 | 46 |
// qDebug() << "Dump Object: " << endl; |
47 |
// m_manager->dumpObjectInfo(); // from QObject |
|
48 |
this->dumpContactMgr(); // private helper function |
|
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
49 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
50 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
51 |
void ContactsEngine::populateAddresses() |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
52 |
{ |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
53 |
QContact *contact; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
54 |
QContactOrganization *dept; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
55 |
QStringList departmentName; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
56 |
QContactPhoneNumber *number; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
57 |
QContactAddress *address; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
58 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
59 |
// this source is open source. Do not put private numbers in here. |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
60 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
61 |
// emergency numbers |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
62 |
// fire Foster City |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
63 |
contact = new QContact(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
64 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
65 |
dept = new QContactOrganization(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
66 |
departmentName << "Foster City Fire department"; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
67 |
dept->setDepartment(departmentName); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
68 |
contact->saveDetail(dept); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
69 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
70 |
number = new QContactPhoneNumber(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
71 |
number->setContexts(QContactDetail::ContextWork); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
72 |
number->setNumber("+1-650-286-3350?"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
73 |
contact->saveDetail(number); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
74 |
//fire.setPreferredDetail("DialAction",number); //doesn't compile. Has it been depreciated? |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
75 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
76 |
// create address detail |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
77 |
address = new QContactAddress(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
78 |
address->setCountry("USA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
79 |
address->setRegion("CA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
80 |
address->setLocality("Foster City"); // RFC 2426 - defines the difference locality and region. |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
81 |
address->setStreet("1040 East Hillsdale Boulevard"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
82 |
address->setPostcode("94404"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
83 |
contact->saveDetail(address); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
84 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
85 |
this->m_manager->saveContact(contact); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
86 |
// Note that the caller retains ownership of the detail. |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
87 |
delete dept; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
88 |
while (!departmentName.isEmpty()) |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
89 |
departmentName.takeFirst(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
90 |
delete number; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
91 |
delete address; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
92 |
delete contact; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
93 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
94 |
// police - foster city |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
95 |
contact = new QContact(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
96 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
97 |
dept = new QContactOrganization(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
98 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
99 |
departmentName << "Foster City Police department"; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
100 |
dept->setDepartment(departmentName); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
101 |
contact->saveDetail(dept); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
102 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
103 |
number = new QContactPhoneNumber(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
104 |
number->setContexts(QContactDetail::ContextWork); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
105 |
number->setNumber("+1(650)286-3300?"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
106 |
contact->saveDetail(number); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
107 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
108 |
// create address detail |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
109 |
address = new QContactAddress(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
110 |
address->setCountry("USA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
111 |
address->setRegion("CA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
112 |
address->setLocality("Foster City"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
113 |
address->setStreet("1030 East Hillsdale Boulevard"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
114 |
address->setPostcode("94404"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
115 |
contact->saveDetail(address); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
116 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
117 |
this->m_manager->saveContact(contact); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
118 |
delete dept; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
119 |
while (!departmentName.isEmpty()) |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
120 |
departmentName.takeFirst(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
121 |
delete number; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
122 |
delete address; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
123 |
delete contact; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
124 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
125 |
// taxi - Foster City |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
126 |
contact = new QContact(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
127 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
128 |
dept = new QContactOrganization(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
129 |
departmentName << "Foster City Yellow Cab"; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
130 |
dept->setDepartment(departmentName); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
131 |
contact->saveDetail(dept); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
132 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
133 |
number = new QContactPhoneNumber(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
134 |
number->setContexts(QContactDetail::ContextWork); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
135 |
number->setNumber("+1(650)367-9999?"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
136 |
contact->saveDetail(number); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
137 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
138 |
// create address detail |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
139 |
address = new QContactAddress(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
140 |
address->setCountry("USA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
141 |
address->setRegion("CA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
142 |
address->setLocality("Foster City"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
143 |
address->setStreet("1055 foster city blvd"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
144 |
address->setPostcode("94404"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
145 |
contact->saveDetail(address); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
146 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
147 |
this->m_manager->saveContact(contact); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
148 |
delete dept; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
149 |
while (!departmentName.isEmpty()) |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
150 |
departmentName.takeFirst(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
151 |
delete number; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
152 |
delete address; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
153 |
delete contact; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
154 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
155 |
// fire - Menlo Park |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
156 |
contact = new QContact(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
157 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
158 |
dept = new QContactOrganization(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
159 |
departmentName << "Menlo Park fire department"; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
160 |
dept->setDepartment(departmentName); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
161 |
contact->saveDetail(dept); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
162 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
163 |
number = new QContactPhoneNumber(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
164 |
number->setContexts(QContactDetail::ContextWork); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
165 |
number->setNumber("+1(650)688-8400??"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
166 |
contact->saveDetail(number); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
167 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
168 |
// create address detail |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
169 |
address = new QContactAddress(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
170 |
address->setCountry("USA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
171 |
address->setRegion("CA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
172 |
address->setLocality("Menlo Park"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
173 |
address->setStreet("170 Middlefield Road"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
174 |
address->setPostcode("94025"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
175 |
contact->saveDetail(address); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
176 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
177 |
this->m_manager->saveContact(contact); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
178 |
delete dept; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
179 |
while (!departmentName.isEmpty()) |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
180 |
departmentName.takeFirst(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
181 |
delete number; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
182 |
delete address; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
183 |
delete contact; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
184 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
185 |
//701 Laurel Street, Menlo Park, CA? - |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
186 |
// police - Menlo Park |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
187 |
contact = new QContact(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
188 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
189 |
dept = new QContactOrganization(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
190 |
departmentName << "Menlo Park police department"; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
191 |
dept->setDepartment(departmentName); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
192 |
contact->saveDetail(dept); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
193 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
194 |
number = new QContactPhoneNumber(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
195 |
number->setContexts(QContactDetail::ContextWork); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
196 |
number->setNumber("+1(650)858-3328???"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
197 |
contact->saveDetail(number); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
198 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
199 |
// create address detail |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
200 |
address = new QContactAddress(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
201 |
address->setCountry("USA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
202 |
address->setRegion("CA"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
203 |
address->setLocality("Menlo Park"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
204 |
address->setStreet("701 Laurel Street"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
205 |
address->setPostcode("94025"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
206 |
contact->saveDetail(address); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
207 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
208 |
this->m_manager->saveContact(contact); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
209 |
delete dept; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
210 |
while (!departmentName.isEmpty()) |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
211 |
departmentName.takeFirst(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
212 |
delete number; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
213 |
delete address; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
214 |
delete contact; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
215 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
216 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
217 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
218 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
219 |
QStringList ContactsEngine::dataSources() |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
220 |
{ |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
221 |
QStringList availableManagers = QContactManager::availableManagers(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
222 |
availableManagers.removeAll("invalid"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
223 |
foreach(QString managerName, availableManagers) { |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
224 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
225 |
QMap<QString, QString> params; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
226 |
QString managerUri = QContactManager::buildUri(managerName, params); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
227 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
228 |
// Add some parameters to SIM backend so that we can use |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
229 |
// all the stores. |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
230 |
if (managerName == "symbiansim") { |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
231 |
availableManagers.removeAll("symbiansim"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
232 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
233 |
availableManagers.append("symbiansim:adn"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
234 |
params.insert("store", "ADN"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
235 |
managerUri = QContactManager::buildUri(managerName, params); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
236 |
m_availableManagers.insert(availableManagers.last(), managerUri); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
237 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
238 |
availableManagers.append("symbiansim:fdn"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
239 |
params.clear(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
240 |
params.insert("store", "FDN"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
241 |
managerUri = QContactManager::buildUri(managerName, params); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
242 |
m_availableManagers.insert(availableManagers.last(), managerUri); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
243 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
244 |
availableManagers.append("symbiansim:sdn"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
245 |
params.clear(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
246 |
params.insert("store", "SDN"); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
247 |
managerUri = QContactManager::buildUri(managerName, params); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
248 |
m_availableManagers.insert(availableManagers.last(), managerUri); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
249 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
250 |
else { |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
251 |
m_availableManagers.insert(managerName, managerUri); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
252 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
253 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
254 |
return (availableManagers); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
255 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
256 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
257 |
int ContactsEngine::rowCount(const QModelIndex &parent) const |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
258 |
{ |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
259 |
QList<QContact> allContacts; |
23 | 260 |
int rc = 0; |
261 |
if (this->m_manager) |
|
262 |
{ |
|
263 |
allContacts = this->m_manager->contacts(); |
|
264 |
// return stringList.count(); |
|
265 |
if (!allContacts.isEmpty()) |
|
266 |
rc = allContacts.count(); |
|
267 |
} |
|
268 |
return rc; |
|
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
269 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
270 |
|
23 | 271 |
void ContactsEngine::enumerateMgrs() |
272 |
{ |
|
273 |
QStringList mgrs = QContactManager::availableManagers(); |
|
274 |
qDebug() << "Enumerate available Contact Managers:" << endl; |
|
275 |
foreach(QString m, mgrs) |
|
276 |
qDebug() << "\tmgr: " << m << endl; |
|
277 |
qDebug() << endl; |
|
278 |
} |
|
279 |
||
280 |
// dump the current contact manager. |
|
281 |
void ContactsEngine::dumpContactMgr() |
|
282 |
{ |
|
283 |
qDebug() << "Dump Contact Manager:" << endl; |
|
284 |
qDebug() << "\tname: " << this->m_manager->managerName() << endl; |
|
285 |
qDebug() << "\tURI: " << this->m_manager->managerUri() << endl; |
|
286 |
qDebug() << "\tVersion: " << this->m_manager->managerVersion() << endl; |
|
287 |
qDebug() << "\tCount:" << this->m_manager->contacts().count() << endl; |
|
288 |
qDebug() << endl; |
|
289 |
} |
|
290 |
||
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
291 |
QVariant ContactsEngine::data(const QModelIndex &index, int role) const |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
292 |
{ |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
293 |
QVariant rc; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
294 |
QList<QContact> allContacts; |
23 | 295 |
QContact c; |
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
296 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
297 |
allContacts = this->m_manager->contacts(); |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
298 |
|
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
299 |
if (!index.isValid() || index.row() >= allContacts.size()) { |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
300 |
return rc; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
301 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
302 |
if (role == Qt::DisplayRole) { |
23 | 303 |
//rc = QVariant(allContacts.at(index.row()).displayLabel()); |
304 |
c = allContacts.at(index.row()); |
|
305 |
// organizations do not have first and last names. So the displayLabel() is empty. |
|
306 |
QContactDetail cd = c.detail(QContactName::DefinitionName); |
|
307 |
if (cd.isEmpty()) { |
|
308 |
rc = QVariant (c.detail(QContactOrganization::DefinitionName).value(QContactOrganization::FieldDepartment) ); |
|
309 |
} else { |
|
310 |
rc = QVariant ( c.displayLabel()); |
|
311 |
} |
|
19
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
312 |
} |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
313 |
return rc; |
e4b6ee329501
WIP: first draft of contact engine
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
314 |
} |