-
Notifications
You must be signed in to change notification settings - Fork 4
/
TypeDefs.cpp
426 lines (403 loc) · 13 KB
/
TypeDefs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/*
* Copyright 2005-2017 Rochus Keller <mailto:me@rochus-keller.info>
*
* This file is part of the DoorScope application
* see <http://doorscope.ch/>).
*
* GNU General Public License Usage
* This file may be used under the terms of the GNU General Public
* License (GPL) versions 2.0 or 3.0 as published by the Free Software
* Foundation and appearing in the file LICENSE.GPL included in
* the packaging of this file. Please review the following information
* to ensure GNU General Public Licensing requirements will be met:
* http://www.fsf.org/licensing/licenses/info/GPLv2.html and
* http://www.gnu.org/copyleft/gpl.html.
*/
#include "TypeDefs.h"
#include <Sdb/Database.h>
#include <Sdb/Obj.h>
#include <Stream/DataReader.h>
#include <QHash>
#include <QtDebug>
#include "AppContext.h"
using namespace Ds;
using namespace Sdb;
const char* IndexDefs::IdxDocId = "<doorscope>IdxDocId";
const char* IndexDefs::IdxDocObjId = "<doorscope>IdxDocObjId";
const char* IndexDefs::IdxAnnDocNr = "<doorscope>IdxAnnDocNr";
struct _NameMapping
{
quint32 d_id;
const char* d_name;
const char* d_pretty;
int d_type;
};
static const _NameMapping s_names[] =
{
{AttrCreatedBy, "CreatedBy", "Created By", 0 },
{AttrCreatedOn, "CreatedOn", "Created On", 0 },
{AttrModifiedBy, "ModifiedBy", "Last Modified By", 0 },
{AttrModifiedOn, "ModifiedOn", "Last Modified On", 0 },
{AttrCreatedThru, "CreatedThru", "Created Thru", 0 },
{AttrReviewStatus, "ReviewStatus", 0, 0 },
{AttrReviewNeeded, "ReviewNeeded", 0, 0 },
{AttrAnnotated, "Annotated", 0, 0 },
{AttrReviewer, "Reviewer", 0, 0 },
{AttrStatusDate, "StatusDate", 0, 0 },
{AttrConsRevStat, "ConsRevStat", 0, 0 },
{TypeDocument, "Document", 0, 0 },
{AttrDocId, "Id", "Doc. ID", TypeDocument },
{AttrDocPath, "Path", 0, 0 },
{AttrDocVer, "Ver", "Version", 0 },
{AttrDocDesc, "Desc", "Description", 0 },
{AttrDocName, "Name", 0, TypeDocument },
{AttrDocType, "Type", 0, TypeDocument },
{AttrDocBaseline, "Baseline", 0, 0 },
{AttrDocVerMaj, "VerMaj", 0, 0 },
{AttrDocVerMin, "VerMin", 0, 0 },
{AttrDocVerSuff, "VerSuff", 0, 0 },
{AttrDocVerAnnot, "VerAnnot", "Baseline Annotation", 0 },
{AttrDocVerDate, "VerDate", 0, 0 },
{AttrDocPrefix, "Prefix", 0, 0 },
{AttrDocExported, "Exported", 0, 0 },
{AttrDocImported, "Imported", 0, 0 },
{AttrDocStream, "Source File", 0, 0 },
{AttrDocAttrs, "Attrs", 0, 0 },
{AttrDocObjAttrs, "ObjAttrs", 0, 0 },
{AttrDocOwning, "Owning", 0, 0 },
{AttrDocMaxAnnot, "MaxAnnot", 0, 0 },
{AttrDocDiffSource, "DiffSource", 0, 0 },
{AttrDocAltName, "AltName", 0, 0 },
{AttrDocIndex, "Index", 0, 0 },
{AttrObjIdent, "RelId", "Absolute Number", 0 },
{AttrObjNumber, "Number", "Object Number", 0 },
{AttrObjAttrChanged, "AttrChanged", 0, 0 },
{AttrObjTextChanged, "TextChanged", 0, 0 },
{AttrObjShort, "Short", "Obj. Short Text", 0 },
{AttrObjText, "Text", "Object Text", TypeObject },
{AttrObjHomeDoc, "HomeDoc", 0, TypeObject },
{AttrObjDeleted, "Deleted", 0, 0 },
{AttrObjDocId, "DocId", 0, TypeObject },
{TypeTitle, "Heading", 0, 0 },
{AttrTitleSplit, "TitleSplit", 0, 0 },
{TypeSection, "Section", 0, 0 },
{AttrSecSplit, "SecSplit", 0, 0 },
{AttrLnkModId, "ModId", 0, 0 },
{AttrLnkModName, "ModName", "Link Module", 0 },
{TypeOutLink, "OutLink", 0, 0 },
{AttrTrgObjId, "ObjId", "Target Object", TypeOutLink },
{AttrTrgDocId, "DocId", "Doc. ID", TypeOutLink },
{AttrTrgDocName, "DocName", "Doc. Name", TypeOutLink },
{AttrTrgDocVer, "DocVer", "Doc. Version", TypeOutLink },
{AttrTrgDocModDate, "DocModDate", "Doc. Version Date", TypeOutLink },
{AttrTrgDocIsBl, "DocIsBl", "Doc. Baseline", TypeOutLink },
{TypeInLink, "InLink", 0, 0 },
{AttrSrcObjId, "ObjId", "Source Object", TypeInLink },
{AttrSrcDocId, "DocId", "Doc. ID", TypeInLink },
{AttrSrcDocName, "DocName", "Doc. Name", TypeInLink },
{AttrSrcDocVer, "DocVer", "Doc. Version", TypeInLink },
{AttrSrcDocModDate, "DocModDate", "Doc. Version Date", TypeInLink },
{AttrSrcDocIsBl, "DocIsBl", "Doc. Baseline", TypeInLink },
{TypeTable, "Table", 0, 0 },
{TypeTableRow, "TableRow", "Table Row", 0 },
{TypeTableCell, "TableCell", "Table Cell", 0 },
{TypePicture, "Picture", 0, 0 },
{AttrPicImage, "Image", 0, 0 },
{AttrPicWidth, "Width", 0, 0 },
{AttrPicHeight, "Height", 0, 0 },
{TypeHistory, "History", 0, 0 },
{AttrHistAuthor, "Author", 0, 0 },
{AttrHistDate, "Date", 0, 0 },
{AttrHistType, "Type", 0, TypeHistory },
{AttrHistObjId, "ObjId", 0, TypeHistory },
{AttrHistAttr, "Attr", 0, TypeHistory },
{AttrHistOld, "Old", 0, 0 },
{AttrHistNew, "New", 0, 0 },
{AttrHistInfo, "Info", 0, 0 },
{TypeFolder, "Folder", 0, 0 },
{AttrFldrName, "Name", 0, TypeFolder },
{AttrFldrExpanded, "Expanded", 0, 0 },
{TypeAnnotation, "Annotation", 0, 0 },
{AttrAnnNr, "Nr", 0, 0 },
{AttrAnnAttr, "Attr", 0, TypeAnnotation },
{AttrAnnPos, "Pos", 0, 0 },
{AttrAnnLen, "Len", 0, 0 },
{AttrAnnText, "Text", 0, TypeAnnotation },
{AttrAnnHomeDoc, "HomeDoc", 0, TypeAnnotation },
{AttrAnnPrio, "Prio", 0, 0 },
{AttrAnnOldNr, "OldNr", 0, 0 },
{TypeStub, "Stub", "Linked Object", 0 },
{AttrStubTitle, "Title", "Object Heading", 0 },
{TypeLuaScript, "Script", 0, 0 },
{TypeLuaFilter, "Filter", 0, 0 },
{AttrScriptName, "Name", 0, TypeLuaScript },
{AttrScriptSource, "Source", 0, TypeLuaScript },
{ 0, 0, 0, 0 }
};
typedef QHash<QPair<quint32,QByteArray>,quint32> NameToAtom; // [ type, name | pretty ] -> atom
static NameToAtom s_nameToAtom;
void TypeDefs::init( Database& db )
{
for( int i = 0; s_names[i].d_id; i++ )
{
QByteArray key = QByteArray::fromRawData( s_names[i].d_name, ::strlen(s_names[i].d_name)+1 );
s_nameToAtom.insert( qMakePair( quint32(0), key ), s_names[i].d_id );
if( s_names[i].d_type )
s_nameToAtom.insert( qMakePair( quint32(s_names[i].d_type), key ), s_names[i].d_id );
if( s_names[i].d_pretty )
{
key = QByteArray::fromRawData( s_names[i].d_pretty, ::strlen(s_names[i].d_pretty)+1 );
s_nameToAtom.insert( qMakePair( quint32(0), key ), s_names[i].d_id );
if( s_names[i].d_type )
s_nameToAtom.insert( qMakePair( quint32(s_names[i].d_type), key ), s_names[i].d_id );
}
}
Database::Lock lock( &db, true );
// Root
//db.presetAtom( "popAccountList", AttrPopAccountList );
// ContentObject
if( db.findIndex( IndexDefs::IdxDocId ) == 0 )
{
IndexMeta def( IndexMeta::Value );
def.d_items.append( IndexMeta::Item( AttrDocId ) );
db.createIndex( IndexDefs::IdxDocId, def );
}
if( db.findIndex( IndexDefs::IdxDocObjId ) == 0 )
{
IndexMeta def( IndexMeta::Value );
def.d_items.append( IndexMeta::Item( AttrObjDocId ) );
def.d_items.append( IndexMeta::Item( AttrObjIdent ) );
db.createIndex( IndexDefs::IdxDocObjId, def );
}
if( db.findIndex( IndexDefs::IdxAnnDocNr ) == 0 )
{
IndexMeta def( IndexMeta::Value );
def.d_items.append( IndexMeta::Item( AttrAnnHomeDoc ) );
def.d_items.append( IndexMeta::Item( AttrAnnNr ) );
db.createIndex( IndexDefs::IdxAnnDocNr, def );
}
db.presetAtom( "DsMax", DsMax );
}
quint32 TypeDefs::findAtom(const char *name, quint32 type)
{
// Dieser Aufruf von fromRawData ergibt eine Size des ByteArray, die das
// Nullzeichen einschliesst. Auch beim Import des DSDX durch DocManager
// resultiert diese size. Wenn wir es nicht so machen, wird ein neues Atom
// zum selben String nochmals erstellt.
QByteArray key = QByteArray::fromRawData( name, ::strlen( name ) + 1 );
quint32 res = 0;
if( type )
res = s_nameToAtom.value( qMakePair( type, key ) );
if( res )
return res;
else
return s_nameToAtom.value( qMakePair( quint32(0), key ) );
}
quint32 TypeDefs::findAtom(Database * db, const char *name, quint32 type)
{
quint32 res = findAtom( name, type );
if( res )
return res;
// unnötig QByteArray key = QByteArray::fromRawData( name, ::strlen( name ) + 1 );
return db->getAtom( name, false );
}
const char* TypeDefs::historyTypeString[] =
{
"unknown",
"createType",
"modifyType",
"deleteType",
"createAttr",
"modifyAttr",
"deleteAttr",
"createObject",
"copyObject",
"modifyObject",
"deleteObject",
"unDeleteObject",
"purgeObject",
"clipCutObject",
"clipMoveObject",
"clipCopyObject",
"createModule",
"baselineModule",
"partitionModule",
"acceptModule",
"returnModule",
"rejoinModule",
"createLink",
"modifyLink",
"deleteLink",
"insertOLE",
"removeOLE",
"changeOLE",
"pasteOLE",
"cutOLE",
"readLocked",
0,
};
const char* TypeDefs::historyTypePrettyString[] =
{
"unknown",
"Create Type",
"Modify Type",
"Delete Type",
"Create Attribute",
"Modify Attribute",
"Delete Attribute",
"Create Object",
"Copy Object",
"Modify Object",
"Delete Object",
"Undelete Object",
"Purge Object",
"Cut Object",
"Move Object",
"Copy Object",
"Create Module",
"Baseline Module",
"Partition Module",
"Accept Module",
"Return Module",
"Rejoin Module",
"Create Link",
"Modify Link",
"Delete Link",
"Insert OLE",
"Remove OLE",
"Change OLE",
"Paste OLE",
"Cut OLE",
"Read Locked",
};
static inline bool _isNull( const QTime& t )
{
return t.hour() == 0 && t.minute() == 0 && t.second() == 0;
}
QString TypeDefs::formatDate( const QDateTime& dt )
{
if( _isNull( dt.time() ) )
return dt.date().toString( Qt::SystemLocaleDate );
else
return dt.toString( Qt::SystemLocaleDate );
}
QString TypeDefs::extractName( const QString& fullName )
{
QStringList l = fullName.split( '/' );
return l.back();
}
QByteArray TypeDefs::getPrettyName( quint32 atom, Sdb::Database* db )
{
if( atom < DsMax )
return getPrettyName( atom );
else if( db )
return db->getAtomString( atom );
else
return "<unknown>";
}
QByteArray TypeDefs::getSimpleName(quint32 atom, Database * db)
{
for( int i = 0; s_names[i].d_id; i++ )
{
if( s_names[i].d_id == atom )
{
return s_names[i].d_name;
}
}
if( db )
return db->getAtomString( atom );
else
return "<unknown>";
}
const char* TypeDefs::getPrettyName( quint32 atom )
{
for( int i = 0; s_names[i].d_id; i++ )
{
if( s_names[i].d_id == atom )
{
if( s_names[i].d_pretty )
return s_names[i].d_pretty;
else
return s_names[i].d_name;
}
}
return "";
}
QString TypeDefs::elided( const Stream::DataCell& v, quint32 len )
{
QString res;
if( v.isNull() )
return "";
if( v.isStr() )
{
res = v.getStr();
res.replace( '\n', ' ' );
res.replace( '\r', "" );
}else if( v.isBml() )
{
Stream::DataReader r( v );
res = r.extractString();
}else
res = v.toPrettyString();
if( len != 0 && res.size() > int(len) )
res = res.left( len - 3 ) + "...";
return res;
}
QString TypeDefs::formatDocName( const Sdb::Obj& doc, bool full )
{
if( doc.isNull() || doc.getType() != TypeDocument )
return "";
QString name = doc.getValue( AttrDocAltName ).toString(true);
if( name.isEmpty() )
name = doc.getValue( AttrDocName ).toString(true);
if( full )
return QObject::tr( "%1 [%2 %3 %4]" ).arg( name ).
arg( doc.getValue( AttrDocVer ).toString(true) ).
arg( (doc.getValue( AttrDocBaseline ).getBool())?
"Baseline":"Current" ).
arg( formatDate( doc.getValue( AttrModifiedOn ).getDateTime() ) );
else
return name;
}
QVariant TypeDefs::prettyValue( const Stream::DataCell& v )
{
// Es wird ein einfacher String ohne Markup erzeugt.
switch( v.getType() )
{
case Stream::DataCell::TypeDateTime:
return TypeDefs::formatDate( v.getDateTime() );
break;
case Stream::DataCell::TypeDate:
return v.getDate().toString( Qt::SystemLocaleDate );
break;
case Stream::DataCell::TypeTime:
return v.getTime().toString( Qt::SystemLocaleDate );
break;
case Stream::DataCell::TypeImg:
{
QImage img;
v.getImage( img );
return QVariant::fromValue( img );
}
break;
case Stream::DataCell::TypeOid:
{
Sdb::Obj obj = AppContext::inst()->getTxn()->getObject(v);
if( obj.isNull() )
return "nil";
else
{
if( obj.hasValue( AttrObjIdent ) )
return obj.getValue( AttrObjIdent ).toString(true);
else if( obj.hasValue( AttrDocId ) )
return obj.getValue( AttrDocId ).toString(true);
else
return getPrettyName( obj.getType() );
}
}
break;
default:
return v.toString(true);
}
return "";
}