27 #include <QDataStream>
31 #include <QMessageBox>
32 #include <QApplication>
76 return s <<
"KLFLegacyData::KLFLibraryItem(id="<<item.
id<<
"; latex="<<item.
latex<<
")" ;
81 return s <<
"KLFLegacyData::KLFLibraryResource(id="<<res.
id<<
"; name="<<res.
name<<
")";
107 return stream << item.
id << item.
name;
111 return stream >> item.
id >> item.
name;
156 stream >> style.
name;
191 klfDbg(
"loading from file "<<fname<<
" (our filename="<<filename<<
")") ;
194 if ( ! fimp.
open(QIODevice::ReadOnly) ) {
195 qWarning(
"Unable to open library file %s!", qPrintable(fname));
203 if (s1 ==
"KLATEXFORMULA_LIBRARY_EXPORT") {
207 stream >> vmaj >> vmin;
209 if (!stream.
atEnd() && stream.
status() == QDataStream::Ok)
211 }
else if (s1 ==
"KLATEXFORMULA_LIBRARY") {
215 stream >> vmaj >> vmin;
224 stream >> lib_max_id;
229 if (!stream.
atEnd() && stream.
status() == QDataStream::Ok)
231 }
else if (s1 ==
"KLATEXFORMULA_HISTORY") {
235 stream >> vmaj >> vmin;
238 stream >> lib_max_id >> history;
243 historyresource.
name =
tr(
"History");
246 library[historyresource] = history;
249 qWarning(
"Error: Library file `%s' is invalid library file or corrupt!", qPrintable(fname));
258 for (j = 0; j < ll.
size(); ++j) {
273 <<
" resources (our filename="<<filename<<
")") ;
275 if ( ! fsav.open(QIODevice::WriteOnly) ) {
276 qWarning(
"Can't write to file %s!", qPrintable(fname));
314 qWarning(
"%s: Saving an old \"history\" resource. Only one resource can be saved, "
317 tr(
"Saving an old \"history\" resource. Only one resource can be saved, "
318 "it will be the first: %1").arg(
resources[0].name));
321 stream <<
QString(
"KLATEXFORMULA_HISTORY") << (qint16)2 << (qint16)0
327 stream <<
QString(
"KLATEXFORMULA_LIBRARY") << (qint16)2 << (qint16)1;
339 qWarning(
"%s: bad library type %d! Falling back to '.klf'-library-export type",
343 stream <<
QString(
"KLATEXFORMULA_LIBRARY_EXPORT") << (qint16)2 << (qint16)1
353 klfDbg(
"in first resource wrote "<<llll.
size()<<
" items.");
370 !
QString::compare(resname, qApp->translate(
"KLFMainWin",
"History"), Qt::CaseInsensitive) )
375 !
QString::compare(resname, qApp->translate(
"KLFMainWin",
"Archive"), Qt::CaseInsensitive) )
404 klfDbgSt(
"Requested empty fname.") ;
408 qWarning(
"%s: file %s does not exist!",
KLF_FUNC_NAME, qPrintable(fname));
412 if (url.
scheme() !=
"klf+legacy") {
413 qWarning(
"KLFLibLegacyEngine::openUrl(): unsupported scheme %s!", qPrintable(url.
scheme()));
430 QString lrname = legacyResourceName;
437 qWarning()<<
KLF_FUNC_NAME<<
": file name "<<fileName<<
" is empty!";
449 lrname =
tr(
"Default Resource");
452 klfDbgSt(
"fileName="<<fileName<<
"; canonical file path="<<
QFileInfo(fileName).canonicalFilePath()
453 <<
"; legacyResourceName="<<legacyResourceName);
460 KLFLibLegacyEngine::KLFLibLegacyEngine(
const QString& fileName,
const QString& resname,
const QUrl& url,
467 qWarning()<<
KLF_FUNC_NAME<<
": Couldn't get KLFLibLegacyFileDataPrivate instance for "<<fileName<<
"! Expect Crash!";
489 klfDbg(
"Opened KLFLibLegacyEngine resource `"<<fileName<<
"': d="<<d<<
"; resources="<<d->
resources
490 <<
" (me="<<
this<<
", d="<<d<<
")\n") ;
499 if ( ! d->
deref() ) {
500 klfDbg(
"last reference to the private liblegacyenginedataprivate object d="<<d<<
", "
501 "saving(?) and deleting. haschanges="<<d->
haschanges) ;
521 klfDbg(
"base cannot modify resource engine...") ;
563 for (k = 0; k < ll.
size() && ll[k].id != (quint32)
id; ++k)
565 if (k == ll.
size()) {
586 for (k = 0; k < ll.
size(); ++k) {
638 qWarning()<<
KLF_FUNC_NAME<<
"("<<subResource<<
",..): no new ID could be found (!?!)";
642 res.
name = subResource;
659 qWarning()<<
KLF_FUNC_NAME<<
": can't find sub-resource "<<subResource<<
" in our data.";
667 resref.
name = subResourceNewName;
671 if (possibleNewId != -1)
672 resref.
id = possibleNewId;
684 klfDbg(
"sub-resource: "<<subResource) ;
688 klfDbg(
"Cannot delete sub-resource "<<subResource) ;
693 qWarning()<<
KLF_FUNC_NAME<<
": can't find sub-resource "<<subResource<<
" in our data.";
712 qWarning(
"KLFLibLegacyEngine::save: resource is read-only!");
723 if (intervalms > 0) {
732 klfDbg(
"subResource="<<subResource<<
"; entrylist="<<entrylist) ;
736 if ( entrylist.
size() == 0 )
739 klfDbg(
"cannot modify data.") ;
745 klfDbg(
"cannot find sub-resource: "<<subResource) ;
752 for (k = 0; k < entrylist.
size(); ++k) {
761 klfDbg(
"finished inserting items. d="<<d<<
"; dumping resources:\n"<<d->
resources
762 <<
"\nand library:\n"<<d->
library) ;
770 if (idlist.
size() == 0)
786 for (k = 0; k < idlist.
size(); ++k) {
790 for (libindex = 0; libindex < ll.
size() && ll[libindex].id != (quint32)idlist[k]; ++libindex)
792 if (libindex == ll.
size()) {
793 qWarning()<<
KLF_FUNC_NAME<<
": Can't find entry with id "<<idlist[k];
798 for (j = 0; j < properties.
size(); ++j) {
799 switch (properties[j]) {
809 d->
library[d->
resources[index]][libindex].datetime = values[j].toDateTime();
818 QString newcategory = values[j].toString();
830 QString newtags = values[j].toString();
850 klfDbg(
": Changed entries. Dump:" ) ;
853 for (kl = 0; kl < ll2.
size(); ++kl)
854 klfDbg(
"\t#"<<kl<<
": "<<ll2[kl].latex<<
" - "<<ll2[kl].category ) ;
882 for (k = 0; k < idlist.
size(); ++k) {
884 for (j = 0; j < ll->
size() && ll->operator[](j).
id != (quint32)idlist[k]; ++j)
886 if (j == ll->
size()) {
887 qWarning(
"KLFLibLegacyEngine::deleteEntries: Can't find ID %d in library list in current resource.",
907 if (newPath.
scheme() ==
"klf+legacy") {
917 QVariantMap m = d->
metadata[
"ResProps"].toMap();
923 if (m.contains(propName) && m[propName] == value)
939 klfDbg(
"property id="<<propId) ;
968 klfDbg(
"file "<<fileName);
971 klfDbg(
"has .klf extension.") ;
976 if ( ! f.
open(QIODevice::ReadOnly) ) {
985 klfDbg(
"read line: got magic "<<s1);
1016 return tr(
"KLatexFormula Library Export File");
1045 QString defsubres = parameters[
"klfDefaultSubResource"].toString();
1050 if ( !parameters.
contains(
"Filename") ) {
1052 <<
"KLFLibLegacyEngineFactory::createResource: bad parameters. They do not contain `Filename': "
1059 qWarning()<<
"KLFLibLegacyEngineFactory::createResource("<<scheme<<
","<<parameters<<
","<<parent<<
"):"