Qtopia library API Documentation

palmtoprecord.cpp

00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include <qtopia/private/palmtoprecord.h>
00021 #include <qtopia/stringutil.h>
00022 #include <qstringlist.h>
00023 
00034 namespace Qtopia {
00035 
00036 
00037 
00038 Record &Record::operator=( const Record &c )
00039 {
00040     if(this == &c ) return *this;
00041     mUid = c.mUid;
00042     mCats = c.mCats;
00043     customMap = c.customMap;
00044     return *this;
00045 }
00046 
00047 void Record::setCategories( int single )
00048 {
00049     if ( single == 0 )
00050     return;
00051     mCats.resize(1);
00052     mCats[0] = single;
00053 }
00054 
00055 // convenience methods provided for loading and saving to xml
00056 QString Record::idsToString( const QArray<int> &catsUnsorted )
00057 {
00058     QArray<int> cats = catsUnsorted;
00059     cats.sort();
00060 
00061     QString str;
00062     for ( uint i = 0; i < cats.size(); i++ )
00063     if ( i == 0 )
00064         str = QString::number( cats[int(i)] );
00065     else
00066         str += ";" + QString::number( cats[int(i)] );
00067 
00068     return str;
00069 }
00070 
00071 // convenience methods provided for loading and saving to xml
00072 QArray<int> Record::idsFromString( const QString &str )
00073 {
00074     QStringList catStrs = QStringList::split( ";", str );
00075     QArray<int> cats( catStrs.count() );
00076     uint i = 0;
00077     for ( QStringList::ConstIterator it = catStrs.begin();
00078       it != catStrs.end(); ++it ) {
00079     cats[int(i)] = (*it).toInt();
00080     i++;
00081     }
00082     return cats;
00083 }
00084 
00089 QString Record::customField( const QString &key) const
00090 {
00091     if (customMap.contains(key))
00092     return customMap[key];
00093 
00094     return QString::null;
00095 }
00096 
00100 void Record::setCustomField( const QString &key, const QString &value)
00101 {
00102 //     qWarning("setting custom " + key + " to " + value);
00103     if (customMap.contains(key))
00104     customMap.replace(key, value);
00105     else
00106     customMap.insert(key, value);
00107 
00108 //     qWarning(QString("custom size %1").arg(customMap.count()));
00109 }
00110 
00114 void Record::removeCustomField(const QString &key)
00115 {
00116     customMap.remove(key);
00117 }
00118 
00119 QString Record::customToXml() const
00120 {
00121     //qWarning(QString("writing custom %1").arg(customMap.count()));
00122     QString buf(" ");
00123     for ( QMap<QString, QString>::ConstIterator cit = customMap.begin();
00124         cit != customMap.end(); ++cit) {
00125 //  qWarning(".ITEM.");
00126     buf += cit.key();
00127     buf += "=\"";
00128     buf += escapeString(cit.data());
00129     buf += "\" ";
00130     }
00131     return buf;
00132 }
00133 
00134 void Record::dump( const QMap<int, QString> &map )
00135 {
00136     QMap<int, QString>::ConstIterator it;
00137     for( it = map.begin(); it != map.end(); ++it )
00138     qDebug("%d : %s",  it.key(),  it.data().local8Bit().data() );
00139 }
00140 
00141 }
00142 
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:06 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001