summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/address.cpp630
-rw-r--r--kabc/address.h346
-rw-r--r--kabc/addressbook.cpp655
-rw-r--r--kabc/addressbook.h337
-rw-r--r--kabc/addressee.cpp1616
-rw-r--r--kabc/addressee.h817
-rw-r--r--kabc/addresseedialog.cpp264
-rw-r--r--kabc/addresseedialog.h160
-rw-r--r--kabc/addresseelist.cpp292
-rw-r--r--kabc/addresseelist.h218
-rw-r--r--kabc/agent.cpp155
-rw-r--r--kabc/agent.h129
-rw-r--r--kabc/distributionlist.cpp293
-rw-r--r--kabc/distributionlist.h219
-rw-r--r--kabc/distributionlistdialog.cpp396
-rw-r--r--kabc/distributionlistdialog.h140
-rw-r--r--kabc/distributionlisteditor.cpp335
-rw-r--r--kabc/distributionlisteditor.h86
-rw-r--r--kabc/field.cpp550
-rw-r--r--kabc/field.h178
-rw-r--r--kabc/formatfactory.cpp181
-rw-r--r--kabc/formatfactory.h104
-rw-r--r--kabc/formatplugin.h81
-rw-r--r--kabc/formats/binaryformat.cpp236
-rw-r--r--kabc/formats/binaryformat.h76
-rw-r--r--kabc/formats/vcardformatplugin2.cpp123
-rw-r--r--kabc/formats/vcardformatplugin2.h68
-rw-r--r--kabc/geo.cpp116
-rw-r--r--kabc/geo.h106
-rw-r--r--kabc/kabc.pro214
-rw-r--r--kabc/kabcE.pro202
-rw-r--r--kabc/key.cpp160
-rw-r--r--kabc/key.h155
-rw-r--r--kabc/phonenumber.cpp204
-rw-r--r--kabc/phonenumber.h165
-rw-r--r--kabc/picture.cpp141
-rw-r--r--kabc/picture.h134
-rw-r--r--kabc/plugin.cpp61
-rw-r--r--kabc/plugin.h50
-rw-r--r--kabc/plugins/dir/resourcedir.cpp363
-rw-r--r--kabc/plugins/dir/resourcedir.h115
-rw-r--r--kabc/plugins/dir/resourcedirconfig.cpp123
-rw-r--r--kabc/plugins/dir/resourcedirconfig.h61
-rw-r--r--kabc/plugins/file/resourcefile.cpp389
-rw-r--r--kabc/plugins/file/resourcefile.h162
-rw-r--r--kabc/plugins/file/resourcefileconfig.cpp144
-rw-r--r--kabc/plugins/file/resourcefileconfig.h65
-rw-r--r--kabc/plugins/ldap/resourceldap.cpp444
-rw-r--r--kabc/plugins/ldap/resourceldap.h99
-rw-r--r--kabc/plugins/ldap/resourceldapconfig.cpp254
-rw-r--r--kabc/plugins/ldap/resourceldapconfig.h100
-rw-r--r--kabc/resource.cpp95
-rw-r--r--kabc/resource.h134
-rw-r--r--kabc/secrecy.cpp107
-rw-r--r--kabc/secrecy.h102
-rw-r--r--kabc/sound.cpp117
-rw-r--r--kabc/sound.h123
-rw-r--r--kabc/stdaddressbook.cpp249
-rw-r--r--kabc/stdaddressbook.h151
-rw-r--r--kabc/timezone.cpp92
-rw-r--r--kabc/timezone.h94
-rw-r--r--kabc/vcard/AdrParam.cpp126
-rw-r--r--kabc/vcard/AdrValue.cpp140
-rw-r--r--kabc/vcard/AgentParam.cpp103
-rw-r--r--kabc/vcard/AgentValue.cpp81
-rw-r--r--kabc/vcard/ClassValue.cpp120
-rw-r--r--kabc/vcard/ContentLine.cpp289
-rw-r--r--kabc/vcard/DateParam.cpp82
-rw-r--r--kabc/vcard/DateValue.cpp434
-rw-r--r--kabc/vcard/EmailParam.cpp116
-rw-r--r--kabc/vcard/Entity.cpp134
-rw-r--r--kabc/vcard/Enum.cpp482
-rw-r--r--kabc/vcard/FloatValue.cpp120
-rw-r--r--kabc/vcard/GeoValue.cpp100
-rw-r--r--kabc/vcard/ImageParam.cpp81
-rw-r--r--kabc/vcard/ImageValue.cpp81
-rw-r--r--kabc/vcard/ImgValue.cpp81
-rw-r--r--kabc/vcard/LangValue.cpp127
-rw-r--r--kabc/vcard/NValue.cpp128
-rw-r--r--kabc/vcard/OrgValue.cpp107
-rw-r--r--kabc/vcard/Param.cpp129
-rw-r--r--kabc/vcard/PhoneNumberValue.cpp81
-rw-r--r--kabc/vcard/README15
-rw-r--r--kabc/vcard/RToken.cpp88
-rw-r--r--kabc/vcard/SoundValue.cpp81
-rw-r--r--kabc/vcard/SourceParam.cpp112
-rw-r--r--kabc/vcard/TelParam.cpp81
-rw-r--r--kabc/vcard/TelValue.cpp81
-rw-r--r--kabc/vcard/TextBinParam.cpp81
-rw-r--r--kabc/vcard/TextBinValue.cpp104
-rw-r--r--kabc/vcard/TextListValue.cpp107
-rw-r--r--kabc/vcard/TextParam.cpp82
-rw-r--r--kabc/vcard/TextValue.cpp86
-rw-r--r--kabc/vcard/URIValue.cpp133
-rw-r--r--kabc/vcard/UTCValue.cpp110
-rw-r--r--kabc/vcard/VCardEntity.cpp119
-rw-r--r--kabc/vcard/VCardv.cpp282
-rw-r--r--kabc/vcard/Value.cpp82
-rw-r--r--kabc/vcard/include/VCard.h43
-rw-r--r--kabc/vcard/include/VCardAdrParam.h64
-rw-r--r--kabc/vcard/include/VCardAdrValue.h83
-rw-r--r--kabc/vcard/include/VCardAgentParam.h60
-rw-r--r--kabc/vcard/include/VCardAgentValue.h44
-rw-r--r--kabc/vcard/include/VCardClassValue.h56
-rw-r--r--kabc/vcard/include/VCardContentLine.h77
-rw-r--r--kabc/vcard/include/VCardDateParam.h44
-rw-r--r--kabc/vcard/include/VCardDateValue.h99
-rw-r--r--kabc/vcard/include/VCardDefines.h52
-rw-r--r--kabc/vcard/include/VCardEmailParam.h56
-rw-r--r--kabc/vcard/include/VCardEntity.h67
-rw-r--r--kabc/vcard/include/VCardEnum.h120
-rw-r--r--kabc/vcard/include/VCardFloatValue.h51
-rw-r--r--kabc/vcard/include/VCardGeoValue.h49
-rw-r--r--kabc/vcard/include/VCardGroup.h39
-rw-r--r--kabc/vcard/include/VCardImageParam.h44
-rw-r--r--kabc/vcard/include/VCardImageValue.h44
-rw-r--r--kabc/vcard/include/VCardImgValue.h39
-rw-r--r--kabc/vcard/include/VCardLangValue.h51
-rw-r--r--kabc/vcard/include/VCardNValue.h56
-rw-r--r--kabc/vcard/include/VCardOrgValue.h50
-rw-r--r--kabc/vcard/include/VCardParam.h59
-rw-r--r--kabc/vcard/include/VCardPhoneNumberValue.h39
-rw-r--r--kabc/vcard/include/VCardRToken.h38
-rw-r--r--kabc/vcard/include/VCardSndValue.h39
-rw-r--r--kabc/vcard/include/VCardSoundValue.h44
-rw-r--r--kabc/vcard/include/VCardSourceParam.h58
-rw-r--r--kabc/vcard/include/VCardTelParam.h51
-rw-r--r--kabc/vcard/include/VCardTelValue.h44
-rw-r--r--kabc/vcard/include/VCardTextBinParam.h44
-rw-r--r--kabc/vcard/include/VCardTextBinValue.h67
-rw-r--r--kabc/vcard/include/VCardTextListValue.h51
-rw-r--r--kabc/vcard/include/VCardTextParam.h44
-rw-r--r--kabc/vcard/include/VCardTextValue.h41
-rw-r--r--kabc/vcard/include/VCardURIValue.h52
-rw-r--r--kabc/vcard/include/VCardUTCValue.h58
-rw-r--r--kabc/vcard/include/VCardVCard.h63
-rw-r--r--kabc/vcard/include/VCardVCardEntity.h56
-rw-r--r--kabc/vcard/include/VCardValue.h46
-rw-r--r--kabc/vcard/include/generated/AdrParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/AdrValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/AgentParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/AgentValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/ClassValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/ContentLine-generated.h23
-rw-r--r--kabc/vcard/include/generated/DateParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/DateValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/EmailParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/FloatValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/GeoValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/Group-generated.h23
-rw-r--r--kabc/vcard/include/generated/ImageParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/ImageValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/ImgParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/ImgValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/LangValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/NValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/Name-generated.h22
-rw-r--r--kabc/vcard/include/generated/OrgValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/Param-generated.h23
-rw-r--r--kabc/vcard/include/generated/ParamName-generated.h22
-rw-r--r--kabc/vcard/include/generated/ParamValue-generated.h22
-rw-r--r--kabc/vcard/include/generated/PhoneNumberValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/SoundValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/SourceParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/TelParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/TelValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/TextBinParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/TextBinValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/TextListValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/TextNSParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/TextParam-generated.h23
-rw-r--r--kabc/vcard/include/generated/TextValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/URIValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/UTCValue-generated.h23
-rw-r--r--kabc/vcard/include/generated/VCard-generated.h23
-rw-r--r--kabc/vcard/include/generated/VCardEntity-generated.h23
-rw-r--r--kabc/vcard/include/generated/Value-generated.h23
-rw-r--r--kabc/vcard/include/generated/generate2
-rw-r--r--kabc/vcard/include/generated/generateHeaders.awk40
-rw-r--r--kabc/vcard/include/generated/headerBodies34
-rw-r--r--kabc/vcard/testread.cpp129
-rw-r--r--kabc/vcard/testwrite.cpp41
-rw-r--r--kabc/vcard/vCard-all.cpp37
-rw-r--r--kabc/vcard21parser.cpp606
-rw-r--r--kabc/vcard21parser.h225
-rw-r--r--kabc/vcardconverter.cpp115
-rw-r--r--kabc/vcardconverter.h120
-rw-r--r--kabc/vcardformatimpl.cpp1023
-rw-r--r--kabc/vcardformatimpl.h112
-rw-r--r--kabc/vcardformatplugin.cpp66
-rw-r--r--kabc/vcardformatplugin.h56
-rw-r--r--kabc/vcardparser/vcard.cpp144
-rw-r--r--kabc/vcardparser/vcard.h90
-rw-r--r--kabc/vcardparser/vcardline.cpp148
-rw-r--r--kabc/vcardparser/vcardline.h99
-rw-r--r--kabc/vcardparser/vcardparser.cpp233
-rw-r--r--kabc/vcardparser/vcardparser.h40
-rw-r--r--kabc/vcardparser/vcardtool.cpp883
-rw-r--r--kabc/vcardparser/vcardtool.h88
199 files changed, 26169 insertions, 0 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
new file mode 100644
index 0000000..26e0b6a
--- a/dev/null
+++ b/kabc/address.cpp
@@ -0,0 +1,630 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28//US added kglobal.h
29#include <kglobal.h>
30
31#include <kapplication.h>
32#include <kdebug.h>
33#include <klocale.h>
34#include <ksimpleconfig.h>
35#include <kstandarddirs.h>
36
37#include <qfile.h>
38
39#include "address.h"
40
41using namespace KABC;
42
43QMap<QString, QString> Address::mISOMap;
44
45Address::Address() :
46 mEmpty( true ), mType( 0 )
47{
48 mId = KApplication::randomString( 10 );
49}
50
51Address::Address( int type ) :
52 mEmpty( true ), mType( type )
53{
54 mId = KApplication::randomString( 10 );
55}
56
57bool Address::operator==( const Address &a ) const
58{
59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false;
60 if ( mExtended != a.mExtended ) return false;
61 if ( mStreet != a.mStreet ) return false;
62 if ( mLocality != a.mLocality ) return false;
63 if ( mRegion != a.mRegion ) return false;
64 if ( mPostalCode != a.mPostalCode ) return false;
65 if ( mCountry != a.mCountry ) return false;
66 if ( mLabel != a.mLabel ) return false;
67
68 return true;
69}
70
71bool Address::operator!=( const Address &a ) const
72{
73 return !( a == *this );
74}
75
76bool Address::isEmpty() const
77{
78 if ( mPostOfficeBox.isEmpty() &&
79 mExtended.isEmpty() &&
80 mStreet.isEmpty() &&
81 mLocality.isEmpty() &&
82 mRegion.isEmpty() &&
83 mPostalCode.isEmpty() &&
84 mCountry.isEmpty() &&
85 mLabel.isEmpty() ) {
86 return true;
87 }
88 return false;
89}
90
91void Address::clear()
92{
93 *this = Address();
94}
95
96void Address::setId( const QString &id )
97{
98 mEmpty = false;
99
100 mId = id;
101}
102
103QString Address::id() const
104{
105 return mId;
106}
107
108void Address::setType( int type )
109{
110 mEmpty = false;
111
112 mType = type;
113}
114
115int Address::type() const
116{
117 return mType;
118}
119
120QString Address::typeLabel() const
121{
122 QString label;
123 bool first = true;
124
125 TypeList list = typeList();
126
127 TypeList::Iterator it;
128 for ( it = list.begin(); it != list.end(); ++it ) {
129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
131 if ( first )
132 first = false;
133 }
134 }
135
136 return label;
137}
138
139void Address::setPostOfficeBox( const QString &s )
140{
141 mEmpty = false;
142
143 mPostOfficeBox = s;
144}
145
146QString Address::postOfficeBox() const
147{
148 return mPostOfficeBox;
149}
150
151QString Address::postOfficeBoxLabel()
152{
153 return i18n("Post Office Box");
154}
155
156
157void Address::setExtended( const QString &s )
158{
159 mEmpty = false;
160
161 mExtended = s;
162}
163
164QString Address::extended() const
165{
166 return mExtended;
167}
168
169QString Address::extendedLabel()
170{
171 return i18n("Extended Address Information");
172}
173
174
175void Address::setStreet( const QString &s )
176{
177 mEmpty = false;
178
179 mStreet = s;
180}
181
182QString Address::street() const
183{
184 return mStreet;
185}
186
187QString Address::streetLabel()
188{
189 return i18n("Street");
190}
191
192
193void Address::setLocality( const QString &s )
194{
195 mEmpty = false;
196
197 mLocality = s;
198}
199
200QString Address::locality() const
201{
202 return mLocality;
203}
204
205QString Address::localityLabel()
206{
207 return i18n("Locality");
208}
209
210
211void Address::setRegion( const QString &s )
212{
213 mEmpty = false;
214
215 mRegion = s;
216}
217
218QString Address::region() const
219{
220 return mRegion;
221}
222
223QString Address::regionLabel()
224{
225 return i18n("Region");
226}
227
228
229void Address::setPostalCode( const QString &s )
230{
231 mEmpty = false;
232
233 mPostalCode = s;
234}
235
236QString Address::postalCode() const
237{
238 return mPostalCode;
239}
240
241QString Address::postalCodeLabel()
242{
243 return i18n("Postal Code");
244}
245
246
247void Address::setCountry( const QString &s )
248{
249 mEmpty = false;
250
251 mCountry = s;
252}
253
254QString Address::country() const
255{
256 return mCountry;
257}
258
259QString Address::countryLabel()
260{
261 return i18n("Country");
262}
263
264
265void Address::setLabel( const QString &s )
266{
267 mEmpty = false;
268
269 mLabel = s;
270}
271
272QString Address::label() const
273{
274 return mLabel;
275}
276
277QString Address::labelLabel()
278{
279 return i18n("Delivery Label");
280}
281
282Address::TypeList Address::typeList()
283{
284 TypeList list;
285
286 list << Dom << Intl << Postal << Parcel << Home << Work << Pref;
287
288 return list;
289}
290
291QString Address::typeLabel( int type )
292{
293 switch ( type ) {
294 case Dom:
295 return i18n("Domestic");
296 break;
297 case Intl:
298 return i18n("International");
299 break;
300 case Postal:
301 return i18n("Postal");
302 break;
303 case Parcel:
304 return i18n("Parcel");
305 break;
306 case Home:
307 return i18n("Home Address", "Home");
308 break;
309 case Work:
310 return i18n("Work Address", "Work");
311 break;
312 case Pref:
313 return i18n("Preferred Address");
314 break;
315 default:
316 return i18n("Other");
317 break;
318 }
319}
320
321void Address::dump() const
322{
323 qDebug("Address::dump() +++++++++++++++++ ");
324#if 0
325 kdDebug(5700) << " Address {" << endl;
326 kdDebug(5700) << " Id: " << id() << endl;
327 kdDebug(5700) << " Extended: " << extended() << endl;
328 kdDebug(5700) << " Street: " << street() << endl;
329 kdDebug(5700) << " Postal Code: " << postalCode() << endl;
330 kdDebug(5700) << " Locality: " << locality() << endl;
331 kdDebug(5700) << " }" << endl;
332#endif
333}
334
335
336QString Address::formattedAddress( const QString &realName
337 , const QString &orgaName ) const
338{
339 QString ciso;
340 QString addrTemplate;
341 QString ret;
342
343 // **************************************************************
344 // LR: currently we have no iso handling - we will format the address manually here
345
346 QString text;
347 if ( !street().isEmpty() )
348 text += street() + "\n";
349
350 if ( !postOfficeBox().isEmpty() )
351 text += postOfficeBox() + "\n";
352
353 text += locality() + QString(" ") + region();
354
355 if ( !postalCode().isEmpty() )
356 text += QString(", ") + postalCode();
357
358 text += "\n";
359
360 if ( !country().isEmpty() )
361 text += country() + "\n";
362
363 text += extended();
364
365
366 return text;
367 // **************************************************************
368
369 // FIXME: first check for iso-country-field and prefer that one
370 if ( !country().isEmpty() ) {
371 ciso = countryToISO( country() );
372 } else {
373 // fall back to our own country
374 ciso = KGlobal::locale()->country();
375 }
376 //qDebug("ciso %s ",ciso.latin1() );
377 KSimpleConfig entry( locate( "locale",
378 QString( "l10n/" ) + ciso + QString( "/entry.desktop" ) ) );
379 entry.setGroup( "KCM Locale" );
380
381 // decide whether this needs special business address formatting
382 if ( orgaName.isNull() ) {
383 addrTemplate = entry.readEntry( "AddressFormat" );
384 } else {
385 addrTemplate = entry.readEntry( "BusinessAddressFormat" );
386 if ( addrTemplate.isEmpty() )
387 addrTemplate = entry.readEntry( "AddressFormat" );
388 }
389
390 // in the case there's no format found at all, default to what we've always
391 // used:
392 if ( addrTemplate.isEmpty() ) {
393 qDebug("address format database incomplete****************** ");
394 kdWarning(5700) << "address format database incomplete "
395 << "(no format for locale " << ciso
396 << " found). Using default address formatting." << endl;
397 addrTemplate = "%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z";
398 }
399
400 // scan
401 parseAddressTemplateSection( addrTemplate, ret, realName, orgaName );
402
403 // now add the country line if needed (formatting this time according to
404 // the rules of our own system country )
405 if ( !country().isEmpty() ) {
406 KSimpleConfig entry( locate( "locale", QString( "l10n/" )
407 + KGlobal::locale()->country() + QString( "/entry.desktop" ) ) );
408 entry.setGroup( "KCM Locale" );
409 QString cpos = entry.readEntry( "AddressCountryPosition" );
410 if ( "BELOW" == cpos || cpos.isEmpty() ) {
411 ret = ret + "\n\n" + country().upper();
412 } else if ( "below" == cpos ) {
413 ret = ret + "\n\n" + country();
414 } else if ( "ABOVE" == cpos ) {
415 ret = country().upper() + "\n\n" + ret;
416 } else if ( "above" == cpos ) {
417 ret = country() + "\n\n" + ret;
418 }
419 }
420
421 return ret;
422}
423
424bool Address::parseAddressTemplateSection( const QString &tsection,
425 QString &result, const QString &realName, const QString &orgaName ) const
426{
427 // This method first parses and substitutes any bracketed sections and
428 // after that replaces any tags with their values. If a bracketed section
429 // or a tag evaluate to zero, they are not just removed but replaced
430 // with a placeholder. This is because in the last step conditionals are
431 // resolved which depend on information about zero-evaluations.
432 result = tsection;
433 int stpos = 0;
434 bool ret = false;
435
436 // first check for brackets that have to be evaluated first
437 int fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
438 while ( -1 != fpos ) {
439 int bpos1 = fpos + KABC_FMTTAG_purgeempty.length();
440 int bpos2;
441 // expect opening bracket and find next balanced closing bracket. If
442 // next char is no opening bracket, continue parsing (no valid tag)
443 if ( '(' == result[bpos1] ) {
444 bpos2 = findBalancedBracket( result, bpos1 );
445 if ( -1 != bpos2 ) {
446 // we have balanced brackets, recursively parse:
447 QString rplstr;
448 bool purge = !parseAddressTemplateSection( result.mid( bpos1+1,
449 bpos2-bpos1-1 ), rplstr,
450 realName, orgaName );
451 if ( purge ) {
452 // purge -> remove all
453 // replace with !_P_!, so conditional tags work later
454 result.replace( fpos, bpos2 - fpos + 1, "!_P_!" );
455 // leave stpos as it is
456 } else {
457 // no purge -> replace with recursively parsed string
458 result.replace( fpos, bpos2 - fpos + 1, rplstr );
459 ret = true;
460 stpos = fpos + rplstr.length();
461 }
462 } else {
463 // unbalanced brackets: keep on parsing (should not happen
464 // and will result in bad formatting)
465 stpos = bpos1;
466 }
467 }
468 fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
469 }
470
471 // after sorting out all purge tags, we just search'n'replace the rest,
472 // keeping track of whether at least one tag evaluates to something.
473 // The following macro needs QString for R_FIELD
474 // It substitutes !_P_! for empty fields so conditional tags work later
475#define REPLTAG(R_TAG,R_FIELD) \
476 if ( result.contains(R_TAG, false) ) { \
477 QString rpl = R_FIELD.isEmpty() ? QString("!_P_!") : R_FIELD; \
478 result.replace( R_TAG, rpl ); \
479 if ( !R_FIELD.isEmpty() ) { \
480 ret = true; \
481 } \
482 }
483 REPLTAG( KABC_FMTTAG_realname, realName );
484 REPLTAG( KABC_FMTTAG_REALNAME, realName.upper() );
485 REPLTAG( KABC_FMTTAG_company, orgaName );
486 REPLTAG( KABC_FMTTAG_COMPANY, orgaName.upper() );
487 REPLTAG( KABC_FMTTAG_pobox, postOfficeBox() );
488 REPLTAG( KABC_FMTTAG_street, street() );
489 REPLTAG( KABC_FMTTAG_STREET, street().upper() );
490 REPLTAG( KABC_FMTTAG_zipcode, postalCode() );
491 REPLTAG( KABC_FMTTAG_location, locality() );
492 REPLTAG( KABC_FMTTAG_LOCATION, locality().upper() );
493 REPLTAG( KABC_FMTTAG_region, region() );
494 REPLTAG( KABC_FMTTAG_REGION, region().upper() );
495 result.replace( KABC_FMTTAG_newline, "\n" );
496#undef REPLTAG
497
498 // conditional comma
499 fpos = result.find( KABC_FMTTAG_condcomma, 0 );
500 while ( -1 != fpos ) {
501 QString str1 = result.mid( fpos - 5, 5 );
502 QString str2 = result.mid( fpos + 2, 5 );
503 if ( str1 != "!_P_!" && str2 != "!_P_!" ) {
504 result.replace( fpos, 2, ", " );
505 } else {
506 result.remove( fpos, 2 );
507 }
508 fpos = result.find( KABC_FMTTAG_condcomma, fpos );
509 }
510 // conditional whitespace
511 fpos = result.find( KABC_FMTTAG_condwhite, 0 );
512 while ( -1 != fpos ) {
513 QString str1 = result.mid( fpos - 5, 5 );
514 QString str2 = result.mid( fpos + 2, 5 );
515 if ( str1 != "!_P_!" && str2 != "!_P_!" ) {
516 result.replace( fpos, 2, " " );
517 } else {
518 result.remove( fpos, 2 );
519 }
520 fpos = result.find( KABC_FMTTAG_condwhite, fpos );
521 }
522
523 // remove purged:
524//US my QT version does not support remove. So lets do it the old fashioned way.
525//US result.remove( "!_P_!" );
526 int n = result.find("!_P_!");
527 if (n >= 0)
528 result.remove( n, 5 );
529
530 return ret;
531}
532
533int Address::findBalancedBracket( const QString &tsection, int pos ) const
534{
535 int balancecounter = 0;
536 for( unsigned int i = pos + 1; i < tsection.length(); i++ ) {
537 if ( ')' == tsection.at(i) && 0 == balancecounter ) {
538 // found end of brackets
539 return i;
540 } else
541 if ( '(' == tsection.at(i) ) {
542 // nested brackets
543 balancecounter++;
544 }
545 }
546 return -1;
547}
548
549QString Address::countryToISO( const QString &cname )
550{
551 // we search a map file for translations from country names to
552 // iso codes, storing caching things in a QMap for faster future
553 // access.
554/*US
555
556 QString isoCode = mISOMap[ cname ];
557 if ( !isoCode.isEmpty() )
558 return isoCode;
559
560 QString mapfile = KGlobal::dirs()->findResource( "data",
561 QString::fromLatin1( "kabc/countrytransl.map" ) );
562
563 QFile file( mapfile );
564 if ( file.open( IO_ReadOnly ) ) {
565 QTextStream s( &file );
566 QString strbuf = s.readLine();
567 while( !strbuf.isNull() ) {
568 if ( strbuf.startsWith( cname ) ) {
569 int index = strbuf.findRev('\t');
570 strbuf = strbuf.mid(index+1, 2);
571 file.close();
572 mISOMap[ cname ] = strbuf;
573 return strbuf;
574 }
575 strbuf = s.readLine();
576 }
577 file.close();
578 }
579*/
580 // fall back to system country
581 mISOMap[ cname ] = KGlobal::locale()->country();
582 return KGlobal::locale()->country();
583}
584
585QString Address::ISOtoCountry( const QString &ISOname )
586{
587/*US
588 // get country name from ISO country code (e.g. "no" -> i18n("Norway"))
589 QString mapfile = KGlobal::dirs()->findResource( "data",
590 QString::fromLatin1( "kabc/countrytransl.map" ) );
591
592kdWarning() << "MAPFILE : " << mapfile << endl;
593 QFile file( mapfile );
594 if ( file.open( IO_ReadOnly ) ) {
595 QTextStream s( &file );
596 QString searchStr = "\t" + ISOname.simplifyWhiteSpace().lower();
597kdWarning() << "Suche : " << searchStr << endl;
598 QString strbuf = s.readLine();
599 int pos;
600 while( !strbuf.isNull() ) {
601 if ( (pos=strbuf.find( searchStr )) != -1 ) {
602 file.close();
603 return i18n(strbuf.left(pos).utf8());
604 }
605 strbuf = s.readLine();
606 }
607 file.close();
608 }
609*/
610 return ISOname;
611}
612
613QDataStream &KABC::operator<<( QDataStream &s, const Address &addr )
614{
615 return s << addr.mId << addr.mType << addr.mPostOfficeBox <<
616 addr.mExtended << addr.mStreet << addr.mLocality <<
617 addr.mRegion << addr.mPostalCode << addr.mCountry <<
618 addr.mLabel;
619}
620
621QDataStream &KABC::operator>>( QDataStream &s, Address &addr )
622{
623 s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >>
624 addr.mStreet >> addr.mLocality >> addr.mRegion >>
625 addr.mPostalCode >> addr.mCountry >> addr.mLabel;
626
627 addr.mEmpty = false;
628
629 return s;
630}
diff --git a/kabc/address.h b/kabc/address.h
new file mode 100644
index 0000000..ad132a7
--- a/dev/null
+++ b/kabc/address.h
@@ -0,0 +1,346 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_ADDRESS_H
29#define KABC_ADDRESS_H
30
31#include <qmap.h>
32#include <qstring.h>
33#include <qvaluelist.h>
34
35// template tags for address formatting localization
36#define KABC_FMTTAG_realname QString("%n")
37#define KABC_FMTTAG_REALNAME QString("%N")
38#define KABC_FMTTAG_company QString("%cm")
39#define KABC_FMTTAG_COMPANY QString("%CM")
40#define KABC_FMTTAG_pobox QString("%p")
41#define KABC_FMTTAG_street QString("%s")
42#define KABC_FMTTAG_STREET QString("%S")
43#define KABC_FMTTAG_zipcode QString("%z")
44#define KABC_FMTTAG_location QString("%l")
45#define KABC_FMTTAG_LOCATION QString("%L")
46#define KABC_FMTTAG_region QString("%r")
47#define KABC_FMTTAG_REGION QString("%R")
48#define KABC_FMTTAG_newline QString("\\n")
49#define KABC_FMTTAG_condcomma QString("%,")
50#define KABC_FMTTAG_condwhite QString("%w")
51#define KABC_FMTTAG_purgeempty QString("%0")
52
53namespace KABC {
54
55/**
56 @short Postal address information.
57
58 This class represents information about a postal address.
59*/
60class Address
61{
62 friend QDataStream &operator<<( QDataStream &, const Address & );
63 friend QDataStream &operator>>( QDataStream &, Address & );
64
65 public:
66 /**
67 List of addresses.
68 */
69 typedef QValueList<Address> List;
70 typedef QValueList<int> TypeList;
71
72 /**
73 Address types:
74
75 @li @p Dom - domestic
76 @li @p Intl - international
77 @li @p Postal - postal
78 @li @p Parcel - parcel
79 @li @p Home - home address
80 @li @p Work - address at work
81 @li @p Pref - preferred address
82 */
83 enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32,
84 Pref = 64 };
85
86 /**
87 Constructor that creates an empty Address, which is initialized
88 with a unique id (see @ref id()).
89 */
90 Address();
91
92 /**
93 This is like @ref Address() just above, with the difference
94 that you can specify the type.
95 */
96 Address( int );
97
98 bool operator==( const Address & ) const;
99 bool operator!=( const Address & ) const;
100
101 /**
102 Returns true, if the address is empty.
103 */
104 bool isEmpty() const;
105
106 /**
107 Clears all entries of the address.
108 */
109 void clear();
110
111 /**
112 Sets the unique id.
113 */
114 void setId( const QString & );
115
116 /*
117 Returns the unique id.
118 */
119 QString id() const;
120
121 /**
122 Sets the type of address. See enum for definiton of types.
123
124 @param type type, can be a bitwise or of multiple types.
125 */
126 void setType( int type );
127
128 /**
129 Returns the type of address. Can be a bitwise or of multiple types.
130 */
131 int type() const;
132
133 /**
134 Returns a translated string of all types the address has.
135 */
136 QString typeLabel() const;
137
138 /**
139 Sets the post office box.
140 */
141 void setPostOfficeBox( const QString & );
142
143 /**
144 Returns the post office box.
145 */
146 QString postOfficeBox() const;
147
148 /**
149 Returns the translated label for post office box field.
150 */
151 static QString postOfficeBoxLabel();
152
153 /**
154 Sets the extended address information.
155 */
156 void setExtended( const QString & );
157
158 /**
159 Returns the extended address information.
160 */
161 QString extended() const;
162
163 /**
164 Returns the translated label for extended field.
165 */
166 static QString extendedLabel();
167
168 /**
169 Sets the street (including number).
170 */
171 void setStreet( const QString & );
172
173 /**
174 Returns the street.
175 */
176 QString street() const;
177
178 /**
179 Returns the translated label for street field.
180 */
181 static QString streetLabel();
182
183 /**
184 Sets the locality, e.g. city.
185 */
186 void setLocality( const QString & );
187
188 /**
189 Returns the locality.
190 */
191 QString locality() const;
192
193 /**
194 Returns the translated label for locality field.
195 */
196 static QString localityLabel();
197
198 /**
199 Sets the region, e.g. state.
200 */
201 void setRegion( const QString & );
202
203 /**
204 Returns the region.
205 */
206 QString region() const;
207
208 /**
209 Returns the translated label for region field.
210 */
211 static QString regionLabel();
212
213 /**
214 Sets the postal code.
215 */
216 void setPostalCode( const QString & );
217
218 /**
219 Returns the postal code.
220 */
221 QString postalCode() const;
222
223 /**
224 Returns the translated label for postal code field.
225 */
226 static QString postalCodeLabel();
227
228 /**
229 Sets the country.
230 */
231 void setCountry( const QString & );
232
233 /**
234 Returns the country.
235 */
236 QString country() const;
237
238 /**
239 Returns the translated label for country field.
240 */
241 static QString countryLabel();
242
243 /**
244 Sets the delivery label. This is the literal text to be used as label.
245 */
246 void setLabel( const QString & );
247
248 /**
249 Returns the delivery label.
250 */
251 QString label() const;
252
253 /**
254 Returns the translated label for delivery label field.
255 */
256 static QString labelLabel();
257
258 /**
259 Returns the list of available types.
260 */
261 static TypeList typeList();
262
263 /**
264 Returns the translated label for a special type.
265 */
266 static QString typeLabel( int type );
267
268 /**
269 Used for debug output.
270 */
271 void dump() const;
272
273 /**
274 Returns this address formatted according to the country-specific
275 address formatting rules. The formatting rules applied depend on
276 either the addresses {@link #country country} field, or (if the
277 latter is empty) on the system country setting. If companyName is
278 provided, an available business address format will be preferred.
279
280 @param realName the formatted name of the contact
281 @param orgaName the name of the organization or company
282 @return the formatted address (containing newline characters)
283 */
284 QString formattedAddress( const QString &realName=QString::null
285 , const QString &orgaName=QString::null ) const;
286
287 /**
288 Returns ISO code for a localized country name. Only localized country
289 names will be understood. This might be replaced by a KLocale method in
290 the future.
291 @param cname name of the country
292 @return two digit ISO code
293 */
294 static QString countryToISO( const QString &cname );
295
296 /**
297 Returns a localized country name for a ISO code.
298 This might be replaced by a KLocale method in the future.
299 @param ISOname two digit ISO code
300 @return localized name of the country
301 @since 3.2
302 */
303 static QString ISOtoCountry( const QString &ISOname );
304
305 private:
306 /**
307 Parses a snippet of an address template
308 @param tsection the template string to be parsed
309 @param result QString reference in which the result will be stored
310 @return true if at least one tag evaluated positively, else false
311 */
312 bool parseAddressTemplateSection( const QString &tsection
313 , QString &result
314 , const QString &realName
315 , const QString &orgaName ) const;
316
317 /**
318 Finds the balanced closing bracket starting from the opening bracket at
319 pos in tsection.
320 @return position of closing bracket, -1 for unbalanced brackets
321 */
322 int findBalancedBracket( const QString &tsection, int pos ) const;
323
324 bool mEmpty;
325
326 QString mId;
327 int mType;
328
329 QString mPostOfficeBox;
330 QString mExtended;
331 QString mStreet;
332 QString mLocality;
333 QString mRegion;
334 QString mPostalCode;
335 QString mCountry;
336 QString mLabel;
337
338 static QMap<QString, QString> mISOMap;
339};
340
341QDataStream &operator<<( QDataStream &, const Address & );
342QDataStream &operator>>( QDataStream &, Address & );
343
344}
345
346#endif
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
new file mode 100644
index 0000000..203efc2
--- a/dev/null
+++ b/kabc/addressbook.cpp
@@ -0,0 +1,655 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KAB_EMBEDDED
29
30#include <qfile.h>
31#include <qregexp.h>
32#include <qtimer.h>
33
34#include <kapplication.h>
35#include <kinstance.h>
36#include <kstandarddirs.h>
37
38#include "errorhandler.h"
39
40#else //KAB_EMBEDDED
41#include <qptrlist.h>
42#endif //KAB_EMBEDDED
43
44#include <kglobal.h>
45#include <klocale.h>
46#include <kdebug.h>
47#include "addressbook.h"
48#include "resource.h"
49
50#ifndef KAB_EMBEDDED
51#include "addressbook.moc"
52#endif //KAB_EMBEDDED
53
54using namespace KABC;
55
56struct AddressBook::AddressBookData
57{
58 Addressee::List mAddressees;
59 Addressee::List mRemovedAddressees;
60 Field::List mAllFields;
61 KConfig *mConfig;
62 KRES::Manager<Resource> *mManager;
63#ifndef KAB_EMBEDDED
64 ErrorHandler *mErrorHandler;
65#endif //KAB_EMBEDDED
66};
67
68struct AddressBook::Iterator::IteratorData
69{
70 Addressee::List::Iterator mIt;
71};
72
73struct AddressBook::ConstIterator::ConstIteratorData
74{
75 Addressee::List::ConstIterator mIt;
76};
77
78AddressBook::Iterator::Iterator()
79{
80 d = new IteratorData;
81}
82
83AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
84{
85 d = new IteratorData;
86 d->mIt = i.d->mIt;
87}
88
89AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
90{
91 if( this == &i ) return *this; // guard against self assignment
92 delete d; // delete the old data the Iterator was completely constructed before
93 d = new IteratorData;
94 d->mIt = i.d->mIt;
95 return *this;
96}
97
98AddressBook::Iterator::~Iterator()
99{
100 delete d;
101}
102
103const Addressee &AddressBook::Iterator::operator*() const
104{
105 return *(d->mIt);
106}
107
108Addressee &AddressBook::Iterator::operator*()
109{
110 return *(d->mIt);
111}
112
113Addressee *AddressBook::Iterator::operator->()
114{
115 return &(*(d->mIt));
116}
117
118AddressBook::Iterator &AddressBook::Iterator::operator++()
119{
120 (d->mIt)++;
121 return *this;
122}
123
124AddressBook::Iterator &AddressBook::Iterator::operator++(int)
125{
126 (d->mIt)++;
127 return *this;
128}
129
130AddressBook::Iterator &AddressBook::Iterator::operator--()
131{
132 (d->mIt)--;
133 return *this;
134}
135
136AddressBook::Iterator &AddressBook::Iterator::operator--(int)
137{
138 (d->mIt)--;
139 return *this;
140}
141
142bool AddressBook::Iterator::operator==( const Iterator &it )
143{
144 return ( d->mIt == it.d->mIt );
145}
146
147bool AddressBook::Iterator::operator!=( const Iterator &it )
148{
149 return ( d->mIt != it.d->mIt );
150}
151
152
153AddressBook::ConstIterator::ConstIterator()
154{
155 d = new ConstIteratorData;
156}
157
158AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
159{
160 d = new ConstIteratorData;
161 d->mIt = i.d->mIt;
162}
163
164AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
165{
166 if( this == &i ) return *this; // guard for self assignment
167 delete d; // delete the old data because the Iterator was really constructed before
168 d = new ConstIteratorData;
169 d->mIt = i.d->mIt;
170 return *this;
171}
172
173AddressBook::ConstIterator::~ConstIterator()
174{
175 delete d;
176}
177
178const Addressee &AddressBook::ConstIterator::operator*() const
179{
180 return *(d->mIt);
181}
182
183const Addressee* AddressBook::ConstIterator::operator->() const
184{
185 return &(*(d->mIt));
186}
187
188AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
189{
190 (d->mIt)++;
191 return *this;
192}
193
194AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
195{
196 (d->mIt)++;
197 return *this;
198}
199
200AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
201{
202 (d->mIt)--;
203 return *this;
204}
205
206AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
207{
208 (d->mIt)--;
209 return *this;
210}
211
212bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
213{
214 return ( d->mIt == it.d->mIt );
215}
216
217bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
218{
219 return ( d->mIt != it.d->mIt );
220}
221
222
223AddressBook::AddressBook()
224{
225 init(0);
226}
227
228AddressBook::AddressBook( const QString &config )
229{
230 init(config);
231}
232
233void AddressBook::init(const QString &config)
234{
235 d = new AddressBookData;
236 if (config != 0) {
237 d->mConfig = new KConfig( config );
238// qDebug("AddressBook::init 1 config=%s",config.latin1() );
239 }
240 else {
241 d->mConfig = 0;
242// qDebug("AddressBook::init 1 config=0");
243 }
244
245#ifndef KAB_EMBEDDED
246 d->mErrorHandler = 0;
247#endif //KAB_EMBEDDED
248 d->mManager = new KRES::Manager<Resource>( "contact" );
249 d->mManager->readConfig( d->mConfig );
250}
251
252AddressBook::~AddressBook()
253{
254 delete d->mConfig; d->mConfig = 0;
255 delete d->mManager; d->mManager = 0;
256#ifndef KAB_EMBEDDED
257 delete d->mErrorHandler; d->mErrorHandler = 0;
258#endif //KAB_EMBEDDED
259 delete d; d = 0;
260}
261
262bool AddressBook::load()
263{
264 kdDebug(5700) << "AddressBook::load()" << endl;
265
266 clear();
267
268 KRES::Manager<Resource>::ActiveIterator it;
269 bool ok = true;
270 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
271 if ( !(*it)->load() ) {
272 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
273 ok = false;
274 }
275
276 // mark all addressees as unchanged
277 Addressee::List::Iterator addrIt;
278 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
279 (*addrIt).setChanged( false );
280
281 return ok;
282}
283
284bool AddressBook::save( Ticket *ticket )
285{
286 kdDebug(5700) << "AddressBook::save()"<< endl;
287
288 if ( ticket->resource() ) {
289 deleteRemovedAddressees();
290
291 return ticket->resource()->save( ticket );
292 }
293
294 return false;
295}
296
297AddressBook::Iterator AddressBook::begin()
298{
299 Iterator it = Iterator();
300 it.d->mIt = d->mAddressees.begin();
301 return it;
302}
303
304AddressBook::ConstIterator AddressBook::begin() const
305{
306 ConstIterator it = ConstIterator();
307 it.d->mIt = d->mAddressees.begin();
308 return it;
309}
310
311AddressBook::Iterator AddressBook::end()
312{
313 Iterator it = Iterator();
314 it.d->mIt = d->mAddressees.end();
315 return it;
316}
317
318AddressBook::ConstIterator AddressBook::end() const
319{
320 ConstIterator it = ConstIterator();
321 it.d->mIt = d->mAddressees.end();
322 return it;
323}
324
325void AddressBook::clear()
326{
327 d->mAddressees.clear();
328}
329
330Ticket *AddressBook::requestSaveTicket( Resource *resource )
331{
332 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
333
334 if ( !resource )
335 {
336 qDebug("AddressBook::requestSaveTicket no resource" );
337 resource = standardResource();
338 }
339
340 KRES::Manager<Resource>::ActiveIterator it;
341 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
342 if ( (*it) == resource ) {
343 if ( (*it)->readOnly() || !(*it)->isOpen() )
344 return 0;
345 else
346 return (*it)->requestSaveTicket();
347 }
348 }
349
350 return 0;
351}
352
353void AddressBook::insertAddressee( const Addressee &a )
354{
355 Addressee::List::Iterator it;
356 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
357 if ( a.uid() == (*it).uid() ) {
358 bool changed = false;
359 Addressee addr = a;
360 if ( addr != (*it) )
361 changed = true;
362
363 (*it) = a;
364 if ( (*it).resource() == 0 )
365 (*it).setResource( standardResource() );
366
367 if ( changed ) {
368 (*it).setRevision( QDateTime::currentDateTime() );
369 (*it).setChanged( true );
370 }
371
372 return;
373 }
374 }
375 d->mAddressees.append( a );
376 Addressee& addr = d->mAddressees.last();
377 if ( addr.resource() == 0 )
378 addr.setResource( standardResource() );
379
380 addr.setChanged( true );
381}
382
383void AddressBook::removeAddressee( const Addressee &a )
384{
385 Iterator it;
386 for ( it = begin(); it != end(); ++it ) {
387 if ( a.uid() == (*it).uid() ) {
388 removeAddressee( it );
389 return;
390 }
391 }
392}
393
394void AddressBook::removeAddressee( const Iterator &it )
395{
396 d->mRemovedAddressees.append( (*it) );
397 d->mAddressees.remove( it.d->mIt );
398}
399
400AddressBook::Iterator AddressBook::find( const Addressee &a )
401{
402 Iterator it;
403 for ( it = begin(); it != end(); ++it ) {
404 if ( a.uid() == (*it).uid() ) {
405 return it;
406 }
407 }
408 return end();
409}
410
411Addressee AddressBook::findByUid( const QString &uid )
412{
413 Iterator it;
414 for ( it = begin(); it != end(); ++it ) {
415 if ( uid == (*it).uid() ) {
416 return *it;
417 }
418 }
419 return Addressee();
420}
421
422Addressee::List AddressBook::allAddressees()
423{
424 return d->mAddressees;
425}
426
427Addressee::List AddressBook::findByName( const QString &name )
428{
429 Addressee::List results;
430
431 Iterator it;
432 for ( it = begin(); it != end(); ++it ) {
433 if ( name == (*it).name() ) {
434 results.append( *it );
435 }
436 }
437
438 return results;
439}
440
441Addressee::List AddressBook::findByEmail( const QString &email )
442{
443 Addressee::List results;
444 QStringList mailList;
445
446 Iterator it;
447 for ( it = begin(); it != end(); ++it ) {
448 mailList = (*it).emails();
449 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
450 if ( email == (*ite) ) {
451 results.append( *it );
452 }
453 }
454 }
455
456 return results;
457}
458
459Addressee::List AddressBook::findByCategory( const QString &category )
460{
461 Addressee::List results;
462
463 Iterator it;
464 for ( it = begin(); it != end(); ++it ) {
465 if ( (*it).hasCategory( category) ) {
466 results.append( *it );
467 }
468 }
469
470 return results;
471}
472
473void AddressBook::dump() const
474{
475 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
476
477 ConstIterator it;
478 for( it = begin(); it != end(); ++it ) {
479 (*it).dump();
480 }
481
482 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
483}
484
485QString AddressBook::identifier()
486{
487 QStringList identifier;
488
489
490 KRES::Manager<Resource>::ActiveIterator it;
491 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
492 if ( !(*it)->identifier().isEmpty() )
493 identifier.append( (*it)->identifier() );
494 }
495
496 return identifier.join( ":" );
497}
498
499Field::List AddressBook::fields( int category )
500{
501 if ( d->mAllFields.isEmpty() ) {
502 d->mAllFields = Field::allFields();
503 }
504
505 if ( category == Field::All ) return d->mAllFields;
506
507 Field::List result;
508 Field::List::ConstIterator it;
509 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
510 if ( (*it)->category() & category ) result.append( *it );
511 }
512
513 return result;
514}
515
516bool AddressBook::addCustomField( const QString &label, int category,
517 const QString &key, const QString &app )
518{
519 if ( d->mAllFields.isEmpty() ) {
520 d->mAllFields = Field::allFields();
521 }
522#ifndef KAB_EMBEDDED
523 QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
524#else //KAB_EMBEDDED
525 QString a = app.isNull() ? KGlobal::getAppName() : app;
526#endif //KAB_EMBEDDED
527
528 QString k = key.isNull() ? label : key;
529
530 Field *field = Field::createCustomField( label, category, k, a );
531
532 if ( !field ) return false;
533
534 d->mAllFields.append( field );
535
536 return true;
537}
538
539QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
540{
541 if (!ab.d) return s;
542
543 return s << ab.d->mAddressees;
544}
545
546QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
547{
548 if (!ab.d) return s;
549
550 s >> ab.d->mAddressees;
551
552 return s;
553}
554
555bool AddressBook::addResource( Resource *resource )
556{
557 qDebug("AddressBook::addResource 1");
558
559 if ( !resource->open() ) {
560 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
561 return false;
562 }
563
564 resource->setAddressBook( this );
565
566 d->mManager->add( resource );
567 return true;
568}
569
570bool AddressBook::removeResource( Resource *resource )
571{
572 resource->close();
573
574 if ( resource == standardResource() )
575 d->mManager->setStandardResource( 0 );
576
577 resource->setAddressBook( 0 );
578
579 d->mManager->remove( resource );
580 return true;
581}
582
583QPtrList<Resource> AddressBook::resources()
584{
585 QPtrList<Resource> list;
586
587// qDebug("AddressBook::resources() 1");
588
589 KRES::Manager<Resource>::ActiveIterator it;
590 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
591 list.append( *it );
592
593 return list;
594}
595
596#ifndef KAB_EMBEDDED
597void AddressBook::setErrorHandler( ErrorHandler *handler )
598{
599 delete d->mErrorHandler;
600 d->mErrorHandler = handler;
601}
602#endif //KAB_EMBEDDED
603
604void AddressBook::error( const QString& msg )
605{
606#ifndef KAB_EMBEDDED
607 if ( !d->mErrorHandler ) // create default error handler
608 d->mErrorHandler = new ConsoleErrorHandler;
609
610 if ( d->mErrorHandler )
611 d->mErrorHandler->error( msg );
612 else
613 kdError(5700) << "no error handler defined" << endl;
614#else //KAB_EMBEDDED
615 kdDebug(5700) << "msg" << endl;
616 qDebug(msg);
617#endif //KAB_EMBEDDED
618}
619
620void AddressBook::deleteRemovedAddressees()
621{
622 Addressee::List::Iterator it;
623 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
624 Resource *resource = (*it).resource();
625 if ( resource && !resource->readOnly() && resource->isOpen() )
626 resource->removeAddressee( *it );
627 }
628
629 d->mRemovedAddressees.clear();
630}
631
632void AddressBook::setStandardResource( Resource *resource )
633{
634// qDebug("AddressBook::setStandardResource 1");
635 d->mManager->setStandardResource( resource );
636}
637
638Resource *AddressBook::standardResource()
639{
640 return d->mManager->standardResource();
641}
642
643KRES::Manager<Resource> *AddressBook::resourceManager()
644{
645 return d->mManager;
646}
647
648void AddressBook::cleanUp()
649{
650 KRES::Manager<Resource>::ActiveIterator it;
651 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
652 if ( !(*it)->readOnly() && (*it)->isOpen() )
653 (*it)->cleanUp();
654 }
655}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
new file mode 100644
index 0000000..3383fc0
--- a/dev/null
+++ b/kabc/addressbook.h
@@ -0,0 +1,337 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H
30
31#include <qobject.h>
32
33#include <kresources/manager.h>
34#include <qptrlist.h>
35
36#ifndef KAB_EMBEDDED
37
38#else //KAB_EMBEDDED
39#endif //KAB_EMBEDDED
40
41
42#include "addressee.h"
43#include "field.h"
44
45namespace KABC {
46
47class ErrorHandler;
48class Resource;
49class Ticket;
50
51/**
52 @short Address Book
53
54 This class provides access to a collection of address book entries.
55*/
56class AddressBook : public QObject
57{
58 Q_OBJECT
59
60 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
61 friend QDataStream &operator>>( QDataStream &, AddressBook & );
62 friend class StdAddressBook;
63
64 public:
65 /**
66 @short Address Book Iterator
67
68 This class provides an iterator for address book entries.
69 */
70 class Iterator
71 {
72 public:
73 Iterator();
74 Iterator( const Iterator & );
75 ~Iterator();
76
77 Iterator &operator=( const Iterator & );
78 const Addressee &operator*() const;
79 Addressee &operator*();
80 Addressee* operator->();
81 Iterator &operator++();
82 Iterator &operator++(int);
83 Iterator &operator--();
84 Iterator &operator--(int);
85 bool operator==( const Iterator &it );
86 bool operator!=( const Iterator &it );
87
88 struct IteratorData;
89 IteratorData *d;
90 };
91
92 /**
93 @short Address Book Const Iterator
94
95 This class provides a const iterator for address book entries.
96 */
97 class ConstIterator
98 {
99 public:
100 ConstIterator();
101 ConstIterator( const ConstIterator & );
102 ~ConstIterator();
103
104 ConstIterator &operator=( const ConstIterator & );
105 const Addressee &operator*() const;
106 const Addressee* operator->() const;
107 ConstIterator &operator++();
108 ConstIterator &operator++(int);
109 ConstIterator &operator--();
110 ConstIterator &operator--(int);
111 bool operator==( const ConstIterator &it );
112 bool operator!=( const ConstIterator &it );
113
114 struct ConstIteratorData;
115 ConstIteratorData *d;
116 };
117
118 /**
119 Constructs a address book object.
120
121 @param format File format class.
122 */
123 AddressBook();
124 AddressBook( const QString &config );
125 virtual ~AddressBook();
126
127 /**
128 Requests a ticket for saving the addressbook. Calling this function locks
129 the addressbook for all other processes. If the address book is already
130 locked the function returns 0. You need the returned @ref Ticket object
131 for calling the @ref save() function.
132
133 @see save()
134 */
135 Ticket *requestSaveTicket( Resource *resource=0 );
136
137 /**
138 Load address book from file.
139 */
140 bool load();
141
142 /**
143 Save address book. The address book is saved to the file, the Ticket
144 object has been requested for by @ref requestSaveTicket().
145
146 @param ticket a ticket object returned by @ref requestSaveTicket()
147 */
148 bool save( Ticket *ticket );
149
150 /**
151 Returns a iterator for first entry of address book.
152 */
153 Iterator begin();
154
155 /**
156 Returns a const iterator for first entry of address book.
157 */
158 ConstIterator begin() const;
159
160 /**
161 Returns a iterator for first entry of address book.
162 */
163 Iterator end();
164
165 /**
166 Returns a const iterator for first entry of address book.
167 */
168 ConstIterator end() const;
169
170 /**
171 Removes all entries from address book.
172 */
173 void clear();
174
175 /**
176 Insert an Addressee object into address book. If an object with the same
177 unique id already exists in the address book it it replaced by the new
178 one. If not the new object is appended to the address book.
179 */
180 void insertAddressee( const Addressee & );
181
182 /**
183 Removes entry from the address book.
184 */
185 void removeAddressee( const Addressee & );
186
187 /**
188 This is like @ref removeAddressee() just above, with the difference that
189 the first element is a iterator, returned by @ref begin().
190 */
191 void removeAddressee( const Iterator & );
192
193 /**
194 Find the specified entry in address book. Returns end(), if the entry
195 couldn't be found.
196 */
197 Iterator find( const Addressee & );
198
199 /**
200 Find the entry specified by an unique id. Returns an empty Addressee
201 object, if the address book does not contain an entry with this id.
202 */
203 Addressee findByUid( const QString & );
204
205
206 /**
207 Returns a list of all addressees in the address book. This list can
208 be sorted with @ref KABC::AddresseeList for example.
209 */
210 Addressee::List allAddressees();
211
212 /**
213 Find all entries with the specified name in the address book. Returns
214 an empty list, if no entries could be found.
215 */
216 Addressee::List findByName( const QString & );
217
218 /**
219 Find all entries with the specified email address in the address book.
220 Returns an empty list, if no entries could be found.
221 */
222 Addressee::List findByEmail( const QString & );
223
224 /**
225 Find all entries wich have the specified category in the address book.
226 Returns an empty list, if no entries could be found.
227 */
228 Addressee::List findByCategory( const QString & );
229
230 /**
231 Return a string identifying this addressbook.
232 */
233 virtual QString identifier();
234
235 /**
236 Used for debug output.
237 */
238 void dump() const;
239
240 void emitAddressBookLocked() { emit addressBookLocked( this ); }
241 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
242 void emitAddressBookChanged() { emit addressBookChanged( this ); }
243
244 /**
245 Return list of all Fields known to the address book which are associated
246 with the given field category.
247 */
248 Field::List fields( int category = Field::All );
249
250 /**
251 Add custom field to address book.
252
253 @param label User visible label of the field.
254 @param category Ored list of field categories.
255 @param key Identifier used as key for reading and writing the field.
256 @param app String used as application key for reading and writing
257 the field.
258 */
259 bool addCustomField( const QString &label, int category = Field::All,
260 const QString &key = QString::null,
261 const QString &app = QString::null );
262
263
264 /**
265 Add address book resource.
266 */
267 bool addResource( Resource * );
268
269 /**
270 Remove address book resource.
271 */
272 bool removeResource( Resource * );
273
274 /**
275 Return pointer list of all resources.
276 */
277 QPtrList<Resource> resources();
278
279 /**
280 Set the @p ErrorHandler, that is used by @ref error() to
281 provide gui-independend error messages.
282 */
283 void setErrorHandler( ErrorHandler * );
284
285 /**
286 Shows gui independend error messages.
287 */
288 void error( const QString& );
289
290 /**
291 Query all resources to clean up their lock files
292 */
293 void cleanUp();
294
295 signals:
296 /**
297 Emitted, when the address book has changed on disk.
298 */
299 void addressBookChanged( AddressBook * );
300
301 /**
302 Emitted, when the address book has been locked for writing.
303 */
304 void addressBookLocked( AddressBook * );
305
306 /**
307 Emitted, when the address book has been unlocked.
308 */
309 void addressBookUnlocked( AddressBook * );
310
311 protected:
312 void deleteRemovedAddressees();
313 void setStandardResource( Resource * );
314 Resource *standardResource();
315 KRES::Manager<Resource> *resourceManager();
316
317 private:
318#ifndef KAB_EMBEDDED
319 QPtrList<Resource> mDummy; // Remove in KDE 4
320#endif //KAB_EMBEDDED
321
322#ifdef KAB_EMBEDDED
323//US optimization
324 void init(const QString &config);
325#endif //KAB_EMBEDDED
326
327
328 struct AddressBookData;
329 AddressBookData *d;
330};
331
332QDataStream &operator<<( QDataStream &, const AddressBook & );
333QDataStream &operator>>( QDataStream &, AddressBook & );
334
335}
336
337#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
new file mode 100644
index 0000000..5cb194a
--- a/dev/null
+++ b/kabc/addressee.cpp
@@ -0,0 +1,1616 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/
2/*
3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#include <kconfig.h>
30
31#include <ksharedptr.h>
32#include <kdebug.h>
33#include <kapplication.h>
34#include <klocale.h>
35//US
36#include <kstandarddirs.h>
37
38//US #include "resource.h"
39#include "addressee.h"
40
41using namespace KABC;
42
43static bool matchBinaryPattern( int value, int pattern );
44
45struct Addressee::AddresseeData : public KShared
46{
47 QString uid;
48 QString name;
49 QString formattedName;
50 QString familyName;
51 QString givenName;
52 QString additionalName;
53 QString prefix;
54 QString suffix;
55 QString nickName;
56 QDateTime birthday;
57 QString mailer;
58 TimeZone timeZone;
59 Geo geo;
60 QString title;
61 QString role;
62 QString organization;
63 QString note;
64 QString productId;
65 QDateTime revision;
66 QString sortString;
67 KURL url;
68 Secrecy secrecy;
69 Picture logo;
70 Picture photo;
71 Sound sound;
72 Agent agent;
73
74 PhoneNumber::List phoneNumbers;
75 Address::List addresses;
76 Key::List keys;
77 QStringList emails;
78 QStringList categories;
79 QStringList custom;
80
81 Resource *resource;
82
83 bool empty :1;
84 bool changed :1;
85};
86
87Addressee::Addressee()
88{
89 mData = new AddresseeData;
90 mData->empty = true;
91 mData->changed = false;
92 mData->resource = 0;
93}
94
95Addressee::~Addressee()
96{
97}
98
99Addressee::Addressee( const Addressee &a )
100{
101 mData = a.mData;
102}
103
104Addressee &Addressee::operator=( const Addressee &a )
105{
106 mData = a.mData;
107 return (*this);
108}
109
110Addressee Addressee::copy()
111{
112 Addressee a;
113 *(a.mData) = *mData;
114 return a;
115}
116
117void Addressee::detach()
118{
119 if ( mData.count() == 1 ) return;
120 *this = copy();
121}
122
123bool Addressee::operator==( const Addressee &a ) const
124{
125 if ( uid() != a.uid() ) return false;
126 if ( mData->name != a.mData->name ) return false;
127 if ( mData->formattedName != a.mData->formattedName ) return false;
128 if ( mData->familyName != a.mData->familyName ) return false;
129 if ( mData->givenName != a.mData->givenName ) return false;
130 if ( mData->additionalName != a.mData->additionalName ) return false;
131 if ( mData->prefix != a.mData->prefix ) return false;
132 if ( mData->suffix != a.mData->suffix ) return false;
133 if ( mData->nickName != a.mData->nickName ) return false;
134 if ( mData->birthday != a.mData->birthday ) return false;
135 if ( mData->mailer != a.mData->mailer ) return false;
136 if ( mData->timeZone != a.mData->timeZone ) return false;
137 if ( mData->geo != a.mData->geo ) return false;
138 if ( mData->title != a.mData->title ) return false;
139 if ( mData->role != a.mData->role ) return false;
140 if ( mData->organization != a.mData->organization ) return false;
141 if ( mData->note != a.mData->note ) return false;
142 if ( mData->productId != a.mData->productId ) return false;
143 if ( mData->revision != a.mData->revision ) return false;
144 if ( mData->sortString != a.mData->sortString ) return false;
145 if ( mData->secrecy != a.mData->secrecy ) return false;
146 if ( mData->logo != a.mData->logo ) return false;
147 if ( mData->photo != a.mData->photo ) return false;
148 if ( mData->sound != a.mData->sound ) return false;
149 if ( mData->agent != a.mData->agent ) return false;
150 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
151 ( mData->url != a.mData->url ) ) return false;
152 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
153 if ( mData->addresses != a.mData->addresses ) return false;
154 if ( mData->keys != a.mData->keys ) return false;
155 if ( mData->emails != a.mData->emails ) return false;
156 if ( mData->categories != a.mData->categories ) return false;
157 if ( mData->custom != a.mData->custom ) return false;
158
159 return true;
160}
161
162bool Addressee::operator!=( const Addressee &a ) const
163{
164 return !( a == *this );
165}
166
167bool Addressee::isEmpty() const
168{
169 return mData->empty;
170}
171
172void Addressee::setUid( const QString &id )
173{
174 if ( id == mData->uid ) return;
175 detach();
176 mData->empty = false;
177 mData->uid = id;
178}
179
180QString Addressee::uid() const
181{
182 if ( mData->uid.isEmpty() )
183 mData->uid = KApplication::randomString( 10 );
184
185 return mData->uid;
186}
187
188QString Addressee::uidLabel()
189{
190 return i18n("Unique Identifier");
191}
192
193void Addressee::setName( const QString &name )
194{
195 if ( name == mData->name ) return;
196 detach();
197 mData->empty = false;
198 mData->name = name;
199}
200
201QString Addressee::name() const
202{
203 return mData->name;
204}
205
206QString Addressee::nameLabel()
207{
208 return i18n("Name");
209}
210
211
212void Addressee::setFormattedName( const QString &formattedName )
213{
214 if ( formattedName == mData->formattedName ) return;
215 detach();
216 mData->empty = false;
217 mData->formattedName = formattedName;
218}
219
220QString Addressee::formattedName() const
221{
222 return mData->formattedName;
223}
224
225QString Addressee::formattedNameLabel()
226{
227 return i18n("Formatted Name");
228}
229
230
231void Addressee::setFamilyName( const QString &familyName )
232{
233 if ( familyName == mData->familyName ) return;
234 detach();
235 mData->empty = false;
236 mData->familyName = familyName;
237}
238
239QString Addressee::familyName() const
240{
241 return mData->familyName;
242}
243
244QString Addressee::familyNameLabel()
245{
246 return i18n("Family Name");
247}
248
249
250void Addressee::setGivenName( const QString &givenName )
251{
252 if ( givenName == mData->givenName ) return;
253 detach();
254 mData->empty = false;
255 mData->givenName = givenName;
256}
257
258QString Addressee::givenName() const
259{
260 return mData->givenName;
261}
262
263QString Addressee::givenNameLabel()
264{
265 return i18n("Given Name");
266}
267
268
269void Addressee::setAdditionalName( const QString &additionalName )
270{
271 if ( additionalName == mData->additionalName ) return;
272 detach();
273 mData->empty = false;
274 mData->additionalName = additionalName;
275}
276
277QString Addressee::additionalName() const
278{
279 return mData->additionalName;
280}
281
282QString Addressee::additionalNameLabel()
283{
284 return i18n("Additional Names");
285}
286
287
288void Addressee::setPrefix( const QString &prefix )
289{
290 if ( prefix == mData->prefix ) return;
291 detach();
292 mData->empty = false;
293 mData->prefix = prefix;
294}
295
296QString Addressee::prefix() const
297{
298 return mData->prefix;
299}
300
301QString Addressee::prefixLabel()
302{
303 return i18n("Honorific Prefixes");
304}
305
306
307void Addressee::setSuffix( const QString &suffix )
308{
309 if ( suffix == mData->suffix ) return;
310 detach();
311 mData->empty = false;
312 mData->suffix = suffix;
313}
314
315QString Addressee::suffix() const
316{
317 return mData->suffix;
318}
319
320QString Addressee::suffixLabel()
321{
322 return i18n("Honorific Suffixes");
323}
324
325
326void Addressee::setNickName( const QString &nickName )
327{
328 if ( nickName == mData->nickName ) return;
329 detach();
330 mData->empty = false;
331 mData->nickName = nickName;
332}
333
334QString Addressee::nickName() const
335{
336 return mData->nickName;
337}
338
339QString Addressee::nickNameLabel()
340{
341 return i18n("Nick Name");
342}
343
344
345void Addressee::setBirthday( const QDateTime &birthday )
346{
347 if ( birthday == mData->birthday ) return;
348 detach();
349 mData->empty = false;
350 mData->birthday = birthday;
351}
352
353QDateTime Addressee::birthday() const
354{
355 return mData->birthday;
356}
357
358QString Addressee::birthdayLabel()
359{
360 return i18n("Birthday");
361}
362
363
364QString Addressee::homeAddressStreetLabel()
365{
366 return i18n("Home Address Street");
367}
368
369
370QString Addressee::homeAddressLocalityLabel()
371{
372 return i18n("Home Address Locality");
373}
374
375
376QString Addressee::homeAddressRegionLabel()
377{
378 return i18n("Home Address Region");
379}
380
381
382QString Addressee::homeAddressPostalCodeLabel()
383{
384 return i18n("Home Address Postal Code");
385}
386
387
388QString Addressee::homeAddressCountryLabel()
389{
390 return i18n("Home Address Country");
391}
392
393
394QString Addressee::homeAddressLabelLabel()
395{
396 return i18n("Home Address Label");
397}
398
399
400QString Addressee::businessAddressStreetLabel()
401{
402 return i18n("Business Address Street");
403}
404
405
406QString Addressee::businessAddressLocalityLabel()
407{
408 return i18n("Business Address Locality");
409}
410
411
412QString Addressee::businessAddressRegionLabel()
413{
414 return i18n("Business Address Region");
415}
416
417
418QString Addressee::businessAddressPostalCodeLabel()
419{
420 return i18n("Business Address Postal Code");
421}
422
423
424QString Addressee::businessAddressCountryLabel()
425{
426 return i18n("Business Address Country");
427}
428
429
430QString Addressee::businessAddressLabelLabel()
431{
432 return i18n("Business Address Label");
433}
434
435
436QString Addressee::homePhoneLabel()
437{
438 return i18n("Home Phone");
439}
440
441
442QString Addressee::businessPhoneLabel()
443{
444 return i18n("Business Phone");
445}
446
447
448QString Addressee::mobilePhoneLabel()
449{
450 return i18n("Mobile Phone");
451}
452
453
454QString Addressee::homeFaxLabel()
455{
456 return i18n("Home Fax");
457}
458
459
460QString Addressee::businessFaxLabel()
461{
462 return i18n("Business Fax");
463}
464
465
466QString Addressee::carPhoneLabel()
467{
468 return i18n("Car Phone");
469}
470
471
472QString Addressee::isdnLabel()
473{
474 return i18n("ISDN");
475}
476
477
478QString Addressee::pagerLabel()
479{
480 return i18n("Pager");
481}
482
483
484QString Addressee::emailLabel()
485{
486 return i18n("Email Address");
487}
488
489
490void Addressee::setMailer( const QString &mailer )
491{
492 if ( mailer == mData->mailer ) return;
493 detach();
494 mData->empty = false;
495 mData->mailer = mailer;
496}
497
498QString Addressee::mailer() const
499{
500 return mData->mailer;
501}
502
503QString Addressee::mailerLabel()
504{
505 return i18n("Mail Client");
506}
507
508
509void Addressee::setTimeZone( const TimeZone &timeZone )
510{
511 if ( timeZone == mData->timeZone ) return;
512 detach();
513 mData->empty = false;
514 mData->timeZone = timeZone;
515}
516
517TimeZone Addressee::timeZone() const
518{
519 return mData->timeZone;
520}
521
522QString Addressee::timeZoneLabel()
523{
524 return i18n("Time Zone");
525}
526
527
528void Addressee::setGeo( const Geo &geo )
529{
530 if ( geo == mData->geo ) return;
531 detach();
532 mData->empty = false;
533 mData->geo = geo;
534}
535
536Geo Addressee::geo() const
537{
538 return mData->geo;
539}
540
541QString Addressee::geoLabel()
542{
543 return i18n("Geographic Position");
544}
545
546
547void Addressee::setTitle( const QString &title )
548{
549 if ( title == mData->title ) return;
550 detach();
551 mData->empty = false;
552 mData->title = title;
553}
554
555QString Addressee::title() const
556{
557 return mData->title;
558}
559
560QString Addressee::titleLabel()
561{
562 return i18n("Title");
563}
564
565
566void Addressee::setRole( const QString &role )
567{
568 if ( role == mData->role ) return;
569 detach();
570 mData->empty = false;
571 mData->role = role;
572}
573
574QString Addressee::role() const
575{
576 return mData->role;
577}
578
579QString Addressee::roleLabel()
580{
581 return i18n("Role");
582}
583
584
585void Addressee::setOrganization( const QString &organization )
586{
587 if ( organization == mData->organization ) return;
588 detach();
589 mData->empty = false;
590 mData->organization = organization;
591}
592
593QString Addressee::organization() const
594{
595 return mData->organization;
596}
597
598QString Addressee::organizationLabel()
599{
600 return i18n("Organization");
601}
602
603
604void Addressee::setNote( const QString &note )
605{
606 if ( note == mData->note ) return;
607 detach();
608 mData->empty = false;
609 mData->note = note;
610}
611
612QString Addressee::note() const
613{
614 return mData->note;
615}
616
617QString Addressee::noteLabel()
618{
619 return i18n("Note");
620}
621
622
623void Addressee::setProductId( const QString &productId )
624{
625 if ( productId == mData->productId ) return;
626 detach();
627 mData->empty = false;
628 mData->productId = productId;
629}
630
631QString Addressee::productId() const
632{
633 return mData->productId;
634}
635
636QString Addressee::productIdLabel()
637{
638 return i18n("Product Identifier");
639}
640
641
642void Addressee::setRevision( const QDateTime &revision )
643{
644 if ( revision == mData->revision ) return;
645 detach();
646 mData->empty = false;
647 mData->revision = revision;
648}
649
650QDateTime Addressee::revision() const
651{
652 return mData->revision;
653}
654
655QString Addressee::revisionLabel()
656{
657 return i18n("Revision Date");
658}
659
660
661void Addressee::setSortString( const QString &sortString )
662{
663 if ( sortString == mData->sortString ) return;
664 detach();
665 mData->empty = false;
666 mData->sortString = sortString;
667}
668
669QString Addressee::sortString() const
670{
671 return mData->sortString;
672}
673
674QString Addressee::sortStringLabel()
675{
676 return i18n("Sort String");
677}
678
679
680void Addressee::setUrl( const KURL &url )
681{
682 if ( url == mData->url ) return;
683 detach();
684 mData->empty = false;
685 mData->url = url;
686}
687
688KURL Addressee::url() const
689{
690 return mData->url;
691}
692
693QString Addressee::urlLabel()
694{
695 return i18n("URL");
696}
697
698
699void Addressee::setSecrecy( const Secrecy &secrecy )
700{
701 if ( secrecy == mData->secrecy ) return;
702 detach();
703 mData->empty = false;
704 mData->secrecy = secrecy;
705}
706
707Secrecy Addressee::secrecy() const
708{
709 return mData->secrecy;
710}
711
712QString Addressee::secrecyLabel()
713{
714 return i18n("Security Class");
715}
716
717
718void Addressee::setLogo( const Picture &logo )
719{
720 if ( logo == mData->logo ) return;
721 detach();
722 mData->empty = false;
723 mData->logo = logo;
724}
725
726Picture Addressee::logo() const
727{
728 return mData->logo;
729}
730
731QString Addressee::logoLabel()
732{
733 return i18n("Logo");
734}
735
736
737void Addressee::setPhoto( const Picture &photo )
738{
739 if ( photo == mData->photo ) return;
740 detach();
741 mData->empty = false;
742 mData->photo = photo;
743}
744
745Picture Addressee::photo() const
746{
747 return mData->photo;
748}
749
750QString Addressee::photoLabel()
751{
752 return i18n("Photo");
753}
754
755
756void Addressee::setSound( const Sound &sound )
757{
758 if ( sound == mData->sound ) return;
759 detach();
760 mData->empty = false;
761 mData->sound = sound;
762}
763
764Sound Addressee::sound() const
765{
766 return mData->sound;
767}
768
769QString Addressee::soundLabel()
770{
771 return i18n("Sound");
772}
773
774
775void Addressee::setAgent( const Agent &agent )
776{
777 if ( agent == mData->agent ) return;
778 detach();
779 mData->empty = false;
780 mData->agent = agent;
781}
782
783Agent Addressee::agent() const
784{
785 return mData->agent;
786}
787
788QString Addressee::agentLabel()
789{
790 return i18n("Agent");
791}
792
793
794
795void Addressee::setNameFromString( const QString &str )
796{
797 setFormattedName( str );
798 setName( str );
799
800 QStringList titles;
801 titles += i18n( "Dr." );
802 titles += i18n( "Miss" );
803 titles += i18n( "Mr." );
804 titles += i18n( "Mrs." );
805 titles += i18n( "Ms." );
806 titles += i18n( "Prof." );
807
808 QStringList suffixes;
809 suffixes += i18n( "I" );
810 suffixes += i18n( "II" );
811 suffixes += i18n( "III" );
812 suffixes += i18n( "Jr." );
813 suffixes += i18n( "Sr." );
814
815 QStringList prefixes;
816 prefixes += "van";
817 prefixes += "von";
818 prefixes += "de";
819
820//US KConfig config( "kabcrc" );
821 KConfig config( locateLocal( "config", "kabcrc") );
822 config.setGroup( "General" );
823 titles += config.readListEntry( "Prefixes" );
824 titles.remove( "" );
825 prefixes += config.readListEntry( "Inclusions" );
826 prefixes.remove( "" );
827 suffixes += config.readListEntry( "Suffixes" );
828 suffixes.remove( "" );
829
830 // clear all name parts
831 setPrefix( "" );
832 setGivenName( "" );
833 setAdditionalName( "" );
834 setFamilyName( "" );
835 setSuffix( "" );
836
837 if ( str.isEmpty() )
838 return;
839
840 int i = str.find(',');
841 if( i < 0 ) {
842 QStringList parts = QStringList::split( " ", str );
843 int leftOffset = 0;
844 int rightOffset = parts.count() - 1;
845
846 QString suffix;
847 while ( rightOffset >= 0 ) {
848 if ( suffixes.contains( parts[ rightOffset ] ) ) {
849 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
850 rightOffset--;
851 } else
852 break;
853 }
854 setSuffix( suffix );
855
856 if ( rightOffset < 0 )
857 return;
858
859 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
860 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
861 rightOffset--;
862 } else
863 setFamilyName( parts[ rightOffset ] );
864
865 QString prefix;
866 while ( leftOffset < rightOffset ) {
867 if ( titles.contains( parts[ leftOffset ] ) ) {
868 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
869 leftOffset++;
870 } else
871 break;
872 }
873 setPrefix( prefix );
874
875 if ( leftOffset < rightOffset ) {
876 setGivenName( parts[ leftOffset ] );
877 leftOffset++;
878 }
879
880 QString additionalName;
881 while ( leftOffset < rightOffset ) {
882 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
883 leftOffset++;
884 }
885 setAdditionalName( additionalName );
886 } else {
887 QString part1 = str.left( i );
888 QString part2 = str.mid( i + 1 );
889
890 QStringList parts = QStringList::split( " ", part1 );
891 int leftOffset = 0;
892 int rightOffset = parts.count() - 1;
893
894 QString suffix;
895 while ( rightOffset >= 0 ) {
896 if ( suffixes.contains( parts[ rightOffset ] ) ) {
897 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
898 rightOffset--;
899 } else
900 break;
901 }
902 setSuffix( suffix );
903
904 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
905 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
906 rightOffset--;
907 } else
908 setFamilyName( parts[ rightOffset ] );
909
910 QString prefix;
911 while ( leftOffset < rightOffset ) {
912 if ( titles.contains( parts[ leftOffset ] ) ) {
913 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
914 leftOffset++;
915 } else
916 break;
917 }
918
919 parts = QStringList::split( " ", part2 );
920
921 leftOffset = 0;
922 rightOffset = parts.count();
923
924 while ( leftOffset < rightOffset ) {
925 if ( titles.contains( parts[ leftOffset ] ) ) {
926 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
927 leftOffset++;
928 } else
929 break;
930 }
931 setPrefix( prefix );
932
933 if ( leftOffset < rightOffset ) {
934 setGivenName( parts[ leftOffset ] );
935 leftOffset++;
936 }
937
938 QString additionalName;
939 while ( leftOffset < rightOffset ) {
940 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
941 leftOffset++;
942 }
943 setAdditionalName( additionalName );
944 }
945}
946
947QString Addressee::realName() const
948{
949 if ( !formattedName().isEmpty() )
950 return formattedName();
951
952 QString n = assembledName();
953
954 if ( n.isEmpty() )
955 n = name();
956
957 return n;
958}
959
960QString Addressee::assembledName() const
961{
962 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
963 familyName() + " " + suffix();
964
965 return name.simplifyWhiteSpace();
966}
967
968QString Addressee::fullEmail( const QString &email ) const
969{
970 QString e;
971 if ( email.isNull() ) {
972 e = preferredEmail();
973 } else {
974 e = email;
975 }
976 if ( e.isEmpty() ) return QString::null;
977
978 QString text;
979 if ( realName().isEmpty() )
980 text = e;
981 else
982 text = assembledName() + " <" + e + ">";
983
984 return text;
985}
986
987void Addressee::insertEmail( const QString &email, bool preferred )
988{
989 detach();
990
991 QStringList::Iterator it = mData->emails.find( email );
992
993 if ( it != mData->emails.end() ) {
994 if ( !preferred || it == mData->emails.begin() ) return;
995 mData->emails.remove( it );
996 mData->emails.prepend( email );
997 } else {
998 if ( preferred ) {
999 mData->emails.prepend( email );
1000 } else {
1001 mData->emails.append( email );
1002 }
1003 }
1004}
1005
1006void Addressee::removeEmail( const QString &email )
1007{
1008 detach();
1009
1010 QStringList::Iterator it = mData->emails.find( email );
1011 if ( it == mData->emails.end() ) return;
1012
1013 mData->emails.remove( it );
1014}
1015
1016QString Addressee::preferredEmail() const
1017{
1018 if ( mData->emails.count() == 0 ) return QString::null;
1019 else return mData->emails.first();
1020}
1021
1022QStringList Addressee::emails() const
1023{
1024 return mData->emails;
1025}
1026void Addressee::setEmails( const QStringList& emails ) {
1027 detach();
1028 mData->emails = emails;
1029}
1030void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1031{
1032 detach();
1033 mData->empty = false;
1034
1035 PhoneNumber::List::Iterator it;
1036 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1037 if ( (*it).id() == phoneNumber.id() ) {
1038 *it = phoneNumber;
1039 return;
1040 }
1041 }
1042 mData->phoneNumbers.append( phoneNumber );
1043}
1044
1045void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1046{
1047 detach();
1048
1049 PhoneNumber::List::Iterator it;
1050 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1051 if ( (*it).id() == phoneNumber.id() ) {
1052 mData->phoneNumbers.remove( it );
1053 return;
1054 }
1055 }
1056}
1057
1058PhoneNumber Addressee::phoneNumber( int type ) const
1059{
1060 PhoneNumber phoneNumber( "", type );
1061 PhoneNumber::List::ConstIterator it;
1062 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1063 if ( matchBinaryPattern( (*it).type(), type ) ) {
1064 if ( (*it).type() & PhoneNumber::Pref )
1065 return (*it);
1066 else if ( phoneNumber.number().isEmpty() )
1067 phoneNumber = (*it);
1068 }
1069 }
1070
1071 return phoneNumber;
1072}
1073
1074PhoneNumber::List Addressee::phoneNumbers() const
1075{
1076 return mData->phoneNumbers;
1077}
1078
1079PhoneNumber::List Addressee::phoneNumbers( int type ) const
1080{
1081 PhoneNumber::List list;
1082
1083 PhoneNumber::List::ConstIterator it;
1084 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1085 if ( matchBinaryPattern( (*it).type(), type ) ) {
1086 list.append( *it );
1087 }
1088 }
1089 return list;
1090}
1091
1092PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1093{
1094 PhoneNumber::List::ConstIterator it;
1095 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1096 if ( (*it).id() == id ) {
1097 return *it;
1098 }
1099 }
1100 return PhoneNumber();
1101}
1102
1103void Addressee::insertKey( const Key &key )
1104{
1105 detach();
1106 mData->empty = false;
1107
1108 Key::List::Iterator it;
1109 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1110 if ( (*it).id() == key.id() ) {
1111 *it = key;
1112 return;
1113 }
1114 }
1115 mData->keys.append( key );
1116}
1117
1118void Addressee::removeKey( const Key &key )
1119{
1120 detach();
1121
1122 Key::List::Iterator it;
1123 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1124 if ( (*it).id() == key.id() ) {
1125 mData->keys.remove( key );
1126 return;
1127 }
1128 }
1129}
1130
1131Key Addressee::key( int type, QString customTypeString ) const
1132{
1133 Key::List::ConstIterator it;
1134 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1135 if ( (*it).type() == type ) {
1136 if ( type == Key::Custom ) {
1137 if ( customTypeString.isEmpty() ) {
1138 return *it;
1139 } else {
1140 if ( (*it).customTypeString() == customTypeString )
1141 return (*it);
1142 }
1143 } else {
1144 return *it;
1145 }
1146 }
1147 }
1148 return Key( QString(), type );
1149}
1150void Addressee::setKeys( const Key::List& list ) {
1151 detach();
1152 mData->keys = list;
1153}
1154
1155Key::List Addressee::keys() const
1156{
1157 return mData->keys;
1158}
1159
1160Key::List Addressee::keys( int type, QString customTypeString ) const
1161{
1162 Key::List list;
1163
1164 Key::List::ConstIterator it;
1165 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1166 if ( (*it).type() == type ) {
1167 if ( type == Key::Custom ) {
1168 if ( customTypeString.isEmpty() ) {
1169 list.append(*it);
1170 } else {
1171 if ( (*it).customTypeString() == customTypeString )
1172 list.append(*it);
1173 }
1174 } else {
1175 list.append(*it);
1176 }
1177 }
1178 }
1179 return list;
1180}
1181
1182Key Addressee::findKey( const QString &id ) const
1183{
1184 Key::List::ConstIterator it;
1185 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1186 if ( (*it).id() == id ) {
1187 return *it;
1188 }
1189 }
1190 return Key();
1191}
1192
1193QString Addressee::asString() const
1194{
1195 return "Smith, agent Smith...";
1196}
1197
1198void Addressee::dump() const
1199{
1200 return;
1201 kdDebug(5700) << "Addressee {" << endl;
1202
1203 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1204
1205 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1206 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1207 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1208 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1209 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1210 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1211 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1212 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1213 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1214 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1215 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1216 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1217 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1218 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1219 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1220 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1221 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1222 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1223 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1224 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1225 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1226 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1227 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1228 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1229 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1230
1231 kdDebug(5700) << " Emails {" << endl;
1232 QStringList e = emails();
1233 QStringList::ConstIterator it;
1234 for( it = e.begin(); it != e.end(); ++it ) {
1235 kdDebug(5700) << " " << (*it) << endl;
1236 }
1237 kdDebug(5700) << " }" << endl;
1238
1239 kdDebug(5700) << " PhoneNumbers {" << endl;
1240 PhoneNumber::List p = phoneNumbers();
1241 PhoneNumber::List::ConstIterator it2;
1242 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1243 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1244 }
1245 kdDebug(5700) << " }" << endl;
1246
1247 Address::List a = addresses();
1248 Address::List::ConstIterator it3;
1249 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1250 (*it3).dump();
1251 }
1252
1253 kdDebug(5700) << " Keys {" << endl;
1254 Key::List k = keys();
1255 Key::List::ConstIterator it4;
1256 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1257 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1258 " Key: " << (*it4).textData() <<
1259 " CustomString: " << (*it4).customTypeString() << endl;
1260 }
1261 kdDebug(5700) << " }" << endl;
1262
1263 kdDebug(5700) << "}" << endl;
1264}
1265
1266
1267void Addressee::insertAddress( const Address &address )
1268{
1269 detach();
1270 mData->empty = false;
1271
1272 Address::List::Iterator it;
1273 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1274 if ( (*it).id() == address.id() ) {
1275 *it = address;
1276 return;
1277 }
1278 }
1279 mData->addresses.append( address );
1280}
1281
1282void Addressee::removeAddress( const Address &address )
1283{
1284 detach();
1285
1286 Address::List::Iterator it;
1287 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1288 if ( (*it).id() == address.id() ) {
1289 mData->addresses.remove( it );
1290 return;
1291 }
1292 }
1293}
1294
1295Address Addressee::address( int type ) const
1296{
1297 Address address( type );
1298 Address::List::ConstIterator it;
1299 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1300 if ( matchBinaryPattern( (*it).type(), type ) ) {
1301 if ( (*it).type() & Address::Pref )
1302 return (*it);
1303 else if ( address.isEmpty() )
1304 address = (*it);
1305 }
1306 }
1307
1308 return address;
1309}
1310
1311Address::List Addressee::addresses() const
1312{
1313 return mData->addresses;
1314}
1315
1316Address::List Addressee::addresses( int type ) const
1317{
1318 Address::List list;
1319
1320 Address::List::ConstIterator it;
1321 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1322 if ( matchBinaryPattern( (*it).type(), type ) ) {
1323 list.append( *it );
1324 }
1325 }
1326
1327 return list;
1328}
1329
1330Address Addressee::findAddress( const QString &id ) const
1331{
1332 Address::List::ConstIterator it;
1333 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1334 if ( (*it).id() == id ) {
1335 return *it;
1336 }
1337 }
1338 return Address();
1339}
1340
1341void Addressee::insertCategory( const QString &c )
1342{
1343 detach();
1344 mData->empty = false;
1345
1346 if ( mData->categories.contains( c ) ) return;
1347
1348 mData->categories.append( c );
1349}
1350
1351void Addressee::removeCategory( const QString &c )
1352{
1353 detach();
1354
1355 QStringList::Iterator it = mData->categories.find( c );
1356 if ( it == mData->categories.end() ) return;
1357
1358 mData->categories.remove( it );
1359}
1360
1361bool Addressee::hasCategory( const QString &c ) const
1362{
1363 return ( mData->categories.contains( c ) );
1364}
1365
1366void Addressee::setCategories( const QStringList &c )
1367{
1368 detach();
1369 mData->empty = false;
1370
1371 mData->categories = c;
1372}
1373
1374QStringList Addressee::categories() const
1375{
1376 return mData->categories;
1377}
1378
1379void Addressee::insertCustom( const QString &app, const QString &name,
1380 const QString &value )
1381{
1382 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1383
1384 detach();
1385 mData->empty = false;
1386
1387 QString qualifiedName = app + "-" + name + ":";
1388
1389 QStringList::Iterator it;
1390 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1391 if ( (*it).startsWith( qualifiedName ) ) {
1392 (*it) = qualifiedName + value;
1393 return;
1394 }
1395 }
1396
1397 mData->custom.append( qualifiedName + value );
1398}
1399
1400void Addressee::removeCustom( const QString &app, const QString &name)
1401{
1402 detach();
1403
1404 QString qualifiedName = app + "-" + name + ":";
1405
1406 QStringList::Iterator it;
1407 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1408 if ( (*it).startsWith( qualifiedName ) ) {
1409 mData->custom.remove( it );
1410 return;
1411 }
1412 }
1413}
1414
1415QString Addressee::custom( const QString &app, const QString &name ) const
1416{
1417 QString qualifiedName = app + "-" + name + ":";
1418 QString value;
1419
1420 QStringList::ConstIterator it;
1421 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1422 if ( (*it).startsWith( qualifiedName ) ) {
1423 value = (*it).mid( (*it).find( ":" ) + 1 );
1424 break;
1425 }
1426 }
1427
1428 return value;
1429}
1430
1431void Addressee::setCustoms( const QStringList &l )
1432{
1433 detach();
1434 mData->empty = false;
1435
1436 mData->custom = l;
1437}
1438
1439QStringList Addressee::customs() const
1440{
1441 return mData->custom;
1442}
1443
1444void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1445 QString &email)
1446{
1447 int startPos, endPos, len;
1448 QString partA, partB, result;
1449 char endCh = '>';
1450
1451 startPos = rawEmail.find('<');
1452 if (startPos < 0)
1453 {
1454 startPos = rawEmail.find('(');
1455 endCh = ')';
1456 }
1457 if (startPos < 0)
1458 {
1459 // We couldn't find any separators, so we assume the whole string
1460 // is the email address
1461 email = rawEmail;
1462 fullName = "";
1463 }
1464 else
1465 {
1466 // We have a start position, try to find an end
1467 endPos = rawEmail.find(endCh, startPos+1);
1468
1469 if (endPos < 0)
1470 {
1471 // We couldn't find the end of the email address. We can only
1472 // assume the entire string is the email address.
1473 email = rawEmail;
1474 fullName = "";
1475 }
1476 else
1477 {
1478 // We have a start and end to the email address
1479
1480 // Grab the name part
1481 fullName = rawEmail.left(startPos).stripWhiteSpace();
1482
1483 // grab the email part
1484 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1485
1486 // Check that we do not have any extra characters on the end of the
1487 // strings
1488 len = fullName.length();
1489 if (fullName[0]=='"' && fullName[len-1]=='"')
1490 fullName = fullName.mid(1, len-2);
1491 else if (fullName[0]=='<' && fullName[len-1]=='>')
1492 fullName = fullName.mid(1, len-2);
1493 else if (fullName[0]=='(' && fullName[len-1]==')')
1494 fullName = fullName.mid(1, len-2);
1495 }
1496 }
1497}
1498
1499void Addressee::setResource( Resource *resource )
1500{
1501 detach();
1502 mData->resource = resource;
1503}
1504
1505Resource *Addressee::resource() const
1506{
1507 return mData->resource;
1508}
1509
1510void Addressee::setChanged( bool value )
1511{
1512 detach();
1513 mData->changed = value;
1514}
1515
1516bool Addressee::changed() const
1517{
1518 return mData->changed;
1519}
1520
1521QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
1522{
1523 if (!a.mData) return s;
1524
1525 s << a.uid();
1526
1527 s << a.mData->name;
1528 s << a.mData->formattedName;
1529 s << a.mData->familyName;
1530 s << a.mData->givenName;
1531 s << a.mData->additionalName;
1532 s << a.mData->prefix;
1533 s << a.mData->suffix;
1534 s << a.mData->nickName;
1535 s << a.mData->birthday;
1536 s << a.mData->mailer;
1537 s << a.mData->timeZone;
1538 s << a.mData->geo;
1539 s << a.mData->title;
1540 s << a.mData->role;
1541 s << a.mData->organization;
1542 s << a.mData->note;
1543 s << a.mData->productId;
1544 s << a.mData->revision;
1545 s << a.mData->sortString;
1546 s << a.mData->url;
1547 s << a.mData->secrecy;
1548 s << a.mData->logo;
1549 s << a.mData->photo;
1550 s << a.mData->sound;
1551 s << a.mData->agent;
1552 s << a.mData->phoneNumbers;
1553 s << a.mData->addresses;
1554 s << a.mData->emails;
1555 s << a.mData->categories;
1556 s << a.mData->custom;
1557 s << a.mData->keys;
1558 return s;
1559}
1560
1561QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
1562{
1563 if (!a.mData) return s;
1564
1565 s >> a.mData->uid;
1566
1567 s >> a.mData->name;
1568 s >> a.mData->formattedName;
1569 s >> a.mData->familyName;
1570 s >> a.mData->givenName;
1571 s >> a.mData->additionalName;
1572 s >> a.mData->prefix;
1573 s >> a.mData->suffix;
1574 s >> a.mData->nickName;
1575 s >> a.mData->birthday;
1576 s >> a.mData->mailer;
1577 s >> a.mData->timeZone;
1578 s >> a.mData->geo;
1579 s >> a.mData->title;
1580 s >> a.mData->role;
1581 s >> a.mData->organization;
1582 s >> a.mData->note;
1583 s >> a.mData->productId;
1584 s >> a.mData->revision;
1585 s >> a.mData->sortString;
1586 s >> a.mData->url;
1587 s >> a.mData->secrecy;
1588 s >> a.mData->logo;
1589 s >> a.mData->photo;
1590 s >> a.mData->sound;
1591 s >> a.mData->agent;
1592 s >> a.mData->phoneNumbers;
1593 s >> a.mData->addresses;
1594 s >> a.mData->emails;
1595 s >> a.mData->categories;
1596 s >> a.mData->custom;
1597 s >> a.mData->keys;
1598
1599 a.mData->empty = false;
1600
1601 return s;
1602}
1603
1604bool matchBinaryPattern( int value, int pattern )
1605{
1606 /**
1607 We want to match all telephonnumbers/addresses which have the bits in the
1608 pattern set. More are allowed.
1609 if pattern == 0 we have a special handling, then we want only those with
1610 exactly no bit set.
1611 */
1612 if ( pattern == 0 )
1613 return ( value == 0 );
1614 else
1615 return ( pattern == ( pattern & value ) );
1616}
diff --git a/kabc/addressee.h b/kabc/addressee.h
new file mode 100644
index 0000000..ee98e03
--- a/dev/null
+++ b/kabc/addressee.h
@@ -0,0 +1,817 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/
2/*
3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#ifndef KABC_ADDRESSEE_H
30#define KABC_ADDRESSEE_H
31
32#include <qdatetime.h>
33#include <qstring.h>
34#include <qstringlist.h>
35#include <qvaluelist.h>
36
37#include <ksharedptr.h>
38#include <kurl.h>
39
40#include "address.h"
41#include "agent.h"
42#include "geo.h"
43#include "key.h"
44#include "phonenumber.h"
45#include "picture.h"
46#include "secrecy.h"
47#include "sound.h"
48#include "timezone.h"
49
50namespace KABC {
51
52class Resource;
53
54/**
55 @short address book entry
56
57 This class represents an entry in the address book.
58
59 The data of this class is implicitly shared. You can pass this class by value.
60
61 If you need the name of a field for presenting it to the user you should use
62 the functions ending in Label(). They return a translated string which can be
63 used as label for the corresponding field.
64
65 About the name fields:
66
67 givenName() is the first name and familyName() the last name. In some
68 countries the family name comes first, that's the reason for the
69 naming. formattedName() is the full name with the correct formatting.
70 It is used as an override, when the correct formatting can't be generated
71 from the other name fields automatically.
72
73 realName() returns a fully formatted name(). It uses formattedName, if set,
74 otherwise it constucts the name from the name fields. As fallback, if
75 nothing else is set it uses name().
76
77 name() is the NAME type of RFC2426. It can be used as internal name for the
78 data enty, but shouldn't be used for displaying the data to the user.
79 */
80class Addressee
81{
82 friend QDataStream &operator<<( QDataStream &, const Addressee & );
83 friend QDataStream &operator>>( QDataStream &, Addressee & );
84
85 public:
86 typedef QValueList<Addressee> List;
87
88 /**
89 Construct an empty address book entry.
90 */
91 Addressee();
92 ~Addressee();
93
94 Addressee( const Addressee & );
95 Addressee &operator=( const Addressee & );
96
97 bool operator==( const Addressee & ) const;
98 bool operator!=( const Addressee & ) const;
99
100 /**
101 Return, if the address book entry is empty.
102 */
103 bool isEmpty() const;
104
105 /**
106 Set unique identifier.
107 */
108 void setUid( const QString &uid );
109 /**
110 Return unique identifier.
111 */
112 QString uid() const;
113 /**
114 Return translated label for uid field.
115 */
116 static QString uidLabel();
117
118 /**
119 Set name.
120 */
121 void setName( const QString &name );
122 /**
123 Return name.
124 */
125 QString name() const;
126 /**
127 Return translated label for name field.
128 */
129 static QString nameLabel();
130
131 /**
132 Set formatted name.
133 */
134 void setFormattedName( const QString &formattedName );
135 /**
136 Return formatted name.
137 */
138 QString formattedName() const;
139 /**
140 Return translated label for formattedName field.
141 */
142 static QString formattedNameLabel();
143
144 /**
145 Set family name.
146 */
147 void setFamilyName( const QString &familyName );
148 /**
149 Return family name.
150 */
151 QString familyName() const;
152 /**
153 Return translated label for familyName field.
154 */
155 static QString familyNameLabel();
156
157 /**
158 Set given name.
159 */
160 void setGivenName( const QString &givenName );
161 /**
162 Return given name.
163 */
164 QString givenName() const;
165 /**
166 Return translated label for givenName field.
167 */
168 static QString givenNameLabel();
169
170 /**
171 Set additional names.
172 */
173 void setAdditionalName( const QString &additionalName );
174 /**
175 Return additional names.
176 */
177 QString additionalName() const;
178 /**
179 Return translated label for additionalName field.
180 */
181 static QString additionalNameLabel();
182
183 /**
184 Set honorific prefixes.
185 */
186 void setPrefix( const QString &prefix );
187 /**
188 Return honorific prefixes.
189 */
190 QString prefix() const;
191 /**
192 Return translated label for prefix field.
193 */
194 static QString prefixLabel();
195
196 /**
197 Set honorific suffixes.
198 */
199 void setSuffix( const QString &suffix );
200 /**
201 Return honorific suffixes.
202 */
203 QString suffix() const;
204 /**
205 Return translated label for suffix field.
206 */
207 static QString suffixLabel();
208
209 /**
210 Set nick name.
211 */
212 void setNickName( const QString &nickName );
213 /**
214 Return nick name.
215 */
216 QString nickName() const;
217 /**
218 Return translated label for nickName field.
219 */
220 static QString nickNameLabel();
221
222 /**
223 Set birthday.
224 */
225 void setBirthday( const QDateTime &birthday );
226 /**
227 Return birthday.
228 */
229 QDateTime birthday() const;
230 /**
231 Return translated label for birthday field.
232 */
233 static QString birthdayLabel();
234
235 /**
236 Return translated label for homeAddressStreet field.
237 */
238 static QString homeAddressStreetLabel();
239
240 /**
241 Return translated label for homeAddressLocality field.
242 */
243 static QString homeAddressLocalityLabel();
244
245 /**
246 Return translated label for homeAddressRegion field.
247 */
248 static QString homeAddressRegionLabel();
249
250 /**
251 Return translated label for homeAddressPostalCode field.
252 */
253 static QString homeAddressPostalCodeLabel();
254
255 /**
256 Return translated label for homeAddressCountry field.
257 */
258 static QString homeAddressCountryLabel();
259
260 /**
261 Return translated label for homeAddressLabel field.
262 */
263 static QString homeAddressLabelLabel();
264
265 /**
266 Return translated label for businessAddressStreet field.
267 */
268 static QString businessAddressStreetLabel();
269
270 /**
271 Return translated label for businessAddressLocality field.
272 */
273 static QString businessAddressLocalityLabel();
274
275 /**
276 Return translated label for businessAddressRegion field.
277 */
278 static QString businessAddressRegionLabel();
279
280 /**
281 Return translated label for businessAddressPostalCode field.
282 */
283 static QString businessAddressPostalCodeLabel();
284
285 /**
286 Return translated label for businessAddressCountry field.
287 */
288 static QString businessAddressCountryLabel();
289
290 /**
291 Return translated label for businessAddressLabel field.
292 */
293 static QString businessAddressLabelLabel();
294
295 /**
296 Return translated label for homePhone field.
297 */
298 static QString homePhoneLabel();
299
300 /**
301 Return translated label for businessPhone field.
302 */
303 static QString businessPhoneLabel();
304
305 /**
306 Return translated label for mobilePhone field.
307 */
308 static QString mobilePhoneLabel();
309
310 /**
311 Return translated label for homeFax field.
312 */
313 static QString homeFaxLabel();
314
315 /**
316 Return translated label for businessFax field.
317 */
318 static QString businessFaxLabel();
319
320 /**
321 Return translated label for carPhone field.
322 */
323 static QString carPhoneLabel();
324
325 /**
326 Return translated label for isdn field.
327 */
328 static QString isdnLabel();
329
330 /**
331 Return translated label for pager field.
332 */
333 static QString pagerLabel();
334
335 /**
336 Return translated label for email field.
337 */
338 static QString emailLabel();
339
340 /**
341 Set mail client.
342 */
343 void setMailer( const QString &mailer );
344 /**
345 Return mail client.
346 */
347 QString mailer() const;
348 /**
349 Return translated label for mailer field.
350 */
351 static QString mailerLabel();
352
353 /**
354 Set time zone.
355 */
356 void setTimeZone( const TimeZone &timeZone );
357 /**
358 Return time zone.
359 */
360 TimeZone timeZone() const;
361 /**
362 Return translated label for timeZone field.
363 */
364 static QString timeZoneLabel();
365
366 /**
367 Set geographic position.
368 */
369 void setGeo( const Geo &geo );
370 /**
371 Return geographic position.
372 */
373 Geo geo() const;
374 /**
375 Return translated label for geo field.
376 */
377 static QString geoLabel();
378
379 /**
380 Set title.
381 */
382 void setTitle( const QString &title );
383 /**
384 Return title.
385 */
386 QString title() const;
387 /**
388 Return translated label for title field.
389 */
390 static QString titleLabel();
391
392 /**
393 Set role.
394 */
395 void setRole( const QString &role );
396 /**
397 Return role.
398 */
399 QString role() const;
400 /**
401 Return translated label for role field.
402 */
403 static QString roleLabel();
404
405 /**
406 Set organization.
407 */
408 void setOrganization( const QString &organization );
409 /**
410 Return organization.
411 */
412 QString organization() const;
413 /**
414 Return translated label for organization field.
415 */
416 static QString organizationLabel();
417
418 /**
419 Set note.
420 */
421 void setNote( const QString &note );
422 /**
423 Return note.
424 */
425 QString note() const;
426 /**
427 Return translated label for note field.
428 */
429 static QString noteLabel();
430
431 /**
432 Set product identifier.
433 */
434 void setProductId( const QString &productId );
435 /**
436 Return product identifier.
437 */
438 QString productId() const;
439 /**
440 Return translated label for productId field.
441 */
442 static QString productIdLabel();
443
444 /**
445 Set revision date.
446 */
447 void setRevision( const QDateTime &revision );
448 /**
449 Return revision date.
450 */
451 QDateTime revision() const;
452 /**
453 Return translated label for revision field.
454 */
455 static QString revisionLabel();
456
457 /**
458 Set sort string.
459 */
460 void setSortString( const QString &sortString );
461 /**
462 Return sort string.
463 */
464 QString sortString() const;
465 /**
466 Return translated label for sortString field.
467 */
468 static QString sortStringLabel();
469
470 /**
471 Set URL.
472 */
473 void setUrl( const KURL &url );
474 /**
475 Return URL.
476 */
477 KURL url() const;
478 /**
479 Return translated label for url field.
480 */
481 static QString urlLabel();
482
483 /**
484 Set security class.
485 */
486 void setSecrecy( const Secrecy &secrecy );
487 /**
488 Return security class.
489 */
490 Secrecy secrecy() const;
491 /**
492 Return translated label for secrecy field.
493 */
494 static QString secrecyLabel();
495
496 /**
497 Set logo.
498 */
499 void setLogo( const Picture &logo );
500 /**
501 Return logo.
502 */
503 Picture logo() const;
504 /**
505 Return translated label for logo field.
506 */
507 static QString logoLabel();
508
509 /**
510 Set photo.
511 */
512 void setPhoto( const Picture &photo );
513 /**
514 Return photo.
515 */
516 Picture photo() const;
517 /**
518 Return translated label for photo field.
519 */
520 static QString photoLabel();
521
522 /**
523 Set sound.
524 */
525 void setSound( const Sound &sound );
526 /**
527 Return sound.
528 */
529 Sound sound() const;
530 /**
531 Return translated label for sound field.
532 */
533 static QString soundLabel();
534
535 /**
536 Set agent.
537 */
538 void setAgent( const Agent &agent );
539 /**
540 Return agent.
541 */
542 Agent agent() const;
543 /**
544 Return translated label for agent field.
545 */
546 static QString agentLabel();
547
548 /**
549 Set name fields by parsing the given string and trying to associate the
550 parts of the string with according fields. This function should probably
551 be a bit more clever.
552 */
553 void setNameFromString( const QString & );
554
555 /**
556 Return the name of the addressee. This is calculated from all the name
557 fields.
558 */
559 QString realName() const;
560
561 /**
562 Return the name that consists of all name parts.
563 */
564 QString assembledName() const;
565
566 /**
567 Return email address including real name.
568
569 @param email Email address to be used to construct the full email string.
570 If this is QString::null the preferred email address is used.
571 */
572 QString fullEmail( const QString &email=QString::null ) const;
573
574 /**
575 Insert an email address. If the email address already exists in this
576 addressee it is not duplicated.
577
578 @param email Email address
579 @param preferred Set to true, if this is the preferred email address of
580 the addressee.
581 */
582 void insertEmail( const QString &email, bool preferred=false );
583
584 /**
585 Remove email address. If the email address doesn't exist, nothing happens.
586 */
587 void removeEmail( const QString &email );
588
589 /**
590 Return preferred email address. This is the first email address or the
591 last one added with @ref insertEmail() with a set preferred parameter.
592 */
593 QString preferredEmail() const;
594
595 /**
596 Return list of all email addresses.
597 */
598 QStringList emails() const;
599
600 /**
601 Set the emails to @param.
602 The first email address gets the preferred one!
603 @param list The list of email addresses.
604 */
605 void setEmails( const QStringList& list);
606
607 /**
608 Insert a phone number. If a phone number with the same id already exists
609 in this addressee it is not duplicated.
610 */
611 void insertPhoneNumber( const PhoneNumber &phoneNumber );
612
613 /**
614 Remove phone number. If no phone number with the given id exists for this
615 addresse nothing happens.
616 */
617 void removePhoneNumber( const PhoneNumber &phoneNumber );
618
619 /**
620 Return phone number, which matches the given type.
621 */
622 PhoneNumber phoneNumber( int type ) const;
623
624 /**
625 Return list of all phone numbers.
626 */
627 PhoneNumber::List phoneNumbers() const;
628
629 /**
630 Return list of phone numbers with a special type.
631 */
632 PhoneNumber::List phoneNumbers( int type ) const;
633
634 /**
635 Return phone number with the given id.
636 */
637 PhoneNumber findPhoneNumber( const QString &id ) const;
638
639 /**
640 Insert a key. If a key with the same id already exists
641 in this addressee it is not duplicated.
642 */
643 void insertKey( const Key &key );
644
645 /**
646 Remove a key. If no key with the given id exists for this
647 addresse nothing happens.
648 */
649 void removeKey( const Key &key );
650
651 /**
652 Return key, which matches the given type.
653 If @p type == Key::Custom you can specify a string
654 that should match. If you leave the string empty, the first
655 key with a custom value is returned.
656 */
657 Key key( int type, QString customTypeString = QString::null ) const;
658
659 /**
660 Return list of all keys.
661 */
662 Key::List keys() const;
663
664 /**
665 Set the list of keys
666 @param keys The keys to be set.
667 */
668 void setKeys( const Key::List& keys);
669
670 /**
671 Return list of keys with a special type.
672 If @p type == Key::Custom you can specify a string
673 that should match. If you leave the string empty, all custom
674 keys will be returned.
675 */
676 Key::List keys( int type, QString customTypeString = QString::null ) const;
677
678 /**
679 Return key with the given id.
680 */
681 Key findKey( const QString &id ) const;
682
683 /**
684 Insert an address. If an address with the same id already exists
685 in this addressee it is not duplicated.
686 */
687 void insertAddress( const Address &address );
688
689 /**
690 Remove address. If no address with the given id exists for this
691 addresse nothing happens.
692 */
693 void removeAddress( const Address &address );
694
695 /**
696 Return address, which matches the given type.
697 */
698 Address address( int type ) const;
699
700 /**
701 Return list of all addresses.
702 */
703 Address::List addresses() const;
704
705 /**
706 Return list of addresses with a special type.
707 */
708 Address::List addresses( int type ) const;
709
710 /**
711 Return address with the given id.
712 */
713 Address findAddress( const QString &id ) const;
714
715 /**
716 Insert category. If the category already exists it is not duplicated.
717 */
718 void insertCategory( const QString & );
719
720 /**
721 Remove category.
722 */
723 void removeCategory( const QString & );
724
725 /**
726 Return, if addressee has the given category.
727 */
728 bool hasCategory( const QString & ) const;
729
730 /**
731 Set categories to given value.
732 */
733 void setCategories( const QStringList & );
734
735 /**
736 Return list of all set categories.
737 */
738 QStringList categories() const;
739
740 /**
741 Insert custom entry. The entry is identified by the name of the inserting
742 application and a unique name. If an entry with the given app and name
743 already exists its value is replaced with the new given value.
744 */
745 void insertCustom( const QString &app, const QString &name,
746 const QString &value );
747
748 /**
749 Remove custom entry.
750 */
751 void removeCustom( const QString &app, const QString &name );
752
753 /**
754 Return value of custom entry, identified by app and entry name.
755 */
756 QString custom( const QString &app, const QString &name ) const;
757
758 /**
759 Set all custom entries.
760 */
761 void setCustoms( const QStringList & );
762
763 /**
764 Return list of all custom entries.
765 */
766 QStringList customs() const;
767
768 /**
769 Parse full email address. The result is given back in fullName and email.
770 */
771 static void parseEmailAddress( const QString &rawEmail, QString &fullName,
772 QString &email );
773
774 /**
775 Debug output.
776 */
777 void dump() const;
778
779 /**
780 Returns string representation of the addressee.
781 */
782 QString asString() const;
783
784 /**
785 Set resource where the addressee is from.
786 */
787 void setResource( Resource *resource );
788
789 /**
790 Return pointer to resource.
791 */
792 Resource *resource() const;
793
794 /**
795 Mark addressee as changed.
796 */
797 void setChanged( bool value );
798
799 /**
800 Return whether the addressee is changed.
801 */
802 bool changed() const;
803
804 private:
805 Addressee copy();
806 void detach();
807
808 struct AddresseeData;
809 mutable KSharedPtr<AddresseeData> mData;
810};
811
812QDataStream &operator<<( QDataStream &, const Addressee & );
813QDataStream &operator>>( QDataStream &, Addressee & );
814
815}
816
817#endif
diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp
new file mode 100644
index 0000000..033e857
--- a/dev/null
+++ b/kabc/addresseedialog.cpp
@@ -0,0 +1,264 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <qlayout.h>
22#include <qpushbutton.h>
23#include <qgroupbox.h>
24#include <qapplication.h>
25#include <qregexp.h>
26
27#include <klocale.h>
28#include <kdebug.h>
29#include <kglobalsettings.h>
30
31#include "stdaddressbook.h"
32
33#include "addresseedialog.h"
34//#include "addresseedialog.moc"
35
36using namespace KABC;
37
38AddresseeItem::AddresseeItem( QListView *parent, const Addressee &addressee ) :
39 QListViewItem( parent ),
40 mAddressee( addressee )
41{
42 setText( Name, addressee.realName() );
43 setText( Email, addressee.preferredEmail() );
44}
45
46QString AddresseeItem::key( int column, bool ) const
47{
48 /* LR
49 if (column == Email) {
50 QString value = text(Email);
51 QRegExp emailRe("<\\S*>");
52 int match = emailRe.search(value);
53 if (match > -1)
54 value = value.mid(match + 1, emailRe.matchedLength() - 2);
55
56 return value.lower();
57 }
58 */
59 return text(column).lower();
60}
61
62AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) :
63 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"),
64 Ok|Cancel, Ok, parent ), mMultiple( multiple )
65{
66 QWidget *topWidget = plainPage();
67
68 QBoxLayout *topLayout = new QHBoxLayout( topWidget );
69 QBoxLayout *listLayout = new QVBoxLayout;
70 topLayout->addLayout( listLayout );
71
72 mAddresseeList = new KListView( topWidget );
73 mAddresseeList->addColumn( i18n("Name") );
74 mAddresseeList->addColumn( i18n("Email") );
75 mAddresseeList->setAllColumnsShowFocus( true );
76 mAddresseeList->setFullWidth( true );
77 listLayout->addWidget( mAddresseeList );
78 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ),
79 SLOT( slotOk() ) );
80 connect( mAddresseeList, SIGNAL( selectionChanged( QListViewItem * ) ),
81 SLOT( updateEdit( QListViewItem * ) ) );
82
83 mAddresseeEdit = new KLineEdit( topWidget );
84 //mAddresseeEdit->setCompletionMode( KGlobalSettings::CompletionAuto );
85 // connect( mAddresseeEdit->completionObject(), SIGNAL( match( const QString & ) ),
86 // SLOT( selectItem( const QString & ) ) );
87 mAddresseeEdit->setFocus();
88 //mAddresseeEdit->completionObject()->setIgnoreCase( true );
89 listLayout->addWidget( mAddresseeEdit );
90
91 //setInitialSize( QSize( 450, 300 ) );
92
93 if ( mMultiple ) {
94 QBoxLayout *selectedLayout = new QVBoxLayout;
95 topLayout->addLayout( selectedLayout );
96 topLayout->setSpacing( spacingHint() );
97
98 QGroupBox *selectedGroup = new QGroupBox( 1, Horizontal, i18n("Selected"),
99 topWidget );
100 selectedLayout->addWidget( selectedGroup );
101
102 mSelectedList = new KListView( selectedGroup );
103 mSelectedList->addColumn( i18n("Name") );
104 mSelectedList->addColumn( i18n("Email") );
105 mSelectedList->setAllColumnsShowFocus( true );
106 mSelectedList->setFullWidth( true );
107 connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ),
108 SLOT( removeSelected() ) );
109
110 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup );
111 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) );
112
113 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ),
114 SLOT( addSelected( QListViewItem * ) ) );
115
116 // setInitialSize( QSize( 650, 350 ) );
117 }
118
119 mAddressBook = StdAddressBook::self( true );
120 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ),
121 SLOT( addressBookChanged() ) );
122 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ),
123 SLOT( addressBookChanged() ) );
124
125 loadAddressBook();
126}
127
128AddresseeDialog::~AddresseeDialog()
129{
130}
131
132void AddresseeDialog::loadAddressBook()
133{
134 mAddresseeList->clear();
135 mItemDict.clear();
136 //mAddresseeEdit->completionObject()->clear();
137
138 AddressBook::Iterator it;
139 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
140 AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) );
141 addCompletionItem( (*it).realName(), item );
142 addCompletionItem( (*it).preferredEmail(), item );
143 }
144}
145
146void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item )
147{
148 if ( str.isEmpty() ) return;
149
150 mItemDict.insert( str, item );
151 //mAddresseeEdit->completionObject()->addItem( str );
152}
153
154void AddresseeDialog::selectItem( const QString &str )
155{
156 if ( str.isEmpty() ) return;
157
158 QListViewItem *item = mItemDict.find( str );
159 if ( item ) {
160 mAddresseeList->blockSignals( true );
161 mAddresseeList->setSelected( item, true );
162 mAddresseeList->ensureItemVisible( item );
163 mAddresseeList->blockSignals( false );
164 }
165}
166
167void AddresseeDialog::updateEdit( QListViewItem *item )
168{
169 mAddresseeEdit->setText( item->text( 0 ) );
170 mAddresseeEdit->setSelection( 0, item->text( 0 ).length() );
171}
172
173void AddresseeDialog::addSelected( QListViewItem *item )
174{
175 AddresseeItem *addrItem = (AddresseeItem *)( item );
176 if ( !addrItem ) return;
177
178 Addressee a = addrItem->addressee();
179
180 QListViewItem *selectedItem = mSelectedDict.find( a.uid() );
181 if ( !selectedItem ) {
182 selectedItem = new AddresseeItem( mSelectedList, a );
183 mSelectedDict.insert( a.uid(), selectedItem );
184 }
185}
186
187void AddresseeDialog::removeSelected()
188{
189 QListViewItem *item = mSelectedList->selectedItem();
190 AddresseeItem *addrItem = (AddresseeItem *)( item );
191 if ( !addrItem ) return;
192
193 mSelectedDict.remove( addrItem->addressee().uid() );
194 delete addrItem;
195}
196
197Addressee AddresseeDialog::addressee()
198{
199 AddresseeItem *aItem = 0;
200
201 if ( mMultiple )
202 aItem = (AddresseeItem *)( mSelectedList->firstChild() );
203 else
204 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() );
205
206 if (aItem) return aItem->addressee();
207 return Addressee();
208}
209
210Addressee::List AddresseeDialog::addressees()
211{
212 Addressee::List al;
213 AddresseeItem *aItem = 0;
214
215 if ( mMultiple ) {
216 QListViewItem *item = mSelectedList->firstChild();
217 while( item ) {
218 aItem = (AddresseeItem *)( item );
219 if ( aItem ) al.append( aItem->addressee() );
220 item = item->nextSibling();
221 }
222 }
223 else
224 {
225 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() );
226 if (aItem) al.append( aItem->addressee() );
227 }
228
229 return al;
230}
231
232Addressee AddresseeDialog::getAddressee( QWidget *parent )
233{
234 AddresseeDialog *dlg = new AddresseeDialog( parent );
235 Addressee addressee;
236 int result = dlg->exec();
237
238 if ( result == QDialog::Accepted ) {
239 addressee = dlg->addressee();
240 }
241
242 delete dlg;
243 return addressee;
244}
245
246Addressee::List AddresseeDialog::getAddressees( QWidget *parent )
247{
248 AddresseeDialog *dlg = new AddresseeDialog( parent, true );
249 Addressee::List addressees;
250 if ( QApplication::desktop()->width() <= 640 )
251 dlg->showMaximized();
252 int result = dlg->exec();
253 if ( result == QDialog::Accepted ) {
254 addressees = dlg->addressees();
255 }
256
257 delete dlg;
258 return addressees;
259}
260
261void AddresseeDialog::addressBookChanged()
262{
263 loadAddressBook();
264}
diff --git a/kabc/addresseedialog.h b/kabc/addresseedialog.h
new file mode 100644
index 0000000..74e7871
--- a/dev/null
+++ b/kabc/addresseedialog.h
@@ -0,0 +1,160 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef KABC_ADDRESSEEDIALOG_H
22#define KABC_ADDRESSEEDIALOG_H
23
24#include <qdict.h>
25
26#include <kdialogbase.h>
27#include <klineedit.h>
28#include <klistview.h>
29
30#include "addressbook.h"
31
32namespace KABC {
33
34/**
35 @short Special ListViewItem, that is used by the AddresseeDialog.
36*/
37class AddresseeItem : public QListViewItem
38{
39 public:
40
41 /**
42 Type of column
43 @li @p Name - Name in Addressee
44 @li @p Email - Email in Addressee
45 */
46 enum columns { Name = 0, Email = 1 };
47
48 /**
49 Constructor.
50
51 @param parent The parent listview.
52 @param addressee The associated addressee.
53 */
54 AddresseeItem( QListView *parent, const Addressee &addressee );
55
56 /**
57 Returns the addressee.
58 */
59 Addressee addressee() const { return mAddressee; }
60
61 /**
62 Method used by QListView to sort the items.
63 */
64 virtual QString key( int column, bool ascending ) const;
65
66 private:
67 Addressee mAddressee;
68};
69
70/**
71 @short Dialog for selecting address book entries.
72
73 This class provides a dialog for selecting entries from the standard KDE
74 address book. Use the getAddressee() function to open a modal dialog,
75 returning an address book entry.
76
77 In the dialog you can select an entry from the list with the mouse or type in
78 the first letters of the name or email address you are searching for. The
79 entry matching best is automatically selected. Use double click, pressing
80 return or pressing the ok button to return the selected addressee to the
81 application.
82*/
83class AddresseeDialog : public KDialogBase
84{
85 Q_OBJECT
86
87 public:
88 /**
89 Construct addressbook entry select dialog.
90
91 @param parent parent widget
92 */
93 AddresseeDialog( QWidget *parent=0, bool multiple=false );
94
95 /**
96 Destructor.
97 */
98 virtual ~AddresseeDialog();
99
100 /**
101 Return the address chosen.
102
103 If it is a multiple select, this will return only the first address chosen
104 */
105 Addressee addressee();
106
107 /**
108 Return the list of addresses chosen
109 */
110 Addressee::List addressees();
111
112 /**
113 Select a single address book entry.
114
115 Open addressee select dialog and return the entry selected by the user.
116 If the user doesn't select an entry or presses cancel, the returned
117 addressee is empty.
118 */
119 static Addressee getAddressee( QWidget *parent );
120
121 /**
122 Select multiple address book entries.
123
124 Open addressee select dialog and return the entries selected by the user.
125 If the user doesn't select an entry or presses cancel, the returned
126 addressee list is empty.
127 */
128 static Addressee::List getAddressees( QWidget *parent );
129
130 private slots:
131 void selectItem( const QString & );
132 void updateEdit( QListViewItem *item );
133 void addSelected( QListViewItem *item );
134 void removeSelected();
135
136 protected slots:
137 void addressBookChanged();
138
139 private:
140 void loadAddressBook();
141 void addCompletionItem( const QString &str, QListViewItem *item );
142
143 bool mMultiple;
144
145 KListView *mAddresseeList;
146 KLineEdit *mAddresseeEdit;
147
148 KListView *mSelectedList;
149
150 AddressBook *mAddressBook;
151
152 QDict<QListViewItem> mItemDict;
153 QDict<QListViewItem> mSelectedDict;
154
155 class AddresseeDialogPrivate;
156 AddresseeDialogPrivate *d;
157};
158
159}
160#endif
diff --git a/kabc/addresseelist.cpp b/kabc/addresseelist.cpp
new file mode 100644
index 0000000..097e162
--- a/dev/null
+++ b/kabc/addresseelist.cpp
@@ -0,0 +1,292 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Jost Schenck <jost@schenck.de>
4 2003 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#include <kdebug.h>
30//US
31#include <qtl.h>
32
33
34#include "addresseelist.h"
35#include "field.h"
36
37using namespace KABC;
38
39//
40//
41// Traits
42//
43//
44
45bool SortingTraits::Uid::eq( const Addressee &a1, const Addressee &a2 )
46{
47 // locale awareness doesn't make sense sorting ids
48 return ( QString::compare( a1.uid(), a2.uid() ) == 0 );
49}
50
51bool SortingTraits::Uid::lt( const Addressee &a1, const Addressee &a2 )
52{
53 // locale awareness doesn't make sense sorting ids
54 return ( QString::compare( a1.uid(), a2.uid() ) < 0 );
55}
56
57bool SortingTraits::Name::eq( const Addressee &a1, const Addressee &a2 )
58{
59//US QString::localeAwareCompare is not available in my distribution. Redefine it to compare
60 return ( QString::compare( a1.name(), a2.name() ) == 0 );
61}
62
63bool SortingTraits::Name::lt( const Addressee &a1, const Addressee &a2 )
64{
65//US QString::localeAwareCompare is not available in my distribution. Redefine it to compare
66 return ( QString::compare( a1.name(), a2.name() ) < 0 );
67}
68
69bool SortingTraits::FormattedName::eq( const Addressee &a1, const Addressee &a2 )
70{
71//US QString::localeAwareCompare is not available in my distribution. Redefine it to compare
72 return ( QString::compare( a1.formattedName(), a2.formattedName() ) == 0 );
73}
74
75bool SortingTraits::FormattedName::lt( const Addressee &a1, const Addressee &a2 )
76{
77//US QString::localeAwareCompare is not available in my distribution. Redefine it to compare
78 return ( QString::compare( a1.formattedName(), a2.formattedName() ) < 0 );
79}
80
81bool SortingTraits::FamilyName::eq( const Addressee &a1, const Addressee &a2 )
82{
83//US QString::localeAwareCompare is not available in my distribution. Redefine it to compare
84 return ( QString::compare( a1.familyName(), a2.familyName() ) == 0
85 && QString::compare( a1.givenName(), a2.givenName() ) == 0 );
86}
87
88bool SortingTraits::FamilyName::lt( const Addressee &a1, const Addressee &a2 )
89{
90//US QString::localeAwareCompare is not available in my distribution. Redefine it to compare
91 int family = QString::compare( a1.familyName(), a2.familyName() );
92 if ( 0 == family ) {
93 return ( QString::compare( a1.givenName(), a2.givenName() ) < 0 );
94 } else {
95 return family < 0;
96 }
97}
98
99bool SortingTraits::GivenName::eq( const Addressee &a1, const Addressee &a2 )
100{
101//US QString::localeAwareCompare is not available in my distribution. Redefine it to compare
102 return ( QString::compare( a1.givenName(), a2.givenName() ) == 0
103 && QString::compare( a1.familyName(), a2.familyName() ) == 0 );
104}
105
106bool SortingTraits::GivenName::lt( const Addressee &a1, const Addressee &a2 )
107{
108//US QString::localeAwareCompare is not available in my distribution. Redefine it to compare
109 int given = QString::compare( a1.givenName(), a2.givenName() );
110 if ( 0 == given ) {
111 return ( QString::compare( a1.familyName(), a2.familyName() ) < 0 );
112 } else {
113 return given < 0;
114 }
115}
116
117//
118//
119// AddresseeList
120//
121//
122
123AddresseeList::AddresseeList()
124 : QValueList<Addressee>()
125{
126 mReverseSorting = false;
127 mActiveSortingCriterion = FormattedName;
128 mActiveSortingField = 0;
129}
130
131AddresseeList::~AddresseeList()
132{
133}
134
135AddresseeList::AddresseeList( const AddresseeList &l )
136 : QValueList<Addressee>( l )
137{
138 mReverseSorting = l.reverseSorting();
139 mActiveSortingCriterion = l.sortingCriterion();
140}
141
142AddresseeList::AddresseeList( const QValueList<Addressee> &l )
143 : QValueList<Addressee>( l )
144{
145 mReverseSorting = false;
146}
147
148void AddresseeList::dump() const
149{
150 kdDebug(5700) << "AddresseeList {" << endl;
151 kdDebug(5700) << "reverse order: " << ( mReverseSorting ? "true" : "false" ) << endl;
152
153 QString crit;
154 if ( Uid == mActiveSortingCriterion ) {
155 crit = "Uid";
156 } else if ( Name == mActiveSortingCriterion ) {
157 crit = "Name";
158 } else if ( FormattedName == mActiveSortingCriterion ) {
159 crit = "FormattedName";
160 } else if ( FamilyName == mActiveSortingCriterion ) {
161 crit = "FamilyName";
162 } else if ( GivenName == mActiveSortingCriterion ) {
163 crit = "GivenName";
164 } else {
165 crit = "unknown -- update dump method";
166 }
167
168 kdDebug(5700) << "sorting criterion: " << crit << endl;
169
170//US
171//US for ( const_iterator it = begin(); it != end(); ++it )
172 for ( ConstIterator it = begin(); it != end(); ++it )
173 (*it).dump();
174
175 kdDebug(5700) << "}" << endl;
176}
177
178void AddresseeList::sortBy( SortingCriterion c )
179{
180 mActiveSortingCriterion = c;
181 if ( Uid == c ) {
182 sortByTrait<SortingTraits::Uid>();
183 } else if ( Name == c ) {
184 sortByTrait<SortingTraits::Name>();
185 } else if ( FormattedName == c ) {
186 sortByTrait<SortingTraits::FormattedName>();
187 } else if ( FamilyName == c ) {
188 sortByTrait<SortingTraits::FamilyName>();
189 } else if ( GivenName==c ) {
190 sortByTrait<SortingTraits::GivenName>();
191 } else {
192 kdError(5700) << "AddresseeList sorting criterion passed for which a trait is not known. No sorting done." << endl;
193 }
194}
195
196void AddresseeList::sort()
197{
198 sortBy( mActiveSortingCriterion );
199}
200
201template<class Trait>
202void AddresseeList::sortByTrait()
203{
204 // FIXME: better sorting algorithm, bubblesort is not acceptable for larger lists.
205 //
206 // for i := 1 to n - 1
207 // do for j := 1 to n - i
208 // do if A[j] > A[j+1]
209 // then temp := A[j]
210 // A[j] := A[j + 1]
211 // A[j + 1 ] := temp
212
213//US iterator i1 = begin();
214 Iterator i1 = begin();
215//US iterator endIt = end();
216 Iterator endIt = end();
217 --endIt;
218 if ( i1 == endIt ) // don't need sorting
219 return;
220
221//US iterator i2 = endIt;
222 Iterator i2 = endIt;
223 while( i1 != endIt ) {
224//US iterator j1 = begin();
225 Iterator j1 = begin();
226//US iterator j2 = j1;
227 Iterator j2 = j1;
228 ++j2;
229 while( j1 != i2 ) {
230 if ( !mReverseSorting && Trait::lt( *j2, *j1 )
231 || mReverseSorting && Trait::lt( *j1, *j2 ) ) {
232 qSwap( *j1, *j2 );
233 }
234 ++j1;
235 ++j2;
236 }
237 ++i1;
238 --i2;
239 }
240}
241
242void AddresseeList::sortByField( Field *field )
243{
244 if ( field )
245 mActiveSortingField = field;
246
247 if ( !mActiveSortingField ) {
248 kdWarning(5700) << "sortByField called with no active sort field" << endl;
249 return;
250 }
251
252 if ( count() == 0 )
253 return;
254
255 quickSortByField( 0, count() - 1 );
256}
257
258void AddresseeList::quickSortByField( int left, int right )
259{
260 int i = left;
261 int j = right;
262 int mid = ( left + right ) / 2;
263
264//US iterator x = at( mid );
265 ConstIterator x = at( mid );
266
267 do {
268 if ( !mReverseSorting ) {
269 //US QString::localeAwareCompare was not available. Used compare instead.
270 while ( QString::compare( mActiveSortingField->value( *at( i ) ).upper(), mActiveSortingField->value( *x ).upper() ) < 0 )
271 i++;
272 //US QString::localeAwareCompare was not available. Used compare instead.
273 while ( QString::compare( mActiveSortingField->value( *at( j ) ).upper(), mActiveSortingField->value( *x ).upper() ) > 0 )
274 j--;
275 } else {
276 //US QString::localeAwareCompare was not available. Used compare instead.
277 while ( QString::compare( mActiveSortingField->value( *at( i ) ).upper(), mActiveSortingField->value( *x ).upper() ) > 0 )
278 i++;
279 //US QString::localeAwareCompare was not available. Used compare instead.
280 while ( QString::compare( mActiveSortingField->value( *at( j ) ).upper(), mActiveSortingField->value( *x ).upper() ) < 0 )
281 j--;
282 }
283 if ( i <= j ) {
284 qSwap( *at( i ), *at( j ) );
285 i++;
286 j--;
287 }
288 } while ( i <= j );
289
290 if ( left < j ) quickSortByField( left, j );
291 if ( right > i ) quickSortByField( i, right );
292}
diff --git a/kabc/addresseelist.h b/kabc/addresseelist.h
new file mode 100644
index 0000000..2df252c
--- a/dev/null
+++ b/kabc/addresseelist.h
@@ -0,0 +1,218 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Jost Schenck <jost@schenck.de>
4 2003 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#ifndef KABC_ADDRESSEELIST_H
30#define KABC_ADDRESSEELIST_H
31
32#include <qvaluelist.h>
33
34#include "addressee.h"
35
36namespace KABC {
37
38class Field;
39
40/**
41 * Each trait must implement one static function for equality, one for "less
42 * than". Class name should be the field name. A trait does not necessarily
43 * have to stick to just one field: a trait sorting by family name can e.g.
44 * sort addressees with equal family name by given name.
45 *
46 * If you want to implement reverse sorting, you do not have to write another
47 * trait, as AddresseeList takes care of that.
48 */
49namespace SortingTraits
50{
51
52class Uid
53{
54 public:
55 static bool eq( const Addressee &, const Addressee & );
56 static bool lt( const Addressee &, const Addressee & );
57};
58
59class Name
60{
61 public:
62 static bool eq( const Addressee &, const Addressee & );
63 static bool lt( const Addressee &, const Addressee & );
64};
65
66class FormattedName
67{
68 public:
69 static bool eq( const Addressee &, const Addressee & );
70 static bool lt( const Addressee &, const Addressee & );
71};
72
73class FamilyName // fallback to given name
74{
75 public:
76 static bool eq( const Addressee &, const Addressee & );
77 static bool lt( const Addressee &, const Addressee & );
78};
79
80class GivenName // fallback to family name
81{
82 public:
83 static bool eq( const Addressee &, const Addressee & );
84 static bool lt( const Addressee &, const Addressee & );
85};
86
87}
88
89/**
90 * Addressee attribute used for sorting.
91 */
92typedef enum { Uid, Name, FormattedName, FamilyName, GivenName } SortingCriterion;
93
94/**
95 * @short a QValueList of Addressee, with sorting functionality
96 *
97 * This class extends the functionality of QValueList with
98 * sorting methods specific to the Addressee class. It can be used
99 * just like any other QValueList but is no template class.
100 *
101 * An AddresseeList does not automatically keep sorted when addressees
102 * are added or removed or the sorting order is changed, as this would
103 * slow down larger operations by sorting after every step. So after
104 * such operations you have to call {@link #sort} or {@link #sortBy} to
105 * create a defined order again.
106 *
107 * Iterator usage is inherited by QValueList and extensively documented
108 * there. Please remember that the state of an iterator is undefined
109 * after any sorting operation.
110 *
111 * For the enumeration Type SortingCriterion, which specifies the
112 * field by the collection will be sorted, the following values exist:
113 * Uid, Name, FormattedName, FamilyName, GivenName.
114 *
115 * @author Jost Schenck jost@schenck.de
116 */
117class AddresseeList : public QValueList<Addressee>
118{
119 public:
120 AddresseeList();
121 ~AddresseeList();
122 AddresseeList( const AddresseeList & );
123 AddresseeList( const QValueList<Addressee> & );
124
125 /**
126 * Debug output.
127 */
128 void dump() const;
129
130 /**
131 * Determines the direction of sorting. On change, the list
132 * will <em>not</em> automatically be resorted.
133 * @param r <tt>true</tt> if sorting should be done reverse, <tt>false</tt> otherwise
134 */
135 void setReverseSorting( bool r = true ) { mReverseSorting = r; }
136
137 /**
138 * Returns the direction of sorting.
139 * @return <tt>true</tt> if sorting is done reverse, <tt>false</tt> otherwise
140 */
141 bool reverseSorting() const { return mReverseSorting; }
142
143 /**
144 * Sorts this list by a specific criterion.
145 * @param c the criterion by which should be sorted
146 */
147 void sortBy( SortingCriterion c );
148
149 /**
150 * Sorts this list by a specific field. If no parameter is given, the
151 * last used Field object will be used.
152 * @param field pointer to the Field object to be sorted by
153 */
154 void sortByField( Field *field = 0 );
155
156 /**
157 * Sorts this list by its active sorting criterion. This normally is the
158 * criterion of the last sortBy operation or <tt>FormattedName</tt> if up
159 * to now there has been no sortBy operation.
160 *
161 * Please note that the sorting trait of the last {@link #sortByTrait}
162 * method call is not remembered and thus the action can not be repeated
163 * by this method.
164 */
165 void sort();
166
167 /**
168 * Templated sort function. You normally will not want to use this but
169 * {@link #sortBy} and {@link #sort} instead as the existing sorting
170 * criteria completely suffice for most cases.
171 *
172 * However, if you do want to use some special sorting criterion, you can
173 * write a trait class that will be provided to this templated method.
174 * This trait class has to have a class declaration like the following:
175 * <pre>
176 * class MySortingTrait {
177 * public:
178 * // eq returns true if a1 and a2 are equal
179 * static bool eq(KABC::Addressee a1, KABC::Addressee a2);
180 * // lt returns true is a1 is "less than" a2
181 * static bool lt(KABC::Addressee a1, KABC::Addressee a2);
182 * };
183 * </pre>
184 * You can then pass this class to the sortByTrait method like this:
185 * <pre>
186 * myAddresseelist.sortByTrait&lt;MySortingTrait&gt;();
187 * </pre>
188 * Please note that the {@link #sort} method can not be used to repeat the
189 * sorting of the last <tt>sortByTrait</tt> action.
190 *
191 * Right now this method uses the bubble sort algorithm. This should be
192 * replaced for a better one when I have time.
193 */
194 template<class Trait> void sortByTrait();
195
196 /**
197 * Returns the active sorting criterion, ie the sorting criterion that
198 * will be used by a {@link #sort} call.
199 */
200 SortingCriterion sortingCriterion() const { return mActiveSortingCriterion; }
201
202 /**
203 * Returns the active sorting field, ie a pointer to the Field object
204 * which was used for the last {@link #sortByField} operation.
205 */
206 Field* sortingField() const { return mActiveSortingField; }
207
208 private:
209 void quickSortByField( int, int );
210
211 bool mReverseSorting;
212 SortingCriterion mActiveSortingCriterion;
213 Field* mActiveSortingField;
214};
215
216}
217
218#endif
diff --git a/kabc/agent.cpp b/kabc/agent.cpp
new file mode 100644
index 0000000..ef26cbf
--- a/dev/null
+++ b/kabc/agent.cpp
@@ -0,0 +1,155 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include "addressee.h"
29
30#include "agent.h"
31
32using namespace KABC;
33
34Agent::Agent()
35 : mAddressee( 0 ), mIntern( false )
36{
37}
38
39Agent::Agent( const QString &url )
40 : mAddressee( 0 ),mUrl( url ), mIntern( false )
41{
42}
43
44Agent::Agent( Addressee *addressee )
45 : mAddressee( addressee ), mIntern( true )
46{
47}
48
49Agent::~Agent()
50{
51 delete mAddressee;
52 mAddressee = 0;
53}
54
55bool Agent::operator==( const Agent &a ) const
56{
57 if ( mIntern != a.mIntern )
58 return false;
59
60 if ( !mIntern ) {
61 if ( mUrl != a.mUrl )
62 return false;
63 } else {
64 if ( mAddressee && !a.mAddressee ) return false;
65 if ( !mAddressee && a.mAddressee ) return false;
66 if ( !mAddressee && !a.mAddressee ) return false;
67 if ( (*mAddressee) != (*a.mAddressee) ) return false;
68 }
69
70 return true;
71}
72
73bool Agent::operator!=( const Agent &a ) const
74{
75 return !( a == *this );
76}
77
78Agent &Agent::operator=( const Agent &addr )
79{
80 if ( this == &addr )
81 return *this;
82
83 if ( addr.mIntern && addr.mAddressee ) {
84 if ( mAddressee )
85 delete mAddressee;
86
87 mAddressee = new Addressee;
88 *mAddressee = *(addr.mAddressee);
89 }
90
91 mUrl = addr.mUrl;
92 mIntern = addr.mIntern;
93
94 return *this;
95}
96
97void Agent::setUrl( const QString &url )
98{
99 mUrl = url;
100 mIntern = false;
101}
102
103void Agent::setAddressee( Addressee *addressee )
104{
105 mAddressee = addressee;
106 mIntern = true;
107}
108
109bool Agent::isIntern() const
110{
111 return mIntern;
112}
113
114QString Agent::url() const
115{
116 return mUrl;
117}
118
119Addressee *Agent::addressee() const
120{
121 return mAddressee;
122}
123
124QString Agent::asString() const
125{
126 if ( mIntern )
127 return "intern agent";
128 else
129 return mUrl;
130}
131
132QDataStream &KABC::operator<<( QDataStream &s, const Agent &agent )
133{
134 Q_UINT32 hasAddressee = ( agent.mAddressee != 0 );
135
136 s << agent.mIntern << agent.mUrl << hasAddressee;
137 if ( hasAddressee )
138 s << (*agent.mAddressee);
139
140 return s;
141}
142
143QDataStream &KABC::operator>>( QDataStream &s, Agent &agent )
144{
145 Q_UINT32 hasAddressee;
146
147 s >> agent.mIntern >> agent.mUrl >> hasAddressee;
148
149 if ( hasAddressee ) {
150 agent.mAddressee = new Addressee;
151 s >> (*agent.mAddressee);
152 }
153
154 return s;
155}
diff --git a/kabc/agent.h b/kabc/agent.h
new file mode 100644
index 0000000..fa459d5
--- a/dev/null
+++ b/kabc/agent.h
@@ -0,0 +1,129 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_AGENT_H
29#define KABC_AGENT_H
30
31namespace KABC {
32
33class Addressee;
34
35/**
36 * Important!!!
37 *
38 * At the moment the vcard format does not support saving and loading
39 * this entity.
40 */
41class Agent
42{
43 friend QDataStream &operator<<( QDataStream &, const Agent & );
44 friend QDataStream &operator>>( QDataStream &, Agent & );
45
46public:
47
48 /**
49 * Consturctor. Creates an empty object.
50 */
51 Agent();
52
53 /**
54 * Consturctor.
55 *
56 * @param url A URL that describes the position of the agent file.
57 */
58 Agent( const QString &url );
59
60 /**
61 * Consturctor.
62 *
63 * @param addressee The addressee object of the agent.
64 */
65 Agent( Addressee *addressee );
66
67 /**
68 * Destructor.
69 */
70 ~Agent();
71
72
73 bool operator==( const Agent & ) const;
74 bool operator!=( const Agent & ) const;
75 Agent &operator=( const Agent & );
76
77 /**
78 * Sets a URL for the location of the agent file. When using this
79 * function, @ref isIntern() will return 'false' until you use
80 * @ref setAddressee().
81 *
82 * @param url The location URL of the agent file.
83 */
84 void setUrl( const QString &url );
85
86 /**
87 * Sets the addressee of the agent. When using this function,
88 * @ref isIntern() will return 'true' until you use @ref setUrl().
89 *
90 * @param addressee The addressee object of the agent.
91 */
92 void setAddressee( Addressee *addressee );
93
94 /**
95 * Returns whether the agent is described by a URL (extern) or
96 * by a addressee (intern).
97 * When this method returns 'true' you can use @ref addressee() to
98 * get a @ref Addressee object. Otherwise you can request the URL
99 * of this agent by @ref url() and load the data from that location.
100 */
101 bool isIntern() const;
102
103 /**
104 * Returns the location URL of this agent.
105 */
106 QString url() const;
107
108 /**
109 * Returns the addressee object of this agent.
110 */
111 Addressee* addressee() const;
112
113 /**
114 * Returns string representation of the agent.
115 */
116 QString asString() const;
117
118private:
119 Addressee *mAddressee;
120 QString mUrl;
121
122 int mIntern;
123};
124
125QDataStream &operator<<( QDataStream &, const Agent & );
126QDataStream &operator>>( QDataStream &, Agent & );
127
128}
129#endif
diff --git a/kabc/distributionlist.cpp b/kabc/distributionlist.cpp
new file mode 100644
index 0000000..aa2725d
--- a/dev/null
+++ b/kabc/distributionlist.cpp
@@ -0,0 +1,293 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <ksimpleconfig.h>
22#include <kstandarddirs.h>
23#include <kdebug.h>
24
25#include "distributionlist.h"
26
27using namespace KABC;
28
29DistributionList::DistributionList( DistributionListManager *manager,
30 const QString &name ) :
31 mManager( manager ), mName( name )
32{
33 mManager->insert( this );
34}
35
36DistributionList::~DistributionList()
37{
38 mManager->remove( this );
39}
40
41void DistributionList::setName( const QString &name )
42{
43 mName = name;
44}
45
46QString DistributionList::name() const
47{
48 return mName;
49}
50
51void DistributionList::insertEntry( const Addressee &a, const QString &email )
52{
53 Entry e( a, email );
54
55 QValueList<Entry>::Iterator it;
56 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
57 if ( (*it).addressee.uid() == a.uid() ) {
58 /**
59 We have to check if both email addresses contains no data,
60 a simple 'email1 == email2' wont work here
61 */
62 if ( ( (*it).email.isNull() && email.isEmpty() ) ||
63 ( (*it).email.isEmpty() && email.isNull() ) ||
64 ( (*it).email == email ) ) {
65 *it = e;
66 return;
67 }
68 }
69 }
70 mEntries.append( e );
71}
72
73void DistributionList::removeEntry( const Addressee &a, const QString &email )
74{
75 QValueList<Entry>::Iterator it;
76 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
77 if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) {
78 mEntries.remove( it );
79 return;
80 }
81 }
82}
83
84QStringList DistributionList::emails() const
85{
86 QStringList emails;
87
88 Entry::List::ConstIterator it;
89 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
90 Addressee a = (*it).addressee;
91 QString email = (*it).email.isEmpty() ? a.fullEmail() :
92 a.fullEmail( (*it).email );
93
94 if ( !email.isEmpty() ) {
95 emails.append( email );
96 }
97 }
98
99 return emails;
100}
101
102DistributionList::Entry::List DistributionList::entries() const
103{
104 return mEntries;
105}
106
107
108DistributionListManager::DistributionListManager( AddressBook *ab ) :
109 mAddressBook( ab )
110{
111}
112
113DistributionListManager::~DistributionListManager()
114{
115}
116
117DistributionList *DistributionListManager::list( const QString &name )
118{
119 DistributionList *list;
120 for( list = mLists.first(); list; list = mLists.next() ) {
121 if ( list->name() == name ) return list;
122 }
123
124 return 0;
125}
126
127void DistributionListManager::insert( DistributionList *l )
128{
129 DistributionList *list;
130 for( list = mLists.first(); list; list = mLists.next() ) {
131 if ( list->name() == l->name() ) {
132 mLists.remove( list );
133 break;
134 }
135 }
136 mLists.append( l );
137}
138
139void DistributionListManager::remove( DistributionList *l )
140{
141 DistributionList *list;
142 for( list = mLists.first(); list; list = mLists.next() ) {
143 if ( list->name() == l->name() ) {
144 mLists.remove( list );
145 return;
146 }
147 }
148}
149
150QStringList DistributionListManager::listNames()
151{
152 QStringList names;
153
154 DistributionList *list;
155 for( list = mLists.first(); list; list = mLists.next() ) {
156 names.append( list->name() );
157 }
158
159 return names;
160}
161
162bool DistributionListManager::load()
163{
164 KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );
165
166#ifndef KAB_EMBEDDED
167
168 QMap<QString,QString> entryMap = cfg.entryMap( mAddressBook->identifier() );
169 if ( entryMap.isEmpty() ) {
170 kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl;
171 return false;
172 }
173
174 cfg.setGroup( mAddressBook->identifier() );
175
176 QMap<QString,QString>::ConstIterator it;
177 for( it = entryMap.begin(); it != entryMap.end(); ++it ) {
178 QString name = it.key();
179
180#else //KAB_EMBEDDED
181 cfg.setGroup( mAddressBook->identifier() );
182 //US we work in microkde with a list of distributionlists
183 QStringList distlists = cfg.readListEntry( "Lists" );
184 if ( distlists.isEmpty() ) {
185 kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl;
186 return false;
187 }
188
189 QStringList::ConstIterator it;
190 for( it = distlists.begin(); it != distlists.end(); ++it ) {
191 QString name = *it;
192
193#endif //KAB_EMBEDDED
194
195 QStringList value = cfg.readListEntry( name );
196
197 kdDebug(5700) << "DLM::load(): " << name << ": " << value.join(",") << endl;
198
199 DistributionList *list = new DistributionList( this, name );
200
201 QStringList::ConstIterator it2 = value.begin();
202 while( it2 != value.end() ) {
203 QString id = *it2++;
204 QString email = *it2;
205
206 kdDebug(5700) << "----- Entry " << id << endl;
207
208 Addressee a = mAddressBook->findByUid( id );
209 if ( !a.isEmpty() ) {
210 list->insertEntry( a, email );
211 }
212
213 if ( it2 == value.end() ) break;
214 ++it2;
215 }
216 }
217
218 return true;
219}
220
221bool DistributionListManager::save()
222{
223 kdDebug(5700) << "DistListManager::save()" << endl;
224
225 KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );
226
227 cfg.deleteGroup( mAddressBook->identifier() );
228 cfg.setGroup( mAddressBook->identifier() );
229
230 DistributionList *list;
231 for( list = mLists.first(); list; list = mLists.next() ) {
232 kdDebug(5700) << " Saving '" << list->name() << "'" << endl;
233 QStringList value;
234 DistributionList::Entry::List entries = list->entries();
235 DistributionList::Entry::List::ConstIterator it;
236 for( it = entries.begin(); it != entries.end(); ++it ) {
237 value.append( (*it).addressee.uid() );
238 value.append( (*it).email );
239 }
240 cfg.writeEntry( list->name(), value );
241 }
242
243#ifdef KAB_EMBEDDED
244//US for microKDE we have not yet sophisticated methods to load maps.
245// Because of that we store also a list of all distributionlists.
246 QStringList namelist;
247 for( list = mLists.first(); list; list = mLists.next() ) {
248 namelist.append( list->name() );
249 }
250 cfg.writeEntry( "Lists", namelist );
251
252#endif //KAB_EMBEDDED
253
254 cfg.sync();
255
256 return true;
257}
258
259DistributionListWatcher* DistributionListWatcher::mSelf = 0;
260
261DistributionListWatcher::DistributionListWatcher()
262 : QObject( 0, "DistributionListWatcher" )
263{
264#ifndef KAB_EMBEDDED
265 mDirWatch = new KDirWatch;
266 mDirWatch->addFile( locateLocal( "data", "kabc/distlists" ) );
267
268 connect( mDirWatch, SIGNAL( dirty( const QString& ) ), SIGNAL( changed() ) );
269 mDirWatch->startScan();
270#endif //KAB_EMBEDDED
271}
272
273DistributionListWatcher::~DistributionListWatcher()
274{
275#ifndef KAB_EMBEDDED
276 delete mDirWatch;
277 mDirWatch = 0;
278#endif //KAB_EMBEDDED
279}
280
281DistributionListWatcher *DistributionListWatcher::self()
282{
283 if ( !mSelf )
284 mSelf = new DistributionListWatcher();
285
286 return mSelf;
287}
288
289
290#ifndef KAB_EMBEDDED
291#include "distributionlist.moc"
292#endif //KAB_EMBEDDED
293
diff --git a/kabc/distributionlist.h b/kabc/distributionlist.h
new file mode 100644
index 0000000..ccff487
--- a/dev/null
+++ b/kabc/distributionlist.h
@@ -0,0 +1,219 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef KABC_DISTRIBUTIONLIST_H
22#define KABC_DISTRIBUTIONLIST_H
23
24#include <kdirwatch.h>
25
26#include "addressbook.h"
27
28namespace KABC {
29
30class DistributionListManager;
31
32/**
33 @short Distribution list of email addresses
34
35 This class represents a list of email addresses. Each email address is
36 associated with an address book entry. If the address book entry changes, the
37 entry in the distribution list is automatically updated.
38*/
39class DistributionList
40{
41 public:
42 /**
43 @short Distribution List Entry
44
45 This class represents an entry of a distribution list. It consists of an
46 addressee and an email address. If the email address is null, the
47 preferred email address of the addressee is used.
48 */
49 struct Entry
50 {
51 typedef QValueList<Entry> List;
52
53 Entry() {}
54 Entry( const Addressee &_addressee, const QString &_email ) :
55 addressee( _addressee ), email( _email ) {}
56
57 Addressee addressee;
58 QString email;
59 };
60
61 /**
62 Create distribution list object.
63
64 @param manager Managing object of this list.
65 @param name Name of this list.
66 */
67 DistributionList( DistributionListManager *manager, const QString &name );
68
69 /**
70 Destructor.
71 */
72 ~DistributionList();
73
74 /**
75 Set name of this list. The name is used as key by the
76 DistributinListManager.
77 */
78 void setName( const QString & );
79
80 /**
81 Get name of this list.
82 */
83 QString name() const;
84
85 /**
86 Insert an entry into this distribution list. If the entry already exists
87 nothing happens.
88 */
89 void insertEntry( const Addressee &, const QString &email=QString::null );
90
91 /**
92 Remove an entry from this distribution list. If the entry doesn't exist
93 nothing happens.
94 */
95 void removeEntry( const Addressee &, const QString &email=QString::null );
96
97 /**
98 Return list of email addresses, which belong to this distributon list.
99 These addresses can be directly used by e.g. a mail client.
100 */
101 QStringList emails() const;
102
103 /**
104 Return list of entries belonging to this distribution list. This function
105 is mainly useful for a distribution list editor.
106 */
107 Entry::List entries() const;
108
109 private:
110 DistributionListManager *mManager;
111 QString mName;
112
113 Entry::List mEntries;
114};
115
116/**
117 @short Manager of distribution lists
118
119 This class represents a collection of distribution lists, which are associated
120 with a given address book.
121*/
122class DistributionListManager
123{
124 public:
125 /**
126 Create manager for given address book.
127 */
128 DistributionListManager( AddressBook * );
129
130 /**
131 Destructor.
132 */
133 ~DistributionListManager();
134
135 /**
136 Return distribution list with given name.
137 */
138 DistributionList *list( const QString &name );
139
140 /**
141 Insert distribution list. If a list with this name already exists, nothing
142 happens.
143 */
144 void insert( DistributionList * );
145
146 /**
147 Remove distribution list. If a list with this name doesn't exist, nothing
148 happens.
149 */
150 void remove( DistributionList * );
151
152 /**
153 Return names of all distribution lists managed by this manager.
154 */
155 QStringList listNames();
156
157 /**
158 Load distribution lists form disk.
159 */
160 bool load();
161
162 /**
163 Save distribution lists to disk.
164 */
165 bool save();
166
167 private:
168 AddressBook *mAddressBook;
169
170 QPtrList<DistributionList> mLists;
171};
172
173/**
174 @short Watchdog for distribution lists
175
176 This class provides a @ref changed() signal that i emitted when the
177 distribution lists has changed in some way.
178
179 Exapmle:
180
181 <pre>
182 KABC::DistributionListWatcher *watchdog = KABC::DistributionListWatcher::self()
183
184 connect( watchdog, SIGNAL( changed() ), SLOT( doSomething() ) );
185 </pre>
186*/
187
188class DistributionListWatcher : public QObject
189{
190 Q_OBJECT
191
192 public:
193 /**
194 * Returns the watcher object.
195 */
196 static DistributionListWatcher *self();
197
198
199 signals:
200 /**
201 * This signal is emmitted whenever the distribution lists has
202 * changed (if a list was added or removed, when a list was
203 * renamed or the entries of the list changed).
204 */
205 void changed();
206
207 protected:
208 DistributionListWatcher();
209 ~DistributionListWatcher();
210
211 private:
212 static DistributionListWatcher* mSelf;
213#ifndef KAB_EMBEDDED
214 KDirWatch *mDirWatch;
215#endif //KAB_EMBEDDED
216};
217
218}
219#endif
diff --git a/kabc/distributionlistdialog.cpp b/kabc/distributionlistdialog.cpp
new file mode 100644
index 0000000..31d5944
--- a/dev/null
+++ b/kabc/distributionlistdialog.cpp
@@ -0,0 +1,396 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <qlistview.h>
22#include <qlayout.h>
23#include <qlabel.h>
24#include <qpushbutton.h>
25#include <qcombobox.h>
26#include <klineeditdlg.h>
27#include <qbuttongroup.h>
28#include <qradiobutton.h>
29
30#include <klocale.h>
31#include <kdebug.h>
32#include <kmessagebox.h>
33
34#include "addressbook.h"
35#include "addresseedialog.h"
36#include "distributionlist.h"
37
38#include "distributionlistdialog.h"
39
40#ifndef KAB_EMBEDDED
41#include "distributionlistdialog.moc"
42#endif //KAB_EMBEDDED
43
44using namespace KABC;
45
46DistributionListDialog::DistributionListDialog( AddressBook *addressBook, QWidget *parent)
47 : KDialogBase( parent, "", true, i18n("Configure Distribution Lists"), Ok, Ok, true)
48{
49 mEditor = new DistributionListEditorWidget( addressBook, this );
50 setMainWidget( mEditor );
51
52 connect( this, SIGNAL( okClicked() ), mEditor, SLOT( save() ) );
53}
54
55DistributionListDialog::~DistributionListDialog()
56{
57}
58
59
60EmailSelector::EmailSelector( const QStringList &emails, const QString &current,
61 QWidget *parent ) :
62 KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
63 parent )
64{
65 QFrame *topFrame = plainPage();
66 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
67
68 mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"),
69 topFrame );
70 topLayout->addWidget( mButtonGroup );
71
72 QStringList::ConstIterator it;
73 for( it = emails.begin(); it != emails.end(); ++it ) {
74 QRadioButton *button = new QRadioButton( *it, mButtonGroup );
75 if ( (*it) == current ) {
76 button->setDown( true );
77 }
78 }
79}
80
81QString EmailSelector::selected()
82{
83 QButton *button = mButtonGroup->selected();
84 if ( button ) return button->text();
85 return QString::null;
86}
87
88QString EmailSelector::getEmail( const QStringList &emails, const QString &current,
89 QWidget *parent )
90{
91 EmailSelector *dlg = new EmailSelector( emails, current, parent );
92 dlg->exec();
93
94 QString result = dlg->selected();
95
96 delete dlg;
97
98 return result;
99}
100
101class EntryItem : public QListViewItem
102{
103 public:
104 EntryItem( QListView *parent, const Addressee &addressee,
105 const QString &email=QString::null ) :
106 QListViewItem( parent ),
107 mAddressee( addressee ),
108 mEmail( email )
109 {
110 setText( 0, addressee.realName() );
111 if( email.isEmpty() ) {
112 setText( 1, addressee.preferredEmail() );
113 setText( 2, i18n("Yes") );
114 } else {
115 setText( 1, email );
116 setText( 2, i18n("No") );
117 }
118 }
119
120 Addressee addressee() const
121 {
122 return mAddressee;
123 }
124
125 QString email() const
126 {
127 return mEmail;
128 }
129
130 private:
131 Addressee mAddressee;
132 QString mEmail;
133};
134
135DistributionListEditorWidget::DistributionListEditorWidget( AddressBook *addressBook, QWidget *parent) :
136 QWidget( parent ),
137 mAddressBook( addressBook )
138{
139 kdDebug(5700) << "DistributionListEditor()" << endl;
140
141 QBoxLayout *topLayout = new QVBoxLayout( this );
142 topLayout->setSpacing( KDialog::spacingHint() );
143
144 QBoxLayout *nameLayout = new QHBoxLayout( topLayout) ;
145
146 mNameCombo = new QComboBox( this );
147 nameLayout->addWidget( mNameCombo );
148 connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) );
149
150 mNewButton = new QPushButton( i18n("New List..."), this );
151 nameLayout->addWidget( mNewButton );
152 connect( mNewButton, SIGNAL( clicked() ), SLOT( newList() ) );
153
154 mEditButton = new QPushButton( i18n("Rename List..."), this );
155 nameLayout->addWidget( mEditButton );
156 connect( mEditButton, SIGNAL( clicked() ), SLOT( editList() ) );
157
158 mRemoveButton = new QPushButton( i18n("Remove List"), this );
159 nameLayout->addWidget( mRemoveButton );
160 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeList() ) );
161
162 QGridLayout *gridLayout = new QGridLayout( topLayout, 3, 3 );
163 gridLayout->setColStretch(1, 1);
164
165 QLabel *listLabel = new QLabel( i18n("Available addresses:"), this );
166 gridLayout->addWidget( listLabel, 0, 0 );
167
168 mListLabel = new QLabel( this );
169 gridLayout->addMultiCellWidget( mListLabel, 0, 0, 1, 2 );
170
171 mAddresseeView = new QListView( this );
172 mAddresseeView->addColumn( i18n("Name") );
173 mAddresseeView->addColumn( i18n("Preferred Email") );
174 mAddresseeView->setAllColumnsShowFocus( true );
175 gridLayout->addWidget( mAddresseeView, 1, 0 );
176 connect( mAddresseeView, SIGNAL( selectionChanged() ),
177 SLOT( slotSelectionAddresseeViewChanged() ) );
178 connect( mAddresseeView, SIGNAL( doubleClicked( QListViewItem * ) ),
179 SLOT( addEntry() ) );
180
181 mAddEntryButton = new QPushButton( i18n("Add Entry"), this );
182 mAddEntryButton->setEnabled(false);
183 gridLayout->addWidget( mAddEntryButton, 2, 0 );
184 connect( mAddEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) );
185
186 mEntryView = new QListView( this );
187 mEntryView->addColumn( i18n("Name") );
188 mEntryView->addColumn( i18n("Email") );
189 mEntryView->addColumn( i18n("Use Preferred") );
190 mEntryView->setEnabled(false);
191 mEntryView->setAllColumnsShowFocus( true );
192 gridLayout->addMultiCellWidget( mEntryView, 1, 1, 1, 2 );
193 connect( mEntryView, SIGNAL( selectionChanged() ),
194 SLOT( slotSelectionEntryViewChanged() ) );
195
196 mChangeEmailButton = new QPushButton( i18n("Change Email..."), this );
197 gridLayout->addWidget( mChangeEmailButton, 2, 1 );
198 connect( mChangeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) );
199
200 mRemoveEntryButton = new QPushButton( i18n("Remove Entry"), this );
201 gridLayout->addWidget( mRemoveEntryButton, 2, 2 );
202 connect( mRemoveEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) );
203
204 mManager = new DistributionListManager( mAddressBook );
205 mManager->load();
206
207 updateAddresseeView();
208 updateNameCombo();
209}
210
211DistributionListEditorWidget::~DistributionListEditorWidget()
212{
213 kdDebug(5700) << "~DistributionListEditor()" << endl;
214
215 delete mManager;
216}
217
218void DistributionListEditorWidget::save()
219{
220 mManager->save();
221}
222
223void DistributionListEditorWidget::slotSelectionEntryViewChanged()
224{
225 EntryItem *entryItem = static_cast<EntryItem *>( mEntryView->selectedItem() );
226 bool state=entryItem;
227
228 mChangeEmailButton->setEnabled(state);
229 mRemoveEntryButton->setEnabled(state);
230}
231
232void DistributionListEditorWidget::newList()
233{
234 KLineEditDlg dlg(i18n("Please enter name:"), QString::null, this);
235 dlg.setCaption(i18n("New Distribution List"));
236 if (!dlg.exec()) return;
237
238 new DistributionList( mManager, dlg.text() );
239
240 mNameCombo->clear();
241 mNameCombo->insertStringList( mManager->listNames() );
242 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
243
244 updateEntryView();
245 slotSelectionAddresseeViewChanged();
246}
247
248void DistributionListEditorWidget::editList()
249{
250 QString oldName = mNameCombo->currentText();
251
252 KLineEditDlg dlg(i18n("Please change name:"), oldName, this);
253 dlg.setCaption(i18n("Distribution List"));
254 if (!dlg.exec()) return;
255
256 DistributionList *list = mManager->list( oldName );
257 list->setName( dlg.text() );
258
259 mNameCombo->clear();
260 mNameCombo->insertStringList( mManager->listNames() );
261 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
262
263 updateEntryView();
264 slotSelectionAddresseeViewChanged();
265}
266
267void DistributionListEditorWidget::removeList()
268{
269 int result = KMessageBox::warningContinueCancel( this,
270 i18n("Delete distribution list '%1'?") .arg( mNameCombo->currentText() ),
271 QString::null, i18n("Delete") );
272
273 if ( result != KMessageBox::Continue ) return;
274
275 delete mManager->list( mNameCombo->currentText() );
276 mNameCombo->removeItem( mNameCombo->currentItem() );
277
278 updateEntryView();
279 slotSelectionAddresseeViewChanged();
280}
281
282void DistributionListEditorWidget::addEntry()
283{
284 AddresseeItem *addresseeItem =
285 static_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
286
287 if( !addresseeItem ) {
288 kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
289 return;
290 }
291
292 DistributionList *list = mManager->list( mNameCombo->currentText() );
293 if ( !list ) {
294 kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
295 return;
296 }
297
298 list->insertEntry( addresseeItem->addressee() );
299 updateEntryView();
300 slotSelectionAddresseeViewChanged();
301}
302
303void DistributionListEditorWidget::removeEntry()
304{
305 DistributionList *list = mManager->list( mNameCombo->currentText() );
306 if ( !list ) return;
307
308 EntryItem *entryItem =
309 static_cast<EntryItem *>( mEntryView->selectedItem() );
310 if ( !entryItem ) return;
311
312 list->removeEntry( entryItem->addressee(), entryItem->email() );
313 delete entryItem;
314}
315
316void DistributionListEditorWidget::changeEmail()
317{
318 DistributionList *list = mManager->list( mNameCombo->currentText() );
319 if ( !list ) return;
320
321 EntryItem *entryItem =
322 static_cast<EntryItem *>( mEntryView->selectedItem() );
323 if ( !entryItem ) return;
324
325 QString email = EmailSelector::getEmail( entryItem->addressee().emails(),
326 entryItem->email(), this );
327 list->removeEntry( entryItem->addressee(), entryItem->email() );
328 list->insertEntry( entryItem->addressee(), email );
329
330 updateEntryView();
331}
332
333void DistributionListEditorWidget::updateEntryView()
334{
335 if ( mNameCombo->currentText().isEmpty() ) {
336 mListLabel->setText( i18n("Selected addressees:") );
337 } else {
338 mListLabel->setText( i18n("Selected addresses in '%1':")
339 .arg( mNameCombo->currentText() ) );
340 }
341
342 mEntryView->clear();
343
344 DistributionList *list = mManager->list( mNameCombo->currentText() );
345 if ( !list ) {
346 mEditButton->setEnabled(false);
347 mRemoveButton->setEnabled(false);
348 mChangeEmailButton->setEnabled(false);
349 mRemoveEntryButton->setEnabled(false);
350 mAddresseeView->setEnabled(false);
351 mEntryView->setEnabled(false);
352 return;
353 } else {
354 mEditButton->setEnabled(true);
355 mRemoveButton->setEnabled(true);
356 mAddresseeView->setEnabled(true);
357 mEntryView->setEnabled(true);
358 }
359
360 DistributionList::Entry::List entries = list->entries();
361 DistributionList::Entry::List::ConstIterator it;
362 for( it = entries.begin(); it != entries.end(); ++it ) {
363 new EntryItem( mEntryView, (*it).addressee, (*it).email );
364 }
365
366 EntryItem *entryItem = static_cast<EntryItem *>( mEntryView->selectedItem() );
367 bool state=entryItem;
368
369 mChangeEmailButton->setEnabled(state);
370 mRemoveEntryButton->setEnabled(state);
371}
372
373void DistributionListEditorWidget::updateAddresseeView()
374{
375 mAddresseeView->clear();
376
377 AddressBook::Iterator it;
378 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
379 new AddresseeItem( mAddresseeView, *it );
380 }
381}
382
383void DistributionListEditorWidget::updateNameCombo()
384{
385 mNameCombo->insertStringList( mManager->listNames() );
386
387 updateEntryView();
388}
389
390void DistributionListEditorWidget::slotSelectionAddresseeViewChanged()
391{
392 AddresseeItem *addresseeItem =
393 static_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
394 bool state=addresseeItem;
395 mAddEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty());
396}
diff --git a/kabc/distributionlistdialog.h b/kabc/distributionlistdialog.h
new file mode 100644
index 0000000..b6d3c80
--- a/dev/null
+++ b/kabc/distributionlistdialog.h
@@ -0,0 +1,140 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef KABC_DISTRIBUTIONLISTDIALOG_H
22#define KABC_DISTRIBUTIONLISTDIALOG_H
23
24#include <qwidget.h>
25
26#include <kdialogbase.h>
27
28class QListView;
29class QLabel;
30class QComboBox;
31class QButtonGroup;
32
33namespace KABC {
34
35class AddressBook;
36class DistributionListEditorWidget;
37class DistributionListManager;
38
39/**
40 @short Frontend to create distribution lists
41
42 Creating a new DistributionListDialog does automatically
43 load all addressees and distribution lists from the config
44 files. The changes will be saved when clicking the 'OK'
45 button.
46
47 Example:
48
49 <pre>
50 KABC::DistributionListDialog *dlg = new
51 KABC::DistributionListDialog( KABC::StdAddressBook::self(), this );
52
53 dlg->exec();
54 </pre>
55*/
56class DistributionListDialog : public KDialogBase
57{
58 Q_OBJECT
59
60 public:
61 /**
62 Constructor.
63
64 @param ab The addressbook, the addressees should be used from
65 @param parent The parent widget
66 */
67 DistributionListDialog( AddressBook *ab, QWidget *parent );
68
69 /**
70 Destructor.
71 */
72 virtual ~DistributionListDialog();
73
74 private:
75 DistributionListEditorWidget *mEditor;
76
77 struct Data;
78 Data *d;
79};
80
81/**
82 @short Helper class
83*/
84class EmailSelector : public KDialogBase
85{
86 public:
87 EmailSelector( const QStringList &emails, const QString &current,
88 QWidget *parent );
89
90 QString selected();
91
92 static QString getEmail( const QStringList &emails, const QString &current,
93 QWidget *parent );
94
95 private:
96 QButtonGroup *mButtonGroup;
97};
98
99/**
100 @short Helper class
101*/
102class DistributionListEditorWidget : public QWidget
103{
104 Q_OBJECT
105
106 public:
107 DistributionListEditorWidget( AddressBook *, QWidget *parent );
108 virtual ~DistributionListEditorWidget();
109
110 private slots:
111 void newList();
112 void editList();
113 void removeList();
114 void addEntry();
115 void removeEntry();
116 void changeEmail();
117 void updateEntryView();
118 void updateAddresseeView();
119 void updateNameCombo();
120 void slotSelectionEntryViewChanged();
121 void slotSelectionAddresseeViewChanged();
122 void save();
123
124 private:
125 QComboBox *mNameCombo;
126 QLabel *mListLabel;
127 QListView *mEntryView;
128 QListView *mAddresseeView;
129
130 AddressBook *mAddressBook;
131 DistributionListManager *mManager;
132 QPushButton *mNewButton, *mEditButton, *mRemoveButton;
133 QPushButton *mChangeEmailButton, *mRemoveEntryButton, *mAddEntryButton;
134
135 struct Data;
136 Data *d;
137};
138
139}
140#endif
diff --git a/kabc/distributionlisteditor.cpp b/kabc/distributionlisteditor.cpp
new file mode 100644
index 0000000..569dc96
--- a/dev/null
+++ b/kabc/distributionlisteditor.cpp
@@ -0,0 +1,335 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <qlistview.h>
22#include <qlayout.h>
23#include <qpushbutton.h>
24#include <qcombobox.h>
25#include <qinputdialog.h>
26#include <qbuttongroup.h>
27#include <qradiobutton.h>
28
29#include <klocale.h>
30#include <kdebug.h>
31
32#include "addressbook.h"
33#include "addresseedialog.h"
34#include "distributionlist.h"
35
36#include "distributionlisteditor.h"
37
38#ifndef KAB_EMBEDDED
39#include "distributionlisteditor.moc"
40#endif //KAB_EMBEDDED
41
42using namespace KABC;
43
44EmailSelectDialog::EmailSelectDialog( const QStringList &emails, const QString &current,
45 QWidget *parent ) :
46 KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
47 parent )
48{
49 QFrame *topFrame = plainPage();
50 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
51
52 mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"),
53 topFrame );
54 topLayout->addWidget( mButtonGroup );
55
56 QStringList::ConstIterator it;
57 for( it = emails.begin(); it != emails.end(); ++it ) {
58 QRadioButton *button = new QRadioButton( *it, mButtonGroup );
59 if ( (*it) == current ) {
60 button->setDown( true );
61 }
62 }
63}
64
65QString EmailSelectDialog::selected()
66{
67 QButton *button = mButtonGroup->selected();
68 if ( button ) return button->text();
69 return QString::null;
70}
71
72QString EmailSelectDialog::getEmail( const QStringList &emails, const QString &current,
73 QWidget *parent )
74{
75 EmailSelectDialog *dlg = new EmailSelectDialog( emails, current, parent );
76 dlg->exec();
77
78 QString result = dlg->selected();
79
80 delete dlg;
81
82 return result;
83}
84
85class EditEntryItem : public QListViewItem
86{
87 public:
88 EditEntryItem( QListView *parent, const Addressee &addressee,
89 const QString &email=QString::null ) :
90 QListViewItem( parent ),
91 mAddressee( addressee ),
92 mEmail( email )
93 {
94 setText( 0, addressee.realName() );
95 if( email.isEmpty() ) {
96 setText( 1, addressee.preferredEmail() );
97 setText( 2, i18n("Yes") );
98 } else {
99 setText( 1, email );
100 setText( 2, i18n("No") );
101 }
102 }
103
104 Addressee addressee() const
105 {
106 return mAddressee;
107 }
108
109 QString email() const
110 {
111 return mEmail;
112 }
113
114 private:
115 Addressee mAddressee;
116 QString mEmail;
117};
118
119DistributionListEditor::DistributionListEditor( AddressBook *addressBook, QWidget *parent) :
120 QWidget( parent ),
121 mAddressBook( addressBook )
122{
123 kdDebug(5700) << "DistributionListEditor()" << endl;
124
125 QBoxLayout *topLayout = new QVBoxLayout( this );
126 topLayout->setMargin( KDialog::marginHint() );
127 topLayout->setSpacing( KDialog::spacingHint() );
128
129 QBoxLayout *nameLayout = new QHBoxLayout( topLayout) ;
130
131 mNameCombo = new QComboBox( this );
132 nameLayout->addWidget( mNameCombo );
133 connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) );
134
135 newButton = new QPushButton( i18n("New List"), this );
136 nameLayout->addWidget( newButton );
137 connect( newButton, SIGNAL( clicked() ), SLOT( newList() ) );
138
139 removeButton = new QPushButton( i18n("Remove List"), this );
140 nameLayout->addWidget( removeButton );
141 connect( removeButton, SIGNAL( clicked() ), SLOT( removeList() ) );
142
143 mEntryView = new QListView( this );
144 mEntryView->addColumn( i18n("Name") );
145 mEntryView->addColumn( i18n("Email") );
146 mEntryView->addColumn( i18n("Use Preferred") );
147 topLayout->addWidget( mEntryView );
148 connect(mEntryView,SIGNAL(selectionChanged ()),this, SLOT(slotSelectionEntryViewChanged()));
149
150 changeEmailButton = new QPushButton( i18n("Change Email"), this );
151 topLayout->addWidget( changeEmailButton );
152 connect( changeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) );
153
154 removeEntryButton = new QPushButton( i18n("Remove Entry"), this );
155 topLayout->addWidget( removeEntryButton );
156 connect( removeEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) );
157
158 addEntryButton = new QPushButton( i18n("Add Entry"), this );
159 topLayout->addWidget( addEntryButton );
160 connect( addEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) );
161
162 mAddresseeView = new QListView( this );
163 mAddresseeView->addColumn( i18n("Name") );
164 mAddresseeView->addColumn( i18n("Preferred Email") );
165 topLayout->addWidget( mAddresseeView );
166
167
168 connect(mAddresseeView,SIGNAL(selectionChanged ()),this, SLOT(slotSelectionAddresseeViewChanged()));
169
170 mManager = new DistributionListManager( mAddressBook );
171 mManager->load();
172
173 updateAddresseeView();
174 updateNameCombo();
175 removeButton->setEnabled(!mManager->listNames().isEmpty());
176}
177
178DistributionListEditor::~DistributionListEditor()
179{
180 kdDebug(5700) << "~DistributionListEditor()" << endl;
181
182 mManager->save();
183 delete mManager;
184}
185
186void DistributionListEditor::slotSelectionEntryViewChanged()
187{
188#ifndef KAB_EMBEDDED
189 EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
190#else //KAB_EMBEDDED
191 EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() );
192#endif //KAB_EMBEDDED
193 bool state = (entryItem != 0L);
194
195 changeEmailButton->setEnabled(state);
196 removeEntryButton->setEnabled(state);
197}
198
199void DistributionListEditor::newList()
200{
201 bool ok = false;
202 QString name = QInputDialog::getText( i18n("New Distribution List"),
203 i18n("Please enter name:"),
204 QLineEdit::Normal, QString::null, &ok,
205 this );
206 if ( !ok || name.isEmpty() ) return;
207
208 new DistributionList( mManager, name );
209
210 mNameCombo->insertItem( name );
211 removeButton->setEnabled(true);
212 updateEntryView();
213}
214
215void DistributionListEditor::removeList()
216{
217 delete mManager->list( mNameCombo->currentText() );
218 mNameCombo->removeItem( mNameCombo->currentItem() );
219 removeButton->setEnabled(!mManager->listNames().isEmpty());
220 addEntryButton->setEnabled( !mNameCombo->currentText().isEmpty());
221 updateEntryView();
222}
223
224void DistributionListEditor::addEntry()
225{
226#ifndef KAB_EMBEDDED
227 AddresseeItem *addresseeItem =
228 dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
229#else //KAB_EMBEDDED
230 AddresseeItem *addresseeItem =
231 (AddresseeItem *)( mAddresseeView->selectedItem() );
232#endif //KAB_EMBEDDED
233
234
235 if( !addresseeItem ) {
236 kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
237 return;
238 }
239
240 DistributionList *list = mManager->list( mNameCombo->currentText() );
241 if ( !list ) {
242 kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
243 return;
244 }
245
246 list->insertEntry( addresseeItem->addressee() );
247 updateEntryView();
248 slotSelectionAddresseeViewChanged();
249}
250
251void DistributionListEditor::removeEntry()
252{
253 DistributionList *list = mManager->list( mNameCombo->currentText() );
254 if ( !list ) return;
255
256#ifndef KAB_EMBEDDED
257 EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
258#else //KAB_EMBEDDED
259 EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() );
260#endif //KAB_EMBEDDED
261 if ( !entryItem ) return;
262
263 list->removeEntry( entryItem->addressee(), entryItem->email() );
264 delete entryItem;
265}
266
267void DistributionListEditor::changeEmail()
268{
269 DistributionList *list = mManager->list( mNameCombo->currentText() );
270 if ( !list ) return;
271
272#ifndef KAB_EMBEDDED
273 EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
274#else //KAB_EMBEDDED
275 EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() );
276#endif //KAB_EMBEDDED
277 if ( !entryItem ) return;
278
279 QString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(),
280 entryItem->email(), this );
281 list->removeEntry( entryItem->addressee(), entryItem->email() );
282 list->insertEntry( entryItem->addressee(), email );
283
284 updateEntryView();
285}
286
287void DistributionListEditor::updateEntryView()
288{
289 DistributionList *list = mManager->list( mNameCombo->currentText() );
290 if ( !list ) return;
291
292 mEntryView->clear();
293 DistributionList::Entry::List entries = list->entries();
294 DistributionList::Entry::List::ConstIterator it;
295 for( it = entries.begin(); it != entries.end(); ++it ) {
296 new EditEntryItem( mEntryView, (*it).addressee, (*it).email );
297 }
298#ifndef KAB_EMBEDDED
299 EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
300#else //KAB_EMBEDDED
301 EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() );
302#endif //KAB_EMBEDDED
303 bool state = (entryItem != 0L);
304
305 changeEmailButton->setEnabled(state);
306 removeEntryButton->setEnabled(state);
307}
308
309void DistributionListEditor::updateAddresseeView()
310{
311 mAddresseeView->clear();
312
313 AddressBook::Iterator it;
314 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
315 new AddresseeItem( mAddresseeView, *it );
316 }
317}
318
319void DistributionListEditor::updateNameCombo()
320{
321 mNameCombo->insertStringList( mManager->listNames() );
322
323 updateEntryView();
324}
325
326void DistributionListEditor::slotSelectionAddresseeViewChanged()
327{
328#ifndef KAB_EMBEDDED
329 AddresseeItem *addresseeItem = dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
330#else //KAB_EMBEDDED
331 AddresseeItem *addresseeItem = (AddresseeItem *)( mAddresseeView->selectedItem() );
332#endif //KAB_EMBEDDED
333 bool state = (addresseeItem != 0L);
334 addEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty());
335}
diff --git a/kabc/distributionlisteditor.h b/kabc/distributionlisteditor.h
new file mode 100644
index 0000000..e0b4221
--- a/dev/null
+++ b/kabc/distributionlisteditor.h
@@ -0,0 +1,86 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20#ifndef KABC_DISTRIBUTIONLISTEDITOR_H
21#define KABC_DISTRIBUTIONLISTEDITOR_H
22
23#include <qwidget.h>
24
25#include <kdialogbase.h>
26
27class QListView;
28class QComboBox;
29class QButtonGroup;
30
31namespace KABC {
32
33class AddressBook;
34class DistributionListManager;
35
36class EmailSelectDialog : public KDialogBase
37{
38 public:
39 EmailSelectDialog( const QStringList &emails, const QString &current,
40 QWidget *parent );
41
42 QString selected();
43
44 static QString getEmail( const QStringList &emails, const QString &current,
45 QWidget *parent );
46
47 private:
48 QButtonGroup *mButtonGroup;
49};
50
51/**
52 @obsolete
53*/
54class DistributionListEditor : public QWidget
55{
56 Q_OBJECT
57 public:
58 DistributionListEditor( AddressBook *, QWidget *parent );
59 virtual ~DistributionListEditor();
60
61 private slots:
62 void newList();
63 void removeList();
64 void addEntry();
65 void removeEntry();
66 void changeEmail();
67 void updateEntryView();
68 void updateAddresseeView();
69 void updateNameCombo();
70 void slotSelectionEntryViewChanged();
71 void slotSelectionAddresseeViewChanged();
72
73 private:
74 QComboBox *mNameCombo;
75 QListView *mEntryView;
76 QListView *mAddresseeView;
77
78 AddressBook *mAddressBook;
79 DistributionListManager *mManager;
80 QPushButton *newButton, *removeButton;
81 QPushButton *changeEmailButton,*removeEntryButton,*addEntryButton;
82};
83
84}
85
86#endif
diff --git a/kabc/field.cpp b/kabc/field.cpp
new file mode 100644
index 0000000..41bbfde
--- a/dev/null
+++ b/kabc/field.cpp
@@ -0,0 +1,550 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/
2/*
3 This file is part of libkabc.
4 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#include <klocale.h>
30#include <kconfig.h>
31#include <kconfigbase.h>
32#include <kglobal.h>
33
34#include "field.h"
35
36using namespace KABC;
37
38class Field::FieldImpl
39{
40 public:
41 FieldImpl( int fieldId, int category = 0,
42 const QString &label = QString::null,
43 const QString &key = QString::null,
44 const QString &app = QString::null )
45 : mFieldId( fieldId ), mCategory( category ), mLabel( label ),
46 mKey( key ), mApp( app ) {}
47
48 enum FieldId
49 {
50 CustomField,
51 FormattedName,
52 FamilyName,
53 GivenName,
54 AdditionalName,
55 Prefix,
56 Suffix,
57 NickName,
58 Birthday,
59 HomeAddressStreet,
60 HomeAddressLocality,
61 HomeAddressRegion,
62 HomeAddressPostalCode,
63 HomeAddressCountry,
64 HomeAddressLabel,
65 BusinessAddressStreet,
66 BusinessAddressLocality,
67 BusinessAddressRegion,
68 BusinessAddressPostalCode,
69 BusinessAddressCountry,
70 BusinessAddressLabel,
71 HomePhone,
72 BusinessPhone,
73 MobilePhone,
74 HomeFax,
75 BusinessFax,
76 CarPhone,
77 Isdn,
78 Pager,
79 Email,
80 Mailer,
81 Title,
82 Role,
83 Organization,
84 Note,
85 Url
86 };
87
88 int fieldId() { return mFieldId; }
89 int category() { return mCategory; }
90
91 QString label() { return mLabel; }
92 QString key() { return mKey; }
93 QString app() { return mApp; }
94
95 private:
96 int mFieldId;
97 int mCategory;
98
99 QString mLabel;
100 QString mKey;
101 QString mApp;
102};
103
104
105Field::List Field::mAllFields;
106Field::List Field::mDefaultFields;
107Field::List Field::mCustomFields;
108
109
110Field::Field( FieldImpl *impl )
111{
112 mImpl = impl;
113}
114
115Field::~Field()
116{
117 delete mImpl;
118}
119
120QString Field::label()
121{
122 switch ( mImpl->fieldId() ) {
123 case FieldImpl::FormattedName:
124 return Addressee::formattedNameLabel();
125 case FieldImpl::FamilyName:
126 return Addressee::familyNameLabel();
127 case FieldImpl::GivenName:
128 return Addressee::givenNameLabel();
129 case FieldImpl::AdditionalName:
130 return Addressee::additionalNameLabel();
131 case FieldImpl::Prefix:
132 return Addressee::prefixLabel();
133 case FieldImpl::Suffix:
134 return Addressee::suffixLabel();
135 case FieldImpl::NickName:
136 return Addressee::nickNameLabel();
137 case FieldImpl::Birthday:
138 return Addressee::birthdayLabel();
139 case FieldImpl::HomeAddressStreet:
140 return Addressee::homeAddressStreetLabel();
141 case FieldImpl::HomeAddressLocality:
142 return Addressee::homeAddressLocalityLabel();
143 case FieldImpl::HomeAddressRegion:
144 return Addressee::homeAddressRegionLabel();
145 case FieldImpl::HomeAddressPostalCode:
146 return Addressee::homeAddressPostalCodeLabel();
147 case FieldImpl::HomeAddressCountry:
148 return Addressee::homeAddressCountryLabel();
149 case FieldImpl::HomeAddressLabel:
150 return Addressee::homeAddressLabelLabel();
151 case FieldImpl::BusinessAddressStreet:
152 return Addressee::businessAddressStreetLabel();
153 case FieldImpl::BusinessAddressLocality:
154 return Addressee::businessAddressLocalityLabel();
155 case FieldImpl::BusinessAddressRegion:
156 return Addressee::businessAddressRegionLabel();
157 case FieldImpl::BusinessAddressPostalCode:
158 return Addressee::businessAddressPostalCodeLabel();
159 case FieldImpl::BusinessAddressCountry:
160 return Addressee::businessAddressCountryLabel();
161 case FieldImpl::BusinessAddressLabel:
162 return Addressee::businessAddressLabelLabel();
163 case FieldImpl::HomePhone:
164 return Addressee::homePhoneLabel();
165 case FieldImpl::BusinessPhone:
166 return Addressee::businessPhoneLabel();
167 case FieldImpl::MobilePhone:
168 return Addressee::mobilePhoneLabel();
169 case FieldImpl::HomeFax:
170 return Addressee::homeFaxLabel();
171 case FieldImpl::BusinessFax:
172 return Addressee::businessFaxLabel();
173 case FieldImpl::CarPhone:
174 return Addressee::carPhoneLabel();
175 case FieldImpl::Isdn:
176 return Addressee::isdnLabel();
177 case FieldImpl::Pager:
178 return Addressee::pagerLabel();
179 case FieldImpl::Email:
180 return Addressee::emailLabel();
181 case FieldImpl::Mailer:
182 return Addressee::mailerLabel();
183 case FieldImpl::Title:
184 return Addressee::titleLabel();
185 case FieldImpl::Role:
186 return Addressee::roleLabel();
187 case FieldImpl::Organization:
188 return Addressee::organizationLabel();
189 case FieldImpl::Note:
190 return Addressee::noteLabel();
191 case FieldImpl::Url:
192 return Addressee::urlLabel();
193 case FieldImpl::CustomField:
194 return mImpl->label();
195 default:
196 return i18n("Unknown Field");
197 }
198}
199
200int Field::category()
201{
202 return mImpl->category();
203}
204
205QString Field::categoryLabel( int category )
206{
207 switch ( category ) {
208 case All:
209 return i18n("All");
210 case Frequent:
211 return i18n("Frequent");
212 case Address:
213 return i18n("Address");
214 case Email:
215 return i18n("Email");
216 case Personal:
217 return i18n("Personal");
218 case Organization:
219 return i18n("Organization");
220 case CustomCategory:
221 return i18n("Custom");
222 default:
223 return i18n("Undefined");
224 }
225}
226
227QString Field::value( const KABC::Addressee &a )
228{
229 switch ( mImpl->fieldId() ) {
230 case FieldImpl::FormattedName:
231 return a.formattedName();
232 case FieldImpl::FamilyName:
233 return a.familyName();
234 case FieldImpl::GivenName:
235 return a.givenName();
236 case FieldImpl::AdditionalName:
237 return a.additionalName();
238 case FieldImpl::Prefix:
239 return a.prefix();
240 case FieldImpl::Suffix:
241 return a.suffix();
242 case FieldImpl::NickName:
243 return a.nickName();
244 case FieldImpl::Mailer:
245 return a.mailer();
246 case FieldImpl::Title:
247 return a.title();
248 case FieldImpl::Role:
249 return a.role();
250 case FieldImpl::Organization:
251 return a.organization();
252 case FieldImpl::Note:
253 return a.note();
254 case FieldImpl::Email:
255 return a.preferredEmail();
256 case FieldImpl::Birthday:
257 if ( a.birthday().isValid() ) {
258//the generated code had the following format: return a.birthday().date().toString( Qt::ISODate );
259// But Qt::IsoDate was not specified.
260 QString _oldFormat = KGlobal::locale()->dateFormat();
261 KGlobal::locale()->setDateFormat("%Y-%m-%d"); // = Qt::ISODate
262 QString dt = KGlobal::locale()->formatDate(a.birthday().date(), false);
263 KGlobal::locale()->setDateFormat(_oldFormat);
264 return dt;
265 }
266 else
267 return QString::null;
268 case FieldImpl::Url:
269 return a.url().prettyURL();
270 case FieldImpl::HomePhone:
271 return a.phoneNumber( PhoneNumber::Home ).number();
272 case FieldImpl::BusinessPhone:
273 return a.phoneNumber( PhoneNumber::Work ).number();
274 case FieldImpl::MobilePhone:
275 return a.phoneNumber( PhoneNumber::Cell ).number();
276 case FieldImpl::HomeFax:
277 return a.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ).number();
278 case FieldImpl::BusinessFax:
279 return a.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ).number();
280 case FieldImpl::CarPhone:
281 return a.phoneNumber( PhoneNumber::Car ).number();
282 case FieldImpl::Isdn:
283 return a.phoneNumber( PhoneNumber::Isdn ).number();
284 case FieldImpl::Pager:
285 return a.phoneNumber( PhoneNumber::Pager ).number();
286 case FieldImpl::HomeAddressStreet:
287 return a.address( Address::Home ).street();
288 case FieldImpl::HomeAddressLocality:
289 return a.address( Address::Home ).locality();
290 case FieldImpl::HomeAddressRegion:
291 return a.address( Address::Home ).region();
292 case FieldImpl::HomeAddressPostalCode:
293 return a.address( Address::Home ).postalCode();
294 case FieldImpl::HomeAddressCountry:
295 return a.address( Address::Home ).country();
296 case FieldImpl::BusinessAddressStreet:
297 return a.address( Address::Work ).street();
298 case FieldImpl::BusinessAddressLocality:
299 return a.address( Address::Work ).locality();
300 case FieldImpl::BusinessAddressRegion:
301 return a.address( Address::Work ).region();
302 case FieldImpl::BusinessAddressPostalCode:
303 return a.address( Address::Work ).postalCode();
304 case FieldImpl::BusinessAddressCountry:
305 return a.address( Address::Work ).country();
306 case FieldImpl::CustomField:
307 return a.custom( mImpl->app(), mImpl->key() );
308 default:
309 return QString::null;
310 }
311}
312
313bool Field::setValue( KABC::Addressee &a, const QString &value )
314{
315 switch ( mImpl->fieldId() ) {
316 case FieldImpl::FormattedName:
317 a.setFormattedName( value );
318 return true;
319 case FieldImpl::FamilyName:
320 a.setFamilyName( value );
321 return true;
322 case FieldImpl::GivenName:
323 a.setGivenName( value );
324 return true;
325 case FieldImpl::AdditionalName:
326 a.setAdditionalName( value );
327 return true;
328 case FieldImpl::Prefix:
329 a.setPrefix( value );
330 return true;
331 case FieldImpl::Suffix:
332 a.setSuffix( value );
333 return true;
334 case FieldImpl::NickName:
335 a.setNickName( value );
336 return true;
337 case FieldImpl::Mailer:
338 a.setMailer( value );
339 return true;
340 case FieldImpl::Title:
341 a.setTitle( value );
342 return true;
343 case FieldImpl::Role:
344 a.setRole( value );
345 return true;
346 case FieldImpl::Organization:
347 a.setOrganization( value );
348 return true;
349 case FieldImpl::Note:
350 a.setNote( value );
351 return true;
352 case FieldImpl::Birthday:
353//US
354//the generated code had the following format: return a.setBirthday( QDate::fromString( value, Qt::ISODate ) );
355// But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ?
356 {
357 QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate
358 a.setBirthday(dt);
359 }
360 return true;
361 case FieldImpl::CustomField:
362 a.insertCustom( mImpl->app(), mImpl->key(), value );
363 default:
364 return false;
365 }
366}
367
368bool Field::isCustom()
369{
370 return mImpl->fieldId() == FieldImpl::CustomField;
371}
372
373Field::List Field::allFields()
374{
375 if ( mAllFields.isEmpty() ) {
376 createField( FieldImpl::FormattedName, Frequent );
377 createField( FieldImpl::FamilyName, Frequent );
378 createField( FieldImpl::GivenName, Frequent );
379 createField( FieldImpl::AdditionalName );
380 createField( FieldImpl::Prefix );
381 createField( FieldImpl::Suffix );
382 createField( FieldImpl::NickName, Personal );
383 createField( FieldImpl::Birthday, Personal );
384 createField( FieldImpl::HomeAddressStreet, Address|Personal );
385 createField( FieldImpl::HomeAddressLocality, Address|Personal );
386 createField( FieldImpl::HomeAddressRegion, Address|Personal );
387 createField( FieldImpl::HomeAddressPostalCode, Address|Personal );
388 createField( FieldImpl::HomeAddressCountry, Address|Personal );
389 createField( FieldImpl::HomeAddressLabel, Address|Personal );
390 createField( FieldImpl::BusinessAddressStreet, Address|Organization );
391 createField( FieldImpl::BusinessAddressLocality, Address|Organization );
392 createField( FieldImpl::BusinessAddressRegion, Address|Organization );
393 createField( FieldImpl::BusinessAddressPostalCode, Address|Organization );
394 createField( FieldImpl::BusinessAddressCountry, Address|Organization );
395 createField( FieldImpl::BusinessAddressLabel, Address|Organization );
396 createField( FieldImpl::HomePhone, Personal|Frequent );
397 createField( FieldImpl::BusinessPhone, Organization|Frequent );
398 createField( FieldImpl::MobilePhone, Frequent );
399 createField( FieldImpl::HomeFax );
400 createField( FieldImpl::BusinessFax );
401 createField( FieldImpl::CarPhone );
402 createField( FieldImpl::Isdn );
403 createField( FieldImpl::Pager );
404 createField( FieldImpl::Email, Email|Frequent );
405 createField( FieldImpl::Mailer, Email );
406 createField( FieldImpl::Title, Organization );
407 createField( FieldImpl::Role, Organization );
408 createField( FieldImpl::Organization, Organization );
409 createField( FieldImpl::Note );
410 createField( FieldImpl::Url );
411 }
412
413 return mAllFields;
414}
415
416Field::List Field::defaultFields()
417{
418 if ( mDefaultFields.isEmpty() ) {
419 createDefaultField( FieldImpl::GivenName );
420 createDefaultField( FieldImpl::FamilyName );
421 createDefaultField( FieldImpl::Email );
422 }
423
424 return mDefaultFields;
425}
426
427void Field::createField( int id, int category )
428{
429 mAllFields.append( new Field( new FieldImpl( id, category ) ) );
430}
431
432void Field::createDefaultField( int id, int category )
433{
434 mDefaultFields.append( new Field( new FieldImpl( id, category ) ) );
435}
436
437void Field::deleteFields()
438{
439 Field::List::ConstIterator it;
440
441 for( it = mAllFields.begin(); it != mAllFields.end(); ++it ) {
442 delete (*it);
443 }
444 mAllFields.clear();
445
446 for( it = mDefaultFields.begin(); it != mDefaultFields.end(); ++it ) {
447 delete (*it);
448 }
449 mDefaultFields.clear();
450
451 for( it = mCustomFields.begin(); it != mCustomFields.end(); ++it ) {
452 delete (*it);
453 }
454 mCustomFields.clear();
455}
456
457void Field::saveFields( const QString &identifier,
458 const Field::List &fields )
459{
460 KConfig *cfg = KGlobal::config();
461 KConfigGroupSaver( cfg, "KABCFields" );
462 saveFields( cfg, identifier, fields );
463}
464
465void Field::saveFields( KConfig *cfg, const QString &identifier,
466 const Field::List &fields )
467{
468 QValueList<int> fieldIds;
469
470//US
471//US qDebug("Field::saveFields to %s %s", cfg->getFileName().latin1(), identifier.latin1());
472
473 int custom = 0;
474 Field::List::ConstIterator it;
475 for( it = fields.begin(); it != fields.end(); ++it ) {
476//US
477//US qDebug("Field::saveFields field:%i", (*it)->mImpl->fieldId());
478
479 fieldIds.append( (*it)->mImpl->fieldId() );
480 if( (*it)->isCustom() ) {
481 QStringList customEntry;
482 customEntry << (*it)->mImpl->label();
483 customEntry << (*it)->mImpl->key();
484 customEntry << (*it)->mImpl->app();
485 cfg->writeEntry( "KABC_CustomEntry_" + identifier + "_" +
486 QString::number( custom++ ), customEntry );
487 }
488 }
489 cfg->writeEntry( identifier, fieldIds );
490}
491
492Field::List Field::restoreFields( const QString &identifier )
493{
494 KConfig *cfg = KGlobal::config();
495 KConfigGroupSaver( cfg, "KABCFields" );
496 cfg->setGroup( "KABCFields" );
497
498 Field::List l = restoreFields( cfg, identifier );
499
500 return l;
501}
502
503Field::List Field::restoreFields( KConfig *cfg, const QString &identifier )
504{
505 QValueList<int> fieldIds = cfg->readIntListEntry( identifier);
506//US
507 qDebug("Field::restoreFields from %s", cfg->getFileName().latin1());
508
509 Field::List fields;
510
511 int custom = 0;
512 QValueList<int>::ConstIterator it;
513 for( it = fieldIds.begin(); it != fieldIds.end(); ++it ) {
514 FieldImpl *f = 0;
515 if ( (*it) == FieldImpl::CustomField ) {
516 QStringList customEntry = cfg->readListEntry( "KABC_CustomEntry_" +
517 identifier + "_" +
518 QString::number( custom++ ) );
519 f = new FieldImpl( *it, CustomCategory, customEntry[ 0 ],
520 customEntry[ 1 ], customEntry[ 2 ] );
521 } else {
522 f = new FieldImpl( *it );
523 }
524 fields.append( new Field( f ) );
525 }
526
527 return fields;
528}
529
530bool Field::equals( Field *field )
531{
532 bool sameId = ( mImpl->fieldId() == field->mImpl->fieldId() );
533
534 if ( !sameId ) return false;
535
536 if ( mImpl->fieldId() != FieldImpl::CustomField ) return true;
537
538 return mImpl->key() == field->mImpl->key();
539}
540
541Field *Field::createCustomField( const QString &label, int category,
542 const QString &key, const QString &app )
543{
544 Field *field = new Field( new FieldImpl( FieldImpl::CustomField,
545 category | CustomCategory,
546 label, key, app ) );
547 mCustomFields.append( field );
548
549 return field;
550}
diff --git a/kabc/field.h b/kabc/field.h
new file mode 100644
index 0000000..9e06597
--- a/dev/null
+++ b/kabc/field.h
@@ -0,0 +1,178 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_FIELD_H
29#define KABC_FIELD_H
30
31#include <qstring.h>
32#include <qvaluelist.h>
33
34#include "addressee.h"
35
36class KConfig;
37
38namespace KABC {
39
40class Field
41{
42 class FieldImpl;
43 friend class FieldImpl;
44
45public:
46 typedef QValueList<Field *> List;
47
48 /**
49 * @li @p All -
50 * @li @p Frequent -
51 * @li @p Address -
52 * @li @p Email -
53 * @li @p Personal -
54 * @li @p Organization -
55 * @li @p CustomCategory -
56 */
57 enum FieldCategory
58 {
59 All = 0x0,
60 Frequent = 0x01,
61 Address = 0x02,
62 Email = 0x04,
63 Personal = 0x08,
64 Organization = 0x10,
65 CustomCategory = 0x20
66 };
67
68 /**
69 * Returns the translated label for this field.
70 */
71 virtual QString label();
72
73 /**
74 * Returns the ored categories the field belongs to.
75 */
76 virtual int category();
77
78 /**
79 * Returns the translated label for field category.
80 */
81 static QString categoryLabel( int category );
82
83 /**
84 * Returns a string representation of the value the field has in the given
85 * Addressee. Returns QString::null, if it is not possible to convert the
86 * value to a string.
87 */
88 virtual QString value( const KABC::Addressee & );
89
90 /**
91 * Sets the value of the field in the given Addressee. Returns true on success
92 * or false, if the given string couldn't be converted to a valid value.
93 */
94 virtual bool setValue( KABC::Addressee &, const QString & );
95
96 /**
97 * Returns, if the field is a user-defined field.
98 */
99 virtual bool isCustom();
100
101 /**
102 * Returns, if the field is equal with @param field.
103 */
104 virtual bool equals( Field *field );
105
106 /**
107 * Returns a list of all fields.
108 */
109 static Field::List allFields();
110
111 /**
112 * Returns a list of the default fields.
113 */
114 static Field::List defaultFields();
115
116 /**
117 * Creates a custom field.
118 *
119 * @param label The label for this field
120 * @param category The category of this field
121 * @param key Unique key for this field
122 * @param app Unique app name for this field
123 */
124 static Field *createCustomField( const QString &label, int category,
125 const QString &key, const QString &app );
126
127 /**
128 * Delete all fields from list.
129 */
130 static void deleteFields();
131
132 /**
133 * Save the field settings to a config file.
134 *
135 * @param cfg The config file object
136 * @param identifier The unique identifier
137 * @param fields The list of the fields
138 */
139 static void saveFields( KConfig *cfg, const QString &identifier,
140 const Field::List &fields );
141 /**
142 * This is the same as above, with the difference, that
143 * the list is stored in KGlobal::config() in group "KABCFields".
144 */
145 static void saveFields( const QString &identifier,
146 const Field::List &fields );
147
148 /**
149 * Load the field settings from a config file.
150 *
151 * @param cfg The config file object
152 * @param identifier The unique identifier
153 */
154 static Field::List restoreFields( KConfig *cfg, const QString &identifier );
155
156 /**
157 * This is the same as above, with the difference, that
158 * the list is loaded from KGlobal::config() from group "KABCFields".
159 */
160 static Field::List restoreFields( const QString &identifier );
161
162protected:
163 static void createField( int id, int category = 0 );
164 static void createDefaultField( int id, int category = 0 );
165
166private:
167 Field( FieldImpl * );
168 virtual ~Field();
169
170 FieldImpl *mImpl;
171
172 static Field::List mAllFields;
173 static Field::List mDefaultFields;
174 static Field::List mCustomFields;
175};
176
177}
178#endif
diff --git a/kabc/formatfactory.cpp b/kabc/formatfactory.cpp
new file mode 100644
index 0000000..2b073d7
--- a/dev/null
+++ b/kabc/formatfactory.cpp
@@ -0,0 +1,181 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <kdebug.h>
22#include <klocale.h>
23#include <ksimpleconfig.h>
24#include <kstandarddirs.h>
25#include <kstaticdeleter.h>
26
27#include <qfile.h>
28#include <qstringlist.h>
29
30#include "vcardformatplugin.h"
31
32#include "formatfactory.h"
33
34using namespace KABC;
35
36FormatFactory *FormatFactory::mSelf = 0;
37static KStaticDeleter<FormatFactory> factoryDeleter;
38
39FormatFactory *FormatFactory::self()
40{
41 kdDebug(5700) << "FormatFactory::self()" << endl;
42
43 if ( !mSelf ) {
44#ifdef KAB_EMBEDDED
45 mSelf = factoryDeleter.setObject( new FormatFactory );
46#else //KAB_EMBEDDED
47 factoryDeleter.setObject( mSelf, new FormatFactory );
48#endif //KAB_EMBEDDED
49
50 }
51 return mSelf;
52}
53
54FormatFactory::FormatFactory()
55{
56 mFormatList.setAutoDelete( true );
57
58 // dummy entry for default format
59 FormatInfo *info = new FormatInfo;
60 info->library = "<NoLibrary>";
61 info->nameLabel = i18n( "vCard" );
62 info->descriptionLabel = i18n( "vCard Format" );
63 mFormatList.insert( "vcard", info );
64
65 QStringList list = KGlobal::dirs()->findAllResources( "data" ,"kabc/formats/*.desktop", true, true );
66 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
67 {
68//US KSimpleConfig config( *it, true );
69 KConfig config( *it );
70
71 if ( !config.hasGroup( "Misc" ) || !config.hasGroup( "Plugin" ) )
72 continue;
73
74 info = new FormatInfo;
75
76 config.setGroup( "Plugin" );
77 QString type = config.readEntry( "Type" );
78 info->library = config.readEntry( "X-KDE-Library" );
79
80 config.setGroup( "Misc" );
81 info->nameLabel = config.readEntry( "Name" );
82 info->descriptionLabel = config.readEntry( "Comment", i18n( "No description available." ) );
83
84 mFormatList.insert( type, info );
85 }
86}
87
88FormatFactory::~FormatFactory()
89{
90 mFormatList.clear();
91}
92
93QStringList FormatFactory::formats()
94{
95 QStringList retval;
96
97 // make sure 'vcard' is the first entry
98 retval << "vcard";
99
100 QDictIterator<FormatInfo> it( mFormatList );
101 for ( ; it.current(); ++it )
102 if ( it.currentKey() != "vcard" )
103 retval << it.currentKey();
104
105 return retval;
106}
107
108FormatInfo *FormatFactory::info( const QString &type )
109{
110 if ( type.isEmpty() )
111 return 0;
112 else
113 return mFormatList[ type ];
114}
115
116FormatPlugin *FormatFactory::format( const QString& type )
117{
118 FormatPlugin *format = 0;
119
120 if ( type.isEmpty() )
121 return 0;
122
123 if ( type == "vcard" ) {
124 format = new VCardFormatPlugin;
125 /* // LR
126 format->setType( type );
127 format->setNameLabel( i18n( "vCard" ) );
128 format->setDescriptionLabel( i18n( "vCard Format" ) );
129 */
130 return format;
131 }
132
133 FormatInfo *fi = mFormatList[ type ];
134 if (!fi)
135 return 0;
136 QString libName = fi->library;
137#ifndef DESKTOP_VERSION
138 KLibrary *library = openLibrary( libName );
139 if ( !library )
140 return 0;
141
142 void *format_func = library->symbol( "format" );
143
144 if ( format_func ) {
145 format = ((FormatPlugin* (*)())format_func)();
146 // LR
147 /*
148 format->setType( type );
149 format->setNameLabel( fi->nameLabel );
150 format->setDescriptionLabel( fi->descriptionLabel );
151 */
152 } else {
153 kdDebug( 5700 ) << "'" << libName << "' is not a format plugin." << endl;
154 return 0;
155 }
156#endif
157 return format;
158}
159
160#ifndef DESKTOP_VERSION
161KLibrary *FormatFactory::openLibrary( const QString& libName )
162{
163 KLibrary *library = 0;
164
165 QString path = KLibLoader::findLibrary( QFile::encodeName( libName ) );
166
167 if ( path.isEmpty() ) {
168 kdDebug( 5700 ) << "No format plugin library was found!" << endl;
169 return 0;
170 }
171
172 library = KLibLoader::self()->library( QFile::encodeName( path ) );
173
174 if ( !library ) {
175 kdDebug( 5700 ) << "Could not load library '" << libName << "'" << endl;
176 return 0;
177 }
178
179 return library;
180}
181#endif
diff --git a/kabc/formatfactory.h b/kabc/formatfactory.h
new file mode 100644
index 0000000..9612374
--- a/dev/null
+++ b/kabc/formatfactory.h
@@ -0,0 +1,104 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef KABC_FORMATFACTORY_H
22#define KABC_FORMATFACTORY_H
23
24#include <qdict.h>
25#include <qstring.h>
26
27#include <kconfig.h>
28#ifndef DESKTOP_VERSION
29#include <klibloader.h>
30#endif
31
32#include "formatplugin.h"
33
34namespace KABC {
35
36struct FormatInfo
37{
38 QString library;
39 QString nameLabel;
40 QString descriptionLabel;
41};
42
43/**
44 * Class for loading format plugins.
45 *
46 * Example:
47 *
48 * <pre>
49 * KABC::FormatFactory *factory = KABC::FormatFactory::self();
50 *
51 * QStringList list = factory->formats();
52 * QStringList::Iterator it;
53 * for ( it = list.begin(); it != list.end(); ++it ) {
54 * KABC::FormatPlugin *format = factory->format( (*it) );
55 * // do something with format
56 * }
57 * </pre>
58 */
59class FormatFactory
60{
61 public:
62
63 /**
64 Destructor.
65 */
66 ~FormatFactory();
67
68 /**
69 * Returns the global format factory.
70 */
71 static FormatFactory *self();
72
73 /**
74 * Returns a pointer to a format object or a null pointer
75 * if format type doesn't exist.
76 *
77 * @param type The type of the format, returned by @ref formats()
78 */
79 FormatPlugin *format( const QString &type );
80
81 /**
82 * Returns a list of all available format types.
83 */
84 QStringList formats();
85
86 /**
87 * Returns the info structure for a special type.
88 */
89 FormatInfo *info( const QString &type );
90
91 protected:
92 FormatFactory();
93
94 private:
95#ifndef DESKTOP_VERSION
96 KLibrary *openLibrary( const QString& libName );
97#endif
98 static FormatFactory *mSelf;
99
100 QDict<FormatInfo> mFormatList;
101};
102
103}
104#endif
diff --git a/kabc/formatplugin.h b/kabc/formatplugin.h
new file mode 100644
index 0000000..d784daf
--- a/dev/null
+++ b/kabc/formatplugin.h
@@ -0,0 +1,81 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_FORMATPLUGIN_H
29#define KABC_FORMATPLUGIN_H
30
31#include <qfile.h>
32
33//US #include "plugin.h"
34#include "resource.h"
35
36namespace KABC {
37
38class AddressBook;
39class Addressee;
40
41/**
42 * @short Base class for address book formats.
43 *
44 * This class provides an abstract interface for ResourceFile and
45 * ResourceDir formats.
46 *
47 * @internal
48 */
49//US class FormatPlugin : public Plugin
50class FormatPlugin
51{
52public:
53
54 /**
55 * Load single addressee from file.
56 */
57 virtual bool load( Addressee &, QFile *file ) = 0;
58
59 /**
60 * Load whole addressbook from file.
61 */
62 virtual bool loadAll( AddressBook *, Resource *, QFile *file ) = 0;
63
64 /**
65 * Save a single Addressee to file.
66 */
67 virtual void save( const Addressee &, QFile *file ) = 0;
68
69 /**
70 * Save whole addressbook to file.
71 */
72 virtual void saveAll( AddressBook *, Resource *, QFile *file ) = 0;
73
74 /**
75 * Checks if given file contains the right format
76 */
77 virtual bool checkFormat( QFile *file ) const = 0;
78};
79
80}
81#endif
diff --git a/kabc/formats/binaryformat.cpp b/kabc/formats/binaryformat.cpp
new file mode 100644
index 0000000..e2f28b8
--- a/dev/null
+++ b/kabc/formats/binaryformat.cpp
@@ -0,0 +1,236 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28
29#include <qdatastream.h>
30#include <qimage.h>
31
32#include <kdebug.h>
33#include <klocale.h>
34#include <kstandarddirs.h>
35
36#include "addressbook.h"
37#include "addressee.h"
38#include "picture.h"
39#include "sound.h"
40
41#include "binaryformat.h"
42
43#define BINARY_FORMAT_VERSION 2
44
45using namespace KABC;
46
47/*US
48extern "C"
49{
50 FormatPlugin *format()
51 {
52 qDebug(" BinaryFormat::format = new BinaryFormat");
53 return new BinaryFormat;
54 }
55}
56*/
57bool BinaryFormat::load( Addressee &addressee, QFile *file )
58{
59 kdDebug(5700) << "BinaryFormat::load()" << endl;
60 QDataStream stream( file );
61
62 if ( !checkHeader( stream ) )
63 return false;
64
65 loadAddressee( addressee, stream );
66
67 return true;
68}
69
70bool BinaryFormat::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
71{
72 kdDebug(5700) << "BinaryFormat::loadAll()" << endl;
73
74 QDataStream stream( file );
75
76 if ( !checkHeader( stream ) )
77 return false;
78
79 Q_UINT32 entries;
80
81 stream >> entries;
82
83 for ( uint i = 0; i < entries; ++i ) {
84 Addressee addressee;
85 loadAddressee( addressee, stream );
86 addressee.setResource( resource );
87 addressBook->insertAddressee( addressee );
88 }
89
90 return true;
91}
92
93void BinaryFormat::save( const Addressee &addressee, QFile *file )
94{
95 kdDebug(5700) << "BinaryFormat::save()" << endl;
96
97 QDataStream stream( file );
98
99 writeHeader( stream );
100
101 Q_UINT32 entries = 1;
102 stream << entries;
103 saveAddressee( addressee, stream );
104}
105
106void BinaryFormat::saveAll( AddressBook *ab, Resource *resource, QFile *file )
107{
108 kdDebug(5700) << "BinaryFormat::saveAll()" << endl;
109
110 Q_UINT32 counter = 0;
111 QDataStream stream( file );
112
113 writeHeader( stream );
114 // set dummy number of entries
115 stream << counter;
116
117 AddressBook::Iterator it;
118 for ( it = ab->begin(); it != ab->end(); ++it ) {
119 if ( (*it).resource() == resource ) {
120 saveAddressee( (*it), stream );
121 counter++;
122 (*it).setChanged( false );
123 }
124 }
125
126 // set real number of entries
127 stream.device()->at( 2 * sizeof( Q_UINT32 ) );
128 stream << counter;
129}
130
131bool BinaryFormat::checkFormat( QFile *file ) const
132{
133 kdDebug(5700) << "BinaryFormat::checkFormat()" << endl;
134
135 QDataStream stream( file );
136
137 return checkHeader( stream );
138}
139
140bool BinaryFormat::checkHeader( QDataStream &stream ) const
141{
142 Q_UINT32 magic, version;
143
144 stream >> magic >> version;
145
146//US QFile *file = dynamic_cast<QFile*>( stream.device() );
147 QFile *file = (QFile*)( stream.device() );
148
149 if ( !file ) {
150 qDebug("BinaryFormat::checkHeader : Not a file?");
151 kdError() << i18n("Not a file?") << endl;
152 return false;
153 }
154
155 if ( magic != 0x2e93e ) {
156 qDebug("BinaryFormat::checkHeader : File '%s' is not binary format.", file->name().latin1());
157 kdError() << i18n("File '%1' is not binary format.").arg( file->name() ) << endl;
158 return false;
159 }
160
161 if ( version != BINARY_FORMAT_VERSION ) {
162 qDebug("BinaryFormat::checkHeader : File '%s' is the wrong version.", file->name().latin1());
163 kdError() << i18n("File '%1' is the wrong version.").arg( file->name() ) << endl;
164 return false;
165 }
166
167 return true;
168}
169
170void BinaryFormat::writeHeader( QDataStream &stream )
171{
172 Q_UINT32 magic, version;
173
174 magic = 0x2e93e;
175 version = BINARY_FORMAT_VERSION;
176
177 stream << magic << version;
178}
179
180void BinaryFormat::loadAddressee( Addressee &addressee, QDataStream &stream )
181{
182 stream >> addressee;
183/*
184 // load pictures
185 Picture photo = addressee.photo();
186 Picture logo = addressee.logo();
187
188 if ( photo.isIntern() ) {
189 QImage img;
190 if ( !img.load( locateLocal( "data", "kabc/photos/" ) + addressee.uid() ) )
191 kdDebug(5700) << "No photo available for '" << addressee.uid() << "'." << endl;
192
193 addressee.setPhoto( img );
194 }
195
196 if ( logo.isIntern() ) {
197 QImage img;
198 if ( !img.load( locateLocal( "data", "kabc/logos/" ) + addressee.uid() ) )
199 kdDebug(5700) << "No logo available for '" << addressee.uid() << "'." << endl;
200
201 addressee.setLogo( img );
202 }
203
204 // load sound
205 // TODO: load sound data from file
206*/
207}
208
209void BinaryFormat::saveAddressee( const Addressee &addressee, QDataStream &stream )
210{
211 stream << addressee;
212/*
213 // load pictures
214 Picture photo = addressee.photo();
215 Picture logo = addressee.logo();
216
217 if ( photo.isIntern() ) {
218 QImage img = photo.data();
219 QString fileName = locateLocal( "data", "kabc/photos/" ) + addressee.uid();
220
221 if ( !img.save( fileName, "PNG" ) )
222 kdDebug(5700) << "Unable to save photo for '" << addressee.uid() << "'." << endl;
223 }
224
225 if ( logo.isIntern() ) {
226 QImage img = logo.data();
227 QString fileName = locateLocal( "data", "kabc/logos/" ) + addressee.uid();
228
229 if ( !img.save( fileName, "PNG" ) )
230 kdDebug(5700) << "Unable to save logo for '" << addressee.uid() << "'." << endl;
231 }
232
233 // save sound
234 // TODO: save the sound data to file
235*/
236}
diff --git a/kabc/formats/binaryformat.h b/kabc/formats/binaryformat.h
new file mode 100644
index 0000000..415fd3b
--- a/dev/null
+++ b/kabc/formats/binaryformat.h
@@ -0,0 +1,76 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/*
21Enhanced Version of the file for platform independent KDE tools.
22Copyright (c) 2004 Ulf Schenk
23
24$Id$
25*/
26
27#ifndef KABC_BINARYFORMAT_H
28#define KABC_BINARYFORMAT_H
29
30#include "formatplugin.h"
31
32namespace KABC {
33
34class AddressBook;
35class Addressee;
36
37/**
38 @short binary file format for addressbook entries.
39*/
40class BinaryFormat : public FormatPlugin
41{
42public:
43 /**
44 * Load single addressee from file.
45 */
46 bool load( Addressee &, QFile *file );
47
48 /**
49 * Load whole addressee from file.
50 */
51 bool loadAll( AddressBook *, Resource *, QFile *file );
52
53 /**
54 * Save single addressee to file.
55 */
56 void save( const Addressee &, QFile *file );
57
58 /**
59 * Save all addressees to file.
60 */
61 void saveAll( AddressBook *, Resource *, QFile *file );
62
63 /**
64 * Check for valid format of a file.
65 */
66 bool checkFormat( QFile *file ) const;
67
68private:
69 void loadAddressee( Addressee &, QDataStream & );
70 void saveAddressee( const Addressee &, QDataStream & );
71 bool checkHeader( QDataStream & ) const;
72 void writeHeader( QDataStream & );
73};
74
75}
76#endif
diff --git a/kabc/formats/vcardformatplugin2.cpp b/kabc/formats/vcardformatplugin2.cpp
new file mode 100644
index 0000000..2a772b4
--- a/dev/null
+++ b/kabc/formats/vcardformatplugin2.cpp
@@ -0,0 +1,123 @@
1/*
2Enhanced Version of the file for platform independent KDE tools.
3Copyright (c) 2004 Ulf Schenk
4
5$Id$
6*/
7
8#include "vcardformatplugin2.h"
9
10#include "address.h"
11#include "addressee.h"
12#include "vcardparser/vcardtool.h"
13
14#include <qtextstream.h>
15#include <qfile.h>
16
17using namespace KABC;
18
19/*US
20extern "C"
21{
22 FormatPlugin *format()
23 {
24 qDebug(" VCardFormatPlugin2::format = new VCardFormatPlugin2");
25 return new VCardFormatPlugin2();
26 }
27}
28*/
29
30VCardFormatPlugin2::VCardFormatPlugin2()
31{
32}
33
34VCardFormatPlugin2::~VCardFormatPlugin2()
35{
36}
37
38bool VCardFormatPlugin2::load( Addressee &addressee, QFile *file )
39{
40 QString data;
41
42 QTextStream t( file );
43 t.setEncoding( QTextStream::UnicodeUTF8 );
44 data = t.read();
45
46 VCardTool tool;
47
48 Addressee::List l = tool.parseVCards( data );
49
50 if ( ! l.first().isEmpty() ) {
51 addressee = l.first();
52 return true;
53 }
54
55 return false;
56}
57
58bool VCardFormatPlugin2::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
59{
60 QString data;
61
62 QTextStream t( file );
63 t.setEncoding( QTextStream::UnicodeUTF8 );
64 data = t.read();
65
66 VCardTool tool;
67
68 Addressee::List l = tool.parseVCards( data );
69
70 Addressee::List::Iterator itr;
71
72 for ( itr = l.begin(); itr != l.end(); ++itr) {
73 Addressee addressee = *itr;
74 addressee.setResource( resource );
75 addressBook->insertAddressee( addressee );
76 }
77
78 return true;
79}
80
81void VCardFormatPlugin2::save( const Addressee &addressee, QFile *file )
82{
83 VCardTool tool;
84 Addressee::List vcardlist;
85
86
87 vcardlist.append( addressee );
88
89 QTextStream t( file );
90 t.setEncoding( QTextStream::UnicodeUTF8 );
91 t << tool.createVCards( vcardlist );
92}
93
94void VCardFormatPlugin2::saveAll( AddressBook *ab, Resource *resource, QFile *file )
95{
96 VCardTool tool;
97 Addressee::List vcardlist;
98
99 AddressBook::Iterator it;
100 for ( it = ab->begin(); it != ab->end(); ++it ) {
101 if ( (*it).resource() == resource ) {
102 (*it).setChanged( false );
103 vcardlist.append( *it );
104 }
105 }
106
107 QTextStream t( file );
108 t.setEncoding( QTextStream::UnicodeUTF8 );
109 t << tool.createVCards( vcardlist );
110}
111
112bool VCardFormatPlugin2::checkFormat( QFile *file ) const
113{
114 QString line;
115
116 file->readLine( line, 1024 );
117 line = line.stripWhiteSpace();
118 if ( line == "BEGIN:VCARD" )
119 return true;
120 else
121 return false;
122}
123
diff --git a/kabc/formats/vcardformatplugin2.h b/kabc/formats/vcardformatplugin2.h
new file mode 100644
index 0000000..585ab6b
--- a/dev/null
+++ b/kabc/formats/vcardformatplugin2.h
@@ -0,0 +1,68 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Zack Rusin <zack@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef VCARDFORMATPLUGIN2_H
29#define VCARDFORMATPLUGIN2_H
30
31#include "formatplugin.h"
32#include "addressee.h"
33
34class QFile;
35
36namespace KABC {
37
38 class Resource;
39 class AddressBook;
40 /**
41 @short Interface of vCard backend for address book.
42
43 This class implements the file format interface of address book entries for
44 the vCard format.
45 */
46 class VCardFormatPlugin2 : public FormatPlugin
47 {
48 public:
49 VCardFormatPlugin2();
50 virtual ~VCardFormatPlugin2();
51
52 bool load( Addressee &, QFile *file );
53 bool loadAll( AddressBook *, Resource *, QFile *file );
54 void save( const Addressee &, QFile *file );
55 void saveAll( AddressBook *, Resource *, QFile *file );
56
57 bool checkFormat( QFile *file ) const;
58
59 private:
60 struct VCardFormatPrivate;
61 VCardFormatPrivate *d;
62 };
63
64
65}
66
67
68#endif
diff --git a/kabc/geo.cpp b/kabc/geo.cpp
new file mode 100644
index 0000000..33597b7
--- a/dev/null
+++ b/kabc/geo.cpp
@@ -0,0 +1,116 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qdatastream.h>
29
30#include "geo.h"
31
32using namespace KABC;
33
34Geo::Geo()
35 : mLatitude( 91 ), mLongitude( 181 ), mValidLat( false ), mValidLong( false )
36{
37}
38
39Geo::Geo( float latitude, float longitude )
40{
41 setLatitude( latitude );
42 setLongitude( longitude );
43}
44
45void Geo::setLatitude( float latitude )
46{
47 if ( latitude >= -90 && latitude <= 90 ) {
48 mLatitude = latitude;
49 mValidLat = true;
50 } else {
51 mLatitude = 91;
52 mValidLat = false;
53 }
54}
55
56float Geo::latitude() const
57{
58 return mLatitude;
59}
60
61void Geo::setLongitude( float longitude)
62{
63 if ( longitude >= -180 && longitude <= 180 ) {
64 mLongitude = longitude;
65 mValidLong = true;
66 } else {
67 mLongitude = 181;
68 mValidLong = false;
69 }
70}
71
72float Geo::longitude() const
73{
74 return mLongitude;
75}
76
77bool Geo::isValid() const
78{
79 return mValidLat && mValidLong;
80}
81
82bool Geo::operator==( const Geo &g ) const
83{
84 if ( !g.isValid() && !isValid() ) return true;
85 if ( !g.isValid() || !isValid() ) return false;
86 if ( g.mLatitude == mLatitude && g.mLongitude == mLongitude ) return true;
87 return false;
88}
89
90bool Geo::operator!=( const Geo &g ) const
91{
92 if ( !g.isValid() && !isValid() ) return false;
93 if ( !g.isValid() || !isValid() ) return true;
94 if ( g.mLatitude == mLatitude && g.mLongitude == mLongitude ) return false;
95 return true;
96}
97
98QString Geo::asString() const
99{
100 return "(" + QString::number(mLatitude) + "," + QString::number(mLongitude) + ")";
101}
102
103QDataStream &KABC::operator<<( QDataStream &s, const Geo &geo )
104{
105 return s << (float)geo.mLatitude << (float)geo.mLongitude;
106}
107
108QDataStream &KABC::operator>>( QDataStream &s, Geo &geo )
109{
110 s >> geo.mLatitude >> geo.mLongitude;
111
112 geo.mValidLat = true;
113 geo.mValidLong = true;
114
115 return s;
116}
diff --git a/kabc/geo.h b/kabc/geo.h
new file mode 100644
index 0000000..4c7f90f
--- a/dev/null
+++ b/kabc/geo.h
@@ -0,0 +1,106 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_GEO_H
29#define KABC_GEO_H
30
31#include <qstring.h>
32
33namespace KABC {
34
35/**
36 @short Geographic position
37
38 This class represents a geographic position.
39*/
40class Geo
41{
42 friend QDataStream &operator<<( QDataStream &, const Geo & );
43 friend QDataStream &operator>>( QDataStream &, Geo & );
44
45 public:
46 /**
47 Construct invalid geographics position object.
48 */
49 Geo();
50
51 /**
52 Construct geographics position object.
53
54 @param latitude Geographical latitude
55 @param longitude Geographical longitude
56 */
57 Geo( float latitude, float longitude );
58
59 /**
60 Sets the latitude.
61 */
62 void setLatitude( float );
63
64 /**
65 Returns the latitude.
66 */
67 float latitude() const;
68
69 /**
70 Sets the longitude.
71 */
72 void setLongitude( float );
73
74 /**
75 Returns the longitude.
76 */
77 float longitude() const;
78
79 /**
80 Returns, if this object contains a valid geographical position.
81 */
82 bool isValid() const;
83
84 bool operator==( const Geo & ) const;
85 bool operator!=( const Geo & ) const;
86
87 /**
88 Returns string representation of geographical position.
89 */
90 QString asString() const;
91
92 private:
93 float mLatitude;
94 float mLongitude;
95
96 bool mValid;
97 bool mValidLat;
98 bool mValidLong;
99};
100
101QDataStream &operator<<( QDataStream &, const Geo & );
102QDataStream &operator>>( QDataStream &, Geo & );
103
104}
105
106#endif
diff --git a/kabc/kabc.pro b/kabc/kabc.pro
new file mode 100644
index 0000000..ea4bbb7
--- a/dev/null
+++ b/kabc/kabc.pro
@@ -0,0 +1,214 @@
1 TEMPLATE= lib
2CONFIG += qt warn_on
3#release debug
4DESTDIR=../bin
5
6TARGET = microkabc
7
8include( ../variables.pri )
9
10INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kio/kfile ../qtcompat ../microkde/kdeui
11
12#LIBS += -lmicrokde -lldap
13LIBS += -L$(QPEDIR)/lib
14DEFINES += KAB_EMBEDDED DESKTOP_VERSION
15unix : {
16
17OBJECTS_DIR = obj/unix
18MOC_DIR = moc/unix
19}
20win32: {
21DEFINES += _WIN32_
22OBJECTS_DIR = obj/win
23MOC_DIR = moc/win
24}
25INTERFACES = \
26
27
28HEADERS = \
29 resource.h \
30 stdaddressbook.h \
31 agent.h \
32 geo.h \
33 key.h \
34 field.h \
35 plugin.h \
36 address.h \
37 addresseelist.h \
38formatfactory.h \
39 formatplugin.h \
40 phonenumber.h \
41distributionlist.h \
42distributionlistdialog.h \
43distributionlisteditor.h \
44vcardformatplugin.h \
45formats/binaryformat.h \
46formats/vcardformatplugin2.h \
47 picture.h \
48 secrecy.h \
49 sound.h \
50 addressbook.h \
51 timezone.h \
52 addressee.h \
53 addresseedialog.h \
54 vcardconverter.h \
55 vcard21parser.h \
56 vcardformatimpl.h \
57 plugins/file/resourcefile.h \
58 plugins/file/resourcefileconfig.h \
59 plugins/dir/resourcedir.h \
60 plugins/dir/resourcedirconfig.h \
61 vcardparser/vcardline.h \
62 vcardparser/vcard.h \
63 vcardparser/vcardtool.h \
64 vcardparser/vcardparser.h \
65vcard/include/VCardAdrParam.h \
66vcard/include/VCardAdrValue.h \
67vcard/include/VCardAgentParam.h \
68vcard/include/VCardContentLine.h \
69vcard/include/VCardDateParam.h \
70vcard/include/VCardDateValue.h \
71vcard/include/VCardEmailParam.h \
72vcard/include/VCardGeoValue.h \
73vcard/include/VCardGroup.h \
74vcard/include/VCardImageParam.h \
75vcard/include/VCardImageValue.h \
76vcard/include/VCardLangValue.h \
77vcard/include/VCardNValue.h \
78vcard/include/VCardParam.h \
79vcard/include/VCardPhoneNumberValue.h \
80vcard/include/VCardSourceParam.h \
81vcard/include/VCardTelParam.h \
82vcard/include/VCardTextParam.h \
83vcard/include/VCardTextNSParam.h \
84vcard/include/VCardTextValue.h \
85vcard/include/VCardTextBinParam.h \
86vcard/include/VCardURIValue.h \
87vcard/include/VCardVCard.h \
88vcard/include/VCardEntity.h \
89vcard/include/VCardValue.h \
90vcard/include/VCardSoundValue.h \
91vcard/include/VCardAgentValue.h \
92vcard/include/VCardTelValue.h \
93vcard/include/VCardTextBinValue.h \
94vcard/include/VCardOrgValue.h \
95vcard/include/VCardUTCValue.h \
96vcard/include/VCardClassValue.h \
97vcard/include/VCardFloatValue.h \
98vcard/include/VCardTextListValue.h \
99vcard/include/generated/AdrParam-generated.h \
100vcard/include/generated/AdrValue-generated.h \
101vcard/include/generated/AgentParam-generated.h \
102vcard/include/generated/ContentLine-generated.h \
103vcard/include/generated/DateParam-generated.h \
104vcard/include/generated/DateValue-generated.h \
105vcard/include/generated/EmailParam-generated.h \
106vcard/include/generated/GeoValue-generated.h \
107vcard/include/generated/Group-generated.h \
108vcard/include/generated/ImageParam-generated.h \
109vcard/include/generated/ImageValue-generated.h \
110vcard/include/generated/LangValue-generated.h \
111vcard/include/generated/NValue-generated.h \
112vcard/include/generated/Param-generated.h \
113vcard/include/generated/PhoneNumberValue-generated.h \
114vcard/include/generated/SourceParam-generated.h \
115vcard/include/generated/TelParam-generated.h \
116vcard/include/generated/TextParam-generated.h \
117vcard/include/generated/TextNSParam-generated.h \
118vcard/include/generated/TextValue-generated.h \
119vcard/include/generated/TextBinParam-generated.h \
120vcard/include/generated/URIValue-generated.h \
121vcard/include/generated/VCard-generated.h \
122vcard/include/generated/VCardEntity-generated.h \
123vcard/include/generated/Value-generated.h \
124vcard/include/generated/SoundValue-generated.h \
125vcard/include/generated/AgentValue-generated.h \
126vcard/include/generated/TelValue-generated.h \
127vcard/include/generated/TextBinValue-generated.h \
128vcard/include/generated/OrgValue-generated.h \
129vcard/include/generated/UTCValue-generated.h \
130vcard/include/generated/ClassValue-generated.h \
131vcard/include/generated/FloatValue-generated.h \
132vcard/include/generated/TextListValue-generated.h
133
134
135# plugins/ldap/resourceldap.h \
136# plugins/ldap/resourceldapconfig.h \
137
138
139SOURCES = \
140distributionlist.cpp \
141distributionlistdialog.cpp \
142distributionlisteditor.cpp \
143vcardformatplugin.cpp \
144formats/binaryformat.cpp \
145formats/vcardformatplugin2.cpp \
146formatfactory.cpp \
147 resource.cpp \
148 stdaddressbook.cpp \
149 plugin.cpp \
150 agent.cpp \
151 geo.cpp \
152 key.cpp \
153 field.cpp \
154 address.cpp \
155 phonenumber.cpp \
156 picture.cpp \
157 secrecy.cpp \
158 sound.cpp \
159 addressbook.cpp \
160 timezone.cpp \
161 addressee.cpp \
162 addresseelist.cpp \
163 addresseedialog.cpp \
164 vcardconverter.cpp \
165 vcard21parser.cpp \
166 vcardformatimpl.cpp \
167 plugins/file/resourcefile.cpp \
168 plugins/file/resourcefileconfig.cpp \
169 plugins/dir/resourcedir.cpp \
170 plugins/dir/resourcedirconfig.cpp \
171 vcardparser/vcardline.cpp \
172 vcardparser/vcard.cpp \
173 vcardparser/vcardtool.cpp \
174 vcardparser/vcardparser.cpp \
175vcard/AdrParam.cpp \
176vcard/AdrValue.cpp \
177vcard/AgentParam.cpp \
178vcard/ContentLine.cpp \
179vcard/DateParam.cpp \
180vcard/DateValue.cpp \
181vcard/EmailParam.cpp \
182vcard/Entity.cpp \
183vcard/Enum.cpp \
184vcard/GeoValue.cpp \
185vcard/ImageParam.cpp \
186vcard/ImageValue.cpp \
187vcard/LangValue.cpp \
188vcard/NValue.cpp \
189vcard/Param.cpp \
190vcard/PhoneNumberValue.cpp \
191vcard/RToken.cpp \
192vcard/SourceParam.cpp \
193vcard/TelParam.cpp \
194vcard/TextParam.cpp \
195vcard/TextValue.cpp \
196vcard/TextBinParam.cpp \
197vcard/URIValue.cpp \
198vcard/VCardv.cpp \
199vcard/VCardEntity.cpp \
200vcard/Value.cpp \
201vcard/SoundValue.cpp \
202vcard/AgentValue.cpp \
203vcard/TelValue.cpp \
204vcard/TextBinValue.cpp \
205vcard/OrgValue.cpp \
206vcard/UTCValue.cpp \
207vcard/ClassValue.cpp \
208vcard/FloatValue.cpp \
209vcard/TextListValue.cpp
210
211
212# plugins/ldap/resourceldap.cpp \
213# plugins/ldap/resourceldapconfig.cpp \
214
diff --git a/kabc/kabcE.pro b/kabc/kabcE.pro
new file mode 100644
index 0000000..6c37beb
--- a/dev/null
+++ b/kabc/kabcE.pro
@@ -0,0 +1,202 @@
1 TEMPLATE= lib
2CONFIG += qt warn_on
3TARGET = microkabc
4
5
6INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../qtcompat
7OBJECTS_DIR = obj/$(PLATFORM)
8MOC_DIR = moc/$(PLATFORM)
9DESTDIR = $(QPEDIR)/lib
10LIBS += -lmicrokde
11#LIBS += -lldap
12LIBS += -L$(QPEDIR)/lib
13DEFINES += KAB_EMBEDDED
14
15INTERFACES = \
16
17HEADERS = \
18 resource.h \
19 stdaddressbook.h \
20 agent.h \
21 geo.h \
22 key.h \
23 field.h \
24 plugin.h \
25 address.h \
26 addresseelist.h \
27formatfactory.h \
28 formatplugin.h \
29 phonenumber.h \
30distributionlist.h \
31distributionlistdialog.h \
32distributionlisteditor.h \
33vcardformatplugin.h \
34formats/binaryformat.h \
35formats/vcardformatplugin2.h \
36 picture.h \
37 secrecy.h \
38 sound.h \
39 addressbook.h \
40 timezone.h \
41 addressee.h \
42 addresseedialog.h \
43 vcardconverter.h \
44 vcard21parser.h \
45 vcardformatimpl.h \
46 plugins/file/resourcefile.h \
47 plugins/file/resourcefileconfig.h \
48 plugins/dir/resourcedir.h \
49 plugins/dir/resourcedirconfig.h \
50 vcardparser/vcardline.h \
51 vcardparser/vcard.h \
52 vcardparser/vcardtool.h \
53 vcardparser/vcardparser.h \
54vcard/include/VCardAdrParam.h \
55vcard/include/VCardAdrValue.h \
56vcard/include/VCardAgentParam.h \
57vcard/include/VCardContentLine.h \
58vcard/include/VCardDateParam.h \
59vcard/include/VCardDateValue.h \
60vcard/include/VCardEmailParam.h \
61vcard/include/VCardGeoValue.h \
62vcard/include/VCardGroup.h \
63vcard/include/VCardImageParam.h \
64vcard/include/VCardImageValue.h \
65vcard/include/VCardLangValue.h \
66vcard/include/VCardNValue.h \
67vcard/include/VCardParam.h \
68vcard/include/VCardPhoneNumberValue.h \
69vcard/include/VCardSourceParam.h \
70vcard/include/VCardTelParam.h \
71vcard/include/VCardTextParam.h \
72vcard/include/VCardTextNSParam.h \
73vcard/include/VCardTextValue.h \
74vcard/include/VCardTextBinParam.h \
75vcard/include/VCardURIValue.h \
76vcard/include/VCardVCard.h \
77vcard/include/VCardEntity.h \
78vcard/include/VCardValue.h \
79vcard/include/VCardSoundValue.h \
80vcard/include/VCardAgentValue.h \
81vcard/include/VCardTelValue.h \
82vcard/include/VCardTextBinValue.h \
83vcard/include/VCardOrgValue.h \
84vcard/include/VCardUTCValue.h \
85vcard/include/VCardClassValue.h \
86vcard/include/VCardFloatValue.h \
87vcard/include/VCardTextListValue.h \
88vcard/include/generated/AdrParam-generated.h \
89vcard/include/generated/AdrValue-generated.h \
90vcard/include/generated/AgentParam-generated.h \
91vcard/include/generated/ContentLine-generated.h \
92vcard/include/generated/DateParam-generated.h \
93vcard/include/generated/DateValue-generated.h \
94vcard/include/generated/EmailParam-generated.h \
95vcard/include/generated/GeoValue-generated.h \
96vcard/include/generated/Group-generated.h \
97vcard/include/generated/ImageParam-generated.h \
98vcard/include/generated/ImageValue-generated.h \
99vcard/include/generated/LangValue-generated.h \
100vcard/include/generated/NValue-generated.h \
101vcard/include/generated/Param-generated.h \
102vcard/include/generated/PhoneNumberValue-generated.h \
103vcard/include/generated/SourceParam-generated.h \
104vcard/include/generated/TelParam-generated.h \
105vcard/include/generated/TextParam-generated.h \
106vcard/include/generated/TextNSParam-generated.h \
107vcard/include/generated/TextValue-generated.h \
108vcard/include/generated/TextBinParam-generated.h \
109vcard/include/generated/URIValue-generated.h \
110vcard/include/generated/VCard-generated.h \
111vcard/include/generated/VCardEntity-generated.h \
112vcard/include/generated/Value-generated.h \
113vcard/include/generated/SoundValue-generated.h \
114vcard/include/generated/AgentValue-generated.h \
115vcard/include/generated/TelValue-generated.h \
116vcard/include/generated/TextBinValue-generated.h \
117vcard/include/generated/OrgValue-generated.h \
118vcard/include/generated/UTCValue-generated.h \
119vcard/include/generated/ClassValue-generated.h \
120vcard/include/generated/FloatValue-generated.h \
121vcard/include/generated/TextListValue-generated.h
122
123
124# plugins/ldap/resourceldap.h \
125# plugins/ldap/resourceldapconfig.h \
126
127
128SOURCES = \
129distributionlist.cpp \
130distributionlistdialog.cpp \
131distributionlisteditor.cpp \
132vcardformatplugin.cpp \
133formats/binaryformat.cpp \
134formats/vcardformatplugin2.cpp \
135formatfactory.cpp \
136 resource.cpp \
137 stdaddressbook.cpp \
138 plugin.cpp \
139 agent.cpp \
140 geo.cpp \
141 key.cpp \
142 field.cpp \
143 address.cpp \
144 phonenumber.cpp \
145 picture.cpp \
146 secrecy.cpp \
147 sound.cpp \
148 addressbook.cpp \
149 timezone.cpp \
150 addressee.cpp \
151 addresseelist.cpp \
152 addresseedialog.cpp \
153 vcardconverter.cpp \
154 vcard21parser.cpp \
155 vcardformatimpl.cpp \
156 plugins/file/resourcefile.cpp \
157 plugins/file/resourcefileconfig.cpp \
158 plugins/dir/resourcedir.cpp \
159 plugins/dir/resourcedirconfig.cpp \
160 vcardparser/vcardline.cpp \
161 vcardparser/vcard.cpp \
162 vcardparser/vcardtool.cpp \
163 vcardparser/vcardparser.cpp \
164vcard/AdrParam.cpp \
165vcard/AdrValue.cpp \
166vcard/AgentParam.cpp \
167vcard/ContentLine.cpp \
168vcard/DateParam.cpp \
169vcard/DateValue.cpp \
170vcard/EmailParam.cpp \
171vcard/Entity.cpp \
172vcard/Enum.cpp \
173vcard/GeoValue.cpp \
174vcard/ImageParam.cpp \
175vcard/ImageValue.cpp \
176vcard/LangValue.cpp \
177vcard/NValue.cpp \
178vcard/Param.cpp \
179vcard/PhoneNumberValue.cpp \
180vcard/RToken.cpp \
181vcard/SourceParam.cpp \
182vcard/TelParam.cpp \
183vcard/TextParam.cpp \
184vcard/TextValue.cpp \
185vcard/TextBinParam.cpp \
186vcard/URIValue.cpp \
187vcard/VCardv.cpp \
188vcard/VCardEntity.cpp \
189vcard/Value.cpp \
190vcard/SoundValue.cpp \
191vcard/AgentValue.cpp \
192vcard/TelValue.cpp \
193vcard/TextBinValue.cpp \
194vcard/OrgValue.cpp \
195vcard/UTCValue.cpp \
196vcard/ClassValue.cpp \
197vcard/FloatValue.cpp \
198vcard/TextListValue.cpp
199
200
201# plugins/ldap/resourceldap.cpp \
202# plugins/ldap/resourceldapconfig.cpp \
diff --git a/kabc/key.cpp b/kabc/key.cpp
new file mode 100644
index 0000000..802424b
--- a/dev/null
+++ b/kabc/key.cpp
@@ -0,0 +1,160 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <kapplication.h>
29#include <klocale.h>
30
31#include "key.h"
32
33using namespace KABC;
34
35Key::Key( const QString &text, int type )
36 : mTextData( text ), mIsBinary( false ), mType( type )
37{
38 mId = KApplication::randomString(8);
39}
40
41Key::~Key()
42{
43}
44
45bool Key::operator==( const Key &k ) const
46{
47 if ( mIsBinary != k.mIsBinary ) return false;
48 if ( mIsBinary )
49 if ( mBinaryData != k.mBinaryData ) return false;
50 else
51 if ( mTextData != k.mTextData ) return false;
52 if ( mType != k.mType ) return false;
53 if ( mCustomTypeString != k.mCustomTypeString ) return false;
54
55 return true;
56}
57
58bool Key::operator!=( const Key &k ) const
59{
60 return !( k == *this );
61}
62
63void Key::setId( const QString &id )
64{
65 mId = id;
66}
67
68QString Key::id() const
69{
70 return mId;
71}
72
73void Key::setBinaryData( const QByteArray &binary )
74{
75 mBinaryData = binary;
76 mIsBinary = true;
77}
78
79QByteArray Key::binaryData() const
80{
81 return mBinaryData;
82}
83
84void Key::setTextData( const QString &text )
85{
86 mTextData = text;
87 mIsBinary = false;
88}
89
90QString Key::textData() const
91{
92 return mTextData;
93}
94
95bool Key::isBinary() const
96{
97 return mIsBinary;
98}
99
100void Key::setType( int type )
101{
102 mType = type;
103}
104
105void Key::setCustomTypeString( const QString &custom )
106{
107 mCustomTypeString = custom;
108}
109
110int Key::type() const
111{
112 return mType;
113}
114
115QString Key::customTypeString() const
116{
117 return mCustomTypeString;
118}
119
120Key::TypeList Key::typeList()
121{
122 TypeList list;
123 list << X509;
124 list << PGP;
125 list << Custom;
126
127 return list;
128}
129
130QString Key::typeLabel( int type )
131{
132 switch ( type ) {
133 case X509:
134 return i18n( "X509" );
135 break;
136 case PGP:
137 return i18n( "PGP" );
138 break;
139 case Custom:
140 return i18n( "Custom" );
141 break;
142 default:
143 return i18n( "Unknown type" );
144 break;
145 }
146}
147
148QDataStream &KABC::operator<<( QDataStream &s, const Key &key )
149{
150 return s << key.mId << key.mIsBinary << key.mTextData << key.mBinaryData <<
151 key.mCustomTypeString << key.mType;
152}
153
154QDataStream &KABC::operator>>( QDataStream &s, Key &key )
155{
156 s >> key.mId >> key.mIsBinary >> key.mTextData >> key.mBinaryData >>
157 key.mCustomTypeString >> key.mType;
158
159 return s;
160}
diff --git a/kabc/key.h b/kabc/key.h
new file mode 100644
index 0000000..6ea5b47
--- a/dev/null
+++ b/kabc/key.h
@@ -0,0 +1,155 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_KEY_H
29#define KABC_KEY_H
30
31#include <qvaluelist.h>
32
33namespace KABC {
34
35/**
36 * @short A class to store an encryption key.
37 */
38class Key
39{
40 friend QDataStream &operator<<( QDataStream &, const Key & );
41 friend QDataStream &operator>>( QDataStream &, Key & );
42
43public:
44 typedef QValueList<Key> List;
45 typedef QValueList<int> TypeList;
46
47 /**
48 * Key types
49 *
50 * @li X509 - X509 key
51 * @li PGP - Pretty Good Privacy key
52 * @li Custom - Custom or IANA conform key
53 */
54 enum Types {
55 X509,
56 PGP,
57 Custom
58 };
59
60 /**
61 * Constructor.
62 *
63 * @param text The text data.
64 * @param type The key type, @see Types.
65 */
66 Key( const QString &text = QString::null, int type = PGP );
67
68 /**
69 * Destructor.
70 */
71 ~Key();
72
73 bool operator==( const Key & ) const;
74 bool operator!=( const Key & ) const;
75
76 /**
77 * Sets the unique identifier.
78 */
79 void setId( const QString &id );
80
81 /**
82 * Returns the unique identifier.
83 */
84 QString id() const;
85
86 /**
87 * Sets binary data.
88 */
89 void setBinaryData( const QByteArray &binary );
90
91 /**
92 * Returns the binary data.
93 */
94 QByteArray binaryData() const;
95
96 /**
97 * Sets text data.
98 */
99 void setTextData( const QString &text );
100
101 /**
102 * Returns the text data.
103 */
104 QString textData() const;
105
106 /**
107 * Returns whether the key contains binary or text data.
108 */
109 bool isBinary() const;
110
111 /**
112 * Sets the type, @see Type.
113 */
114 void setType( int type );
115
116 /**
117 * Sets custom type string.
118 */
119 void setCustomTypeString( const QString &custom );
120
121 /**
122 * Returns the type, @see Type.
123 */
124 int type() const;
125
126 /**
127 * Returns the custom type string.
128 */
129 QString customTypeString() const;
130
131 /**
132 * Returns a list of all available key types.
133 */
134 static TypeList typeList();
135
136 /**
137 * Returns a translated label for a given key type.
138 */
139 static QString typeLabel( int type );
140
141private:
142 QByteArray mBinaryData;
143 QString mId;
144 QString mTextData;
145 QString mCustomTypeString;
146
147 int mIsBinary;
148 int mType;
149};
150
151QDataStream &operator<<( QDataStream &, const Key & );
152QDataStream &operator>>( QDataStream &, Key & );
153
154}
155#endif
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
new file mode 100644
index 0000000..ad3e65b
--- a/dev/null
+++ b/kabc/phonenumber.cpp
@@ -0,0 +1,204 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <kapplication.h>
29#include <klocale.h>
30
31#include "phonenumber.h"
32
33using namespace KABC;
34
35PhoneNumber::PhoneNumber() :
36 mType( Home )
37{
38 init();
39}
40
41PhoneNumber::PhoneNumber( const QString &number, int type ) :
42 mType( type ), mNumber( number )
43{
44 init();
45}
46
47PhoneNumber::~PhoneNumber()
48{
49}
50
51void PhoneNumber::init()
52{
53 mId = KApplication::randomString( 8 );
54}
55
56bool PhoneNumber::operator==( const PhoneNumber &p ) const
57{
58 if ( mNumber != p.mNumber ) return false;
59 if ( mType != p.mType ) return false;
60
61 return true;
62}
63
64bool PhoneNumber::operator!=( const PhoneNumber &p ) const
65{
66 return !( p == *this );
67}
68
69void PhoneNumber::setId( const QString &id )
70{
71 mId = id;
72}
73
74QString PhoneNumber::id() const
75{
76 return mId;
77}
78
79void PhoneNumber::setNumber( const QString &number )
80{
81 mNumber = number;
82}
83
84QString PhoneNumber::number() const
85{
86 return mNumber;
87}
88
89void PhoneNumber::setType( int type )
90{
91 mType = type;
92}
93
94int PhoneNumber::type() const
95{
96 return mType;
97}
98
99QString PhoneNumber::typeLabel() const
100{
101 QString label;
102 bool first = true;
103
104 TypeList list = typeList();
105
106 TypeList::Iterator it;
107 for ( it = list.begin(); it != list.end(); ++it ) {
108 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
109 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
110 if ( first )
111 first = false;
112 }
113 }
114
115 return label;
116}
117
118QString PhoneNumber::label() const
119{
120 return typeLabel( type() );
121}
122
123PhoneNumber::TypeList PhoneNumber::typeList()
124{
125 TypeList list;
126
127 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
128 << Bbs << Modem << Car << Isdn << Pcs << Pager;
129
130 return list;
131}
132
133QString PhoneNumber::label( int type )
134{
135 return typeLabel( type );
136}
137
138QString PhoneNumber::typeLabel( int type )
139{
140 switch ( type ) {
141 case Home:
142 return i18n("Home phone", "Home");
143 break;
144 case Work:
145 return i18n("Work phone", "Work");
146 break;
147 case Msg:
148 return i18n("Messenger");
149 break;
150 case Pref:
151 return i18n("Preferred Number");
152 break;
153 case Voice:
154 return i18n("Voice");
155 break;
156 case Fax:
157 return i18n("Fax");
158 break;
159 case Cell:
160 return i18n("Mobile Phone", "Mobile" );
161 break;
162 case Video:
163 return i18n("Video");
164 break;
165 case Bbs:
166 return i18n("Mailbox");
167 break;
168 case Modem:
169 return i18n("Modem");
170 break;
171 case Car:
172 return i18n("Car Phone", "Car" );
173 break;
174 case Isdn:
175 return i18n("ISDN");
176 break;
177 case Pcs:
178 return i18n("PCS");
179 break;
180 case Pager:
181 return i18n("Pager");
182 break;
183 case Home | Fax:
184 return i18n("Home Fax");
185 break;
186 case Work | Fax:
187 return i18n("Work Fax");
188 break;
189 default:
190 return i18n("Other");
191 }
192}
193
194QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
195{
196 return s << phone.mId << phone.mType << phone.mNumber;
197}
198
199QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
200{
201 s >> phone.mId >> phone.mType >> phone.mNumber;
202
203 return s;
204}
diff --git a/kabc/phonenumber.h b/kabc/phonenumber.h
new file mode 100644
index 0000000..6a9c8cb
--- a/dev/null
+++ b/kabc/phonenumber.h
@@ -0,0 +1,165 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_PHONENUMBER_H
29#define KABC_PHONENUMBER_H
30
31#include <qvaluelist.h>
32#include <qstring.h>
33
34namespace KABC {
35
36/**
37 @short Phonenumber information.
38
39 This class provides phone number information. A phone number is classified by
40 a type. The following types are available, it's possible to use multiple types
41 @ref Types for a number by combining them through a logical or.
42*/
43class PhoneNumber
44{
45 friend QDataStream &operator<<( QDataStream &, const PhoneNumber & );
46 friend QDataStream &operator>>( QDataStream &, PhoneNumber & );
47
48 public:
49 typedef QValueList<PhoneNumber> List;
50 typedef QValueList<int> TypeList;
51
52 /**
53 @li @p Home - Home number
54 @li @p Work - Office number
55 @li @p Msg - Messaging
56 @li @p Pref - Preferred number
57 @li @p Voice - Voice
58 @li @p Fax - Fax machine
59 @li @p Cell - Cell phone
60 @li @p Video - Video phone
61 @li @p Bbs - Mailbox
62 @li @p Modem - Modem
63 @li @p Car - Car phone
64 @li @p Isdn - ISDN connection
65 @li @p Pcs - Personal Communication Service
66 @li @p Pager - Pager
67 */
68 enum Types { Home = 1, Work = 2, Msg = 4, Pref = 8, Voice = 16, Fax = 32,
69 Cell = 64, Video = 128, Bbs = 256, Modem = 512, Car = 1024,
70 Isdn = 2048, Pcs = 4096, Pager = 8192 };
71
72 /**
73 Create an empty phone number object.
74 */
75 PhoneNumber();
76
77 /**
78 Create a phonenumber object.
79
80 @param number Number
81 @param type Type as defined in enum. Multiple types can be
82 specified by combining them by a logical or.
83 */
84 PhoneNumber( const QString &number, int type = Home );
85
86 /**
87 Destructor.
88 */
89 ~PhoneNumber();
90
91 bool operator==( const PhoneNumber & ) const;
92 bool operator!=( const PhoneNumber & ) const;
93
94 /**
95 Sets the unique identifier.
96 */
97 void setId( const QString &id );
98
99 /**
100 Returns the unique identifier.
101 */
102 QString id() const;
103
104 /**
105 Sets the number.
106 */
107 void setNumber( const QString & );
108
109 /**
110 Returns the number.
111 */
112 QString number() const;
113
114 /**
115 Sets the type. Multiple types can be specified by combining them by
116 a logical or.
117 */
118 void setType( int );
119
120 /**
121 Returns the type. Can be a multiple types combined by a logical or.
122 */
123 int type() const;
124
125 /**
126 Returns a translated string of all types the address has.
127 */
128 QString typeLabel() const;
129
130 /**
131 Returns the translated label for phone number depending on its type.
132 */
133 QString label() const;
134
135 /**
136 Returns a list of all available types
137 */
138 static TypeList typeList();
139
140 /**
141 Returns the translated label for phone number type.
142 */
143 static QString typeLabel( int type );
144
145 /**
146 Returns the translated label for phone number type.
147 @obsolete
148 */
149 static QString label( int type );
150
151 private:
152 void init();
153
154 QString mId;
155
156 int mType;
157 QString mNumber;
158};
159
160QDataStream &operator<<( QDataStream &, const PhoneNumber & );
161QDataStream &operator>>( QDataStream &, PhoneNumber & );
162
163}
164
165#endif
diff --git a/kabc/picture.cpp b/kabc/picture.cpp
new file mode 100644
index 0000000..6a34b98
--- a/dev/null
+++ b/kabc/picture.cpp
@@ -0,0 +1,141 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include "picture.h"
29
30using namespace KABC;
31
32Picture::Picture()
33 : mIntern( false )
34{
35 mUndefined = true;
36}
37
38Picture::Picture( const QString &url )
39 : mUrl( url ), mIntern( false )
40{
41 mUndefined = false;
42}
43
44Picture::Picture( const QImage &data )
45 : mData( data ), mIntern( true )
46{
47 mUndefined = false;
48}
49
50Picture::~Picture()
51{
52}
53
54bool Picture::operator==( const Picture &p ) const
55{
56 if ( mIntern != p.mIntern ) return false;
57
58 if ( mIntern ) {
59 if ( mData != p.mData )
60 return false;
61 } else {
62 if ( mUrl != p.mUrl )
63 return false;
64 }
65
66 return true;
67}
68
69bool Picture::operator!=( const Picture &p ) const
70{
71 return !( p == *this );
72}
73
74void Picture::setUrl( const QString &url )
75{
76 mUrl = url;
77 mIntern = false;
78 mUndefined = false;
79}
80
81void Picture::setData( const QImage &data )
82{
83 mData = data;
84 mIntern = true;
85 mUndefined = false;
86}
87
88void Picture::setType( const QString &type )
89{
90 mType = type;
91}
92
93bool Picture::isIntern() const
94{
95 return mIntern;
96}
97
98QString Picture::url() const
99{
100 return mUrl;
101}
102
103QImage Picture::data() const
104{
105 return mData;
106}
107QPixmap Picture::pixmap() const
108{
109 QPixmap p;
110 p.convertFromImage ( mData );
111 return p;
112}
113
114QString Picture::type() const
115{
116 return mType;
117}
118bool Picture::undefined() const
119{
120 return mUndefined;
121}
122
123
124QString Picture::asString() const
125{
126 if ( mIntern )
127 return "intern picture";
128 else
129 return mUrl;
130}
131
132QDataStream &KABC::operator<<( QDataStream &s, const Picture &picture )
133{
134 return s << picture.mIntern << picture.mUrl << picture.mType << picture.mData;
135}
136
137QDataStream &KABC::operator>>( QDataStream &s, Picture &picture )
138{
139 s >> picture.mIntern >> picture.mUrl >> picture.mType >> picture.mData;
140 return s;
141}
diff --git a/kabc/picture.h b/kabc/picture.h
new file mode 100644
index 0000000..714d1e2
--- a/dev/null
+++ b/kabc/picture.h
@@ -0,0 +1,134 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_PICTURE_H
29#define KABC_PICTURE_H
30
31#include <qimage.h>
32
33namespace KABC {
34
35class Picture
36{
37 friend QDataStream &operator<<( QDataStream &, const Picture & );
38 friend QDataStream &operator>>( QDataStream &, Picture & );
39
40public:
41
42 /**
43 * Consturctor. Creates an empty object.
44 */
45 Picture();
46
47 /**
48 * Consturctor.
49 *
50 * @param url A URL that describes the position of the picture file.
51 */
52 Picture( const QString &url );
53
54 /**
55 * Consturctor.
56 *
57 * @param data The raw data of the picture.
58 */
59 Picture( const QImage &data );
60
61 /**
62 * Destructor.
63 */
64 ~Picture();
65
66 bool undefined() const;
67 bool operator==( const Picture & ) const;
68 bool operator!=( const Picture & ) const;
69
70 /**
71 * Sets a URL for the location of the picture file. When using this
72 * function, @ref isIntern() will return 'false' until you use
73 * @ref setData().
74 *
75 * @param url The location URL of the picture file.
76 */
77 void setUrl( const QString &url );
78
79 /**
80 * Sets the raw data of the picture. When using this function,
81 * @ref isIntern() will return 'true' until you use @ref setUrl().
82 *
83 * @param data The raw data of the picture.
84 */
85 void setData( const QImage &data );
86
87 /**
88 * Sets the type of the picture.
89 */
90 void setType( const QString &type );
91
92 /**
93 * Returns whether the picture is described by a URL (extern) or
94 * by the raw data (intern).
95 * When this method returns 'true' you can use @ref data() to
96 * get the raw data. Otherwise you can request the URL of this
97 * picture by @ref url() and load the raw data from that location.
98 */
99 bool isIntern() const;
100
101 /**
102 * Returns the location URL of this picture.
103 */
104 QString url() const;
105
106 /**
107 * Returns the raw data of this picture.
108 */
109 QImage data() const;
110 QPixmap pixmap() const;
111 /**
112 * Returns the type of this picture.
113 */
114 QString type() const;
115
116 /**
117 * Returns string representation of the picture.
118 */
119 QString asString() const;
120
121private:
122 QString mUrl;
123 QString mType;
124 QImage mData;
125 bool mUndefined;
126
127 int mIntern;
128};
129
130QDataStream &operator<<( QDataStream &, const Picture & );
131QDataStream &operator>>( QDataStream &, Picture & );
132
133}
134#endif
diff --git a/kabc/plugin.cpp b/kabc/plugin.cpp
new file mode 100644
index 0000000..16c7e86
--- a/dev/null
+++ b/kabc/plugin.cpp
@@ -0,0 +1,61 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include "plugin.h"
22
23using namespace KABC;
24
25Plugin::Plugin()
26{
27}
28
29Plugin::~Plugin()
30{
31}
32
33void Plugin::setType( const QString& type )
34{
35 mType = type;
36}
37
38QString Plugin::type() const
39{
40 return mType;
41}
42
43void Plugin::setNameLabel( const QString& label )
44{
45 mNameLabel = label;
46}
47
48QString Plugin::nameLabel() const
49{
50 return mNameLabel;
51}
52
53void Plugin::setDescriptionLabel( const QString& label )
54{
55 mDescriptionLabel = label;
56}
57
58QString Plugin::descriptionLabel() const
59{
60 return mDescriptionLabel;
61}
diff --git a/kabc/plugin.h b/kabc/plugin.h
new file mode 100644
index 0000000..122a995
--- a/dev/null
+++ b/kabc/plugin.h
@@ -0,0 +1,50 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef KABC_PLUGIN_H
22#define KABC_PLUGIN_H
23
24#include <qstring.h>
25
26namespace KABC {
27
28class Plugin
29{
30public:
31 Plugin();
32 virtual ~Plugin();
33
34 virtual void setType( const QString& type );
35 virtual QString type() const;
36
37 virtual void setNameLabel( const QString& label );
38 virtual QString nameLabel() const;
39
40 virtual void setDescriptionLabel( const QString& label );
41 virtual QString descriptionLabel() const;
42
43private:
44 QString mType;
45 QString mNameLabel;
46 QString mDescriptionLabel;
47};
48
49}
50#endif
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
new file mode 100644
index 0000000..f354a9e
--- a/dev/null
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -0,0 +1,363 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28
29#include <sys/types.h>
30#include <sys/stat.h>
31#ifndef _WIN32_
32#include <unistd.h>
33#endif
34
35#include <qregexp.h>
36#include <qtimer.h>
37#include <qwidget.h>
38
39#include <kapplication.h>
40#include <kconfig.h>
41#include <kdebug.h>
42//US #include <kgenericfactory.h>
43#include <kglobal.h>
44#include <klocale.h>
45#include <kstandarddirs.h>
46#include <kurlrequester.h>
47
48#include "addressbook.h"
49
50//US #include "formatfactory.h"
51
52#include "resourcedirconfig.h"
53#include "stdaddressbook.h"
54
55//US
56#include <qdir.h>
57#include <formats/vcardformatplugin2.h>
58#include <formats/binaryformat.h>
59
60#include "resourcedir.h"
61
62using namespace KABC;
63
64extern "C"
65{
66 void *init_kabc_dir()
67 {
68 qDebug("resourcedir.cpp : init_kabc_dir has to be changed");
69//US return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>();
70 return 0;
71 }
72}
73
74
75ResourceDir::ResourceDir( const KConfig *config )
76 : Resource( config )
77{
78 QString path;
79
80 KConfig *cfg = (KConfig *)config;
81 if ( cfg ) {
82//US path = config->readEntry( "FilePath" );
83 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() );
84//US mFormatName = config->readEntry( "FileFormat" );
85 mFormatName = cfg->readEntry( "FileFormat", "vcard" );
86 } else {
87 path = StdAddressBook::directoryName();
88 mFormatName = "vcard";
89 }
90
91
92/*US FormatFactory *factory = FormatFactory::self();
93 mFormat = factory->format( mFormatName );
94
95 if ( !mFormat ) {
96 mFormatName = "vcard";
97 mFormat = factory->format( mFormatName );
98 }
99*/
100
101//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1());
102 if (mFormatName == "vcard")
103 mFormat = new VCardFormatPlugin2();
104 else if (mFormatName == "binary")
105 mFormat = new BinaryFormat();
106 else
107 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1());
108
109
110/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods
111 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) );
112 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) );
113 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) );
114*/
115
116 setPath( path );
117}
118
119ResourceDir::~ResourceDir()
120{
121 delete mFormat;
122 mFormat = 0;
123}
124
125void ResourceDir::writeConfig( KConfig *config )
126{
127 Resource::writeConfig( config );
128
129 config->writeEntry( "FilePath", mPath );
130 config->writeEntry( "FileFormat", mFormatName );
131}
132
133Ticket *ResourceDir::requestSaveTicket()
134{
135 kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl;
136
137 if ( !addressBook() ) return 0;
138
139 if ( !lock( mPath ) ) {
140 kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '"
141 << mPath << "'" << endl;
142 return 0;
143 }
144 return createTicket( this );
145}
146
147
148bool ResourceDir::doOpen()
149{
150 QDir dir( mPath );
151 if ( !dir.exists() ) { // no directory available
152 return dir.mkdir( dir.path() );
153 } else {
154 QString testName = dir.entryList( QDir::Files )[0];
155 if ( testName.isNull() || testName.isEmpty() ) // no file in directory
156 return true;
157
158 QFile file( mPath + "/" + testName );
159 if ( file.open( IO_ReadOnly ) )
160 return true;
161
162 if ( file.size() == 0 )
163 return true;
164
165 bool ok = mFormat->checkFormat( &file );
166 file.close();
167 return ok;
168 }
169}
170
171void ResourceDir::doClose()
172{
173}
174
175bool ResourceDir::load()
176{
177 kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl;
178
179 QDir dir( mPath );
180 QStringList files = dir.entryList( QDir::Files );
181
182 QStringList::Iterator it;
183 bool ok = true;
184 for ( it = files.begin(); it != files.end(); ++it ) {
185 QFile file( mPath + "/" + (*it) );
186
187 if ( !file.open( IO_ReadOnly ) ) {
188 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) );
189 ok = false;
190 continue;
191 }
192
193 if ( !mFormat->loadAll( addressBook(), this, &file ) )
194 ok = false;
195
196 file.close();
197 }
198
199 return ok;
200}
201
202bool ResourceDir::save( Ticket *ticket )
203{
204 kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl;
205
206 AddressBook::Iterator it;
207 bool ok = true;
208
209 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
210 if ( (*it).resource() != this || !(*it).changed() )
211 continue;
212
213 QFile file( mPath + "/" + (*it).uid() );
214 if ( !file.open( IO_WriteOnly ) ) {
215 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) );
216 continue;
217 }
218
219 mFormat->save( *it, &file );
220
221 // mark as unchanged
222 (*it).setChanged( false );
223
224 file.close();
225 }
226
227 delete ticket;
228 unlock( mPath );
229
230 return ok;
231}
232
233bool ResourceDir::lock( const QString &path )
234{
235 kdDebug(5700) << "ResourceDir::lock()" << endl;
236
237 QString p = path;
238//US change the implementation how the lockfilename is getting created
239//US p.replace( QRegExp("/"), "_" );
240//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" );
241 KURL url(p);
242 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
243
244
245 kdDebug(5700) << "-- lock name: " << lockName << endl;
246
247 if ( QFile::exists( lockName ) ) return false;
248
249 QString lockUniqueName;
250 lockUniqueName = p + KApplication::randomString( 8 );
251
252 url = lockUniqueName;
253//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
254 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
255
256 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
257
258 // Create unique file
259 QFile file( mLockUniqueName );
260 file.open( IO_WriteOnly );
261 file.close();
262
263 // Create lock file
264#ifdef _WIN32_
265 int result = 0;
266 qDebug("WARNING: ResourceDir::lock cannot link ");
267#else
268 int result = ::link( QFile::encodeName( mLockUniqueName ),
269 QFile::encodeName( lockName ) );
270#endif
271 if ( result == 0 ) {
272 addressBook()->emitAddressBookLocked();
273 return true;
274 }
275
276 // TODO: check stat
277
278 return false;
279}
280
281void ResourceDir::unlock( const QString &path )
282{
283 QString p = path;
284//US change the implementation how the lockfilename is getting created
285//US p.replace( QRegExp( "/" ), "_" );
286//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" );
287 KURL url(p);
288 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" );
289
290 ::unlink( QFile::encodeName( lockName ) );
291 QFile::remove( mLockUniqueName );
292 addressBook()->emitAddressBookUnlocked();
293}
294
295void ResourceDir::setPath( const QString &path )
296{
297/*US ToDo: no synchronization so far. Has to be changed in the future
298 mDirWatch.stopScan();
299 mDirWatch.removeDir( mPath );
300*/
301 mPath = path;
302
303/*US ToDo: no synchronization so far. Has to be changed in the future
304 mDirWatch.addDir( mPath, true );
305 mDirWatch.startScan();
306*/
307
308//US simulate KDirWatch event
309 pathChanged();
310
311}
312
313QString ResourceDir::path() const
314{
315 return mPath;
316}
317
318void ResourceDir::setFormat( const QString &format )
319{
320 mFormatName = format;
321
322 if ( mFormat )
323 delete mFormat;
324
325//US FormatFactory *factory = FormatFactory::self();
326//US mFormat = factory->format( mFormatName );
327
328qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1());
329 if (mFormatName == "vcard")
330 mFormat = new VCardFormatPlugin2();
331 else if (mFormatName == "binary")
332 mFormat = new BinaryFormat();
333 else
334 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1());
335
336
337}
338
339QString ResourceDir::format() const
340{
341 return mFormatName;
342}
343
344void ResourceDir::pathChanged()
345{
346 if ( !addressBook() )
347 return;
348
349 load();
350 addressBook()->emitAddressBookChanged();
351}
352
353void ResourceDir::removeAddressee( const Addressee& addr )
354{
355 QFile::remove( mPath + "/" + addr.uid() );
356}
357
358void ResourceDir::cleanUp()
359{
360 unlock( mPath );
361}
362
363//US #include "resourcedir.moc"
diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h
new file mode 100644
index 0000000..6e35695
--- a/dev/null
+++ b/kabc/plugins/dir/resourcedir.h
@@ -0,0 +1,115 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_RESOURCEDIR_H
29#define KABC_RESOURCEDIR_H
30
31#include <kconfig.h>
32#include <kdirwatch.h>
33
34#include <sys/types.h>
35
36#include "resource.h"
37
38class QTimer;
39
40namespace KABC {
41
42class FormatPlugin;
43
44/**
45 @internal
46*/
47class ResourceDir : public Resource
48{
49 Q_OBJECT
50
51public:
52 ResourceDir( const KConfig* );
53 ~ResourceDir();
54
55 virtual void writeConfig( KConfig* );
56
57 virtual bool doOpen();
58 virtual void doClose();
59
60 virtual Ticket *requestSaveTicket();
61
62 virtual bool load();
63 virtual bool save( Ticket * );
64
65 /**
66 * Set path to be used for saving.
67 */
68 void setPath( const QString & );
69
70 /**
71 * Return path used for loading and saving the address book.
72 */
73 QString path() const;
74
75 /**
76 * Set the format by name.
77 */
78 void setFormat( const QString &format );
79
80 /**
81 * Returns the format name.
82 */
83 QString format() const;
84
85 /**
86 * Remove a addressee from its source.
87 * This method is mainly called by KABC::AddressBook.
88 */
89 virtual void removeAddressee( const Addressee& addr );
90
91 /**
92 * This method is called by an error handler if the application
93 * crashed
94 */
95 virtual void cleanUp();
96
97protected slots:
98 void pathChanged();
99
100protected:
101 bool lock( const QString &path );
102 void unlock( const QString &path );
103
104private:
105 FormatPlugin *mFormat;
106
107 KDirWatch mDirWatch;
108
109 QString mPath;
110 QString mFormatName;
111 QString mLockUniqueName;
112};
113
114}
115#endif
diff --git a/kabc/plugins/dir/resourcedirconfig.cpp b/kabc/plugins/dir/resourcedirconfig.cpp
new file mode 100644
index 0000000..98d18fe
--- a/dev/null
+++ b/kabc/plugins/dir/resourcedirconfig.cpp
@@ -0,0 +1,123 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qlabel.h>
29#include <qlayout.h>
30
31#include <kdebug.h>
32#include <klocale.h>
33#include <kstandarddirs.h>
34#include <kdialog.h>
35
36//US #include "formatfactory.h"
37#include "resourcedir.h"
38#include "stdaddressbook.h"
39
40#include "resourcedirconfig.h"
41
42using namespace KABC;
43
44ResourceDirConfig::ResourceDirConfig( QWidget* parent, const char* name )
45 : KRES::ConfigWidget( parent, name )
46{
47 QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0,
48 KDialog::spacingHint() );
49
50 QLabel *label = new QLabel( i18n( "Format:" ), this );
51 mFormatBox = new KComboBox( this );
52
53 mainLayout->addWidget( label, 0, 0 );
54 mainLayout->addWidget( mFormatBox, 0, 1 );
55
56 label = new QLabel( i18n( "Location:" ), this );
57 mFileNameEdit = new KURLRequester( this );
58//US mFileNameEdit->setMode( KFile::Directory );
59
60 mainLayout->addWidget( label, 1, 0 );
61 mainLayout->addWidget( mFileNameEdit, 1, 1 );
62
63/*US lets hardcode the formats instead of using a factory
64 FormatFactory *factory = FormatFactory::self();
65 QStringList formats = factory->formats();
66 QStringList::Iterator it;
67 for ( it = formats.begin(); it != formats.end(); ++it ) {
68 FormatInfo *info = factory->info( *it );
69 if ( info ) {
70 mFormatTypes << (*it);
71 mFormatBox->insertItem( info->nameLabel );
72 }
73 }
74*/
75 mFormatTypes << "vcard";
76 mFormatTypes << "binary";
77 mFormatBox->insertItem( "vcard" );
78 mFormatBox->insertItem( "binary" );
79
80
81 mInEditMode = false;
82}
83
84void ResourceDirConfig::setEditMode( bool value )
85{
86 mFormatBox->setEnabled( !value );
87 mInEditMode = value;
88}
89
90void ResourceDirConfig::loadSettings( KRES::Resource *res )
91{
92//US ResourceDir *resource = dynamic_cast<ResourceDir*>( res );
93 ResourceDir *resource = (ResourceDir*)( res );
94
95 if ( !resource ) {
96 kdDebug(5700) << "ResourceDirConfig::loadSettings(): cast failed" << endl;
97 return;
98 }
99
100 mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
101
102 mFileNameEdit->setURL( resource->path() );
103 if ( mFileNameEdit->url().isEmpty() )
104 mFileNameEdit->setURL( KABC::StdAddressBook::directoryName() );
105}
106
107void ResourceDirConfig::saveSettings( KRES::Resource *res )
108{
109//US ResourceDir *resource = dynamic_cast<ResourceDir*>( res );
110 ResourceDir *resource = (ResourceDir*)( res );
111
112 if ( !resource ) {
113 kdDebug(5700) << "ResourceDirConfig::loadSettings(): cast failed" << endl;
114 return;
115 }
116
117 if ( mInEditMode )
118 resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
119
120 resource->setPath( mFileNameEdit->url() );
121}
122
123//US #include "resourcedirconfig.moc"
diff --git a/kabc/plugins/dir/resourcedirconfig.h b/kabc/plugins/dir/resourcedirconfig.h
new file mode 100644
index 0000000..5af38a5
--- a/dev/null
+++ b/kabc/plugins/dir/resourcedirconfig.h
@@ -0,0 +1,61 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef RESOURCEDIRCONFIG_H
29#define RESOURCEDIRCONFIG_H
30
31#include <kcombobox.h>
32#include <kurlrequester.h>
33
34#include <kresources/configwidget.h>
35
36namespace KABC {
37
38class ResourceDirConfig : public KRES::ConfigWidget
39{
40 Q_OBJECT
41
42public:
43 ResourceDirConfig( QWidget* parent = 0, const char* name = 0 );
44
45 void setEditMode( bool value );
46
47public slots:
48 void loadSettings( KRES::Resource* );
49 void saveSettings( KRES::Resource* );
50
51private:
52 KComboBox* mFormatBox;
53 KURLRequester* mFileNameEdit;
54
55 QStringList mFormatTypes;
56
57 bool mInEditMode;
58};
59
60}
61#endif
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
new file mode 100644
index 0000000..d30ed2f
--- a/dev/null
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -0,0 +1,389 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <sys/types.h>
29#include <sys/stat.h>
30#ifndef _WIN32_
31#include <unistd.h>
32#endif
33
34#include <qfile.h>
35#include <qfileinfo.h>
36#include <qregexp.h>
37#include <qtimer.h>
38
39#include <kapplication.h>
40#include <kconfig.h>
41#include <kdebug.h>
42#include <klocale.h>
43//US #include <ksavefile.h>
44#include <kstandarddirs.h>
45
46//US #include "formatfactory.h"
47
48#include "resource.h"
49#include "resourcefileconfig.h"
50#include "stdaddressbook.h"
51
52#include <formats/vcardformatplugin2.h>
53#include <formats/binaryformat.h>
54
55
56#include "resourcefile.h"
57
58using namespace KABC;
59
60extern "C"
61{
62 void *init_kabc_file()
63 {
64 qDebug("!!!resourcefile.cpp : init_kabc_file has to be changed");
65//US return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
66 return 0;
67 }
68}
69
70
71ResourceFile::ResourceFile( const KConfig *config )
72 : Resource( config ) , mFormat( 0 )
73{
74 QString fileName, formatName;
75
76 KConfig *cfg = (KConfig *)config;
77 if ( cfg ) {
78 fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() );
79 formatName = cfg->readEntry( "FileFormat", "vcard" );
80// qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() );
81 } else {
82 fileName = StdAddressBook::fileName();
83 formatName = "vcard";
84// qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() );
85 }
86
87 init( fileName, formatName );
88}
89
90ResourceFile::ResourceFile( const QString &fileName,
91 const QString &formatName )
92 : Resource( 0 )
93{
94// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
95 init( fileName, formatName );
96}
97
98void ResourceFile::init( const QString &fileName, const QString &formatName )
99{
100 mFormatName = formatName;
101
102/*US FormatFactory *factory = FormatFactory::self();
103 mFormat = factory->format( mFormatName );
104
105 if ( !mFormat ) {
106 mFormatName = "vcard";
107 mFormat = factory->format( mFormatName );
108 }
109*/
110
111//US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1());
112 if (mFormatName == "vcard") {
113 mFormat = new VCardFormatPlugin2();
114// qDebug("ResourceFile::init format VCardFormatPlugin2");
115 }
116 else if (mFormatName == "binary") {
117 mFormat = new BinaryFormat();
118// qDebug("ResourceFile::init format BinaryFormat");
119 }
120 else
121 qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1());
122
123/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods
124 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
125 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
126 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
127*/
128
129 setFileName( fileName );
130}
131
132ResourceFile::~ResourceFile()
133{
134 delete mFormat;
135 mFormat = 0;
136}
137
138void ResourceFile::writeConfig( KConfig *config )
139{
140 Resource::writeConfig( config );
141
142 config->writeEntry( "FileName", mFileName );
143 config->writeEntry( "FileFormat", mFormatName );
144
145// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
146
147}
148
149Ticket *ResourceFile::requestSaveTicket()
150{
151 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
152
153 if ( !addressBook() ) return 0;
154
155 if ( !lock( mFileName ) ) {
156 kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '"
157 << mFileName << "'" << endl;
158 return 0;
159 }
160 return createTicket( this );
161}
162
163
164bool ResourceFile::doOpen()
165{
166 QFile file( mFileName );
167
168 if ( !file.exists() ) {
169 // try to create the file
170 bool ok = file.open( IO_WriteOnly );
171 if ( ok )
172 file.close();
173
174 return ok;
175 } else {
176 if ( !file.open( IO_ReadWrite ) )
177 return false;
178
179 if ( file.size() == 0 ) {
180 file.close();
181 return true;
182 }
183
184 bool ok = mFormat->checkFormat( &file );
185 file.close();
186
187 return ok;
188 }
189}
190
191void ResourceFile::doClose()
192{
193}
194
195bool ResourceFile::load()
196{
197 kdDebug(5700) << "ResourceFile::load(): '" << mFileName << "'" << endl;
198
199 QFile file( mFileName );
200 if ( !file.open( IO_ReadOnly ) ) {
201 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
202 return false;
203 }
204
205// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
206
207 return mFormat->loadAll( addressBook(), this, &file );
208}
209
210bool ResourceFile::save( Ticket *ticket )
211{
212// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
213 kdDebug(5700) << "ResourceFile::save()" << endl;
214
215 // create backup file
216 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
217
218/*US we use a simpler method to create a backupfile
219
220 (void) KSaveFile::backupFile( mFileName, QString::null /*directory*/
221/*US ,extension );
222
223 KSaveFile saveFile( mFileName );
224 bool ok = false;
225 if ( saveFile.status() == 0 && saveFile.file() )
226 {
227 mFormat->saveAll( addressBook(), this, saveFile.file() );
228 ok = saveFile.close();
229 }
230*/
231
232//US ToDo: write backupfile
233 QFile info;
234 info.setName( mFileName );
235 bool ok = info.open( IO_WriteOnly );
236 if ( ok ) {
237 mFormat->saveAll( addressBook(), this, &info );
238
239 info.close();
240 ok = true;
241 }
242 else {
243
244 }
245
246 if ( !ok )
247 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
248
249 delete ticket;
250 unlock( mFileName );
251
252 return ok;
253
254 qDebug("ResourceFile::save has to be changed");
255 return true;
256}
257
258bool ResourceFile::lock( const QString &fileName )
259{
260 kdDebug(5700) << "ResourceFile::lock()" << endl;
261
262 QString fn = fileName;
263
264//US change the implementation how the lockfilename is getting created
265//US fn.replace( QRegExp("/"), "_" );
266//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
267
268 KURL url(fn);
269 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
270
271 kdDebug(5700) << "-- lock name: " << lockName << endl;
272
273 if (QFile::exists( lockName )) return false;
274
275 QString lockUniqueName;
276 lockUniqueName = fn + KApplication::randomString( 8 );
277
278 url = lockUniqueName;
279//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
280 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
281 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
282
283 // Create unique file
284 QFile file( mLockUniqueName );
285 file.open( IO_WriteOnly );
286 file.close();
287
288 // Create lock file
289 int result = 0;//::link( QFile::encodeName( mLockUniqueName ),
290 // QFile::encodeName( lockName ) );
291 qDebug("lock files %s, %s needs to be fixed", mLockUniqueName.latin1(), lockName.latin1() );
292
293 if ( result == 0 ) {
294 addressBook()->emitAddressBookLocked();
295 return true;
296 }
297
298 // TODO: check stat
299
300 return false;
301}
302
303void ResourceFile::unlock( const QString &fileName )
304{
305 QString fn = fileName;
306//US change the implementation how the lockfilename is getting created
307//US fn.replace( QRegExp( "/" ), "_" );
308//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
309//US QString lockName = fn + ".lock";
310 KURL url(fn);
311 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
312
313 QFile::remove( lockName );
314 QFile::remove( mLockUniqueName );
315 addressBook()->emitAddressBookUnlocked();
316}
317
318void ResourceFile::setFileName( const QString &fileName )
319{
320/*US ToDo: no synchronization so far. Has to be changed in the future
321 mDirWatch.stopScan();
322 mDirWatch.removeFile( mFileName );
323*/
324 mFileName = fileName;
325
326
327/*US ToDo: no synchronization so far. Has to be changed in the future
328 mDirWatch.addFile( mFileName );
329 mDirWatch.startScan();
330*/
331//US simulate KDirWatch event
332 fileChanged();
333}
334
335QString ResourceFile::fileName() const
336{
337 return mFileName;
338}
339
340void ResourceFile::setFormat( const QString &format )
341{
342 mFormatName = format;
343 delete mFormat;
344
345//US FormatFactory *factory = FormatFactory::self();
346//US mFormat = factory->format( mFormatName );
347
348//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
349 if (mFormatName == "vcard") {
350 mFormat = new VCardFormatPlugin2();
351// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
352 }
353 else if (mFormatName == "binary") {
354 mFormat = new BinaryFormat();
355// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
356 }
357 else
358 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
359
360}
361
362QString ResourceFile::format() const
363{
364 return mFormatName;
365}
366
367void ResourceFile::fileChanged()
368{
369 // There is a small theoretical chance that KDirWatch calls us before
370 // we are fully constructed
371 if (!addressBook())
372 return;
373 load();
374 addressBook()->emitAddressBookChanged();
375}
376
377void ResourceFile::removeAddressee( const Addressee &addr )
378{
379 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) );
380 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) );
381 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
382}
383
384void ResourceFile::cleanUp()
385{
386 unlock( mFileName );
387}
388
389//US #include "resourcefile.moc"
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h
new file mode 100644
index 0000000..4522d78
--- a/dev/null
+++ b/kabc/plugins/file/resourcefile.h
@@ -0,0 +1,162 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28
29#ifndef KABC_RESOURCEFILE_H
30#define KABC_RESOURCEFILE_H
31
32#include <kconfig.h>
33#include <kdirwatch.h>
34
35#include <sys/types.h>
36
37#include <resource.h>
38
39class QTimer;
40class FormatPlugin;
41
42namespace KABC {
43
44//US class FormatPlugin;
45class ResourceConfigWidget;
46
47/**
48 @internal
49*/
50class ResourceFile : public Resource
51{
52 Q_OBJECT
53
54public:
55
56 /**
57 Constructor.
58
59 @param cfg The config object where custom resource settings are stored.
60 */
61 ResourceFile( const KConfig *cfg );
62
63 /**
64 Construct file resource on file @arg fileName using format @arg formatName.
65 */
66 ResourceFile( const QString &fileName, const QString &formatName = "vcard" );
67
68 /**
69 * Destructor.
70 */
71 ~ResourceFile();
72
73 /**
74 Writes the config back.
75 */
76 virtual void writeConfig( KConfig *cfg );
77
78 /**
79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load().
81 */
82 virtual bool doOpen();
83
84 /**
85 * Closes the file again.
86 */
87 virtual void doClose();
88
89 /**
90 * Requests a save ticket, that is used by @ref save()
91 */
92 virtual Ticket *requestSaveTicket();
93
94 /**
95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false.
97 */
98 virtual bool load();
99
100 /**
101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false.
103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */
106 virtual bool save( Ticket *ticket );
107
108 /**
109 * Set name of file to be used for saving.
110 */
111 void setFileName( const QString & );
112
113 /**
114 * Return name of file used for loading and saving the address book.
115 */
116 QString fileName() const;
117
118 /**
119 Sets a new format by name.
120 */
121 void setFormat( const QString &name );
122
123 /**
124 Returns the format name.
125 */
126 QString format() const;
127
128 /**
129 * Remove a addressee from its source.
130 * This method is mainly called by KABC::AddressBook.
131 */
132 virtual void removeAddressee( const Addressee& addr );
133
134 /**
135 * This method is called by an error handler if the application
136 * crashed
137 */
138 virtual void cleanUp();
139
140protected slots:
141 void fileChanged();
142
143protected:
144 void init( const QString &fileName, const QString &format );
145
146 bool lock( const QString &fileName );
147 void unlock( const QString &fileName );
148
149private:
150 QString mFileName;
151 QString mFormatName;
152
153 FormatPlugin *mFormat;
154
155 QString mLockUniqueName;
156
157 KDirWatch mDirWatch;
158};
159
160}
161
162#endif
diff --git a/kabc/plugins/file/resourcefileconfig.cpp b/kabc/plugins/file/resourcefileconfig.cpp
new file mode 100644
index 0000000..b63775d
--- a/dev/null
+++ b/kabc/plugins/file/resourcefileconfig.cpp
@@ -0,0 +1,144 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qlabel.h>
29#include <qlayout.h>
30#include <qfileinfo.h>
31
32#include <kdebug.h>
33#include <klocale.h>
34#include <kstandarddirs.h>
35#include <kdialog.h>
36#ifndef _WIN32_
37#include <unistd.h>
38#endif
39//US #include "formatfactory.h"
40#include <qfile.h>
41#include "resourcefile.h"
42#include "stdaddressbook.h"
43
44#include "resourcefileconfig.h"
45
46using namespace KABC;
47
48ResourceFileConfig::ResourceFileConfig( QWidget* parent, const char* name )
49 : ConfigWidget( parent, name )
50{
51//qDebug("ResourceFileConfig::ResourceFileConfig");
52
53 QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0,
54 KDialog::spacingHint() );
55
56 QLabel *label = new QLabel( i18n( "Format:" ), this );
57 mFormatBox = new KComboBox( this );
58
59 mainLayout->addWidget( label, 0, 0 );
60 mainLayout->addWidget( mFormatBox, 0, 1 );
61
62 label = new QLabel( i18n( "Location:" ), this );
63 mFileNameEdit = new KURLRequester( this );
64
65 connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ),
66 SLOT( checkFilePermissions( const QString & ) ) );
67
68 mainLayout->addWidget( label, 1, 0 );
69 mainLayout->addWidget( mFileNameEdit, 1, 1 );
70
71
72/*US lets hardcode the formats instead of using a factory
73 FormatFactory *factory = FormatFactory::self();
74 QStringList formats = factory->formats();
75 QStringList::Iterator it;
76
77 for ( it = formats.begin(); it != formats.end(); ++it ) {
78 FormatInfo *info = factory->info( *it );
79 if ( info ) {
80 mFormatTypes << (*it);
81 mFormatBox->insertItem( info->nameLabel );
82 }
83 }
84*/
85 mFormatTypes << "vcard";
86 mFormatTypes << "binary";
87 mFormatBox->insertItem( "vcard" );
88 mFormatBox->insertItem( "binary" );
89
90 mInEditMode = false;
91}
92
93void ResourceFileConfig::setEditMode( bool value )
94{
95 mFormatBox->setEnabled( !value );
96 mInEditMode = value;
97}
98
99void ResourceFileConfig::loadSettings( KRES::Resource *res )
100{
101//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
102 ResourceFile *resource = (ResourceFile*)( res );
103
104 if ( !resource ) {
105 kdDebug(5700) << "ResourceFileConfig::loadSettings(): cast failed" << endl;
106 return;
107 }
108
109 mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
110
111 mFileNameEdit->setURL( resource->fileName() );
112 if ( mFileNameEdit->url().isEmpty() )
113 mFileNameEdit->setURL( KABC::StdAddressBook::fileName() );
114}
115
116void ResourceFileConfig::saveSettings( KRES::Resource *res )
117{
118//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
119 ResourceFile *resource = (ResourceFile*)( res );
120
121 if ( !resource ) {
122 kdDebug(5700) << "ResourceFileConfig::saveSettings(): cast failed" << endl;
123 return;
124 }
125
126 if ( !mInEditMode )
127 resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
128
129 resource->setFileName( mFileNameEdit->url() );
130}
131void ResourceFileConfig::checkFilePermissions( const QString& fileName )
132{
133 // If file exist but is not writeable...
134#ifdef _WIN32_
135 QFileInfo fi ( QFile::encodeName( fileName ) );
136 if ( fi.exists() )
137 emit setReadOnly(!fi.isReadable() );
138#else
139 if ( access( QFile::encodeName( fileName ), F_OK ) == 0 )
140 emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 );
141#endif
142}
143
144//US #include "resourcefileconfig.moc"
diff --git a/kabc/plugins/file/resourcefileconfig.h b/kabc/plugins/file/resourcefileconfig.h
new file mode 100644
index 0000000..31ccaaf
--- a/dev/null
+++ b/kabc/plugins/file/resourcefileconfig.h
@@ -0,0 +1,65 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#ifndef RESOURCEFILECONFIG_H
30#define RESOURCEFILECONFIG_H
31
32#include <kcombobox.h>
33#include <kurlrequester.h>
34
35#include <kresources/configwidget.h>
36
37namespace KABC {
38
39class ResourceFileConfig : public KRES::ConfigWidget
40{
41 Q_OBJECT
42
43public:
44 ResourceFileConfig( QWidget* parent = 0, const char* name = 0 );
45
46 void setEditMode( bool value );
47
48public slots:
49 void loadSettings( KRES::Resource *resource );
50 void saveSettings( KRES::Resource *resource );
51
52protected slots:
53 void checkFilePermissions( const QString& fileName );
54
55private:
56 KComboBox* mFormatBox;
57 KURLRequester* mFileNameEdit;
58 bool mInEditMode;
59
60 QStringList mFormatTypes;
61};
62
63}
64
65#endif
diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp
new file mode 100644
index 0000000..1c54f63
--- a/dev/null
+++ b/kabc/plugins/ldap/resourceldap.cpp
@@ -0,0 +1,444 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <kdebug.h>
29#include <kglobal.h>
30#include <klineedit.h>
31#include <klocale.h>
32#include <kconfig.h>
33#include <kstringhandler.h>
34
35#include <stdlib.h>
36
37#include "resourceldap.h"
38#include "resourceldapconfig.h"
39
40using namespace KABC;
41
42extern "C"
43{
44 void *init_kabc_ldap()
45 {
46 qDebug("resourceldap.cpp : init_kabc_ldap has to be changed");
47//US return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig>();
48 }
49}
50
51void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value );
52
53
54ResourceLDAP::ResourceLDAP( const KConfig *config )
55 : Resource( config ), mPort( 389 ), mLdap( 0 )
56{
57 KConfig *cfg = (KConfig *)config;
58 if ( cfg ) {
59 mUser = cfg->readEntry( "LdapUser" );
60 mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) );
61 mDn = cfg->readEntry( "LdapDn" );
62 mHost = cfg->readEntry( "LdapHost" );
63 mPort = cfg->readNumEntry( "LdapPort", 389 );
64 mFilter = cfg->readEntry( "LdapFilter" );
65 mAnonymous = cfg->readBoolEntry( "LdapAnonymous" );
66
67 QStringList attributes = cfg->readListEntry( "LdapAttributes" );
68 for ( uint pos = 0; pos < attributes.count(); pos += 2 )
69 mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] );
70 }
71
72 /**
73 If you want to add new attributes, append them here, add a
74 translation string in the ctor of AttributesDialog and
75 handle them in the load() method below.
76 These are the default values from
77 */
78 if ( mAttributes.count() == 0 ) {
79 mAttributes.insert( "commonName", "cn" );
80 mAttributes.insert( "formattedName", "displayName" );
81 mAttributes.insert( "familyName", "sn" );
82 mAttributes.insert( "givenName", "givenName" );
83 mAttributes.insert( "mail", "mail" );
84 mAttributes.insert( "mailAlias", "" );
85 mAttributes.insert( "phoneNumber", "telephoneNumber" );
86 mAttributes.insert( "uid", "uid" );
87 }
88}
89
90void ResourceLDAP::writeConfig( KConfig *config )
91{
92 Resource::writeConfig( config );
93
94 config->writeEntry( "LdapUser", mUser );
95 config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) );
96 config->writeEntry( "LdapDn", mDn );
97 config->writeEntry( "LdapHost", mHost );
98 config->writeEntry( "LdapPort", mPort );
99 config->writeEntry( "LdapFilter", mFilter );
100 config->writeEntry( "LdapAnonymous", mAnonymous );
101
102 QStringList attributes;
103 QMap<QString, QString>::Iterator it;
104 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it )
105 attributes << it.key() << it.data();
106
107 config->writeEntry( "LdapAttributes", attributes );
108}
109
110Ticket *ResourceLDAP::requestSaveTicket()
111{
112 if ( !addressBook() ) {
113 kdDebug(5700) << "no addressbook" << endl;
114 return 0;
115 }
116
117 return createTicket( this );
118}
119
120bool ResourceLDAP::doOpen()
121{
122 if ( mLdap )
123 return false;
124
125 if ( !mPort )
126 mPort = 389;
127
128 mLdap = ldap_init( mHost.local8Bit(), mPort );
129 if ( !mLdap ) {
130 addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) );
131 return false;
132 }
133
134 if ( !mUser.isEmpty() && !mAnonymous ) {
135 if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) {
136 addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) );
137 return false;
138 }
139
140 kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl;
141 } else {
142 if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) {
143 addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) );
144 return false;
145 }
146
147 kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl;
148 }
149
150 int deref = LDAP_DEREF_ALWAYS;
151 if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) {
152 kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl;
153 return false;
154 }
155
156 if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) {
157 kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl;
158 return false;
159 }
160
161 return true;
162}
163
164void ResourceLDAP::doClose()
165{
166 if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) {
167 kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl;
168 return;
169 }
170
171 mLdap = 0;
172}
173
174bool ResourceLDAP::load()
175{
176 LDAPMessage *res;
177 LDAPMessage *msg;
178 BerElement *track;
179 char *names;
180 char **values;
181
182 char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ];
183
184 QMap<QString, QString>::Iterator it;
185 int i = 0;
186 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
187 if ( !it.data().isEmpty() ) {
188 unsigned int len = it.data().utf8().length();
189 LdapSearchAttr[ i ] = new char[ len+1 ];
190 memcpy( LdapSearchAttr[ i ], it.data().utf8(), len );
191 LdapSearchAttr[ i ][ len ] = 0;
192 ++i;
193 }
194 }
195 LdapSearchAttr[ i ] = 0;
196
197 QString filter = mFilter;
198 if ( filter.isEmpty() )
199 filter = "cn=*";
200
201 int result;
202 if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(),
203 LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) {
204 addressBook()->error( i18n( "Unable to search on server '%1': %2" )
205 .arg( mHost )
206 .arg( ldap_err2string( result ) ) );
207
208 for ( i = 0; LdapSearchAttr[ i ]; ++i )
209 delete [] LdapSearchAttr[ i ];
210 delete [] LdapSearchAttr;
211
212 return false;
213 }
214
215 for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) {
216 Addressee addr;
217 addr.setResource( this );
218 for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) {
219 values = ldap_get_values( mLdap, msg, names );
220 for ( int i = 0; i < ldap_count_values( values ); ++i ) {
221 QString name = QString::fromUtf8( names ).lower();
222 QString value = QString::fromUtf8( values[ i ] );
223
224 if ( name == mAttributes[ "commonName" ].lower() ) {
225 if ( !addr.formattedName().isEmpty() ) {
226 QString fn = addr.formattedName();
227 addr.setNameFromString( value );
228 addr.setFormattedName( fn );
229 } else
230 addr.setNameFromString( value );
231 } else if ( name == mAttributes[ "formattedName" ].lower() ) {
232 addr.setFormattedName( value );
233 } else if ( name == mAttributes[ "givenName" ].lower() ) {
234 addr.setGivenName( value );
235 } else if ( name == mAttributes[ "mail" ].lower() ) {
236 addr.insertEmail( value, true );
237 } else if ( name == mAttributes[ "mailAlias" ].lower() ) {
238 addr.insertEmail( value, false );
239 } else if ( name == mAttributes[ "phoneNumber" ].lower() ) {
240 PhoneNumber phone;
241 phone.setNumber( value );
242 addr.insertPhoneNumber( phone );
243 break; // read only the home number
244 } else if ( name == mAttributes[ "familyName" ].lower() ) {
245 addr.setFamilyName( value );
246 } else if ( name == mAttributes[ "uid" ].lower() ) {
247 addr.setUid( value );
248 }
249 }
250 ldap_value_free( values );
251 }
252 ber_free( track, 0 );
253
254 addressBook()->insertAddressee( addr );
255 }
256
257 ldap_msgfree( res );
258
259 for ( i = 0; LdapSearchAttr[ i ]; ++i )
260 delete [] LdapSearchAttr[ i ];
261 delete [] LdapSearchAttr;
262
263 return true;
264}
265
266bool ResourceLDAP::save( Ticket * )
267{
268 AddressBook::Iterator it;
269 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
270 if ( (*it).resource() == this && (*it).changed() ) {
271 LDAPMod **mods = NULL;
272
273 addModOp( &mods, "objectClass", "organizationalPerson" );
274 addModOp( &mods, "objectClass", "person" );
275 addModOp( &mods, "objectClass", "Top" );
276 addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() );
277 addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() );
278 addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() );
279 addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() );
280 addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() );
281
282 QStringList emails = (*it).emails();
283 QStringList::ConstIterator mailIt;
284 bool first = true;
285 for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) {
286 if ( first ) {
287 addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) );
288 first = false;
289 } else
290 addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) );
291 }
292
293 PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home );
294 addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() );
295
296 QString dn = "cn=" + (*it).assembledName() + "," + mDn;
297
298 int retval;
299 if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS )
300 addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) );
301
302 ldap_mods_free( mods, 1 );
303
304 // mark as unchanged
305 (*it).setChanged( false );
306 }
307 }
308
309 return true;
310}
311
312void ResourceLDAP::removeAddressee( const Addressee &addr )
313{
314 LDAPMessage *res;
315 LDAPMessage *msg;
316
317 QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter );
318
319 kdDebug(5700) << "ldap:removeAddressee" << filter << endl;
320
321 ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(),
322 0, 0, &res );
323
324 for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) {
325 char *dn = ldap_get_dn( mLdap, msg );
326 kdDebug(5700) << "found " << dn << endl;
327 if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS )
328 addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) );
329 ldap_memfree( dn );
330 }
331
332 ldap_msgfree( res );
333}
334
335void ResourceLDAP::setUser( const QString &user )
336{
337 mUser = user;
338}
339
340QString ResourceLDAP::user() const
341{
342 return mUser;
343}
344
345void ResourceLDAP::setPassword( const QString &password )
346{
347 mPassword = password;
348}
349
350QString ResourceLDAP::password() const
351{
352 return mPassword;
353}
354
355void ResourceLDAP::setDn( const QString &dn )
356{
357 mDn = dn;
358}
359
360QString ResourceLDAP::dn() const
361{
362 return mDn;
363}
364
365void ResourceLDAP::setHost( const QString &host )
366{
367 mHost = host;
368}
369
370QString ResourceLDAP::host() const
371{
372 return mHost;
373}
374
375void ResourceLDAP::setPort( int port )
376{
377 mPort = port;
378}
379
380int ResourceLDAP::port() const
381{
382 return mPort;
383}
384
385void ResourceLDAP::setFilter( const QString &filter )
386{
387 mFilter = filter;
388}
389
390QString ResourceLDAP::filter() const
391{
392 return mFilter;
393}
394
395void ResourceLDAP::setIsAnonymous( bool value )
396{
397 mAnonymous = value;
398}
399
400bool ResourceLDAP::isAnonymous() const
401{
402 return mAnonymous;
403}
404
405void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes )
406{
407 mAttributes = attributes;
408}
409
410QMap<QString, QString> ResourceLDAP::attributes() const
411{
412 return mAttributes;
413}
414
415void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value )
416{
417 if ( value.isNull() )
418 return;
419
420 LDAPMod**mods;
421
422 mods = *pmods;
423
424 uint i = 0;
425 if ( mods != 0 )
426 for ( ; mods[ i ] != 0; ++i );
427
428 if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) {
429 kdError() << "ResourceLDAP: realloc" << endl;
430 return;
431 }
432
433 *pmods = mods;
434 mods[ i + 1 ] = 0;
435
436 mods[ i ] = new LDAPMod;
437
438 mods[ i ]->mod_op = 0;
439 mods[ i ]->mod_type = strdup( attr.utf8() );
440 mods[ i ]->mod_values = new char*[ 2 ];
441 mods[ i ]->mod_values[ 0 ] = strdup( value.utf8() );
442 mods[ i ]->mod_values[ 1 ] = 0;
443}
444
diff --git a/kabc/plugins/ldap/resourceldap.h b/kabc/plugins/ldap/resourceldap.h
new file mode 100644
index 0000000..0625f30
--- a/dev/null
+++ b/kabc/plugins/ldap/resourceldap.h
@@ -0,0 +1,99 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_RESOURCELDAP_H
29#define KABC_RESOURCELDAP_H
30
31
32#include <lber.h>
33#include <ldap.h>
34
35#include "addressbook.h"
36#include "resource.h"
37
38class KConfig;
39
40namespace KABC {
41
42class ResourceLDAP : public Resource
43{
44public:
45
46 ResourceLDAP( const KConfig* );
47
48 virtual void writeConfig( KConfig* );
49
50 virtual bool doOpen();
51 virtual void doClose();
52
53 virtual Ticket *requestSaveTicket();
54
55 virtual bool load();
56 virtual bool save( Ticket * );
57
58 virtual void removeAddressee( const Addressee& addr );
59
60 void setUser( const QString &user );
61 QString user() const;
62
63 void setPassword( const QString &password );
64 QString password() const;
65
66 void setDn( const QString &dn );
67 QString dn() const;
68
69 void setHost( const QString &host );
70 QString host() const;
71
72 void setPort( int port );
73 int port() const;
74
75 void setFilter( const QString &filter );
76 QString filter() const;
77
78 void setIsAnonymous( bool value );
79 bool isAnonymous() const;
80
81 void setAttributes( const QMap<QString, QString> &attributes );
82 QMap<QString, QString> attributes() const;
83
84private:
85 QString mUser;
86 QString mPassword;
87 QString mDn;
88 QString mHost;
89 QString mFilter;
90 int mPort;
91 bool mAnonymous;
92 QMap<QString, QString> mAttributes;
93
94 LDAP *mLdap;
95};
96
97}
98
99#endif
diff --git a/kabc/plugins/ldap/resourceldapconfig.cpp b/kabc/plugins/ldap/resourceldapconfig.cpp
new file mode 100644
index 0000000..2c0d030
--- a/dev/null
+++ b/kabc/plugins/ldap/resourceldapconfig.cpp
@@ -0,0 +1,254 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qcheckbox.h>
29#include <qlabel.h>
30#include <qlayout.h>
31#include <qpushbutton.h>
32#include <qspinbox.h>
33#include <qvbox.h>
34
35//US #include <kaccelmanager.h>
36#include <kcombobox.h>
37#include <kdebug.h>
38#include <kdialogbase.h>
39#include <klocale.h>
40#include <klineedit.h>
41
42#include "resourceldap.h"
43
44#include "resourceldapconfig.h"
45
46using namespace KABC;
47
48ResourceLDAPConfig::ResourceLDAPConfig( QWidget* parent, const char* name )
49 : KRES::ConfigWidget( parent, name )
50{
51 QGridLayout *mainLayout = new QGridLayout( this, 8, 2, 0,
52 KDialog::spacingHint() );
53
54 QLabel *label = new QLabel( i18n( "User:" ), this );
55 mUser = new KLineEdit( this );
56
57 mainLayout->addWidget( label, 0, 0 );
58 mainLayout->addWidget( mUser, 0, 1 );
59
60 label = new QLabel( i18n( "Password:" ), this );
61 mPassword = new KLineEdit( this );
62 mPassword->setEchoMode( KLineEdit::Password );
63
64 mainLayout->addWidget( label, 1, 0 );
65 mainLayout->addWidget( mPassword, 1, 1 );
66
67 label = new QLabel( i18n( "Host:" ), this );
68 mHost = new KLineEdit( this );
69
70 mainLayout->addWidget( label, 2, 0 );
71 mainLayout->addWidget( mHost, 2, 1 );
72
73 label = new QLabel( i18n( "Port:" ), this );
74 QVBox *box = new QVBox( this );
75 mPort = new QSpinBox( 0, 65535, 1, box );
76 mPort->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) );
77 mPort->setValue( 389 );
78 new QWidget( box, "dummy" );
79
80 mainLayout->addWidget( label, 3, 0 );
81 mainLayout->addWidget( box, 3, 1 );
82
83 label = new QLabel( i18n( "Dn:" ), this );
84 mDn = new KLineEdit( this );
85
86 mainLayout->addWidget( label, 4, 0 );
87 mainLayout->addWidget( mDn, 4, 1 );
88
89 label = new QLabel( i18n( "Filter:" ), this );
90 mFilter = new KLineEdit( this );
91
92 mainLayout->addWidget( label, 5, 0 );
93 mainLayout->addWidget( mFilter, 5, 1 );
94
95 mAnonymous = new QCheckBox( i18n( "Anonymous login" ), this );
96 mainLayout->addMultiCellWidget( mAnonymous, 6, 6, 0, 1 );
97
98 mEditButton = new QPushButton( i18n( "Edit Attributes..." ), this );
99 mainLayout->addMultiCellWidget( mEditButton, 7, 7, 0, 1 );
100
101 connect( mAnonymous, SIGNAL( toggled(bool) ), mUser, SLOT( setDisabled(bool) ) );
102 connect( mAnonymous, SIGNAL( toggled(bool) ), mPassword, SLOT( setDisabled(bool) ) );
103 connect( mEditButton, SIGNAL( clicked() ), SLOT( editAttributes() ) );
104}
105
106void ResourceLDAPConfig::loadSettings( KRES::Resource *res )
107{
108//US ResourceLDAP *resource = dynamic_cast<ResourceLDAP*>( res );
109 ResourceLDAP *resource = (ResourceLDAP*)( res );
110
111 if ( !resource ) {
112 kdDebug(5700) << "ResourceLDAPConfig::loadSettings(): cast failed" << endl;
113 return;
114 }
115
116 mUser->setText( resource->user() );
117 mPassword->setText( resource->password() );
118 mHost->setText( resource->host() );
119 mPort->setValue( resource->port() );
120 mDn->setText( resource->dn() );
121 mFilter->setText( resource->filter() );
122 mAnonymous->setChecked( resource->isAnonymous() );
123 mAttributes = resource->attributes();
124}
125
126void ResourceLDAPConfig::saveSettings( KRES::Resource *res )
127{
128//US ResourceLDAP *resource = dynamic_cast<ResourceLDAP*>( res );
129 ResourceLDAP *resource = (ResourceLDAP*)( res );
130
131 if ( !resource ) {
132 kdDebug(5700) << "ResourceLDAPConfig::saveSettings(): cast failed" << endl;
133 return;
134 }
135
136 resource->setUser( mUser->text() );
137 resource->setPassword( mPassword->text() );
138 resource->setHost( mHost->text() );
139 resource->setPort( mPort->value() );
140 resource->setDn( mDn->text() );
141 resource->setFilter( mFilter->text() );
142 resource->setIsAnonymous( mAnonymous->isChecked() );
143 resource->setAttributes( mAttributes );
144}
145
146void ResourceLDAPConfig::editAttributes()
147{
148 AttributesDialog dlg( mAttributes, this );
149 if ( dlg.exec() )
150 mAttributes = dlg.attributes();
151}
152
153AttributesDialog::AttributesDialog( const QMap<QString, QString> &attributes,
154 QWidget *parent, const char *name )
155 : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel,
156 Ok, parent, name, true, true )
157{
158 mNameDict.setAutoDelete( true );
159 mNameDict.insert( "commonName", new QString( i18n( "Common name" ) ) );
160 mNameDict.insert( "formattedName", new QString( i18n( "Formatted name" ) ) );
161 mNameDict.insert( "familyName", new QString( i18n( "Family name" ) ) );
162 mNameDict.insert( "givenName", new QString( i18n( "Given name" ) ) );
163 mNameDict.insert( "mail", new QString( i18n( "Email" ) ) );
164 mNameDict.insert( "mailAlias", new QString( i18n( "Email alias" ) ) );
165 mNameDict.insert( "phoneNumber", new QString( i18n( "Telephone number" ) ) );
166 mNameDict.insert( "uid", new QString( i18n( "UID" ) ) );
167
168 // overwrite the default values here
169 QMap<QString, QString> kolabMap, netscapeMap, evolutionMap, outlookMap;
170
171 // kolab
172 kolabMap.insert( "formattedName", "display-name" );
173 kolabMap.insert( "mailAlias", "mailalias" );
174
175 // evolution
176 evolutionMap.insert( "formattedName", "fileAs" );
177
178 mMapList.append( attributes );
179 mMapList.append( kolabMap );
180 mMapList.append( netscapeMap );
181 mMapList.append( evolutionMap );
182 mMapList.append( outlookMap );
183
184 QFrame *page = plainPage();
185 QGridLayout *layout = new QGridLayout( page, 2, attributes.count() + 1,
186 0, spacingHint() );
187
188 QLabel *label = new QLabel( i18n( "Template:" ), page );
189 layout->addWidget( label, 0, 0 );
190 mMapCombo = new KComboBox( page );
191 layout->addWidget( mMapCombo, 0, 1 );
192
193 mMapCombo->insertItem( i18n( "User Defined" ) );
194 mMapCombo->insertItem( i18n( "Kolab" ) );
195 mMapCombo->insertItem( i18n( "Netscape" ) );
196 mMapCombo->insertItem( i18n( "Evolution" ) );
197 mMapCombo->insertItem( i18n( "Outlook" ) );
198 connect( mMapCombo, SIGNAL( activated( int ) ), SLOT( mapChanged( int ) ) );
199
200 QMap<QString, QString>::ConstIterator it;
201 int i;
202 for ( i = 1, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
203 label = new QLabel( *mNameDict[ it.key() ] + ":", page );
204 KLineEdit *lineedit = new KLineEdit( page );
205 mLineEditDict.insert( it.key(), lineedit );
206 lineedit->setText( it.data() );
207 label->setBuddy( lineedit );
208 layout->addWidget( label, i, 0 );
209 layout->addWidget( lineedit, i, 1 );
210 }
211
212//US KAcceleratorManager::manage( this );
213}
214
215AttributesDialog::~AttributesDialog()
216{
217}
218
219QMap<QString, QString> AttributesDialog::attributes() const
220{
221 QMap<QString, QString> map;
222
223 QDictIterator<KLineEdit> it( mLineEditDict );
224 for ( ; it.current(); ++it )
225 map.insert( it.currentKey(), it.current()->text() );
226
227 return map;
228}
229
230void AttributesDialog::mapChanged( int pos )
231{
232 // default map
233 QMap<QString, QString> defaultMap;
234 defaultMap.insert( "commonName", "cn" );
235 defaultMap.insert( "formattedName", "displayName" );
236 defaultMap.insert( "familyName", "sn" );
237 defaultMap.insert( "givenName", "givenName" );
238 defaultMap.insert( "mail", "mail" );
239 defaultMap.insert( "mailAlias", "" );
240 defaultMap.insert( "phoneNumber", "telephoneNumber" );
241 defaultMap.insert( "uid", "uid" );
242
243 // apply first the default and than the spezific changes
244 QMap<QString, QString>::Iterator it;
245 for ( it = defaultMap.begin(); it != defaultMap.end(); ++it )
246 mLineEditDict[ it.key() ]->setText( it.data() );
247
248 for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
249 if ( !it.data().isEmpty() )
250 mLineEditDict[ it.key() ]->setText( it.data() );
251 }
252}
253
254//US #include "resourceldapconfig.moc"
diff --git a/kabc/plugins/ldap/resourceldapconfig.h b/kabc/plugins/ldap/resourceldapconfig.h
new file mode 100644
index 0000000..42d30ff
--- a/dev/null
+++ b/kabc/plugins/ldap/resourceldapconfig.h
@@ -0,0 +1,100 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef RESOURCELDAPCONFIG_H
29#define RESOURCELDAPCONFIG_H
30
31#include <qmap.h>
32//US
33#include <qdict.h>
34
35#include <kdialogbase.h>
36#include <kresources/configwidget.h>
37
38class QCheckBox;
39class QPushButton;
40class QSpinBox;
41class QString;
42
43class KComboBox;
44class KLineEdit;
45
46namespace KABC {
47
48class ResourceLDAPConfig : public KRES::ConfigWidget
49{
50 Q_OBJECT
51
52 public:
53 ResourceLDAPConfig( QWidget* parent = 0, const char* name = 0 );
54
55 public slots:
56 void loadSettings( KRES::Resource* );
57 void saveSettings( KRES::Resource* );
58
59 private slots:
60 void editAttributes();
61
62 private:
63 KLineEdit *mUser;
64 KLineEdit *mPassword;
65 KLineEdit *mHost;
66 QSpinBox *mPort;
67 KLineEdit *mDn;
68 KLineEdit *mFilter;
69 QCheckBox *mAnonymous;
70 QPushButton *mEditButton;
71 QMap<QString, QString> mAttributes;
72};
73
74class AttributesDialog : public KDialogBase
75{
76 Q_OBJECT
77
78 public:
79 AttributesDialog( const QMap<QString, QString> &attributes, QWidget *parent,
80 const char *name = 0 );
81 ~AttributesDialog();
82
83 QMap<QString, QString> attributes() const;
84
85 private slots:
86 void mapChanged( int pos );
87
88 private:
89 enum { UserMap, KolabMap, NetscapeMap, EvolutionMap, OutlookMap };
90
91 KComboBox *mMapCombo;
92 QValueList< QMap<QString, QString> > mMapList;
93
94 QDict<KLineEdit> mLineEditDict;
95 QDict<QString> mNameDict;
96};
97
98}
99
100#endif
diff --git a/kabc/resource.cpp b/kabc/resource.cpp
new file mode 100644
index 0000000..9a1a5f8
--- a/dev/null
+++ b/kabc/resource.cpp
@@ -0,0 +1,95 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <kdebug.h>
29
30#include "resource.h"
31
32using namespace KABC;
33
34Resource::Resource( const KConfig *config )
35 : KRES::Resource( config ), mAddressBook( 0 )
36{
37}
38
39Resource::~Resource()
40{
41}
42
43void Resource::writeConfig( KConfig *config )
44{
45 KRES::Resource::writeConfig( config );
46}
47
48void Resource::setAddressBook( AddressBook *ab )
49{
50 mAddressBook = ab;
51}
52
53AddressBook *Resource::addressBook()
54{
55 return mAddressBook;
56}
57
58bool Resource::doOpen()
59{
60 return true;
61}
62
63void Resource::doClose()
64{
65}
66
67Ticket *Resource::requestSaveTicket()
68{
69 return 0;
70}
71
72bool Resource::load()
73{
74 return true;
75}
76
77bool Resource::save( Ticket * )
78{
79 return false;
80}
81
82Ticket *Resource::createTicket( Resource *resource )
83{
84 return new Ticket( resource );
85}
86
87void Resource::removeAddressee( const Addressee& )
88{
89 // do nothing
90}
91
92void Resource::cleanUp()
93{
94 // do nothing
95}
diff --git a/kabc/resource.h b/kabc/resource.h
new file mode 100644
index 0000000..c363125
--- a/dev/null
+++ b/kabc/resource.h
@@ -0,0 +1,134 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_RESOURCE_H
29#define KABC_RESOURCE_H
30
31#include <kresources/resource.h>
32
33#include "addressbook.h"
34
35namespace KABC {
36
37/**
38 * @short Helper class for handling coordinated save of address books.
39 *
40 * This class is used as helper class for saving address book.
41 * @see requestSaveTicket(), save().
42 */
43class Ticket
44{
45 friend class Resource;
46 public:
47 Resource *resource() { return mResource; }
48
49 private:
50 Ticket( Resource *resource ) : mResource( resource ) {}
51
52 Resource *mResource;
53};
54
55/**
56 * @internal
57 */
58class Resource : public KRES::Resource
59{
60public:
61 /**
62 * Constructor
63 */
64 Resource( const KConfig *config );
65
66 /**
67 * Destructor.
68 */
69 virtual ~Resource();
70
71 /**
72 * Sets the address book of the resource.
73 */
74 void setAddressBook( AddressBook* );
75
76 /**
77 * Returns a pointer to the addressbook.
78 */
79 AddressBook *addressBook();
80
81 /**
82 * Writes the resource specific config to file.
83 */
84 virtual void writeConfig( KConfig *config );
85
86 /**
87 * Open the resource and returns if it was successfully
88 */
89 virtual bool doOpen();
90
91 /**
92 * Close the resource and returns if it was successfully
93 */
94 virtual void doClose();
95
96 /**
97 * Request a ticket, you have to pass through @ref save() to
98 * allow locking.
99 */
100 virtual Ticket *requestSaveTicket();
101
102 /**
103 * Load all addressees to the addressbook
104 */
105 virtual bool load();
106
107 /**
108 * Save all addressees to the addressbook.
109 *
110 * @param ticket The ticket you get by @ref requestSaveTicket()
111 */
112 virtual bool save( Ticket *ticket );
113
114 /**
115 * Removes a addressee from resource. This method is mainly
116 * used by record-based resources like LDAP or SQL.
117 */
118 virtual void removeAddressee( const Addressee& addr );
119
120 /**
121 * This method is called by an error handler if the application
122 * crashed
123 */
124 virtual void cleanUp();
125
126protected:
127 Ticket *createTicket( Resource * );
128
129private:
130 AddressBook *mAddressBook;
131};
132
133}
134#endif
diff --git a/kabc/secrecy.cpp b/kabc/secrecy.cpp
new file mode 100644
index 0000000..f4bcb51
--- a/dev/null
+++ b/kabc/secrecy.cpp
@@ -0,0 +1,107 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <klocale.h>
29
30#include "secrecy.h"
31
32using namespace KABC;
33
34Secrecy::Secrecy( int type )
35 : mType( type )
36{
37}
38
39bool Secrecy::operator==( const Secrecy &s ) const
40{
41 return ( mType == s.mType );
42}
43
44bool Secrecy::operator!=( const Secrecy &s ) const
45{
46 return !( *this == s );
47}
48
49bool Secrecy::isValid() const
50{
51 return mType != Invalid;
52}
53
54void Secrecy::setType( int type )
55{
56 mType = type;
57}
58
59int Secrecy::type() const
60{
61 return mType;
62}
63
64Secrecy::TypeList Secrecy::typeList()
65{
66 TypeList list;
67 list << Public;
68 list << Private;
69 list << Confidential;
70
71 return list;
72}
73
74QString Secrecy::typeLabel( int type )
75{
76 switch ( type ) {
77 case Public:
78 return i18n( "Public" );
79 break;
80 case Private:
81 return i18n( "Private" );
82 break;
83 case Confidential:
84 return i18n( "Confidential" );
85 break;
86 default:
87 return i18n( "Unknown type" );
88 break;
89 }
90}
91
92QString Secrecy::asString() const
93{
94 return typeLabel( mType );
95}
96
97QDataStream &KABC::operator<<( QDataStream &s, const Secrecy &secrecy )
98{
99 return s << secrecy.mType;
100}
101
102QDataStream &KABC::operator>>( QDataStream &s, Secrecy &secrecy )
103{
104 s >> secrecy.mType;
105
106 return s;
107}
diff --git a/kabc/secrecy.h b/kabc/secrecy.h
new file mode 100644
index 0000000..8f2f736
--- a/dev/null
+++ b/kabc/secrecy.h
@@ -0,0 +1,102 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_SECRECY_H
29#define KABC_SECRECY_H
30
31#include <qvaluelist.h>
32
33namespace KABC {
34
35class Secrecy
36{
37 friend QDataStream &operator<<( QDataStream &, const Secrecy & );
38 friend QDataStream &operator>>( QDataStream &, Secrecy & );
39
40public:
41 typedef QValueList<int> TypeList;
42
43 /**
44 * Secrecy types
45 *
46 * @li Public - for public access
47 * @li Private - only private access
48 * @li Confidential - access for confidential persons
49 */
50 enum Types {
51 Public,
52 Private,
53 Confidential,
54 Invalid
55 };
56
57 /**
58 * Constructor.
59 *
60 * @param type The secrecy type, @see Types.
61 */
62 Secrecy( int type = Invalid );
63
64 bool operator==( const Secrecy & ) const;
65 bool operator!=( const Secrecy & ) const;
66
67 /**
68 Returns if the Secrecy object has a valid value.
69 */
70 bool isValid() const;
71
72 /**
73 * Sets the type, @see Types.
74 */
75 void setType( int type );
76
77 /**
78 * Returns the type, @see Types.
79 */
80 int type() const;
81
82 /**
83 * Returns a list of all available secrecy types.
84 */
85 static TypeList typeList();
86
87 /**
88 * Returns a translated label for a given secrecy type.
89 */
90 static QString typeLabel( int type );
91
92 /**
93 * For debug.
94 */
95 QString asString() const;
96
97private:
98 int mType;
99};
100
101}
102#endif
diff --git a/kabc/sound.cpp b/kabc/sound.cpp
new file mode 100644
index 0000000..b2e5254
--- a/dev/null
+++ b/kabc/sound.cpp
@@ -0,0 +1,117 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk changes
24
25$Id$
26*/
27
28#include "sound.h"
29
30#include <qdatastream.h>
31
32using namespace KABC;
33
34Sound::Sound()
35 : mIntern( false )
36{
37}
38
39Sound::Sound( const QString &url )
40 : mUrl( url ), mIntern( false )
41{
42}
43
44Sound::Sound( const QByteArray &data )
45 : mData( data ), mIntern( true )
46{
47}
48
49Sound::~Sound()
50{
51}
52
53bool Sound::operator==( const Sound &s ) const
54{
55 if ( mIntern != s.mIntern ) return false;
56
57 if ( mIntern ) {
58 if ( mData != s.mData )
59 return false;
60 } else {
61 if ( mUrl != s.mUrl )
62 return false;
63 }
64
65 return true;
66}
67
68bool Sound::operator!=( const Sound &s ) const
69{
70 return !( s == *this );
71}
72
73void Sound::setUrl( const QString &url )
74{
75 mUrl = url;
76 mIntern = false;
77}
78
79void Sound::setData( const QByteArray &data )
80{
81 mData = data;
82 mIntern = true;
83}
84
85bool Sound::isIntern() const
86{
87 return mIntern;
88}
89
90QString Sound::url() const
91{
92 return mUrl;
93}
94
95QByteArray Sound::data() const
96{
97 return mData;
98}
99
100QString Sound::asString() const
101{
102 if ( mIntern )
103 return "intern sound";
104 else
105 return mUrl;
106}
107
108QDataStream &KABC::operator<<( QDataStream &s, const Sound &sound )
109{
110 return s << sound.mIntern << sound.mUrl << sound.mData;
111}
112
113QDataStream &KABC::operator>>( QDataStream &s, Sound &sound )
114{
115 s >> sound.mIntern >> sound.mUrl >> sound.mData;
116 return s;
117}
diff --git a/kabc/sound.h b/kabc/sound.h
new file mode 100644
index 0000000..0ec5ec8
--- a/dev/null
+++ b/kabc/sound.h
@@ -0,0 +1,123 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_SOUND_H
29#define KABC_SOUND_H
30
31#include <qcstring.h>
32#include <qstring.h>
33
34namespace KABC {
35
36class Sound
37{
38 friend QDataStream &operator<<( QDataStream &, const Sound & );
39 friend QDataStream &operator>>( QDataStream &, Sound & );
40
41public:
42
43 /**
44 * Consturctor. Creates an empty object.
45 */
46 Sound();
47
48 /**
49 * Consturctor.
50 *
51 * @param url A URL that describes the position of the sound file.
52 */
53 Sound( const QString &url );
54
55 /**
56 * Consturctor.
57 *
58 * @param data The raw data of the sound.
59 */
60 Sound( const QByteArray &data );
61
62 /**
63 * Destructor.
64 */
65 ~Sound();
66
67
68 bool operator==( const Sound & ) const;
69 bool operator!=( const Sound & ) const;
70
71 /**
72 * Sets a URL for the location of the sound file. When using this
73 * function, @ref isIntern() will return 'false' until you use
74 * @ref setData().
75 *
76 * @param url The location URL of the sound file.
77 */
78 void setUrl( const QString &url );
79
80 /**
81 * Sets the raw data of the sound. When using this function,
82 * @ref isIntern() will return 'true' until you use @ref setUrl().
83 *
84 * @param data The raw data of the sound.
85 */
86 void setData( const QByteArray &data );
87
88 /**
89 * Returns whether the sound is described by a URL (extern) or
90 * by the raw data (intern).
91 * When this method returns 'true' you can use @ref data() to
92 * get the raw data. Otherwise you can request the URL of this
93 * sound by @ref url() and load the raw data from that location.
94 */
95 bool isIntern() const;
96
97 /**
98 * Returns the location URL of this sound.
99 */
100 QString url() const;
101
102 /**
103 * Returns the raw data of this sound.
104 */
105 QByteArray data() const;
106
107 /**
108 * Returns string representation of the sound.
109 */
110 QString asString() const;
111
112private:
113 QString mUrl;
114 QByteArray mData;
115
116 int mIntern;
117};
118
119QDataStream &operator<<( QDataStream &, const Sound & );
120QDataStream &operator>>( QDataStream &, Sound & );
121
122}
123#endif
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
new file mode 100644
index 0000000..f9fc70b
--- a/dev/null
+++ b/kabc/stdaddressbook.cpp
@@ -0,0 +1,249 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27#ifndef DESKTOP_VERSION
28#include <qpe/global.h>
29#else
30
31#include <qdir.h>
32#endif
33#ifdef KAB_EMBEDDED
34
35#include <stdlib.h>
36#else //KAB_EMBEDDED
37
38#include <stdlib.h>
39
40//US#include <kresources/manager.h>
41#include <kapplication.h>
42#include <kcrash.h>
43#include <ksimpleconfig.h>
44
45
46#endif //KAB_EMBEDDED
47
48#include "resource.h"
49#include <kresources/manager.h>
50#include <kdebug.h>
51#include <klocale.h>
52#include <kstaticdeleter.h>
53#include <kstandarddirs.h>
54
55#include "stdaddressbook.h"
56
57using namespace KABC;
58
59StdAddressBook *StdAddressBook::mSelf = 0;
60bool StdAddressBook::mAutomaticSave = true;
61
62static KStaticDeleter<StdAddressBook> addressBookDeleter;
63
64QString StdAddressBook::fileName()
65{
66 return locateLocal( "data", "kabc/std.vcf" );
67}
68
69QString StdAddressBook::directoryName()
70{
71 qDebug("StdAddressBook::directoryName() WILL FAIL OR NOT" );
72 return locateLocal( "data", "kabc/stdvcf" );
73}
74
75void StdAddressBook::handleCrash()
76{
77 StdAddressBook::self()->cleanUp();
78}
79
80StdAddressBook *StdAddressBook::self()
81{
82
83 if ( !mSelf )
84 {
85 QString appdir = StdAddressBook::setTempAppDir();
86
87 kdDebug(5700) << "StdAddressBook::self()" << endl;
88// US im am not sure why I have to use the other format here??
89#ifdef KAB_EMBEDDED
90 mSelf = addressBookDeleter.setObject( new StdAddressBook );
91#else //KAB_EMBEDDED
92 addressBookDeleter.setObject( mSelf, new StdAddressBook );
93#endif //KAB_EMBEDDED
94 KStandardDirs::setAppDir( appdir );
95 }
96
97 return mSelf;
98}
99
100QString StdAddressBook::setTempAppDir()
101{
102 QString appDIR = KStandardDirs::appDir();
103#ifdef DESKTOP_VERSION
104 QString appdir = QDir::homeDirPath();
105 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" )
106 appdir += "kaddressbook/";
107 else
108 appdir += "/kaddressbook/";
109 KStandardDirs::setAppDir( QDir::convertSeparators( appdir ));
110#else
111 KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) );
112#endif
113
114 return appDIR;
115}
116StdAddressBook *StdAddressBook::self( bool onlyFastResources )
117{
118
119 if ( !mSelf )
120 {
121 QString appdir =StdAddressBook::setTempAppDir();
122#ifdef KAB_EMBEDDED
123 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) );
124#else //KAB_EMBEDDED
125 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) );
126#endif //KAB_EMBEDDED
127 KStandardDirs::setAppDir( appdir );
128 }
129 return mSelf;
130}
131
132StdAddressBook::StdAddressBook()
133//US : AddressBook( "kabcrc" )
134 : AddressBook( locateLocal( "config", "kabcrc") )
135{
136
137 init( false );
138}
139
140StdAddressBook::StdAddressBook( bool onlyFastResources )
141//US : AddressBook( "kabcrc" )
142 : AddressBook( locateLocal( "config", "kabcrc") )
143{
144
145 init( onlyFastResources );
146}
147
148StdAddressBook::~StdAddressBook()
149{
150 if ( mAutomaticSave )
151 save();
152}
153
154void StdAddressBook::init( bool )
155{
156 KRES::Manager<Resource> *manager = resourceManager();
157 KRES::Manager<Resource>::ActiveIterator it;
158
159 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
160 (*it)->setAddressBook( this );
161 if ( !(*it)->open() )
162 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
163 }
164
165 Resource *res = standardResource();
166 if ( !res ) {
167 res = manager->createResource( "file" );
168 if ( res )
169 {
170 addResource( res );
171 }
172 else
173 kdDebug(5700) << "No resource available!!!" << endl;
174 }
175
176 setStandardResource( res );
177 manager->writeConfig();
178
179 load();
180}
181
182bool StdAddressBook::save()
183{
184 kdDebug(5700) << "StdAddressBook::save()" << endl;
185
186 bool ok = true;
187 AddressBook *ab = self();
188
189 ab->deleteRemovedAddressees();
190
191 KRES::Manager<Resource>::ActiveIterator it;
192 KRES::Manager<Resource> *manager = ab->resourceManager();
193 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
194 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
195 Ticket *ticket = ab->requestSaveTicket( *it );
196// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
197 if ( !ticket ) {
198 ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
199 .arg( (*it)->resourceName() ) );
200 return false;
201 }
202
203 if ( !ab->save( ticket ) )
204 ok = false;
205 }
206 }
207
208 return ok;
209}
210
211void StdAddressBook::close()
212{
213//US destructObject is not defined on my system???. Is setObject(0) the same ???
214#ifndef KAB_EMBEDDED
215 addressBookDeleter.destructObject();
216#else //KAB_EMBEDDED
217 addressBookDeleter.setObject(0);
218#endif //KAB_EMBEDDED
219
220}
221
222void StdAddressBook::setAutomaticSave( bool enable )
223{
224 mAutomaticSave = enable;
225}
226
227bool StdAddressBook::automaticSave()
228{
229 return mAutomaticSave;
230}
231
232// should get const for 4.X
233Addressee StdAddressBook::whoAmI()
234{
235//US KConfig config( "kabcrc" );
236 KConfig config( locateLocal("config", "kabcrc") );
237 config.setGroup( "General" );
238
239 return findByUid( config.readEntry( "WhoAmI" ) );
240}
241
242void StdAddressBook::setWhoAmI( const Addressee &addr )
243{
244//US KConfig config( "kabcrc" );
245 KConfig config( locateLocal("config", "kabcrc") );
246 config.setGroup( "General" );
247
248 config.writeEntry( "WhoAmI", addr.uid() );
249}
diff --git a/kabc/stdaddressbook.h b/kabc/stdaddressbook.h
new file mode 100644
index 0000000..9ec53b0
--- a/dev/null
+++ b/kabc/stdaddressbook.h
@@ -0,0 +1,151 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_STDADDRESSBOOK_H
29#define KABC_STDADDRESSBOOK_H
30
31#include "addressbook.h"
32
33namespace KABC {
34
35/**
36 Standard KDE address book
37
38 This class provides access to the standard KDE address book shared by all
39 applications.
40
41 It's implemented as a singleton. Use @ref self() to get the address book
42 object. On the first self() call the address book also gets loaded.
43
44 Example:
45
46 <pre>
47 KABC::AddressBook *ab = KABC::StdAddressBook::self();
48
49 KABC::AddressBook::Iterator it;
50 for ( it = ab->begin(); it != ab->end(); ++it ) {
51 kdDebug() << "UID=" << (*it).uid() << endl;
52
53 // do some other stuff
54 }
55
56 KABC::StdAddressBook::save();
57 </pre>
58*/
59class StdAddressBook : public AddressBook
60{
61 public:
62
63 /**
64 Destructor.
65 */
66 ~StdAddressBook();
67
68 /**
69 Return the standard addressbook object. It also loads slow resources.
70 It is the same as self(false); .
71 */
72 static StdAddressBook *self();
73
74 /**
75 This is the same as above, but with specified
76 behaviour of resource loading.
77
78 @param onlyFastResource Only resources marked as 'fast' should be loaded
79 */
80 // FIXME for KDE4 return StdAddressBook and merge with the metod above -zecke
81 static StdAddressBook *self( bool onlyFastResources );
82
83 /**
84 Save the standard address book to disk.
85 */
86 static bool save();
87
88 /**
89 Call this method in your crash handler to allow the library clean up
90 possible locks.
91 */
92 static void handleCrash();
93
94 /**
95 Returns the default file name for vcard-based addressbook
96 */
97 static QString fileName();
98
99 /**
100 Returns the default directory name for vcard-based addressbook
101 */
102 static QString directoryName();
103
104 /**
105 Set the automatic save property of the address book.
106 If @p enable is TRUE (default) the address book is saved at
107 destruction time otherwise you have to call @ref save() to
108 explicitely save it.
109 */
110 static void setAutomaticSave( bool enable );
111
112 /**
113 Closes the address book. Depending on @ref automaticSave() it will
114 save the address book first.
115 */
116 static void close();
117
118 /**
119 Returns whether the address book is saved at destruction time.
120 See also @ref setAutomaticSave().
121 */
122 static bool automaticSave();
123
124 /**
125 Returns the contact, that is associated with the owner of the
126 address book. This contact should be used by other programs
127 to access user specific data.
128 */
129 Addressee whoAmI();
130
131 /**
132 Sets the users contact. See @ref whoAmI() for more information.
133
134 @param uid The uid of the users contact.
135 */
136 void setWhoAmI( const Addressee &addr );
137
138 protected:
139 StdAddressBook();
140 StdAddressBook( bool onlyFastResources );
141
142 void init( bool onlyFastResources );
143
144 private:
145 static QString setTempAppDir();
146 static StdAddressBook *mSelf;
147 static bool mAutomaticSave;
148};
149
150}
151#endif
diff --git a/kabc/timezone.cpp b/kabc/timezone.cpp
new file mode 100644
index 0000000..2018395
--- a/dev/null
+++ b/kabc/timezone.cpp
@@ -0,0 +1,92 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qdatastream.h>
29
30#include "timezone.h"
31
32using namespace KABC;
33
34TimeZone::TimeZone() :
35 mOffset( 0 ), mValid( false )
36{
37}
38
39TimeZone::TimeZone( int offset ) :
40 mOffset( offset ), mValid( true )
41{
42}
43
44void TimeZone::setOffset( int offset )
45{
46 mOffset = offset;
47 mValid = true;
48}
49
50int TimeZone::offset() const
51{
52 return mOffset;
53}
54
55bool TimeZone::isValid() const
56{
57 return mValid;
58}
59
60bool TimeZone::operator==( const TimeZone &t ) const
61{
62 if ( !t.isValid() && !isValid() ) return true;
63 if ( !t.isValid() || !isValid() ) return false;
64 if ( t.mOffset == mOffset ) return true;
65 return false;
66}
67
68bool TimeZone::operator!=( const TimeZone &t ) const
69{
70 if ( !t.isValid() && !isValid() ) return false;
71 if ( !t.isValid() || !isValid() ) return true;
72 if ( t.mOffset != mOffset ) return true;
73 return false;
74}
75
76QString TimeZone::asString() const
77{
78 return QString::number( mOffset );
79}
80
81QDataStream &KABC::operator<<( QDataStream &s, const TimeZone &zone )
82{
83 return s << zone.mOffset;
84}
85
86QDataStream &KABC::operator>>( QDataStream &s, TimeZone &zone )
87{
88 s >> zone.mOffset;
89 zone.mValid = true;
90
91 return s;
92}
diff --git a/kabc/timezone.h b/kabc/timezone.h
new file mode 100644
index 0000000..8d96e03
--- a/dev/null
+++ b/kabc/timezone.h
@@ -0,0 +1,94 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_TIMEZONE_H
29#define KABC_TIMEZONE_H
30
31#include <qstring.h>
32
33namespace KABC {
34
35/**
36 * @short Time zone information.
37 *
38 * This class stores information about a time zone.
39 */
40class TimeZone
41{
42 friend QDataStream &operator<<( QDataStream &, const TimeZone & );
43 friend QDataStream &operator>>( QDataStream &, TimeZone & );
44
45public:
46
47 /**
48 * Construct invalid time zone.
49 */
50 TimeZone();
51
52 /**
53 * Construct time zone.
54 *
55 * @param offset Offset in minutes relative to UTC.
56 */
57 TimeZone( int offset );
58
59 /**
60 * Set time zone offset relative to UTC.
61 *
62 * @param offset Offset in minutes.
63 */
64 void setOffset( int );
65
66 /**
67 * Return offset in minutes relative to UTC.
68 */
69 int offset() const;
70
71 /**
72 * Return, if this time zone object is valid.
73 */
74 bool isValid() const;
75
76 bool operator==( const TimeZone & ) const;
77 bool operator!=( const TimeZone & ) const;
78
79 /**
80 * Return string representation of time zone offset.
81 */
82 QString asString() const;
83
84private:
85 int mOffset; // Offset in minutes
86
87 bool mValid;
88};
89
90QDataStream &operator<<( QDataStream &, const TimeZone & );
91QDataStream &operator>>( QDataStream &, TimeZone & );
92
93}
94#endif
diff --git a/kabc/vcard/AdrParam.cpp b/kabc/vcard/AdrParam.cpp
new file mode 100644
index 0000000..fa46499
--- a/dev/null
+++ b/kabc/vcard/AdrParam.cpp
@@ -0,0 +1,126 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardRToken.h>
25#include <VCardAdrParam.h>
26#include <VCardParam.h>
27
28using namespace VCARD;
29
30AdrParam::AdrParam()
31 :Param()
32{
33}
34
35AdrParam::AdrParam(const AdrParam & x)
36 :Param(x),
37 adrTypeList_(x.adrTypeList_)
38{
39}
40
41AdrParam::AdrParam(const QCString & s)
42 :Param(s)
43{
44}
45
46 AdrParam &
47AdrParam::operator = (AdrParam & x)
48{
49 if (*this == x) return *this;
50
51 adrTypeList_= x.adrTypeList();
52 textParam_ = x.textParam();
53
54 Param::operator = (x);
55 return *this;
56}
57
58 AdrParam &
59AdrParam::operator = (const QCString & s)
60{
61 Param::operator = (s);
62
63 adrTypeList_.clear();
64 textParam_.truncate(0);
65
66 return *this;
67}
68
69 bool
70AdrParam::operator == (AdrParam & x)
71{
72 parse();
73
74 if (!x.textParam().isEmpty())
75 return (x.textParam_ == textParam_);
76
77 if (x.adrTypeList().count() != adrTypeList_.count())
78 return false;
79
80 QStrListIterator it(x.adrTypeList_);
81
82 for (; it.current(); ++it)
83 if (!adrTypeList_.find(it.current()))
84 return false;
85
86 return true;
87}
88
89AdrParam::~AdrParam()
90{
91}
92
93 void
94AdrParam::_parse()
95{
96 adrTypeList_.clear();
97
98 if (strRep_.left(4) != "TYPE") {
99 textParam_ = strRep_;
100 return;
101 }
102
103 if (!strRep_.contains('='))
104 return;
105
106 RTokenise(strRep_, ",", adrTypeList_);
107}
108
109 void
110AdrParam::_assemble()
111{
112 if (!textParam_.isEmpty()) {
113 strRep_ = textParam_;
114 return;
115 }
116
117 QStrListIterator it(adrTypeList_);
118
119 for (; it.current(); ++it) {
120
121 strRep_ += it.current();
122
123 if (it.current() != adrTypeList_.last())
124 strRep_ += ',';
125 }
126}
diff --git a/kabc/vcard/AdrValue.cpp b/kabc/vcard/AdrValue.cpp
new file mode 100644
index 0000000..7ecef33
--- a/dev/null
+++ b/kabc/vcard/AdrValue.cpp
@@ -0,0 +1,140 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardRToken.h>
25#include <VCardAdrValue.h>
26#include <VCardValue.h>
27#include <VCardDefines.h>
28
29using namespace VCARD;
30
31AdrValue::AdrValue()
32 :Value()
33{
34}
35
36AdrValue::AdrValue(const AdrValue & x)
37 :Value(x),
38 poBox_ (x.poBox_),
39 extAddress_(x.extAddress_),
40 street_ (x.street_),
41 locality_(x.locality_),
42 region_ (x.region_),
43 postCode_(x.postCode_),
44 countryName_(x.countryName_)
45{
46}
47
48AdrValue::AdrValue(const QCString & s)
49 :Value(s)
50{
51}
52
53 AdrValue &
54AdrValue::operator = (AdrValue & x)
55{
56 if (*this == x) return *this;
57
58 poBox_ = x.poBox_;
59 extAddress_= x.extAddress_;
60 street_ = x.street_;
61 locality_= x.locality_;
62 region_ = x.region_;
63 postCode_= x.postCode_;
64 countryName_= x.countryName_;
65
66 Value::operator = (x);
67 return *this;
68}
69
70 AdrValue &
71AdrValue::operator = (const QCString & s)
72{
73 Value::operator = (s);
74 return *this;
75}
76
77 bool
78AdrValue::operator == (AdrValue & x)
79{
80 parse();
81 x.parse();
82
83 return (
84 poBox_ == x.poBox_ &&
85 extAddress_ == x.extAddress_&&
86 street_ == x.street_ &&
87 locality_ == x.locality_ &&
88 region_ == x.region_ &&
89 postCode_ == x.postCode_ &&
90 countryName_== x.countryName_);
91}
92
93AdrValue::~AdrValue()
94{
95}
96
97 AdrValue *
98AdrValue::clone()
99{
100 return new AdrValue( *this );
101}
102
103 void
104AdrValue::_parse()
105{
106 vDebug("AdrValue::_parse()");
107
108 QStrList l;
109 RTokenise(strRep_, ";", l);
110
111 for (unsigned int i = 0; i < l.count(); i++) {
112
113 switch (i) {
114
115 case 0: poBox_ = l.at(0);break;
116 case 1: extAddress_ = l.at(1);break;
117 case 2: street_ = l.at(2);break;
118 case 3: locality_ = l.at(3);break;
119 case 4: region_ = l.at(4);break;
120 case 5: postCode_ = l.at(5);break;
121 case 6: countryName_ = l.at(6);break;
122 default: break;
123 }
124 }
125}
126
127 void
128AdrValue::_assemble()
129{
130 vDebug("AdrValue::_assemble");
131
132 strRep_ = poBox_;
133 strRep_ += ";" +extAddress_;
134 strRep_ += ";" +street_;
135 strRep_ += ";" +locality_;
136 strRep_ += ";" +region_;
137 strRep_ += ";" +postCode_;
138 strRep_ += ";" +countryName_;
139}
140
diff --git a/kabc/vcard/AgentParam.cpp b/kabc/vcard/AgentParam.cpp
new file mode 100644
index 0000000..5625e00
--- a/dev/null
+++ b/kabc/vcard/AgentParam.cpp
@@ -0,0 +1,103 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardAgentParam.h>
25
26#include <VCardParam.h>
27
28using namespace VCARD;
29
30AgentParam::AgentParam()
31 :Param()
32{
33}
34
35AgentParam::AgentParam(const AgentParam & x)
36 :Param(x),
37 refer_(x.refer_),
38 uri_(x.uri_)
39{
40}
41
42AgentParam::AgentParam(const QCString & s)
43 :Param(s)
44{
45}
46
47 AgentParam &
48AgentParam::operator = (AgentParam & x)
49{
50 if (*this == x) return *this;
51
52 refer_= x.refer_;
53 uri_= x.uri_;
54
55 Param::operator = (x);
56 return *this;
57}
58
59 AgentParam &
60AgentParam::operator = (const QCString & s)
61{
62 Param::operator = (s);
63 return *this;
64}
65
66 bool
67AgentParam::operator == (AgentParam & x)
68{
69 parse();
70
71 if (refer_)
72 return (x.refer() && uri_ == x.uri_);
73
74 return !x.refer();
75}
76
77AgentParam::~AgentParam()
78{
79}
80
81 void
82AgentParam::_parse()
83{
84 if (strRep_.isEmpty()) {
85 refer_ = false;
86 return;
87 }
88
89 refer_= true;
90 uri_= strRep_;
91}
92
93 void
94AgentParam::_assemble()
95{
96 if (!refer_) {
97 strRep_.truncate(0);
98 return;
99 }
100
101 strRep_ = uri_.asString();
102 return;
103}
diff --git a/kabc/vcard/AgentValue.cpp b/kabc/vcard/AgentValue.cpp
new file mode 100644
index 0000000..bccde80
--- a/dev/null
+++ b/kabc/vcard/AgentValue.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardAgentValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30AgentValue::AgentValue()
31 :Value()
32{
33}
34
35AgentValue::AgentValue(const AgentValue & x)
36 :Value(x)
37{
38}
39
40AgentValue::AgentValue(const QCString & s)
41 :Value(s)
42{
43}
44
45 AgentValue &
46AgentValue::operator = (AgentValue & x)
47{
48 if (*this == x) return *this;
49
50 Value::operator = (x);
51 return *this;
52}
53
54 AgentValue &
55AgentValue::operator = (const QCString & s)
56{
57 Value::operator = (s);
58 return *this;
59}
60
61 bool
62AgentValue::operator == (AgentValue & x)
63{
64 x.parse();
65 return false;
66}
67
68AgentValue::~AgentValue()
69{
70}
71
72 void
73AgentValue::_parse()
74{
75}
76
77 void
78AgentValue::_assemble()
79{
80}
81
diff --git a/kabc/vcard/ClassValue.cpp b/kabc/vcard/ClassValue.cpp
new file mode 100644
index 0000000..f01e5a6
--- a/dev/null
+++ b/kabc/vcard/ClassValue.cpp
@@ -0,0 +1,120 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardClassValue.h>
25
26#include <VCardValue.h>
27
28#include <kdebug.h>
29
30using namespace VCARD;
31
32ClassValue::ClassValue()
33 :Value()
34{
35}
36
37ClassValue::ClassValue(const ClassValue & x)
38 :Value(x),
39 classType_(x.classType_)
40{
41}
42
43ClassValue::ClassValue(const QCString & s)
44 :Value(s)
45{
46}
47
48 ClassValue &
49ClassValue::operator = (ClassValue & x)
50{
51 if (*this == x) return *this;
52 x.parse();
53
54 classType_ = x.classType_;
55
56 Value::operator = (x);
57 return *this;
58}
59
60 ClassValue &
61ClassValue::operator = (const QCString & s)
62{
63 Value::operator = (s);
64 return *this;
65}
66
67 bool
68ClassValue::operator == (ClassValue & x)
69{
70 x.parse();
71 return ( classType_ == x.classType_ );
72}
73
74ClassValue::~ClassValue()
75{
76}
77
78 ClassValue *
79ClassValue::clone()
80{
81 return new ClassValue( *this );
82}
83
84 void
85ClassValue::_parse()
86{
87 if (qstricmp(strRep_, "PUBLIC") == 0)
88 classType_ = Public;
89
90 else if (qstricmp(strRep_, "PRIVATE") == 0)
91 classType_ = Private;
92
93 else if (qstricmp(strRep_, "CONFIDENTIAL") == 0)
94 classType_ = Confidential;
95
96 else classType_ = Other;
97}
98
99 void
100ClassValue::_assemble()
101{
102 switch (classType_) {
103
104 case Public:
105 strRep_ = "PUBLIC";
106 break;
107
108 case Private:
109 strRep_ = "PRIVATE";
110 break;
111
112 case Confidential:
113 strRep_ = "CONFIDENTIAL";
114 break;
115
116 default:
117 break;
118 }
119}
120
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp
new file mode 100644
index 0000000..6fa1a8f
--- a/dev/null
+++ b/kabc/vcard/ContentLine.cpp
@@ -0,0 +1,289 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <qcstring.h>
25#include <qstrlist.h>
26#include <qregexp.h>
27
28#include <kdebug.h>
29
30#include <VCardAdrParam.h>
31#include <VCardAgentParam.h>
32#include <VCardDateParam.h>
33#include <VCardEmailParam.h>
34#include <VCardImageParam.h>
35#include <VCardSourceParam.h>
36#include <VCardTelParam.h>
37#include <VCardTextBinParam.h>
38#include <VCardTextParam.h>
39
40#include <VCardAdrValue.h>
41#include <VCardAgentValue.h>
42#include <VCardDateValue.h>
43#include <VCardImageValue.h>
44#include <VCardTextValue.h>
45#include <VCardTextBinValue.h>
46#include <VCardLangValue.h>
47#include <VCardNValue.h>
48#include <VCardURIValue.h>
49#include <VCardSoundValue.h>
50#include <VCardClassValue.h>
51#include <VCardFloatValue.h>
52#include <VCardOrgValue.h>
53#include <VCardTelValue.h>
54#include <VCardTextListValue.h>
55#include <VCardUTCValue.h>
56#include <VCardGeoValue.h>
57
58#include <VCardRToken.h>
59#include <VCardContentLine.h>
60
61#include <VCardEntity.h>
62#include <VCardEnum.h>
63#include <VCardDefines.h>
64
65using namespace VCARD;
66
67ContentLine::ContentLine()
68 :Entity(),
69 value_(0)
70{
71}
72
73ContentLine::ContentLine(const ContentLine & x)
74 :Entity(x),
75 group_ (x.group_),
76 name_ (x.name_),
77 paramList_(x.paramList_),
78 value_(x.value_->clone())
79{
80}
81
82ContentLine::ContentLine(const QCString & s)
83 :Entity(s),
84 value_(0)
85{
86}
87
88 ContentLine &
89ContentLine::operator = (ContentLine & x)
90{
91 if (*this == x) return *this;
92
93 paramList_ = x.paramList();
94 value_ = x.value_->clone();
95
96 Entity::operator = (x);
97 return *this;
98}
99
100 ContentLine &
101ContentLine::operator = (const QCString & s)
102{
103 Entity::operator = (s);
104 delete value_;
105 value_ = 0;
106 return *this;
107}
108
109 bool
110ContentLine::operator == (ContentLine & x)
111{
112 x.parse();
113
114 QPtrListIterator<Param> it(x.paramList());
115
116 if (!paramList_.find(it.current()))
117 return false;
118
119 return true;
120}
121
122ContentLine::~ContentLine()
123{
124 delete value_;
125 value_ = 0;
126}
127
128 void
129ContentLine::_parse()
130{
131 vDebug("parse");
132
133 // Unqote newlines
134 strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" );
135
136 int split = strRep_.find(':');
137
138 if (split == -1) { // invalid content line
139 vDebug("No ':'");
140 return;
141 }
142
143 QCString firstPart(strRep_.left(split));
144 QCString valuePart(strRep_.mid(split + 1));
145
146 split = firstPart.find('.');
147
148 if (split != -1) {
149 group_ = firstPart.left(split);
150 firstPart= firstPart.mid(split + 1);
151 }
152
153 vDebug("Group == " + group_);
154 vDebug("firstPart == " + firstPart);
155 vDebug("valuePart == " + valuePart);
156
157 // Now we have the group, the name and param list together and the value.
158
159 QStrList l;
160
161 RTokenise(firstPart, ";", l);
162
163 if (l.count() == 0) {// invalid - no name !
164 vDebug("No name for this content line !");
165 return;
166 }
167
168 name_ = l.at(0);
169
170 // Now we have the name, so the rest of 'l' is the params.
171 // Remove the name part.
172 l.remove(0u);
173
174 entityType_= EntityNameToEntityType(name_);
175 paramType_= EntityTypeToParamType(entityType_);
176
177 unsigned int i = 0;
178
179 // For each parameter, create a new parameter of the correct type.
180
181 QStrListIterator it(l);
182
183 for (; it.current(); ++it, i++) {
184
185 QCString str = *it;
186
187 split = str.find("=");
188 if (split < 0 ) {
189 vDebug("No '=' in paramter.");
190 continue;
191 }
192
193 QCString paraName = str.left(split);
194 QCString paraValue = str.mid(split + 1);
195
196 QStrList paraValues;
197 RTokenise(paraValue, ",", paraValues);
198
199 QStrListIterator it2( paraValues );
200
201 for(; it2.current(); ++it2) {
202
203 Param *p = new Param;
204 p->setName( paraName );
205 p->setValue( *it2 );
206
207 paramList_.append(p);
208 }
209 }
210
211 // Create a new value of the correct type.
212
213 valueType_ = EntityTypeToValueType(entityType_);
214
215 //kdDebug(5710) << "valueType: " << valueType_ << endl;
216
217 switch (valueType_) {
218
219 case ValueSound: value_ = new SoundValue;break;
220 case ValueAgent: value_ = new AgentValue;break;
221 case ValueAddress: value_ = new AdrValue; break;
222 case ValueTel: value_ = new TelValue; break;
223 case ValueTextBin: value_ = new TextBinValue;break;
224 case ValueOrg: value_ = new OrgValue; break;
225 case ValueN: value_ = new NValue; break;
226 case ValueUTC: value_ = new UTCValue; break;
227 case ValueURI: value_ = new URIValue; break;
228 case ValueClass: value_ = new ClassValue;break;
229 case ValueFloat: value_ = new FloatValue;break;
230 case ValueImage: value_ = new ImageValue;break;
231 case ValueDate: value_ = new DateValue; break;
232 case ValueTextList: value_ = new TextListValue;break;
233 case ValueGeo: value_ = new GeoValue; break;
234 case ValueText:
235 case ValueUnknown:
236 default: value_ = new TextValue; break;
237 }
238
239 *value_ = valuePart;
240}
241
242 void
243ContentLine::_assemble()
244{
245 vDebug("Assemble (argl) - my name is \"" + name_ + "\"");
246 strRep_.truncate(0);
247
248 QCString line;
249
250 if (!group_.isEmpty())
251 line += group_ + '.';
252
253 line += name_;
254
255 vDebug("Adding parameters");
256 ParamListIterator it(paramList_);
257
258 for (; it.current(); ++it)
259 line += ";" + it.current()->asString();
260
261 vDebug("Adding value");
262 if (value_ != 0)
263 line += ":" + value_->asString();
264 else
265 vDebug("No value");
266
267 // Quote newlines
268 line = line.replace( QRegExp( "\n" ), "\\n" );
269
270 // Fold lines longer than 72 chars
271 const int maxLen = 72;
272 uint cursor = 0;
273 while( line.length() > ( cursor + 1 ) * maxLen ) {
274 strRep_ += line.mid( cursor * maxLen, maxLen );
275 strRep_ += "\r\n ";
276 ++cursor;
277 }
278 strRep_ += line.mid( cursor * maxLen );
279}
280
281 void
282ContentLine::clear()
283{
284 group_.truncate(0);
285 name_.truncate(0);
286 paramList_.clear();
287 delete value_;
288 value_ = 0;
289}
diff --git a/kabc/vcard/DateParam.cpp b/kabc/vcard/DateParam.cpp
new file mode 100644
index 0000000..52af089
--- a/dev/null
+++ b/kabc/vcard/DateParam.cpp
@@ -0,0 +1,82 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardDateParam.h>
25
26#include <VCardParam.h>
27
28using namespace VCARD;
29
30DateParam::DateParam()
31 :Param()
32{
33}
34
35DateParam::DateParam(const DateParam & x)
36 :Param(x)
37{
38}
39
40DateParam::DateParam(const QCString & s)
41 :Param(s)
42{
43}
44
45 DateParam &
46DateParam::operator = (DateParam & x)
47{
48 if (*this == x) return *this;
49
50 Param::operator = (x);
51 return *this;
52}
53
54 DateParam &
55DateParam::operator = (const QCString & s)
56{
57 Param::operator = (s);
58 return *this;
59}
60
61 bool
62DateParam::operator == (DateParam & x)
63{
64 x.parse();
65
66 return false;
67}
68
69DateParam::~DateParam()
70{
71}
72
73 void
74DateParam::_parse()
75{
76}
77
78 void
79DateParam::_assemble()
80{
81}
82
diff --git a/kabc/vcard/DateValue.cpp b/kabc/vcard/DateValue.cpp
new file mode 100644
index 0000000..c5c5c85
--- a/dev/null
+++ b/kabc/vcard/DateValue.cpp
@@ -0,0 +1,434 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <qregexp.h>
25
26#include <kdebug.h>
27
28#include <VCardDefines.h>
29#include <VCardDateValue.h>
30#include <VCardValue.h>
31
32using namespace VCARD;
33
34DateValue::DateValue()
35 :Value()
36{
37 vDebug("DateValue::DateValue()");
38}
39
40DateValue::DateValue(
41 unsigned intyear,
42 unsigned intmonth,
43 unsigned intday,
44 unsigned inthour,
45 unsigned intminute,
46 unsigned intsecond,
47 double secFrac,
48 bool zonePositive,
49 unsigned intzoneHour,
50 unsigned intzoneMinute)
51 : Value (),
52 year_ (year),
53 month_ (month),
54 day_ (day),
55 hour_ (hour),
56 minute_ (minute),
57 second_ (second),
58 zoneHour_ (zoneHour),
59 zoneMinute_ (zoneMinute),
60 secFrac_ (secFrac),
61 zonePositive_(zonePositive),
62 hasTime_(true)
63{
64 parsed_ = true;
65 assembled_ = false;
66}
67
68DateValue::DateValue(const QDate & d)
69 : Value (),
70 year_ (d.year()),
71 month_ (d.month()),
72 day_ (d.day()),
73 hasTime_(false)
74{
75 parsed_ = true;
76 assembled_ = false;
77}
78
79DateValue::DateValue(const QDateTime & d)
80 : Value (),
81 year_ (d.date().year()),
82 month_ (d.date().month()),
83 day_ (d.date().day()),
84 hour_ (d.time().hour()),
85 minute_ (d.time().minute()),
86 second_ (d.time().second()),
87 hasTime_(true)
88{
89 parsed_ = true;
90 assembled_ = false;
91}
92
93DateValue::DateValue(const DateValue & x)
94 :Value(x)
95{
96 year_ = x.year_;
97 month_ = x.month_;
98 day_ = x.day_;
99 hour_ = x.hour_;
100 minute_ = x.minute_;
101 second_ = x.second_;
102 zoneHour_ = x.zoneHour_;
103 zoneMinute_ = x.zoneMinute_;
104 secFrac_ = x.secFrac_;
105 hasTime_ = x.hasTime_;
106}
107
108DateValue::DateValue(const QCString & s)
109 :Value(s)
110{
111}
112
113 DateValue &
114DateValue::operator = (DateValue & x)
115{
116 if (*this == x) return *this;
117
118 Value::operator = (x);
119 return *this;
120}
121
122 DateValue &
123DateValue::operator = (const QCString & s)
124{
125 Value::operator = (s);
126 return *this;
127}
128
129 bool
130DateValue::operator == (DateValue & x)
131{
132 x.parse();
133 return false;
134}
135
136DateValue::~DateValue()
137{
138}
139
140 DateValue *
141DateValue::clone()
142{
143 return new DateValue( *this );
144}
145
146 void
147DateValue::_parse()
148{
149 vDebug("DateValue::_parse()");
150
151 // date = date-full-year ["-"] date-month ["-"] date-mday
152 // time = time-hour [":"] time-minute [":"] time-second [":"]
153 // [time-secfrac] [time-zone]
154
155 int timeSep = strRep_.find('T');
156
157 QCString dateStr;
158 QCString timeStr;
159
160 if (timeSep == -1) {
161
162 dateStr = strRep_;
163 vDebug("Has date string \"" + dateStr + "\"");
164
165 } else {
166
167 dateStr = strRep_.left(timeSep);
168 vDebug("Has date string \"" + dateStr + "\"");
169
170 timeStr = strRep_.mid(timeSep + 1);
171 vDebug("Has time string \"" + timeStr + "\"");
172 }
173
174 /////////////////////////////////////////////////////////////// DATE
175
176 dateStr.replace(QRegExp("-"), "");
177
178 kdDebug(5710) << "dateStr: " << dateStr << endl;
179
180 year_= dateStr.left(4).toInt();
181 month_= dateStr.mid(4, 2).toInt();
182 day_= dateStr.right(2).toInt();
183
184 if (timeSep == -1) {
185 hasTime_ = false;
186 return; // No time, done.
187 }
188 else
189 hasTime_ = true;
190
191 /////////////////////////////////////////////////////////////// TIME
192
193 /////////////////////////////////////////////////////////////// ZONE
194
195 int zoneSep = timeStr.find('Z');
196
197 if (zoneSep != -1 && timeStr.length() - zoneSep > 3) {
198
199 QCString zoneStr(timeStr.mid(zoneSep + 1));
200 vDebug("zoneStr == " + zoneStr);
201
202 zonePositive_= (zoneStr[0] == '+');
203 zoneHour_ = zoneStr.mid(1, 2).toInt();
204 zoneMinute_ = zoneStr.right(2).toInt();
205
206 timeStr.remove(zoneSep, timeStr.length() - zoneSep);
207 }
208
209 //////////////////////////////////////////////////// SECOND FRACTION
210
211 int secFracSep = timeStr.findRev(',');
212
213 if (secFracSep != -1 && zoneSep != -1) { // zoneSep checked to avoid errors.
214 QCString quirkafleeg = "0." + timeStr.mid(secFracSep + 1, zoneSep);
215 secFrac_ = quirkafleeg.toDouble();
216 }
217
218 /////////////////////////////////////////////////////////////// HMS
219
220 timeStr.replace(QRegExp(":"), "");
221
222 hour_= timeStr.left(2).toInt();
223 minute_= timeStr.mid(2, 2).toInt();
224 second_= timeStr.mid(4, 2).toInt();
225}
226
227 void
228DateValue::_assemble()
229{
230 vDebug("DateValue::_assemble");
231
232 QCString year;
233 QCString month;
234 QCString day;
235
236 year.setNum( year_ );
237 month.setNum( month_ );
238 day.setNum( day_ );
239
240 if ( month.length() < 2 ) month.prepend( "0" );
241 if ( day.length() < 2 ) day.prepend( "0" );
242
243 strRep_ = year + '-' + month + '-' + day;
244
245 if ( hasTime_ ) {
246 QCString hour;
247 QCString minute;
248 QCString second;
249
250 hour.setNum( hour_ );
251 minute.setNum( minute_ );
252 second.setNum( second_ );
253
254 if ( hour.length() < 2 ) hour.prepend( "0" );
255 if ( minute.length() < 2 ) minute.prepend( "0" );
256 if ( second.length() < 2 ) second.prepend( "0" );
257
258 strRep_ += 'T' + hour + ':' + minute + ':' + second + 'Z';
259 }
260}
261
262 unsigned int
263DateValue::year()
264{
265 parse();
266 return year_;
267}
268
269 unsigned int
270DateValue::month()
271{
272 parse();
273 return month_;
274}
275
276 unsigned int
277DateValue::day()
278{
279 parse();
280 return day_;
281}
282 unsigned int
283DateValue::hour()
284{
285 parse();
286 return hour_;
287}
288
289 unsigned int
290DateValue::minute()
291{
292 parse();
293 return minute_;
294}
295
296 unsigned int
297DateValue::second()
298{
299 parse();
300 return second_;
301}
302
303 double
304DateValue::secondFraction()
305{
306 parse();
307 return secFrac_;
308}
309
310 bool
311DateValue::zonePositive()
312{
313 parse();
314 return zonePositive_;
315}
316
317 unsigned int
318DateValue::zoneHour()
319{
320 parse();
321 return zoneHour_;
322}
323
324 unsigned int
325DateValue::zoneMinute()
326{
327 parse();
328 return zoneMinute_;
329}
330
331 void
332DateValue::setYear(unsigned int i)
333{
334 year_ = i;
335 assembled_ = false;
336}
337
338 void
339DateValue::setMonth(unsigned int i)
340{
341 month_ = i;
342 assembled_ = false;
343}
344
345 void
346DateValue::setDay(unsigned int i)
347{
348 day_ = i;
349 assembled_ = false;
350}
351
352 void
353DateValue::setHour(unsigned int i)
354{
355 hour_ = i;
356 assembled_ = false;
357}
358
359 void
360DateValue::setMinute(unsigned int i)
361{
362 minute_ = i;
363 assembled_ = false;
364}
365
366 void
367DateValue::setSecond(unsigned int i)
368{
369 second_ = i;
370 assembled_ = false;
371}
372
373 void
374DateValue::setSecondFraction(double d)
375{
376 secFrac_ = d;
377 assembled_ = false;
378}
379
380 void
381DateValue::setZonePositive(bool b)
382{
383 zonePositive_ = b;
384 assembled_ = false;
385 }
386
387 void
388DateValue::setZoneHour(unsigned int i)
389{
390 zoneHour_ = i;
391 assembled_ = false;
392}
393
394 void
395DateValue::setZoneMinute(unsigned int i)
396{
397 zoneMinute_ = i;
398 assembled_ = false;
399}
400
401 QDate
402DateValue::qdate()
403{
404 parse();
405 QDate d(year_, month_, day_);
406 return d;
407}
408
409 QTime
410DateValue::qtime()
411{
412 parse();
413 QTime t(hour_, minute_, second_);
414 //t.setMs(1 / secFrac_);
415 return t;
416}
417
418 QDateTime
419DateValue::qdt()
420{
421 parse();
422 QDateTime dt;
423 dt.setDate(qdate());
424 dt.setTime(qtime());
425 return dt;
426}
427
428 bool
429DateValue::hasTime()
430{
431 parse();
432 return hasTime_;
433}
434
diff --git a/kabc/vcard/EmailParam.cpp b/kabc/vcard/EmailParam.cpp
new file mode 100644
index 0000000..8c87477
--- a/dev/null
+++ b/kabc/vcard/EmailParam.cpp
@@ -0,0 +1,116 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardEmailParam.h>
25#include <VCardParam.h>
26#include <VCardDefines.h>
27
28using namespace VCARD;
29
30EmailParam::EmailParam()
31 :Param()
32{
33 vDebug("ctor");
34}
35
36EmailParam::EmailParam(const EmailParam & x)
37 :Param(x),
38 emailType_(x.emailType_),
39 pref_ (x.pref_)
40{
41}
42
43EmailParam::EmailParam(const QCString & s)
44 :Param(s)
45{
46}
47
48 EmailParam &
49EmailParam::operator = (EmailParam & x)
50{
51 if (*this == x) return *this;
52
53 emailType_= x.emailType();
54 pref_ = x.pref_;
55
56 Param::operator = (x);
57 return *this;
58}
59
60 EmailParam &
61EmailParam::operator = (const QCString & s)
62{
63 Param::operator = (s);
64 return *this;
65}
66
67 bool
68EmailParam::operator == (EmailParam & x)
69{
70 parse();
71
72 if (pref_)
73 return (x.pref_ && x.emailType() == emailType_);
74
75 return !x.pref();
76}
77
78EmailParam::~EmailParam()
79{
80}
81
82 void
83EmailParam::_parse()
84{
85#if 0
86 Param::parseToList();
87
88 SubParamListIterator it(subParamList_);
89
90 pref_ = true;
91 emailType_ = "";
92
93 for (; it.current(); ++it) {
94
95 if (qstricmp(it.current()->name(), "TYPE") == 0) {
96 emailType_ = it.current()->value();
97 continue;
98 }
99
100 if (qstricmp(it.current()->name(), "PREF") == 0) {
101 pref_ = true;
102 }
103 }
104#endif
105}
106
107 void
108EmailParam::_assemble()
109{
110 strRep_ = "TYPE=";
111 strRep_ += emailType_;
112
113 if (pref_)
114 strRep_ += ",PREF";
115}
116
diff --git a/kabc/vcard/Entity.cpp b/kabc/vcard/Entity.cpp
new file mode 100644
index 0000000..b7d09e0
--- a/dev/null
+++ b/kabc/vcard/Entity.cpp
@@ -0,0 +1,134 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardEntity.h>
25
26using namespace VCARD;
27
28Entity::Entity()
29 : parsed_ (false),
30 assembled_(true)
31{
32 // empty
33}
34
35Entity::Entity(const Entity & e)
36 : strRep_ (e.strRep_),
37 parsed_ (e.parsed_),
38 assembled_(e.assembled_)
39{
40 // empty
41}
42
43Entity::Entity(const QCString & s)
44 : strRep_ (s),
45 parsed_ (false),
46 assembled_(true)
47{
48 // empty
49}
50
51 Entity &
52Entity::operator = (const Entity & e)
53{
54 if (this == &e) return *this;
55
56 strRep_ = e.strRep_;
57 parsed_ = e.parsed_;
58 assembled_= e.assembled_;
59
60 return *this;
61}
62
63 Entity &
64Entity::operator = (const QCString & s)
65{
66 strRep_ = s;
67 parsed_ = false;
68 assembled_= true;
69
70 return *this;
71}
72
73 bool
74Entity::operator == (Entity & e)
75{
76 return asString() == e.asString();
77}
78
79 bool
80Entity::operator != (Entity & e)
81{
82 return !(*this == e);
83}
84
85 bool
86Entity::operator == (const QCString & s)
87{
88 return asString() == s;
89}
90
91 bool
92Entity::operator != (const QCString & s)
93{
94 return !(*this == s);
95}
96
97Entity::~Entity()
98{
99 // empty
100}
101
102 QCString
103Entity::asString()
104{
105 //vDebug("Entity::asString()");
106 assemble();
107
108 return strRep_;
109}
110
111 void
112Entity::parse()
113{
114 //vDebug( "Entity::parse()" );
115
116 if (!parsed_) _parse();
117
118 parsed_ = true;
119 assembled_= false;
120}
121
122 void
123Entity::assemble()
124{
125 //vDebug( "Entity::assemble()" );
126
127 if (assembled_) return;
128
129 parse();
130 _assemble();
131
132 assembled_= true;
133}
134
diff --git a/kabc/vcard/Enum.cpp b/kabc/vcard/Enum.cpp
new file mode 100644
index 0000000..cc48b5a
--- a/dev/null
+++ b/kabc/vcard/Enum.cpp
@@ -0,0 +1,482 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <qcstring.h>
25#include <ctype.h>
26
27#include <VCardEnum.h>
28
29using namespace VCARD;
30
31// There are 31 possible types, not including extensions.
32 const QCString
33VCARD::paramNames [] =
34{
35 "NAME",
36 "PROFILE",
37 "SOURCE",
38 "FN",
39 "N",
40 "NICKNAME",
41 "PHOTO",
42 "BDAY",
43 "ADR",
44 "LABEL",
45 "TEL",
46 "EMAIL",
47 "MAILER",
48 "TZ",
49 "GEO",
50 "TITLE",
51 "ROLE",
52 "LOGO",
53 "AGENT",
54 "ORG",
55 "CATEGORIES",
56 "NOTE",
57 "PRODID",
58 "REV",
59 "SORT-STRING",
60 "SOUND",
61 "UID",
62 "URL",
63 "VERSION",
64 "CLASS",
65 "KEY"
66};
67
68 const ParamType
69VCARD::paramTypesTable[] = {
70 ParamNone, // NAME
71 ParamNone, // PROFILE
72 ParamSource, // SOURCE
73 ParamText, // FN
74 ParamText, // N
75 ParamText, // NICKNAME
76 ParamImage, // PHOTO (inline/refer)
77 ParamDate, // BDAY ("VALUE = "date-time/date)
78 ParamAddrText, // ADR (adr-param/text-param)
79 ParamAddrText, // LABEL (adr-param/text-param)
80 ParamTel, // TEL
81 ParamEmail, // EMAIL
82 ParamText, // MAILER
83 ParamNone, // TZ
84 ParamNone, // GEO
85 ParamText, // TITLE
86 ParamText, // ROLE
87 ParamImage, // LOGO
88 ParamAgent, // AGENT
89 ParamText, // ORG
90 ParamText, // CATEGORIES
91 ParamText, // NOTE
92 ParamNone, // PRODID
93 ParamDate, // REV
94 ParamText, // SORT-STRING
95 ParamSound, // SOUND
96 ParamNone, // UID
97 ParamNone, // URL
98 ParamNone, // VERSION
99 ParamNone, // CLASS
100 ParamTextBin, // KEY
101 ParamTextNS // X
102};
103
104 ParamType
105VCARD::EntityTypeToParamType(EntityType e)
106{
107 ParamType t(ParamUnknown);
108
109 switch (e) {
110
111 //---------------------------------------------------------------//
112 case EntityAgent: t = ParamAgent; break;
113 //---------------------------------------------------------------//
114 case EntitySound: t = ParamSound; break;
115 //---------------------------------------------------------------//
116 case EntitySource: t = ParamSource;break;
117 //---------------------------------------------------------------//
118 case EntityTelephone: t = ParamTel; break;
119 //---------------------------------------------------------------//
120 case EntityEmail: t = ParamEmail; break;
121 //---------------------------------------------------------------//
122 case EntityKey: t = ParamTextBin;break;
123 //---------------------------------------------------------------//
124 case EntityExtension: t = ParamTextNS;break;
125 //---------------------------------------------------------------//
126 case EntityAddress:
127 case EntityLabel: t = ParamAddrText;break;
128 //---------------------------------------------------------------//
129 case EntityBirthday:
130 case EntityRevision: t = ParamDate; break;
131 //---------------------------------------------------------------//
132 case EntityPhoto:
133 case EntityLogo: t = ParamImage; break;
134 //---------------------------------------------------------------//
135 case EntityOrganisation:
136 case EntityTitle:
137 case EntityRole:
138 case EntityFullName:
139 case EntityMailer:
140 case EntityN:
141 case EntitySortString:
142 case EntityNickname:
143 case EntityCategories:
144 case EntityNote: t = ParamText; break;
145 //---------------------------------------------------------------//
146 case EntityProductID:
147 case EntityTimeZone:
148 case EntityUID:
149 case EntityURL:
150 case EntityClass:
151 case EntityGeo:
152 case EntityName:
153 case EntityVersion:
154 case EntityProfile:
155 default: t = ParamNone; break;
156 //---------------------------------------------------------------//
157
158 }
159
160 return t;
161}
162
163 ValueType
164VCARD::EntityTypeToValueType(EntityType e)
165{
166 ValueType t(ValueUnknown);
167
168 switch (e) {
169
170 //---------------------------------------------------------------//
171 case EntitySound: t = ValueSound; break;
172 //---------------------------------------------------------------//
173 case EntityAgent: t = ValueAgent; break;
174 //---------------------------------------------------------------//
175 case EntityAddress: t = ValueAddress;break;
176 //---------------------------------------------------------------//
177 case EntityTelephone: t = ValueTel; break;
178 //---------------------------------------------------------------//
179 case EntityKey: t = ValueTextBin;break;
180 //---------------------------------------------------------------//
181 case EntityOrganisation: t = ValueOrg; break;
182 //---------------------------------------------------------------//
183 case EntityN: t = ValueN; break;
184 //---------------------------------------------------------------//
185 case EntityTimeZone: t = ValueUTC; break;
186 //---------------------------------------------------------------//
187 case EntityClass: t = ValueClass; break;
188 //---------------------------------------------------------------//
189 case EntityGeo: t = ValueGeo; break;
190 //---------------------------------------------------------------//
191 case EntitySource:
192 case EntityURL: t = ValueURI; break;
193 //---------------------------------------------------------------//
194 case EntityPhoto:
195 case EntityLogo: t = ValueImage; break;
196 //---------------------------------------------------------------//
197 case EntityBirthday:
198 case EntityRevision: t = ValueDate; break;
199 //---------------------------------------------------------------//
200 case EntityCategories:
201 case EntityNickname: t = ValueTextList;break;
202 //---------------------------------------------------------------//
203 case EntityLabel:
204 case EntityExtension:
205 case EntityEmail:
206 case EntityTitle:
207 case EntityRole:
208 case EntityFullName:
209 case EntityMailer:
210 case EntityProductID:
211 case EntityName:
212 case EntitySortString:
213 case EntityVersion:
214 case EntityProfile:
215 case EntityUID:
216 case EntityNote:
217 default: t = ValueText; break;
218 //---------------------------------------------------------------//
219
220 }
221
222 return t;
223}
224
225 QCString
226VCARD::EntityTypeToParamName(EntityType e)
227{
228 if ( e > EntityUnknown ) e = EntityUnknown;
229 return paramNames[ int( e ) ];
230}
231
232 EntityType
233VCARD::EntityNameToEntityType(const QCString & s)
234{
235 if (s.isEmpty()) return EntityUnknown;
236
237 EntityType t(EntityUnknown);
238
239 switch (s[0]) {
240
241 case 'A':
242 if (s == "ADR")
243 t = EntityAddress;
244 else if (s == "AGENT")
245 t = EntityAgent;
246 break;
247
248 case 'B':
249 if (s == "BDAY")
250 t = EntityBirthday;
251 break;
252
253 case 'C':
254 if (s == "CATEGORIES")
255 t = EntityCategories;
256 else if (s == "CLASS")
257 t = EntityClass;
258 break;
259
260 case 'E':
261 if (s == "EMAIL")
262 t = EntityEmail;
263 break;
264
265 case 'F':
266 if (s == "FN")
267 t = EntityFullName;
268 break;
269
270 case 'G':
271 if (s == "GEO")
272 t = EntityGeo;
273 break;
274
275 case 'K':
276 if (s == "KEY")
277 t = EntityKey;
278 break;
279
280 case 'L':
281 if (s == "LABEL")
282 t = EntityLabel;
283 else if (s == "LOGO")
284 t = EntityLogo;
285 break;
286
287 case 'M':
288 if (s == "MAILER")
289 t = EntityMailer;
290 break;
291
292 case 'N':
293 if (s == "N")
294 t = EntityN;
295 else if (s == "NAME")
296 t = EntityName;
297 else if (s == "NICKNAME")
298 t = EntityNickname;
299 else if (s == "NOTE")
300 t = EntityNote;
301 break;
302
303 case 'O':
304 if (s == "ORG")
305 t = EntityOrganisation;
306 break;
307
308 case 'P':
309 if (s == "PHOTO")
310 t = EntityPhoto;
311 else if (s == "PRODID")
312 t = EntityProductID;
313 else if (s == "PROFILE")
314 t = EntityProfile;
315 break;
316
317 case 'R':
318 if (s == "REV")
319 t = EntityRevision;
320 else if (s == "ROLE")
321 t = EntityRole;
322 break;
323
324 case 'S':
325 if (s == "SORT-STRING")
326 t = EntitySortString;
327 else if (s == "SOUND")
328 t = EntitySound;
329 else if (s == "SOURCE")
330 t = EntitySource;
331 break;
332
333 case 'T':
334 if (s == "TEL")
335 t = EntityTelephone;
336 else if (s == "TITLE")
337 t = EntityTitle;
338 else if (s == "TZ")
339 t = EntityTimeZone;
340 break;
341
342 case 'U':
343 if (s == "UID")
344 t = EntityUID;
345 else if (s == "URL")
346 t = EntityURL;
347 case 'V':
348 if (s == "VERSION")
349 t = EntityVersion;
350 break;
351
352 case 'X':
353 if (s.left(2) == "X-")
354 t = EntityExtension;
355 break;
356
357 default:
358
359 t = EntityUnknown;
360 }
361
362 return t;
363}
364
365// The copyright notice below refers to the base64 codec functions used below,
366// which are modified from the original sources.
367
368/*
369 * Original version Copyright 1988 by The Leland Stanford Junior University
370 * Copyright 1998 by the University of Washington
371 *
372 * Permission to use, copy, modify, and distribute this software and its
373 * documentation for any purpose and without fee is hereby granted, provided
374 * that the above copyright notices appear in all copies and that both the
375 * above copyright notices and this permission notice appear in supporting
376 * documentation, and that the name of the University of Washington or The
377 * Leland Stanford Junior University not be used in advertising or publicity
378 * pertaining to distribution of the software without specific, written prior
379 * permission. This software is made available "as is", and
380 * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY
381 * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE,
382 * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
383 * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
384 * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY
385 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
386 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
387 * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF
388 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
389 *
390 */
391
392static char B64[] =
393 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
394
395// the mime base64 disctionary used for decoding
396static signed char b64dec[] = {
397 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0
398 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10
399 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 20
400 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 30
401 -1, -1, -1,-19, -1, -1, -1,-16, -4, -4, // 40 -19 == '+' -16 == '/'
402 -4, -4, -4, -4, -4, -4, -4, -4, -1, -1, // 50 -4 == '0'
403 -1, 0, -1, -1, -1, 65, 65, 65, 65, 65, // 60 0 == '=' 65 == 'A'
404 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, // 70
405 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, // 80
406 65, -1, -1, -1, -1, -1, -1, 71, 71, 71, // 90 71 == 'a'
407 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, // 100
408 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, // 110
409 71, 71, 71, -1, -1, -1, -1, -1, -1, -1, // 120
410 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 130
411 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 140
412 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 150
413 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 160
414 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 170
415 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 180
416 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 190
417 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 200
418 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 210
419 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 220
420 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 230
421 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 240
422 -1, -1, -1, -1, -1, -1, -1 // 250
423};
424
425 char *
426VCARD::decodeBase64(const char * s, unsigned long srcl, unsigned long & len)
427{
428 register unsigned char c;
429 register unsigned long e(0);
430 len = 0;
431 unsigned const char * src = (unsigned const char *)s;
432 char * ret = new char[srcl + (srcl / 4 + 1)];
433 register char *d = ret;
434 while (srcl--) { // Critical loop
435 c = *src++;
436 int dec = b64dec[c];
437 if (dec == -1) continue;
438 if (c == '=') {
439 switch (e++) {
440 case 3: e = 0; break;
441 case 2: if (*src == '=') break;
442 default: delete [] ret; ret = 0; return 0;break;
443 }
444 continue;
445 }
446 c -= dec;
447 if (e == 0) { *d = c << 2; ++e; continue; }
448 switch (e) {
449 case 1: *d |= c >> 4; *++d = c << 4;break;
450 case 2: *d |= c >> 2; *++d = c << 6;break;
451 case 3: *d++ |= c; e = 0; continue; break;
452 }
453 ++e;
454 }
455 len = d - (char *)ret;
456 return ret;
457}
458
459
460 char *
461VCARD::encodeBase64(const char * src, unsigned long srcl, unsigned long & destl)
462{
463 register const unsigned char *s = (unsigned char *)src;
464 register unsigned long i = ((srcl + 2) / 3) * 4;
465 destl = i += 2 * ((i / 60) + 1);
466 i = 0;
467 char * ret = new char[destl];
468 register unsigned char *d((unsigned char *)ret);
469 while (srcl != 0) { // Critical loop
470 *d++ = B64[s[0] >> 2];
471 *d++ = B64[((s[0] << 4) + (--srcl == 0 ? 0 : s[1] >> 4)) & 0x3f];
472 *d++ = srcl == 0 ? '=' :
473 B64[((s[1] << 2) + (--srcl == 0 ? 0 : s[2] >> 6)) & 0x3f];
474 *d++ = srcl == 0 ?'=' : B64[s[2] & 0x3f];
475 if (srcl != 0) srcl--;
476 if (++i == 15) { i = 0; *d++ = '\r'; *d++ = '\n'; }
477 s += 3;
478 }
479 *d = '\r'; *++d = '\n'; *++d = '\0';
480 return ret;
481}
482
diff --git a/kabc/vcard/FloatValue.cpp b/kabc/vcard/FloatValue.cpp
new file mode 100644
index 0000000..15bb664
--- a/dev/null
+++ b/kabc/vcard/FloatValue.cpp
@@ -0,0 +1,120 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardFloatValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30FloatValue::FloatValue()
31 :Value()
32{
33}
34
35FloatValue::FloatValue(float f)
36 : Value(),
37 value_(f)
38{
39 parsed_ = true;
40}
41
42FloatValue::FloatValue(const FloatValue & x)
43 :Value(x)
44{
45 value_ = x.value_;
46}
47
48FloatValue::FloatValue(const QCString & s)
49 :Value(s)
50{
51}
52
53 FloatValue &
54FloatValue::operator = (FloatValue & x)
55{
56 if (*this == x) return *this;
57
58 x.parse();
59 value_ = x.value_;
60
61 Value::operator = (x);
62 return *this;
63}
64
65 FloatValue &
66FloatValue::operator = (const QCString & s)
67{
68 Value::operator = (s);
69 return *this;
70}
71
72 bool
73FloatValue::operator == (FloatValue & x)
74{
75 x.parse();
76 return (value_ == x.value_);
77}
78
79FloatValue::~FloatValue()
80{
81}
82
83 void
84FloatValue::_parse()
85{
86 bool negative(false);
87
88 if (strRep_[0] == '-' || strRep_[1] == '+') {
89
90 if (strRep_[0] == '-')
91 negative = true;
92
93 strRep_.remove(0, 1);
94 }
95
96 value_ = strRep_.toFloat();
97 if (negative)
98 value_ = -value_;
99}
100
101 void
102FloatValue::_assemble()
103{
104 strRep_ = QCString().setNum(value_);
105}
106
107 float
108FloatValue::value()
109{
110 parse();
111 return value_;
112}
113
114 void
115FloatValue::setValue(float f)
116{
117 parsed_ = true;
118 value_ = f;
119}
120
diff --git a/kabc/vcard/GeoValue.cpp b/kabc/vcard/GeoValue.cpp
new file mode 100644
index 0000000..e02b402
--- a/dev/null
+++ b/kabc/vcard/GeoValue.cpp
@@ -0,0 +1,100 @@
1/*
2 This file is part of libvcard.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <VCardGeoValue.h>
22
23#include <VCardValue.h>
24
25#include <kdebug.h>
26
27using namespace VCARD;
28
29GeoValue::GeoValue()
30 :Value()
31{
32}
33
34GeoValue::GeoValue(const GeoValue & x)
35 :Value(x), latitude_(x.latitude_), longitude_(x.longitude_)
36{
37}
38
39GeoValue::GeoValue(const QCString & s)
40 :Value(s)
41{
42}
43
44 GeoValue &
45GeoValue::operator = (GeoValue & x)
46{
47 if (*this == x) return *this;
48
49 latitude_ = x.latitude_;
50 longitude_ = x.longitude_;
51
52 Value::operator = (x);
53 return *this;
54}
55
56 GeoValue &
57GeoValue::operator = (const QCString & s)
58{
59 Value::operator = (s);
60 return *this;
61}
62
63 bool
64GeoValue::operator == (GeoValue & x)
65{
66 x.parse();
67
68 if ( latitude_ != x.latitude_ ) return false;
69 if ( longitude_ != x.longitude_ ) return false;
70
71 return true;
72}
73
74GeoValue::~GeoValue()
75{
76}
77
78 GeoValue *
79GeoValue::clone()
80{
81 return new GeoValue( *this );
82}
83
84 void
85GeoValue::_parse()
86{
87 int semiColon = strRep_.find( ";" );
88
89 if ( semiColon == -1 ) // invalid
90 return;
91
92 latitude_ = strRep_.left( semiColon ).toFloat();
93 longitude_ = strRep_.mid( semiColon + 1, strRep_.length() - semiColon ).toFloat();
94}
95
96 void
97GeoValue::_assemble()
98{
99 strRep_.sprintf( "%.6f;%.6f", latitude_, longitude_ );
100}
diff --git a/kabc/vcard/ImageParam.cpp b/kabc/vcard/ImageParam.cpp
new file mode 100644
index 0000000..c9cf6fd
--- a/dev/null
+++ b/kabc/vcard/ImageParam.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardImageParam.h>
25
26#include <VCardParam.h>
27
28using namespace VCARD;
29
30ImageParam::ImageParam()
31 :Param()
32{
33}
34
35ImageParam::ImageParam(const ImageParam & x)
36 :Param(x)
37{
38}
39
40ImageParam::ImageParam(const QCString & s)
41 :Param(s)
42{
43}
44
45 ImageParam &
46ImageParam::operator = (ImageParam & x)
47{
48 if (*this == x) return *this;
49
50 Param::operator = (x);
51 return *this;
52}
53
54 ImageParam &
55ImageParam::operator = (const QCString & s)
56{
57 Param::operator = (s);
58 return *this;
59}
60
61 bool
62ImageParam::operator == (ImageParam & x)
63{
64 x.parse();
65 return false;
66}
67
68ImageParam::~ImageParam()
69{
70}
71
72 void
73ImageParam::_parse()
74{
75}
76
77 void
78ImageParam::_assemble()
79{
80}
81
diff --git a/kabc/vcard/ImageValue.cpp b/kabc/vcard/ImageValue.cpp
new file mode 100644
index 0000000..4630fac
--- a/dev/null
+++ b/kabc/vcard/ImageValue.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardImageValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30ImageValue::ImageValue()
31 :Value()
32{
33}
34
35ImageValue::ImageValue(const ImageValue & x)
36 :Value(x)
37{
38}
39
40ImageValue::ImageValue(const QCString & s)
41 :Value(s)
42{
43}
44
45 ImageValue &
46ImageValue::operator = (ImageValue & x)
47{
48 if (*this == x) return *this;
49
50 Value::operator = (x);
51 return *this;
52}
53
54 ImageValue &
55ImageValue::operator = (const QCString & s)
56{
57 Value::operator = (s);
58 return *this;
59}
60
61 bool
62ImageValue::operator == (ImageValue & x)
63{
64 x.parse();
65 return false;
66}
67
68ImageValue::~ImageValue()
69{
70}
71
72 void
73ImageValue::_parse()
74{
75}
76
77 void
78ImageValue::_assemble()
79{
80}
81
diff --git a/kabc/vcard/ImgValue.cpp b/kabc/vcard/ImgValue.cpp
new file mode 100644
index 0000000..7b961f8
--- a/dev/null
+++ b/kabc/vcard/ImgValue.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardImgValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30ImgValue::ImgValue()
31 :Value()
32{
33}
34
35ImgValue::ImgValue(const ImgValue & x)
36 :Value(x)
37{
38}
39
40ImgValue::ImgValue(const QCString & s)
41 :Value(s)
42{
43}
44
45 ImgValue &
46ImgValue::operator = (ImgValue & x)
47{
48 if (*this == x) return *this;
49
50 Value::operator = (x);
51 return *this;
52}
53
54 ImgValue &
55ImgValue::operator = (const QCString & s)
56{
57 Value::operator = (s);
58 return *this;
59}
60
61 bool
62ImgValue::operator == (ImgValue & x)
63{
64 x.parse();
65 return false;
66}
67
68ImgValue::~ImgValue()
69{
70}
71
72 void
73ImgValue::_parse()
74{
75}
76
77 void
78ImgValue::_assemble()
79{
80}
81
diff --git a/kabc/vcard/LangValue.cpp b/kabc/vcard/LangValue.cpp
new file mode 100644
index 0000000..edf1804
--- a/dev/null
+++ b/kabc/vcard/LangValue.cpp
@@ -0,0 +1,127 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardRToken.h>
25
26#include <VCardLangValue.h>
27
28#include <VCardValue.h>
29
30using namespace VCARD;
31
32LangValue::LangValue()
33 :Value()
34{
35}
36
37LangValue::LangValue(const LangValue & x)
38 :Value(x)
39{
40}
41
42LangValue::LangValue(const QCString & s)
43 :Value(s)
44{
45}
46
47 LangValue &
48LangValue::operator = (LangValue & x)
49{
50 if (*this == x) return *this;
51
52 Value::operator = (x);
53 return *this;
54}
55
56 LangValue &
57LangValue::operator = (const QCString & s)
58{
59 Value::operator = (s);
60 return *this;
61}
62
63 bool
64LangValue::operator == (LangValue & x)
65{
66 x.parse();
67 return false;
68}
69
70LangValue::~LangValue()
71{
72}
73
74 void
75LangValue::_parse()
76{
77 QStrList l;
78 RTokenise(strRep_, "-", l);
79
80 if (l.count() == 0) return;
81
82 primary_ = l.at(0);
83
84 l.remove(0u);
85
86 subtags_ = l;
87}
88
89 void
90LangValue::_assemble()
91{
92 strRep_ = primary_;
93
94 QStrListIterator it(subtags_);
95
96 for (; it.current(); ++it)
97 strRep_ += QCString('-') + it.current();
98}
99
100 QCString
101LangValue::primary()
102{
103 parse();
104 return primary_;
105}
106
107 QStrList
108LangValue::subtags()
109{
110 parse();
111 return subtags_;
112}
113
114 void
115LangValue::setPrimary(const QCString & s)
116{
117 parse();
118 primary_ = s;
119}
120
121 void
122LangValue::setSubTags(const QStrList & l)
123{
124 parse();
125 subtags_ = l;
126}
127
diff --git a/kabc/vcard/NValue.cpp b/kabc/vcard/NValue.cpp
new file mode 100644
index 0000000..cdec621
--- a/dev/null
+++ b/kabc/vcard/NValue.cpp
@@ -0,0 +1,128 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <qstrlist.h>
25
26#include <VCardRToken.h>
27#include <VCardNValue.h>
28#include <VCardValue.h>
29#include <VCardDefines.h>
30
31using namespace VCARD;
32
33NValue::NValue()
34 :Value()
35{
36 vDebug("ctor");
37}
38
39NValue::NValue(const NValue & x)
40 :Value(x),
41 family_(x.family_),
42 given_(x.given_),
43 middle_(x.middle_),
44 prefix_(x.prefix_),
45 suffix_(x.suffix_)
46{
47}
48
49NValue::NValue(const QCString & s)
50 :Value(s)
51{
52 vDebug("ctor");
53}
54
55 NValue &
56NValue::operator = (NValue & x)
57{
58 if (*this == x) return *this;
59
60 family_= x.family_;
61 given_= x.given_;
62 middle_= x.middle_;
63 prefix_= x.prefix_;
64 suffix_= x.suffix_;
65
66 Value::operator = (x);
67 return *this;
68}
69
70 NValue &
71NValue::operator = (const QCString & s)
72{
73 Value::operator = (s);
74 return *this;
75}
76
77 bool
78NValue::operator == (NValue & x)
79{
80 x.parse();
81
82 return (
83 family_ == x.family_&&
84 given_ == x.given_&&
85 middle_ == x.middle_&&
86 prefix_ == x.prefix_&&
87 suffix_ == x.suffix_);
88}
89
90NValue::~NValue()
91{
92}
93
94 NValue *
95NValue::clone()
96{
97 return new NValue( *this );
98}
99
100 void
101NValue::_parse()
102{
103 QStrList l;
104 RTokenise(strRep_, ";", l);
105
106 for (unsigned int i = 0; i < l.count(); i++) {
107
108 switch (i) {
109 case 0: family_ = l.at(0);break;
110 case 1: given_ = l.at(1);break;
111 case 2: middle_ = l.at(2);break;
112 case 3: prefix_ = l.at(3);break;
113 case 4: suffix_ = l.at(4);break;
114 default: break;
115 }
116 }
117}
118
119 void
120NValue::_assemble()
121{
122 strRep_ = family_;
123 strRep_ += ";" +given_;
124 strRep_ += ";" +middle_;
125 strRep_ += ";" +prefix_;
126 strRep_ += ";" +suffix_;
127}
128
diff --git a/kabc/vcard/OrgValue.cpp b/kabc/vcard/OrgValue.cpp
new file mode 100644
index 0000000..c3134c8
--- a/dev/null
+++ b/kabc/vcard/OrgValue.cpp
@@ -0,0 +1,107 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardRToken.h>
25
26#include <VCardOrgValue.h>
27
28#include <VCardValue.h>
29
30using namespace VCARD;
31
32OrgValue::OrgValue()
33 :Value()
34{
35}
36
37OrgValue::OrgValue(const OrgValue & x)
38 :Value(x)
39{
40}
41
42OrgValue::OrgValue(const QCString & s)
43 :Value(s)
44{
45}
46
47 OrgValue &
48OrgValue::operator = (OrgValue & x)
49{
50 if (*this == x) return *this;
51
52 Value::operator = (x);
53 return *this;
54}
55
56 OrgValue &
57OrgValue::operator = (const QCString & s)
58{
59 Value::operator = (s);
60 return *this;
61}
62
63 bool
64OrgValue::operator == (OrgValue & x)
65{
66 x.parse();
67 return false;
68}
69
70OrgValue::~OrgValue()
71{
72}
73
74 void
75OrgValue::_parse()
76{
77 RTokenise(strRep_, ";", valueList_);
78}
79
80 void
81OrgValue::_assemble()
82{
83 bool first(true);
84
85 QStrListIterator it(valueList_);
86
87 for (; it.current(); ++it) {
88 if (!first) strRep_ += ';';
89 strRep_ += it.current();
90 first = false;
91 }
92}
93
94 unsigned int
95OrgValue::numValues()
96{
97 parse();
98 return valueList_.count();
99}
100
101 QCString
102OrgValue::value(unsigned int i)
103{
104 parse();
105 return valueList_.at(i);
106}
107
diff --git a/kabc/vcard/Param.cpp b/kabc/vcard/Param.cpp
new file mode 100644
index 0000000..c513613
--- a/dev/null
+++ b/kabc/vcard/Param.cpp
@@ -0,0 +1,129 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardParam.h>
25
26#include <VCardEntity.h>
27
28#include <VCardRToken.h>
29
30using namespace VCARD;
31
32Param::Param()
33 :Entity(),
34 name_(""),
35 value_("")
36{
37}
38
39Param::Param(const Param & x)
40 :Entity(x),
41 name_(x.name_),
42 value_(x.value_)
43{
44}
45
46Param::Param(const QCString & s)
47 :Entity(s),
48 name_(""),
49 value_("")
50{
51}
52
53 Param &
54Param::operator = (Param & x)
55{
56 if (*this == x) return *this;
57
58 Entity::operator = (x);
59 name_ = x.name_;
60 value_ = x.value_;
61
62 return *this;
63}
64
65 Param &
66Param::operator = (const QCString & s)
67{
68 Entity::operator = (s);
69 return *this;
70}
71
72 bool
73Param::operator == (Param & x)
74{
75 x.parse();
76 return false;
77}
78
79Param::~Param()
80{
81}
82
83 void
84Param::_parse()
85{
86}
87
88 void
89Param::_assemble()
90{
91 strRep_ = name_ + "=" + value_;
92}
93
94Param::Param(const QCString &name, const QCString &value)
95 :Entity(),
96 name_(name),
97 value_(value)
98{
99 parsed_ = true;
100 assembled_ = false;
101}
102
103 void
104Param::setName(const QCString & name)
105{
106 name_ = name;
107
108 assembled_ = false;
109}
110
111 void
112Param::setValue(const QCString & value)
113{
114 value_ = value;
115
116 assembled_ = false;
117}
118
119 QCString
120Param::name()
121{
122 return name_;
123}
124
125 QCString
126Param::value()
127{
128 return value_;
129}
diff --git a/kabc/vcard/PhoneNumberValue.cpp b/kabc/vcard/PhoneNumberValue.cpp
new file mode 100644
index 0000000..17b1400
--- a/dev/null
+++ b/kabc/vcard/PhoneNumberValue.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardPhoneNumberValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30PhoneNumberValue::PhoneNumberValue()
31 :Value()
32{
33}
34
35PhoneNumberValue::PhoneNumberValue(const PhoneNumberValue & x)
36 :Value(x)
37{
38}
39
40PhoneNumberValue::PhoneNumberValue(const QCString & s)
41 :Value(s)
42{
43}
44
45 PhoneNumberValue &
46PhoneNumberValue::operator = (PhoneNumberValue & x)
47{
48 if (*this == x) return *this;
49
50 Value::operator = (x);
51 return *this;
52}
53
54 PhoneNumberValue &
55PhoneNumberValue::operator = (const QCString & s)
56{
57 Value::operator = (s);
58 return *this;
59}
60
61 bool
62PhoneNumberValue::operator == (PhoneNumberValue & x)
63{
64 x.parse();
65 return false;
66}
67
68PhoneNumberValue::~PhoneNumberValue()
69{
70}
71
72 void
73PhoneNumberValue::_parse()
74{
75}
76
77 void
78PhoneNumberValue::_assemble()
79{
80}
81
diff --git a/kabc/vcard/README b/kabc/vcard/README
new file mode 100644
index 0000000..18a9daf
--- a/dev/null
+++ b/kabc/vcard/README
@@ -0,0 +1,15 @@
1libvcard (C) 1999 Rik Hemsley <rik@kde.org>
2Written for the KDE project.
3
4This software is licensed under the MIT license.
5
6A vCard 3.0 parser based on the same principles that librmm (from Empath) uses.
7
8It's small and very fast due to parsing and assembly of object being lazy.
9
10There is a base64 codec declared in Enum.h
11
12Feedback welcome.
13
14Rik <rik@kde.org>
15
diff --git a/kabc/vcard/RToken.cpp b/kabc/vcard/RToken.cpp
new file mode 100644
index 0000000..2a85820
--- a/dev/null
+++ b/kabc/vcard/RToken.cpp
@@ -0,0 +1,88 @@
1/*
2
3 libvcard - vCard parsing library for vCard version 3.0
4
5 Copyright (C) 1999 Rik Hemsley rik@kde.org
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to
9 deal in the Software without restriction, including without limitation the
10 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 sell copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25#include <string.h>
26#include <stddef.h>
27#include <qcstring.h>
28#include <qstrlist.h>
29
30namespace VCARD
31{
32
33 Q_UINT32
34RTokenise(const char * str, const char * delim, QStrList & l)
35{
36 // FIXME no stderr !
37 l.clear();
38
39 if (!delim || !str || strlen(delim) == 0 || strlen(str) == 0) return 0;
40
41 char * len = (char *)(str + strlen(str));// End of string.
42
43 register char * rstart = new char[strlen(str) + 1];
44 register char * r = rstart;
45
46
47 register const char * i = str;// Cursor.
48
49 while (i <= len) {
50
51 if (*i == '\\') { // Escaped chars go straight through.
52 *r++ = *i++;
53 if (i <= len)
54 *r++ = *i++;
55 continue;
56 }
57
58 if (strchr(delim, *i) != 0) {
59 // We hit a delimiter. If we have some text, make a new token.
60 // This has the effect that multiple delimiters are collapsed.
61 // cs: We mustn't collapse multiple delimiters, otherwise we
62 // lose empty fields.
63 *r = '\0';
64 // if (r != rstart) {
65 l.append(rstart);
66 // }
67 r = rstart;
68 ++i;
69 continue;
70 }
71
72 *r++ = *i++;
73 }
74
75 // Catch last token
76 //if (r != rstart) {
77 *r = '\0';
78 l.append(rstart);
79 //}
80
81 r = 0;
82
83 delete [] rstart;
84
85 return l.count();
86}
87
88}
diff --git a/kabc/vcard/SoundValue.cpp b/kabc/vcard/SoundValue.cpp
new file mode 100644
index 0000000..81040d1
--- a/dev/null
+++ b/kabc/vcard/SoundValue.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardSoundValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30SoundValue::SoundValue()
31 :Value()
32{
33}
34
35SoundValue::SoundValue(const SoundValue & x)
36 :Value(x)
37{
38}
39
40SoundValue::SoundValue(const QCString & s)
41 :Value(s)
42{
43}
44
45 SoundValue &
46SoundValue::operator = (SoundValue & x)
47{
48 if (*this == x) return *this;
49
50 Value::operator = (x);
51 return *this;
52}
53
54 SoundValue &
55SoundValue::operator = (const QCString & s)
56{
57 Value::operator = (s);
58 return *this;
59}
60
61 bool
62SoundValue::operator == (SoundValue & x)
63{
64 x.parse();
65 return false;
66}
67
68SoundValue::~SoundValue()
69{
70}
71
72 void
73SoundValue::_parse()
74{
75}
76
77 void
78SoundValue::_assemble()
79{
80}
81
diff --git a/kabc/vcard/SourceParam.cpp b/kabc/vcard/SourceParam.cpp
new file mode 100644
index 0000000..cd51cbd
--- a/dev/null
+++ b/kabc/vcard/SourceParam.cpp
@@ -0,0 +1,112 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardSourceParam.h>
25
26#include <VCardParam.h>
27
28using namespace VCARD;
29
30SourceParam::SourceParam()
31 :Param(),
32 type_(SourceParam::TypeUnknown)
33{
34}
35
36SourceParam::SourceParam(const SourceParam & x)
37 :Param(x),
38 type_(x.type_),
39 par_(x.par_),
40 val_(x.val_)
41{
42}
43
44SourceParam::SourceParam(const QCString & s)
45 :Param(s),
46 type_(SourceParam::TypeUnknown)
47{
48}
49
50 SourceParam &
51SourceParam::operator = (SourceParam & x)
52{
53 if (*this == x) return *this;
54 type_= x.type();
55 par_= x.par();
56 val_= x.val();
57
58 Param::operator = (x);
59 return *this;
60}
61
62 SourceParam &
63SourceParam::operator = (const QCString & s)
64{
65 Param::operator = (s);
66 return *this;
67}
68
69 bool
70SourceParam::operator == (SourceParam & x)
71{
72 x.parse();
73 return false;
74}
75
76SourceParam::~SourceParam()
77{
78}
79
80 void
81SourceParam::_parse()
82{
83 int i = strRep_.find('=');
84 if (i == -1) // Invalid
85 return;
86
87 par_ = strRep_.left(i);
88 val_ = strRep_.right(strRep_.length() - i - 1);
89
90 if (qstricmp(par_, "VALUE") == 0 && qstricmp(val_, "uri") == 0)
91 type_ = TypeValue;
92 else if (qstricmp(par_, "CONTEXT") == 0 && qstricmp(val_, "word") == 0)
93 type_ = TypeContext;
94 else if (qstrnicmp(par_, "X-", 2) == 0) {
95 type_ = TypeX;
96 }
97 else type_ = TypeUnknown;
98
99}
100
101 void
102SourceParam::_assemble()
103{
104 if (type_ == TypeValue)
105 strRep_ = "VALUE=uri";
106 else if (type_ == TypeContext)
107 strRep_ = "CONTEXT=word";
108 else if (type_ == TypeX)
109 strRep_ = par_ + "=" + val_;
110 else strRep_ = "";
111}
112
diff --git a/kabc/vcard/TelParam.cpp b/kabc/vcard/TelParam.cpp
new file mode 100644
index 0000000..9d9fe4d
--- a/dev/null
+++ b/kabc/vcard/TelParam.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardTelParam.h>
25
26#include <VCardParam.h>
27
28using namespace VCARD;
29
30TelParam::TelParam()
31 :Param()
32{
33}
34
35TelParam::TelParam(const TelParam & x)
36 :Param(x)
37{
38}
39
40TelParam::TelParam(const QCString & s)
41 :Param(s)
42{
43}
44
45 TelParam &
46TelParam::operator = (TelParam & x)
47{
48 if (*this == x) return *this;
49
50 Param::operator = (x);
51 return *this;
52}
53
54 TelParam &
55TelParam::operator = (const QCString & s)
56{
57 Param::operator = (s);
58 return *this;
59}
60
61 bool
62TelParam::operator == (TelParam & x)
63{
64 x.parse();
65 return false;
66}
67
68TelParam::~TelParam()
69{
70}
71
72 void
73TelParam::_parse()
74{
75}
76
77 void
78TelParam::_assemble()
79{
80}
81
diff --git a/kabc/vcard/TelValue.cpp b/kabc/vcard/TelValue.cpp
new file mode 100644
index 0000000..349f99a
--- a/dev/null
+++ b/kabc/vcard/TelValue.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardTelValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30TelValue::TelValue()
31 :Value()
32{
33}
34
35TelValue::TelValue(const TelValue & x)
36 :Value(x)
37{
38}
39
40TelValue::TelValue(const QCString & s)
41 :Value(s)
42{
43}
44
45 TelValue &
46TelValue::operator = (TelValue & x)
47{
48 if (*this == x) return *this;
49
50 Value::operator = (x);
51 return *this;
52}
53
54 TelValue &
55TelValue::operator = (const QCString & s)
56{
57 Value::operator = (s);
58 return *this;
59}
60
61 bool
62TelValue::operator == (TelValue & x)
63{
64 x.parse();
65 return false;
66}
67
68TelValue::~TelValue()
69{
70}
71
72 void
73TelValue::_parse()
74{
75}
76
77 void
78TelValue::_assemble()
79{
80}
81
diff --git a/kabc/vcard/TextBinParam.cpp b/kabc/vcard/TextBinParam.cpp
new file mode 100644
index 0000000..66f2946
--- a/dev/null
+++ b/kabc/vcard/TextBinParam.cpp
@@ -0,0 +1,81 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardTextBinParam.h>
25
26#include <VCardParam.h>
27
28using namespace VCARD;
29
30TextBinParam::TextBinParam()
31 :Param()
32{
33}
34
35TextBinParam::TextBinParam(const TextBinParam & x)
36 :Param(x)
37{
38}
39
40TextBinParam::TextBinParam(const QCString & s)
41 :Param(s)
42{
43}
44
45 TextBinParam &
46TextBinParam::operator = (TextBinParam & x)
47{
48 if (*this == x) return *this;
49
50 Param::operator = (x);
51 return *this;
52}
53
54 TextBinParam &
55TextBinParam::operator = (const QCString & s)
56{
57 Param::operator = (s);
58 return *this;
59}
60
61 bool
62TextBinParam::operator == (TextBinParam & x)
63{
64 x.parse();
65 return false;
66}
67
68TextBinParam::~TextBinParam()
69{
70}
71
72 void
73TextBinParam::_parse()
74{
75}
76
77 void
78TextBinParam::_assemble()
79{
80}
81
diff --git a/kabc/vcard/TextBinValue.cpp b/kabc/vcard/TextBinValue.cpp
new file mode 100644
index 0000000..c584009
--- a/dev/null
+++ b/kabc/vcard/TextBinValue.cpp
@@ -0,0 +1,104 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <kmdcodec.h>
25
26#include <VCardTextBinValue.h>
27#include <VCardValue.h>
28
29using namespace VCARD;
30
31TextBinValue::TextBinValue()
32 :Value()
33{
34}
35
36TextBinValue::TextBinValue(const TextBinValue & x)
37 :Value(x)
38{
39 mIsBinary_ = x.mIsBinary_;
40 mData_ = x.mData_;
41 mUrl_ = x.mUrl_;
42}
43
44TextBinValue::TextBinValue(const QCString & s)
45 :Value(s)
46{
47}
48
49 TextBinValue &
50TextBinValue::operator = (TextBinValue & x)
51{
52 if (*this == x) return *this;
53
54 mIsBinary_ = x.mIsBinary_;
55 mData_ = x.mData_;
56 mUrl_ = x.mUrl_;
57
58 Value::operator = (x);
59 return *this;
60}
61
62 TextBinValue &
63TextBinValue::operator = (const QCString & s)
64{
65 Value::operator = (s);
66 return *this;
67}
68
69 bool
70TextBinValue::operator == (TextBinValue & x)
71{
72 x.parse();
73
74 if ( mIsBinary_ != x.mIsBinary_ ) return false;
75 if ( mData_ != x.mData_ ) return false;
76 if ( mUrl_ != x.mUrl_ ) return false;
77
78 return true;
79}
80
81TextBinValue::~TextBinValue()
82{
83}
84
85 TextBinValue *
86TextBinValue::clone()
87{
88 return new TextBinValue( *this );
89}
90
91 void
92TextBinValue::_parse()
93{
94}
95
96 void
97TextBinValue::_assemble()
98{
99 if ( mIsBinary_ ) {
100 strRep_ = KCodecs::base64Encode( mData_ );
101 } else
102 strRep_ = mUrl_.utf8();
103}
104
diff --git a/kabc/vcard/TextListValue.cpp b/kabc/vcard/TextListValue.cpp
new file mode 100644
index 0000000..c4ac1e3
--- a/dev/null
+++ b/kabc/vcard/TextListValue.cpp
@@ -0,0 +1,107 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardRToken.h>
25
26#include <VCardTextListValue.h>
27
28#include <VCardValue.h>
29
30using namespace VCARD;
31
32TextListValue::TextListValue()
33 :Value()
34{
35}
36
37TextListValue::TextListValue(const TextListValue & x)
38 :Value(x)
39{
40}
41
42TextListValue::TextListValue(const QCString & s)
43 :Value(s)
44{
45}
46
47 TextListValue &
48TextListValue::operator = (TextListValue & x)
49{
50 if (*this == x) return *this;
51
52 Value::operator = (x);
53 return *this;
54}
55
56 TextListValue &
57TextListValue::operator = (const QCString & s)
58{
59 Value::operator = (s);
60 return *this;
61}
62
63 bool
64TextListValue::operator == (TextListValue & x)
65{
66 x.parse();
67 return false;
68}
69
70TextListValue::~TextListValue()
71{
72}
73
74 void
75TextListValue::_parse()
76{
77 RTokenise(strRep_, ";", valueList_);
78}
79
80 void
81TextListValue::_assemble()
82{
83 bool first(true);
84
85 QStrListIterator it(valueList_);
86
87 for (; it.current(); ++it) {
88 if (!first) strRep_ += ';';
89 strRep_ += it.current();
90 first = false;
91 }
92}
93
94 unsigned int
95TextListValue::numValues()
96{
97 parse();
98 return valueList_.count();
99}
100
101 QCString
102TextListValue::value(unsigned int i)
103{
104 parse();
105 return valueList_.at(i);
106}
107
diff --git a/kabc/vcard/TextParam.cpp b/kabc/vcard/TextParam.cpp
new file mode 100644
index 0000000..7c68700
--- a/dev/null
+++ b/kabc/vcard/TextParam.cpp
@@ -0,0 +1,82 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardTextParam.h>
25
26#include <VCardParam.h>
27
28using namespace VCARD;
29
30TextParam::TextParam()
31 :Param()
32{
33}
34
35TextParam::TextParam(const TextParam & x)
36 :Param(x)
37{
38}
39
40TextParam::TextParam(const QCString & s)
41 :Param(s)
42{
43}
44
45 TextParam &
46TextParam::operator = (TextParam & x)
47{
48 if (*this == x) return *this;
49
50 Param::operator = (x);
51 return *this;
52}
53
54 TextParam &
55TextParam::operator = (const QCString & s)
56{
57 Param::operator = (s);
58 return *this;
59}
60
61 bool
62TextParam::operator == (TextParam & x)
63{
64 x.parse();
65
66 return false;
67}
68
69TextParam::~TextParam()
70{
71}
72
73 void
74TextParam::_parse()
75{
76}
77
78 void
79TextParam::_assemble()
80{
81}
82
diff --git a/kabc/vcard/TextValue.cpp b/kabc/vcard/TextValue.cpp
new file mode 100644
index 0000000..09934fa
--- a/dev/null
+++ b/kabc/vcard/TextValue.cpp
@@ -0,0 +1,86 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardTextValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30TextValue::TextValue()
31 :Value()
32{
33}
34
35TextValue::TextValue(const TextValue & x)
36 :Value(x)
37{
38}
39
40TextValue::TextValue(const QCString & s)
41 :Value(s)
42{
43}
44
45 TextValue &
46TextValue::operator = (TextValue & x)
47{
48 if (*this == x) return *this;
49
50 Value::operator = (x);
51 return *this;
52}
53
54 TextValue &
55TextValue::operator = (const QCString & s)
56{
57 Value::operator = (s);
58 return *this;
59}
60
61 bool
62TextValue::operator == (TextValue & x)
63{
64 return strRep_ = x.strRep_;
65}
66
67TextValue::~TextValue()
68{
69}
70
71 TextValue *
72TextValue::clone()
73{
74 return new TextValue( *this );
75}
76
77 void
78TextValue::_parse()
79{
80}
81
82 void
83TextValue::_assemble()
84{
85}
86
diff --git a/kabc/vcard/URIValue.cpp b/kabc/vcard/URIValue.cpp
new file mode 100644
index 0000000..c1d1022
--- a/dev/null
+++ b/kabc/vcard/URIValue.cpp
@@ -0,0 +1,133 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardURIValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30URIValue::URIValue()
31 :Value()
32{
33}
34
35URIValue::URIValue(const QCString & scheme, const QCString & schemeSpecificPart)
36 :Value(),
37 scheme_ (scheme),
38 schemeSpecificPart_(schemeSpecificPart)
39{
40 parsed_ = true;
41}
42
43URIValue::URIValue(const URIValue & x)
44 : Value (x),
45 scheme_ (x.scheme_),
46 schemeSpecificPart_(x.schemeSpecificPart_)
47{
48}
49
50URIValue::URIValue(const QCString & s)
51 :Value(s)
52{
53}
54
55 URIValue &
56URIValue::operator = (URIValue & x)
57{
58 if (*this == x) return *this;
59
60 scheme_ = x.scheme_;
61 schemeSpecificPart_= x.schemeSpecificPart_;
62
63 Value::operator = (x);
64 return *this;
65}
66
67 URIValue &
68URIValue::operator = (const QCString & s)
69{
70 Value::operator = (s);
71 return *this;
72}
73
74 bool
75URIValue::operator == (URIValue & x)
76{
77 x.parse();
78 return (
79 (scheme_ == x.scheme_) &&
80 (schemeSpecificPart_== x.schemeSpecificPart_));
81
82 return false;
83}
84
85URIValue::~URIValue()
86{
87}
88
89 void
90URIValue::_parse()
91{
92 int split = strRep_.find(':');
93 if (split == -1)
94 return;
95
96 scheme_ = strRep_.left(split);
97 schemeSpecificPart_ = strRep_.mid(split + 1);
98}
99
100 void
101URIValue::_assemble()
102{
103 strRep_ = scheme_ + ':' + schemeSpecificPart_;
104}
105
106 QCString
107URIValue::scheme()
108{
109 parse();
110 return scheme_;
111}
112
113 QCString
114URIValue::schemeSpecificPart()
115{
116 parse();
117 return schemeSpecificPart_;
118}
119
120 void
121URIValue::setScheme(const QCString & s)
122{
123 parse();
124 scheme_ = s;
125}
126
127 void
128URIValue::setSchemeSpecificPart(const QCString & s)
129{
130 parse();
131 schemeSpecificPart_ = s;
132}
133
diff --git a/kabc/vcard/UTCValue.cpp b/kabc/vcard/UTCValue.cpp
new file mode 100644
index 0000000..374306c
--- a/dev/null
+++ b/kabc/vcard/UTCValue.cpp
@@ -0,0 +1,110 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardUTCValue.h>
25
26#include <VCardValue.h>
27
28using namespace VCARD;
29
30UTCValue::UTCValue()
31 :Value()
32{
33}
34
35UTCValue::UTCValue(const UTCValue & x)
36 : Value(x),positive_(x.positive_), hour_(x.hour_), minute_(x.minute_)
37
38{
39}
40
41UTCValue::UTCValue(const QCString & s)
42 :Value(s)
43{
44}
45
46 UTCValue &
47UTCValue::operator = (UTCValue & x)
48{
49 if (*this == x) return *this;
50
51 positive_ = x.positive_;
52 hour_ = x.hour_;
53 minute_ = x.minute_;
54
55 Value::operator = (x);
56 return *this;
57}
58
59 UTCValue &
60UTCValue::operator = (const QCString & s)
61{
62 Value::operator = (s);
63 return *this;
64}
65
66 bool
67UTCValue::operator == (UTCValue & x)
68{
69 x.parse();
70
71 if (positive_ != x.positive_) return false;
72 if (hour_ != x.hour_) return false;
73 if (minute_ != x.minute_) return false;
74
75 return true;
76}
77
78UTCValue::~UTCValue()
79{
80}
81
82 UTCValue *
83UTCValue::clone()
84{
85 return new UTCValue( *this );
86}
87
88 void
89UTCValue::_parse()
90{
91 if ( strRep_.isEmpty() )
92 return;
93
94 positive_ = ( strRep_[0] == '+' );
95
96 int colon = strRep_.find( ':' );
97
98 if ( colon == -1 ) // Not valid.
99 return;
100
101 hour_= strRep_.mid( 1, 2 ).toInt();
102 minute_= strRep_.right( 2 ).toInt();
103}
104
105 void
106UTCValue::_assemble()
107{
108 strRep_.sprintf( "%c%.2i:%.2i", (positive_ ? '+' : '-'), hour_, minute_ );
109}
110
diff --git a/kabc/vcard/VCardEntity.cpp b/kabc/vcard/VCardEntity.cpp
new file mode 100644
index 0000000..0c21e2f
--- a/dev/null
+++ b/kabc/vcard/VCardEntity.cpp
@@ -0,0 +1,119 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <qregexp.h>
25
26#include <VCardDefines.h>
27#include <VCardVCardEntity.h>
28
29using namespace VCARD;
30
31VCardEntity::VCardEntity()
32 :Entity()
33{
34}
35
36VCardEntity::VCardEntity(const VCardEntity & x)
37 :Entity(x)
38{
39}
40
41VCardEntity::VCardEntity(const QCString & s)
42 :Entity(s)
43{
44}
45
46 VCardEntity &
47VCardEntity::operator = (VCardEntity & x)
48{
49 if (*this == x) return *this;
50
51 Entity::operator = (x);
52 return *this;
53}
54
55 VCardEntity &
56VCardEntity::operator = (const QCString & s)
57{
58 Entity::operator = (s);
59 return *this;
60}
61
62 bool
63VCardEntity::operator == (VCardEntity & x)
64{
65 x.parse();
66 return false;
67}
68
69VCardEntity::~VCardEntity()
70{
71}
72
73 void
74VCardEntity::_parse()
75{
76 vDebug("parse");
77 QCString s(strRep_);
78
79 int i = s.find(QRegExp("BEGIN:VCARD", false));
80
81 while (i != -1) {
82
83 i = s.find(QRegExp("BEGIN:VCARD", false), 11);
84
85 QCString cardStr(s.left(i));
86
87 VCard * v = new VCard(cardStr);
88
89 cardList_.append(v);
90
91 v->parse();
92
93 s.remove(0, i);
94 }
95}
96
97 void
98VCardEntity::_assemble()
99{
100 VCardListIterator it(cardList_);
101
102 for (; it.current(); ++it)
103 strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck.
104}
105
106 VCardList &
107VCardEntity::cardList()
108{
109 parse();
110 return cardList_;
111}
112
113 void
114VCardEntity::setCardList(const VCardList & l)
115{
116 parse();
117 cardList_ = l;
118}
119
diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp
new file mode 100644
index 0000000..8d271f4
--- a/dev/null
+++ b/kabc/vcard/VCardv.cpp
@@ -0,0 +1,282 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <qcstring.h>
25#include <qstrlist.h>
26
27#include <VCardEntity.h>
28#include <VCardVCard.h>
29#include <VCardContentLine.h>
30#include <VCardRToken.h>
31
32#include <VCardDefines.h>
33
34using namespace VCARD;
35
36VCard::VCard()
37 :Entity()
38{
39}
40
41VCard::VCard(const VCard & x)
42 :Entity(x),
43 group_(x.group_),
44 contentLineList_(x.contentLineList_)
45{
46}
47
48VCard::VCard(const QCString & s)
49 :Entity(s)
50{
51}
52
53 VCard &
54VCard::operator = (VCard & x)
55{
56 if (*this == x) return *this;
57
58 group_ = x.group();
59 contentLineList_= x.contentLineList_;
60
61 Entity::operator = (x);
62 return *this;
63}
64
65 VCard &
66VCard::operator = (const QCString & s)
67{
68 Entity::operator = (s);
69 return *this;
70}
71
72 bool
73VCard::operator == (VCard & x)
74{
75 x.parse();
76 return false;
77}
78
79VCard::~VCard()
80{
81}
82
83 void
84VCard::_parse()
85{
86 vDebug("parse() called");
87 QStrList l;
88
89 RTokenise(strRep_, "\r\n", l);
90
91 if (l.count() < 3) { // Invalid VCARD !
92 vDebug("Invalid vcard");
93 return;
94 }
95
96 // Get the first line
97 QCString beginLine = QCString(l.at(0)).stripWhiteSpace();
98
99 vDebug("Begin line == \"" + beginLine + "\"");
100
101 // Remove extra blank lines
102 while (QCString(l.last()).isEmpty())
103 l.remove(l.last());
104
105 // Now we know this is the last line
106 QCString endLine = l.last();
107
108 // Trash the first and last lines as we have seen them.
109 l.remove(0u);
110 l.remove(l.last());
111
112 ///////////////////////////////////////////////////////////////
113 // FIRST LINE
114
115 int split = beginLine.find(':');
116
117 if (split == -1) { // invalid, no BEGIN
118 vDebug("No split");
119 return;
120 }
121
122 QCString firstPart(beginLine.left(split));
123 QCString valuePart(beginLine.mid(split + 1));
124
125 split = firstPart.find('.');
126
127 if (split != -1) {
128 group_ = firstPart.left(split);
129 firstPart= firstPart.right(firstPart.length() - split - 1);
130 }
131
132 if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN !
133 vDebug("No BEGIN");
134 return;
135 }
136
137 if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard !
138 vDebug("No VCARD");
139 return;
140 }
141
142 ///////////////////////////////////////////////////////////////
143 // CONTENT LINES
144 //
145 vDebug("Content lines");
146
147 // Handle folded lines.
148
149 QStrList refolded;
150
151 QStrListIterator it(l);
152
153 QCString cur;
154
155 for (; it.current(); ++it) {
156
157 cur = it.current();
158
159 ++it;
160
161 while (
162 it.current() &&
163 it.current()[0] == ' '&&
164 strlen(it.current()) != 1)
165 {
166 cur += it.current() + 1;
167 ++it;
168 }
169
170 --it;
171
172 refolded.append(cur);
173 }
174
175 QStrListIterator it2(refolded);
176
177 for (; it2.current(); ++it2) {
178
179 vDebug("New contentline using \"" + QCString(it2.current()) + "\"");
180 ContentLine * cl = new ContentLine(it2.current());
181
182 cl->parse();
183
184 contentLineList_.append(cl);
185 }
186
187 ///////////////////////////////////////////////////////////////
188 // LAST LINE
189
190 split = endLine.find(':');
191
192 if (split == -1) // invalid, no END
193 return;
194
195 firstPart = endLine.left(split);
196 valuePart = endLine.right(firstPart.length() - split - 1);
197
198 split = firstPart.find('.');
199
200 if (split != -1) {
201 group_ = firstPart.left(split);
202 firstPart= firstPart.right(firstPart.length() - split - 1);
203 }
204
205 if (qstricmp(firstPart, "END") != 0) // No END !
206 return;
207
208 if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard !
209 return;
210}
211
212 void
213VCard::_assemble()
214{
215 vDebug("Assembling vcard");
216 strRep_ = "BEGIN:VCARD\r\n";
217 strRep_ += "VERSION:3.0\r\n";
218
219 QPtrListIterator<ContentLine> it(contentLineList_);
220
221 for (; it.current(); ++it)
222 strRep_ += it.current()->asString() + "\r\n";
223
224 strRep_ += "END:VCARD\r\n";
225}
226
227 bool
228VCard::has(EntityType t)
229{
230 parse();
231 return contentLine(t) == 0 ? false : true;
232}
233
234 bool
235VCard::has(const QCString & s)
236{
237 parse();
238 return contentLine(s) == 0 ? false : true;
239}
240
241 void
242VCard::add(const ContentLine & cl)
243{
244 parse();
245 ContentLine * c = new ContentLine(cl);
246 contentLineList_.append(c);
247}
248
249 void
250VCard::add(const QCString & s)
251{
252 parse();
253 ContentLine * c = new ContentLine(s);
254 contentLineList_.append(c);
255}
256
257 ContentLine *
258VCard::contentLine(EntityType t)
259{
260 parse();
261 QPtrListIterator<ContentLine> it(contentLineList_);
262
263 for (; it.current(); ++it)
264 if (it.current()->entityType() == t)
265 return it.current();
266
267 return 0;
268}
269
270 ContentLine *
271VCard::contentLine(const QCString & s)
272{
273 parse();
274 QPtrListIterator<ContentLine> it(contentLineList_);
275
276 for (; it.current(); ++it)
277 if (it.current()->entityType() == EntityNameToEntityType(s))
278 return it.current();
279
280 return 0;
281}
282
diff --git a/kabc/vcard/Value.cpp b/kabc/vcard/Value.cpp
new file mode 100644
index 0000000..1978af2
--- a/dev/null
+++ b/kabc/vcard/Value.cpp
@@ -0,0 +1,82 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <VCardEntity.h>
25#include <VCardValue.h>
26
27using namespace VCARD;
28
29Value::Value()
30 :Entity()
31{
32}
33
34Value::Value(const Value & x)
35 :Entity(x)
36{
37}
38
39Value::Value(const QCString & s)
40 :Entity(s)
41{
42}
43
44 Value &
45Value::operator = (Value & x)
46{
47 if (*this == x) return *this;
48
49 Entity::operator = (x);
50 return *this;
51}
52
53 Value &
54Value::operator = (const QCString & s)
55{
56 Entity::operator = (s);
57 return *this;
58}
59
60 bool
61Value::operator == (Value & x)
62{
63 x.parse();
64 return false;
65}
66
67Value::~Value()
68{
69}
70
71 void
72Value::_parse()
73{
74}
75
76 void
77Value::_assemble()
78{
79 //USvDebug("Value::_assemble()");
80 qDebug("Value::_assemble()");
81}
82
diff --git a/kabc/vcard/include/VCard.h b/kabc/vcard/include/VCard.h
new file mode 100644
index 0000000..17b50e8
--- a/dev/null
+++ b/kabc/vcard/include/VCard.h
@@ -0,0 +1,43 @@
1#ifndef VCARD_H
2#define VCARD_H
3
4#include "VCardAdrParam.h"
5#include "VCardAdrValue.h"
6#include "VCardAgentParam.h"
7#include "VCardAgentValue.h"
8#include "VCardClassValue.h"
9#include "VCardContentLine.h"
10#include "VCardDateParam.h"
11#include "VCardDateValue.h"
12#include "VCardDefines.h"
13#include "VCardEmailParam.h"
14#include "VCardEntity.h"
15#include "VCardEnum.h"
16#include "VCardFloatValue.h"
17#include "VCardGeoValue.h"
18#include "VCardGroup.h"
19#include "VCardImageParam.h"
20#include "VCardImageValue.h"
21#include "VCardImgValue.h"
22#include "VCardLangValue.h"
23#include "VCardNValue.h"
24#include "VCardOrgValue.h"
25#include "VCardParam.h"
26#include "VCardPhoneNumberValue.h"
27#include "VCardRToken.h"
28#include "VCardSoundValue.h"
29#include "VCardSourceParam.h"
30#include "VCardTelParam.h"
31#include "VCardTelValue.h"
32#include "VCardTextBinParam.h"
33#include "VCardTextBinValue.h"
34#include "VCardTextListValue.h"
35#include "VCardTextParam.h"
36#include "VCardTextValue.h"
37#include "VCardURIValue.h"
38#include "VCardUTCValue.h"
39#include "VCardVCard.h"
40#include "VCardVCardEntity.h"
41#include "VCardValue.h"
42
43#endif
diff --git a/kabc/vcard/include/VCardAdrParam.h b/kabc/vcard/include/VCardAdrParam.h
new file mode 100644
index 0000000..89dcb64
--- a/dev/null
+++ b/kabc/vcard/include/VCardAdrParam.h
@@ -0,0 +1,64 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef ADRPARAM_H
25#define ADRPARAM_H
26
27#include <qcstring.h>
28#include <qstrlist.h>
29
30#include <VCardParam.h>
31
32namespace VCARD
33{
34
35class AdrParam : public Param
36{
37
38#include "AdrParam-generated.h"
39
40 QStrList adrTypeList()
41 { parse(); return adrTypeList_; }
42
43 QCString textParam()
44 { parse(); return textParam_; }
45
46 void setAdrTypeList(const QStrList & l)
47 { adrTypeList_ = l; assembled_ = false; }
48
49 void setTextParam(const QCString & s)
50 { textParam_ = s; assembled_ = false; }
51
52 enum AdrType {
53 AdrDom, AdrIntl, AdrPostal, AdrParcel, AdrHome, AdrWork, AdrPref,
54 AdrIANA, AdrX
55 };
56
57 private:
58
59 QStrListadrTypeList_;
60 QCStringtextParam_;
61};
62}
63
64#endif
diff --git a/kabc/vcard/include/VCardAdrValue.h b/kabc/vcard/include/VCardAdrValue.h
new file mode 100644
index 0000000..0731924
--- a/dev/null
+++ b/kabc/vcard/include/VCardAdrValue.h
@@ -0,0 +1,83 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef ADRVALUE_H
25#define ADRVALUE_H
26
27#include <qstrlist.h>
28#include <VCardValue.h>
29
30namespace VCARD
31{
32
33class AdrValue : public Value
34{
35
36#include "AdrValue-generated.h"
37
38 AdrValue *clone();
39
40 void setPOBox(const QCString & s)
41 { poBox_ = s; assembled_ = false; }
42
43 void setExtAddress(const QCString & s)
44 { extAddress_ = s; assembled_ = false; }
45
46 void setStreet(const QCString & s)
47 { street_ = s; assembled_ = false; }
48
49 void setLocality(const QCString & s)
50 { locality_ = s; assembled_ = false; }
51
52 void setRegion(const QCString & s)
53 { region_ = s; assembled_ = false; }
54
55 void setPostCode(const QCString & s)
56 { postCode_ = s; assembled_ = false; }
57
58 void setCountryName(const QCString & s)
59 { countryName_ = s; assembled_ = false; }
60
61 QCString poBox() { parse(); return poBox_;}
62 QCString extAddress() { parse(); return extAddress_;}
63 QCString street() { parse(); return street_;}
64 QCString locality() { parse(); return locality_;}
65 QCString region() { parse(); return region_;}
66 QCString postCode() { parse(); return postCode_;}
67 QCString countryName() { parse(); return countryName_;}
68
69 private:
70
71 QCString poBox_;
72 QCString extAddress_;
73 QCString street_;
74 QCString locality_;
75 QCString region_;
76 QCString postCode_;
77 QCString countryName_;
78};
79
80}
81
82#endif
83
diff --git a/kabc/vcard/include/VCardAgentParam.h b/kabc/vcard/include/VCardAgentParam.h
new file mode 100644
index 0000000..72a05db
--- a/dev/null
+++ b/kabc/vcard/include/VCardAgentParam.h
@@ -0,0 +1,60 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef AGENTPARAM_H
25#define AGENTPARAM_H
26
27#include <qcstring.h>
28
29#include <VCardParam.h>
30#include <VCardURIValue.h>
31
32namespace VCARD
33{
34
35class AgentParam : public Param
36{
37
38#include "AgentParam-generated.h"
39
40 bool refer()
41 { parse(); return refer_; }
42
43 URIValue uri()
44 { parse(); return uri_; }
45
46 void setRefer(bool b)
47 { refer_ = b; assembled_ = false; }
48
49 void setURI(const QCString & s)
50 { uri_ = s; assembled_ = false; }
51
52 private:
53
54 bool refer_;
55 URIValueuri_;
56};
57
58}
59
60#endif
diff --git a/kabc/vcard/include/VCardAgentValue.h b/kabc/vcard/include/VCardAgentValue.h
new file mode 100644
index 0000000..f655836
--- a/dev/null
+++ b/kabc/vcard/include/VCardAgentValue.h
@@ -0,0 +1,44 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef AGENTVALUE_H
25#define AGENTVALUE_H
26
27#include <qcstring.h>
28
29#include <VCardValue.h>
30
31namespace VCARD
32{
33
34class AgentValue : public Value
35{
36
37#include "AgentValue-generated.h"
38
39 private:
40};
41
42}
43
44#endif
diff --git a/kabc/vcard/include/VCardClassValue.h b/kabc/vcard/include/VCardClassValue.h
new file mode 100644
index 0000000..ff133c2
--- a/dev/null
+++ b/kabc/vcard/include/VCardClassValue.h
@@ -0,0 +1,56 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef CLASSVALUE_H
25#define CLASSVALUE_H
26
27#include <qcstring.h>
28
29#include <VCardValue.h>
30
31#include <kdebug.h>
32
33namespace VCARD
34{
35
36class ClassValue : public Value
37{
38
39#include "ClassValue-generated.h"
40
41 enum ClassType {
42 Public, Private, Confidential, Other
43 };
44
45 ClassValue *clone();
46
47 void setType( int type ) { classType_ = type; assembled_ = false; parsed_ = true; }
48 int type() { parse(); return classType_; }
49
50 private:
51 int classType_;
52};
53
54}
55
56#endif
diff --git a/kabc/vcard/include/VCardContentLine.h b/kabc/vcard/include/VCardContentLine.h
new file mode 100644
index 0000000..1c5f5be
--- a/dev/null
+++ b/kabc/vcard/include/VCardContentLine.h
@@ -0,0 +1,77 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef CONTENTLINE_H
25#define CONTENTLINE_H
26
27#include <qptrlist.h>
28
29#include "VCardEnum.h"
30#include "VCardEntity.h"
31#include "VCardParam.h"
32#include "VCardValue.h"
33
34namespace VCARD
35{
36
37class ContentLine : public Entity
38{
39
40#include "ContentLine-generated.h"
41
42 QCString group() { parse(); return group_;}
43 QCString name() { parse(); return name_;}
44 Value * value() { parse(); return value_;}
45 ParamList paramList() { parse(); return paramList_;}
46 ParamType paramType() { parse(); return paramType_;}
47 ValueType valueType() { parse(); return valueType_;}
48 EntityType entityType() { parse(); return entityType_;}
49
50 void setGroup (const QCString & s)
51 { group_ = s; assembled_ = false; }
52
53 void setName (const QCString & s)
54 { name_ = s; assembled_ = false; }
55
56 void setValue (Value *s)
57 { value_ = s; assembled_ = false; }
58
59 void setParamList(const ParamList & l)
60 { paramList_ = l; assembled_ = false; }
61
62 void clear ();
63
64 private:
65
66 QCString group_;
67 QCString name_;
68 QPtrList<Param> paramList_;
69 Value * value_;
70
71 ParamType paramType_;
72 ValueType valueType_;
73 EntityType entityType_;
74};
75}
76
77#endif
diff --git a/kabc/vcard/include/VCardDateParam.h b/kabc/vcard/include/VCardDateParam.h
new file mode 100644
index 0000000..21ac1f1
--- a/dev/null
+++ b/kabc/vcard/include/VCardDateParam.h
@@ -0,0 +1,44 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef DATEPARAM_H
25#define DATEPARAM_H
26
27#include <qcstring.h>
28
29#include <VCardParam.h>
30
31namespace VCARD
32{
33
34class DateParam : public Param
35{
36
37#include "DateParam-generated.h"
38
39 private:
40};
41
42}
43
44#endif
diff --git a/kabc/vcard/include/VCardDateValue.h b/kabc/vcard/include/VCardDateValue.h
new file mode 100644
index 0000000..c248966
--- a/dev/null
+++ b/kabc/vcard/include/VCardDateValue.h
@@ -0,0 +1,99 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef DATEVALUE_H
25#define DATEVALUE_H
26
27#include <qcstring.h>
28#include <qdatetime.h>
29
30#include <VCardValue.h>
31
32namespace VCARD
33{
34
35class DateValue : public Value
36{
37#include "DateValue-generated.h"
38
39 DateValue(
40 unsigned intyear,
41 unsigned intmonth,
42 unsigned intday,
43 unsigned inthour = 0,
44 unsigned intminute = 0,
45 unsigned intsecond = 0,
46 double secFrac = 0,
47 bool zonePositive = true,
48 unsigned intzoneHour = 0,
49 unsigned intzoneMinute = 0);
50
51 DateValue(const QDate &);
52 DateValue(const QDateTime &);
53
54 DateValue *clone();
55
56 bool hasTime();
57
58 unsigned intyear();
59 unsigned intmonth();
60 unsigned intday();
61 unsigned inthour();
62 unsigned intminute();
63 unsigned intsecond();
64 double secondFraction();
65 bool zonePositive();
66 unsigned intzoneHour();
67 unsigned intzoneMinute();
68
69 void setYear (unsigned int);
70 void setMonth (unsigned int);
71 void setDay (unsigned int);
72 void setHour (unsigned int);
73 void setMinute (unsigned int);
74 void setSecond (unsigned int);
75 void setSecondFraction(double);
76 void setZonePositive(bool);
77 void setZoneHour (unsigned int);
78 void setZoneMinute (unsigned int);
79
80 QDate qdate();
81 QTime qtime();
82 QDateTime qdt();
83
84 private:
85
86 unsigned intyear_, month_, day_,
87 hour_, minute_, second_,
88 zoneHour_, zoneMinute_;
89
90 double secFrac_;
91
92 bool zonePositive_;
93
94 bool hasTime_;
95};
96
97}
98
99#endif
diff --git a/kabc/vcard/include/VCardDefines.h b/kabc/vcard/include/VCardDefines.h
new file mode 100644
index 0000000..dd38ae2
--- a/dev/null
+++ b/kabc/vcard/include/VCardDefines.h
@@ -0,0 +1,52 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef VCARD_DEFINES_H
25#define VCARD_DEFINES_H
26
27#include <kdebug.h>
28
29#ifdef VCARD_DEBUG
30#define vDebug(a) kdDebug(5710) << a << endl;
31#else
32#define vDebug(a)
33#endif
34
35#if 0
36#ifndef NDEBUG
37 #include <qcstring.h>
38 #include <iostream>
39 #ifdef __GNUG__
40 # define vDebug(a) cerr << className() << ":" << __FUNCTION__ << " (" \
41 << __LINE__ << "): " << QCString((a)).data() << endl;
42 #else
43 # define vDebug(a) cerr << className() << ": " \
44 << QCString((a)).data() << endl;
45 #endif
46#else
47 #define vDebug(a)
48#endif
49#endif
50
51#endif // Included this file
52
diff --git a/kabc/vcard/include/VCardEmailParam.h b/kabc/vcard/include/VCardEmailParam.h
new file mode 100644
index 0000000..98d1b30
--- a/dev/null
+++ b/kabc/vcard/include/VCardEmailParam.h
@@ -0,0 +1,56 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef EMAILPARAM_H
25#define EMAILPARAM_H
26
27#include <qcstring.h>
28
29#include <VCardParam.h>
30
31namespace VCARD
32{
33
34class EmailParam : public Param
35{
36
37#include "EmailParam-generated.h"
38
39 QCString emailType() { parse(); return emailType_;}
40 bool pref() { parse(); return pref_; }
41
42 void setEmailType(const QCString & s)
43 { emailType_ = s; assembled_ = false; }
44
45 void setPref(bool b)
46 { pref_ = b; assembled_ = false; }
47
48 private:
49
50 QCStringemailType_;
51 bool pref_;
52};
53
54}
55
56#endif
diff --git a/kabc/vcard/include/VCardEntity.h b/kabc/vcard/include/VCardEntity.h
new file mode 100644
index 0000000..3c945b5
--- a/dev/null
+++ b/kabc/vcard/include/VCardEntity.h
@@ -0,0 +1,67 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef ENTITY_H
25#define ENTITY_H
26
27#include <qcstring.h>
28
29namespace VCARD
30{
31
32class Entity
33{
34 public:
35
36 Entity();
37 Entity(const Entity & e);
38 Entity(const QCString & s);
39
40 virtual Entity & operator = (const Entity & e);
41 virtual Entity & operator = (const QCString & s);
42
43 virtual bool operator == (Entity & e);
44 virtual bool operator != (Entity & e);
45 virtual bool operator == (const QCString & s);
46 virtual bool operator != (const QCString & s);
47
48 virtual ~Entity();
49
50 QCString asString();
51
52 virtual void parse();
53 virtual void assemble();
54
55 virtual void _parse() = 0;
56 virtual void _assemble() = 0;
57
58 protected:
59
60 QCString strRep_;
61 bool parsed_;
62 bool assembled_;
63};
64
65}
66
67#endif
diff --git a/kabc/vcard/include/VCardEnum.h b/kabc/vcard/include/VCardEnum.h
new file mode 100644
index 0000000..b4e4094
--- a/dev/null
+++ b/kabc/vcard/include/VCardEnum.h
@@ -0,0 +1,120 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef ENUM_H
25#define ENUM_H
26
27#include <qcstring.h>
28
29namespace VCARD
30{
31
32extern const QCString paramNames [];
33
34enum EntityType {
35 EntityName,
36 EntityProfile,
37 EntitySource,
38 EntityFullName,
39 EntityN,
40 EntityNickname,
41 EntityPhoto,
42 EntityBirthday,
43 EntityAddress,
44 EntityLabel,
45 EntityTelephone,
46 EntityEmail,
47 EntityMailer,
48 EntityTimeZone,
49 EntityGeo,
50 EntityTitle,
51 EntityRole,
52 EntityLogo,
53 EntityAgent,
54 EntityOrganisation,
55 EntityCategories,
56 EntityNote,
57 EntityProductID,
58 EntityRevision,
59 EntitySortString,
60 EntitySound,
61 EntityUID,
62 EntityURL,
63 EntityVersion,
64 EntityClass,
65 EntityKey,
66 EntityExtension,
67 EntityUnknown
68};
69
70enum ValueType {
71 ValueSound,
72 ValueAgent,
73 ValueAddress,
74 ValueTel,
75 ValueTextBin,
76 ValueOrg,
77 ValueN,
78 ValueUTC,
79 ValueURI,
80 ValueClass,
81 ValueFloat,
82 ValueImage,
83 ValueDate,
84 ValueTextList,
85 ValueText,
86 ValueGeo,
87 ValueUnknown
88};
89
90enum ParamType {
91 ParamUnknown,
92 ParamNone,
93 ParamSource,
94 ParamText,
95 ParamImage,
96 ParamDate,
97 ParamAddrText,
98 ParamTel,
99 ParamEmail,
100 ParamMailer,
101 ParamAgent,
102 ParamTextBin,
103 ParamTextNS,
104 ParamSound
105};
106
107extern const ParamType paramTypesTable[];
108
109ParamType EntityTypeToParamType(EntityType);
110ValueType EntityTypeToValueType(EntityType);
111QCString EntityTypeToParamName(EntityType);
112EntityType EntityNameToEntityType(const QCString &);
113
114char * encodeBase64(const char *, unsigned long, unsigned long &);
115char * decodeBase64(const char *, unsigned long, unsigned long &);
116
117}
118
119#endif
120
diff --git a/kabc/vcard/include/VCardFloatValue.h b/kabc/vcard/include/VCardFloatValue.h
new file mode 100644
index 0000000..69fdc22
--- a/dev/null
+++ b/kabc/vcard/include/VCardFloatValue.h
@@ -0,0 +1,51 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef FLOATVALUE_H
25#define FLOATVALUE_H
26
27#include <qcstring.h>
28
29#include <VCardValue.h>
30
31namespace VCARD
32{
33
34class FloatValue : public Value
35{
36
37#include "FloatValue-generated.h"
38
39 FloatValue(float);
40
41 float value();
42 void setValue(float);
43
44 private:
45
46 float value_;
47};
48
49}
50
51#endif
diff --git a/kabc/vcard/include/VCardGeoValue.h b/kabc/vcard/include/VCardGeoValue.h
new file mode 100644
index 0000000..662761c
--- a/dev/null
+++ b/kabc/vcard/include/VCardGeoValue.h
@@ -0,0 +1,49 @@
1/*
2 This file is part of libvcard.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef GEOVALUE_H
22#define GEOVALUE_H
23
24#include <VCardValue.h>
25
26namespace VCARD
27{
28
29class GeoValue : public Value
30{
31
32#include "GeoValue-generated.h"
33
34 GeoValue *clone();
35
36 void setLatitude( float lat ) { latitude_ = lat; assembled_ = false; }
37 void setLongitude( float lon ) { longitude_ = lon; assembled_ = false; }
38
39 float latitude() { parse(); return latitude_; }
40 float longitude() { parse(); return longitude_; }
41
42 private:
43 float latitude_;
44 float longitude_;
45};
46
47}
48
49#endif
diff --git a/kabc/vcard/include/VCardGroup.h b/kabc/vcard/include/VCardGroup.h
new file mode 100644
index 0000000..ff775fb
--- a/dev/null
+++ b/kabc/vcard/include/VCardGroup.h
@@ -0,0 +1,39 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef GROUP_H
25#define GROUP_H
26
27#include <VCardEntity.h>
28
29namespace VCARD
30{
31
32class Group : public Entity
33{
34#include "Group-generated.h"
35};
36
37}
38
39#endif
diff --git a/kabc/vcard/include/VCardImageParam.h b/kabc/vcard/include/VCardImageParam.h
new file mode 100644
index 0000000..ce99ccc
--- a/dev/null
+++ b/kabc/vcard/include/VCardImageParam.h
@@ -0,0 +1,44 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef IMGPARAM_H
25#define IMGPARAM_H
26
27#include <qcstring.h>
28
29#include <VCardParam.h>
30
31namespace VCARD
32{
33
34class ImageParam : public Param
35{
36
37#include "ImageParam-generated.h"
38
39 private:
40};
41
42}
43
44#endif
diff --git a/kabc/vcard/include/VCardImageValue.h b/kabc/vcard/include/VCardImageValue.h
new file mode 100644
index 0000000..6ce0371
--- a/dev/null
+++ b/kabc/vcard/include/VCardImageValue.h
@@ -0,0 +1,44 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef IMAGEVALUE_H
25#define IMAGEVALUE_H
26
27#include <qcstring.h>
28
29#include <VCardValue.h>
30
31namespace VCARD
32{
33
34class ImageValue : public Value
35{
36
37#include "ImageValue-generated.h"
38
39 private:
40};
41
42}
43
44#endif
diff --git a/kabc/vcard/include/VCardImgValue.h b/kabc/vcard/include/VCardImgValue.h
new file mode 100644
index 0000000..b09ad64
--- a/dev/null
+++ b/kabc/vcard/include/VCardImgValue.h
@@ -0,0 +1,39 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef IMGVALUE_H
25#define IMGVALUE_H
26
27#include <VCardValue.h>
28
29namespace VCARD
30{
31
32class ImgValue : public Value
33{
34#include "ImgValue-generated.h"
35};
36
37}
38
39#endif
diff --git a/kabc/vcard/include/VCardLangValue.h b/kabc/vcard/include/VCardLangValue.h
new file mode 100644
index 0000000..991ceed
--- a/dev/null
+++ b/kabc/vcard/include/VCardLangValue.h
@@ -0,0 +1,51 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef LANGVALUE_H
25#define LANGVALUE_H
26
27#include <qcstring.h>
28#include <qstrlist.h>
29
30#include <VCardValue.h>
31
32namespace VCARD
33{
34
35class LangValue : public Value
36{
37#include "LangValue-generated.h"
38
39 QCString primary();
40 QStrList subtags();
41
42 void setPrimary(const QCString &);
43 void setSubTags(const QStrList &);
44
45 QCString primary_;
46 QStrList subtags_;
47};
48
49}
50
51#endif
diff --git a/kabc/vcard/include/VCardNValue.h b/kabc/vcard/include/VCardNValue.h
new file mode 100644
index 0000000..306821b
--- a/dev/null
+++ b/kabc/vcard/include/VCardNValue.h
@@ -0,0 +1,56 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef NVALUE_H
25#define NVALUE_H
26
27#include <VCardValue.h>
28
29namespace VCARD
30{
31
32class NValue : public Value
33{
34#include "NValue-generated.h"
35 NValue *clone();
36
37 QCString family() { parse(); return family_;}
38 QCString given() { parse(); return given_;}
39 QCString middle() { parse(); return middle_;}
40 QCString prefix() { parse(); return prefix_;}
41 QCString suffix() { parse(); return suffix_;}
42
43 void setFamily (const QCString & s) { family_= s; assembled_ = false; }
44 void setGiven (const QCString & s) { given_= s; assembled_ = false; }
45 void setMiddle (const QCString & s) { middle_= s; assembled_ = false; }
46 void setPrefix (const QCString & s) { prefix_= s; assembled_ = false; }
47 void setSuffix (const QCString & s) { suffix_= s; assembled_ = false; }
48
49 private:
50
51 QCString family_, given_, middle_, prefix_, suffix_;
52};
53
54}
55
56#endif
diff --git a/kabc/vcard/include/VCardOrgValue.h b/kabc/vcard/include/VCardOrgValue.h
new file mode 100644
index 0000000..c4f3f25
--- a/dev/null
+++ b/kabc/vcard/include/VCardOrgValue.h
@@ -0,0 +1,50 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef ORGVALUE_H
25#define ORGVALUE_H
26
27#include <qcstring.h>
28#include <qstrlist.h>
29
30#include <VCardValue.h>
31
32namespace VCARD
33{
34
35class OrgValue : public Value
36{
37
38#include "OrgValue-generated.h"
39
40 unsigned int numValues();
41 QCString value(unsigned int);
42
43 private:
44
45 QStrList valueList_;
46};
47
48}
49
50#endif
diff --git a/kabc/vcard/include/VCardParam.h b/kabc/vcard/include/VCardParam.h
new file mode 100644
index 0000000..b61ce5c
--- a/dev/null
+++ b/kabc/vcard/include/VCardParam.h
@@ -0,0 +1,59 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef PARAM_H
25#define PARAM_H
26
27#include <qcstring.h>
28#include <qptrlist.h>
29
30#include <VCardEntity.h>
31
32namespace VCARD
33{
34
35class Param : public Entity
36{
37
38#include "Param-generated.h"
39
40 Param(const QCString &name, const QCString &value);
41
42 void setName(const QCString &);
43 void setValue(const QCString &);
44
45 QCString name();
46 QCString value();
47
48 private:
49
50 QCString name_;
51 QCString value_;
52};
53
54typedef QPtrList<Param> ParamList;
55typedef QPtrListIterator<Param> ParamListIterator;
56
57}
58
59#endif
diff --git a/kabc/vcard/include/VCardPhoneNumberValue.h b/kabc/vcard/include/VCardPhoneNumberValue.h
new file mode 100644
index 0000000..a567bdc
--- a/dev/null
+++ b/kabc/vcard/include/VCardPhoneNumberValue.h
@@ -0,0 +1,39 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef PHONENUMBERVALUE_H
25#define PHONENUMBERVALUE_H
26
27#include <VCardValue.h>
28
29namespace VCARD
30{
31
32class PhoneNumberValue : public Value
33{
34#include "PhoneNumberValue-generated.h"
35};
36
37}
38
39#endif
diff --git a/kabc/vcard/include/VCardRToken.h b/kabc/vcard/include/VCardRToken.h
new file mode 100644
index 0000000..2f95f1b
--- a/dev/null
+++ b/kabc/vcard/include/VCardRToken.h
@@ -0,0 +1,38 @@
1/*
2
3 libvcard - vCard parsing library for vCard version 3.0
4
5 Copyright (C) 1999 Rik Hemsley rik@kde.org
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to
9 deal in the Software without restriction, including without limitation the
10 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 sell copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25#ifndef RTOKEN_H
26#define RTOKEN_H
27
28#include <qstrlist.h>
29
30namespace VCARD
31{
32
33Q_UINT32 RTokenise(const char * str, const char * delim, QStrList & l);
34
35}
36
37#endif
38
diff --git a/kabc/vcard/include/VCardSndValue.h b/kabc/vcard/include/VCardSndValue.h
new file mode 100644
index 0000000..ce56221
--- a/dev/null
+++ b/kabc/vcard/include/VCardSndValue.h
@@ -0,0 +1,39 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef SNDVALUE_H
25#define SNDVALUE_H
26
27#include <VCardValue.h>
28
29namespace VCARD
30{
31
32class SndValue : public Value
33{
34#include "SndValue-generated.h"
35};
36
37}
38
39#endif
diff --git a/kabc/vcard/include/VCardSoundValue.h b/kabc/vcard/include/VCardSoundValue.h
new file mode 100644
index 0000000..994f55e
--- a/dev/null
+++ b/kabc/vcard/include/VCardSoundValue.h
@@ -0,0 +1,44 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef SOUNDVALUE_H
25#define SOUNDVALUE_H
26
27#include <qcstring.h>
28
29#include <VCardValue.h>
30
31namespace VCARD
32{
33
34class SoundValue : public Value
35{
36
37#include "SoundValue-generated.h"
38
39 private:
40};
41
42}
43
44#endif
diff --git a/kabc/vcard/include/VCardSourceParam.h b/kabc/vcard/include/VCardSourceParam.h
new file mode 100644
index 0000000..887ea20
--- a/dev/null
+++ b/kabc/vcard/include/VCardSourceParam.h
@@ -0,0 +1,58 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef SOURCEPARAM_H
25#define SOURCEPARAM_H
26
27#include <qcstring.h>
28
29#include <VCardParam.h>
30
31namespace VCARD
32{
33
34class SourceParam : public Param
35{
36
37#include "SourceParam-generated.h"
38
39 enum SourceParamType { TypeUnknown, TypeValue, TypeContext, TypeX };
40
41 SourceParamType type(){ parse(); return type_;}
42 QCString par() { parse(); return par_; }
43 QCString val() { parse(); return val_; }
44
45 void setType(SourceParamType t) { type_= t; assembled_ = false; }
46 void setPar(const QCString & s) { par_= s; assembled_ = false; }
47 void setVal(const QCString & s) { val_= s; assembled_ = false; }
48
49 private:
50
51 SourceParamType type_;
52 // May be "VALUE = uri" or "CONTEXT = word" or "x-name = *SAFE-CHAR"
53 QCString par_, val_; // Sub-parameter, value
54};
55
56}
57
58#endif
diff --git a/kabc/vcard/include/VCardTelParam.h b/kabc/vcard/include/VCardTelParam.h
new file mode 100644
index 0000000..27d7dcc
--- a/dev/null
+++ b/kabc/vcard/include/VCardTelParam.h
@@ -0,0 +1,51 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef TELPARAM_H
25#define TELPARAM_H
26
27#include <qcstring.h>
28
29#include <VCardParam.h>
30
31namespace VCARD
32{
33
34class TelParam : public Param
35{
36#include "TelParam-generated.h"
37
38 enum TelType {
39 TelHome, TelWork, TelPref, TelVoice, TelFex, TelMsg, TelCell,
40 TelPager, TelBBS, TelModem, TelCar, TelISDN, TelVideo, TelPCS,
41 TelIANA, TelX
42 };
43
44 private:
45
46 QPtrList<TelType> types_;
47};
48
49}
50
51#endif
diff --git a/kabc/vcard/include/VCardTelValue.h b/kabc/vcard/include/VCardTelValue.h
new file mode 100644
index 0000000..9cf5a98
--- a/dev/null
+++ b/kabc/vcard/include/VCardTelValue.h
@@ -0,0 +1,44 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef TELVALUE_H
25#define TELVALUE_H
26
27#include <qcstring.h>
28
29#include <VCardValue.h>
30
31namespace VCARD
32{
33
34class TelValue : public Value
35{
36
37#include "TelValue-generated.h"
38
39 private:
40};
41
42}
43
44#endif
diff --git a/kabc/vcard/include/VCardTextBinParam.h b/kabc/vcard/include/VCardTextBinParam.h
new file mode 100644
index 0000000..31dec86
--- a/dev/null
+++ b/kabc/vcard/include/VCardTextBinParam.h
@@ -0,0 +1,44 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef TEXTBINPARAM_H
25#define TEXTBINPARAM_H
26
27#include <qcstring.h>
28
29#include <VCardParam.h>
30
31namespace VCARD
32{
33
34class TextBinParam : public Param
35{
36
37#include "TextBinParam-generated.h"
38
39 private:
40};
41
42}
43
44#endif
diff --git a/kabc/vcard/include/VCardTextBinValue.h b/kabc/vcard/include/VCardTextBinValue.h
new file mode 100644
index 0000000..8d44fdf
--- a/dev/null
+++ b/kabc/vcard/include/VCardTextBinValue.h
@@ -0,0 +1,67 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef TEXTBINVALUE_H
25#define TEXTBINVALUE_H
26
27#include <qcstring.h>
28
29#include <VCardValue.h>
30
31namespace VCARD
32{
33
34class TextBinValue : public Value
35{
36
37#include "TextBinValue-generated.h"
38
39 TextBinValue *clone();
40
41 bool isBinary() { parse(); return mIsBinary_; }
42 QByteArray data() { parse(); return mData_; }
43 QString url() { parse(); return mUrl_; }
44
45 void setData( const QByteArray &data )
46 {
47 mData_ = data;
48 mIsBinary_ = true;
49 assembled_ = false;
50 }
51
52 void setUrl( const QString &url )
53 {
54 mUrl_ = url;
55 mIsBinary_ = false;
56 assembled_ = false;
57 }
58
59 private:
60 int mIsBinary_;
61 QByteArray mData_;
62 QString mUrl_;
63};
64
65}
66
67#endif
diff --git a/kabc/vcard/include/VCardTextListValue.h b/kabc/vcard/include/VCardTextListValue.h
new file mode 100644
index 0000000..8e47af5
--- a/dev/null
+++ b/kabc/vcard/include/VCardTextListValue.h
@@ -0,0 +1,51 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef TEXTLISTVALUE_H
25#define TEXTLISTVALUE_H
26
27#include <qstrlist.h>
28
29#include <qcstring.h>
30
31#include <VCardValue.h>
32
33namespace VCARD
34{
35
36class TextListValue : public Value
37{
38
39#include "TextListValue-generated.h"
40
41 unsigned int numValues();
42 QCString value(unsigned int);
43
44 private:
45
46 QStrList valueList_;
47};
48
49}
50
51#endif
diff --git a/kabc/vcard/include/VCardTextParam.h b/kabc/vcard/include/VCardTextParam.h
new file mode 100644
index 0000000..08b5f57
--- a/dev/null
+++ b/kabc/vcard/include/VCardTextParam.h
@@ -0,0 +1,44 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef TEXTPARAM_H
25#define TEXTPARAM_H
26
27#include <qcstring.h>
28
29#include <VCardParam.h>
30
31namespace VCARD
32{
33
34class TextParam : public Param
35{
36
37#include "TextParam-generated.h"
38
39 private:
40};
41
42}
43
44#endif
diff --git a/kabc/vcard/include/VCardTextValue.h b/kabc/vcard/include/VCardTextValue.h
new file mode 100644
index 0000000..afe8753
--- a/dev/null
+++ b/kabc/vcard/include/VCardTextValue.h
@@ -0,0 +1,41 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef TEXTVALUE_H
25#define TEXTVALUE_H
26
27#include <VCardValue.h>
28
29namespace VCARD
30{
31
32class TextValue : public Value
33{
34#include "TextValue-generated.h"
35
36 TextValue *clone();
37};
38
39}
40
41#endif
diff --git a/kabc/vcard/include/VCardURIValue.h b/kabc/vcard/include/VCardURIValue.h
new file mode 100644
index 0000000..5fd7184
--- a/dev/null
+++ b/kabc/vcard/include/VCardURIValue.h
@@ -0,0 +1,52 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef URIVALUE_H
25#define URIVALUE_H
26
27#include <VCardValue.h>
28
29namespace VCARD
30{
31
32class URIValue : public Value
33{
34#include "URIValue-generated.h"
35
36 URIValue(const QCString & scheme, const QCString & schemeSpecificPart);
37
38 QCString scheme();
39 QCString schemeSpecificPart();
40
41 void setScheme (const QCString &);
42 void setSchemeSpecificPart(const QCString &);
43
44 private:
45
46 QCString scheme_;
47 QCString schemeSpecificPart_;
48};
49
50}
51
52#endif
diff --git a/kabc/vcard/include/VCardUTCValue.h b/kabc/vcard/include/VCardUTCValue.h
new file mode 100644
index 0000000..ff695e0
--- a/dev/null
+++ b/kabc/vcard/include/VCardUTCValue.h
@@ -0,0 +1,58 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef UTCVALUE_H
25#define UTCVALUE_H
26
27#include <qcstring.h>
28
29#include <VCardValue.h>
30
31namespace VCARD
32{
33
34class UTCValue : public Value
35{
36
37#include "UTCValue-generated.h"
38
39 UTCValue *clone();
40
41 void setPositive( int p ) { positive_ = p; assembled_ = false; }
42 void setHour( int h ) { hour_ = h; assembled_ = false; }
43 void setMinute( int m ) { minute_ = m; assembled_ = false; }
44
45 bool positive() { parse(); return positive_; }
46 unsigned int hour() { parse(); return hour_; }
47 unsigned int minute() { parse(); return minute_; }
48
49 private:
50
51 bool positive_;
52 unsigned int hour_;
53 unsigned int minute_;
54};
55
56}
57
58#endif
diff --git a/kabc/vcard/include/VCardVCard.h b/kabc/vcard/include/VCardVCard.h
new file mode 100644
index 0000000..5dec166
--- a/dev/null
+++ b/kabc/vcard/include/VCardVCard.h
@@ -0,0 +1,63 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef VCARD_VCARD_H
25#define VCARD_VCARD_H
26
27#include <qstring.h>
28#include <qptrlist.h>
29
30#include <VCardEnum.h>
31#include <VCardEntity.h>
32#include <VCardContentLine.h>
33
34namespace VCARD
35{
36
37class VCard : public Entity
38{
39
40#include "VCard-generated.h"
41
42 bool has(EntityType);
43 bool has(const QCString &);
44
45 void add(const ContentLine &);
46 void add(const QCString &);
47
48 ContentLine * contentLine(EntityType);
49 ContentLine * contentLine(const QCString &);
50
51 QCString group() { parse(); return group_; }
52
53 QPtrList<ContentLine>contentLineList() { parse(); return contentLineList_; }
54
55 private:
56
57 QCString group_;
58 QPtrList<ContentLine>contentLineList_;
59};
60
61}
62
63#endif
diff --git a/kabc/vcard/include/VCardVCardEntity.h b/kabc/vcard/include/VCardVCardEntity.h
new file mode 100644
index 0000000..47ba370
--- a/dev/null
+++ b/kabc/vcard/include/VCardVCardEntity.h
@@ -0,0 +1,56 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef VCARD_ENTITY_H
25#define VCARD_ENTITY_H
26
27#include <qstring.h>
28#include <qptrlist.h>
29
30#include <VCardEnum.h>
31#include <VCardVCard.h>
32#include <VCardEntity.h>
33
34namespace VCARD
35{
36
37typedef QPtrList<VCard> VCardList;
38typedef QPtrListIterator<VCard> VCardListIterator;
39
40class VCardEntity : public Entity
41{
42
43#include "VCardEntity-generated.h"
44
45 void setCardList(const VCardList & l);
46 VCardList & cardList();
47
48 private:
49
50 VCardList cardList_;
51
52};
53
54}
55
56#endif
diff --git a/kabc/vcard/include/VCardValue.h b/kabc/vcard/include/VCardValue.h
new file mode 100644
index 0000000..7cfe4a0
--- a/dev/null
+++ b/kabc/vcard/include/VCardValue.h
@@ -0,0 +1,46 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#ifndef VALUE_H
25#define VALUE_H
26
27#include <qptrlist.h>
28
29#include <VCardEntity.h>
30
31namespace VCARD
32{
33
34class Value : public Entity
35{
36#include "Value-generated.h"
37
38 virtual Value *clone() { return new Value( *this ); }
39};
40
41typedef QPtrList<Value> ValueList;
42typedef QPtrListIterator<Value> ValueListIterator;
43
44}
45
46#endif
diff --git a/kabc/vcard/include/generated/AdrParam-generated.h b/kabc/vcard/include/generated/AdrParam-generated.h
new file mode 100644
index 0000000..3e265d8
--- a/dev/null
+++ b/kabc/vcard/include/generated/AdrParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4AdrParam();
5AdrParam(const AdrParam&);
6AdrParam(const QCString&);
7AdrParam & operator = (AdrParam&);
8AdrParam & operator = (const QCString&);
9bool operator ==(AdrParam&);
10bool operator !=(AdrParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {AdrParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~AdrParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "AdrParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/AdrValue-generated.h b/kabc/vcard/include/generated/AdrValue-generated.h
new file mode 100644
index 0000000..e1d93e4
--- a/dev/null
+++ b/kabc/vcard/include/generated/AdrValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4AdrValue();
5AdrValue(const AdrValue&);
6AdrValue(const QCString&);
7AdrValue & operator = (AdrValue&);
8AdrValue & operator = (const QCString&);
9bool operator ==(AdrValue&);
10bool operator !=(AdrValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {AdrValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~AdrValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "AdrValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/AgentParam-generated.h b/kabc/vcard/include/generated/AgentParam-generated.h
new file mode 100644
index 0000000..6423867
--- a/dev/null
+++ b/kabc/vcard/include/generated/AgentParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4AgentParam();
5AgentParam(const AgentParam&);
6AgentParam(const QCString&);
7AgentParam & operator = (AgentParam&);
8AgentParam & operator = (const QCString&);
9bool operator ==(AgentParam&);
10bool operator !=(AgentParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {AgentParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~AgentParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "AgentParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/AgentValue-generated.h b/kabc/vcard/include/generated/AgentValue-generated.h
new file mode 100644
index 0000000..76bb81c
--- a/dev/null
+++ b/kabc/vcard/include/generated/AgentValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4AgentValue();
5AgentValue(const AgentValue&);
6AgentValue(const QCString&);
7AgentValue & operator = (AgentValue&);
8AgentValue & operator = (const QCString&);
9bool operator ==(AgentValue&);
10bool operator !=(AgentValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {AgentValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~AgentValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "AgentValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/ClassValue-generated.h b/kabc/vcard/include/generated/ClassValue-generated.h
new file mode 100644
index 0000000..df4ed5f
--- a/dev/null
+++ b/kabc/vcard/include/generated/ClassValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4ClassValue();
5ClassValue(const ClassValue&);
6ClassValue(const QCString&);
7ClassValue & operator = (ClassValue&);
8ClassValue & operator = (const QCString&);
9bool operator ==(ClassValue&);
10bool operator !=(ClassValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {ClassValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~ClassValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "ClassValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/ContentLine-generated.h b/kabc/vcard/include/generated/ContentLine-generated.h
new file mode 100644
index 0000000..9efe273
--- a/dev/null
+++ b/kabc/vcard/include/generated/ContentLine-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4ContentLine();
5ContentLine(const ContentLine&);
6ContentLine(const QCString&);
7ContentLine & operator = (ContentLine&);
8ContentLine & operator = (const QCString&);
9bool operator ==(ContentLine&);
10bool operator !=(ContentLine& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {ContentLine a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~ContentLine();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "ContentLine"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/DateParam-generated.h b/kabc/vcard/include/generated/DateParam-generated.h
new file mode 100644
index 0000000..ff1da58
--- a/dev/null
+++ b/kabc/vcard/include/generated/DateParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4DateParam();
5DateParam(const DateParam&);
6DateParam(const QCString&);
7DateParam & operator = (DateParam&);
8DateParam & operator = (const QCString&);
9bool operator ==(DateParam&);
10bool operator !=(DateParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {DateParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~DateParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "DateParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/DateValue-generated.h b/kabc/vcard/include/generated/DateValue-generated.h
new file mode 100644
index 0000000..a382823
--- a/dev/null
+++ b/kabc/vcard/include/generated/DateValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4DateValue();
5DateValue(const DateValue&);
6DateValue(const QCString&);
7DateValue & operator = (DateValue&);
8DateValue & operator = (const QCString&);
9bool operator ==(DateValue&);
10bool operator !=(DateValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {DateValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~DateValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "DateValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/EmailParam-generated.h b/kabc/vcard/include/generated/EmailParam-generated.h
new file mode 100644
index 0000000..428a6fc
--- a/dev/null
+++ b/kabc/vcard/include/generated/EmailParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4EmailParam();
5EmailParam(const EmailParam&);
6EmailParam(const QCString&);
7EmailParam & operator = (EmailParam&);
8EmailParam & operator = (const QCString&);
9bool operator ==(EmailParam&);
10bool operator !=(EmailParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {EmailParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~EmailParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "EmailParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/FloatValue-generated.h b/kabc/vcard/include/generated/FloatValue-generated.h
new file mode 100644
index 0000000..cac55cf
--- a/dev/null
+++ b/kabc/vcard/include/generated/FloatValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4FloatValue();
5FloatValue(const FloatValue&);
6FloatValue(const QCString&);
7FloatValue & operator = (FloatValue&);
8FloatValue & operator = (const QCString&);
9bool operator ==(FloatValue&);
10bool operator !=(FloatValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {FloatValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~FloatValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "FloatValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/GeoValue-generated.h b/kabc/vcard/include/generated/GeoValue-generated.h
new file mode 100644
index 0000000..594f3ad
--- a/dev/null
+++ b/kabc/vcard/include/generated/GeoValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4GeoValue();
5GeoValue(const GeoValue&);
6GeoValue(const QCString&);
7GeoValue & operator = (GeoValue&);
8GeoValue & operator = (const QCString&);
9bool operator ==(GeoValue&);
10bool operator !=(GeoValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {GeoValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~GeoValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "GeoValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/Group-generated.h b/kabc/vcard/include/generated/Group-generated.h
new file mode 100644
index 0000000..f39302d
--- a/dev/null
+++ b/kabc/vcard/include/generated/Group-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4Group();
5Group(const Group&);
6Group(const QCString&);
7Group & operator = (Group&);
8Group & operator = (const QCString&);
9bool operator ==(Group&);
10bool operator !=(Group& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {Group a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~Group();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "Group"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/ImageParam-generated.h b/kabc/vcard/include/generated/ImageParam-generated.h
new file mode 100644
index 0000000..81edfd2
--- a/dev/null
+++ b/kabc/vcard/include/generated/ImageParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4ImageParam();
5ImageParam(const ImageParam&);
6ImageParam(const QCString&);
7ImageParam & operator = (ImageParam&);
8ImageParam & operator = (const QCString&);
9bool operator ==(ImageParam&);
10bool operator !=(ImageParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {ImageParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~ImageParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "ImageParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/ImageValue-generated.h b/kabc/vcard/include/generated/ImageValue-generated.h
new file mode 100644
index 0000000..5a2c493
--- a/dev/null
+++ b/kabc/vcard/include/generated/ImageValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4ImageValue();
5ImageValue(const ImageValue&);
6ImageValue(const QCString&);
7ImageValue & operator = (ImageValue&);
8ImageValue & operator = (const QCString&);
9bool operator ==(ImageValue&);
10bool operator !=(ImageValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {ImageValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~ImageValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "ImageValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/ImgParam-generated.h b/kabc/vcard/include/generated/ImgParam-generated.h
new file mode 100644
index 0000000..46a6ca0
--- a/dev/null
+++ b/kabc/vcard/include/generated/ImgParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4ImgParam();
5ImgParam(const ImgParam&);
6ImgParam(const QCString&);
7ImgParam & operator = (ImgParam&);
8ImgParam & operator = (const QCString&);
9bool operator ==(ImgParam&);
10bool operator !=(ImgParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {ImgParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~ImgParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21virtual const char * className() const { return "ImgParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/ImgValue-generated.h b/kabc/vcard/include/generated/ImgValue-generated.h
new file mode 100644
index 0000000..d75d545
--- a/dev/null
+++ b/kabc/vcard/include/generated/ImgValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4ImgValue();
5ImgValue(const ImgValue&);
6ImgValue(const QCString&);
7ImgValue & operator = (ImgValue&);
8ImgValue & operator = (const QCString&);
9bool operator ==(ImgValue&);
10bool operator !=(ImgValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {ImgValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~ImgValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21virtual const char * className() const { return "ImgValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/LangValue-generated.h b/kabc/vcard/include/generated/LangValue-generated.h
new file mode 100644
index 0000000..23e138b
--- a/dev/null
+++ b/kabc/vcard/include/generated/LangValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4LangValue();
5LangValue(const LangValue&);
6LangValue(const QCString&);
7LangValue & operator = (LangValue&);
8LangValue & operator = (const QCString&);
9bool operator ==(LangValue&);
10bool operator !=(LangValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {LangValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~LangValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "LangValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/NValue-generated.h b/kabc/vcard/include/generated/NValue-generated.h
new file mode 100644
index 0000000..082c253
--- a/dev/null
+++ b/kabc/vcard/include/generated/NValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4NValue();
5NValue(const NValue&);
6NValue(const QCString&);
7NValue & operator = (NValue&);
8NValue & operator = (const QCString&);
9bool operator ==(NValue&);
10bool operator !=(NValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {NValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~NValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "NValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/Name-generated.h b/kabc/vcard/include/generated/Name-generated.h
new file mode 100644
index 0000000..0e69abd
--- a/dev/null
+++ b/kabc/vcard/include/generated/Name-generated.h
@@ -0,0 +1,22 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4V_Name();
5V_Name(const V_Name&);
6V_Name(const QCString&);
7V_Name & operator = (V_Name&);
8V_Name & operator = (const QCString&);
9bool operator ==(V_Name&);
10bool operator !=(V_Name& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {V_Name a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~V_Name();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21
22// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/OrgValue-generated.h b/kabc/vcard/include/generated/OrgValue-generated.h
new file mode 100644
index 0000000..51eb1b7
--- a/dev/null
+++ b/kabc/vcard/include/generated/OrgValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4OrgValue();
5OrgValue(const OrgValue&);
6OrgValue(const QCString&);
7OrgValue & operator = (OrgValue&);
8OrgValue & operator = (const QCString&);
9bool operator ==(OrgValue&);
10bool operator !=(OrgValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {OrgValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~OrgValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "OrgValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/Param-generated.h b/kabc/vcard/include/generated/Param-generated.h
new file mode 100644
index 0000000..cf4666a
--- a/dev/null
+++ b/kabc/vcard/include/generated/Param-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4Param();
5Param(const Param&);
6Param(const QCString&);
7Param & operator = (Param&);
8Param & operator = (const QCString&);
9bool operator ==(Param&);
10bool operator !=(Param& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {Param a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~Param();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "Param"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/ParamName-generated.h b/kabc/vcard/include/generated/ParamName-generated.h
new file mode 100644
index 0000000..ef673c3
--- a/dev/null
+++ b/kabc/vcard/include/generated/ParamName-generated.h
@@ -0,0 +1,22 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4V_ParamName();
5V_ParamName(const V_ParamName&);
6V_ParamName(const QCString&);
7V_ParamName & operator = (V_ParamName&);
8V_ParamName & operator = (const QCString&);
9bool operator ==(V_ParamName&);
10bool operator !=(V_ParamName& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {V_ParamName a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~V_ParamName();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21
22// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/ParamValue-generated.h b/kabc/vcard/include/generated/ParamValue-generated.h
new file mode 100644
index 0000000..e73500f
--- a/dev/null
+++ b/kabc/vcard/include/generated/ParamValue-generated.h
@@ -0,0 +1,22 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4V_ParamValue();
5V_ParamValue(const V_ParamValue&);
6V_ParamValue(const QCString&);
7V_ParamValue & operator = (V_ParamValue&);
8V_ParamValue & operator = (const QCString&);
9bool operator ==(V_ParamValue&);
10bool operator !=(V_ParamValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {V_ParamValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~V_ParamValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21
22// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/PhoneNumberValue-generated.h b/kabc/vcard/include/generated/PhoneNumberValue-generated.h
new file mode 100644
index 0000000..1320f18
--- a/dev/null
+++ b/kabc/vcard/include/generated/PhoneNumberValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4PhoneNumberValue();
5PhoneNumberValue(const PhoneNumberValue&);
6PhoneNumberValue(const QCString&);
7PhoneNumberValue & operator = (PhoneNumberValue&);
8PhoneNumberValue & operator = (const QCString&);
9bool operator ==(PhoneNumberValue&);
10bool operator !=(PhoneNumberValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {PhoneNumberValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~PhoneNumberValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "PhoneNumberValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/SoundValue-generated.h b/kabc/vcard/include/generated/SoundValue-generated.h
new file mode 100644
index 0000000..a9ab2e8
--- a/dev/null
+++ b/kabc/vcard/include/generated/SoundValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4SoundValue();
5SoundValue(const SoundValue&);
6SoundValue(const QCString&);
7SoundValue & operator = (SoundValue&);
8SoundValue & operator = (const QCString&);
9bool operator ==(SoundValue&);
10bool operator !=(SoundValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {SoundValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~SoundValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "SoundValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/SourceParam-generated.h b/kabc/vcard/include/generated/SourceParam-generated.h
new file mode 100644
index 0000000..75fefb8
--- a/dev/null
+++ b/kabc/vcard/include/generated/SourceParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4SourceParam();
5SourceParam(const SourceParam&);
6SourceParam(const QCString&);
7SourceParam & operator = (SourceParam&);
8SourceParam & operator = (const QCString&);
9bool operator ==(SourceParam&);
10bool operator !=(SourceParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {SourceParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~SourceParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "SourceParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/TelParam-generated.h b/kabc/vcard/include/generated/TelParam-generated.h
new file mode 100644
index 0000000..3ee77cc
--- a/dev/null
+++ b/kabc/vcard/include/generated/TelParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4TelParam();
5TelParam(const TelParam&);
6TelParam(const QCString&);
7TelParam & operator = (TelParam&);
8TelParam & operator = (const QCString&);
9bool operator ==(TelParam&);
10bool operator !=(TelParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {TelParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~TelParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "TelParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/TelValue-generated.h b/kabc/vcard/include/generated/TelValue-generated.h
new file mode 100644
index 0000000..3213e1c
--- a/dev/null
+++ b/kabc/vcard/include/generated/TelValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4TelValue();
5TelValue(const TelValue&);
6TelValue(const QCString&);
7TelValue & operator = (TelValue&);
8TelValue & operator = (const QCString&);
9bool operator ==(TelValue&);
10bool operator !=(TelValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {TelValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~TelValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "TelValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/TextBinParam-generated.h b/kabc/vcard/include/generated/TextBinParam-generated.h
new file mode 100644
index 0000000..d075c10
--- a/dev/null
+++ b/kabc/vcard/include/generated/TextBinParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4TextBinParam();
5TextBinParam(const TextBinParam&);
6TextBinParam(const QCString&);
7TextBinParam & operator = (TextBinParam&);
8TextBinParam & operator = (const QCString&);
9bool operator ==(TextBinParam&);
10bool operator !=(TextBinParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {TextBinParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~TextBinParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "TextBinParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/TextBinValue-generated.h b/kabc/vcard/include/generated/TextBinValue-generated.h
new file mode 100644
index 0000000..e9553ac
--- a/dev/null
+++ b/kabc/vcard/include/generated/TextBinValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4TextBinValue();
5TextBinValue(const TextBinValue&);
6TextBinValue(const QCString&);
7TextBinValue & operator = (TextBinValue&);
8TextBinValue & operator = (const QCString&);
9bool operator ==(TextBinValue&);
10bool operator !=(TextBinValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {TextBinValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~TextBinValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "TextBinValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/TextListValue-generated.h b/kabc/vcard/include/generated/TextListValue-generated.h
new file mode 100644
index 0000000..9f46124
--- a/dev/null
+++ b/kabc/vcard/include/generated/TextListValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4TextListValue();
5TextListValue(const TextListValue&);
6TextListValue(const QCString&);
7TextListValue & operator = (TextListValue&);
8TextListValue & operator = (const QCString&);
9bool operator ==(TextListValue&);
10bool operator !=(TextListValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {TextListValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~TextListValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "TextListValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/TextNSParam-generated.h b/kabc/vcard/include/generated/TextNSParam-generated.h
new file mode 100644
index 0000000..d7f58ca
--- a/dev/null
+++ b/kabc/vcard/include/generated/TextNSParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4TextNSParam();
5TextNSParam(const TextNSParam&);
6TextNSParam(const QCString&);
7TextNSParam & operator = (TextNSParam&);
8TextNSParam & operator = (const QCString&);
9bool operator ==(TextNSParam&);
10bool operator !=(TextNSParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {TextNSParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~TextNSParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "TextNSParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/TextParam-generated.h b/kabc/vcard/include/generated/TextParam-generated.h
new file mode 100644
index 0000000..154e1bf
--- a/dev/null
+++ b/kabc/vcard/include/generated/TextParam-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4TextParam();
5TextParam(const TextParam&);
6TextParam(const QCString&);
7TextParam & operator = (TextParam&);
8TextParam & operator = (const QCString&);
9bool operator ==(TextParam&);
10bool operator !=(TextParam& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {TextParam a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~TextParam();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "TextParam"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/TextValue-generated.h b/kabc/vcard/include/generated/TextValue-generated.h
new file mode 100644
index 0000000..e1c4dcc
--- a/dev/null
+++ b/kabc/vcard/include/generated/TextValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4TextValue();
5TextValue(const TextValue&);
6TextValue(const QCString&);
7TextValue & operator = (TextValue&);
8TextValue & operator = (const QCString&);
9bool operator ==(TextValue&);
10bool operator !=(TextValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {TextValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~TextValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "TextValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/URIValue-generated.h b/kabc/vcard/include/generated/URIValue-generated.h
new file mode 100644
index 0000000..dbcb5c1
--- a/dev/null
+++ b/kabc/vcard/include/generated/URIValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4URIValue();
5URIValue(const URIValue&);
6URIValue(const QCString&);
7URIValue & operator = (URIValue&);
8URIValue & operator = (const QCString&);
9bool operator ==(URIValue&);
10bool operator !=(URIValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {URIValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~URIValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "URIValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/UTCValue-generated.h b/kabc/vcard/include/generated/UTCValue-generated.h
new file mode 100644
index 0000000..46e447b
--- a/dev/null
+++ b/kabc/vcard/include/generated/UTCValue-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4UTCValue();
5UTCValue(const UTCValue&);
6UTCValue(const QCString&);
7UTCValue & operator = (UTCValue&);
8UTCValue & operator = (const QCString&);
9bool operator ==(UTCValue&);
10bool operator !=(UTCValue& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {UTCValue a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~UTCValue();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "UTCValue"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/VCard-generated.h b/kabc/vcard/include/generated/VCard-generated.h
new file mode 100644
index 0000000..4d7d96d
--- a/dev/null
+++ b/kabc/vcard/include/generated/VCard-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4VCard();
5VCard(const VCard&);
6VCard(const QCString&);
7VCard & operator = (VCard&);
8VCard & operator = (const QCString&);
9bool operator ==(VCard&);
10bool operator !=(VCard& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {VCard a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~VCard();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "VCard"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/VCardEntity-generated.h b/kabc/vcard/include/generated/VCardEntity-generated.h
new file mode 100644
index 0000000..9f2dfbc
--- a/dev/null
+++ b/kabc/vcard/include/generated/VCardEntity-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4VCardEntity();
5VCardEntity(const VCardEntity&);
6VCardEntity(const QCString&);
7VCardEntity & operator = (VCardEntity&);
8VCardEntity & operator = (const QCString&);
9bool operator ==(VCardEntity&);
10bool operator !=(VCardEntity& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {VCardEntity a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~VCardEntity();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "VCardEntity"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/Value-generated.h b/kabc/vcard/include/generated/Value-generated.h
new file mode 100644
index 0000000..7afac34
--- a/dev/null
+++ b/kabc/vcard/include/generated/Value-generated.h
@@ -0,0 +1,23 @@
1// XXX Automatically generated. DO NOT EDIT! XXX //
2
3public:
4Value();
5Value(const Value&);
6Value(const QCString&);
7Value & operator = (Value&);
8Value & operator = (const QCString&);
9bool operator ==(Value&);
10bool operator !=(Value& x) {return !(*this==x);}
11bool operator ==(const QCString& s) {Value a(s);return(*this==a);}
12bool operator != (const QCString& s) {return !(*this == s);}
13
14virtual ~Value();
15void parse() {if(!parsed_) _parse();parsed_=true;assembled_=false;}
16
17void assemble() {if(assembled_) return;parse();_assemble();assembled_=true;}
18
19void _parse();
20void _assemble();
21const char * className() const { return "Value"; }
22
23// End of automatically generated code //
diff --git a/kabc/vcard/include/generated/generate b/kabc/vcard/include/generated/generate
new file mode 100644
index 0000000..926dbf1
--- a/dev/null
+++ b/kabc/vcard/include/generated/generate
@@ -0,0 +1,2 @@
1#!/bin/sh
2cat headerBodies | awk -f generateHeaders.awk
diff --git a/kabc/vcard/include/generated/generateHeaders.awk b/kabc/vcard/include/generated/generateHeaders.awk
new file mode 100644
index 0000000..1053144
--- a/dev/null
+++ b/kabc/vcard/include/generated/generateHeaders.awk
@@ -0,0 +1,40 @@
1#!/bin/awk -f
2
3{
4 outfile = $1 "-generated.h"
5 name = $1
6
7 OFS=""
8
9 print "// XXX Automatically generated. DO NOT EDIT! XXX //\n" > outfile
10
11 if ($2 == "v") { pre = "virtual " } else { pre = "" }
12
13 print "public:" >> outfile
14 print name "();" >> outfile
15 print name "(const " name "&);" >> outfile
16 print name "(const QCString&);" >> outfile
17 print pre name " & operator = (" name "&);" >> outfile
18 print pre name " & operator = (const QCString&);" >> outfile
19 print pre "bool operator ==(" name "&);" >> outfile
20 print pre "bool operator !=(" name "& x) {return !(*this==x);}" \
21 >> outfile
22 print pre "bool operator ==(const QCString& s) {" name " a(s);" \
23 "return(*this==a);} " >> outfile
24 print pre "bool operator != (const QCString& s) {return !(*this == s);}\n" \
25 >> outfile
26 print "virtual ~" name "();" >> outfile
27 print pre "void parse() " \
28 "{if(!parsed_) _parse();parsed_=true;assembled_=false;}\n" \
29 >> outfile
30 print pre "void assemble() " \
31 "{if(assembled_) return;parse();_assemble();assembled_=true;}\n" \
32 >> outfile
33 print pre "void _parse();" >> outfile
34 print pre "void _assemble();" >> outfile
35 print pre "const char * className() const { return \"" name "\"; }" \
36 >> outfile
37
38 print "\n// End of automatically generated code //" >> outfile
39}
40
diff --git a/kabc/vcard/include/generated/headerBodies b/kabc/vcard/include/generated/headerBodies
new file mode 100644
index 0000000..5e77b2b
--- a/dev/null
+++ b/kabc/vcard/include/generated/headerBodies
@@ -0,0 +1,34 @@
1AdrParam Param
2AdrValue Value
3AgentParam Param
4ContentLine Entity
5DateParam Param
6DateValue Value
7EmailParam Param
8GeoValue Value
9Group Entity
10ImageParam Param
11ImageValue Value
12LangValue Value
13NValue Value
14Param Entity
15PhoneNumberValue Value
16SourceParam Param
17TelParam Param
18TextParam Param
19TextNSParam Param
20TextValue Value
21TextBinParam Param
22URIValue Value
23VCard Entity
24VCardEntity Entity
25Value Entity
26SoundValue Value
27AgentValue Value
28TelValue Value
29TextBinValue Value
30OrgValue Value
31UTCValue Value
32ClassValue Value
33FloatValue Value
34TextListValue Value
diff --git a/kabc/vcard/testread.cpp b/kabc/vcard/testread.cpp
new file mode 100644
index 0000000..919c661
--- a/dev/null
+++ b/kabc/vcard/testread.cpp
@@ -0,0 +1,129 @@
1#include <iostream>
2#include <stdlib.h>
3#include <assert.h>
4
5#include <qfile.h>
6#include <qtextstream.h>
7
8#include <VCard.h>
9
10using namespace std;
11
12int main(int argc, char * argv[])
13{
14 if (argc != 2) {
15 cerr << "Usage: " << argv[0] << " <filename>" << endl;
16 exit(1);
17 }
18
19 QFile f(argv[1]);
20
21 QCString str;
22
23 if (!f.open(IO_ReadOnly)) {
24 cerr << "Couldn't open file \"" << argv[1] << endl;
25 exit(1);
26 }
27
28 QTextStream t(&f);
29
30 while (!t.eof())
31 str += t.readLine().utf8() + '\n';
32
33 using namespace VCARD;
34
35 // Iterate through all vCards in the file.
36
37 cout << "--------- begin ----------" << endl;
38 cout << str.data();
39 cout << "--------- end ----------" << endl;
40
41 VCardEntity e(str);
42
43 VCardListIterator it(e.cardList());
44
45 for (; it.current(); ++it) {
46
47 cerr << "****************** VCARD ********************" << endl;
48
49 // Create a vcard using the string representation.
50 VCard & v (*it.current());
51
52 if (v.has(EntityEmail)) {
53 cerr << "Email parameter found" << endl;
54
55 QCString s = v.contentLine(EntityEmail)->value()->asString();
56
57 cerr << "Email value == " << s << endl;
58 }
59
60 if (v.has(EntityNickname)) {
61 cerr << "Nickname parameter found" << endl;
62
63 cerr << "Nickname value == " <<
64 v.contentLine(EntityNickname)->value()->asString() <<
65 endl;
66 }
67
68 if (v.has(EntityRevision)) {
69
70 cerr << "Revision parameter found" << endl;
71
72 DateValue * d =
73 (DateValue *)
74 v.contentLine(EntityRevision)->value();
75
76 assert(d != 0);
77
78 cerr << "Revision date: " << endl;
79 cerr << "Day : " << d->day() << endl;
80 cerr << "Month : " << d->month()<< endl;
81 cerr << "Year : " << d->year() << endl;
82
83 if (d->hasTime()) {
84 cerr << "Revision date has a time component" << endl;
85 cerr << "Revision time: " << endl;
86 cerr << "Hour : " << d->hour()<< endl;
87 cerr << "Minute : " << d->minute()<< endl;
88 cerr << "Second : " << d->second()<< endl;
89
90 }
91 else cerr << "Revision date does NOT have a time component" << endl;
92 }
93
94 if (v.has(EntityURL)) {
95 cerr << "URL Parameter found" << endl;
96
97 cerr << "URL Value == " <<
98 v.contentLine(EntityURL)->value()->asString() <<
99 endl;
100
101 URIValue * urlVal =
102 (URIValue *)v.contentLine(EntityURL)->value();
103
104 assert(urlVal != 0);
105
106 cerr << "URL scheme == " <<
107 urlVal->scheme() << endl;
108
109 cerr << "URL scheme specific part == " <<
110 urlVal->schemeSpecificPart() << endl;
111 }
112
113 if (v.has(EntityN)) {
114 cerr << "N Parameter found" << endl;
115
116 NValue * n =
117 (NValue *)(v.contentLine(EntityN)->value());
118
119 cerr << "Family name == " << n->family()<< endl;
120 cerr << "Given name == " << n->given()<< endl;
121 cerr << "Middle name == " << n->middle()<< endl;
122 cerr << "Prefix == " << n->prefix()<< endl;
123 cerr << "Suffix == " << n->suffix()<< endl;
124 }
125
126 cerr << "***************** END VCARD ******************" << endl;
127 }
128}
129
diff --git a/kabc/vcard/testwrite.cpp b/kabc/vcard/testwrite.cpp
new file mode 100644
index 0000000..e4bbe7b
--- a/dev/null
+++ b/kabc/vcard/testwrite.cpp
@@ -0,0 +1,41 @@
1#include <kaboutdata.h>
2#include <kapplication.h>
3#include <kdebug.h>
4#include <klocale.h>
5#include <kcmdlineargs.h>
6
7#include <VCard.h>
8
9int main(int argc,char **argv)
10{
11 KAboutData aboutData("testwrite",I18N_NOOP("TestWritevCard"),"0.1");
12 KCmdLineArgs::init(argc,argv,&aboutData);
13
14 KApplication app;
15
16 kdDebug() << "Test Write VCard" << endl;
17
18 using namespace VCARD;
19
20 VCard v;
21
22 ContentLine cl1;
23 cl1.setName(EntityTypeToParamName(EntityName));
24 cl1.setValue(new TextValue("Hans Wurst"));
25 v.add(cl1);
26
27 ContentLine cl2;
28 cl2.setName(EntityTypeToParamName(EntityTelephone));
29 cl2.setValue(new TelValue("12345"));
30 ParamList p;
31 p.append( new TelParam("home") );
32 p.append( new TelParam("fax") );
33 cl2.setParamList( p );
34 v.add(cl2);
35
36 QCString str = v.asString();
37
38 kdDebug() << "--- VCard begin ---" << endl
39 << str
40 << "--- VCard end ---" << endl;
41}
diff --git a/kabc/vcard/vCard-all.cpp b/kabc/vcard/vCard-all.cpp
new file mode 100644
index 0000000..07bbcd2
--- a/dev/null
+++ b/kabc/vcard/vCard-all.cpp
@@ -0,0 +1,37 @@
1#include "AdrParam.cpp"
2#include "AdrValue.cpp"
3#include "AgentParam.cpp"
4#include "AgentValue.cpp"
5#include "ClassValue.cpp"
6#include "ContentLine.cpp"
7#include "DateParam.cpp"
8#include "DateValue.cpp"
9#include "EmailParam.cpp"
10#include "Entity.cpp"
11#include "Enum.cpp"
12#include "FloatValue.cpp"
13#include "GeoValue.cpp"
14#include "ImageParam.cpp"
15#include "ImageValue.cpp"
16#include "ImgValue.cpp"
17#include "LangValue.cpp"
18#include "NValue.cpp"
19#include "OrgValue.cpp"
20#include "Param.cpp"
21#include "PhoneNumberValue.cpp"
22#include "RToken.cpp"
23#include "SoundValue.cpp"
24#include "SourceParam.cpp"
25#include "TelParam.cpp"
26#include "TelValue.cpp"
27#include "TextBinParam.cpp"
28#include "TextBinValue.cpp"
29#include "TextListValue.cpp"
30#include "TextParam.cpp"
31#include "TextValue.cpp"
32#include "URIValue.cpp"
33#include "UTCValue.cpp"
34#include "VCard.cpp"
35#include "VCardEntity.cpp"
36#include "Value.cpp"
37
diff --git a/kabc/vcard21parser.cpp b/kabc/vcard21parser.cpp
new file mode 100644
index 0000000..b02aac4
--- a/dev/null
+++ b/kabc/vcard21parser.cpp
@@ -0,0 +1,606 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Mark Westcott <mark@houseoffish.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qmap.h>
29#include <qregexp.h>
30#include <kmdcodec.h>
31
32#include "vcard21parser.h"
33#include "vcardconverter.h"
34
35using namespace KABC;
36
37bool VCardLineX::isValid() const
38{
39 // Invalid: if it is "begin:vcard" or "end:vcard"
40 if ( name == VCARD_BEGIN_N || name == VCARD_END_N )
41 return false;
42
43 if ( name[0] == 'x' && name[1] == '-' ) // A custom x- line
44 return true;
45
46 // This is long but it makes it a bit faster (and saves me from using
47 // a tree which is probably the ideal situation, but a bit memory heavy)
48 switch( name[0] ) {
49 case 'a':
50 if ( name == VCARD_ADR && qualified &&
51 (qualifiers.contains(VCARD_ADR_DOM) ||
52 qualifiers.contains(VCARD_ADR_INTL) ||
53 qualifiers.contains(VCARD_ADR_POSTAL) ||
54 qualifiers.contains(VCARD_ADR_HOME) ||
55 qualifiers.contains(VCARD_ADR_WORK) ||
56 qualifiers.contains(VCARD_ADR_PREF)
57 ) )
58 return true;
59
60 if ( name == VCARD_AGENT )
61 return true;
62 break;
63
64 case 'b':
65 if ( name == VCARD_BDAY )
66 return true;
67 break;
68
69 case 'c':
70 if ( name == VCARD_CATEGORIES )
71 return true;
72 if ( name == VCARD_CLASS && qualified &&
73 (qualifiers.contains(VCARD_CLASS_PUBLIC) ||
74 qualifiers.contains(VCARD_CLASS_PRIVATE) ||
75 qualifiers.contains(VCARD_CLASS_CONFIDENTIAL)
76 ) )
77 return true;
78 break;
79
80 case 'e':
81 if ( name == VCARD_EMAIL && qualified &&
82 (qualifiers.contains(VCARD_EMAIL_INTERNET) ||
83 qualifiers.contains(VCARD_EMAIL_PREF) ||
84 qualifiers.contains(VCARD_EMAIL_X400)
85 ) )
86 return true;
87 break;
88
89 case 'f':
90 if ( name == VCARD_FN )
91 return true;
92 break;
93
94 case 'g':
95 if ( name == VCARD_GEO )
96 return true;
97 break;
98
99 case 'k':
100 if ( name == VCARD_KEY && qualified &&
101 (qualifiers.contains(VCARD_KEY_X509) ||
102 qualifiers.contains(VCARD_KEY_PGP)
103 ) )
104 return true;
105 break;
106
107 case 'l':
108 if ( name == VCARD_LABEL )
109 return true;
110 if ( name == VCARD_LOGO )
111 return true;
112 break;
113
114 case 'm':
115 if ( name == VCARD_MAILER )
116 return true;
117 break;
118
119 case 'n':
120 if ( name == VCARD_N )
121 return true;
122 if ( name == VCARD_NAME )
123 return true;
124 if ( name == VCARD_NICKNAME )
125 return true;
126 if ( name == VCARD_NOTE )
127 return true;
128 break;
129
130 case 'o':
131 if ( name == VCARD_ORG )
132 return true;
133 break;
134
135 case 'p':
136 if ( name == VCARD_PHOTO )
137 return true;
138 if ( name == VCARD_PROFILE )
139 return true;
140 if ( name == VCARD_PRODID )
141 return true;
142 break;
143
144 case 'r':
145 if ( name == VCARD_ROLE )
146 return true;
147 if ( name == VCARD_REV )
148 return true;
149 break;
150
151 case 's':
152 if ( name == VCARD_SOURCE )
153 return true;
154 if ( name == VCARD_SOUND )
155 return true;
156 break;
157
158 case 't':
159 if ( name == VCARD_TEL && qualified &&
160 (qualifiers.contains(VCARD_TEL_HOME) ||
161 qualifiers.contains(VCARD_TEL_WORK) ||
162 qualifiers.contains(VCARD_TEL_PREF) ||
163 qualifiers.contains(VCARD_TEL_VOICE) ||
164 qualifiers.contains(VCARD_TEL_FAX) ||
165 qualifiers.contains(VCARD_TEL_MSG) ||
166 qualifiers.contains(VCARD_TEL_CELL) ||
167 qualifiers.contains(VCARD_TEL_PAGER) ||
168 qualifiers.contains(VCARD_TEL_BBS) ||
169 qualifiers.contains(VCARD_TEL_MODEM) ||
170 qualifiers.contains(VCARD_TEL_CAR) ||
171 qualifiers.contains(VCARD_TEL_ISDN) ||
172 qualifiers.contains(VCARD_TEL_VIDEO) ||
173 qualifiers.contains(VCARD_TEL_PCS)
174 ) )
175 return true;
176 if ( name == VCARD_TZ )
177 return true;
178 if ( name == VCARD_TITLE )
179 return true;
180 break;
181
182 case 'u':
183 if ( name == VCARD_URL )
184 return true;
185 if ( name == VCARD_UID )
186 return true;
187 break;
188
189 case 'v':
190 if ( name == VCARD_VERSION )
191 return true;
192 break;
193 default:
194 break;
195 }
196
197 return false;
198}
199
200
201VCard21Parser::VCard21Parser()
202{
203}
204
205VCard21Parser::~VCard21Parser()
206{
207}
208
209void VCard21Parser::readFromString(KABC::AddressBook *addressbook, const QString &data)
210{
211 KABC::Addressee mAddressee = readFromString(data);
212 addressbook->insertAddressee(mAddressee);
213}
214
215KABC::Addressee VCard21Parser::readFromString( const QString &data)
216{
217 KABC::Addressee addressee;
218 VCard21ParserImpl *mVCard = VCard21ParserImpl::parseVCard(data);
219 QString tmpStr;
220
221 // Check if parsing failed
222 if (mVCard == 0)
223 {
224 kdDebug() << "Parsing failed" << endl;
225 return addressee;
226 }
227 //set the addressees name and formated name
228 QStringList tmpList = mVCard->getValues(VCARD_N);
229 QString formattedName = "";
230 if (tmpList.count() > 0)
231 addressee.setFamilyName(tmpList[0]);
232 if (tmpList.count() > 1)
233 addressee.setGivenName(tmpList[1]);
234 if (tmpList.count() > 2)
235 addressee.setAdditionalName(tmpList[2]);
236 if (tmpList.count() > 3)
237 addressee.setPrefix(tmpList[3]);
238 if (tmpList.count() > 4)
239 addressee.setSuffix(tmpList[4]);
240
241 tmpStr = (mVCard->getValue(VCARD_FN));
242 if (!tmpStr.isEmpty())
243 addressee.setFormattedName(tmpStr);
244
245 //set the addressee's nick name
246 tmpStr = mVCard->getValue(VCARD_NICKNAME);
247 addressee.setNickName(tmpStr);
248 //set the addressee's organisation
249 tmpStr = mVCard->getValue(VCARD_ORG);
250 addressee.setOrganization(tmpStr);
251 //set the addressee's title
252 tmpStr = mVCard->getValue(VCARD_TITLE);
253 addressee.setTitle(tmpStr);
254 //set the addressee's email - we can only deal with two. The preferenced one and one other.
255 tmpStr = mVCard->getValue(VCARD_EMAIL, VCARD_EMAIL_INTERNET);
256 addressee.insertEmail(tmpStr, false);
257 tmpStr = mVCard->getValue(VCARD_EMAIL,VCARD_EMAIL_PREF);
258 addressee.insertEmail(tmpStr, true);
259 //set the addressee's url
260 tmpStr = mVCard->getValue(VCARD_URL);
261 if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_WORK);
262 if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_HOME);
263 if (!tmpStr.isEmpty()) {
264 addressee.setUrl(KURL(tmpStr));
265 }
266
267 //set the addressee's birthday
268 tmpStr = mVCard->getValue(VCARD_BDAY);
269 addressee.setBirthday(VCardStringToDate(tmpStr));
270
271 //set the addressee's phone numbers
272 for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) {
273 if ( (*i).name == VCARD_TEL ) {
274 int type = 0;
275 if ( (*i).qualified ) {
276 if ( (*i).qualifiers.contains( VCARD_TEL_HOME ) )
277 type |= PhoneNumber::Home;
278 if ( (*i).qualifiers.contains( VCARD_TEL_WORK ) )
279 type |= PhoneNumber::Work;
280 if ( (*i).qualifiers.contains( VCARD_TEL_PREF ) )
281 type |= PhoneNumber::Pref;
282 // if ( (*i).qualifiers.contains( VCARD_TEL_VOICE ) )
283 // type |= PhoneNumber::Voice;
284 if ( (*i).qualifiers.contains( VCARD_TEL_FAX ) )
285 type |= PhoneNumber::Fax;
286 if ( (*i).qualifiers.contains( VCARD_TEL_MSG ) )
287 type |= PhoneNumber::Msg;
288 if ( (*i).qualifiers.contains( VCARD_TEL_CELL ) )
289 type |= PhoneNumber::Cell;
290 if ( (*i).qualifiers.contains( VCARD_TEL_PAGER ) )
291 type |= PhoneNumber::Pager;
292 if ( (*i).qualifiers.contains( VCARD_TEL_BBS ) )
293 type |= PhoneNumber::Bbs;
294 if ( (*i).qualifiers.contains( VCARD_TEL_MODEM ) )
295 type |= PhoneNumber::Modem;
296 if ( (*i).qualifiers.contains( VCARD_TEL_CAR ) )
297 type |= PhoneNumber::Car;
298 if ( (*i).qualifiers.contains( VCARD_TEL_ISDN ) )
299 type |= PhoneNumber::Isdn;
300 if ( (*i).qualifiers.contains( VCARD_TEL_VIDEO ) )
301 type |= PhoneNumber::Video;
302 if ( (*i).qualifiers.contains( VCARD_TEL_PCS ) )
303 type |= PhoneNumber::Pcs;
304 }
305 addressee.insertPhoneNumber( PhoneNumber( (*i).parameters[ 0 ], type ) );
306 }
307 }
308
309 //set the addressee's addresses
310 for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) {
311 if ( (*i).name == VCARD_ADR ) {
312 int type = 0;
313 if ( (*i).qualified ) {
314 if ( (*i).qualifiers.contains( VCARD_ADR_DOM ) )
315 type |= Address::Dom;
316 if ( (*i).qualifiers.contains( VCARD_ADR_INTL ) )
317 type |= Address::Intl;
318 if ( (*i).qualifiers.contains( VCARD_ADR_POSTAL ) )
319 type |= Address::Postal;
320 if ( (*i).qualifiers.contains( VCARD_ADR_PARCEL ) )
321 type |= Address::Parcel;
322 if ( (*i).qualifiers.contains( VCARD_ADR_HOME ) )
323 type |= Address::Home;
324 if ( (*i).qualifiers.contains( VCARD_ADR_WORK ) )
325 type |= Address::Work;
326 if ( (*i).qualifiers.contains( VCARD_ADR_PREF ) )
327 type |= Address::Pref;
328 }
329 addressee.insertAddress( readAddressFromQStringList( (*i).parameters, type ) );
330 }
331 }
332
333 //set the addressee's delivery label
334 tmpStr = mVCard->getValue(VCARD_LABEL);
335 if (!tmpStr.isEmpty()) {
336qDebug("VCard21Parser::readFromString please verify if replace is correct");
337//US tmpStr.replace("\r\n","\n");
338 tmpStr.replace( QRegExp("\r\n"), "\n" );
339 Address tmpAddress;
340 tmpAddress.setLabel(tmpStr);
341 addressee.insertAddress(tmpAddress);
342 }
343
344 //set the addressee's notes
345 tmpStr = mVCard->getValue(VCARD_NOTE);
346qDebug("VCard21Parser::readFromString please verify if correct");
347//US tmpStr.replace("\r\n","\n");
348 tmpStr.replace( QRegExp("\r\n"), "\n" );
349 addressee.setNote(tmpStr);
350
351 //set the addressee's timezone
352 tmpStr = mVCard->getValue(VCARD_TZ);
353 TimeZone tmpZone(tmpStr.toInt());
354 addressee.setTimeZone(tmpZone);
355
356 //set the addressee's geographical position
357 tmpList = mVCard->getValues(VCARD_GEO);
358 if (tmpList.count()==2)
359 {
360 tmpStr = tmpList[0];
361 float glat = tmpStr.toFloat();
362 tmpStr = tmpList[1];
363 float glong = tmpStr.toFloat();
364 Geo tmpGeo(glat,glong);
365 addressee.setGeo(tmpGeo);
366 }
367
368 //set the last revision date
369 tmpStr = mVCard->getValue(VCARD_REV);
370 addressee.setRevision(VCardStringToDate(tmpStr));
371
372 //set the role of the addressee
373 tmpStr = mVCard->getValue(VCARD_ROLE);
374 addressee.setRole(tmpStr);
375
376 return addressee;
377}
378
379
380
381KABC::Address VCard21Parser::readAddressFromQStringList ( const QStringList &data, const int type )
382{
383 KABC::Address mAddress;
384 mAddress.setType( type );
385
386 if ( data.count() > 0 )
387 mAddress.setPostOfficeBox( data[0] );
388 if ( data.count() > 1 )
389 mAddress.setExtended( data[1] );
390 if ( data.count() > 2 )
391 mAddress.setStreet( data[2] );
392 if ( data.count() > 3 )
393 mAddress.setLocality( data[3] );
394 if ( data.count() > 4 )
395 mAddress.setRegion( data[4] );
396 if ( data.count() > 5 )
397 mAddress.setPostalCode( data[5] );
398 if ( data.count() > 6 )
399 mAddress.setCountry( data[6] );
400
401 return mAddress;
402}
403
404
405VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err )
406{
407 int _err = 0;
408 int _state = VC_STATE_BEGIN;
409
410 QValueList<VCardLineX> *_vcdata;
411 QValueList<QString> lines;
412
413 _vcdata = new QValueList<VCardLineX>;
414
415 lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), vc );
416
417 // for each line in the vCard
418 for ( QStringList::Iterator j = lines.begin(); j != lines.end(); ++j ) {
419 VCardLineX _vcl;
420
421 // take spaces off the end - ugly but necessary hack
422 for ( int g = (*j).length()-1; g > 0 && (*j)[g].isSpace(); --g )
423 (*j)[g] = 0;
424
425 // first token:
426 // verify state, update if necessary
427 if ( _state & VC_STATE_BEGIN) {
428 if ( !qstricmp( (*j).latin1(), VCARD_BEGIN ) ) {
429 _state = VC_STATE_BODY;
430 continue;
431 } else {
432 _err = VC_ERR_NO_BEGIN;
433 break;
434 }
435 } else if ( _state & VC_STATE_BODY ) {
436 if ( !qstricmp( (*j).latin1(), VCARD_END ) ) {
437 _state |= VC_STATE_END;
438 break;
439 }
440
441 // split into two tokens
442 int colon = (*j).find( ':' );
443 if ( colon < 0 ) {
444 _err = VC_ERR_INVALID_LINE;
445 break;
446 }
447
448 QString key = (*j).left( colon );
449 QString value = (*j).mid( colon + 1 );
450
451 // check for qualifiers and
452 // set name, qualified, qualifier(s)
453 QStringList keyTokens = QStringList::split( ';', key );
454 bool qp = false, first_pass = true;
455 bool b64 = false;
456
457 if ( keyTokens.count() > 0 ) {
458 _vcl.qualified = false;
459 _vcl.name = keyTokens[ 0 ].lower();
460
461 for ( QStringList::Iterator z = keyTokens.begin(); z != keyTokens.end(); ++z ) {
462 QString zz = (*z).lower();
463 if ( zz == VCARD_QUOTED_PRINTABLE || zz == VCARD_ENCODING_QUOTED_PRINTABLE ) {
464 qp = true;
465 } else if ( zz == VCARD_BASE64 ) {
466 b64 = true;
467 } else if ( !first_pass ) {
468 _vcl.qualified = true;
469 _vcl.qualifiers.append( zz );
470 }
471 first_pass = false;
472 }
473 } else {
474 _err = VC_ERR_INVALID_LINE;
475 }
476
477 if ( _err != 0 )
478 break;
479
480 if ( _vcl.name == VCARD_VERSION )
481 _state |= VC_STATE_HAVE_VERSION;
482
483 if ( _vcl.name == VCARD_N || _vcl.name == VCARD_FN )
484 _state |= VC_STATE_HAVE_N;
485
486 // second token:
487 // split into tokens by ;
488 // add to parameters vector
489 if ( b64 ) {
490 if ( value.at( value.length() - 1 ) != '=' )
491 do {
492 value += *( ++j );
493 } while ( (*j).at( (*j).length() - 1 ) != '=' );
494 } else {
495 if ( qp ) { // join any split lines
496 while ( value.at( value.length() - 1 ) == '=' ) {
497 value.remove( value.length() - 1, 1 );
498 value.append(*( ++j ));
499 }
500 }
501 _vcl.parameters = QStringList::split( ';', value, true );
502 if ( qp ) { // decode the quoted printable
503 for ( QStringList::Iterator z = _vcl.parameters.begin(); z != _vcl.parameters.end(); ++z )
504 *z = KCodecs::quotedPrintableDecode( (*z).latin1() );
505 }
506 }
507 } else {
508 _err = VC_ERR_INTERNAL;
509 break;
510 }
511
512 // validate VCardLineX
513 if ( !_vcl.isValid() ) {
514 _err = VC_ERR_INVALID_LINE;
515 break;
516 }
517
518 // add to vector
519 _vcdata->append( _vcl );
520 }
521
522 // errors to check at the last minute (exit state related)
523 if ( _err == 0 ) {
524 if ( !( _state & VC_STATE_END ) ) // we have to have an end!!
525 _err = VC_ERR_NO_END;
526
527 if ( !( _state & VC_STATE_HAVE_N ) || // we have to have the mandatories!
528 !( _state & VC_STATE_HAVE_VERSION ) )
529 _err = VC_ERR_MISSING_MANDATORY;
530 }
531
532 // set the error message if we can, and only return an object
533 // if the vCard was valid.
534 if ( err )
535 *err = _err;
536
537 if ( _err != 0 ) {
538 delete _vcdata;
539 return 0;
540 }
541
542 return new VCard21ParserImpl( _vcdata );
543}
544
545VCard21ParserImpl::VCard21ParserImpl(QValueList<VCardLineX> *_vcd) : _vcdata(_vcd)
546{
547}
548
549
550QString VCard21ParserImpl::getValue(const QString& name, const QString& qualifier)
551{
552 QString failed;
553 const QString lowname = name.lower();
554 const QString lowqualifier = qualifier.lower();
555
556 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
557 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) {
558 if ((*i).parameters.count() > 0)
559 return (*i).parameters[0];
560 else return failed;
561 }
562 }
563 return failed;
564}
565
566
567QString VCard21ParserImpl::getValue(const QString& name)
568{
569 QString failed;
570 const QString lowname = name.lower();
571
572 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
573 if ((*i).name == lowname && !(*i).qualified) {
574 if ((*i).parameters.count() > 0)
575 return (*i).parameters[0];
576 else return failed;
577 }
578 }
579 return failed;
580}
581
582
583QStringList VCard21ParserImpl::getValues(const QString& name)
584{
585 const QString lowname = name.lower();
586 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
587 if ((*i).name == lowname && !(*i).qualified)
588 return (*i).parameters;
589 }
590 // failed.
591 return QStringList();
592}
593
594QStringList VCard21ParserImpl::getValues(const QString& name, const QString& qualifier)
595{
596 const QString lowname = name.lower();
597 const QString lowqualifier = qualifier.lower();
598 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
599 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier))
600 return (*i).parameters;
601 }
602 // failed.
603 return QStringList();
604}
605
606
diff --git a/kabc/vcard21parser.h b/kabc/vcard21parser.h
new file mode 100644
index 0000000..24b0eb2
--- a/dev/null
+++ b/kabc/vcard21parser.h
@@ -0,0 +1,225 @@
1/*
2 This file is part of libkabc.
3
4 Copyright (c) 2002 Mark Westcott <mark@houseoffish.org>
5 Copyright (c) 2000 George Staikos <staikos@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#ifndef KABC_VCARD21FORMAT_H
30#define KABC_VCARD21FORMAT_H
31
32#include <qdatetime.h>
33#include <kdebug.h>
34#include <qregexp.h>
35#include <qstring.h>
36#include <kurl.h>
37#include <qvaluelist.h>
38
39#include "addressee.h"
40#include "addressbook.h"
41#include "phonenumber.h"
42
43
44#define VCARD_BEGIN "begin:vcard"
45#define VCARD_END "end:vcard"
46#define VCARD_BEGIN_N "begin"
47#define VCARD_END_N "end"
48#define VCARD_VERSION "version"
49
50#define VCARD_FN "fn"
51#define VCARD_N "n"
52
53// optional
54#define VCARD_NAME "name"
55#define VCARD_NICKNAME "nickname"
56#define VCARD_PHOTO "photo"
57#define VCARD_BDAY "bday"
58#define VCARD_ADR "adr"
59
60// types
61#define VCARD_ADR_DOM "dom"
62#define VCARD_ADR_INTL "intl"
63#define VCARD_ADR_POSTAL "postal"
64#define VCARD_ADR_PARCEL "parcel"
65#define VCARD_ADR_HOME "home"
66#define VCARD_ADR_WORK "work"
67#define VCARD_ADR_PREF "pref"
68// values
69#define VCARD_ADR_POBOX "PO Box"
70#define VCARD_ADR_EXTADR "Extended Address"
71#define VCARD_ADR_STREET "Street"
72#define VCARD_ADR_LOCALITY "Locality"
73#define VCARD_ADR_REGION "Region"
74#define VCARD_ADR_POSTCODE "Postal Code"
75#define VCARD_ADR_COUNTRY "Country Name"
76#define VCARD_LABEL "label"
77#define VCARD_PROFILE "profile"
78#define VCARD_SOURCE "source"
79#define VCARD_TEL "tel"
80// types
81#define VCARD_TEL_HOME "home"
82#define VCARD_TEL_WORK "work"
83#define VCARD_TEL_PREF "pref"
84#define VCARD_TEL_VOICE "voice"
85#define VCARD_TEL_FAX "fax"
86#define VCARD_TEL_MSG "msg"
87#define VCARD_TEL_CELL "cell"
88#define VCARD_TEL_PAGER "pager"
89#define VCARD_TEL_BBS "bbs"
90#define VCARD_TEL_MODEM "modem"
91#define VCARD_TEL_CAR "car"
92#define VCARD_TEL_ISDN "isdn"
93#define VCARD_TEL_VIDEO "video"
94#define VCARD_TEL_PCS "pcs"
95#define VCARD_EMAIL "email"
96// types
97#define VCARD_EMAIL_PREF "pref"
98#define VCARD_EMAIL_INTERNET "internet"
99#define VCARD_EMAIL_X400 "x400"
100#define VCARD_TZ "tz"
101#define VCARD_GEO "geo"
102#define VCARD_MAILER "mailer"
103#define VCARD_TITLE "title"
104#define VCARD_ROLE "role"
105#define VCARD_LOGO "logo"
106#define VCARD_AGENT "agent"
107#define VCARD_ORG "org"
108#define VCARD_CATEGORIES "categories"
109#define VCARD_NOTE "note"
110#define VCARD_PRODID "prodid"
111#define VCARD_REV "rev"
112#define VCARD_SOUND "sound"
113#define VCARD_UID "uid"
114#define VCARD_URL "url"
115#define VCARD_CLASS "class"
116#define VCARD_CLASS_PUBLIC "public"
117#define VCARD_CLASS_PRIVATE "private"
118#define VCARD_CLASS_CONFIDENTIAL "confidential"
119#define VCARD_KEY "key"
120// types
121#define VCARD_KEY_X509 "x509"
122#define VCARD_KEY_PGP "pgp"
123
124#define VCARD_QUOTED_PRINTABLE "quoted-printable"
125// this one is a temporary hack until we support TYPE=VALUE
126#define VCARD_ENCODING_QUOTED_PRINTABLE "encoding=quoted-printable"
127#define VCARD_BASE64 "base64"
128
129#define VC_STATE_BEGIN 1
130#define VC_STATE_BODY 2
131#define VC_STATE_END 4
132#define VC_STATE_HAVE_N 8
133#define VC_STATE_HAVE_VERSION 16
134
135#define VC_ERR_NO_BEGIN 1
136#define VC_ERR_NO_END 2
137#define VC_ERR_INVALID_LINE 3
138#define VC_ERR_INTERNAL 4
139#define VC_ERR_INVALID_NAME 5
140#define VC_ERR_MISSING_MANDATORY 6
141
142namespace KABC {
143
144class AddressBook;
145
146class VCard21Parser
147{
148public:
149
150 /**
151 * Constructor.
152 */
153 VCard21Parser();
154
155 /**
156 * Destructor.
157 */
158 virtual ~VCard21Parser();
159
160 /**
161 * Parses a string in vcard2.1 format and saves the single addressees
162 * to the address book.
163 *
164 * @param ab The address book.
165 * @param str The vcard string.
166 */
167 void readFromString( KABC::AddressBook *ab, const QString &str );
168
169 /**
170 * FIXME: we need a writeToString method
171 * QString writeToString (KABC::AddressBook *);
172 */
173
174 /**
175 * Parses a string in vcard2.1 format and returns the inherent addressee.
176 */
177 KABC::Addressee readFromString( const QString &data);
178
179 /**
180 * Helper method to store a address.
181 *
182 * @param data A string list, that is filled with 'street', 'house number' ...
183 * @param type The type of the returned address.
184 */
185 static KABC::Address readAddressFromQStringList (const QStringList &data, const int type);
186};
187
188}
189
190/**
191 * @short Helper class
192 */
193class VCardLineX
194{
195public:
196 QString name;
197 bool qualified;
198 QValueList<QString> qualifiers;
199 QValueList<QString> parameters;
200 bool isValid() const;
201};
202
203/**
204 * @short Helper class
205 */
206class VCard21ParserImpl
207{
208 friend class VCardLineX;
209
210public:
211 VCard21ParserImpl() { };
212 virtual ~VCard21ParserImpl() { };
213 static VCard21ParserImpl *parseVCard(const QString& vc, int *err = NULL);
214 QString getValue(const QString& name, const QString& qualifier);
215 QString getValue(const QString& name);
216 QStringList getValues(const QString& name, const QString& qualifier);
217 QStringList getValues(const QString& name);
218
219 QValueList<VCardLineX> *_vcdata;
220
221private:
222 VCard21ParserImpl (QValueList<VCardLineX> *_vcd);
223};
224
225#endif
diff --git a/kabc/vcardconverter.cpp b/kabc/vcardconverter.cpp
new file mode 100644
index 0000000..266cdf9
--- a/dev/null
+++ b/kabc/vcardconverter.cpp
@@ -0,0 +1,115 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28//US
29#include "kglobal.h"
30
31#include "vcard21parser.h"
32#include "vcardformatimpl.h"
33
34#include "vcardconverter.h"
35
36using namespace KABC;
37
38struct VCardConverter::VCardConverterData
39{
40 VCard21Parser vcard21parser;
41 VCardFormatImpl vcard30parser;
42};
43
44VCardConverter::VCardConverter()
45 : d( new VCardConverterData )
46{
47}
48
49VCardConverter::~VCardConverter()
50{
51 delete d;
52 d = 0;
53}
54
55bool VCardConverter::vCardToAddressee( const QString &str, Addressee &addr, Version version )
56{
57 if ( version == v2_1 ) {
58 addr = d->vcard21parser.readFromString( str );
59 return true;
60 }
61
62 if ( version == v3_0 )
63 return d->vcard30parser.readFromString( str, addr );
64
65 return false;
66}
67
68bool VCardConverter::addresseeToVCard( const Addressee &addr, QString &str, Version version )
69{
70 if ( version == v2_1 )
71 return false;
72
73 if ( version == v3_0 )
74 return d->vcard30parser.writeToString( addr, str );
75
76 return false;
77}
78
79
80/* Helper functions */
81
82QString KABC::dateToVCardString( const QDateTime &dateTime )
83{
84qDebug("vcardconverter.cpp : KABC::dateToVCardString transformation does not work yet");
85 return KGlobal::locale()->formatDate(dateTime.date(), true);
86//US return dateTime.toString("yyyyMMddThhmmssZ");
87}
88
89QString KABC::dateToVCardString( const QDate &date )
90{
91qDebug("vcardconverter.cpp : KABC::dateToVCardString transformation does not work yet");
92 return KGlobal::locale()->formatDate(date, true);
93//US return date.toString("yyyyMMdd");
94}
95
96QDateTime KABC::VCardStringToDate( const QString &dateString )
97{
98 QDate date;
99 QTime time;
100 QString d( dateString );
101
102//US I hope this is correct
103//US d = d.remove('-').remove(':');
104 d = d.replace( QRegExp("-"), "" );
105 d = d.replace( QRegExp(":"), "" );
106
107
108 if (d.length()>=8)
109 date = QDate( d.mid(0,4).toUInt(), d.mid(4,2).toUInt(), d.mid(6,2).toUInt() );
110 if (d.length()>9 && d[8].upper()=='T')
111 time = QTime( d.mid(9,2).toUInt(), d.mid(11,2).toUInt(), d.mid(13,2).toUInt() );
112
113 return QDateTime( date, time );
114}
115
diff --git a/kabc/vcardconverter.h b/kabc/vcardconverter.h
new file mode 100644
index 0000000..52259fc
--- a/dev/null
+++ b/kabc/vcardconverter.h
@@ -0,0 +1,120 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_VCARDCONVERTER_H
29#define KABC_VCARDCONVERTER_H
30
31#include <qstring.h>
32
33#include "addressee.h"
34
35namespace KABC {
36
37/**
38 * Class to convert a vcard string to a addressee and vice versa.
39 * At the moment there exists read support for vCard2.1 and vCard3.0
40 * and write support for vCard3.0
41 */
42class VCardConverter
43{
44public:
45
46 /**
47 * @li v2_1 - VCard format version 2.1
48 * @li v3_0 - VCard format version 3.0
49 */
50 enum Version
51 {
52 v2_1,
53 v3_0
54 };
55
56 /**
57 * Constructor.
58 */
59 VCardConverter();
60
61 /**
62 * Destructor.
63 */
64 ~VCardConverter();
65
66 /**
67 * Converts a vcard string to an addressee.
68 *
69 * @param str The vcard string.
70 * @param addr The addressee.
71 * @param version The version of the vcard string.
72 */
73 bool vCardToAddressee( const QString &str, Addressee &addr, Version version = v3_0 );
74
75 /**
76 * Converts an addressee to a vcard string.
77 *
78 * @param addr The addressee.
79 * @param str The vcard string.
80 * @param version The version of the vcard string.
81 */
82 bool addresseeToVCard( const Addressee &addr, QString &str, Version version = v3_0 );
83
84private:
85 struct VCardConverterData;
86 VCardConverterData *d;
87};
88
89
90/**
91 Helper functions
92 */
93
94/**
95 * Converts a QDateTime to a date string as it is used in VCard and LDIF files.
96 * The return value is in the form "yyyyMMddThhmmssZ" (e.g. "20031201T120000Z")
97 * @param dateTime date and time to be converted
98 * @since 3.2
99 */
100QString dateToVCardString( const QDateTime &dateTime );
101
102/**
103 * Converts a QDate to a short date string as it is used in VCard and LDIF files.
104 * The return value is in the form "yyyyMMdd" (e.g. "20031201")
105 * @param date date to be converted
106 * @since 3.2
107 */
108QString dateToVCardString( const QDate &date );
109
110/**
111 * Converts a date string as it is used in VCard and LDIF files to a QDateTime value.
112 * If the date string does not contain a time value, it will be returned as 00:00:00.
113 * (e.g. "20031201T120000" will return a QDateTime for 2003-12-01 at 12:00)
114 * @param dateString string representing the date and time.
115 * @since 3.2
116 */
117QDateTime VCardStringToDate( const QString &dateString );
118
119}
120#endif
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
new file mode 100644
index 0000000..f90f813
--- a/dev/null
+++ b/kabc/vcardformatimpl.cpp
@@ -0,0 +1,1023 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qfile.h>
29#include <qregexp.h>
30
31#include <kdebug.h>
32#include <kmdcodec.h>
33#include <kstandarddirs.h>
34#include <ktempfile.h>
35
36#include <VCard.h>
37
38#include "addressbook.h"
39#include "vcardformatimpl.h"
40
41using namespace KABC;
42using namespace VCARD;
43
44bool VCardFormatImpl::load( Addressee &addressee, QFile *file )
45{
46 kdDebug(5700) << "VCardFormat::load()" << endl;
47
48 QByteArray fdata = file->readAll();
49 QCString data(fdata.data(), fdata.size()+1);
50
51 VCardEntity e( data );
52
53 VCardListIterator it( e.cardList() );
54
55 if ( it.current() ) {
56 VCard v(*it.current());
57 loadAddressee( addressee, v );
58 return true;
59 }
60
61 return false;
62}
63
64bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
65{
66 kdDebug(5700) << "VCardFormat::loadAll()" << endl;
67
68 QByteArray fdata = file->readAll();
69 QCString data(fdata.data(), fdata.size()+1);
70
71 VCardEntity e( data );
72
73 VCardListIterator it( e.cardList() );
74
75 for (; it.current(); ++it) {
76 VCard v(*it.current());
77 Addressee addressee;
78 loadAddressee( addressee, v );
79 addressee.setResource( resource );
80 addressBook->insertAddressee( addressee );
81 }
82
83 return true;
84}
85
86void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
87{
88 VCardEntity vcards;
89 VCardList vcardlist;
90 vcardlist.setAutoDelete( true );
91
92 VCard *v = new VCard;
93
94 saveAddressee( addressee, v, false );
95
96 vcardlist.append( v );
97 vcards.setCardList( vcardlist );
98
99 QCString vcardData = vcards.asString();
100 file->writeBlock( (const char*)vcardData, vcardData.length() );
101}
102
103void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file )
104{
105 VCardEntity vcards;
106 VCardList vcardlist;
107 vcardlist.setAutoDelete( true );
108
109 AddressBook::Iterator it;
110 for ( it = ab->begin(); it != ab->end(); ++it ) {
111 if ( (*it).resource() == resource ) {
112 VCard *v = new VCard;
113 saveAddressee( (*it), v, false );
114 (*it).setChanged( false );
115 vcardlist.append( v );
116 }
117 }
118
119 vcards.setCardList( vcardlist );
120
121 QCString vcardData = vcards.asString();
122 file->writeBlock( (const char*)vcardData, vcardData.length() );
123}
124
125bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard &v )
126{
127 QPtrList<ContentLine> contentLines = v.contentLineList();
128 ContentLine *cl;
129
130 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
131 QCString n = cl->name();
132 if ( n.left( 2 ) == "X-" ) {
133 n = n.mid( 2 );
134 int posDash = n.find( "-" );
135 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ),
136 QString::fromUtf8( n.mid( posDash + 1 ) ),
137 QString::fromUtf8( cl->value()->asString() ) );
138 continue;
139 }
140
141 EntityType type = cl->entityType();
142 switch( type ) {
143
144 case EntityUID:
145 addressee.setUid( readTextValue( cl ) );
146 break;
147
148 case EntityEmail:
149 addressee.insertEmail( readTextValue( cl ) );
150 break;
151
152 case EntityName:
153 addressee.setName( readTextValue( cl ) );
154 break;
155
156 case EntityFullName:
157 addressee.setFormattedName( readTextValue( cl ) );
158 break;
159
160 case EntityURL:
161 addressee.setUrl( KURL( readTextValue( cl ) ) );
162 break;
163
164 case EntityNickname:
165 addressee.setNickName( readTextValue( cl ) );
166 break;
167
168 case EntityLabel:
169 // not yet supported by kabc
170 break;
171
172 case EntityMailer:
173 addressee.setMailer( readTextValue( cl ) );
174 break;
175
176 case EntityTitle:
177 addressee.setTitle( readTextValue( cl ) );
178 break;
179
180 case EntityRole:
181 addressee.setRole( readTextValue( cl ) );
182 break;
183
184 case EntityOrganisation:
185 addressee.setOrganization( readTextValue( cl ) );
186 break;
187
188 case EntityNote:
189 addressee.setNote( readTextValue( cl ) );
190 break;
191
192 case EntityProductID:
193 addressee.setProductId( readTextValue( cl ) );
194 break;
195
196 case EntitySortString:
197 addressee.setSortString( readTextValue( cl ) );
198 break;
199
200 case EntityN:
201 readNValue( cl, addressee );
202 break;
203
204 case EntityAddress:
205 addressee.insertAddress( readAddressValue( cl ) );
206 break;
207
208 case EntityTelephone:
209 addressee.insertPhoneNumber( readTelephoneValue( cl ) );
210 break;
211
212 case EntityCategories:
213 addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) );
214 break;
215
216 case EntityBirthday:
217 addressee.setBirthday( readDateValue( cl ) );
218 break;
219
220 case EntityRevision:
221 addressee.setRevision( readDateTimeValue( cl ) );
222 break;
223
224 case EntityGeo:
225 addressee.setGeo( readGeoValue( cl ) );
226 break;
227
228 case EntityTimeZone:
229 addressee.setTimeZone( readUTCValue( cl ) );
230 break;
231
232 case EntityVersion:
233 break;
234
235 case EntityClass:
236 addressee.setSecrecy( readClassValue( cl ) );
237 break;
238
239 case EntityKey:
240 addressee.insertKey( readKeyValue( cl ) );
241 break;
242
243 case EntityPhoto:
244 addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) );
245 break;
246
247 case EntityLogo:
248 addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) );
249 break;
250
251 case EntityAgent:
252 addressee.setAgent( readAgentValue( cl ) );
253 break;
254
255 case EntitySound:
256 addressee.setSound( readSoundValue( cl, addressee ) );
257 break;
258
259 default:
260 kdDebug(5700) << "VCardFormat::load(): Unsupported entity: "
261 << int( type ) << ": " << cl->asString() << endl;
262 break;
263 }
264 }
265
266 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
267 EntityType type = cl->entityType();
268 if ( type == EntityLabel ) {
269 int type = readAddressParam( cl );
270 Address address = addressee.address( type );
271 if ( address.isEmpty() )
272 address.setType( type );
273
274 address.setLabel( QString::fromUtf8( cl->value()->asString() ) );
275 addressee.insertAddress( address );
276 }
277 }
278
279 return true;
280}
281
282void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern )
283{
284 ContentLine cl;
285 QString value;
286
287 addTextValue( v, EntityName, addressee.name() );
288 addTextValue( v, EntityUID, addressee.uid() );
289 addTextValue( v, EntityFullName, addressee.formattedName() );
290
291 QStringList emails = addressee.emails();
292 QStringList::ConstIterator it4;
293 for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) {
294 addTextValue( v, EntityEmail, *it4 );
295 }
296
297 QStringList customs = addressee.customs();
298 QStringList::ConstIterator it5;
299 for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) {
300 addCustomValue( v, *it5 );
301 }
302
303 addTextValue( v, EntityURL, addressee.url().url() );
304
305 addNValue( v, addressee );
306
307 addTextValue( v, EntityNickname, addressee.nickName() );
308 addTextValue( v, EntityMailer, addressee.mailer() );
309 addTextValue( v, EntityTitle, addressee.title() );
310 addTextValue( v, EntityRole, addressee.role() );
311 addTextValue( v, EntityOrganisation, addressee.organization() );
312 addTextValue( v, EntityNote, addressee.note() );
313 addTextValue( v, EntityProductID, addressee.productId() );
314 addTextValue( v, EntitySortString, addressee.sortString() );
315
316 Address::List addresses = addressee.addresses();
317 Address::List::ConstIterator it3;
318 for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) {
319 addAddressValue( v, *it3 );
320 addLabelValue( v, *it3 );
321 }
322
323 PhoneNumber::List phoneNumbers = addressee.phoneNumbers();
324 PhoneNumber::List::ConstIterator it2;
325 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
326 addTelephoneValue( v, *it2 );
327 }
328
329 Key::List keys = addressee.keys();
330 Key::List::ConstIterator it6;
331 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) {
332 addKeyValue( v, *it6 );
333 }
334
335 addTextValue( v, EntityCategories, addressee.categories().join(",") );
336
337 addDateValue( v, EntityBirthday, addressee.birthday().date() );
338 addDateTimeValue( v, EntityRevision, addressee.revision() );
339 addGeoValue( v, addressee.geo() );
340 addUTCValue( v, addressee.timeZone() );
341
342 addClassValue( v, addressee.secrecy() );
343
344 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern );
345 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern );
346
347 addAgentValue( v, addressee.agent() );
348
349 addSoundValue( v, addressee.sound(), addressee, intern );
350}
351
352void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt )
353{
354 if ( txt.isEmpty() ) return;
355
356 ContentLine cl;
357 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() );
358 QString value = txt.mid( txt.find( ":" ) + 1 );
359 if ( value.isEmpty() )
360 return;
361 cl.setValue( new TextValue( value.utf8() ) );
362 v->add(cl);
363}
364
365void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt )
366{
367 if ( txt.isEmpty() ) return;
368
369 ContentLine cl;
370 cl.setName( EntityTypeToParamName( type ) );
371 cl.setValue( new TextValue( txt.utf8() ) );
372 v->add(cl);
373}
374
375void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type,
376 const QDate &date )
377{
378 if ( !date.isValid() ) return;
379
380 ContentLine cl;
381 cl.setName( EntityTypeToParamName( type ) );
382
383 DateValue *v = new DateValue( date );
384 cl.setValue( v );
385 vcard->add(cl);
386}
387
388void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type,
389 const QDateTime &dateTime )
390{
391 if ( !dateTime.isValid() ) return;
392
393 ContentLine cl;
394 cl.setName( EntityTypeToParamName( type ) );
395
396 DateValue *v = new DateValue( dateTime );
397 cl.setValue( v );
398 vcard->add(cl);
399}
400
401void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a )
402{
403 if ( a.isEmpty() )
404 return;
405
406 ContentLine cl;
407 cl.setName( EntityTypeToParamName( EntityAddress ) );
408
409 AdrValue *v = new AdrValue;
410 v->setPOBox( a.postOfficeBox().utf8() );
411 v->setExtAddress( a.extended().utf8() );
412 v->setStreet( a.street().utf8() );
413 v->setLocality( a.locality().utf8() );
414 v->setRegion( a.region().utf8() );
415 v->setPostCode( a.postalCode().utf8() );
416 v->setCountryName( a.country().utf8() );
417 cl.setValue( v );
418
419 addAddressParam( &cl, a.type() );
420
421 vcard->add( cl );
422}
423
424void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a )
425{
426 if ( a.label().isEmpty() ) return;
427
428 ContentLine cl;
429 cl.setName( EntityTypeToParamName( EntityLabel ) );
430 cl.setValue( new TextValue( a.label().utf8() ) );
431
432 addAddressParam( &cl, a.type() );
433
434 vcard->add( cl );
435}
436
437void VCardFormatImpl::addAddressParam( ContentLine *cl, int type )
438{
439 ParamList params;
440 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) );
441 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) );
442 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) );
443 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) );
444 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) );
445 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) );
446 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) );
447 cl->setParamList( params );
448}
449
450void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo )
451{
452 if ( !geo.isValid() ) return;
453
454 ContentLine cl;
455 cl.setName( EntityTypeToParamName( EntityGeo ) );
456
457 GeoValue *v = new GeoValue;
458 v->setLatitude( geo.latitude() );
459 v->setLongitude( geo.longitude() );
460
461 cl.setValue( v );
462 vcard->add(cl);
463}
464
465void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz )
466{
467 if ( !tz.isValid() ) return;
468
469 ContentLine cl;
470 cl.setName( EntityTypeToParamName( EntityTimeZone ) );
471
472 UTCValue *v = new UTCValue;
473
474 v->setPositive( tz.offset() >= 0 );
475 v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
476 v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
477
478 cl.setValue( v );
479 vcard->add(cl);
480}
481
482void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy )
483{
484 ContentLine cl;
485 cl.setName( EntityTypeToParamName( EntityClass ) );
486
487 ClassValue *v = new ClassValue;
488 switch ( secrecy.type() ) {
489 case Secrecy::Public:
490 v->setType( (int)ClassValue::Public );
491 break;
492 case Secrecy::Private:
493 v->setType( (int)ClassValue::Private );
494 break;
495 case Secrecy::Confidential:
496 v->setType( (int)ClassValue::Confidential );
497 break;
498 }
499
500 cl.setValue( v );
501 vcard->add(cl);
502}
503
504
505Address VCardFormatImpl::readAddressValue( ContentLine *cl )
506{
507 Address a;
508 AdrValue *v = (AdrValue *)cl->value();
509 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) );
510 a.setExtended( QString::fromUtf8( v->extAddress() ) );
511 a.setStreet( QString::fromUtf8( v->street() ) );
512 a.setLocality( QString::fromUtf8( v->locality() ) );
513 a.setRegion( QString::fromUtf8( v->region() ) );
514 a.setPostalCode( QString::fromUtf8( v->postCode() ) );
515 a.setCountry( QString::fromUtf8( v->countryName() ) );
516
517 a.setType( readAddressParam( cl ) );
518
519 return a;
520}
521
522int VCardFormatImpl::readAddressParam( ContentLine *cl )
523{
524 int type = 0;
525 ParamList params = cl->paramList();
526 ParamListIterator it( params );
527 for( ; it.current(); ++it ) {
528 if ( (*it)->name() == "TYPE" ) {
529 if ( (*it)->value() == "dom" ) type |= Address::Dom;
530 else if ( (*it)->value() == "intl" ) type |= Address::Intl;
531 else if ( (*it)->value() == "parcel" ) type |= Address::Parcel;
532 else if ( (*it)->value() == "postal" ) type |= Address::Postal;
533 else if ( (*it)->value() == "work" ) type |= Address::Work;
534 else if ( (*it)->value() == "home" ) type |= Address::Home;
535 else if ( (*it)->value() == "pref" ) type |= Address::Pref;
536 }
537 }
538 return type;
539}
540
541void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a )
542{
543 ContentLine cl;
544 cl.setName(EntityTypeToParamName( EntityN ) );
545 NValue *v = new NValue;
546 v->setFamily( a.familyName().utf8() );
547 v->setGiven( a.givenName().utf8() );
548 v->setMiddle( a.additionalName().utf8() );
549 v->setPrefix( a.prefix().utf8() );
550 v->setSuffix( a.suffix().utf8() );
551
552 cl.setValue( v );
553 vcard->add(cl);
554}
555
556void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a )
557{
558 NValue *v = (NValue *)cl->value();
559 a.setFamilyName( QString::fromUtf8( v->family() ) );
560 a.setGivenName( QString::fromUtf8( v->given() ) );
561 a.setAdditionalName( QString::fromUtf8( v->middle() ) );
562 a.setPrefix( QString::fromUtf8( v->prefix() ) );
563 a.setSuffix( QString::fromUtf8( v->suffix() ) );
564}
565
566void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p )
567{
568 if ( p.number().isEmpty() )
569 return;
570
571 ContentLine cl;
572 cl.setName(EntityTypeToParamName(EntityTelephone));
573 cl.setValue(new TelValue( p.number().utf8() ));
574
575 ParamList params;
576 if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) );
577 if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) );
578 if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) );
579 if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) );
580 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) );
581 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) );
582 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) );
583 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) );
584 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) );
585 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) );
586 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) );
587 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) );
588 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) );
589 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) );
590 cl.setParamList( params );
591
592 v->add(cl);
593}
594
595PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl )
596{
597 PhoneNumber p;
598 TelValue *value = (TelValue *)cl->value();
599 p.setNumber( QString::fromUtf8( value->asString() ) );
600
601 int type = 0;
602 ParamList params = cl->paramList();
603 ParamListIterator it( params );
604 for( ; it.current(); ++it ) {
605 if ( (*it)->name() == "TYPE" ) {
606 if ( (*it)->value() == "home" ) type |= PhoneNumber::Home;
607 else if ( (*it)->value() == "work" ) type |= PhoneNumber::Work;
608 else if ( (*it)->value() == "msg" ) type |= PhoneNumber::Msg;
609 else if ( (*it)->value() == "pref" ) type |= PhoneNumber::Pref;
610 else if ( (*it)->value() == "voice" ) type |= PhoneNumber::Voice;
611 else if ( (*it)->value() == "fax" ) type |= PhoneNumber::Fax;
612 else if ( (*it)->value() == "cell" ) type |= PhoneNumber::Cell;
613 else if ( (*it)->value() == "video" ) type |= PhoneNumber::Video;
614 else if ( (*it)->value() == "bbs" ) type |= PhoneNumber::Bbs;
615 else if ( (*it)->value() == "modem" ) type |= PhoneNumber::Modem;
616 else if ( (*it)->value() == "car" ) type |= PhoneNumber::Car;
617 else if ( (*it)->value() == "isdn" ) type |= PhoneNumber::Isdn;
618 else if ( (*it)->value() == "pcs" ) type |= PhoneNumber::Pcs;
619 else if ( (*it)->value() == "pager" ) type |= PhoneNumber::Pager;
620 }
621 }
622 p.setType( type );
623
624 return p;
625}
626
627QString VCardFormatImpl::readTextValue( ContentLine *cl )
628{
629 VCARD::Value *value = cl->value();
630 if ( value ) {
631 return QString::fromUtf8( value->asString() );
632 } else {
633 kdDebug(5700) << "No value: " << cl->asString() << endl;
634 return QString::null;
635 }
636}
637
638QDate VCardFormatImpl::readDateValue( ContentLine *cl )
639{
640 DateValue *dateValue = (DateValue *)cl->value();
641 if ( dateValue )
642 return dateValue->qdate();
643 else
644 return QDate();
645}
646
647QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl )
648{
649 DateValue *dateValue = (DateValue *)cl->value();
650 if ( dateValue )
651 return dateValue->qdt();
652 else
653 return QDateTime();
654}
655
656Geo VCardFormatImpl::readGeoValue( ContentLine *cl )
657{
658 GeoValue *geoValue = (GeoValue *)cl->value();
659 if ( geoValue ) {
660 Geo geo( geoValue->latitude(), geoValue->longitude() );
661 return geo;
662 } else
663 return Geo();
664}
665
666TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl )
667{
668 UTCValue *utcValue = (UTCValue *)cl->value();
669 if ( utcValue ) {
670 TimeZone tz;
671 tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1));
672 return tz;
673 } else
674 return TimeZone();
675}
676
677Secrecy VCardFormatImpl::readClassValue( ContentLine *cl )
678{
679 ClassValue *classValue = (ClassValue *)cl->value();
680 if ( classValue ) {
681 Secrecy secrecy;
682 switch ( classValue->type() ) {
683 case ClassValue::Public:
684 secrecy.setType( Secrecy::Public );
685 break;
686 case ClassValue::Private:
687 secrecy.setType( Secrecy::Private );
688 break;
689 case ClassValue::Confidential:
690 secrecy.setType( Secrecy::Confidential );
691 break;
692 }
693
694 return secrecy;
695 } else
696 return Secrecy();
697}
698
699void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key )
700{
701 ContentLine cl;
702 cl.setName( EntityTypeToParamName( EntityKey ) );
703
704 ParamList params;
705 if ( key.isBinary() ) {
706 cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) );
707 params.append( new Param( "ENCODING", "b" ) );
708 } else {
709 cl.setValue( new TextValue( key.textData().utf8() ) );
710 }
711
712 switch ( key.type() ) {
713 case Key::X509:
714 params.append( new Param( "TYPE", "X509" ) );
715 break;
716 case Key::PGP:
717 params.append( new Param( "TYPE", "PGP" ) );
718 break;
719 case Key::Custom:
720 params.append( new Param( "TYPE", key.customTypeString().utf8() ) );
721 break;
722 }
723
724 cl.setParamList( params );
725 vcard->add( cl );
726}
727
728Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl )
729{
730 Key key;
731 bool isBinary = false;
732 TextValue *v = (TextValue *)cl->value();
733
734 ParamList params = cl->paramList();
735 ParamListIterator it( params );
736 for( ; it.current(); ++it ) {
737 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
738 isBinary = true;
739 if ( (*it)->name() == "TYPE" ) {
740 if ( (*it)->value().isEmpty() )
741 continue;
742 if ( (*it)->value() == "X509" )
743 key.setType( Key::X509 );
744 else if ( (*it)->value() == "PGP" )
745 key.setType( Key::PGP );
746 else {
747 key.setType( Key::Custom );
748 key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) );
749 }
750 }
751 }
752
753
754 if ( isBinary ) {
755 QByteArray data;
756 KCodecs::base64Decode( v->asString().stripWhiteSpace(), data );
757 key.setBinaryData( data );
758 } else {
759 key.setTextData( QString::fromUtf8( v->asString() ) );
760 }
761
762 return key;
763}
764
765
766void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent )
767{
768 if ( agent.isIntern() && !agent.addressee() )
769 return;
770
771 if ( !agent.isIntern() && agent.url().isEmpty() )
772 return;
773
774 ContentLine cl;
775 cl.setName( EntityTypeToParamName( EntityAgent ) );
776
777 ParamList params;
778 if ( agent.isIntern() ) {
779 QString vstr;
780 Addressee *addr = agent.addressee();
781 if ( addr ) {
782 writeToString( (*addr), vstr );
783
784 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
785/*US
786 vstr.replace( ":", "\\:" );
787 vstr.replace( ",", "\\," );
788 vstr.replace( ";", "\\;" );
789 vstr.replace( "\r\n", "\\n" );
790*/
791 vstr.replace( QRegExp(":"), "\\:" );
792 vstr.replace( QRegExp(","), "\\," );
793 vstr.replace( QRegExp(";"), "\\;" );
794 vstr.replace( QRegExp("\r\n"), "\\n" );
795
796 cl.setValue( new TextValue( vstr.utf8() ) );
797 } else
798 return;
799 } else {
800 cl.setValue( new TextValue( agent.url().utf8() ) );
801 params.append( new Param( "VALUE", "uri" ) );
802 }
803
804 cl.setParamList( params );
805 vcard->add( cl );
806}
807
808Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl )
809{
810 Agent agent;
811 bool isIntern = true;
812 TextValue *v = (TextValue *)cl->value();
813
814 ParamList params = cl->paramList();
815 ParamListIterator it( params );
816 for( ; it.current(); ++it ) {
817 if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" )
818 isIntern = false;
819 }
820
821 if ( isIntern ) {
822 QString vstr = QString::fromUtf8( v->asString() );
823 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
824/*US
825 vstr.replace( "\\n", "\r\n" );
826 vstr.replace( "\\:", ":" );
827 vstr.replace( "\\,", "," );
828 vstr.replace( "\\;", ";" );
829*/
830 vstr.replace( QRegExp("\\n"), "\r\n" );
831 vstr.replace( QRegExp("\\:"), ":" );
832 vstr.replace( QRegExp("\\,"), "," );
833 vstr.replace( QRegExp("\\;"), ";" );
834
835 Addressee *addr = new Addressee;
836 readFromString( vstr, *addr );
837 agent.setAddressee( addr );
838 } else {
839 agent.setUrl( QString::fromUtf8( v->asString() ) );
840 }
841
842 return agent;
843}
844
845void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern )
846{
847 ContentLine cl;
848 cl.setName( EntityTypeToParamName( type ) );
849
850 if ( pic.isIntern() && pic.data().isNull() )
851 return;
852
853 if ( !pic.isIntern() && pic.url().isEmpty() )
854 return;
855
856 ParamList params;
857 if ( pic.isIntern() ) {
858 QImage img = pic.data();
859 if ( intern ) { // only for vCard export we really write the data inline
860 QByteArray data;
861 QDataStream s( data, IO_WriteOnly );
862 s.setVersion( 4 ); // to produce valid png files
863 s << img;
864 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
865
866 } else { // save picture in cache
867 QString dir;
868 if ( type == EntityPhoto )
869 dir = "photos";
870 if ( type == EntityLogo )
871 dir = "logos";
872
873 img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() );
874 cl.setValue( new TextValue( "<dummy>" ) );
875 }
876 params.append( new Param( "ENCODING", "b" ) );
877 if ( !pic.type().isEmpty() )
878 params.append( new Param( "TYPE", pic.type().utf8() ) );
879 } else {
880
881 cl.setValue( new TextValue( pic.url().utf8() ) );
882 params.append( new Param( "VALUE", "uri" ) );
883 }
884
885 cl.setParamList( params );
886 vcard->add( cl );
887}
888
889Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr )
890{
891 Picture pic;
892 bool isInline = false;
893 QString picType;
894 TextValue *v = (TextValue *)cl->value();
895
896 ParamList params = cl->paramList();
897 ParamListIterator it( params );
898 for( ; it.current(); ++it ) {
899 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
900 isInline = true;
901 if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() )
902 picType = QString::fromUtf8( (*it)->value() );
903 }
904
905 if ( isInline ) {
906 QImage img;
907 if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache
908 QString dir;
909 if ( type == EntityPhoto )
910 dir = "photos";
911 if ( type == EntityLogo )
912 dir = "logos";
913
914 img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) );
915 } else {
916 QByteArray data;
917 KCodecs::base64Decode( v->asString(), data );
918 img.loadFromData( data );
919 }
920 pic.setData( img );
921 pic.setType( picType );
922 } else {
923 pic.setUrl( QString::fromUtf8( v->asString() ) );
924 }
925
926 return pic;
927}
928
929void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern )
930{
931 ContentLine cl;
932 cl.setName( EntityTypeToParamName( EntitySound ) );
933
934 if ( sound.isIntern() && sound.data().isNull() )
935 return;
936
937 if ( !sound.isIntern() && sound.url().isEmpty() )
938 return;
939
940 ParamList params;
941 if ( sound.isIntern() ) {
942 QByteArray data = sound.data();
943 if ( intern ) { // only for vCard export we really write the data inline
944 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
945 } else { // save sound in cache
946 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
947 if ( file.open( IO_WriteOnly ) ) {
948 file.writeBlock( data );
949 }
950 cl.setValue( new TextValue( "<dummy>" ) );
951 }
952 params.append( new Param( "ENCODING", "b" ) );
953 } else {
954 cl.setValue( new TextValue( sound.url().utf8() ) );
955 params.append( new Param( "VALUE", "uri" ) );
956 }
957
958 cl.setParamList( params );
959 vcard->add( cl );
960}
961
962Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr )
963{
964 Sound sound;
965 bool isInline = false;
966 TextValue *v = (TextValue *)cl->value();
967
968 ParamList params = cl->paramList();
969 ParamListIterator it( params );
970 for( ; it.current(); ++it ) {
971 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
972 isInline = true;
973 }
974
975 if ( isInline ) {
976 QByteArray data;
977 if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache
978 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
979 if ( file.open( IO_ReadOnly ) ) {
980 data = file.readAll();
981 file.close();
982 }
983 } else {
984 KCodecs::base64Decode( v->asString(), data );
985 }
986 sound.setData( data );
987 } else {
988 sound.setUrl( QString::fromUtf8( v->asString() ) );
989 }
990
991 return sound;
992}
993
994bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee )
995{
996 VCardEntity e( vcard.utf8() );
997 VCardListIterator it( e.cardList() );
998
999 if ( it.current() ) {
1000 VCard v(*it.current());
1001 loadAddressee( addressee, v );
1002 return true;
1003 }
1004
1005 return false;
1006}
1007
1008bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard )
1009{
1010 VCardEntity vcards;
1011 VCardList vcardlist;
1012 vcardlist.setAutoDelete( true );
1013
1014 VCard *v = new VCard;
1015
1016 saveAddressee( addressee, v, true );
1017
1018 vcardlist.append( v );
1019 vcards.setCardList( vcardlist );
1020 vcard = QString::fromUtf8( vcards.asString() );
1021
1022 return true;
1023}
diff --git a/kabc/vcardformatimpl.h b/kabc/vcardformatimpl.h
new file mode 100644
index 0000000..2dd68d9
--- a/dev/null
+++ b/kabc/vcardformatimpl.h
@@ -0,0 +1,112 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#ifndef KABC_VCARDFORMATIMPL_H
29#define KABC_VCARDFORMATIMPL_H
30
31#include <qstring.h>
32#include <qfile.h>
33
34#include "address.h"
35#include "addressee.h"
36
37#include <VCard.h>
38
39namespace KABC {
40
41class AddressBook;
42
43/**
44 @short Implementation of vCard backend for address book.
45
46 This class implements reading and writing of address book information using
47 the vCard format. It requires the vCard lib from kdepim.
48*/
49class VCardFormatImpl
50{
51 public:
52 bool load( Addressee &, QFile *file );
53 bool loadAll( AddressBook *, Resource *, QFile *file );
54 void save( const Addressee &, QFile *file );
55 void saveAll( AddressBook *, Resource *, QFile *file );
56
57 bool readFromString( const QString &vcard, Addressee &addr );
58 bool writeToString( const Addressee &addressee, QString &vcard );
59
60 protected:
61 bool loadAddressee( Addressee &, VCARD::VCard & );
62 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern );
63
64 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & );
65 QString readTextValue( VCARD::ContentLine * );
66
67 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & );
68 QDate readDateValue( VCARD::ContentLine * );
69
70 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & );
71 QDateTime readDateTimeValue( VCARD::ContentLine * );
72
73 void addAddressValue( VCARD::VCard *, const Address & );
74 Address readAddressValue( VCARD::ContentLine * );
75
76 void addLabelValue( VCARD::VCard *, const Address & );
77
78 void addTelephoneValue( VCARD::VCard *, const PhoneNumber & );
79 PhoneNumber readTelephoneValue( VCARD::ContentLine * );
80
81 void addNValue( VCARD::VCard *, const Addressee & );
82 void readNValue( VCARD::ContentLine *, Addressee & );
83
84 void addCustomValue( VCARD::VCard *, const QString & );
85
86 void addAddressParam( VCARD::ContentLine *, int );
87 int readAddressParam( VCARD::ContentLine * );
88
89 void addGeoValue( VCARD::VCard *, const Geo & );
90 Geo readGeoValue( VCARD::ContentLine * );
91
92 void addUTCValue( VCARD::VCard *, const TimeZone & );
93 TimeZone readUTCValue( VCARD::ContentLine * );
94
95 void addClassValue( VCARD::VCard *, const Secrecy & );
96 Secrecy readClassValue( VCARD::ContentLine * );
97
98 void addKeyValue( VCARD::VCard *, const Key & );
99 Key readKeyValue( VCARD::ContentLine * );
100
101 void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool );
102 Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr );
103
104 void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool );
105 Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr );
106
107 void addAgentValue( VCARD::VCard *, const Agent & );
108 Agent readAgentValue( VCARD::ContentLine * );
109};
110
111}
112#endif
diff --git a/kabc/vcardformatplugin.cpp b/kabc/vcardformatplugin.cpp
new file mode 100644
index 0000000..3cba59a
--- a/dev/null
+++ b/kabc/vcardformatplugin.cpp
@@ -0,0 +1,66 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include "vcardformatplugin.h"
22#include "vcardformatimpl.h"
23
24using namespace KABC;
25
26VCardFormatPlugin::VCardFormatPlugin()
27{
28 mImpl = new VCardFormatImpl;
29}
30
31VCardFormatPlugin::~VCardFormatPlugin()
32{
33 delete mImpl;
34}
35
36bool VCardFormatPlugin::load( Addressee &addressee, QFile *file )
37{
38 return mImpl->load( addressee, file );
39}
40
41bool VCardFormatPlugin::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
42{
43 return mImpl->loadAll( addressBook, resource, file );
44}
45
46void VCardFormatPlugin::save( const Addressee &addressee, QFile *file )
47{
48 mImpl->save( addressee, file );
49}
50
51void VCardFormatPlugin::saveAll( AddressBook *addressBook, Resource *resource, QFile *file )
52{
53 mImpl->saveAll( addressBook, resource, file );
54}
55
56bool VCardFormatPlugin::checkFormat( QFile *file ) const
57{
58 QString line;
59
60 file->readLine( line, 1024 );
61 line = line.stripWhiteSpace();
62 if ( line == "BEGIN:VCARD" )
63 return true;
64 else
65 return false;
66}
diff --git a/kabc/vcardformatplugin.h b/kabc/vcardformatplugin.h
new file mode 100644
index 0000000..dc2b45d
--- a/dev/null
+++ b/kabc/vcardformatplugin.h
@@ -0,0 +1,56 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef KABC_VCARDFORMATPLUGIN_H
22#define KABC_VCARDFORMATPLUGIN_H
23
24#include "formatplugin.h"
25
26namespace KABC {
27
28class AddressBook;
29class Addressee;
30class VCardFormatImpl;
31
32/**
33 @short Interface of vCard backend for address book.
34
35 This class implements the file format interface of address book entries for
36 the vCard format.
37*/
38class VCardFormatPlugin : public FormatPlugin
39{
40 public:
41 VCardFormatPlugin();
42 virtual ~VCardFormatPlugin();
43
44 bool load( Addressee &, QFile *file );
45 bool loadAll( AddressBook *, Resource *, QFile *file );
46 void save( const Addressee &, QFile *file );
47 void saveAll( AddressBook *, Resource *, QFile *file );
48
49 bool checkFormat( QFile *file ) const;
50
51 private:
52 VCardFormatImpl *mImpl;
53};
54
55}
56#endif
diff --git a/kabc/vcardparser/vcard.cpp b/kabc/vcardparser/vcard.cpp
new file mode 100644
index 0000000..da97ec2
--- a/dev/null
+++ b/kabc/vcardparser/vcard.cpp
@@ -0,0 +1,144 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include "vcard.h"
22
23using namespace KABC;
24
25VCard::VCard()
26 : mLineMap( 0 )
27{
28}
29
30VCard::VCard( const VCard& vcard )
31 : mLineMap( 0 )
32{
33 if ( vcard.mLineMap ) {
34 if ( !mLineMap )
35 mLineMap = new QMap<QString, QValueList<VCardLine> >;
36
37 *mLineMap = *(vcard.mLineMap);
38 } else {
39 delete mLineMap;
40 mLineMap = 0;
41 }
42}
43
44VCard::~VCard()
45{
46 delete mLineMap;
47 mLineMap = 0;
48}
49
50VCard& VCard::operator=( const VCard& vcard )
51{
52 if ( &vcard == this )
53 return *this;
54
55 if ( vcard.mLineMap ) {
56 if ( !mLineMap )
57 mLineMap = new QMap<QString, QValueList<VCardLine> >;
58
59 *mLineMap = *(vcard.mLineMap);
60 } else {
61 delete mLineMap;
62 mLineMap = 0;
63 }
64
65 return *this;
66}
67
68void VCard::clear()
69{
70 if ( mLineMap )
71 mLineMap->clear();
72}
73
74QStringList VCard::identifiers() const
75{
76 if ( !mLineMap )
77 return QStringList();
78 else {
79//US method QMap::keys() not available yet. SO collect the data manually
80//US return mLineMap->keys();
81
82 QStringList result;
83
84 QMap< QString, VCardLine::List >::ConstIterator it;
85 for( it = mLineMap->begin(); it != mLineMap->end(); ++it ) {
86 result << it.key().latin1();
87 }
88 return result;
89 }
90}
91
92void VCard::addLine( const VCardLine& line )
93{
94 if ( !mLineMap )
95 mLineMap = new QMap<QString, QValueList<VCardLine> >;
96
97 (*mLineMap)[ line.identifier() ].append( line );
98}
99
100VCardLine::List VCard::lines( const QString& identifier )
101{
102 if ( !mLineMap )
103 return VCardLine::List();
104 else
105 return (*mLineMap)[ identifier ];
106}
107
108VCardLine VCard::line( const QString& identifier )
109{
110 if ( !mLineMap )
111 return VCardLine();
112 else
113 return (*mLineMap)[ identifier ][ 0 ];
114}
115
116void VCard::setVersion( Version version )
117{
118 if ( !mLineMap )
119 mLineMap = new QMap<QString, QValueList<VCardLine> >;
120 else {
121//US mLineMap->erase( "VERSION" );
122 mLineMap->remove( "VERSION" );
123 }
124 VCardLine line;
125 line.setIdentifier( "VERSION" );
126 if ( version == v2_1 )
127 line.setIdentifier( "2.1" );
128 if ( version == v3_0 )
129 line.setIdentifier( "3.0" );
130
131 (*mLineMap)[ "VERSION" ].append( line );
132}
133
134VCard::Version VCard::version() const
135{
136 if ( !mLineMap )
137 return v3_0;
138
139 VCardLine line = (*mLineMap)[ "VERSION" ][ 0 ];
140 if ( line.value() == "2.1" )
141 return v2_1;
142 else
143 return v3_0;
144}
diff --git a/kabc/vcardparser/vcard.h b/kabc/vcardparser/vcard.h
new file mode 100644
index 0000000..ce672b5
--- a/dev/null
+++ b/kabc/vcardparser/vcard.h
@@ -0,0 +1,90 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef VCARD_H
22#define VCARD_H
23
24#include "vcardline.h"
25#include <qmap.h>
26#include <qstringlist.h>
27#include <qvaluelist.h>
28
29namespace KABC {
30
31class VCard
32{
33 public:
34 typedef QValueList<VCard> List;
35
36 enum Version { v2_1, v3_0 };
37
38 VCard();
39 VCard( const VCard& );
40
41 ~VCard();
42
43 VCard& operator=( const VCard& );
44
45 /**
46 * Removes all lines from the vCard.
47 */
48 void clear();
49
50 /**
51 * Returns a list of all identifiers that exists in the
52 * vCard.
53 */
54 QStringList identifiers() const;
55
56 /**
57 * Adds a VCardLine to the VCard
58 */
59 void addLine( const VCardLine& line );
60
61 /**
62 * Returns all lines of the vcard with a special identifier.
63 */
64 VCardLine::List lines( const QString& identifier );
65
66 /**
67 * Returns only the first line of the vcard with a special identifier.
68 */
69 VCardLine line( const QString& identifier );
70
71 /**
72 * Set the version of the vCard.
73 */
74 void setVersion( Version version );
75
76 /**
77 * Returns the version of this vCard.
78 */
79 Version version() const;
80
81 private:
82 QMap< QString, VCardLine::List > *mLineMap;
83
84 class VCardPrivate;
85 VCardPrivate *d;
86};
87
88}
89
90#endif
diff --git a/kabc/vcardparser/vcardline.cpp b/kabc/vcardparser/vcardline.cpp
new file mode 100644
index 0000000..84638f8
--- a/dev/null
+++ b/kabc/vcardparser/vcardline.cpp
@@ -0,0 +1,148 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include "vcardline.h"
22
23using namespace KABC;
24
25VCardLine::VCardLine()
26 : mParamMap( 0 )
27{
28}
29
30VCardLine::VCardLine( const QString &identifier )
31 : mParamMap( 0 )
32{
33 mIdentifier = identifier;
34}
35
36VCardLine::VCardLine( const QString &identifier, const QVariant &value )
37 : mParamMap( 0 )
38{
39 mIdentifier = identifier;
40 mValue = value;
41}
42
43VCardLine::VCardLine( const VCardLine& line )
44 : mParamMap( 0 )
45{
46 if ( line.mParamMap ) {
47 if ( !mParamMap )
48 mParamMap = new QMap<QString, QStringList>;
49
50 *mParamMap = *(line.mParamMap);
51 } else {
52 delete mParamMap;
53 mParamMap = 0;
54 }
55
56 mValue = line.mValue;
57 mIdentifier = line.mIdentifier;
58}
59
60VCardLine::~VCardLine()
61{
62 delete mParamMap;
63 mParamMap = 0;
64}
65
66VCardLine& VCardLine::operator=( const VCardLine& line )
67{
68 if ( &line == this )
69 return *this;
70
71 if ( line.mParamMap ) {
72 if ( !mParamMap )
73 mParamMap = new QMap<QString, QStringList>;
74
75 *mParamMap = *(line.mParamMap);
76 } else {
77 delete mParamMap;
78 mParamMap = 0;
79 }
80
81 mValue = line.mValue;
82 mIdentifier = line.mIdentifier;
83
84 return *this;
85}
86
87void VCardLine::setIdentifier( const QString& identifier )
88{
89 mIdentifier = identifier;
90}
91
92QString VCardLine::identifier() const
93{
94 return mIdentifier;
95}
96void VCardLine::setValue( const QVariant& value )
97{
98 mValue = value;
99}
100
101QVariant VCardLine::value() const
102{
103 return mValue;
104}
105
106QStringList VCardLine::parameterList() const
107{
108 if ( !mParamMap )
109 return QStringList();
110 else {
111//US method QMap::keys() not available yet. SO collect the data manually
112//US return mParamMap->keys();
113
114 QStringList result;
115
116 QMap<QString, QStringList>::ConstIterator it;
117 for( it = mParamMap->begin(); it != mParamMap->end(); ++it ) {
118 result << it.key().latin1();
119 }
120 return result;
121 }
122}
123
124void VCardLine::addParameter( const QString& param, const QString& value )
125{
126 if ( !mParamMap )
127 mParamMap = new QMap<QString, QStringList>;
128
129 QStringList &list = (*mParamMap)[ param ];
130 if ( list.find( value ) == list.end() ) // not included yet
131 list.append( value );
132}
133
134QStringList VCardLine::parameters( const QString& param ) const
135{
136 if ( !mParamMap )
137 return QStringList();
138 else
139 return (*mParamMap)[ param ];
140}
141
142QString VCardLine::parameter( const QString& param ) const
143{
144 if ( !mParamMap )
145 return QString::null;
146 else
147 return (*mParamMap)[ param ][ 0 ];
148}
diff --git a/kabc/vcardparser/vcardline.h b/kabc/vcardparser/vcardline.h
new file mode 100644
index 0000000..78b61f8
--- a/dev/null
+++ b/kabc/vcardparser/vcardline.h
@@ -0,0 +1,99 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef VCARDLINE_H
22#define VCARDLINE_H
23
24#include <qstringlist.h>
25#include <qvaluelist.h>
26#include <qvariant.h>
27#include <qmap.h>
28#include <qstring.h>
29
30namespace KABC {
31
32class VCardLine
33{
34 public:
35 typedef QValueList<VCardLine> List;
36
37 VCardLine();
38 VCardLine( const QString &identifier );
39 VCardLine( const QString &identifier, const QVariant &value );
40 VCardLine( const VCardLine& );
41
42 ~VCardLine();
43
44 VCardLine& operator=( const VCardLine& );
45
46 /**
47 * Sets the identifier of this line e.g. UID, FN, CLASS
48 */
49 void setIdentifier( const QString& identifier );
50
51 /**
52 * Returns the identifier of this line.
53 */
54 QString identifier() const;
55
56 /**
57 * Sets the value of of this line.
58 */
59 void setValue( const QVariant& value );
60
61 /**
62 * Returns the value of this line.
63 */
64 QVariant value() const;
65
66 /**
67 * Returns all parameters.
68 */
69 QStringList parameterList() const;
70
71 /**
72 * Add a new parameter to the line.
73 */
74 void addParameter( const QString& param, const QString& value );
75
76 /**
77 * Returns the values of a special parameter.
78 * You can get a list of all parameters with @ref paramList().
79 */
80 QStringList parameters( const QString& param ) const;
81
82 /**
83 * Returns only the first value of a special parameter.
84 * You can get a list of all parameters with @ref paramList().
85 */
86 QString parameter( const QString& param ) const;
87
88 private:
89 QMap< QString, QStringList > *mParamMap;
90 QString mIdentifier;
91 QVariant mValue;
92
93 class VCardLinePrivate;
94 VCardLinePrivate *d;
95};
96
97}
98
99#endif
diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp
new file mode 100644
index 0000000..9ea084d
--- a/dev/null
+++ b/kabc/vcardparser/vcardparser.cpp
@@ -0,0 +1,233 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <qregexp.h>
22
23#include <kmdcodec.h>
24
25#include "vcardparser.h"
26
27#define FOLD_WIDTH 75
28
29using namespace KABC;
30
31VCardParser::VCardParser()
32{
33}
34
35VCardParser::~VCardParser()
36{
37}
38
39VCard::List VCardParser::parseVCards( const QString& text )
40{
41 VCard currentVCard;
42 VCard::List vCardList;
43 QString currentLine;
44
45 QStringList lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), text );
46 QStringList::Iterator it;
47
48 bool inVCard = false;
49 for ( it = lines.begin(); it != lines.end(); ++it ) {
50
51 if ( (*it).isEmpty() ) // empty line
52 continue;
53
54 if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous
55 currentLine += (*it).remove( 0, 1 );
56 continue;
57 } else {
58 if ( inVCard && !currentLine.isEmpty() ) { // now parse the line
59 int colon = currentLine.find( ':' );
60 if ( colon == -1 ) { // invalid line
61 currentLine = (*it);
62 continue;
63 }
64
65 VCardLine vCardLine;
66 QString key = currentLine.left( colon ).stripWhiteSpace();
67 QString value = currentLine.mid( colon + 1 );
68
69 QStringList params = QStringList::split( ';', key );
70 vCardLine.setIdentifier( params[0] );
71 if ( params.count() > 1 ) { // find all parameters
72 for ( uint i = 1; i < params.count(); ++i ) {
73 QStringList pair = QStringList::split( '=', params[i] );
74//US if ( pair.size() == 1 ) {
75 if ( pair.count() == 1 ) {
76 pair.prepend( "type" );
77 }
78 if ( pair[1].contains( ',' ) ) { // parameter in type=x,y,z format
79 QStringList args = QStringList::split( ',', pair[ 1 ] );
80 for ( uint j = 0; j < args.count(); ++j )
81 vCardLine.addParameter( pair[0].lower(), args[j] );
82 } else
83 vCardLine.addParameter( pair[0].lower(), pair[1] );
84 }
85 }
86
87 params = vCardLine.parameterList();
88 if ( params.contains( "encoding" ) ) { // have to decode the data
89#if 0
90 QByteArray input, output;
91 input = value.local8Bit();
92 if ( vCardLine.parameter( "encoding" ).lower() == "b" )
93 KCodecs::base64Decode( input, output );
94 else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" )
95 KCodecs::quotedPrintableDecode( input, output );
96
97 //qDebug("VCardParser::parseVCards has to be verified");
98 //US I am not sure if this is correct
99 //US vCardLine.setValue( output );
100 QCString cs(output);
101 qDebug("len1 %d len2 %d ",input.size(), output.size( ));
102#endif
103 QCString cs = value.local8Bit();
104 qDebug("****************************************** ");
105 qDebug("************* WARNING ******************** ");
106 qDebug("****************************************** ");
107 qDebug("Make sure, the decoding is done after");
108 qDebug("QVariant conversion!");
109 qDebug("Insert Line DECODING OKAY, where this is implemented");
110 // use for decoding the above code!
111 vCardLine.setValue( cs );
112 } else {
113
114 //qDebug("VCardParser::parseVCards has to be verified");
115//US vCardLine.setValue( value.replace( "\\n", "\n" ) );
116 vCardLine.setValue( value.replace( QRegExp("\\n"), "\n" ) );
117 }
118
119 currentVCard.addLine( vCardLine );
120 }
121 // we do not save the start and end tag as vcardline
122 if ( (*it).lower().startsWith( "begin:vcard" ) ) {
123 inVCard = true;
124 //qDebug("VCardParser::parseVCards has to be verified");
125//US currentLine.setLength( 0 );
126 currentLine = "";
127 currentVCard.clear(); // flush vcard
128 continue;
129 }
130
131 if ( (*it).lower().startsWith( "end:vcard" ) ) {
132 inVCard = false;
133 vCardList.append( currentVCard );
134 //qDebug("VCardParser::parseVCards has to be verified");
135//US currentLine.setLength( 0 );
136 currentLine = "";
137 currentVCard.clear(); // flush vcard
138 continue;
139 }
140
141 currentLine = (*it);
142 }
143 }
144
145 return vCardList;
146}
147
148QString VCardParser::createVCards( const VCard::List& list )
149{
150 QString text;
151 QString textLine;
152 QString encodingType;
153 QStringList idents;
154 QStringList params;
155 QStringList values;
156 QStringList::ConstIterator identIt;
157 QStringList::Iterator paramIt;
158 QStringList::Iterator valueIt;
159
160 VCardLine::List lines;
161 VCardLine::List::Iterator lineIt;
162 VCard::List::ConstIterator cardIt;
163
164 bool hasEncoding;
165
166
167 // iterate over the cards
168 for ( cardIt = list.begin(); cardIt != list.end(); ++cardIt ) {
169 text.append( "BEGIN:VCARD\r\n" );
170
171 idents = (*cardIt).identifiers();
172 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
173 VCard card = (*cardIt);
174 lines = card.lines( (*identIt) );
175
176 // iterate over the lines
177 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
178 if ( !(*lineIt).value().asString().isEmpty() ) {
179 textLine = (*lineIt).identifier();
180
181 params = (*lineIt).parameterList();
182 hasEncoding = false;
183 if ( params.count() > 0 ) { // we have parameters
184 for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) {
185 if ( (*paramIt) == "encoding" ) {
186 hasEncoding = true;
187 encodingType = (*lineIt).parameter( "encoding" ).lower();
188 }
189
190 values = (*lineIt).parameters( *paramIt );
191 for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) {
192 textLine.append( ";" + (*paramIt).upper() );
193 if ( !(*valueIt).isEmpty() )
194 textLine.append( "=" + (*valueIt) );
195 }
196 }
197 }
198
199 if ( hasEncoding ) { // have to encode the data
200 QByteArray input, output;
201
202 qDebug("VCardParser::createVCards has to be verified");
203//US input = (*lineIt).value().toByteArray();
204
205//US I am not sure if this is correct
206 QCString cs ((*lineIt).value().toCString());
207 input = cs;
208
209 if ( encodingType == "b" )
210 KCodecs::base64Encode( input, output );
211 else if ( encodingType == "quoted-printable" )
212 KCodecs::quotedPrintableEncode( input, output );
213 textLine.append( ":" + QString( output ) );
214 } else {
215 qDebug("VCardParser::createVCards has to be verified");
216//US textLine.append( ":" + (*lineIt).value().asString().replace( "\n", "\\n" ) );
217 textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) );
218 }
219 if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line
220 for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i )
221 text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" );
222 } else
223 text.append( textLine + "\r\n" );
224 }
225 }
226 }
227
228 text.append( "END:VCARD\r\n" );
229 text.append( "\r\n" );
230 }
231
232 return text;
233}
diff --git a/kabc/vcardparser/vcardparser.h b/kabc/vcardparser/vcardparser.h
new file mode 100644
index 0000000..ae185ef
--- a/dev/null
+++ b/kabc/vcardparser/vcardparser.h
@@ -0,0 +1,40 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef VCARDPARSER_H
22#define VCARDPARSER_H
23
24#include "vcard.h"
25
26namespace KABC {
27
28class VCardParser
29{
30 public:
31 VCardParser();
32 ~VCardParser();
33
34 static VCard::List parseVCards( const QString& text );
35 static QString createVCards( const VCard::List& list );
36};
37
38}
39
40#endif
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp
new file mode 100644
index 0000000..01c5b3e
--- a/dev/null
+++ b/kabc/vcardparser/vcardtool.cpp
@@ -0,0 +1,883 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <qdatastream.h>
22#include <qstring.h>
23#include <qregexp.h>
24#include <kmdcodec.h>
25
26#include "agent.h"
27#include "key.h"
28#include "picture.h"
29#include "secrecy.h"
30#include "sound.h"
31
32#include "vcardtool.h"
33
34using namespace KABC;
35
36VCardTool::VCardTool()
37{
38 mAddressTypeMap.insert( "dom", Address::Dom );
39 mAddressTypeMap.insert( "intl", Address::Intl );
40 mAddressTypeMap.insert( "postal", Address::Postal );
41 mAddressTypeMap.insert( "parcel", Address::Parcel );
42 mAddressTypeMap.insert( "home", Address::Home );
43 mAddressTypeMap.insert( "work", Address::Work );
44 mAddressTypeMap.insert( "pref", Address::Pref );
45
46 mPhoneTypeMap.insert( "HOME", PhoneNumber::Home );
47 mPhoneTypeMap.insert( "WORK", PhoneNumber::Work );
48 mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg );
49 mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref );
50 mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice );
51 mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax );
52 mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell );
53 mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video );
54 mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs );
55 mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem );
56 mPhoneTypeMap.insert( "CAR", PhoneNumber::Car );
57 mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn );
58 mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs );
59 mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager );
60}
61
62VCardTool::~VCardTool()
63{
64}
65
66QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
67{
68 VCard::List vCardList;
69
70 Addressee::List::Iterator addrIt;
71 for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) {
72 VCard card;
73 QStringList::ConstIterator strIt;
74
75 // ADR + LABEL
76 Address::List addresses = (*addrIt).addresses();
77 for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) {
78 QStringList address;
79
80/*US
81 address.append( (*it).postOfficeBox().replace( ';', "\\;" ) );
82 address.append( (*it).extended().replace( ';', "\\;" ) );
83 address.append( (*it).street().replace( ';', "\\;" ) );
84 address.append( (*it).locality().replace( ';', "\\;" ) );
85 address.append( (*it).region().replace( ';', "\\;" ) );
86 address.append( (*it).postalCode().replace( ';', "\\;" ) );
87 address.append( (*it).country().replace( ';', "\\;" ) );
88*/
89//US using the old implementation instead
90 //qDebug("VCardTool::createVCards has to be verified");
91 address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) );
92 address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) );
93 address.append( (*it).street().replace( QRegExp(";"), "\\;" ) );
94 address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) );
95 address.append( (*it).region().replace( QRegExp(";"), "\\;" ) );
96 address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) );
97 address.append( (*it).country().replace( QRegExp(";"), "\\;" ) );
98
99 VCardLine adrLine( "ADR", address.join( ";" ) );
100 VCardLine labelLine( "LABEL", (*it).label() );
101
102 bool hasLabel = !(*it).label().isEmpty();
103 QMap<QString, int>::Iterator typeIt;
104 for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) {
105 if ( typeIt.data() & (*it).type() ) {
106 adrLine.addParameter( "TYPE", typeIt.key() );
107 if ( hasLabel )
108 labelLine.addParameter( "TYPE", typeIt.key() );
109 }
110 }
111
112 card.addLine( adrLine );
113 if ( hasLabel )
114 card.addLine( labelLine );
115 }
116
117 // AGENT
118 card.addLine( createAgent( version, (*addrIt).agent() ) );
119
120 // BDAY
121 card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) );
122
123 // CATEGORIES
124 if ( version == VCard::v3_0 ) {
125 QStringList categories = (*addrIt).categories();
126 QStringList::Iterator catIt;
127 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt )
128 {
129//US using the old implementation instead
130 // qDebug("VCardTool::createVCards has to be verified");
131//US (*catIt).replace( ',', "\\," );
132 (*catIt).replace( QRegExp(","), "\\," );
133 }
134 card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) );
135 }
136
137 // CLASS
138 if ( version == VCard::v3_0 ) {
139 card.addLine( createSecrecy( (*addrIt).secrecy() ) );
140 }
141
142 // EMAIL
143 QStringList emails = (*addrIt).emails();
144 bool pref = true;
145 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) {
146 VCardLine line( "EMAIL", *strIt );
147 if ( pref == true ) {
148 line.addParameter( "TYPE", "PREF" );
149 pref = false;
150 }
151 card.addLine( line );
152 }
153
154 // FN
155 card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) );
156
157 // GEO
158 Geo geo = (*addrIt).geo();
159 if ( geo.isValid() ) {
160 QString str;
161 str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() );
162 card.addLine( VCardLine( "GEO", str ) );
163 }
164
165 // KEY
166 Key::List keys = (*addrIt).keys();
167 Key::List::ConstIterator keyIt;
168 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt )
169 card.addLine( createKey( *keyIt ) );
170
171 // LOGO
172 card.addLine( createPicture( "LOGO", (*addrIt).logo() ) );
173
174 // MAILER
175 card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) );
176
177 // N
178 QStringList name;
179//US using the old implementation instead
180 //qDebug("VCardTool::createVCards has to be verified");
181/*US
182 name.append( (*addrIt).familyName().replace( ';', "\\;" ) );
183 name.append( (*addrIt).givenName().replace( ';', "\\;" ) );
184 name.append( (*addrIt).additionalName().replace( ';', "\\;" ) );
185 name.append( (*addrIt).prefix().replace( ';', "\\;" ) );
186 name.append( (*addrIt).suffix().replace( ';', "\\;" ) );
187*/
188 name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) );
189 name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) );
190 name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) );
191 name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) );
192 name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) );
193
194 if ( !name.join( "" ).isEmpty() )
195 card.addLine( VCardLine( "N", name.join( ";" ) ) );
196
197 // NICKNAME
198 if ( version == VCard::v3_0 )
199 card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) );
200
201 // NOTE
202 card.addLine( VCardLine( "NOTE", (*addrIt).note() ) );
203
204 // ORG
205 card.addLine( VCardLine( "ORG", (*addrIt).organization() ) );
206
207 // PHOTO
208 card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) );
209
210 // PROID
211 if ( version == VCard::v3_0 )
212 card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) );
213
214 // REV
215 card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) );
216
217 // ROLE
218 card.addLine( VCardLine( "ROLE", (*addrIt).role() ) );
219
220 // SORT-STRING
221 if ( version == VCard::v3_0 )
222 card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) );
223
224 // SOUND
225 card.addLine( createSound( (*addrIt).sound() ) );
226
227 // TEL
228 PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
229 PhoneNumber::List::ConstIterator phoneIt;
230 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
231 VCardLine line( "TEL", (*phoneIt).number() );
232
233 QMap<QString, int>::Iterator typeIt;
234 for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) {
235 if ( typeIt.data() & (*phoneIt).type() )
236 line.addParameter( "TYPE", typeIt.key() );
237 }
238
239 card.addLine( line );
240 }
241
242 // TITLE
243 card.addLine( VCardLine( "TITLE", (*addrIt).title() ) );
244
245 // TZ
246 TimeZone timeZone = (*addrIt).timeZone();
247 if ( timeZone.isValid() ) {
248 QString str;
249
250 int neg = 1;
251 if ( timeZone.offset() < 0 )
252 neg = -1;
253
254 str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ),
255 ( timeZone.offset() / 60 ) * neg,
256 ( timeZone.offset() % 60 ) * neg );
257
258 card.addLine( VCardLine( "TZ", str ) );
259 }
260
261 // UID
262 card.addLine( VCardLine( "UID", (*addrIt).uid() ) );
263
264 // URL
265 card.addLine( VCardLine( "URL", (*addrIt).url().url() ) );
266
267 // VERSION
268 if ( version == VCard::v2_1 )
269 card.addLine( VCardLine( "VERSION", "2.1" ) );
270 if ( version == VCard::v3_0 )
271 card.addLine( VCardLine( "VERSION", "3.0" ) );
272
273 // X-
274 QStringList customs = (*addrIt).customs();
275 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
276 QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) );
277 QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 );
278 if ( value.isEmpty() )
279 continue;
280
281 card.addLine( VCardLine( identifier, value ) );
282 }
283
284 vCardList.append( card );
285 }
286
287 return VCardParser::createVCards( vCardList );
288}
289
290Addressee::List VCardTool::parseVCards( const QString& vcard )
291{
292 QChar semicolonSep( ';' );
293 QChar commaSep( ',' );
294 QString identifier;
295
296 Addressee::List addrList;
297 VCard::List vCardList = VCardParser::parseVCards( vcard );
298 VCard::List::Iterator cardIt;
299 for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) {
300 Addressee addr;
301 QStringList idents = (*cardIt).identifiers();
302 QStringList::ConstIterator identIt;
303 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
304 VCard card = (*cardIt);
305 VCardLine::List lines = card.lines( (*identIt) );
306 VCardLine::List::Iterator lineIt;
307
308 // iterate over the lines
309 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
310 QStringList params = (*lineIt).parameterList();
311
312 identifier = (*lineIt).identifier().lower();
313 // ADR
314 if ( identifier == "adr" ) {
315 Address address;
316 QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
317 if ( addrParts.count() > 0 )
318 address.setPostOfficeBox( addrParts[ 0 ] );
319 if ( addrParts.count() > 1 )
320 address.setExtended( addrParts[ 1 ] );
321 if ( addrParts.count() > 2 )
322 address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") );
323 if ( addrParts.count() > 3 )
324 address.setLocality( addrParts[ 3 ] );
325 if ( addrParts.count() > 4 )
326 address.setRegion( addrParts[ 4 ] );
327 if ( addrParts.count() > 5 )
328 address.setPostalCode( addrParts[ 5 ] );
329 if ( addrParts.count() > 6 )
330 address.setCountry( addrParts[ 6 ] );
331
332 int type = 0;
333
334 QStringList types = (*lineIt).parameters( "type" );
335 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
336 type += mAddressTypeMap[ (*it).lower() ];
337
338 if ( !type )
339 type = Address::Home; // default
340
341 address.setType( type );
342 addr.insertAddress( address );
343 }
344
345 // AGENT
346 if ( identifier == "agent" )
347 addr.setAgent( parseAgent( *lineIt ) );
348
349 // BDAY
350 if ( identifier == "bday" )
351 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) );
352
353 // CATEGORIES
354 if ( identifier == "categories" ) {
355 QStringList categories = splitString( commaSep, (*lineIt).value().asString() );
356 addr.setCategories( categories );
357 }
358
359 // CLASS
360 if ( identifier == "class" )
361 addr.setSecrecy( parseSecrecy( *lineIt ) );
362
363 // EMAIL
364 if ( identifier == "email" ) {
365 QStringList types = (*lineIt).parameters( "type" );
366 addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) );
367 }
368
369 // FN
370 if ( identifier == "fn" )
371 addr.setFormattedName( (*lineIt).value().asString() );
372
373 // GEO
374 if ( identifier == "geo" ) {
375 Geo geo;
376
377 QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true );
378 geo.setLatitude( geoParts[ 0 ].toFloat() );
379 geo.setLongitude( geoParts[ 1 ].toFloat() );
380
381 addr.setGeo( geo );
382 }
383
384 // KEY
385 if ( identifier == "key" )
386 addr.insertKey( parseKey( *lineIt ) );
387
388 // LABEL
389 if ( identifier == "label" ) {
390 int type = 0;
391
392 QStringList types = (*lineIt).parameters( "type" );
393 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
394 type += mAddressTypeMap[ (*it).lower() ];
395
396 if ( !type )
397 type = Address::Home;
398
399 KABC::Address::List addressList = addr.addresses();
400 KABC::Address::List::Iterator it;
401 for ( it = addressList.begin(); it != addressList.end(); ++it ) {
402 if ( (*it).type() == type ) {
403 (*it).setLabel( (*lineIt).value().asString() );
404 addr.insertAddress( *it );
405 }
406 }
407 }
408
409 // LOGO
410 if ( identifier == "logo" )
411 addr.setLogo( parsePicture( *lineIt ) );
412
413 // MAILER
414 if ( identifier == "mailer" )
415 addr.setMailer( (*lineIt).value().asString() );
416
417 // N
418 if ( identifier == "n" ) {
419 QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() );
420 if ( nameParts.count() > 0 )
421 addr.setFamilyName( nameParts[ 0 ] );
422 if ( nameParts.count() > 1 )
423 addr.setGivenName( nameParts[ 1 ] );
424 if ( nameParts.count() > 2 )
425 addr.setAdditionalName( nameParts[ 2 ] );
426 if ( nameParts.count() > 3 )
427 addr.setPrefix( nameParts[ 3 ] );
428 if ( nameParts.count() > 4 )
429 addr.setSuffix( nameParts[ 4 ] );
430 }
431
432 // NICKNAME
433 if ( identifier == "nickname" )
434 addr.setNickName( (*lineIt).value().asString() );
435
436 // NOTE
437 if ( identifier == "note" ) {
438// #ifdef DESKTOP_VERSION
439// addr.setNote( (*lineIt).value().asString() );
440// #else
441 QString note = (*lineIt).value().asString();
442 if ( ! note.isEmpty() )
443 addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") );
444 else
445 addr.setNote( note );
446 //#endif
447 }
448
449 // ORGANIZATION
450 if ( identifier == "org" )
451 addr.setOrganization( (*lineIt).value().asString() );
452
453 // PHOTO
454 if ( identifier == "photo" )
455 addr.setPhoto( parsePicture( *lineIt ) );
456
457 // PROID
458 if ( identifier == "prodid" )
459 addr.setProductId( (*lineIt).value().asString() );
460
461 // REV
462 if ( identifier == "rev" )
463 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
464
465 // ROLE
466 if ( identifier == "role" )
467 addr.setRole( (*lineIt).value().asString() );
468
469 // SORT-STRING
470 if ( identifier == "sort-string" )
471 addr.setSortString( (*lineIt).value().asString() );
472
473 // SOUND
474 if ( identifier == "sound" )
475 addr.setSound( parseSound( *lineIt ) );
476
477 // TEL
478 if ( identifier == "tel" ) {
479 PhoneNumber phone;
480 phone.setNumber( (*lineIt).value().asString() );
481
482 int type = 0;
483
484 QStringList types = (*lineIt).parameters( "type" );
485 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
486 type += mPhoneTypeMap[(*it).upper()];
487
488 if ( !type )
489 type = PhoneNumber::Home; // default
490
491 phone.setType( type );
492
493 addr.insertPhoneNumber( phone );
494 }
495
496 // TITLE
497 if ( identifier == "title" )
498 addr.setTitle( (*lineIt).value().asString() );
499
500 // TZ
501 if ( identifier == "tz" ) {
502 TimeZone tz;
503 QString date = (*lineIt).value().asString();
504
505 int hours = date.mid( 1, 2).toInt();
506 int minutes = date.mid( 4, 2 ).toInt();
507 int offset = ( hours * 60 ) + minutes;
508 offset = offset * ( date[ 0 ] == '+' ? 1 : -1 );
509
510 tz.setOffset( offset );
511 addr.setTimeZone( tz );
512 }
513
514 // UID
515 if ( identifier == "uid" )
516 addr.setUid( (*lineIt).value().asString() );
517
518 // URL
519 if ( identifier == "url" )
520 addr.setUrl( (*lineIt).value().asString() );
521
522 // X-
523 if ( identifier.startsWith( "x-" ) ) {
524 QString key = (*lineIt).identifier().mid( 2 );
525 int dash = key.find( "-" );
526 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
527 }
528 }
529 }
530
531 addrList.append( addr );
532 }
533
534 return addrList;
535}
536
537QDateTime VCardTool::parseDateTime( const QString &str )
538{
539 QDateTime dateTime;
540
541 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd)
542 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
543 str.mid( 6, 2 ).toInt() ) );
544
545 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss
546 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
547 str.mid( 17, 2 ).toInt() ) );
548
549 } else { // is extended format yyyy-mm-dd
550 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
551 str.mid( 8, 2 ).toInt() ) );
552
553 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss
554 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
555 str.mid( 17, 2 ).toInt() ) );
556 }
557
558 return dateTime;
559}
560
561QString VCardTool::createDateTime( const QDateTime &dateTime )
562{
563 QString str;
564
565 if ( dateTime.date().isValid() ) {
566 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
567 dateTime.date().day() );
568 if ( dateTime.time().isValid() ) {
569 QString tmp;
570 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
571 dateTime.time().second() );
572 str += tmp;
573 }
574 }
575
576 return str;
577}
578
579Picture VCardTool::parsePicture( const VCardLine &line )
580{
581 Picture pic;
582
583 QStringList params = line.parameterList();
584 if ( params.contains( "encoding" ) ) {
585 QCString cs(line.value().asCString());
586 QByteArray input, output;
587 input = line.value().asCString();
588 if ( line.parameter( "encoding" ).lower() == "b" )
589 KCodecs::base64Decode( input, output );
590 else if ( line.parameter( "encoding" ).lower() == "quoted-printable" )
591 KCodecs::quotedPrintableDecode( input, output );
592
593 qDebug("********** DECODING OKAY ************** (picture)");
594 pic.setData( QImage(output) );
595
596 }
597 else if ( params.contains( "value" ) ) {
598 if ( line.parameter( "value" ).lower() == "uri" )
599 pic.setUrl( line.value().asString() );
600 }
601
602 if ( params.contains( "type" ) )
603 pic.setType( line.parameter( "type" ) );
604
605 return pic;
606}
607
608VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
609{
610 // LR fixed
611 VCardLine line( identifier );
612
613 if ( pic.isIntern() ) {
614 if ( !pic.data().isNull() ) {
615#if 0
616 QByteArray input;
617 QDataStream s( input, IO_WriteOnly );
618 s.setVersion( 4 );
619 s << pic.data();
620 line.setValue( input );
621#else
622 QCString input;
623 QDataStream s( input, IO_WriteOnly );
624 s.setVersion( 4 );
625 s << pic.data();
626 //QCString cs(line.value().asCString());
627 //QImage qi(cs);
628 line.setValue( input );
629#endif
630
631 line.addParameter( "encoding", "b" );
632 line.addParameter( "type", "image/png" );
633 }
634 } else if ( !pic.url().isEmpty() ) {
635 line.setValue( pic.url() );
636 line.addParameter( "value", "URI" );
637 }
638
639 return line;
640}
641
642Sound VCardTool::parseSound( const VCardLine &line )
643{
644 Sound snd;
645
646 QStringList params = line.parameterList();
647 if ( params.contains( "encoding" ) ) {
648 qDebug("VCardTool::parseSound has to be verified");
649//US snd.setData( line.value().asByteArray() );
650//US I am not sure if this is correct
651 QCString cs(line.value().asCString());
652 snd.setData( cs );
653 }
654 else if ( params.contains( "value" ) ) {
655 if ( line.parameter( "value" ).lower() == "uri" )
656 snd.setUrl( line.value().asString() );
657 }
658
659/* TODO: support sound types
660 if ( params.contains( "type" ) )
661 snd.setType( line.parameter( "type" ) );
662*/
663
664 return snd;
665}
666
667VCardLine VCardTool::createSound( const Sound &snd )
668{
669 VCardLine line( "SOUND" );
670
671 if ( snd.isIntern() ) {
672 if ( !snd.data().isEmpty() ) {
673 qDebug("VCardTool::createSound has to be verified");
674//US line.setValue( snd.data() );
675
676//US I am not sure if this is correct
677 QCString cs(snd.data());
678 line.setValue( cs );
679
680
681 line.addParameter( "encoding", "b" );
682 // TODO: need to store sound type!!!
683 }
684 } else if ( !snd.url().isEmpty() ) {
685 line.setValue( snd.url() );
686 line.addParameter( "value", "URI" );
687 }
688
689 return line;
690}
691
692Key VCardTool::parseKey( const VCardLine &line )
693{
694 Key key;
695
696 QStringList params = line.parameterList();
697 if ( params.contains( "encoding" ) ) {
698 qDebug("VCardTool::parseKey has to be verified");
699//US key.setBinaryData( line.value().asByteArray() );
700
701//US I am not sure if this is correct
702 QCString cs( line.value().asCString() );
703 key.setBinaryData( cs );
704 }
705 else
706 key.setTextData( line.value().asString() );
707
708 if ( params.contains( "type" ) ) {
709 if ( line.parameter( "type" ).lower() == "x509" )
710 key.setType( Key::X509 );
711 else if ( line.parameter( "type" ).lower() == "pgp" )
712 key.setType( Key::PGP );
713 else {
714 key.setType( Key::Custom );
715 key.setCustomTypeString( line.parameter( "type" ) );
716 }
717 }
718
719 return key;
720}
721
722VCardLine VCardTool::createKey( const Key &key )
723{
724 VCardLine line( "KEY" );
725
726 if ( key.isBinary() ) {
727 if ( !key.binaryData().isEmpty() ) {
728 qDebug("VCardTool::createKey has to be verified");
729//US line.setValue( key.binaryData() );
730//US I am not sure if this is correct
731 QCString cs(key.binaryData());
732 line.setValue( cs );
733
734
735 line.addParameter( "encoding", "b" );
736 }
737 } else if ( !key.textData().isEmpty() )
738 line.setValue( key.textData() );
739
740 if ( key.type() == Key::X509 )
741 line.addParameter( "type", "X509" );
742 else if ( key.type() == Key::PGP )
743 line.addParameter( "type", "PGP" );
744 else if ( key.type() == Key::Custom )
745 line.addParameter( "type", key.customTypeString() );
746
747 return line;
748}
749
750Secrecy VCardTool::parseSecrecy( const VCardLine &line )
751{
752 Secrecy secrecy;
753
754 if ( line.value().asString().lower() == "public" )
755 secrecy.setType( Secrecy::Public );
756 if ( line.value().asString().lower() == "private" )
757 secrecy.setType( Secrecy::Private );
758 if ( line.value().asString().lower() == "confidential" )
759 secrecy.setType( Secrecy::Confidential );
760
761 return secrecy;
762}
763
764VCardLine VCardTool::createSecrecy( const Secrecy &secrecy )
765{
766 VCardLine line( "CLASS" );
767
768 int type = secrecy.type();
769
770 if ( type == Secrecy::Public )
771 line.setValue( "PUBLIC" );
772 else if ( type == Secrecy::Private )
773 line.setValue( "PRIVATE" );
774 else if ( type == Secrecy::Confidential )
775 line.setValue( "CONFIDENTIAL" );
776
777 return line;
778}
779
780Agent VCardTool::parseAgent( const VCardLine &line )
781{
782 Agent agent;
783
784 QStringList params = line.parameterList();
785 if ( params.contains( "value" ) ) {
786 if ( line.parameter( "value" ).lower() == "uri" )
787 agent.setUrl( line.value().asString() );
788 } else {
789 QString str = line.value().asString();
790
791//US using the old implementation instead
792 qDebug("VCardTool::parseAgent has to be verified");
793/*US
794 str.replace( "\\n", "\r\n" );
795 str.replace( "\\N", "\r\n" );
796 str.replace( "\\;", ";" );
797 str.replace( "\\:", ":" );
798 str.replace( "\\,", "," );
799*/
800 str.replace( QRegExp("\\n") , "\r\n" );
801 str.replace( QRegExp("\\N") , "\r\n" );
802 str.replace( QRegExp("\\;") , ";" );
803 str.replace( QRegExp("\\:") , ":" );
804 str.replace( QRegExp("\\,") , "," );
805
806 Addressee::List list = parseVCards( str );
807 if ( list.count() > 0 ) {
808 Addressee *addr = new Addressee;
809 *addr = list[ 0 ];
810 agent.setAddressee( addr );
811 }
812 }
813
814 return agent;
815}
816
817VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent )
818{
819 VCardLine line( "AGENT" );
820
821 if ( agent.isIntern() ) {
822 if ( agent.addressee() != 0 ) {
823 Addressee::List list;
824 list.append( *agent.addressee() );
825
826 QString str = createVCards( list, version );
827
828//US using the old implementation instead
829 qDebug("VCardTool::createAgent has to be verified");
830/*US
831 str.replace( "\r\n", "\\n" );
832 str.replace( ";", "\\;" );
833 str.replace( ":", "\\:" );
834 str.replace( ",", "\\," );
835*/
836 str.replace( QRegExp("\r\n"), "\\n" );
837 str.replace( QRegExp(";"), "\\;" );
838 str.replace( QRegExp(":"), "\\:" );
839 str.replace( QRegExp(","), "\\," );
840 line.setValue( str );
841 }
842 } else if ( !agent.url().isEmpty() ) {
843 line.setValue( agent.url() );
844 line.addParameter( "value", "URI" );
845 }
846
847 return line;
848}
849
850QStringList VCardTool::splitString( const QChar &sep, const QString &str )
851{
852 QStringList list;
853 QString value( str );
854
855 int start = 0;
856 int pos = value.find( sep, start );
857
858 while ( pos != -1 ) {
859 if ( value[ pos - 1 ] != '\\' ) {
860 if ( pos > start && pos <= (int)value.length() )
861 list << value.mid( start, pos - start );
862 else
863 list << QString::null;
864
865 start = pos + 1;
866 pos = value.find( sep, start );
867 } else {
868 if ( pos != 0 ) {
869 value.replace( pos - 1, 2, sep );
870 pos = value.find( sep, pos );
871 } else
872 pos = value.find( sep, pos + 1 );
873 }
874 }
875
876 int l = value.length() - 1;
877 if ( value.mid( start, l - start + 1 ).length() > 0 )
878 list << value.mid( start, l - start + 1 );
879 else
880 list << QString::null;
881
882 return list;
883}
diff --git a/kabc/vcardparser/vcardtool.h b/kabc/vcardparser/vcardtool.h
new file mode 100644
index 0000000..40a3b82
--- a/dev/null
+++ b/kabc/vcardparser/vcardtool.h
@@ -0,0 +1,88 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef KABC_VCARDTOOL_H
22#define KABC_VCARDTOOL_H
23
24#include "addressee.h"
25#include "vcardparser.h"
26
27class QDateTime;
28
29namespace KABC {
30
31class Agent;
32class Key;
33class Picture;
34class Secrecy;
35class Sound;
36
37class VCardTool
38{
39 public:
40 VCardTool();
41 ~VCardTool();
42
43 /**
44 Creates a string that contains the addressees from the list in
45 the vCard format.
46 */
47 QString createVCards( Addressee::List list, VCard::Version version = VCard::v3_0 );
48
49 /**
50 Parses the string and returns a list of addressee objects.
51 */
52 Addressee::List parseVCards( const QString& vcard );
53
54 private:
55 /**
56 Split a string and replaces escaped separators on the fly with
57 unescaped ones.
58 */
59 QStringList splitString( const QChar &sep, const QString &value );
60
61 QDateTime parseDateTime( const QString &str );
62 QString createDateTime( const QDateTime &dateTime );
63
64 Picture parsePicture( const VCardLine &line );
65 VCardLine createPicture( const QString &identifier, const Picture &pic );
66
67 Sound parseSound( const VCardLine &line );
68 VCardLine createSound( const Sound &snd );
69
70 Key parseKey( const VCardLine &line );
71 VCardLine createKey( const Key &key );
72
73 Secrecy parseSecrecy( const VCardLine &line );
74 VCardLine createSecrecy( const Secrecy &secrecy );
75
76 Agent parseAgent( const VCardLine &line );
77 VCardLine createAgent( VCard::Version version, const Agent &agent );
78
79 QMap<QString, int> mAddressTypeMap;
80 QMap<QString, int> mPhoneTypeMap;
81
82 class VCardToolPrivate;
83 VCardToolPrivate *d;
84};
85
86}
87
88#endif