00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __CONTACT_H__
00022 #define __CONTACT_H__
00023
00024 #include <qtopia/private/palmtoprecord.h>
00025 #include <qtopia/private/recordfields.h>
00026
00027 #include <qstringlist.h>
00028
00029 #if defined(QPC_TEMPLATEDLL)
00030
00031 QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
00032
00033 #endif
00034
00035 class ContactPrivate;
00036 class QPC_EXPORT Contact : public Qtopia::Record
00037 {
00038 friend class DataSet;
00039 public:
00040 Contact();
00041 Contact( const QMap<int, QString> &fromMap );
00042 virtual ~Contact();
00043
00044 static void writeVCard( const QString &filename, const QValueList<Contact> &contacts);
00045 static void writeVCard( const QString &filename, const Contact &c );
00046 static QValueList<Contact> readVCard( const QString &filename );
00047
00048 enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
00049
00050 void setTitle( const QString &v ) { replace( Qtopia::Title, v ); }
00051 void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); }
00052 void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); }
00053 void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); }
00054 void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); }
00055 void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); }
00056 void setFileAs();
00057
00058
00059 void setDefaultEmail( const QString &v );
00060
00061 void insertEmail( const QString &v );
00062 void removeEmail( const QString &v );
00063 void clearEmails();
00064 void insertEmails( const QStringList &v );
00065
00066
00067 void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); }
00068 void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); }
00069 void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); }
00070 void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); }
00071 void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); }
00072 void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); }
00073 void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); }
00074 void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); }
00075 void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); }
00076
00077
00078 void setCompany( const QString &v ) { replace( Qtopia::Company, v ); }
00079 void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); }
00080 void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); }
00081 void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); }
00082 void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); }
00083 void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); }
00084 void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
00085 void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
00086 void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
00087 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
00088 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
00089 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
00090 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
00091 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
00092 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
00093 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
00094 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
00095
00096
00097 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
00098 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
00099 void setBirthday( const QString &v ) { replace( Qtopia::Birthday, v ); }
00100 void setAnniversary( const QString &v ) { replace( Qtopia::Anniversary, v ); }
00101 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
00102 void setChildren( const QString &v );
00103
00104
00105 void setNotes( const QString &v ) { replace( Qtopia::Notes, v); }
00106
00107 bool match( const QString ®exp ) const;
00108
00109
00110 #ifdef QTOPIA_INTERNAL_CONTACT_MRE
00111 bool match( const QRegExp ®exp ) const;
00112 #endif
00113
00114
00115
00116
00117
00118
00119 QString fullName() const;
00120 QString title() const { return find( Qtopia::Title ); }
00121 QString firstName() const { return find( Qtopia::FirstName ); }
00122 QString middleName() const { return find( Qtopia::MiddleName ); }
00123 QString lastName() const { return find( Qtopia::LastName ); }
00124 QString suffix() const { return find( Qtopia::Suffix ); }
00125 QString fileAs() const { return find( Qtopia::FileAs ); }
00126
00127
00128 QString defaultEmail() const { return find( Qtopia::DefaultEmail ); }
00129 QStringList emailList() const;
00130
00131
00132 QString homeStreet() const { return find( Qtopia::HomeStreet ); }
00133 QString homeCity() const { return find( Qtopia::HomeCity ); }
00134 QString homeState() const { return find( Qtopia::HomeState ); }
00135 QString homeZip() const { return find( Qtopia::HomeZip ); }
00136 QString homeCountry() const { return find( Qtopia::HomeCountry ); }
00137 QString homePhone() const { return find( Qtopia::HomePhone ); }
00138 QString homeFax() const { return find( Qtopia::HomeFax ); }
00139 QString homeMobile() const { return find( Qtopia::HomeMobile ); }
00140 QString homeWebpage() const { return find( Qtopia::HomeWebPage ); }
00146 QString displayHomeAddress() const;
00147
00148
00149 QString company() const { return find( Qtopia::Company ); }
00150 QString businessStreet() const { return find( Qtopia::BusinessStreet ); }
00151 QString businessCity() const { return find( Qtopia::BusinessCity ); }
00152 QString businessState() const { return find( Qtopia::BusinessState ); }
00153 QString businessZip() const { return find( Qtopia::BusinessZip ); }
00154 QString businessCountry() const { return find( Qtopia::BusinessCountry ); }
00155 QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); }
00156 QString jobTitle() const { return find( Qtopia::JobTitle ); }
00157 QString department() const { return find( Qtopia::Department ); }
00158 QString office() const { return find( Qtopia::Office ); }
00159 QString businessPhone() const { return find( Qtopia::BusinessPhone ); }
00160 QString businessFax() const { return find( Qtopia::BusinessFax ); }
00161 QString businessMobile() const { return find( Qtopia::BusinessMobile ); }
00162 QString businessPager() const { return find( Qtopia::BusinessPager ); }
00163 QString profession() const { return find( Qtopia::Profession ); }
00164 QString assistant() const { return find( Qtopia::Assistant ); }
00165 QString manager() const { return find( Qtopia::Manager ); }
00171 QString displayBusinessAddress() const;
00172
00173
00174 QString spouse() const { return find( Qtopia::Spouse ); }
00175 QString gender() const { return find( Qtopia::Gender ); }
00176 QString birthday() const { return find( Qtopia::Birthday ); }
00177 QString anniversary() const { return find( Qtopia::Anniversary ); }
00178 QString nickname() const { return find( Qtopia::Nickname ); }
00179 QString children() const { return find( Qtopia::Children ); }
00180 QStringList childrenList() const;
00181
00182
00183 QString notes() const { return find( Qtopia::Notes ); }
00184 QString groups() const { return find( Qtopia::Groups ); }
00185 QStringList groupList() const;
00186
00187
00188
00189
00190
00191 static QStringList fields();
00192 static QStringList trfields();
00193
00194 QString toRichText() const;
00195 QMap<int, QString> toMap() const;
00196 QString field( int key ) const { return find( key ); }
00197
00198
00199
00200 void saveJournal( journal_action action, const QString &key = QString::null );
00201 void save( QString &buf ) const;
00202
00203 void setUid( int i )
00204 { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); }
00205
00206 private:
00207 friend class AbEditor;
00208 friend class AbTable;
00209 friend class AddressBookAccessPrivate;
00210 friend class XMLIO;
00211
00212 QString emailSeparator() const { return " "; }
00213
00214 void setEmails( const QString &v );
00215 QString emails() const { return find( Qtopia::Emails ); }
00216
00217 void insert( int key, const QString &value );
00218 void replace( int key, const QString &value );
00219 QString find( int key ) const;
00220
00221 QString displayAddress( const QString &street,
00222 const QString &city,
00223 const QString &state,
00224 const QString &zip,
00225 const QString &country ) const;
00226
00227 Qtopia::UidGen &uidGen() { return sUidGen; }
00228 static Qtopia::UidGen sUidGen;
00229 QMap<int, QString> mMap;
00230 ContactPrivate *d;
00231 };
00232
00233
00234 inline void Contact::insertEmail( const QString &v )
00235 {
00236
00237 QString e = v.simplifyWhiteSpace();
00238 QString def = defaultEmail();
00239
00240
00241 if ( def.isEmpty() ) {
00242 setDefaultEmail( e );
00243 return;
00244 }
00245
00246
00247 QString emailsStr = find( Qtopia::Emails );
00248 if ( emailsStr.contains( e ))
00249 return;
00250 if ( !emailsStr.isEmpty() )
00251 emailsStr += emailSeparator();
00252 emailsStr += e;
00253 replace( Qtopia::Emails, emailsStr );
00254 }
00255
00256 inline void Contact::removeEmail( const QString &v )
00257 {
00258 QString e = v.simplifyWhiteSpace();
00259 QString def = defaultEmail();
00260 QString emailsStr = find( Qtopia::Emails );
00261 QStringList emails = emailList();
00262
00263
00264 if ( !emailsStr.contains( e ) )
00265 return;
00266
00267
00268
00269 emails.remove( e );
00270
00271 emailsStr = emails.join(emailSeparator());
00272 replace( Qtopia::Emails, emailsStr );
00273
00274
00275 if ( def == e ) {
00276
00277 if ( !emails.count() )
00278 clearEmails();
00279 else
00280 setDefaultEmail( emails.first() );
00281 }
00282 }
00283 inline void Contact::clearEmails()
00284 {
00285 mMap.remove( Qtopia::DefaultEmail );
00286 mMap.remove( Qtopia::Emails );
00287 }
00288 inline void Contact::setDefaultEmail( const QString &v )
00289 {
00290 QString e = v.simplifyWhiteSpace();
00291
00292
00293 replace( Qtopia::DefaultEmail, e );
00294
00295 if ( !e.isEmpty() )
00296 insertEmail( e );
00297
00298 }
00299
00300 inline void Contact::insertEmails( const QStringList &v )
00301 {
00302 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
00303 insertEmail( *it );
00304 }
00305
00306 #endif