-rw-r--r-- | library/backend/contact.h | 102 |
1 files changed, 93 insertions, 9 deletions
diff --git a/library/backend/contact.h b/library/backend/contact.h index a74cbbe..4999430 100644 --- a/library/backend/contact.h +++ b/library/backend/contact.h | |||
@@ -1,12 +1,12 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
@@ -16,24 +16,24 @@ | |||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #ifndef __CONTACT_H__ | 21 | #ifndef __CONTACT_H__ |
22 | #define __CONTACT_H__ | 22 | #define __CONTACT_H__ |
23 | 23 | ||
24 | #include <qpe/palmtoprecord.h> | 24 | #include <qtopia/private/palmtoprecord.h> |
25 | #include <qpe/recordfields.h> | 25 | #include <qtopia/private/recordfields.h> |
26 | 26 | ||
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | 28 | ||
29 | #if defined(QPC_TEMPLATEDLL) | 29 | #if defined(QPC_TEMPLATEDLL) |
30 | // MOC_SKIP_BEGIN | 30 | // MOC_SKIP_BEGIN |
31 | template class QPC_EXPORT QMap<int, QString>; | 31 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; |
32 | // MOC_SKIP_END | 32 | // MOC_SKIP_END |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | class ContactPrivate; | 35 | class ContactPrivate; |
36 | class QPC_EXPORT Contact : public Qtopia::Record | 36 | class QPC_EXPORT Contact : public Qtopia::Record |
37 | { | 37 | { |
38 | friend class DataSet; | 38 | friend class DataSet; |
39 | public: | 39 | public: |
@@ -51,19 +51,22 @@ public: | |||
51 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } | 51 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } |
52 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } | 52 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } |
53 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } | 53 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } |
54 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } | 54 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } |
55 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } | 55 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } |
56 | void setFileAs(); | 56 | void setFileAs(); |
57 | 57 | ||
58 | // default email address | 58 | // default email address |
59 | void setDefaultEmail( const QString &v ) { replace( Qtopia::DefaultEmail, v ); } | 59 | void setDefaultEmail( const QString &v ); |
60 | // the emails should be seperated by a semicolon | 60 | // inserts email to list and ensure's doesn't already exist |
61 | void setEmails( const QString &v ); | 61 | void insertEmail( const QString &v ); |
62 | void removeEmail( const QString &v ); | ||
63 | void clearEmails(); | ||
64 | void insertEmails( const QStringList &v ); | ||
62 | 65 | ||
63 | // home | 66 | // home |
64 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } | 67 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } |
65 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } | 68 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } |
66 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } | 69 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } |
67 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } | 70 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } |
68 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } | 71 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } |
69 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } | 72 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } |
@@ -118,17 +121,16 @@ public: | |||
118 | QString firstName() const { return find( Qtopia::FirstName ); } | 121 | QString firstName() const { return find( Qtopia::FirstName ); } |
119 | QString middleName() const { return find( Qtopia::MiddleName ); } | 122 | QString middleName() const { return find( Qtopia::MiddleName ); } |
120 | QString lastName() const { return find( Qtopia::LastName ); } | 123 | QString lastName() const { return find( Qtopia::LastName ); } |
121 | QString suffix() const { return find( Qtopia::Suffix ); } | 124 | QString suffix() const { return find( Qtopia::Suffix ); } |
122 | QString fileAs() const { return find( Qtopia::FileAs ); } | 125 | QString fileAs() const { return find( Qtopia::FileAs ); } |
123 | 126 | ||
124 | 127 | ||
125 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } | 128 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } |
126 | QString emails() const { return find( Qtopia::Emails ); } | ||
127 | QStringList emailList() const; | 129 | QStringList emailList() const; |
128 | 130 | ||
129 | // home | 131 | // home |
130 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } | 132 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } |
131 | QString homeCity() const { return find( Qtopia::HomeCity ); } | 133 | QString homeCity() const { return find( Qtopia::HomeCity ); } |
132 | QString homeState() const { return find( Qtopia::HomeState ); } | 134 | QString homeState() const { return find( Qtopia::HomeState ); } |
133 | QString homeZip() const { return find( Qtopia::HomeZip ); } | 135 | QString homeZip() const { return find( Qtopia::HomeZip ); } |
134 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } | 136 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } |
@@ -197,26 +199,108 @@ public: | |||
197 | // journaling... | 199 | // journaling... |
198 | void saveJournal( journal_action action, const QString &key = QString::null ); | 200 | void saveJournal( journal_action action, const QString &key = QString::null ); |
199 | void save( QString &buf ) const; | 201 | void save( QString &buf ) const; |
200 | 202 | ||
201 | void setUid( int i ) | 203 | void setUid( int i ) |
202 | { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } | 204 | { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } |
203 | 205 | ||
204 | private: | 206 | private: |
207 | friend class AbEditor; | ||
205 | friend class AbTable; | 208 | friend class AbTable; |
209 | friend class AddressBookAccessPrivate; | ||
210 | friend class XMLIO; | ||
211 | |||
212 | QString emailSeparator() const { return " "; } | ||
213 | // the emails should be seperated by a comma | ||
214 | void setEmails( const QString &v ); | ||
215 | QString emails() const { return find( Qtopia::Emails ); } | ||
216 | |||
206 | void insert( int key, const QString &value ); | 217 | void insert( int key, const QString &value ); |
207 | void replace( int key, const QString &value ); | 218 | void replace( int key, const QString &value ); |
208 | QString find( int key ) const; | 219 | QString find( int key ) const; |
209 | 220 | ||
210 | QString displayAddress( const QString &street, | 221 | QString displayAddress( const QString &street, |
211 | const QString &city, | 222 | const QString &city, |
212 | const QString &state, | 223 | const QString &state, |
213 | const QString &zip, | 224 | const QString &zip, |
214 | const QString &country ) const; | 225 | const QString &country ) const; |
215 | 226 | ||
216 | Qtopia::UidGen &uidGen() { return sUidGen; } | 227 | Qtopia::UidGen &uidGen() { return sUidGen; } |
217 | static Qtopia::UidGen sUidGen; | 228 | static Qtopia::UidGen sUidGen; |
218 | QMap<int, QString> mMap; | 229 | QMap<int, QString> mMap; |
219 | ContactPrivate *d; | 230 | ContactPrivate *d; |
220 | }; | 231 | }; |
221 | 232 | ||
233 | // these methods are inlined to keep binary compatability with Qtopia 1.5 | ||
234 | inline void Contact::insertEmail( const QString &v ) | ||
235 | { | ||
236 | //qDebug("insertEmail %s", v.latin1()); | ||
237 | QString e = v.simplifyWhiteSpace(); | ||
238 | QString def = defaultEmail(); | ||
239 | |||
240 | // if no default, set it as the default email and don't insert | ||
241 | if ( def.isEmpty() ) { | ||
242 | setDefaultEmail( e ); // will insert into the list for us | ||
243 | return; | ||
244 | } | ||
245 | |||
246 | // otherwise, insert assuming doesn't already exist | ||
247 | QString emailsStr = find( Qtopia::Emails ); | ||
248 | if ( emailsStr.contains( e )) | ||
249 | return; | ||
250 | if ( !emailsStr.isEmpty() ) | ||
251 | emailsStr += emailSeparator(); | ||
252 | emailsStr += e; | ||
253 | replace( Qtopia::Emails, emailsStr ); | ||
254 | } | ||
255 | |||
256 | inline void Contact::removeEmail( const QString &v ) | ||
257 | { | ||
258 | QString e = v.simplifyWhiteSpace(); | ||
259 | QString def = defaultEmail(); | ||
260 | QString emailsStr = find( Qtopia::Emails ); | ||
261 | QStringList emails = emailList(); | ||
262 | |||
263 | // otherwise, must first contain it | ||
264 | if ( !emailsStr.contains( e ) ) | ||
265 | return; | ||
266 | |||
267 | // remove it | ||
268 | //qDebug(" removing email from list %s", e.latin1()); | ||
269 | emails.remove( e ); | ||
270 | // reset the string | ||
271 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator | ||
272 | replace( Qtopia::Emails, emailsStr ); | ||
273 | |||
274 | // if default, then replace the default email with the first one | ||
275 | if ( def == e ) { | ||
276 | //qDebug("removeEmail is default; setting new default"); | ||
277 | if ( !emails.count() ) | ||
278 | clearEmails(); | ||
279 | else // setDefaultEmail will remove e from the list | ||
280 | setDefaultEmail( emails.first() ); | ||
281 | } | ||
282 | } | ||
283 | inline void Contact::clearEmails() | ||
284 | { | ||
285 | mMap.remove( Qtopia::DefaultEmail ); | ||
286 | mMap.remove( Qtopia::Emails ); | ||
287 | } | ||
288 | inline void Contact::setDefaultEmail( const QString &v ) | ||
289 | { | ||
290 | QString e = v.simplifyWhiteSpace(); | ||
291 | |||
292 | //qDebug("Contact::setDefaultEmail %s", e.latin1()); | ||
293 | replace( Qtopia::DefaultEmail, e ); | ||
294 | |||
295 | if ( !e.isEmpty() ) | ||
296 | insertEmail( e ); | ||
297 | |||
298 | } | ||
299 | |||
300 | inline void Contact::insertEmails( const QStringList &v ) | ||
301 | { | ||
302 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) | ||
303 | insertEmail( *it ); | ||
304 | } | ||
305 | |||
222 | #endif | 306 | #endif |