summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-06-29 03:15:32 (UTC)
committer ulf69 <ulf69>2004-06-29 03:15:32 (UTC)
commita52c5f5a0b10cff057d9bca6046d50bfefb6896c (patch) (unidiff)
treee73363a510ab90f7f81f57f7376724449d3dfea5
parentf1b5f865e890dc5fd689474405a263163f2235f5 (diff)
downloadkdepimpi-a52c5f5a0b10cff057d9bca6046d50bfefb6896c.zip
kdepimpi-a52c5f5a0b10cff057d9bca6046d50bfefb6896c.tar.gz
kdepimpi-a52c5f5a0b10cff057d9bca6046d50bfefb6896c.tar.bz2
transfered files into the binary subfolder. That allowes us to build it as a .so
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/formats/binaryformat.cpp236
-rw-r--r--kabc/formats/binaryformat.h76
2 files changed, 0 insertions, 312 deletions
diff --git a/kabc/formats/binaryformat.cpp b/kabc/formats/binaryformat.cpp
deleted file mode 100644
index e2f28b8..0000000
--- a/kabc/formats/binaryformat.cpp
+++ b/dev/null
@@ -1,236 +0,0 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28
29#include <qdatastream.h>
30#include <qimage.h>
31
32#include <kdebug.h>
33#include <klocale.h>
34#include <kstandarddirs.h>
35
36#include "addressbook.h"
37#include "addressee.h"
38#include "picture.h"
39#include "sound.h"
40
41#include "binaryformat.h"
42
43#define BINARY_FORMAT_VERSION 2
44
45using namespace KABC;
46
47/*US
48extern "C"
49{
50 FormatPlugin *format()
51 {
52 qDebug(" BinaryFormat::format = new BinaryFormat");
53 return new BinaryFormat;
54 }
55}
56*/
57bool BinaryFormat::load( Addressee &addressee, QFile *file )
58{
59 kdDebug(5700) << "BinaryFormat::load()" << endl;
60 QDataStream stream( file );
61
62 if ( !checkHeader( stream ) )
63 return false;
64
65 loadAddressee( addressee, stream );
66
67 return true;
68}
69
70bool BinaryFormat::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
71{
72 kdDebug(5700) << "BinaryFormat::loadAll()" << endl;
73
74 QDataStream stream( file );
75
76 if ( !checkHeader( stream ) )
77 return false;
78
79 Q_UINT32 entries;
80
81 stream >> entries;
82
83 for ( uint i = 0; i < entries; ++i ) {
84 Addressee addressee;
85 loadAddressee( addressee, stream );
86 addressee.setResource( resource );
87 addressBook->insertAddressee( addressee );
88 }
89
90 return true;
91}
92
93void BinaryFormat::save( const Addressee &addressee, QFile *file )
94{
95 kdDebug(5700) << "BinaryFormat::save()" << endl;
96
97 QDataStream stream( file );
98
99 writeHeader( stream );
100
101 Q_UINT32 entries = 1;
102 stream << entries;
103 saveAddressee( addressee, stream );
104}
105
106void BinaryFormat::saveAll( AddressBook *ab, Resource *resource, QFile *file )
107{
108 kdDebug(5700) << "BinaryFormat::saveAll()" << endl;
109
110 Q_UINT32 counter = 0;
111 QDataStream stream( file );
112
113 writeHeader( stream );
114 // set dummy number of entries
115 stream << counter;
116
117 AddressBook::Iterator it;
118 for ( it = ab->begin(); it != ab->end(); ++it ) {
119 if ( (*it).resource() == resource ) {
120 saveAddressee( (*it), stream );
121 counter++;
122 (*it).setChanged( false );
123 }
124 }
125
126 // set real number of entries
127 stream.device()->at( 2 * sizeof( Q_UINT32 ) );
128 stream << counter;
129}
130
131bool BinaryFormat::checkFormat( QFile *file ) const
132{
133 kdDebug(5700) << "BinaryFormat::checkFormat()" << endl;
134
135 QDataStream stream( file );
136
137 return checkHeader( stream );
138}
139
140bool BinaryFormat::checkHeader( QDataStream &stream ) const
141{
142 Q_UINT32 magic, version;
143
144 stream >> magic >> version;
145
146//US QFile *file = dynamic_cast<QFile*>( stream.device() );
147 QFile *file = (QFile*)( stream.device() );
148
149 if ( !file ) {
150 qDebug("BinaryFormat::checkHeader : Not a file?");
151 kdError() << i18n("Not a file?") << endl;
152 return false;
153 }
154
155 if ( magic != 0x2e93e ) {
156 qDebug("BinaryFormat::checkHeader : File '%s' is not binary format.", file->name().latin1());
157 kdError() << i18n("File '%1' is not binary format.").arg( file->name() ) << endl;
158 return false;
159 }
160
161 if ( version != BINARY_FORMAT_VERSION ) {
162 qDebug("BinaryFormat::checkHeader : File '%s' is the wrong version.", file->name().latin1());
163 kdError() << i18n("File '%1' is the wrong version.").arg( file->name() ) << endl;
164 return false;
165 }
166
167 return true;
168}
169
170void BinaryFormat::writeHeader( QDataStream &stream )
171{
172 Q_UINT32 magic, version;
173
174 magic = 0x2e93e;
175 version = BINARY_FORMAT_VERSION;
176
177 stream << magic << version;
178}
179
180void BinaryFormat::loadAddressee( Addressee &addressee, QDataStream &stream )
181{
182 stream >> addressee;
183/*
184 // load pictures
185 Picture photo = addressee.photo();
186 Picture logo = addressee.logo();
187
188 if ( photo.isIntern() ) {
189 QImage img;
190 if ( !img.load( locateLocal( "data", "kabc/photos/" ) + addressee.uid() ) )
191 kdDebug(5700) << "No photo available for '" << addressee.uid() << "'." << endl;
192
193 addressee.setPhoto( img );
194 }
195
196 if ( logo.isIntern() ) {
197 QImage img;
198 if ( !img.load( locateLocal( "data", "kabc/logos/" ) + addressee.uid() ) )
199 kdDebug(5700) << "No logo available for '" << addressee.uid() << "'." << endl;
200
201 addressee.setLogo( img );
202 }
203
204 // load sound
205 // TODO: load sound data from file
206*/
207}
208
209void BinaryFormat::saveAddressee( const Addressee &addressee, QDataStream &stream )
210{
211 stream << addressee;
212/*
213 // load pictures
214 Picture photo = addressee.photo();
215 Picture logo = addressee.logo();
216
217 if ( photo.isIntern() ) {
218 QImage img = photo.data();
219 QString fileName = locateLocal( "data", "kabc/photos/" ) + addressee.uid();
220
221 if ( !img.save( fileName, "PNG" ) )
222 kdDebug(5700) << "Unable to save photo for '" << addressee.uid() << "'." << endl;
223 }
224
225 if ( logo.isIntern() ) {
226 QImage img = logo.data();
227 QString fileName = locateLocal( "data", "kabc/logos/" ) + addressee.uid();
228
229 if ( !img.save( fileName, "PNG" ) )
230 kdDebug(5700) << "Unable to save logo for '" << addressee.uid() << "'." << endl;
231 }
232
233 // save sound
234 // TODO: save the sound data to file
235*/
236}
diff --git a/kabc/formats/binaryformat.h b/kabc/formats/binaryformat.h
deleted file mode 100644
index 415fd3b..0000000
--- a/kabc/formats/binaryformat.h
+++ b/dev/null
@@ -1,76 +0,0 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/*
21Enhanced Version of the file for platform independent KDE tools.
22Copyright (c) 2004 Ulf Schenk
23
24$Id$
25*/
26
27#ifndef KABC_BINARYFORMAT_H
28#define KABC_BINARYFORMAT_H
29
30#include "formatplugin.h"
31
32namespace KABC {
33
34class AddressBook;
35class Addressee;
36
37/**
38 @short binary file format for addressbook entries.
39*/
40class BinaryFormat : public FormatPlugin
41{
42public:
43 /**
44 * Load single addressee from file.
45 */
46 bool load( Addressee &, QFile *file );
47
48 /**
49 * Load whole addressee from file.
50 */
51 bool loadAll( AddressBook *, Resource *, QFile *file );
52
53 /**
54 * Save single addressee to file.
55 */
56 void save( const Addressee &, QFile *file );
57
58 /**
59 * Save all addressees to file.
60 */
61 void saveAll( AddressBook *, Resource *, QFile *file );
62
63 /**
64 * Check for valid format of a file.
65 */
66 bool checkFormat( QFile *file ) const;
67
68private:
69 void loadAddressee( Addressee &, QDataStream & );
70 void saveAddressee( const Addressee &, QDataStream & );
71 bool checkHeader( QDataStream & ) const;
72 void writeHeader( QDataStream & );
73};
74
75}
76#endif