summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-06-29 03:14:07 (UTC)
committer ulf69 <ulf69>2004-06-29 03:14:07 (UTC)
commitf1b5f865e890dc5fd689474405a263163f2235f5 (patch) (unidiff)
tree4d74594b4157e465bf9436c328b2d75e3ea7fdb3
parent6035724601fc8b0541df085a7e20e738a85d81cd (diff)
downloadkdepimpi-f1b5f865e890dc5fd689474405a263163f2235f5.zip
kdepimpi-f1b5f865e890dc5fd689474405a263163f2235f5.tar.gz
kdepimpi-f1b5f865e890dc5fd689474405a263163f2235f5.tar.bz2
transfered binarypluigin into subdirectory to build it as a .so
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/formats/binary/binaryformat.cpp233
-rw-r--r--kabc/formats/binary/binaryformat.h76
-rw-r--r--kabc/formats/binary/kabcformat_binaryE.pro21
3 files changed, 330 insertions, 0 deletions
diff --git a/kabc/formats/binary/binaryformat.cpp b/kabc/formats/binary/binaryformat.cpp
new file mode 100644
index 0000000..fe1f36e
--- a/dev/null
+++ b/kabc/formats/binary/binaryformat.cpp
@@ -0,0 +1,233 @@
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#include <qdatastream.h>
29#include <qimage.h>
30
31#include <kdebug.h>
32#include <klocale.h>
33#include <kstandarddirs.h>
34
35#include "addressbook.h"
36#include "addressee.h"
37#include "picture.h"
38#include "sound.h"
39
40#include "binaryformat.h"
41
42#define BINARY_FORMAT_VERSION 2
43
44using namespace KABC;
45
46extern "C"
47{
48 FormatPlugin *format()
49 {
50 return new BinaryFormat;
51 }
52}
53
54bool BinaryFormat::load( Addressee &addressee, QFile *file )
55{
56 kdDebug(5700) << "BinaryFormat::load()" << endl;
57 QDataStream stream( file );
58
59 if ( !checkHeader( stream ) )
60 return false;
61
62 loadAddressee( addressee, stream );
63
64 return true;
65}
66
67bool BinaryFormat::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
68{
69 kdDebug(5700) << "BinaryFormat::loadAll()" << endl;
70
71 QDataStream stream( file );
72
73 if ( !checkHeader( stream ) )
74 return false;
75
76 Q_UINT32 entries;
77
78 stream >> entries;
79
80 for ( uint i = 0; i < entries; ++i ) {
81 Addressee addressee;
82 loadAddressee( addressee, stream );
83 addressee.setResource( resource );
84 addressBook->insertAddressee( addressee );
85 }
86
87 return true;
88}
89
90void BinaryFormat::save( const Addressee &addressee, QFile *file )
91{
92 kdDebug(5700) << "BinaryFormat::save()" << endl;
93
94 QDataStream stream( file );
95
96 writeHeader( stream );
97
98 Q_UINT32 entries = 1;
99 stream << entries;
100 saveAddressee( addressee, stream );
101}
102
103void BinaryFormat::saveAll( AddressBook *ab, Resource *resource, QFile *file )
104{
105 kdDebug(5700) << "BinaryFormat::saveAll()" << endl;
106
107 Q_UINT32 counter = 0;
108 QDataStream stream( file );
109
110 writeHeader( stream );
111 // set dummy number of entries
112 stream << counter;
113
114 AddressBook::Iterator it;
115 for ( it = ab->begin(); it != ab->end(); ++it ) {
116 if ( (*it).resource() == resource ) {
117 saveAddressee( (*it), stream );
118 counter++;
119 (*it).setChanged( false );
120 }
121 }
122
123 // set real number of entries
124 stream.device()->at( 2 * sizeof( Q_UINT32 ) );
125 stream << counter;
126}
127
128bool BinaryFormat::checkFormat( QFile *file ) const
129{
130 kdDebug(5700) << "BinaryFormat::checkFormat()" << endl;
131
132 QDataStream stream( file );
133
134 return checkHeader( stream );
135}
136
137bool BinaryFormat::checkHeader( QDataStream &stream ) const
138{
139 Q_UINT32 magic, version;
140
141 stream >> magic >> version;
142
143//US QFile *file = dynamic_cast<QFile*>( stream.device() );
144 QFile *file = (QFile*)( stream.device() );
145
146 if ( !file ) {
147 qDebug("BinaryFormat::checkHeader : Not a file?");
148 kdError() << i18n("Not a file?") << endl;
149 return false;
150 }
151
152 if ( magic != 0x2e93e ) {
153 qDebug("BinaryFormat::checkHeader : File '%s' is not binary format.", file->name().latin1());
154 kdError() << i18n("File '%1' is not binary format.").arg( file->name() ) << endl;
155 return false;
156 }
157
158 if ( version != BINARY_FORMAT_VERSION ) {
159 qDebug("BinaryFormat::checkHeader : File '%s' is the wrong version.", file->name().latin1());
160 kdError() << i18n("File '%1' is the wrong version.").arg( file->name() ) << endl;
161 return false;
162 }
163
164 return true;
165}
166
167void BinaryFormat::writeHeader( QDataStream &stream )
168{
169 Q_UINT32 magic, version;
170
171 magic = 0x2e93e;
172 version = BINARY_FORMAT_VERSION;
173
174 stream << magic << version;
175}
176
177void BinaryFormat::loadAddressee( Addressee &addressee, QDataStream &stream )
178{
179 stream >> addressee;
180/*
181 // load pictures
182 Picture photo = addressee.photo();
183 Picture logo = addressee.logo();
184
185 if ( photo.isIntern() ) {
186 QImage img;
187 if ( !img.load( locateLocal( "data", "kabc/photos/" ) + addressee.uid() ) )
188 kdDebug(5700) << "No photo available for '" << addressee.uid() << "'." << endl;
189
190 addressee.setPhoto( img );
191 }
192
193 if ( logo.isIntern() ) {
194 QImage img;
195 if ( !img.load( locateLocal( "data", "kabc/logos/" ) + addressee.uid() ) )
196 kdDebug(5700) << "No logo available for '" << addressee.uid() << "'." << endl;
197
198 addressee.setLogo( img );
199 }
200
201 // load sound
202 // TODO: load sound data from file
203*/
204}
205
206void BinaryFormat::saveAddressee( const Addressee &addressee, QDataStream &stream )
207{
208 stream << addressee;
209/*
210 // load pictures
211 Picture photo = addressee.photo();
212 Picture logo = addressee.logo();
213
214 if ( photo.isIntern() ) {
215 QImage img = photo.data();
216 QString fileName = locateLocal( "data", "kabc/photos/" ) + addressee.uid();
217
218 if ( !img.save( fileName, "PNG" ) )
219 kdDebug(5700) << "Unable to save photo for '" << addressee.uid() << "'." << endl;
220 }
221
222 if ( logo.isIntern() ) {
223 QImage img = logo.data();
224 QString fileName = locateLocal( "data", "kabc/logos/" ) + addressee.uid();
225
226 if ( !img.save( fileName, "PNG" ) )
227 kdDebug(5700) << "Unable to save logo for '" << addressee.uid() << "'." << endl;
228 }
229
230 // save sound
231 // TODO: save the sound data to file
232*/
233}
diff --git a/kabc/formats/binary/binaryformat.h b/kabc/formats/binary/binaryformat.h
new file mode 100644
index 0000000..415fd3b
--- a/dev/null
+++ b/kabc/formats/binary/binaryformat.h
@@ -0,0 +1,76 @@
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
diff --git a/kabc/formats/binary/kabcformat_binaryE.pro b/kabc/formats/binary/kabcformat_binaryE.pro
new file mode 100644
index 0000000..2d9594d
--- a/dev/null
+++ b/kabc/formats/binary/kabcformat_binaryE.pro
@@ -0,0 +1,21 @@
1 TEMPLATE= lib
2CONFIG += qt warn_on release
3#release debug
4
5TARGET = microkabcformat_binary
6#INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../qtcompat
7INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../qtcompat
8OBJECTS_DIR = obj/$(PLATFORM)
9MOC_DIR = moc
10DESTDIR = $(QPEDIR)/lib
11LIBS += -lmicrokde -lmicrokabc
12LIBS += -L$(QPEDIR)/lib
13DEFINES += KAB_EMBEDDED
14
15INTERFACES = \
16
17HEADERS = \
18 binaryformat.h
19
20SOURCES = \
21 binaryformat.cpp