summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp2
-rw-r--r--kabc/picture.cpp38
-rw-r--r--kabc/vcard/ContentLine.cpp30
-rw-r--r--kabc/vcard/VCardv.cpp77
4 files changed, 99 insertions, 48 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3ce733d..568dfc4 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1638,159 +1638,161 @@ void Addressee::setKeys( const Key::List& list ) {
1638} 1638}
1639 1639
1640Key::List Addressee::keys() const 1640Key::List Addressee::keys() const
1641{ 1641{
1642 return mData->keys; 1642 return mData->keys;
1643} 1643}
1644 1644
1645Key::List Addressee::keys( int type, QString customTypeString ) const 1645Key::List Addressee::keys( int type, QString customTypeString ) const
1646{ 1646{
1647 Key::List list; 1647 Key::List list;
1648 1648
1649 Key::List::ConstIterator it; 1649 Key::List::ConstIterator it;
1650 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1650 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1651 if ( (*it).type() == type ) { 1651 if ( (*it).type() == type ) {
1652 if ( type == Key::Custom ) { 1652 if ( type == Key::Custom ) {
1653 if ( customTypeString.isEmpty() ) { 1653 if ( customTypeString.isEmpty() ) {
1654 list.append(*it); 1654 list.append(*it);
1655 } else { 1655 } else {
1656 if ( (*it).customTypeString() == customTypeString ) 1656 if ( (*it).customTypeString() == customTypeString )
1657 list.append(*it); 1657 list.append(*it);
1658 } 1658 }
1659 } else { 1659 } else {
1660 list.append(*it); 1660 list.append(*it);
1661 } 1661 }
1662 } 1662 }
1663 } 1663 }
1664 return list; 1664 return list;
1665} 1665}
1666 1666
1667Key Addressee::findKey( const QString &id ) const 1667Key Addressee::findKey( const QString &id ) const
1668{ 1668{
1669 Key::List::ConstIterator it; 1669 Key::List::ConstIterator it;
1670 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1670 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1671 if ( (*it).id() == id ) { 1671 if ( (*it).id() == id ) {
1672 return *it; 1672 return *it;
1673 } 1673 }
1674 } 1674 }
1675 return Key(); 1675 return Key();
1676} 1676}
1677 1677
1678QString Addressee::asString() const 1678QString Addressee::asString() const
1679{ 1679{
1680 return "Smith, agent Smith..."; 1680 return "Smith, agent Smith...";
1681} 1681}
1682 1682
1683void Addressee::dump() const 1683void Addressee::dump() const
1684{ 1684{
1685 return; 1685 return;
1686#if 0
1686 kdDebug(5700) << "Addressee {" << endl; 1687 kdDebug(5700) << "Addressee {" << endl;
1687 1688
1688 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1689 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1689 1690
1690 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1691 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1691 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1692 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1692 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1693 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1693 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1694 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1694 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1695 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1695 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1696 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1696 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1697 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1697 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1698 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1698 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1699 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1699 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1700 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1700 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1701 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1701 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1702 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1702 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1703 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1703 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1704 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1704 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1705 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1705 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1706 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1706 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1707 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1707 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1708 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1708 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1709 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1709 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1710 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1710 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1711 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1711 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1712 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1712 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1713 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1713 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1714 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1714 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1715 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1715 1716
1716 kdDebug(5700) << " Emails {" << endl; 1717 kdDebug(5700) << " Emails {" << endl;
1717 QStringList e = emails(); 1718 QStringList e = emails();
1718 QStringList::ConstIterator it; 1719 QStringList::ConstIterator it;
1719 for( it = e.begin(); it != e.end(); ++it ) { 1720 for( it = e.begin(); it != e.end(); ++it ) {
1720 kdDebug(5700) << " " << (*it) << endl; 1721 kdDebug(5700) << " " << (*it) << endl;
1721 } 1722 }
1722 kdDebug(5700) << " }" << endl; 1723 kdDebug(5700) << " }" << endl;
1723 1724
1724 kdDebug(5700) << " PhoneNumbers {" << endl; 1725 kdDebug(5700) << " PhoneNumbers {" << endl;
1725 PhoneNumber::List p = phoneNumbers(); 1726 PhoneNumber::List p = phoneNumbers();
1726 PhoneNumber::List::ConstIterator it2; 1727 PhoneNumber::List::ConstIterator it2;
1727 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1728 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1728 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1729 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1729 } 1730 }
1730 kdDebug(5700) << " }" << endl; 1731 kdDebug(5700) << " }" << endl;
1731 1732
1732 Address::List a = addresses(); 1733 Address::List a = addresses();
1733 Address::List::ConstIterator it3; 1734 Address::List::ConstIterator it3;
1734 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1735 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1735 (*it3).dump(); 1736 (*it3).dump();
1736 } 1737 }
1737 1738
1738 kdDebug(5700) << " Keys {" << endl; 1739 kdDebug(5700) << " Keys {" << endl;
1739 Key::List k = keys(); 1740 Key::List k = keys();
1740 Key::List::ConstIterator it4; 1741 Key::List::ConstIterator it4;
1741 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1742 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1742 kdDebug(5700) << " Type: " << int((*it4).type()) << 1743 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1743 " Key: " << (*it4).textData() << 1744 " Key: " << (*it4).textData() <<
1744 " CustomString: " << (*it4).customTypeString() << endl; 1745 " CustomString: " << (*it4).customTypeString() << endl;
1745 } 1746 }
1746 kdDebug(5700) << " }" << endl; 1747 kdDebug(5700) << " }" << endl;
1747 1748
1748 kdDebug(5700) << "}" << endl; 1749 kdDebug(5700) << "}" << endl;
1750#endif
1749} 1751}
1750 1752
1751 1753
1752void Addressee::insertAddress( const Address &address ) 1754void Addressee::insertAddress( const Address &address )
1753{ 1755{
1754 detach(); 1756 detach();
1755 mData->empty = false; 1757 mData->empty = false;
1756 1758
1757 Address::List::Iterator it; 1759 Address::List::Iterator it;
1758 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1760 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1759 if ( (*it).id() == address.id() ) { 1761 if ( (*it).id() == address.id() ) {
1760 *it = address; 1762 *it = address;
1761 return; 1763 return;
1762 } 1764 }
1763 } 1765 }
1764 mData->addresses.append( address ); 1766 mData->addresses.append( address );
1765} 1767}
1766 1768
1767void Addressee::removeAddress( const Address &address ) 1769void Addressee::removeAddress( const Address &address )
1768{ 1770{
1769 detach(); 1771 detach();
1770 1772
1771 Address::List::Iterator it; 1773 Address::List::Iterator it;
1772 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1774 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1773 if ( (*it).id() == address.id() ) { 1775 if ( (*it).id() == address.id() ) {
1774 mData->addresses.remove( it ); 1776 mData->addresses.remove( it );
1775 return; 1777 return;
1776 } 1778 }
1777 } 1779 }
1778} 1780}
1779 1781
1780Address Addressee::address( int type ) const 1782Address Addressee::address( int type ) const
1781{ 1783{
1782 Address address( type ); 1784 Address address( type );
1783 Address::List::ConstIterator it; 1785 Address::List::ConstIterator it;
1784 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1786 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1785 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1787 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1786 if ( (*it).type() & Address::Pref ) 1788 if ( (*it).type() & Address::Pref )
1787 return (*it); 1789 return (*it);
1788 else if ( address.isEmpty() ) 1790 else if ( address.isEmpty() )
1789 address = (*it); 1791 address = (*it);
1790 } 1792 }
1791 } 1793 }
1792 1794
1793 return address; 1795 return address;
1794} 1796}
1795 1797
1796Address::List Addressee::addresses() const 1798Address::List Addressee::addresses() const
diff --git a/kabc/picture.cpp b/kabc/picture.cpp
index 6a34b98..57aa297 100644
--- a/kabc/picture.cpp
+++ b/kabc/picture.cpp
@@ -8,106 +8,132 @@
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 "picture.h" 28#include "picture.h"
29 29
30using namespace KABC; 30using namespace KABC;
31 31
32Picture::Picture() 32Picture::Picture()
33 : mIntern( false ) 33 : mIntern( false )
34{ 34{
35 mUndefined = true; 35 mUndefined = true;
36} 36}
37 37
38Picture::Picture( const QString &url ) 38Picture::Picture( const QString &url )
39 : mUrl( url ), mIntern( false ) 39 : mUrl( url ), mIntern( false )
40{ 40{
41 mUndefined = false; 41 mUndefined = false;
42} 42}
43 43
44Picture::Picture( const QImage &data ) 44Picture::Picture( const QImage &data )
45 : mData( data ), mIntern( true ) 45 : mData( data ), mIntern( true )
46{ 46{
47 mUndefined = false; 47 mUndefined = false;
48} 48}
49 49
50Picture::~Picture() 50Picture::~Picture()
51{ 51{
52} 52}
53 53
54bool Picture::operator==( const Picture &p ) const 54bool Picture::operator==( const Picture &p ) const
55{ 55{
56 if ( mIntern != p.mIntern ) return false; 56 //qDebug("compare PIC ");
57 57 if ( mUndefined && p.mUndefined ) {
58 //qDebug("compare PIC true 1 ");
59 return true;
60 }
61 if ( mUndefined || p.mUndefined ) {
62 //qDebug("compare PIC false 1");
63 return false;
64 }
65 // now we should deal with two defined pics!
66 if ( mIntern != p.mIntern ) {
67 //qDebug("compare PIC false 2");
68 return false;
69 }
58 if ( mIntern ) { 70 if ( mIntern ) {
59 if ( mData != p.mData ) 71 //qDebug("mIntern ");
72 if ( mData.isNull() && p.mData.isNull() ) {
73 //qDebug("compare PIC true 2 ");
74 return true;
75 }
76 if ( mData.isNull() || p.mData.isNull() ){
77 //qDebug("compare PIC false 3-1");
78
79 return false;
80 }
81 if ( mData != p.mData ) {
82 //qDebug("compare PIC false 3");
60 return false; 83 return false;
84 }
61 } else { 85 } else {
62 if ( mUrl != p.mUrl ) 86 if ( mUrl != p.mUrl ) {
63 return false; 87 //qDebug("compare PIC false 4");
88 return false;
89 }
64 } 90 }
65 91 //qDebug("compare PIC true ");
66 return true; 92 return true;
67} 93}
68 94
69bool Picture::operator!=( const Picture &p ) const 95bool Picture::operator!=( const Picture &p ) const
70{ 96{
71 return !( p == *this ); 97 return !( p == *this );
72} 98}
73 99
74void Picture::setUrl( const QString &url ) 100void Picture::setUrl( const QString &url )
75{ 101{
76 mUrl = url; 102 mUrl = url;
77 mIntern = false; 103 mIntern = false;
78 mUndefined = false; 104 mUndefined = false;
79} 105}
80 106
81void Picture::setData( const QImage &data ) 107void Picture::setData( const QImage &data )
82{ 108{
83 mData = data; 109 mData = data;
84 mIntern = true; 110 mIntern = true;
85 mUndefined = false; 111 mUndefined = false;
86} 112}
87 113
88void Picture::setType( const QString &type ) 114void Picture::setType( const QString &type )
89{ 115{
90 mType = type; 116 mType = type;
91} 117}
92 118
93bool Picture::isIntern() const 119bool Picture::isIntern() const
94{ 120{
95 return mIntern; 121 return mIntern;
96} 122}
97 123
98QString Picture::url() const 124QString Picture::url() const
99{ 125{
100 return mUrl; 126 return mUrl;
101} 127}
102 128
103QImage Picture::data() const 129QImage Picture::data() const
104{ 130{
105 return mData; 131 return mData;
106} 132}
107QPixmap Picture::pixmap() const 133QPixmap Picture::pixmap() const
108{ 134{
109 QPixmap p; 135 QPixmap p;
110 p.convertFromImage ( mData ); 136 p.convertFromImage ( mData );
111 return p; 137 return p;
112} 138}
113 139
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp
index c368172..2f88cde 100644
--- a/kabc/vcard/ContentLine.cpp
+++ b/kabc/vcard/ContentLine.cpp
@@ -228,94 +228,122 @@ ContentLine::_parse()
228 RTokenise(paraValue, ",", paraValues); 228 RTokenise(paraValue, ",", paraValues);
229 229
230 QStrListIterator it2( paraValues ); 230 QStrListIterator it2( paraValues );
231 231
232 for(; it2.current(); ++it2) { 232 for(; it2.current(); ++it2) {
233 233
234 Param *p = new Param; 234 Param *p = new Param;
235 p->setName( paraName ); 235 p->setName( paraName );
236 p->setValue( *it2 ); 236 p->setValue( *it2 );
237 237
238 paramList_.append(p); 238 paramList_.append(p);
239 } 239 }
240 } 240 }
241 241
242 // Create a new value of the correct type. 242 // Create a new value of the correct type.
243 243
244 valueType_ = EntityTypeToValueType(entityType_); 244 valueType_ = EntityTypeToValueType(entityType_);
245 245
246 //kdDebug(5710) << "valueType: " << valueType_ << endl; 246 //kdDebug(5710) << "valueType: " << valueType_ << endl;
247 247
248 switch (valueType_) { 248 switch (valueType_) {
249 249
250 case ValueSound: value_ = new SoundValue;break; 250 case ValueSound: value_ = new SoundValue;break;
251 case ValueAgent: value_ = new AgentValue;break; 251 case ValueAgent: value_ = new AgentValue;break;
252 case ValueAddress: value_ = new AdrValue; break; 252 case ValueAddress: value_ = new AdrValue; break;
253 case ValueTel: value_ = new TelValue; break; 253 case ValueTel: value_ = new TelValue; break;
254 case ValueTextBin: value_ = new TextBinValue;break; 254 case ValueTextBin: value_ = new TextBinValue;break;
255 case ValueOrg: value_ = new OrgValue; break; 255 case ValueOrg: value_ = new OrgValue; break;
256 case ValueN: value_ = new NValue; break; 256 case ValueN: value_ = new NValue; break;
257 case ValueUTC: value_ = new UTCValue; break; 257 case ValueUTC: value_ = new UTCValue; break;
258 case ValueURI: value_ = new URIValue; break; 258 case ValueURI: value_ = new URIValue; break;
259 case ValueClass: value_ = new ClassValue;break; 259 case ValueClass: value_ = new ClassValue;break;
260 case ValueFloat: value_ = new FloatValue;break; 260 case ValueFloat: value_ = new FloatValue;break;
261 case ValueImage: value_ = new ImageValue;break; 261 case ValueImage: value_ = new ImageValue;break;
262 case ValueDate: value_ = new DateValue; break; 262 case ValueDate: value_ = new DateValue; break;
263 case ValueTextList: value_ = new TextListValue;break; 263 case ValueTextList: value_ = new TextListValue;break;
264 case ValueGeo: value_ = new GeoValue; break; 264 case ValueGeo: value_ = new GeoValue; break;
265 case ValueText: 265 case ValueText:
266 case ValueUnknown: 266 case ValueUnknown:
267 default: value_ = new TextValue; break; 267 default: value_ = new TextValue; break;
268 } 268 }
269 269
270 *value_ = valuePart; 270 *value_ = valuePart;
271} 271}
272 272
273 void 273 void
274ContentLine::_assemble() 274ContentLine::_assemble()
275{ 275{
276 //strRep_.truncate(0);
277 QString line;
278 if (!group_.isEmpty())
279 line = group_ + '.';
280 line += name_;
281 ParamListIterator it(paramList_);
282 for (; it.current(); ++it)
283 line += ";" + it.current()->asString();
284
285 if (value_ != 0)
286 line += ":" + value_->asString();
287
288 line = line.replace( QRegExp( "\n" ), "\\n" );
289
290 // Fold lines longer than 72 chars
291 const int maxLen = 72;
292 uint cursor = 0;
293 QString cut;
294 while( line.length() > ( cursor + 1 ) * maxLen ) {
295 cut += line.mid( cursor * maxLen, maxLen );
296 cut += "\r\n ";
297 ++cursor;
298 }
299 cut += line.mid( cursor * maxLen );
300 strRep_ = cut.latin1();
301 //qDebug("ContentLine::_assemble()\n%s*****", strRep_.data());
302#if 0
276 vDebug("Assemble (argl) - my name is \"" + name_ + "\""); 303 vDebug("Assemble (argl) - my name is \"" + name_ + "\"");
277 strRep_.truncate(0); 304 strRep_.truncate(0);
278 305
279 QCString line; 306 QCString line;
280 307
281 if (!group_.isEmpty()) 308 if (!group_.isEmpty())
282 line += group_ + '.'; 309 line += group_ + '.';
283 310
284 line += name_; 311 line += name_;
285 312
286 vDebug("Adding parameters"); 313 vDebug("Adding parameters");
287 ParamListIterator it(paramList_); 314 ParamListIterator it(paramList_);
288 315
289 for (; it.current(); ++it) 316 for (; it.current(); ++it)
290 line += ";" + it.current()->asString(); 317 line += ";" + it.current()->asString();
291 318
292 vDebug("Adding value"); 319 vDebug("Adding value");
293 if (value_ != 0) 320 if (value_ != 0)
294 line += ":" + value_->asString(); 321 line += ":" + value_->asString();
295 else 322 else
296 vDebug("No value"); 323 vDebug("No value");
297 324
298 // Quote newlines 325 // Quote newlines
299 line = line.replace( QRegExp( "\n" ), "\\n" ); 326 line = line.replace( QRegExp( "\n" ), "\\n" );
300 327
301 // Fold lines longer than 72 chars 328 // Fold lines longer than 72 chars
302 const int maxLen = 72; 329 const int maxLen = 72;
303 uint cursor = 0; 330 uint cursor = 0;
304 while( line.length() > ( cursor + 1 ) * maxLen ) { 331 while( line.length() > ( cursor + 1 ) * maxLen ) {
305 strRep_ += line.mid( cursor * maxLen, maxLen ); 332 strRep_ += line.mid( cursor * maxLen, maxLen );
306 strRep_ += "\r\n "; 333 strRep_ += "\r\n ";
307 ++cursor; 334 ++cursor;
308 } 335 }
309 strRep_ += line.mid( cursor * maxLen ); 336 strRep_ += line.mid( cursor * maxLen );
310 //qDebug("ContentLine::_assemble()\n%s*****", strRep_.data()); 337 qDebug("ContentLine::_assemble()\n%s*****", strRep_.data());
338#endif
311} 339}
312 340
313 void 341 void
314ContentLine::clear() 342ContentLine::clear()
315{ 343{
316 group_.truncate(0); 344 group_.truncate(0);
317 name_.truncate(0); 345 name_.truncate(0);
318 paramList_.clear(); 346 paramList_.clear();
319 delete value_; 347 delete value_;
320 value_ = 0; 348 value_ = 0;
321} 349}
diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp
index bc80707..49bfe43 100644
--- a/kabc/vcard/VCardv.cpp
+++ b/kabc/vcard/VCardv.cpp
@@ -1,274 +1,269 @@
1/* 1/*
2 libvcard - vCard parsing library for vCard version 3.0 2 libvcard - vCard parsing library for vCard version 3.0
3 3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org 4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy 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 7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the 8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 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 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: 11 furnished to do so, subject to the following conditions:
12 12
13 The above copyright notice and this permission notice shall be included in 13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software. 14 all copies or substantial portions of the Software.
15 15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 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, 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 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 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 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. 21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/ 22*/
23 23
24#include <qcstring.h> 24#include <qcstring.h>
25#include <qstrlist.h> 25#include <qstrlist.h>
26#include <qstringlist.h>
27#include <qstring.h>
28#include <qvaluelist.h>
26 29
27#include <VCardEntity.h> 30#include <VCardEntity.h>
28#include <VCardVCard.h> 31#include <VCardVCard.h>
29#include <VCardContentLine.h> 32#include <VCardContentLine.h>
30#include <VCardRToken.h> 33#include <VCardRToken.h>
31 34
32#include <VCardDefines.h> 35#include <VCardDefines.h>
33 36
34using namespace VCARD; 37using namespace VCARD;
35 38
36VCard::VCard() 39VCard::VCard()
37 :Entity() 40 :Entity()
38{ 41{
39 contentLineList_.setAutoDelete( TRUE ); 42 contentLineList_.setAutoDelete( TRUE );
40} 43}
41 44
42VCard::VCard(const VCard & x) 45VCard::VCard(const VCard & x)
43 :Entity(x), 46 :Entity(x),
44 group_(x.group_) 47 group_(x.group_)
45{ 48{
46 contentLineList_.setAutoDelete( TRUE ); 49 contentLineList_.setAutoDelete( TRUE );
47 50
48 QPtrListIterator<ContentLine> it(x.contentLineList_); 51 QPtrListIterator<ContentLine> it(x.contentLineList_);
49 for (; it.current(); ++it) { 52 for (; it.current(); ++it) {
50 ContentLine * c = new ContentLine(*it.current()); 53 ContentLine * c = new ContentLine(*it.current());
51 contentLineList_.append(c); 54 contentLineList_.append(c);
52 } 55 }
53 56
54} 57}
55 58
56VCard::VCard(const QCString & s) 59VCard::VCard(const QCString & s)
57 :Entity(s) 60 :Entity(s)
58{ 61{
59 contentLineList_.setAutoDelete( TRUE ); 62 contentLineList_.setAutoDelete( TRUE );
60} 63}
61 64
62 VCard & 65 VCard &
63VCard::operator = (VCard & x) 66VCard::operator = (VCard & x)
64{ 67{
65 if (*this == x) return *this; 68 if (*this == x) return *this;
66 69
67 group_ = x.group(); 70 group_ = x.group();
68 QPtrListIterator<ContentLine> it(x.contentLineList_); 71 QPtrListIterator<ContentLine> it(x.contentLineList_);
69 for (; it.current(); ++it) { 72 for (; it.current(); ++it) {
70 ContentLine * c = new ContentLine(*it.current()); 73 ContentLine * c = new ContentLine(*it.current());
71 contentLineList_.append(c); 74 contentLineList_.append(c);
72 } 75 }
73 76
74 Entity::operator = (x); 77 Entity::operator = (x);
75 return *this; 78 return *this;
76} 79}
77 80
78 VCard & 81 VCard &
79VCard::operator = (const QCString & s) 82VCard::operator = (const QCString & s)
80{ 83{
81 Entity::operator = (s); 84 Entity::operator = (s);
82 return *this; 85 return *this;
83} 86}
84 87
85 bool 88 bool
86VCard::operator == (VCard & x) 89VCard::operator == (VCard & x)
87{ 90{
88 x.parse(); 91 x.parse();
89 return false; 92 return false;
90} 93}
91 94
92VCard::~VCard() 95VCard::~VCard()
93{ 96{
94} 97}
95 98
96 void 99 void
97VCard::_parse() 100VCard::_parse()
98{ 101{
99 vDebug("parse() called"); 102
100 QStrList l; 103 QStringList l;
104 QStrList sl;
101 105
102 RTokenise(strRep_, "\r\n", l); 106 RTokenise(strRep_, "\r\n", sl);
103 107
104 if (l.count() < 3) { // Invalid VCARD ! 108 if (sl.count() < 3) { // Invalid VCARD !
105 vDebug("Invalid vcard"); 109 //qDebug("invalid vcard ");
106 return; 110 return;
107 } 111 }
108 112 l = QStringList::fromStrList( sl );
109 // Get the first line 113 // Get the first line
110 QCString beginLine = QCString(l.at(0)).stripWhiteSpace(); 114 QString beginLine = l[0].stripWhiteSpace();
111
112 vDebug("Begin line == \"" + beginLine + "\"");
113 115
114 // Remove extra blank lines 116 // Remove extra blank lines
115 while (QCString(l.last()).isEmpty()) 117 while (l.last().isEmpty())
116 l.remove(l.last()); 118 l.remove(l.last());
117 119
118 // Now we know this is the last line 120 // Now we know this is the last line
119 QCString endLine = l.last(); 121 QString endLine = l.last();
120 122
121 // Trash the first and last lines as we have seen them. 123 // Trash the first and last lines as we have seen them.
122 l.remove(0u); 124 l.remove(l.first());
123 l.remove(l.last()); 125 l.remove(l.last());
124 126
125 /////////////////////////////////////////////////////////////// 127 ///////////////////////////////////////////////////////////////
126 // FIRST LINE 128 // FIRST LINE
127 129
128 int split = beginLine.find(':'); 130 int split = beginLine.find(':');
129 131
130 if (split == -1) { // invalid, no BEGIN 132 if (split == -1) { // invalid, no BEGIN
131 vDebug("No split"); 133 vDebug("No split");
132 return; 134 return;
133 } 135 }
134 136
135 QCString firstPart(beginLine.left(split)); 137 QString firstPart(beginLine.left(split));
136 QCString valuePart(beginLine.mid(split + 1)); 138 QString valuePart(beginLine.mid(split + 1));
137 139
138 split = firstPart.find('.'); 140 split = firstPart.find('.');
139 141
140 if (split != -1) { 142 if (split != -1) {
141 group_ = firstPart.left(split); 143 group_ = firstPart.left(split);
142 firstPart= firstPart.right(firstPart.length() - split - 1); 144 firstPart= firstPart.right(firstPart.length() - split - 1);
143 } 145 }
144 146
145 if (qstrnicmp(firstPart, "BEGIN", 5) != 0) { // No BEGIN ! 147 if (firstPart.left(5) != "BEGIN" ) { // No BEGIN !
146 vDebug("No BEGIN"); 148 qDebug("no BEGIN in vcard ");
147 return; 149 return;
148 } 150 }
149 151
150 if (qstrnicmp(valuePart, "VCARD", 5) != 0) { // Not a vcard ! 152 if (valuePart.left(5) != "VCARD") { // Not a vcard !
151 vDebug("No VCARD"); 153 qDebug("not a VCARD ");
152 return; 154 return;
153 } 155 }
154 156
155 /////////////////////////////////////////////////////////////// 157 ///////////////////////////////////////////////////////////////
156 // CONTENT LINES 158 // CONTENT LINES
157 // 159 //
158 vDebug("Content lines"); 160 vDebug("Content lines");
159 161
160 // Handle folded lines. 162 // Handle folded lines.
161 163
162 QStrList refolded; 164 QStringList refolded;
163
164 QStrListIterator it(l);
165 165
166 QCString cur;
167 166
168 for (; it.current(); ++it) { 167 QStringList::Iterator it = l.begin();
169 168
170 cur = it.current(); 169 QString cur;
171 170
171 for (; it != l.end(); ++it) {
172 cur = (*it);
172 ++it; 173 ++it;
173 174 while ( it!= l.end() && (*it).at(0) == ' '&& (*it).length()!= 1) {
174 while ( 175 cur += (*it) ;
175 it.current() &&
176 it.current()[0] == ' '&&
177 strlen(it.current()) != 1)
178 {
179 cur += it.current() + 1;
180 ++it; 176 ++it;
181 } 177 }
182
183 --it; 178 --it;
184
185 refolded.append(cur); 179 refolded.append(cur);
186 } 180 }
187 181 QStringList::Iterator it2 = refolded.begin();
188 QStrListIterator it2(refolded); 182 for (; it2 != refolded.end(); ++it2) {
189 183 ContentLine * cl = new ContentLine(QCString((*it2).latin1()));
190 for (; it2.current(); ++it2) {
191 vDebug("New contentline using \"" + QCString(it2.current()) + "\"");
192 ContentLine * cl = new ContentLine(it2.current());
193
194 cl->parse(); 184 cl->parse();
195 if (cl->value() == 0) 185 if (cl->value() == 0)
196 { 186 {
197 qDebug("Content line could not be parsed. Discarded: %s", it2.current()); 187 qDebug("Content line could not be parsed. Discarded: %s", (*it2).latin1());
198 delete cl; 188 delete cl;
199 } 189 }
200 else 190 else
201 contentLineList_.append(cl); 191 contentLineList_.append(cl);
202 } 192 }
203 193
204 /////////////////////////////////////////////////////////////// 194 ///////////////////////////////////////////////////////////////
205 // LAST LINE 195 // LAST LINE
206 196
197
198 // LR: sorry, but the remaining code in this method makes no sense
199
200#if 0
207 split = endLine.find(':'); 201 split = endLine.find(':');
208 202
209 if (split == -1) // invalid, no END 203 if (split == -1) // invalid, no END
210 return; 204 return;
211 205
212 firstPart = endLine.left(split); 206 firstPart = endLine.left(split);
213 valuePart = endLine.right(firstPart.length() - split - 1); 207 valuePart = endLine.right(firstPart.length() - split - 1);
214 208
215 split = firstPart.find('.'); 209 split = firstPart.find('.');
216 210
217 if (split != -1) { 211 if (split != -1) {
218 group_ = firstPart.left(split); 212 group_ = firstPart.left(split);
219 firstPart= firstPart.right(firstPart.length() - split - 1); 213 firstPart= firstPart.right(firstPart.length() - split - 1);
220 } 214 }
221 215
222 if (qstricmp(firstPart, "END") != 0) // No END ! 216 if (qstricmp(firstPart, "END") != 0) // No END !
223 return; 217 return;
224 218
225 if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard ! 219 if (qstricmp(valuePart, "VCARD") != 0) // Not a vcard !
226 return; 220 return;
221#endif
227} 222}
228 223
229 void 224 void
230VCard::_assemble() 225VCard::_assemble()
231{ 226{
232 vDebug("Assembling vcard"); 227 vDebug("Assembling vcard");
233 strRep_ = "BEGIN:VCARD\r\n"; 228 strRep_ = "BEGIN:VCARD\r\n";
234 strRep_ += "VERSION:3.0\r\n"; 229 strRep_ += "VERSION:3.0\r\n";
235 230
236 QPtrListIterator<ContentLine> it(contentLineList_); 231 QPtrListIterator<ContentLine> it(contentLineList_);
237 232
238 for (; it.current(); ++it) 233 for (; it.current(); ++it)
239 strRep_ += it.current()->asString() + "\r\n"; 234 strRep_ += it.current()->asString() + "\r\n";
240 235
241 strRep_ += "END:VCARD\r\n"; 236 strRep_ += "END:VCARD\r\n";
242} 237}
243 238
244 bool 239 bool
245VCard::has(EntityType t) 240VCard::has(EntityType t)
246{ 241{
247 parse(); 242 parse();
248 return contentLine(t) == 0 ? false : true; 243 return contentLine(t) == 0 ? false : true;
249} 244}
250 245
251 bool 246 bool
252VCard::has(const QCString & s) 247VCard::has(const QCString & s)
253{ 248{
254 parse(); 249 parse();
255 return contentLine(s) == 0 ? false : true; 250 return contentLine(s) == 0 ? false : true;
256} 251}
257 252
258 void 253 void
259VCard::add(const ContentLine & cl) 254VCard::add(const ContentLine & cl)
260{ 255{
261 parse(); 256 parse();
262 ContentLine * c = new ContentLine(cl); 257 ContentLine * c = new ContentLine(cl);
263 contentLineList_.append(c); 258 contentLineList_.append(c);
264} 259}
265 260
266 void 261 void
267VCard::add(const QCString & s) 262VCard::add(const QCString & s)
268{ 263{
269 parse(); 264 parse();
270 ContentLine * c = new ContentLine(s); 265 ContentLine * c = new ContentLine(s);
271 contentLineList_.append(c); 266 contentLineList_.append(c);
272} 267}
273 268
274 ContentLine * 269 ContentLine *