-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,85 +1,88 @@ | |||
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. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
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: |
40 | Contact(); | 40 | Contact(); |
41 | Contact( const QMap<int, QString> &fromMap ); | 41 | Contact( const QMap<int, QString> &fromMap ); |
42 | virtual ~Contact(); | 42 | virtual ~Contact(); |
43 | 43 | ||
44 | static void writeVCard( const QString &filename, const QValueList<Contact> &contacts); | 44 | static void writeVCard( const QString &filename, const QValueList<Contact> &contacts); |
45 | static void writeVCard( const QString &filename, const Contact &c ); | 45 | static void writeVCard( const QString &filename, const Contact &c ); |
46 | static QValueList<Contact> readVCard( const QString &filename ); | 46 | static QValueList<Contact> readVCard( const QString &filename ); |
47 | 47 | ||
48 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 48 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
49 | 49 | ||
50 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } | 50 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } |
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 ); } |
70 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } | 73 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } |
71 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } | 74 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } |
72 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } | 75 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } |
73 | 76 | ||
74 | // business | 77 | // business |
75 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } | 78 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } |
76 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } | 79 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } |
77 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } | 80 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } |
78 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } | 81 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } |
79 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } | 82 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } |
80 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } | 83 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } |
81 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } | 84 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } |
82 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } | 85 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } |
83 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } | 86 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } |
84 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } | 87 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } |
85 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } | 88 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } |
@@ -102,49 +105,48 @@ public: | |||
102 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } | 105 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } |
103 | 106 | ||
104 | bool match( const QString ®exp ) const; | 107 | bool match( const QString ®exp ) const; |
105 | 108 | ||
106 | // DON'T ATTEMPT TO USE THIS | 109 | // DON'T ATTEMPT TO USE THIS |
107 | #ifdef QTOPIA_INTERNAL_CONTACT_MRE | 110 | #ifdef QTOPIA_INTERNAL_CONTACT_MRE |
108 | bool match( const QRegExp ®exp ) const; | 111 | bool match( const QRegExp ®exp ) const; |
109 | #endif | 112 | #endif |
110 | 113 | ||
111 | // // custom | 114 | // // custom |
112 | // void setCustomField( const QString &key, const QString &v ) | 115 | // void setCustomField( const QString &key, const QString &v ) |
113 | // { replace(Custom- + key, v ); } | 116 | // { replace(Custom- + key, v ); } |
114 | 117 | ||
115 | // name | 118 | // name |
116 | QString fullName() const; | 119 | QString fullName() const; |
117 | QString title() const { return find( Qtopia::Title ); } | 120 | QString title() const { return find( Qtopia::Title ); } |
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 ); } |
135 | QString homePhone() const { return find( Qtopia::HomePhone ); } | 137 | QString homePhone() const { return find( Qtopia::HomePhone ); } |
136 | QString homeFax() const { return find( Qtopia::HomeFax ); } | 138 | QString homeFax() const { return find( Qtopia::HomeFax ); } |
137 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } | 139 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } |
138 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } | 140 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } |
139 | /** Multi line string containing all non-empty address info in the form | 141 | /** Multi line string containing all non-empty address info in the form |
140 | * Street | 142 | * Street |
141 | * City, State Zip | 143 | * City, State Zip |
142 | * Country | 144 | * Country |
143 | */ | 145 | */ |
144 | QString displayHomeAddress() const; | 146 | QString displayHomeAddress() const; |
145 | 147 | ||
146 | // business | 148 | // business |
147 | QString company() const { return find( Qtopia::Company ); } | 149 | QString company() const { return find( Qtopia::Company ); } |
148 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } | 150 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } |
149 | QString businessCity() const { return find( Qtopia::BusinessCity ); } | 151 | QString businessCity() const { return find( Qtopia::BusinessCity ); } |
150 | QString businessState() const { return find( Qtopia::BusinessState ); } | 152 | QString businessState() const { return find( Qtopia::BusinessState ); } |
@@ -181,42 +183,124 @@ public: | |||
181 | QString notes() const { return find( Qtopia::Notes ); } | 183 | QString notes() const { return find( Qtopia::Notes ); } |
182 | QString groups() const { return find( Qtopia::Groups ); } | 184 | QString groups() const { return find( Qtopia::Groups ); } |
183 | QStringList groupList() const; | 185 | QStringList groupList() const; |
184 | 186 | ||
185 | // // custom | 187 | // // custom |
186 | // const QString &customField( const QString &key ) | 188 | // const QString &customField( const QString &key ) |
187 | // { return find( Custom- + key ); } | 189 | // { return find( Custom- + key ); } |
188 | 190 | ||
189 | static QStringList fields(); | 191 | static QStringList fields(); |
190 | static QStringList trfields(); | 192 | static QStringList trfields(); |
191 | 193 | ||
192 | QString toRichText() const; | 194 | QString toRichText() const; |
193 | QMap<int, QString> toMap() const; | 195 | QMap<int, QString> toMap() const; |
194 | QString field( int key ) const { return find( key ); } | 196 | QString field( int key ) const { return find( key ); } |
195 | 197 | ||
196 | 198 | ||
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 |