| # kabc Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# simpleformat.cpp

    00001 /*
    00002     This file is part of libkabc.
    00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public License
    00016     along with this library; see the file COPYING.LIB.  If not, write to
    00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include <qfile.h>
    00022
    00023 #include <ksimpleconfig.h>
    00024 #include <kdebug.h>
    00025
    00026 #include "addressbook.h"
    00027
    00028 #include "simpleformat.h"
    00029
    00030 using namespace KABC;
    00031
    00032 bool SimpleFormat::load( AddressBook *addressBook, const QString &fileName )
    00033 {
    00034   kdDebug(5700) << "SimpleFormat::load(): " << fileName << endl;
    00035
    00036   KSimpleConfig cfg( fileName );
    00037
    00038   QStringList uids = cfg.groupList();
    00039   QStringList::ConstIterator it;
    00040   for( it = uids.begin(); it != uids.end(); ++it ) {
    00041     if ( (*it) == "<default>" ) continue;
    00042     cfg.setGroup( *it );
    00043     Addressee a;
    00044     a.setUid( *it );
    00045     a.setName( cfg.readEntry( "name" ) );
    00046     a.setFormattedName( cfg.readEntry( "formattedName" ) );
    00047     a.insertEmail( cfg.readEntry( "email" ) );
    00048 #if 0
    00049     QStringList phoneNumbers = cfg.readListEntry( "phonenumbers" );
    00050     QStringList::ConstIterator it2;
    00051     for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
    00052       PhoneNumber n;
    00053       n.setNumber( cfg.readEntry( "phonenumber" + (*it2) ) );
    00054       n.setType( PhoneNumber::Type((*it2).toInt()));
    00055       a.insertPhoneNumber( n );
    00056     }
    00057 #endif
    00058     addressBook->insertAddressee( a );
    00059   }
    00060
    00061   return true;
    00062 }
    00063
    00064 bool SimpleFormat::save( AddressBook *addressBook, const QString &fileName )
    00065 {
    00066   kdDebug(5700) << "SimpleFormat::save(): " << fileName << endl;
    00067
    00068   QFile::remove( fileName );
    00069
    00070   KSimpleConfig cfg( fileName );
    00071
    00072   AddressBook::Iterator it;
    00073   for ( it = addressBook->begin(); it != addressBook->end(); ++it ) {
    00074     cfg.setGroup( (*it).uid() );
    00075     cfg.writeEntry( "name", (*it).name() );
    00076     cfg.writeEntry( "formattedName", (*it).formattedName() );
    00077     cfg.writeEntry( "email", (*it).preferredEmail() );
    00078
    00079 #if 0
    00080     QStringList phoneNumberList;
    00081     PhoneNumber::List phoneNumbers = (*it).phoneNumbers();
    00082     PhoneNumber::List::ConstIterator it2;
    00083     for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
    00084       cfg.writeEntry( "phonenumber" + QString::number( int((*it2).type()) ),
    00085                       (*it2).number() );
    00086       phoneNumberList.append( QString::number( int((*it2).type()) ) );
    00087     }
    00088     cfg.writeEntry( "phonenumbers", phoneNumberList );
    00089 #endif
    00090   }
    00091
    00092   return true;
    00093 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:29:22 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001