37
// some default values
41
setCreationDate( QDateTime::currentDateTime() );
42
setModificationDate( QDateTime::currentDateTime() );
43
setLastBackupDate( QDateTime::currentDateTime() );
45
setCreator( QString() );
37
// some default values
41
setCreationDate(QDateTime::currentDateTime());
42
setModificationDate(QDateTime::currentDateTime());
43
setLastBackupDate(QDateTime::currentDateTime());
45
setCreator(QString());
51
while(!records.isEmpty()) delete records.takeFirst();
51
while (!records.isEmpty()) delete records.takeFirst();
55
bool PalmDB::load( const char* filename )
55
bool PalmDB::load(const char* filename)
59
if (!in.open (QIODevice::ReadOnly))
63
stream.setDevice (&in);
65
unsigned filesize = stream.device()->size();
66
if( filesize < 72 ) return false;
69
stream.setByteOrder (QDataStream::BigEndian);
71
// now start to read PDB header (72 bytes)
73
// read and encode database name
74
// The name field is 32 bytes long, and is NUL terminated.
75
// Use the length parameter of fromLatin1() anyway.
77
for(int k = 0; k < 32; k++)
79
m_name = QString::fromLatin1( (char*) name, 31 );
81
// read database attribute
86
// read database version (app-specific)
91
// NOTE: PDB specifies date as number of seconds since 1 Jan 1904
92
// QDateTime::setTime_t expects number of seconds since 1 Jan 1970
93
// so, we make adjustment with a constant offset of 2082844800
94
const int adjust = 2082844800;
99
m_creationDate.setTime_t( creation - adjust );
101
// read modification date
102
quint32 modification;
103
stream >> modification;
104
m_modificationDate.setTime_t( modification - adjust );
106
// read last backup date
108
stream >> lastbackup;
109
m_lastBackupDate.setTime_t( lastbackup - adjust );
111
// read modification number
115
// read app info id and sort info id
116
quint32 appid, sortid;
120
// read and encode database type
122
stream >> dbt[0] >> dbt[1] >> dbt[2] >> dbt[3];
123
m_type = QString::fromLatin1( (char*) dbt, 4 );
125
// read and encode database creator
127
stream >> dbc[0] >> dbc[1] >> dbc[2] >> dbc[3];
128
m_creator = QString::fromLatin1( (char*) dbc, 4 );
130
// read unique id seed
133
m_uniqueIDSeed = idseed;
135
// now start to read PDB record list (variable-length)
138
// FIXME what to do with this ?
146
// read entries in record list
147
// find out location and size of each record
148
QVector<unsigned> recpos( numrec );
149
QVector<int> recsize( numrec );
151
// FIXME any other better way to find record size ?
152
for( int r = 0; r < numrec; r++ )
156
stream >> pos >> flag >> dummy >> dummy >> dummy;
157
recpos[r] = pos; recsize[r] = filesize - pos;
158
if( r> 0 ) recsize[r-1] = pos - recpos[r-1]; // fixup
59
if (!in.open(QIODevice::ReadOnly))
63
stream.setDevice(&in);
65
unsigned filesize = stream.device()->size();
66
if (filesize < 72) return false;
69
stream.setByteOrder(QDataStream::BigEndian);
71
// now start to read PDB header (72 bytes)
73
// read and encode database name
74
// The name field is 32 bytes long, and is NUL terminated.
75
// Use the length parameter of fromLatin1() anyway.
77
for (int k = 0; k < 32; k++)
79
m_name = QString::fromLatin1((char*) name, 31);
81
// read database attribute
86
// read database version (app-specific)
91
// NOTE: PDB specifies date as number of seconds since 1 Jan 1904
92
// QDateTime::setTime_t expects number of seconds since 1 Jan 1970
93
// so, we make adjustment with a constant offset of 2082844800
94
const int adjust = 2082844800;
99
m_creationDate.setTime_t(creation - adjust);
101
// read modification date
102
quint32 modification;
103
stream >> modification;
104
m_modificationDate.setTime_t(modification - adjust);
106
// read last backup date
108
stream >> lastbackup;
109
m_lastBackupDate.setTime_t(lastbackup - adjust);
111
// read modification number
115
// read app info id and sort info id
116
quint32 appid, sortid;
120
// read and encode database type
122
stream >> dbt[0] >> dbt[1] >> dbt[2] >> dbt[3];
123
m_type = QString::fromLatin1((char*) dbt, 4);
125
// read and encode database creator
127
stream >> dbc[0] >> dbc[1] >> dbc[2] >> dbc[3];
128
m_creator = QString::fromLatin1((char*) dbc, 4);
130
// read unique id seed
133
m_uniqueIDSeed = idseed;
135
// now start to read PDB record list (variable-length)
138
// FIXME what to do with this ?
146
// read entries in record list
147
// find out location and size of each record
148
QVector<unsigned> recpos(numrec);
149
QVector<int> recsize(numrec);
151
// FIXME any other better way to find record size ?
152
for (int r = 0; r < numrec; r++) {
155
stream >> pos >> flag >> dummy >> dummy >> dummy;
156
recpos[r] = pos; recsize[r] = filesize - pos;
157
if (r > 0) recsize[r-1] = pos - recpos[r-1]; // fixup
163
qDebug( "name: \"%s\"", m_name.latin1() );
164
qDebug( "type: \"%s\"", m_type.latin1() );
165
qDebug( "creator: \"%s\"", m_creator.latin1() );
166
qDebug( "attributes: 0x%04X", m_attributes );
167
qDebug( "version: 0x%04X", m_version );
168
qDebug( "creation date: %s", m_creationDate.toString().latin1() );
169
qDebug( "modification date: %s", m_modificationDate.toString().latin1() );
170
qDebug( "last backup date: %s", m_lastBackupDate.toString().latin1() );
171
qDebug( "number of records: %d", numrec );
172
for( int r = 0; r < numrec; r++ )
173
qDebug( " rec %d at 0x%X size %d", r, recpos[r], recsize[r] );
162
qDebug("name: \"%s\"", qPrintable(m_name));
163
qDebug("type: \"%s\"", qPrintable(m_type));
164
qDebug("creator: \"%s\"", qPrintable(m_creator));
165
qDebug("attributes: 0x%04X", m_attributes);
166
qDebug("version: 0x%04X", m_version);
167
qDebug("creation date: %s", qPrintable(m_creationDate.toString()));
168
qDebug("modification date: %s", qPrintable(m_modificationDate.toString()));
169
qDebug("last backup date: %s", qPrintable(m_lastBackupDate.toString()));
170
qDebug("number of records: %d", numrec);
171
for (int r = 0; r < numrec; r++)
172
qDebug(" rec %d at 0x%X size %d", r, recpos[r], recsize[r]);
178
for( int r = 0; r < numrec; r++ )
180
QByteArray* data = new QByteArray;
177
for (int r = 0; r < numrec; r++) {
178
QByteArray* data = new QByteArray;
182
if( recpos[r] < filesize )
183
if( recsize[r] >= 0 )
185
data->resize( recsize[r] );
186
stream.device()->at( recpos[r] );
180
if (recpos[r] < filesize)
181
if (recsize[r] >= 0) {
182
data->resize(recsize[r]);
183
stream.device()->at(recpos[r]);
188
185
# warning "kde4 port it"
190
//for( int q = 0; q < recsize[r]; q++ )
191
//{ quint8 c; stream >> c; data->at(q) = c; }
187
//for( int q = 0; q < recsize[r]; q++ )
188
//{ quint8 c; stream >> c; data->at(q) = c; }
190
records.append(data);
199
bool PalmDB::save(const char* filename)
203
if (!out.open(QIODevice::WriteOnly))
207
stream.setDevice(&out);
210
stream.setByteOrder(QDataStream::BigEndian);
212
// now write PDB header (72 bytes)
214
// write database name
216
const char *dbname = m_name.toLatin1();
217
for (unsigned k = 0; k < 31; k++) {
218
quint8 c = (k < m_name.length()) ? dbname[k] : 0;
222
// NUL-terminate the database name
229
// write database attribute
230
quint16 attr = m_attributes;
233
// write database version (app-specific)
234
quint16 ver = m_version;
237
// reference date is 1 Jan 1904
238
// see also note in function load() above
239
QDateTime ref = QDateTime(QDate(1904, 1, 1));
241
// write creation date
242
quint32 creation = -m_creationDate.secsTo(ref);
245
// write modification date
246
quint32 modification = -m_modificationDate.secsTo(ref);
247
stream << modification;
249
// write last backup date
250
quint32 lastbackup = -m_lastBackupDate.secsTo(ref);
251
stream << lastbackup;
253
// write modification number
257
// write app info id and sort info id
258
quint32 appid = 0, sortid = 0;
262
// write and encode database type
264
const char *dbtype = m_type.toLatin1();
265
for (int p = 0; p < 4; p++) dbt[p] = dbtype[p];
266
stream << dbt[0] << dbt[1] << dbt[2] << dbt[3];
268
// write and encode database creator
270
const char *dbcreator = m_creator.toLatin1();
271
for (int p = 0; p < 4; p++) dbc[p] = dbcreator[p];
272
stream << dbc[0] << dbc[1] << dbc[2] << dbc[3];
274
// write unique id seed
278
// now start to read PDB record list (variable-length)
281
quint32 nextlist = 0;
285
quint16 numrec = records.count();
288
// where is the first record ?
289
// 78 is size of PDB header, 2 is filler before data
290
quint32 pos = 78 + 2;
291
pos += records.count() * 8;
294
for (unsigned r = 0; r < records.count(); r++) {
295
quint8 flag = 0, dummy = 0;
298
stream << dummy << dummy << dummy;
299
pos += records.at(r)->count();
302
// write 2-byte dummy
307
for (unsigned r = 0; r < records.count(); r++) {
308
QByteArray *data = records.at(r);
310
for (unsigned j = 0; j < data->count(); j++) {
311
quint8 c = data->at(j);
193
records.append( data );
202
bool PalmDB::save( const char* filename )
205
QFile out( filename );
206
if( !out.open( QIODevice::WriteOnly ) )
210
stream.setDevice( &out );
213
stream.setByteOrder (QDataStream::BigEndian);
215
// now write PDB header (72 bytes)
217
// write database name
219
const char *dbname = m_name.latin1();
220
for( unsigned k=0; k<31; k++ )
222
quint8 c = (k<m_name.length()) ? dbname[k] : 0;
226
// NUL-terminate the database name
233
// write database attribute
234
quint16 attr = m_attributes;
237
// write database version (app-specific)
238
quint16 ver = m_version;
241
// reference date is 1 Jan 1904
242
// see also note in function load() above
243
QDateTime ref = QDateTime(QDate( 1904, 1, 1) );
245
// write creation date
246
quint32 creation = -m_creationDate.secsTo( ref );
249
// write modification date
250
quint32 modification = -m_modificationDate.secsTo( ref );
251
stream << modification;
253
// write last backup date
254
quint32 lastbackup = -m_lastBackupDate.secsTo( ref );
255
stream << lastbackup;
257
// write modification number
261
// write app info id and sort info id
262
quint32 appid = 0, sortid = 0;
266
// write and encode database type
268
const char *dbtype = m_type.latin1();
269
for( int p=0; p<4; p++ ) dbt[p]=dbtype[p];
270
stream << dbt[0] << dbt[1] << dbt[2] << dbt[3];
272
// write and encode database creator
274
const char *dbcreator = m_creator.latin1();
275
for( int p=0; p<4; p++ ) dbc[p]=dbcreator[p];
276
stream << dbc[0] << dbc[1] << dbc[2] << dbc[3];
278
// write unique id seed
282
// now start to read PDB record list (variable-length)
285
quint32 nextlist = 0;
289
quint16 numrec = records.count();
292
// where is the first record ?
293
// 78 is size of PDB header, 2 is filler before data
294
quint32 pos = 78 + 2;
295
pos += records.count()*8;
298
for( unsigned r = 0; r < records.count(); r++ )
300
quint8 flag = 0, dummy = 0;
303
stream << dummy << dummy << dummy;
304
pos += records.at(r)->count();
307
// write 2-byte dummy
312
for( unsigned r = 0; r < records.count(); r++ )
314
QByteArray *data = records.at( r );
315
if( !data ) continue;
316
for( unsigned j=0; j<data->count(); j++ )
318
quint8 c = data->at( j );
329
void PalmDB::setType( const QString& t )
332
if( m_type.length() > 4 )
333
m_type = m_type.left( 4 );
334
while( m_type.length() < 4 )
339
void PalmDB::setCreator( const QString& c )
342
if( m_creator.length() > 4 )
343
m_type = m_creator.left( 4 );
344
while( m_creator.length() < 4 )
345
m_creator.append( 32 );
322
void PalmDB::setType(const QString& t)
325
if (m_type.length() > 4)
326
m_type = m_type.left(4);
327
while (m_type.length() < 4)
332
void PalmDB::setCreator(const QString& c)
335
if (m_creator.length() > 4)
336
m_type = m_creator.left(4);
337
while (m_creator.length() < 4)
338
m_creator.append(32);