summaryrefslogtreecommitdiff
path: root/library/backend/contact.h
Unidiff
Diffstat (limited to 'library/backend/contact.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/contact.h102
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,43 +1,43 @@
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
31template class QPC_EXPORT QMap<int, QString>; 31QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
32// MOC_SKIP_END 32// MOC_SKIP_END
33#endif 33#endif
34 34
35class ContactPrivate; 35class ContactPrivate;
36class QPC_EXPORT Contact : public Qtopia::Record 36class QPC_EXPORT Contact : public Qtopia::Record
37{ 37{
38 friend class DataSet; 38 friend class DataSet;
39public: 39public:
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
@@ -47,27 +47,30 @@ public:
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
@@ -114,25 +117,24 @@ public:
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 // email 127 // email
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 ); }
@@ -193,30 +195,112 @@ public:
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
204private: 206private:
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
234inline 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
256inline 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}
283inline void Contact::clearEmails()
284{
285 mMap.remove( Qtopia::DefaultEmail );
286 mMap.remove( Qtopia::Emails );
287}
288inline 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
300inline 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