From e38d2351b83fa65c66ccde443777647ef5cb6cff Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 1 Mar 2010 19:17:32 +0000 Subject: Added KDE3 version of Tellico git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/translators/referencerimporter.cpp | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/translators/referencerimporter.cpp (limited to 'src/translators/referencerimporter.cpp') diff --git a/src/translators/referencerimporter.cpp b/src/translators/referencerimporter.cpp new file mode 100644 index 0000000..32ba251 --- /dev/null +++ b/src/translators/referencerimporter.cpp @@ -0,0 +1,71 @@ +/*************************************************************************** + copyright : (C) 2007 by Robby Stephenson + email : robby@periapsis.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of version 2 of the GNU General Public License as * + * published by the Free Software Foundation; * + * * + ***************************************************************************/ + +#include "referencerimporter.h" +#include "../collection.h" +#include "../core/netaccess.h" +#include "../imagefactory.h" + +#include + +using Tellico::Import::ReferencerImporter; + +ReferencerImporter::ReferencerImporter(const KURL& url_) : XSLTImporter(url_) { + QString xsltFile = locate("appdata", QString::fromLatin1("referencer2tellico.xsl")); + if(!xsltFile.isEmpty()) { + KURL u; + u.setPath(xsltFile); + XSLTImporter::setXSLTURL(u); + } else { + kdWarning() << "ReferencerImporter() - unable to find referencer2tellico.xml!" << endl; + } +} + +bool ReferencerImporter::canImport(int type) const { + return type == Data::Collection::Bibtex; +} + +Tellico::Data::CollPtr ReferencerImporter::collection() { + Data::CollPtr coll = XSLTImporter::collection(); + if(!coll) { + return 0; + } + + Data::FieldPtr field = coll->fieldByName(QString::fromLatin1("cover")); + if(!field && !coll->imageFields().isEmpty()) { + field = coll->imageFields().front(); + } else if(!field) { + field = new Data::Field(QString::fromLatin1("cover"), i18n("Front Cover"), Data::Field::Image); + coll->addField(field); + } + + Data::EntryVec entries = coll->entries(); + for(Data::EntryVecIt entry = entries.begin(); entry != entries.end(); ++entry) { + QString url = entry->field(QString::fromLatin1("url")); + if(url.isEmpty()) { + continue; + } + QPixmap pix = NetAccess::filePreview(url); + if(pix.isNull()) { + continue; + } + QString id = ImageFactory::addImage(pix, QString::fromLatin1("PNG")); + if(id.isEmpty()) { + continue; + } + entry->setField(field, id); + } + return coll; +} + +#include "referencerimporter.moc" -- cgit v1.2.1