author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (side-by-side diff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/vcardparser | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | kabc/vcardparser/vcard.h | 4 | ||||
-rw-r--r-- | kabc/vcardparser/vcardline.cpp | 6 | ||||
-rw-r--r-- | kabc/vcardparser/vcardline.h | 8 | ||||
-rw-r--r-- | kabc/vcardparser/vcardparser.cpp | 2 | ||||
-rw-r--r-- | kabc/vcardparser/vcardtool.cpp | 2 |
5 files changed, 12 insertions, 10 deletions
diff --git a/kabc/vcardparser/vcard.h b/kabc/vcardparser/vcard.h index 0bee441..85b50e4 100644 --- a/kabc/vcardparser/vcard.h +++ b/kabc/vcardparser/vcard.h @@ -1,91 +1,91 @@ /* This file is part of libkabc. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef VCARDPARSER_VCARD_H #define VCARDPARSER_VCARD_H #include "vcardline.h" #include <qmap.h> #include <qstringlist.h> -#include <qvaluelist.h> +#include <q3valuelist.h> namespace KABC { class VCard { public: - typedef QValueList<VCard> List; + typedef Q3ValueList<VCard> List; typedef QMap< QString, VCardLine::List > LineMap; enum Version { v2_1, v3_0 }; VCard(); VCard( const VCard& ); ~VCard(); VCard& operator=( const VCard& ); /** * Removes all lines from the vCard. */ void clear(); /** * Returns a list of all identifiers that exists in the * vCard. */ QStringList identifiers() const; /** * Adds a VCardLine to the VCard */ void addLine( const VCardLine& line ); /** * Returns all lines of the vcard with a special identifier. */ VCardLine::List lines( const QString& identifier ) const; /** * Returns only the first line of the vcard with a special identifier. */ VCardLine line( const QString& identifier ) const; /** * Set the version of the vCard. */ void setVersion( Version version ); /** * Returns the version of this vCard. */ Version version() const; private: LineMap mLineMap; class VCardPrivate; VCardPrivate *d; }; } #endif diff --git a/kabc/vcardparser/vcardline.cpp b/kabc/vcardparser/vcardline.cpp index 8df2d32..c7254a0 100644 --- a/kabc/vcardparser/vcardline.cpp +++ b/kabc/vcardparser/vcardline.cpp @@ -1,153 +1,155 @@ /* This file is part of libkabc. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "vcardline.h" +//Added by qt3to4: +#include <Q3CString> using namespace KABC; class VCardLine::VCardLinePrivate { public: QString mGroup; }; VCardLine::VCardLine() : d( 0 ) { } VCardLine::VCardLine( const QString &identifier ) : d( 0 ) { mIdentifier = identifier; } VCardLine::VCardLine( const QString &identifier, const QString &value ) : d( 0 ) { mIdentifier = identifier; - mValue.assign( value.data(), value.length() ); + mValue = value; } VCardLine::VCardLine( const VCardLine& line ) : d( 0 ) { mParamMap = line.mParamMap; mValue = line.mValue; mIdentifier = line.mIdentifier; } VCardLine::~VCardLine() { delete d; d = 0; } VCardLine& VCardLine::operator=( const VCardLine& line ) { if ( &line == this ) return *this; mParamMap = line.mParamMap; mValue = line.mValue; mIdentifier = line.mIdentifier; return *this; } void VCardLine::setIdentifier( const QString& identifier ) { mIdentifier = identifier; } QString VCardLine::identifier() const { return mIdentifier; } void VCardLine::setValueString( const QString& value ) { setValueCString( value.utf8() ); } -void VCardLine::setValueCString( const QCString& value ) +void VCardLine::setValueCString( const Q3CString& value ) { mValue.duplicate( value.data(), value.length() ); } void VCardLine::setValueBytes( const QByteArray& value ) { mValue = value; } QString VCardLine::valueString() const { return QString::fromUtf8( mValue.data(), mValue.size() ); } QByteArray VCardLine::valueBytes() const { return mValue; } void VCardLine::setGroup( const QString& group ) { if ( !d ) d = new VCardLinePrivate(); d->mGroup = group; } QString VCardLine::group() const { if ( d ) return d->mGroup; else return QString(); } bool VCardLine::hasGroup() const { if ( !d ) return false; else return d->mGroup.isEmpty(); } QStringList VCardLine::parameterList() const { //return mParamMap.keys(); //US method QMap::keys() not available yet. SO collect the data manually //US return mParamMap->keys(); QStringList result; QMap<QString, QStringList>::ConstIterator it; for( it = mParamMap.begin(); it != mParamMap.end(); ++it ) { result << it.key().latin1(); } return result; } void VCardLine::addParameter( const QString& param, const QString& value ) { QStringList &list = mParamMap[ param ]; if ( list.findIndex( value ) == -1 ) // not included yet list.append( value ); } diff --git a/kabc/vcardparser/vcardline.h b/kabc/vcardparser/vcardline.h index 8dc9322..dc4bdec 100644 --- a/kabc/vcardparser/vcardline.h +++ b/kabc/vcardparser/vcardline.h @@ -1,119 +1,119 @@ /* This file is part of libkabc. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef VCARDLINE_H #define VCARDLINE_H #include <qstringlist.h> -#include <qvaluelist.h> -#include <qcstring.h> +#include <q3valuelist.h> +#include <q3cstring.h> #include <qvariant.h> #include <qmap.h> #include <qstring.h> namespace KABC { class VCardLine { public: - typedef QValueList<VCardLine> List; + typedef Q3ValueList<VCardLine> List; typedef QMap<QString, QStringList> ParamMap; VCardLine(); VCardLine( const QString &identifier ); VCardLine( const QString &identifier, const QString &value ); VCardLine( const VCardLine& ); ~VCardLine(); VCardLine& operator=( const VCardLine& ); /** * Sets the identifier of this line e.g. UID, FN, CLASS */ void setIdentifier( const QString& identifier ); /** * Returns the identifier of this line. */ QString identifier() const; /** * Sets the value of of this line. */ void setValueString( const QString& value ); - void setValueCString( const QCString& value ); + void setValueCString( const Q3CString& value ); void setValueBytes( const QByteArray& value ); /** * Returns the value of this line. */ QString valueString() const; QByteArray valueBytes() const; /** * Sets the group the line belongs to. */ void setGroup( const QString& group ); /** * Returns the group the line belongs to. */ QString group() const; /** * Returns whether the line belongs to a group. */ bool hasGroup() const; /** * Returns all parameters. */ QStringList parameterList() const; /** * Add a new parameter to the line. */ void addParameter( const QString& param, const QString& value ); /** * Returns the values of a special parameter. * You can get a list of all parameters with paramList(). */ QStringList parameters( const QString& param ) const; /** * Returns only the first value of a special parameter. * You can get a list of all parameters with paramList(). */ QString parameter( const QString& param ) const; private: ParamMap mParamMap; QString mIdentifier; QByteArray mValue; class VCardLinePrivate; VCardLinePrivate *d; }; } #endif diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp index 11622a0..a319531 100644 --- a/kabc/vcardparser/vcardparser.cpp +++ b/kabc/vcardparser/vcardparser.cpp @@ -157,84 +157,84 @@ VCard::List VCardParser::parseVCards( const QString& text ) } return vCardList; } QString VCardParser::createVCards( const VCard::List& list ) { QString text; QString textLine; QString encodingType; QStringList idents; QStringList params; QStringList values; QStringList::ConstIterator identIt; QStringList::Iterator paramIt; QStringList::ConstIterator valueIt; VCardLine::List lines; VCardLine::List::ConstIterator lineIt; VCard::List::ConstIterator cardIt; bool hasEncoding; // iterate over the cards VCard::List::ConstIterator listEnd( list.end() ); for ( cardIt = list.begin(); cardIt != listEnd; ++cardIt ) { text.append( "BEGIN:VCARD\r\n" ); idents = (*cardIt).identifiers(); for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { lines = (*cardIt).lines( (*identIt) ); // iterate over the lines for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { if ( !(*lineIt).valueString().isEmpty() ) { if ( (*lineIt).hasGroup() ) textLine = (*lineIt).group() + "." + (*lineIt).identifier(); else textLine = (*lineIt).identifier(); params = (*lineIt).parameterList(); hasEncoding = false; if ( params.count() > 0 ) { // we have parameters for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { if ( (*paramIt) == "encoding" ) { hasEncoding = true; encodingType = (*lineIt).parameter( "encoding" ).lower(); } values = (*lineIt).parameters( *paramIt ); for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) { textLine.append( ";" + (*paramIt).upper() ); if ( !(*valueIt).isEmpty() ) textLine.append( "=" + (*valueIt) ); } } } if ( hasEncoding ) { // have to encode the data QByteArray input, output; input = (*lineIt).valueBytes(); if ( encodingType == "b" ) KCodecs::base64Encode( input, output ); else if ( encodingType == "quoted-printable" ) - KCodecs::quotedPrintableEncode( input, output ); + KCodecs::quotedPrintableEncode( input, output, true ); textLine.append( ":" + QString( output ) ); } else textLine.append( ":" + (*lineIt).valueString().replace( QRegExp("\n"), "\\n" ) ); if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); } else text.append( textLine + "\r\n" ); } } } text.append( "END:VCARD\r\n" ); text.append( "\r\n" ); } return text; } diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp index 204326e..435c3b0 100644 --- a/kabc/vcardparser/vcardtool.cpp +++ b/kabc/vcardparser/vcardtool.cpp @@ -591,129 +591,129 @@ QDateTime VCardTool::parseDateTime( const QString &str ) dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(), str.mid( 6, 2 ).toInt() ) ); if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), str.mid( 17, 2 ).toInt() ) ); } else { // is extended format yyyy-mm-dd dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(), str.mid( 8, 2 ).toInt() ) ); if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), str.mid( 17, 2 ).toInt() ) ); } return dateTime; } QString VCardTool::createDateTime( const QDateTime &dateTime ) { QString str; if ( dateTime.date().isValid() ) { str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(), dateTime.date().day() ); if ( dateTime.time().isValid() ) { QString tmp; tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(), dateTime.time().second() ); str += tmp; } } return str; } Picture VCardTool::parsePicture( const VCardLine &line ) { Picture pic; const QStringList params = line.parameterList(); if ( params.findIndex( "encoding" ) != -1 ) { QImage img; img.loadFromData( line.valueBytes() ); pic.setData( img ); } else if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) pic.setUrl( line.valueString() ); } if ( params.findIndex( "type" ) != -1 ) pic.setType( line.parameter( "type" ) ); return pic; } VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) { VCardLine line( identifier ); if ( pic.isIntern() ) { if ( !pic.data().isNull() ) { QByteArray input; - QDataStream s( input, IO_WriteOnly ); + QDataStream s( &input, QIODevice::WriteOnly ); s.setVersion( 4 ); s << pic.data(); line.setValueBytes( input ); line.addParameter( "encoding", "b" ); line.addParameter( "type", "image/png" ); } } else if ( !pic.url().isEmpty() ) { QByteArray ba; line.setValueString( pic.url() ); line.addParameter( "value", "URI" ); } return line; } Sound VCardTool::parseSound( const VCardLine &line ) { Sound snd; const QStringList params = line.parameterList(); if ( params.findIndex( "encoding" ) != -1 ) snd.setData( line.valueBytes() ); else if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) snd.setUrl( line.valueString() ); } /* TODO: support sound types if ( params.contains( "type" ) ) snd.setType( line.parameter( "type" ) ); */ return snd; } VCardLine VCardTool::createSound( const Sound &snd ) { VCardLine line( "SOUND" ); if ( snd.isIntern() ) { if ( !snd.data().isEmpty() ) { line.setValueBytes( snd.data() ); line.addParameter( "encoding", "b" ); // TODO: need to store sound type!!! } } else if ( !snd.url().isEmpty() ) { line.setValueString( snd.url() ); line.addParameter( "value", "URI" ); } return line; } Key VCardTool::parseKey( const VCardLine &line ) { Key key; const QStringList params = line.parameterList(); if ( params.findIndex( "encoding" ) != -1 ) key.setBinaryData( line.valueBytes() ); else key.setTextData( line.valueString() ); if ( params.findIndex( "type" ) != -1 ) { |