28 #include <QDataStream>
40 #define KLFLIBRESOURCEENGINE_WARN_NO_DEFAULT_SUBRESOURCE(func) \
41 if ((pFeatureFlags & FeatureSubResources) && pDefaultSubResource.isNull()) { \
42 qWarning("KLFLibResourceEngine::" func "(id): sub-resources are supported feature but" \
43 " no default sub-resource is specified!"); } \
55 initRegisteredProperties();
68 initRegisteredProperties();
84 initRegisteredProperties();
107 void KLFLibEntry::initRegisteredProperties()
125 if (s[0] ==
'%' && s[1] ==
':') {
126 return s.
mid(2).trimmed();
128 return QString::null;
134 if (s[0] ==
'%' && s[1] ==
':') {
136 s = latex.
section(
'\n', 1, 1, QString::SectionSkipEmpty);
139 return s.
mid(1).trimmed();
141 return QString::null;
148 while (k < latex.
length() && latex[k].isSpace())
150 if (k == latex.
length())
return "";
151 if (latex[k] ==
'%') {
153 if (k == latex.
length())
return "";
155 if (latex[k] ==
':') {
157 while (k < latex.
length() && latex[k] !=
'\n')
160 if (k >= latex.
length())
return "";
161 if (latex[k] !=
'%') {
166 if (k >= latex.
length())
return "";
169 while (k < latex.
length() && latex[k] !=
'\n')
172 if (k >= latex.
length())
return "";
185 s =
"%: "+category+
"\n";
197 QString c = categoryPath.
trimmed().split(
'/', QString::SkipEmptyParts).join(
"/");
210 : pCloneOf(NULL), pPropId(propId), pOrder(order)
214 : pCloneOf(clone), pPropId(clone->pPropId), pOrder(clone->pOrder)
224 if (pCloneOf != NULL) {
225 qWarning()<<
"Attempt to setPropId() in entry sorter that is a clone of "<<pCloneOf;
232 if (pCloneOf != NULL) {
233 qWarning()<<
"Attempt to setOrder() in entry sorter that is a clone of "<<pCloneOf;
243 if (pCloneOf != NULL)
264 int propId, Qt::SortOrder order)
const
266 if (pCloneOf != NULL)
271 if (order == Qt::AscendingOrder)
278 if (pCloneOf != NULL)
279 return pCloneOf->operator()(a, b);
289 registerEncoder(
this);
296 staticEncoderList.
append(encoder);
301 return staticEncoderList;
309 for (k = 0; k < staticEncoderList.
size(); ++k) {
310 encTypes << staticEncoderList[k]->supportedEncodingMimeTypes();
319 for (k = 0; k < staticEncoderList.
size(); ++k) {
320 decTypes << staticEncoderList[k]->supportedDecodingMimeTypes();
327 const QVariantMap& metaData)
331 for (k = 0; k < staticEncoderList.
size(); ++k) {
332 QStringList mimeTypeList = staticEncoderList[k]->supportedEncodingMimeTypes();
333 for (j = 0; j < mimeTypeList.size(); ++j) {
335 staticEncoderList[k]->encodeMime(entryList, metaData, mimeTypeList[j]);
337 klfDbg(
"Skipping mime type "<<mimeTypeList[k]<<
" because it did not provide any data.");
339 mime->
setData(mimeTypeList[j], data);
352 for (k = 0; k < fmts.size(); ++k) {
362 QVariantMap *metaDataPtr)
366 for (k = 0; k < fmts.size(); ++k) {
370 bool result = decoder->
decodeMime(mimeData->
data(fmts[k]), fmts[k], entryListPtr, metaDataPtr);
384 for (k = 0; k < staticEncoderList.
size(); ++k)
386 return staticEncoderList[k];
388 qWarning()<<
KLF_FUNC_NAME<<
": Failed to find encoder for mime-type "<<mimeType;
396 for (k = 0; k < staticEncoderList.
size(); ++k)
398 return staticEncoderList[k];
400 qWarning()<<
KLF_FUNC_NAME<<
": Failed to find decoder for mime-type "<<mimeType;
419 pFeatureFlags(featureflags), pReadOnly(false), pDefaultSubResource(
QString()),
420 pProgressBlocked(false), pThisOperationProgressBlockedOnly(false)
422 initRegisteredProperties();
428 if (rdonly.size() && rdonly.last() ==
"true") {
436 if (!defaultsubresource.isEmpty()) {
438 pDefaultSubResource = defaultsubresource.last();
447 void KLFLibResourceEngine::initRegisteredProperties()
462 !pDefaultSubResource.
isNull()) {
463 url.
addQueryItem(
"klfDefaultSubResource", pDefaultSubResource);
506 return pDefaultSubResource;
579 pReadOnly = readonly;
586 if (pDefaultSubResource == subResource)
589 pDefaultSubResource = subResource;
621 return entry(pDefaultSubResource,
id);
626 return hasEntry(pDefaultSubResource,
id);
633 return entries(pDefaultSubResource, idList, wantedEntryProperties);
640 return allEntries(pDefaultSubResource, wantedEntryProperties);
645 return allIds(pDefaultSubResource);
650 pProgressBlocked =
true;
651 pThisOperationProgressBlockedOnly =
true;
656 pProgressBlocked = block;
657 pThisOperationProgressBlockedOnly =
false;
662 bool blocked = pProgressBlocked;
663 if (pThisOperationProgressBlockedOnly)
664 pProgressBlocked =
false;
693 return changeEntries(pDefaultSubResource, idlist, properties, values);
819 return stream << entrywid.
id << entrywid.
entry;
823 return stream >> entrywid.
id >> entrywid.
entry;
843 return dbg<<
"EntryMatchCondition{...}";
845 dbg <<
"EntryMatchCondition{type=";
847 return dbg <<
"match-all}";
860 return dbg <<
"unknown-type}";
863 static const char *w_and =
" AND ";
864 static const char *w_or =
" OR ";
865 static const char *w_not =
" NOT ";
868 dbg << (word+1) <<
"; list: ";
871 for (k = 0; k < conditions.size(); ++k) {
874 dbg << conditions[k];
902 for (k = 0; k < idList.
size(); ++k)
903 idList << elist[k].
id;
910 return entry(subResource,
id).latex().size();
919 for (k = 0; k < idList.
size(); ++k)
929 return queryImpl(
this, subResource, query, result);
934 return queryValuesImpl(
this, subResource, entryPropId);
947 }
else if (list->
size() <= skip) {
950 *list = list->
mid(skip);
957 if (list->
size() > limit)
958 *list = list->
mid(0, limit);
972 if (result == NULL) {
973 qWarning()<<
KLF_FUNC_NAME<<
": expected valid `result' pointer";
985 for (k = 0; k < allEList.
size(); ++k) {
1002 klfDbgSt(
"About to return. Number of entries in TEE VALUE.") ;
1009 const QString& subResource,
int entryPropId)
1014 for (k = 0; k < allEList.
size(); ++k) {
1015 QVariant p = allEList[k].entry.property(entryPropId);
1031 switch (condition.
type()) {
1043 qWarning()<<
KLF_FUNC_NAME<<
": NOT condition with no arguments!";
1046 return ! testEntryMatchConditionImpl(condlist[0], libentry);
1051 for (k = 0; k < condlist.
size(); ++k) {
1052 if (testEntryMatchConditionImpl(condlist[k], libentry))
1060 for (k = 0; k < condlist.
size(); ++k) {
1061 if ( ! testEntryMatchConditionImpl(condlist[k], libentry) )
1066 qWarning()<<
KLF_FUNC_NAME<<
": KLFLib::EntryMatchCondition type "<<condition.
type()<<
" not known!";
1074 : mSorter(sorter), mResult(result)
1081 reference_is_rawentrylist =
true;
1083 reference_is_rawentrylist =
false;
1087 reference_is_rawentrylist =
true;
1092 if (reference_is_rawentrylist)
1093 return mResult->rawEntryList.size();
1095 return mResult->entryWithIdList.size();
1107 #define klf_lower_bound_entry \
1108 qLowerBound<KLFLibEntryList::iterator,KLFLibEntry,const KLFLibEntrySorter&>
1109 #define klf_lower_bound_ewid \
1110 qLowerBound<QList<KLFLibEntryWithId>::iterator,KLFLibEntryWithId,const QueryResultListSorter&>
1116 if (mSorter->propId() == -1) {
1118 if (reference_is_rawentrylist)
1119 pos = mResult->rawEntryList.size();
1121 pos = mResult->entryWithIdList.size();
1124 if (reference_is_rawentrylist) {
1127 pos = it - mResult->rawEntryList.begin();
1130 klf_lower_bound_ewid(mResult->entryWithIdList.begin(), mResult->entryWithIdList.end(), ewid, *
this);
1131 pos = it - mResult->entryWithIdList.
begin();
1136 mResult->entryIdList.insert(pos, ewid.
id);
1138 mResult->rawEntryList.insert(pos, ewid.
entry);
1140 mResult->entryWithIdList.insert(pos, ewid);
1194 if ( factory == NULL ) {
1195 qWarning()<<
"KLFLibEngineFactory::openURL("<<url<<
"): No suitable factory found!";
1207 if ( resource == NULL ) {
1208 qWarning()<<
"KLFLibEngineFactory::listSubResources("<<url<<
"): Unable to open resource!";
1212 qWarning()<<
"KLFLibEngineFactory::listSubResources("<<url<<
"): Resource does not support sub-resources!";
1218 for (k = 0; k < subreslist.size(); ++k) {
1220 subresmap[subreslist[k]]
1224 subresmap[subreslist[k]] =
QString();