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<<
"):"
virtual ~KLFLibLegacyEngine()
static QString categoryFromLatex(const QString &latex)
static KLFLegacyData::KLFStyle toLegacyStyle(const KLFStyle &style)
QList< KLFLibraryResource > KLFLibraryResourceList
void updateResourceProperty(int propId)
virtual bool canDeleteSubResource(const QString &subResource) const
int findResourceName(const QString &resname)
push_back(const T &value)
virtual QStringList subResourceList() const
static KLFLibEntry toLibEntry(const KLFLegacyData::KLFLibraryItem &item)
KLF_EXPORT uint klfUrlCompare(const QUrl &url1, const QUrl &url2, uint interestFlags, const QStringList &interestQueryItems)
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
virtual bool createSubResource(const QString &subResource, const QString &subResourceTitle)
virtual void setProperty(const QString &propname, const QVariant &value)
#define klfDbg(streamableItems)
void subResourceRenamed(const QString &oldSubResourceName, const QString &newSubResourceName)
Emitted when a sub-resource is renamed.
fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
#define KLF_DEBUG_BLOCK(msg)
LegacyLibType legacyLibType
static QString stripCategoryTagsFromLatex(const QString &latex)
virtual bool saveTo(const QUrl &newPath)
virtual bool deleteSubResource(const QString &subResource)
KLFLegacyData::KLFStyle style
hasQueryItem(const QString &key)
static QString tagsFromLatex(const QString &latex)
tr(const char *sourceText, const char *comment=0, int n=-1)
virtual KLFLibEntry entry(const QString &resource, entryId id)
bool load(const QString &fname=QString())
virtual uint compareUrlTo(const QUrl &other, uint interestFlags=0xfffffff) const
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
The Latex Code of the equation.
virtual QString toString(uint toStringFlags=0) const
virtual bool isReadOnly() const
query read-only state
void dataChanged(const QString &subResource, int modificationType, const QList< KLFLib::entryId > &entryIdList)
Emitted when data has changed.
QDebug & operator<<(QDebug &s, const KLFLegacyData::KLFLibraryItem &item)
virtual bool deleteEntries(const QString &subResource, const QList< entryId > &idlist)
void subResourceCreated(const QString &newSubResource)
Emitted when a sub-resource is created.
KLF_EXPORT QString klfUrlLocalFilePath(const QUrl &url)
void subResourceDeleted(const QString &subResource)
Emitted when a sub-resource is deleted.
static KLFLibLegacyFileDataPrivate * instanceFor(const QString fname, bool starttimer)
void resourcePropertyChanged(int propId)
Emitted when a resource property changes.
The Legacy Library support for the KLFLib framework.
KLFLibLegacyEngineFactory(QObject *parent=NULL)
startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive)
setScheme(const QString &scheme)
KLFLegacyData::KLFLibrary library
endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive)
compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
static KLFLegacyData::KLFLibraryItem toLegacyLibItem(const KLFLibEntry &entry)
virtual QString schemeTitle(const QString &scheme) const
virtual QList< KLFLibEntryWithId > allEntries(const QString &resource, const QList< int > &wantedEntryProperties=QList< int >())
void emitResourcePropertyChanged(int propId)
KLF_EXPORT bool operator<(const KLFLegacyData::KLFLibraryResource a, const KLFLegacyData::KLFLibraryResource b)
The Category to which eq. belongs (path-style string)
static QString canonicalFilePath(const QString &fname)
#define KLF_DEBUG_TIME_BLOCK(msg)
virtual bool canModifyProp(int propid) const
virtual bool changeEntries(const QString &subResource, const QList< entryId > &idlist, const QList< int > &properties, const QList< QVariant > &values)
static QString latexAddCategoryTagsComment(const QString &latex, const QString &category, const QString &tags)
virtual bool canModifyData(const QString &subResource, ModifyType modifytype) const
Tags about the equation (string)
virtual bool saveResourceProperty(int propId, const QVariant &value)
fromValue(const T &value)
virtual QString correspondingWidgetType(const QString &scheme) const
Provides a simple API for reading library resources.
virtual QStringList supportedTypes() const
static KLFLibLegacyEngine * openUrl(const QUrl &url, QObject *parent=NULL)
QMap< KLFLibraryResource, KLFLibraryList > KLFLibrary
KLF_EXPORT bool operator==(const KLFLegacyData::KLFLibraryItem &a, const KLFLegacyData::KLFLibraryItem &b)
virtual QList< entryId > insertEntries(const QString &subResource, const KLFLibEntryList &entries)
KLFLegacyData::KLFLibraryResourceList resources
virtual KLFLibResourceEngine * createResource(const QString &scheme, const Parameters ¶meters, QObject *parent=NULL)
An entry (single formula) in the library.
QString guessScheme(const QString &fileName) const
virtual bool hasSubResource(const QString &subResource) const
virtual bool renameSubResource(const QString &subResource, const QString &subResourceName)
#define klfDbgSt(streamableItems)
An Image Preview of equation (scaled down QImage)
virtual uint schemeFunctions(const QString &scheme) const
critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void setAllProperties(const QMap< QString, QVariant > &propValues)
addQueryItem(const QString &key, const QString &value)
warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
virtual QVariant property(const QString &propName) const
A KLFLibEntry in combination with a KLFLib::entryId.
virtual QUrl url(uint flags=0x0) const
query URL
virtual bool canRegisterProperty(const QString &propName) const
virtual bool canModifyData(const QString &subRes, ModifyType modifytype) const
An abstract resource engine.
virtual bool canRenameSubResource(const QString &subResource) const
QString propertyNameForId(int propId) const
The Date/Time at which the equation was evaluated.
virtual bool canCreateSubResource() const
connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type=Qt::AutoCompatConnection)
virtual void setAutoSaveInterval(int intervalms)
KLF_EXPORT QDataStream & operator>>(QDataStream &stream, KLFLegacyData::KLFLibraryItem &item)
QList< KLFLibraryItem > KLFLibraryList
bool save(const QString &fname=QString())
virtual bool canModifyProp(int propId) const
queryItemValue(const QString &key)
localeAwareCompare(const QString &s1, const QString &s2)
int getReservedResourceId(const QString &resourceName, int defaultId)
KLF_EXPORT bool resources_equal_for_import(const KLFLegacyData::KLFLibraryResource a, const KLFLegacyData::KLFLibraryResource b)
static KLFLibLegacyEngine * createDotKLF(const QString &fileName, QString legacyResourceName, QObject *parent=NULL)
fromLocalFile(const QString &localFile)
virtual KLFLibResourceEngine * openResource(const QUrl &location, QObject *parent=NULL)