21 #include <tqdatastream.h>
26 #include <kstandarddirs.h>
28 #include "addressbook.h"
29 #include "addressee.h"
33 #include "binaryformat.h"
35 #define BINARY_FORMAT_VERSION 1
50 TQDataStream stream( file );
52 if ( !checkHeader( stream ) )
55 loadAddressee( addressee, stream );
64 TQDataStream stream( file );
66 if ( !checkHeader( stream ) )
73 for ( uint i = 0; i < entries; ++i ) {
75 loadAddressee( addressee, stream );
78 resource->insertAddressee( addressee );
88 TQDataStream stream( file );
90 writeHeader( stream );
92 TQ_UINT32 entries = 1;
94 saveAddressee( addressee, stream );
101 TQ_UINT32 counter = 0;
102 TQDataStream stream( file );
104 writeHeader( stream );
109 for ( it = resource->begin(); it != resource->end(); ++it ) {
110 saveAddressee( (*it), stream );
112 (*it).setChanged(
false );
116 stream.device()->at( 2 *
sizeof( TQ_UINT32 ) );
122 kdDebug(5700) <<
"BinaryFormat::checkFormat()" <<
endl;
124 TQDataStream stream( file );
126 return checkHeader( stream );
129 bool BinaryFormat::checkHeader( TQDataStream &stream )
const
131 TQ_UINT32 magic, version;
133 stream >> magic >> version;
135 TQFile *file =
dynamic_cast<TQFile*
>( stream.device() );
142 if ( magic != 0x2e93e ) {
143 kdError() << TQString(i18n(
"File '%1' is not binary format.").arg( file->name() )) <<
endl;
147 if ( version != BINARY_FORMAT_VERSION ) {
148 kdError() << TQString(i18n(
"File '%1' is the wrong version.").arg( file->name() )) <<
endl;
155 void BinaryFormat::writeHeader( TQDataStream &stream )
160 version = BINARY_FORMAT_VERSION;
165 void BinaryFormat::loadAddressee(
Addressee &addressee, TQDataStream &stream )
194 void BinaryFormat::saveAddressee(
const Addressee &addressee, TQDataStream &stream )
void setChanged(bool value)
Mark addressee as changed.
void setResource(Resource *resource)
Set resource where the addressee is from.
kndbgstream & endl(kndbgstream &s)
kdbgstream kdError(int area=0)
kdbgstream kdDebug(int area=0)
static data, shared by ALL addressee objects