summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-09-29 02:41:02 (UTC)
committer ulf69 <ulf69>2004-09-29 02:41:02 (UTC)
commitf7810320ed36a03c96d00436f6b589b9b5ca8c30 (patch) (unidiff)
tree2d47b246b4fef9e7001573405018543e15849b5f
parentcd2cb3a9e2ea93909efc9efa16ddd80c2d2b5408 (diff)
downloadkdepimpi-f7810320ed36a03c96d00436f6b589b9b5ca8c30.zip
kdepimpi-f7810320ed36a03c96d00436f6b589b9b5ca8c30.tar.gz
kdepimpi-f7810320ed36a03c96d00436f6b589b9b5ca8c30.tar.bz2
set env variable KABC_DEBUG to display processewd addresses while loading
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardformatimpl.cpp11
-rw-r--r--kabc/vcardformatimpl.h5
2 files changed, 16 insertions, 0 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
index 1bf2cde..ede5773 100644
--- a/kabc/vcardformatimpl.cpp
+++ b/kabc/vcardformatimpl.cpp
@@ -1,178 +1,189 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 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, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <qfile.h> 28#include <qfile.h>
29#include <qregexp.h> 29#include <qregexp.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kmdcodec.h> 32#include <kmdcodec.h>
33#include <kstandarddirs.h> 33#include <kstandarddirs.h>
34#include <ktempfile.h> 34#include <ktempfile.h>
35 35
36#include <VCard.h> 36#include <VCard.h>
37 37
38#include "addressbook.h" 38#include "addressbook.h"
39#include "vcardformatimpl.h" 39#include "vcardformatimpl.h"
40 40
41using namespace KABC; 41using namespace KABC;
42using namespace VCARD; 42using namespace VCARD;
43 43
44int VCardFormatImpl::debug = -1;
45
46VCardFormatImpl::VCardFormatImpl()
47{
48 debug = (getenv("KABC_DEBUG") != 0);
49}
50
44bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) 51bool VCardFormatImpl::load( Addressee &addressee, QFile *file )
45{ 52{
46 kdDebug(5700) << "VCardFormat::load()" << endl; 53 kdDebug(5700) << "VCardFormat::load()" << endl;
47 54
48 QByteArray fdata = file->readAll(); 55 QByteArray fdata = file->readAll();
49 QCString data(fdata.data(), fdata.size()+1); 56 QCString data(fdata.data(), fdata.size()+1);
50 57
51 VCardEntity e( data ); 58 VCardEntity e( data );
52 59
53 VCardListIterator it( e.cardList() ); 60 VCardListIterator it( e.cardList() );
54 61
55 if ( it.current() ) { 62 if ( it.current() ) {
56//US VCard v(*it.current()); 63//US VCard v(*it.current());
57//US loadAddressee( addressee, v ); 64//US loadAddressee( addressee, v );
58 loadAddressee( addressee, it.current() ); 65 loadAddressee( addressee, it.current() );
59 return true; 66 return true;
60 } 67 }
61 68
62 return false; 69 return false;
63} 70}
64 71
65bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) 72bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
66{ 73{
67 kdDebug(5700) << "VCardFormat::loadAll()" << endl; 74 kdDebug(5700) << "VCardFormat::loadAll()" << endl;
68 75
69 QByteArray fdata = file->readAll(); 76 QByteArray fdata = file->readAll();
70 QCString data(fdata.data(), fdata.size()+1); 77 QCString data(fdata.data(), fdata.size()+1);
71 78
72 VCardEntity e( data ); 79 VCardEntity e( data );
73 80
74 VCardListIterator it( e.cardList() ); 81 VCardListIterator it( e.cardList() );
75 82
76 for (; it.current(); ++it) { 83 for (; it.current(); ++it) {
77//US VCard v(*it.current()); 84//US VCard v(*it.current());
78 Addressee addressee; 85 Addressee addressee;
79//US loadAddressee( addressee, v ); 86//US loadAddressee( addressee, v );
80 loadAddressee( addressee, it.current() ); 87 loadAddressee( addressee, it.current() );
81 addressee.setResource( resource ); 88 addressee.setResource( resource );
82 addressBook->insertAddressee( addressee ); 89 addressBook->insertAddressee( addressee );
90 if (debug == true)
91 {
92 printf("address %s loaded successfully\n", addressee.formattedName().latin1());
93 }
83 } 94 }
84 95
85 return true; 96 return true;
86} 97}
87 98
88void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) 99void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
89{ 100{
90 VCardEntity vcards; 101 VCardEntity vcards;
91 VCardList vcardlist; 102 VCardList vcardlist;
92 vcardlist.setAutoDelete( true ); 103 vcardlist.setAutoDelete( true );
93 104
94 VCard *v = new VCard; 105 VCard *v = new VCard;
95 106
96 saveAddressee( addressee, v, false ); 107 saveAddressee( addressee, v, false );
97 108
98 vcardlist.append( v ); 109 vcardlist.append( v );
99 vcards.setCardList( vcardlist ); 110 vcards.setCardList( vcardlist );
100 111
101 QCString vcardData = vcards.asString(); 112 QCString vcardData = vcards.asString();
102 file->writeBlock( (const char*)vcardData, vcardData.length() ); 113 file->writeBlock( (const char*)vcardData, vcardData.length() );
103} 114}
104 115
105void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) 116void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file )
106{ 117{
107 VCardEntity vcards; 118 VCardEntity vcards;
108 VCardList vcardlist; 119 VCardList vcardlist;
109 vcardlist.setAutoDelete( true ); 120 vcardlist.setAutoDelete( true );
110 121
111 AddressBook::Iterator it; 122 AddressBook::Iterator it;
112 for ( it = ab->begin(); it != ab->end(); ++it ) { 123 for ( it = ab->begin(); it != ab->end(); ++it ) {
113 if ( (*it).resource() == resource ) { 124 if ( (*it).resource() == resource ) {
114 VCard *v = new VCard; 125 VCard *v = new VCard;
115 saveAddressee( (*it), v, false ); 126 saveAddressee( (*it), v, false );
116 (*it).setChanged( false ); 127 (*it).setChanged( false );
117 vcardlist.append( v ); 128 vcardlist.append( v );
118 } 129 }
119 } 130 }
120 131
121 vcards.setCardList( vcardlist ); 132 vcards.setCardList( vcardlist );
122 133
123 QCString vcardData = vcards.asString(); 134 QCString vcardData = vcards.asString();
124 file->writeBlock( (const char*)vcardData, vcardData.length() ); 135 file->writeBlock( (const char*)vcardData, vcardData.length() );
125} 136}
126 137
127bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) 138bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
128{ 139{
129 QPtrList<ContentLine> contentLines = v->contentLineList(); 140 QPtrList<ContentLine> contentLines = v->contentLineList();
130 ContentLine *cl; 141 ContentLine *cl;
131 142
132 for( cl = contentLines.first(); cl; cl = contentLines.next() ) { 143 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
133 QCString n = cl->name(); 144 QCString n = cl->name();
134 if ( n.left( 2 ) == "X-" ) { 145 if ( n.left( 2 ) == "X-" ) {
135 n = n.mid( 2 ); 146 n = n.mid( 2 );
136 int posDash = n.find( "-" ); 147 int posDash = n.find( "-" );
137 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), 148 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ),
138 QString::fromUtf8( n.mid( posDash + 1 ) ), 149 QString::fromUtf8( n.mid( posDash + 1 ) ),
139 QString::fromUtf8( cl->value()->asString() ) ); 150 QString::fromUtf8( cl->value()->asString() ) );
140 continue; 151 continue;
141 } 152 }
142 153
143 EntityType type = cl->entityType(); 154 EntityType type = cl->entityType();
144 switch( type ) { 155 switch( type ) {
145 156
146 case EntityUID: 157 case EntityUID:
147 addressee.setUid( readTextValue( cl ) ); 158 addressee.setUid( readTextValue( cl ) );
148 break; 159 break;
149 160
150 case EntityEmail: 161 case EntityEmail:
151 addressee.insertEmail( readTextValue( cl ) ); 162 addressee.insertEmail( readTextValue( cl ) );
152 break; 163 break;
153 164
154 case EntityName: 165 case EntityName:
155 addressee.setName( readTextValue( cl ) ); 166 addressee.setName( readTextValue( cl ) );
156 break; 167 break;
157 168
158 case EntityFullName: 169 case EntityFullName:
159 addressee.setFormattedName( readTextValue( cl ) ); 170 addressee.setFormattedName( readTextValue( cl ) );
160 break; 171 break;
161 172
162 case EntityURL: 173 case EntityURL:
163 addressee.setUrl( KURL( readTextValue( cl ) ) ); 174 addressee.setUrl( KURL( readTextValue( cl ) ) );
164 break; 175 break;
165 176
166 case EntityNickname: 177 case EntityNickname:
167 addressee.setNickName( readTextValue( cl ) ); 178 addressee.setNickName( readTextValue( cl ) );
168 break; 179 break;
169 180
170 case EntityLabel: 181 case EntityLabel:
171 // not yet supported by kabc 182 // not yet supported by kabc
172 break; 183 break;
173 184
174 case EntityMailer: 185 case EntityMailer:
175 addressee.setMailer( readTextValue( cl ) ); 186 addressee.setMailer( readTextValue( cl ) );
176 break; 187 break;
177 188
178 case EntityTitle: 189 case EntityTitle:
diff --git a/kabc/vcardformatimpl.h b/kabc/vcardformatimpl.h
index fa3d55f..4821047 100644
--- a/kabc/vcardformatimpl.h
+++ b/kabc/vcardformatimpl.h
@@ -1,112 +1,117 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 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, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_VCARDFORMATIMPL_H 28#ifndef KABC_VCARDFORMATIMPL_H
29#define KABC_VCARDFORMATIMPL_H 29#define KABC_VCARDFORMATIMPL_H
30 30
31#include <qstring.h> 31#include <qstring.h>
32#include <qfile.h> 32#include <qfile.h>
33 33
34#include "address.h" 34#include "address.h"
35#include "addressee.h" 35#include "addressee.h"
36 36
37#include <VCard.h> 37#include <VCard.h>
38 38
39namespace KABC { 39namespace KABC {
40 40
41class AddressBook; 41class AddressBook;
42 42
43/** 43/**
44 @short Implementation of vCard backend for address book. 44 @short Implementation of vCard backend for address book.
45 45
46 This class implements reading and writing of address book information using 46 This class implements reading and writing of address book information using
47 the vCard format. It requires the vCard lib from kdepim. 47 the vCard format. It requires the vCard lib from kdepim.
48*/ 48*/
49class VCardFormatImpl 49class VCardFormatImpl
50{ 50{
51 public: 51 public:
52 VCardFormatImpl();
53
52 bool load( Addressee &, QFile *file ); 54 bool load( Addressee &, QFile *file );
53 bool loadAll( AddressBook *, Resource *, QFile *file ); 55 bool loadAll( AddressBook *, Resource *, QFile *file );
54 void save( const Addressee &, QFile *file ); 56 void save( const Addressee &, QFile *file );
55 void saveAll( AddressBook *, Resource *, QFile *file ); 57 void saveAll( AddressBook *, Resource *, QFile *file );
56 58
57 bool readFromString( const QString &vcard, Addressee &addr ); 59 bool readFromString( const QString &vcard, Addressee &addr );
58 bool writeToString( const Addressee &addressee, QString &vcard ); 60 bool writeToString( const Addressee &addressee, QString &vcard );
59 61
60 protected: 62 protected:
61 bool loadAddressee( Addressee &, VCARD::VCard * ); 63 bool loadAddressee( Addressee &, VCARD::VCard * );
62 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern ); 64 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern );
63 65
64 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & ); 66 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & );
65 QString readTextValue( VCARD::ContentLine * ); 67 QString readTextValue( VCARD::ContentLine * );
66 68
67 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & ); 69 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & );
68 QDate readDateValue( VCARD::ContentLine * ); 70 QDate readDateValue( VCARD::ContentLine * );
69 71
70 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & ); 72 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & );
71 QDateTime readDateTimeValue( VCARD::ContentLine * ); 73 QDateTime readDateTimeValue( VCARD::ContentLine * );
72 74
73 void addAddressValue( VCARD::VCard *, const Address & ); 75 void addAddressValue( VCARD::VCard *, const Address & );
74 Address readAddressValue( VCARD::ContentLine * ); 76 Address readAddressValue( VCARD::ContentLine * );
75 77
76 void addLabelValue( VCARD::VCard *, const Address & ); 78 void addLabelValue( VCARD::VCard *, const Address & );
77 79
78 void addTelephoneValue( VCARD::VCard *, const PhoneNumber & ); 80 void addTelephoneValue( VCARD::VCard *, const PhoneNumber & );
79 PhoneNumber readTelephoneValue( VCARD::ContentLine * ); 81 PhoneNumber readTelephoneValue( VCARD::ContentLine * );
80 82
81 void addNValue( VCARD::VCard *, const Addressee & ); 83 void addNValue( VCARD::VCard *, const Addressee & );
82 void readNValue( VCARD::ContentLine *, Addressee & ); 84 void readNValue( VCARD::ContentLine *, Addressee & );
83 85
84 void addCustomValue( VCARD::VCard *, const QString & ); 86 void addCustomValue( VCARD::VCard *, const QString & );
85 87
86 void addAddressParam( VCARD::ContentLine *, int ); 88 void addAddressParam( VCARD::ContentLine *, int );
87 int readAddressParam( VCARD::ContentLine * ); 89 int readAddressParam( VCARD::ContentLine * );
88 90
89 void addGeoValue( VCARD::VCard *, const Geo & ); 91 void addGeoValue( VCARD::VCard *, const Geo & );
90 Geo readGeoValue( VCARD::ContentLine * ); 92 Geo readGeoValue( VCARD::ContentLine * );
91 93
92 void addUTCValue( VCARD::VCard *, const TimeZone & ); 94 void addUTCValue( VCARD::VCard *, const TimeZone & );
93 TimeZone readUTCValue( VCARD::ContentLine * ); 95 TimeZone readUTCValue( VCARD::ContentLine * );
94 96
95 void addClassValue( VCARD::VCard *, const Secrecy & ); 97 void addClassValue( VCARD::VCard *, const Secrecy & );
96 Secrecy readClassValue( VCARD::ContentLine * ); 98 Secrecy readClassValue( VCARD::ContentLine * );
97 99
98 void addKeyValue( VCARD::VCard *, const Key & ); 100 void addKeyValue( VCARD::VCard *, const Key & );
99 Key readKeyValue( VCARD::ContentLine * ); 101 Key readKeyValue( VCARD::ContentLine * );
100 102
101 void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool ); 103 void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool );
102 Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr ); 104 Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr );
103 105
104 void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool ); 106 void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool );
105 Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr ); 107 Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr );
106 108
107 void addAgentValue( VCARD::VCard *, const Agent & ); 109 void addAgentValue( VCARD::VCard *, const Agent & );
108 Agent readAgentValue( VCARD::ContentLine * ); 110 Agent readAgentValue( VCARD::ContentLine * );
111
112 private:
113 static int debug;
109}; 114};
110 115
111} 116}
112#endif 117#endif