summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-08-20 00:36:50 (UTC)
committer ulf69 <ulf69>2004-08-20 00:36:50 (UTC)
commitd39b363278224b969d4c2945d32968c980b5d842 (patch) (unidiff)
tree418087aff444216ddb08fcd94fa7fdbfa6d46947
parentf4149cef5f3be19d64c9c53130a62de0ec28ee44 (diff)
downloadkdepimpi-d39b363278224b969d4c2945d32968c980b5d842.zip
kdepimpi-d39b363278224b969d4c2945d32968c980b5d842.tar.gz
kdepimpi-d39b363278224b969d4c2945d32968c980b5d842.tar.bz2
performance optimization during vCard loading
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/vcardformatimpl.cpp19
-rw-r--r--kabc/vcardformatimpl.h2
2 files changed, 12 insertions, 9 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
index 3fcaf94..bd9a57b 100644
--- a/kabc/vcardformatimpl.cpp
+++ b/kabc/vcardformatimpl.cpp
@@ -44,47 +44,49 @@ using namespace VCARD;
44bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) 44bool VCardFormatImpl::load( Addressee &addressee, QFile *file )
45{ 45{
46 kdDebug(5700) << "VCardFormat::load()" << endl; 46 kdDebug(5700) << "VCardFormat::load()" << endl;
47 47
48 QByteArray fdata = file->readAll(); 48 QByteArray fdata = file->readAll();
49 QCString data(fdata.data(), fdata.size()+1); 49 QCString data(fdata.data(), fdata.size()+1);
50 50
51 VCardEntity e( data ); 51 VCardEntity e( data );
52 52
53 VCardListIterator it( e.cardList() ); 53 VCardListIterator it( e.cardList() );
54 54
55 if ( it.current() ) { 55 if ( it.current() ) {
56 VCard v(*it.current()); 56//US VCard v(*it.current());
57 loadAddressee( addressee, v ); 57//US loadAddressee( addressee, v );
58 loadAddressee( addressee, it.current() );
58 return true; 59 return true;
59 } 60 }
60 61
61 return false; 62 return false;
62} 63}
63 64
64bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) 65bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
65{ 66{
66 kdDebug(5700) << "VCardFormat::loadAll()" << endl; 67 kdDebug(5700) << "VCardFormat::loadAll()" << endl;
67 68
68 QByteArray fdata = file->readAll(); 69 QByteArray fdata = file->readAll();
69 QCString data(fdata.data(), fdata.size()+1); 70 QCString data(fdata.data(), fdata.size()+1);
70 71
71 VCardEntity e( data ); 72 VCardEntity e( data );
72 73
73 VCardListIterator it( e.cardList() ); 74 VCardListIterator it( e.cardList() );
74 75
75 for (; it.current(); ++it) { 76 for (; it.current(); ++it) {
76 VCard v(*it.current()); 77//US VCard v(*it.current());
77 Addressee addressee; 78 Addressee addressee;
78 loadAddressee( addressee, v ); 79//US loadAddressee( addressee, v );
80 loadAddressee( addressee, it.current() );
79 addressee.setResource( resource ); 81 addressee.setResource( resource );
80 addressBook->insertAddressee( addressee ); 82 addressBook->insertAddressee( addressee );
81 } 83 }
82 84
83 return true; 85 return true;
84} 86}
85 87
86void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) 88void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
87{ 89{
88 VCardEntity vcards; 90 VCardEntity vcards;
89 VCardList vcardlist; 91 VCardList vcardlist;
90 vcardlist.setAutoDelete( true ); 92 vcardlist.setAutoDelete( true );
@@ -113,27 +115,27 @@ void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file
113 saveAddressee( (*it), v, false ); 115 saveAddressee( (*it), v, false );
114 (*it).setChanged( false ); 116 (*it).setChanged( false );
115 vcardlist.append( v ); 117 vcardlist.append( v );
116 } 118 }
117 } 119 }
118 120
119 vcards.setCardList( vcardlist ); 121 vcards.setCardList( vcardlist );
120 122
121 QCString vcardData = vcards.asString(); 123 QCString vcardData = vcards.asString();
122 file->writeBlock( (const char*)vcardData, vcardData.length() ); 124 file->writeBlock( (const char*)vcardData, vcardData.length() );
123} 125}
124 126
125bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard &v ) 127bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
126{ 128{
127 QPtrList<ContentLine> contentLines = v.contentLineList(); 129 QPtrList<ContentLine> contentLines = v->contentLineList();
128 ContentLine *cl; 130 ContentLine *cl;
129 131
130 for( cl = contentLines.first(); cl; cl = contentLines.next() ) { 132 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
131 QCString n = cl->name(); 133 QCString n = cl->name();
132 if ( n.left( 2 ) == "X-" ) { 134 if ( n.left( 2 ) == "X-" ) {
133 n = n.mid( 2 ); 135 n = n.mid( 2 );
134 int posDash = n.find( "-" ); 136 int posDash = n.find( "-" );
135 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), 137 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ),
136 QString::fromUtf8( n.mid( posDash + 1 ) ), 138 QString::fromUtf8( n.mid( posDash + 1 ) ),
137 QString::fromUtf8( cl->value()->asString() ) ); 139 QString::fromUtf8( cl->value()->asString() ) );
138 continue; 140 continue;
139 } 141 }
@@ -992,26 +994,27 @@ Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &
992 sound.setUrl( QString::fromUtf8( v->asString() ) ); 994 sound.setUrl( QString::fromUtf8( v->asString() ) );
993 } 995 }
994 996
995 return sound; 997 return sound;
996} 998}
997 999
998bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) 1000bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee )
999{ 1001{
1000 VCardEntity e( vcard.utf8() ); 1002 VCardEntity e( vcard.utf8() );
1001 VCardListIterator it( e.cardList() ); 1003 VCardListIterator it( e.cardList() );
1002 1004
1003 if ( it.current() ) { 1005 if ( it.current() ) {
1004 VCard v(*it.current()); 1006//US VCard v(*it.current());
1005 loadAddressee( addressee, v ); 1007//US loadAddressee( addressee, v );
1008 loadAddressee( addressee, it.current() );
1006 return true; 1009 return true;
1007 } 1010 }
1008 1011
1009 return false; 1012 return false;
1010} 1013}
1011 1014
1012bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard ) 1015bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard )
1013{ 1016{
1014 VCardEntity vcards; 1017 VCardEntity vcards;
1015 VCardList vcardlist; 1018 VCardList vcardlist;
1016 vcardlist.setAutoDelete( true ); 1019 vcardlist.setAutoDelete( true );
1017 1020
diff --git a/kabc/vcardformatimpl.h b/kabc/vcardformatimpl.h
index 2dd68d9..fa3d55f 100644
--- a/kabc/vcardformatimpl.h
+++ b/kabc/vcardformatimpl.h
@@ -49,25 +49,25 @@ class AddressBook;
49class VCardFormatImpl 49class VCardFormatImpl
50{ 50{
51 public: 51 public:
52 bool load( Addressee &, QFile *file ); 52 bool load( Addressee &, QFile *file );
53 bool loadAll( AddressBook *, Resource *, QFile *file ); 53 bool loadAll( AddressBook *, Resource *, QFile *file );
54 void save( const Addressee &, QFile *file ); 54 void save( const Addressee &, QFile *file );
55 void saveAll( AddressBook *, Resource *, QFile *file ); 55 void saveAll( AddressBook *, Resource *, QFile *file );
56 56
57 bool readFromString( const QString &vcard, Addressee &addr ); 57 bool readFromString( const QString &vcard, Addressee &addr );
58 bool writeToString( const Addressee &addressee, QString &vcard ); 58 bool writeToString( const Addressee &addressee, QString &vcard );
59 59
60 protected: 60 protected:
61 bool loadAddressee( Addressee &, VCARD::VCard & ); 61 bool loadAddressee( Addressee &, VCARD::VCard * );
62 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern ); 62 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern );
63 63
64 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & ); 64 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & );
65 QString readTextValue( VCARD::ContentLine * ); 65 QString readTextValue( VCARD::ContentLine * );
66 66
67 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & ); 67 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & );
68 QDate readDateValue( VCARD::ContentLine * ); 68 QDate readDateValue( VCARD::ContentLine * );
69 69
70 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & ); 70 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & );
71 QDateTime readDateTimeValue( VCARD::ContentLine * ); 71 QDateTime readDateTimeValue( VCARD::ContentLine * );
72 72
73 void addAddressValue( VCARD::VCard *, const Address & ); 73 void addAddressValue( VCARD::VCard *, const Address & );