37
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: This header handles the phonebook manager resolve number static
|
|
15 |
* functions.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#ifndef MSGCONTACTHANDLER_H_
|
|
20 |
#define MSGCONTACTHANDLER_H_
|
|
21 |
|
|
22 |
#include <qmobilityglobal.h>
|
|
23 |
|
|
24 |
#include <qtcontacts.h>
|
|
25 |
#include <qcontactfilter.h>
|
|
26 |
#include <qcontactdetailfilter.h>
|
|
27 |
#include <QFile>
|
|
28 |
#include <qversitcontactimporter.h>
|
|
29 |
#include <qversitdocument.h>
|
|
30 |
#include <qversitreader.h>
|
56
|
31 |
#include <qcontactid.h>
|
37
|
32 |
|
|
33 |
QTM_BEGIN_NAMESPACE
|
|
34 |
class QContactManager;
|
|
35 |
QTM_END_NAMESPACE
|
|
36 |
|
|
37 |
QTM_USE_NAMESPACE
|
|
38 |
|
|
39 |
class MsgContactHandler
|
|
40 |
{
|
56
|
41 |
|
37
|
42 |
public:
|
|
43 |
|
|
44 |
/**
|
|
45 |
* This shall resolve contact number with display name
|
|
46 |
* @param contactNumber number to resolve
|
|
47 |
* @param displayName resolved name
|
56
|
48 |
* @param countPhoneNumber specifies number of contacts inside
|
37
|
49 |
* the resolved contact ex mobile, home, office etc
|
|
50 |
* @return contacts unique localId
|
|
51 |
*/
|
|
52 |
static int resolveContactDisplayName(const QString& contactNumber,
|
|
53 |
QString& displayName,
|
|
54 |
int& countPhoneNumber)
|
|
55 |
{
|
|
56 |
QContactManager phonebookManager;
|
|
57 |
QVariant address(contactNumber);
|
|
58 |
|
|
59 |
// apply filter on phone number field
|
|
60 |
QContactDetailFilter phoneFilter;
|
|
61 |
phoneFilter.setDetailDefinitionName(
|
|
62 |
QContactPhoneNumber::DefinitionName,
|
|
63 |
QContactPhoneNumber::FieldNumber);
|
|
64 |
|
|
65 |
phoneFilter.setValue(address);
|
|
66 |
phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
|
|
67 |
QList<QContact> matchingContacts =
|
|
68 |
phonebookManager.contacts(phoneFilter);
|
|
69 |
if (matchingContacts.count() > 0)
|
|
70 |
{
|
|
71 |
// Fill the contact details
|
|
72 |
QContact match = matchingContacts.at(0);
|
|
73 |
|
|
74 |
displayName = match.displayLabel();
|
|
75 |
QList<QContactPhoneNumber> numbers =
|
|
76 |
match.details<QContactPhoneNumber> ();
|
|
77 |
countPhoneNumber = numbers.count();
|
|
78 |
return match.localId();
|
|
79 |
}
|
|
80 |
|
|
81 |
// apply filter on email address field
|
|
82 |
QContactDetailFilter emailFilter;
|
|
83 |
emailFilter.setDetailDefinitionName(
|
|
84 |
QContactEmailAddress::DefinitionName,
|
|
85 |
QContactEmailAddress::FieldEmailAddress);
|
|
86 |
|
|
87 |
emailFilter.setValue(address);
|
|
88 |
emailFilter.setMatchFlags(QContactFilter::MatchExactly);
|
|
89 |
matchingContacts = phonebookManager.contacts(emailFilter);
|
|
90 |
if ( matchingContacts.count() > 0 )
|
|
91 |
{
|
|
92 |
// Fill the contact details
|
|
93 |
QContact match = matchingContacts.at(0);
|
|
94 |
|
|
95 |
displayName = match.displayLabel();
|
|
96 |
QList<QContactEmailAddress> numbers =
|
|
97 |
match.details<QContactEmailAddress> ();
|
|
98 |
countPhoneNumber = numbers.count();
|
|
99 |
return match.localId();
|
|
100 |
}
|
|
101 |
|
|
102 |
// no matching contact
|
|
103 |
displayName = contactNumber;
|
|
104 |
return -1;
|
|
105 |
}
|
|
106 |
|
|
107 |
/**
|
|
108 |
* This shall resolve contact number with display name
|
|
109 |
* @param contactNumber number to resolve
|
|
110 |
* @param fieldName specifies filter name
|
|
111 |
* @param fieldType specifies filter type
|
|
112 |
* @return contact unique local id
|
|
113 |
*/
|
|
114 |
static int resolveContactDisplayName(const QString& contactNumber,
|
|
115 |
const QString& fieldName,
|
|
116 |
const QString& fieldType)
|
|
117 |
{
|
|
118 |
int contactId = -1;
|
|
119 |
|
|
120 |
QContactManager phonebookManager("symbian");
|
|
121 |
|
|
122 |
QContactDetailFilter phoneFilter;
|
|
123 |
phoneFilter.setDetailDefinitionName(fieldName, fieldType);
|
|
124 |
phoneFilter.setValue(contactNumber);
|
|
125 |
phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
|
|
126 |
|
|
127 |
QList<QContact>
|
|
128 |
matchingContacts = phonebookManager.contacts(phoneFilter);
|
|
129 |
|
|
130 |
if (matchingContacts.count() > 0)
|
|
131 |
{
|
|
132 |
contactId = matchingContacts.at(0).localId();
|
|
133 |
}
|
|
134 |
return contactId;
|
|
135 |
}
|
|
136 |
|
|
137 |
//---------------------------------------------------------------
|
|
138 |
// findContactList
|
|
139 |
// Finds the contact matching the phone number.
|
|
140 |
// @param phoneNumber Phone number to be matchned.
|
|
141 |
// @return List of matching contacts.
|
|
142 |
//---------------------------------------------------------------
|
|
143 |
static QList<QContact> findContactList(const QString &phoneNumber)
|
|
144 |
{
|
|
145 |
QContactManager phonebookManager("symbian");
|
|
146 |
|
|
147 |
QContactDetailFilter phoneFilter;
|
|
148 |
phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName,
|
|
149 |
QContactPhoneNumber::FieldNumber);
|
|
150 |
phoneFilter.setValue(phoneNumber);
|
|
151 |
phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
|
56
|
152 |
|
37
|
153 |
QList<QContact> matchingContacts = phonebookManager.contacts(phoneFilter);
|
|
154 |
|
|
155 |
return matchingContacts;
|
|
156 |
}
|
56
|
157 |
|
37
|
158 |
/**
|
|
159 |
* Get display-name of a contact from VCard.
|
|
160 |
* @param filePath, VCard file-path
|
|
161 |
* @return display-name
|
|
162 |
*/
|
|
163 |
|
|
164 |
static QString getVCardDisplayName(QString& filePath)
|
|
165 |
{
|
|
166 |
QString displayName = QString("");
|
|
167 |
//open file for parsing
|
|
168 |
QFile file(filePath);
|
|
169 |
if (!file.open(QIODevice::ReadOnly))
|
|
170 |
{
|
|
171 |
return displayName;
|
|
172 |
}
|
|
173 |
// parse contents
|
|
174 |
QVersitReader reader;
|
|
175 |
reader.setDevice(&file);
|
|
176 |
if (reader.startReading())
|
|
177 |
{
|
|
178 |
if (reader.waitForFinished())
|
|
179 |
{
|
|
180 |
QList<QVersitDocument> versitDocuments = reader.results();
|
|
181 |
// Use the resulting document
|
|
182 |
if (versitDocuments.count() > 0)
|
|
183 |
{
|
|
184 |
QVersitContactImporter importer;
|
|
185 |
bool import_docs = importer.importDocuments(versitDocuments);
|
|
186 |
if(import_docs)
|
|
187 |
{
|
|
188 |
QList<QContact> contacts = importer.contacts();
|
|
189 |
// get display-name
|
|
190 |
if (contacts.count() > 0)
|
|
191 |
{
|
|
192 |
//resolveSynthesizedDisplayLabel
|
|
193 |
QContactManager* contactManager =
|
|
194 |
new QContactManager("symbian");
|
|
195 |
displayName
|
|
196 |
= contactManager->synthesizedDisplayLabel(contacts[0]);
|
|
197 |
delete contactManager;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
}
|
|
201 |
}
|
|
202 |
}
|
|
203 |
file.close();
|
|
204 |
return displayName;
|
|
205 |
}
|
56
|
206 |
|
|
207 |
/**
|
|
208 |
* Get list of self-addresses
|
|
209 |
* @return QStringList, list of self-addresses
|
|
210 |
*/
|
|
211 |
static QStringList selfAddresses()
|
|
212 |
{
|
|
213 |
QStringList selfAddrs;
|
|
214 |
QContactManager* contactManager =
|
|
215 |
new QContactManager("symbian");
|
|
216 |
QContactLocalId selfId = contactManager->selfContactId();
|
|
217 |
if( (selfId == 0) ||
|
|
218 |
(contactManager->error() == QContactManager::DoesNotExistError) )
|
|
219 |
{
|
|
220 |
// if no self-address exists
|
|
221 |
return selfAddrs;
|
|
222 |
}
|
|
223 |
|
|
224 |
QContact selfContact = contactManager->contact(selfId);
|
|
225 |
|
|
226 |
// append numbers to the list of self-addresses
|
|
227 |
QList<QContactPhoneNumber> selfPhoneNumbers =
|
|
228 |
selfContact.details<QContactPhoneNumber>();
|
|
229 |
int selfNumCount = selfPhoneNumbers.count();
|
|
230 |
for(int i=0; i< selfNumCount; i++)
|
|
231 |
{
|
|
232 |
selfAddrs << selfPhoneNumbers.at(i).number();
|
|
233 |
}
|
|
234 |
|
|
235 |
// append email-addresses to the list
|
|
236 |
QList<QContactEmailAddress> selfEmailAddrs =
|
|
237 |
selfContact.details<QContactEmailAddress>();
|
|
238 |
int selfEmailAddrCount = selfEmailAddrs.count();
|
|
239 |
for(int i=0; i< selfEmailAddrCount; i++)
|
|
240 |
{
|
|
241 |
selfAddrs << selfEmailAddrs.at(i).emailAddress();
|
|
242 |
}
|
|
243 |
return selfAddrs;
|
|
244 |
}
|
|
245 |
|
37
|
246 |
};
|
|
247 |
|
|
248 |
#endif /* MSGCONTACTHANDLER_H_ */
|