summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/ocontact.h
authoreilers <eilers>2002-09-27 17:11:44 (UTC)
committer eilers <eilers>2002-09-27 17:11:44 (UTC)
commit44c98b497ff1cb8cddba10b56435f136a583cce2 (patch) (unidiff)
treed76ab641b0a9151031f1ec7ac19ff00c11f82b53 /libopie2/opiepim/ocontact.h
parentd44b205c9009af71db036b3951363a91110e1c20 (diff)
downloadopie-44c98b497ff1cb8cddba10b56435f136a583cce2.zip
opie-44c98b497ff1cb8cddba10b56435f136a583cce2.tar.gz
opie-44c98b497ff1cb8cddba10b56435f136a583cce2.tar.bz2
Added API for accessing the Contact-Database ! It is compiling, but
please do not expect that anything is working ! I will debug that stuff in the next time .. Please read README_COMPILE for compiling !
Diffstat (limited to 'libopie2/opiepim/ocontact.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ocontact.h311
1 files changed, 311 insertions, 0 deletions
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h
new file mode 100644
index 0000000..e0555c8
--- a/dev/null
+++ b/libopie2/opiepim/ocontact.h
@@ -0,0 +1,311 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef __OCONTACT_H__
22#define __OCONTACT_H__
23
24#include <opie/opimrecord.h>
25#include <qpe/recordfields.h>
26
27#include <qstringlist.h>
28
29#if defined(QPC_TEMPLATEDLL)
30// MOC_SKIP_BEGIN
31QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
32// MOC_SKIP_END
33#endif
34
35class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se)
36class QPC_EXPORT OContact : public OPimRecord
37{
38 friend class DataSet;
39public:
40 OContact();
41 OContact( const QMap<int, QString> &fromMap );
42 virtual ~OContact();
43
44 static void writeVCard( const QString &filename, const QValueList<OContact> &contacts);
45 static void writeVCard( const QString &filename, const OContact &c );
46 static QValueList<OContact> readVCard( const QString &filename );
47
48 enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
49
50 void setTitle( const QString &v ) { replace( Qtopia::Title, v ); }
51 void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); }
52 void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); }
53 void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); }
54 void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); }
55 void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); }
56 void setFileAs();
57
58 // default email address
59 void setDefaultEmail( const QString &v );
60 // inserts email to list and ensure's doesn't already exist
61 void insertEmail( const QString &v );
62 void removeEmail( const QString &v );
63 void clearEmails();
64 void insertEmails( const QStringList &v );
65
66 // home
67 void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); }
68 void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); }
69 void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); }
70 void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); }
71 void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); }
72 void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); }
73 void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); }
74 void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); }
75 void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); }
76
77 // business
78 void setCompany( const QString &v ) { replace( Qtopia::Company, v ); }
79 void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); }
80 void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); }
81 void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); }
82 void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); }
83 void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); }
84 void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); }
85 void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); }
86 void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); }
87 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
88 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
89 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
90 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
91 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
92 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
93 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
94 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
95
96 // personal
97 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
98 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
99 void setBirthday( const QString &v ) { replace( Qtopia::Birthday, v ); }
100 void setAnniversary( const QString &v ) { replace( Qtopia::Anniversary, v ); }
101 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
102 void setChildren( const QString &v );
103
104 // other
105 void setNotes( const QString &v ) { replace( Qtopia::Notes, v); }
106
107 bool match( const QString &regexp ) const;
108
109// DON'T ATTEMPT TO USE THIS
110#ifdef QTOPIA_INTERNAL_CONTACT_MRE
111 bool match( const QRegExp &regexp ) const;
112#endif
113
114// // custom
115// void setCustomField( const QString &key, const QString &v )
116// { replace(Custom- + key, v ); }
117
118 // name
119 QString fullName() const;
120 QString title() const { return find( Qtopia::Title ); }
121 QString firstName() const { return find( Qtopia::FirstName ); }
122 QString middleName() const { return find( Qtopia::MiddleName ); }
123 QString lastName() const { return find( Qtopia::LastName ); }
124 QString suffix() const { return find( Qtopia::Suffix ); }
125 QString fileAs() const { return find( Qtopia::FileAs ); }
126
127 // email
128 QString defaultEmail() const { return find( Qtopia::DefaultEmail ); }
129 QStringList emailList() const;
130
131 // home
132 QString homeStreet() const { return find( Qtopia::HomeStreet ); }
133 QString homeCity() const { return find( Qtopia::HomeCity ); }
134 QString homeState() const { return find( Qtopia::HomeState ); }
135 QString homeZip() const { return find( Qtopia::HomeZip ); }
136 QString homeCountry() const { return find( Qtopia::HomeCountry ); }
137 QString homePhone() const { return find( Qtopia::HomePhone ); }
138 QString homeFax() const { return find( Qtopia::HomeFax ); }
139 QString homeMobile() const { return find( Qtopia::HomeMobile ); }
140 QString homeWebpage() const { return find( Qtopia::HomeWebPage ); }
141 /** Multi line string containing all non-empty address info in the form
142 * Street
143 * City, State Zip
144 * Country
145 */
146 QString displayHomeAddress() const;
147
148 // business
149 QString company() const { return find( Qtopia::Company ); }
150 QString businessStreet() const { return find( Qtopia::BusinessStreet ); }
151 QString businessCity() const { return find( Qtopia::BusinessCity ); }
152 QString businessState() const { return find( Qtopia::BusinessState ); }
153 QString businessZip() const { return find( Qtopia::BusinessZip ); }
154 QString businessCountry() const { return find( Qtopia::BusinessCountry ); }
155 QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); }
156 QString jobTitle() const { return find( Qtopia::JobTitle ); }
157 QString department() const { return find( Qtopia::Department ); }
158 QString office() const { return find( Qtopia::Office ); }
159 QString businessPhone() const { return find( Qtopia::BusinessPhone ); }
160 QString businessFax() const { return find( Qtopia::BusinessFax ); }
161 QString businessMobile() const { return find( Qtopia::BusinessMobile ); }
162 QString businessPager() const { return find( Qtopia::BusinessPager ); }
163 QString profession() const { return find( Qtopia::Profession ); }
164 QString assistant() const { return find( Qtopia::Assistant ); }
165 QString manager() const { return find( Qtopia::Manager ); }
166 /** Multi line string containing all non-empty address info in the form
167 * Street
168 * City, State Zip
169 * Country
170 */
171 QString displayBusinessAddress() const;
172
173 //personal
174 QString spouse() const { return find( Qtopia::Spouse ); }
175 QString gender() const { return find( Qtopia::Gender ); }
176 QString birthday() const { return find( Qtopia::Birthday ); }
177 QString anniversary() const { return find( Qtopia::Anniversary ); }
178 QString nickname() const { return find( Qtopia::Nickname ); }
179 QString children() const { return find( Qtopia::Children ); }
180 QStringList childrenList() const;
181
182 // other
183 QString notes() const { return find( Qtopia::Notes ); }
184 QString groups() const { return find( Qtopia::Groups ); }
185 QStringList groupList() const;
186
187// // custom
188// const QString &customField( const QString &key )
189// { return find( Custom- + key ); }
190
191 static QStringList fields();
192 static QStringList trfields();
193
194 QString toRichText() const;
195 QMap<int, QString> toMap() const;
196 QString field( int key ) const { return find( key ); }
197
198
199 // journaling...
200 void saveJournal( journal_action action, const QString &key = QString::null );
201 void save( QString &buf ) const;
202
203 void setUid( int i )
204{ Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); }
205
206 QString toShortText()const;
207 QString OContact::type()const;
208 QMap<QString,QString> OContact::toExtraMap() const;
209 class QString OContact::recordField(int) const;
210
211private:
212 friend class AbEditor;
213 friend class AbTable;
214 friend class AddressBookAccessPrivate;
215 friend class XMLIO;
216
217 QString emailSeparator() const { return " "; }
218 // the emails should be seperated by a comma
219 void setEmails( const QString &v );
220 QString emails() const { return find( Qtopia::Emails ); }
221
222 void insert( int key, const QString &value );
223 void replace( int key, const QString &value );
224 QString find( int key ) const;
225
226 QString displayAddress( const QString &street,
227 const QString &city,
228 const QString &state,
229 const QString &zip,
230 const QString &country ) const;
231
232 Qtopia::UidGen &uidGen() { return sUidGen; }
233 static Qtopia::UidGen sUidGen;
234 QMap<int, QString> mMap;
235 ContactPrivate *d;
236};
237
238// these methods are inlined to keep binary compatability with Qtopia 1.5
239inline void OContact::insertEmail( const QString &v )
240{
241 //qDebug("insertEmail %s", v.latin1());
242 QString e = v.simplifyWhiteSpace();
243 QString def = defaultEmail();
244
245 // if no default, set it as the default email and don't insert
246 if ( def.isEmpty() ) {
247 setDefaultEmail( e ); // will insert into the list for us
248 return;
249 }
250
251 // otherwise, insert assuming doesn't already exist
252 QString emailsStr = find( Qtopia::Emails );
253 if ( emailsStr.contains( e ))
254 return;
255 if ( !emailsStr.isEmpty() )
256 emailsStr += emailSeparator();
257 emailsStr += e;
258 replace( Qtopia::Emails, emailsStr );
259}
260
261inline void OContact::removeEmail( const QString &v )
262{
263 QString e = v.simplifyWhiteSpace();
264 QString def = defaultEmail();
265 QString emailsStr = find( Qtopia::Emails );
266 QStringList emails = emailList();
267
268 // otherwise, must first contain it
269 if ( !emailsStr.contains( e ) )
270 return;
271
272 // remove it
273 //qDebug(" removing email from list %s", e.latin1());
274 emails.remove( e );
275 // reset the string
276 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
277 replace( Qtopia::Emails, emailsStr );
278
279 // if default, then replace the default email with the first one
280 if ( def == e ) {
281 //qDebug("removeEmail is default; setting new default");
282 if ( !emails.count() )
283 clearEmails();
284 else // setDefaultEmail will remove e from the list
285 setDefaultEmail( emails.first() );
286 }
287}
288inline void OContact::clearEmails()
289{
290 mMap.remove( Qtopia::DefaultEmail );
291 mMap.remove( Qtopia::Emails );
292}
293inline void OContact::setDefaultEmail( const QString &v )
294{
295 QString e = v.simplifyWhiteSpace();
296
297 //qDebug("OContact::setDefaultEmail %s", e.latin1());
298 replace( Qtopia::DefaultEmail, e );
299
300 if ( !e.isEmpty() )
301 insertEmail( e );
302
303}
304
305inline void OContact::insertEmails( const QStringList &v )
306{
307 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
308 insertEmail( *it );
309}
310
311#endif