|
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> |
|
31 |
|
32 QTM_BEGIN_NAMESPACE |
|
33 class QContactManager; |
|
34 QTM_END_NAMESPACE |
|
35 |
|
36 QTM_USE_NAMESPACE |
|
37 |
|
38 class MsgContactHandler |
|
39 { |
|
40 |
|
41 public: |
|
42 |
|
43 /** |
|
44 * This shall resolve contact number with display name |
|
45 * @param contactNumber number to resolve |
|
46 * @param displayName resolved name |
|
47 * @param countPhoneNumber specifies number of contacts inside |
|
48 * the resolved contact ex mobile, home, office etc |
|
49 * @return contacts unique localId |
|
50 */ |
|
51 static int resolveContactDisplayName(const QString& contactNumber, |
|
52 QString& displayName, |
|
53 int& countPhoneNumber) |
|
54 { |
|
55 QContactManager * phonebookManager; |
|
56 QContactDetailFilter phoneFilter; |
|
57 phonebookManager = new QContactManager("symbian"); |
|
58 phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, |
|
59 QContactPhoneNumber::FieldNumber); |
|
60 |
|
61 QVariant address(contactNumber); |
|
62 phoneFilter.setValue(address); |
|
63 phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith); |
|
64 |
|
65 QList<QContact> matchingContacts = |
|
66 phonebookManager->contacts(phoneFilter); |
|
67 |
|
68 if (matchingContacts.count() > 0) |
|
69 { |
|
70 // Fill the contact details |
|
71 QContact match = matchingContacts.at(0); |
|
72 |
|
73 displayName = match.displayLabel(); |
|
74 QList<QContactPhoneNumber> numbers = |
|
75 match.details<QContactPhoneNumber> (); |
|
76 countPhoneNumber = numbers.count(); |
|
77 return match.localId(); |
|
78 } |
|
79 else // no matching contacts |
|
80 { |
|
81 displayName = contactNumber; |
|
82 return -1; |
|
83 } |
|
84 } |
|
85 |
|
86 /** |
|
87 * This shall resolve contact number with display name |
|
88 * @param contactNumber number to resolve |
|
89 * @param fieldName specifies filter name |
|
90 * @param fieldType specifies filter type |
|
91 * @return contact unique local id |
|
92 */ |
|
93 static int resolveContactDisplayName(const QString& contactNumber, |
|
94 const QString& fieldName, |
|
95 const QString& fieldType) |
|
96 { |
|
97 int contactId = -1; |
|
98 |
|
99 QContactManager phonebookManager("symbian"); |
|
100 |
|
101 QContactDetailFilter phoneFilter; |
|
102 phoneFilter.setDetailDefinitionName(fieldName, fieldType); |
|
103 phoneFilter.setValue(contactNumber); |
|
104 phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith); |
|
105 |
|
106 QList<QContact> |
|
107 matchingContacts = phonebookManager.contacts(phoneFilter); |
|
108 |
|
109 if (matchingContacts.count() > 0) |
|
110 { |
|
111 contactId = matchingContacts.at(0).localId(); |
|
112 } |
|
113 return contactId; |
|
114 } |
|
115 |
|
116 //--------------------------------------------------------------- |
|
117 // findContactList |
|
118 // Finds the contact matching the phone number. |
|
119 // @param phoneNumber Phone number to be matchned. |
|
120 // @return List of matching contacts. |
|
121 //--------------------------------------------------------------- |
|
122 static QList<QContact> findContactList(const QString &phoneNumber) |
|
123 { |
|
124 QContactManager phonebookManager("symbian"); |
|
125 |
|
126 QContactDetailFilter phoneFilter; |
|
127 phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, |
|
128 QContactPhoneNumber::FieldNumber); |
|
129 phoneFilter.setValue(phoneNumber); |
|
130 phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith); |
|
131 |
|
132 QList<QContact> matchingContacts = phonebookManager.contacts(phoneFilter); |
|
133 |
|
134 return matchingContacts; |
|
135 } |
|
136 |
|
137 /** |
|
138 * Get display-name of a contact from VCard. |
|
139 * @param filePath, VCard file-path |
|
140 * @return display-name |
|
141 */ |
|
142 |
|
143 static QString getVCardDisplayName(QString& filePath) |
|
144 { |
|
145 QString displayName = QString(""); |
|
146 //open file for parsing |
|
147 QFile file(filePath); |
|
148 if (!file.open(QIODevice::ReadOnly)) |
|
149 { |
|
150 return displayName; |
|
151 } |
|
152 // parse contents |
|
153 QVersitReader reader; |
|
154 reader.setDevice(&file); |
|
155 if (reader.startReading()) |
|
156 { |
|
157 if (reader.waitForFinished()) |
|
158 { |
|
159 QList<QVersitDocument> versitDocuments = reader.results(); |
|
160 // Use the resulting document |
|
161 if (versitDocuments.count() > 0) |
|
162 { |
|
163 QVersitContactImporter importer; |
|
164 QList<QContact> contacts = |
|
165 importer.importContacts(versitDocuments); |
|
166 // get display-name |
|
167 if (contacts.count() > 0) |
|
168 { |
|
169 //resolveSynthesizedDisplayLabel |
|
170 QContactManager* contactManager = |
|
171 new QContactManager("symbian"); |
|
172 displayName |
|
173 = contactManager->synthesizedDisplayLabel(contacts[0]); |
|
174 delete contactManager; |
|
175 } |
|
176 } |
|
177 } |
|
178 } |
|
179 file.close(); |
|
180 return displayName; |
|
181 } |
|
182 }; |
|
183 |
|
184 #endif /* MSGCONTACTHANDLER_H_ */ |