From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- noatun/modules/kjofol-skin/parser.cpp | 132 ++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 noatun/modules/kjofol-skin/parser.cpp (limited to 'noatun/modules/kjofol-skin/parser.cpp') diff --git a/noatun/modules/kjofol-skin/parser.cpp b/noatun/modules/kjofol-skin/parser.cpp new file mode 100644 index 00000000..df5fdc40 --- /dev/null +++ b/noatun/modules/kjofol-skin/parser.cpp @@ -0,0 +1,132 @@ +/*************************************************************************** + parser.cpp - Reads *.rc files in kjöfol-config-format into a QDict + -------------------------------------- + Maintainer: Stefan Gehn + + ***************************************************************************/ + +// local includes +#include "parser.h" +#include "kjprefs.h" + +// system includes +#include +#include +#include +#include +#include +#include + +Parser::Parser() : QDict(17,false) +{ + mSkinAbout=""; + mImageCache.setAutoDelete(true); + setAutoDelete(true); +} + +void Parser::conserveMemory() +{ + mImageCache.clear(); +} + +void Parser::open(const QString &file) +{ + clear(); + mImageCache.clear(); + mSkinAbout=""; + mDir=KURL(file).directory(); + QFile f(file); + if ( !f.exists() ) + return; + f.open(IO_ReadOnly); + + f.at(0); + QTextStream stream(&f); + while (!stream.eof()) + { + QString line=stream.readLine(); + line=line.simplifyWhiteSpace(); + if ((!line.length()) || line[0]=='#') + continue; + QStringList *l=new QStringList(QStringList::split(" ", (line.lower()))); + QString first=l->first(); + + // special handling for about-texts as the key "about" can appear multiple + // times and thus does not fit into qdict. + if (first=="about") + { + if (!mSkinAbout.isEmpty()) + mSkinAbout+="\n"; + + mSkinAbout += line.mid(6); +// kdDebug(66666) << "found About-line, mSkinAbout is now '" << mSkinAbout << "'" << endl; + delete l; // don't need the stringlist anymore + } + else + insert(first, l); + } +} + +QString Parser::fileItem(const QString &i) const +{ + return dir()+'/'+i; +} + +QString Parser::dir() const +{ + return mDir; +} + +Parser::ImagePixmap* Parser::getPair(const QString &filenameOld) const +{ + // is it in there? + ImagePixmap *pair; + { + pair=mImageCache.find(filenameOld); + if (pair) + return pair; + } + + QString filename=fileItem(filenameOld); + + QImage image; + + // Determine file-format trough mimetype (no stupid .ext test) + KMimeMagicResult * result = KMimeMagic::self()->findFileType( filename ); + + if ( result->mimeType() == "image/png" ) + { +// image = NoatunApp::readPNG(filenameNoCase(filename)); + QImageIO iio; + iio.setFileName( filenameNoCase(filename) ); + // forget about gamma-value, fix for broken PNGs + iio.setGamma( 0.00000001 ); + if ( iio.read() ) + { + image = iio.image(); + image.setAlphaBuffer(false); // we don't want/support alpha-channels + } + else + { + kdDebug(66666) << "Could not load file: " << filename.latin1() << endl; + } + } + else + { + image = QImage(filenameNoCase(filename)); + } + + //add to the cache + QPixmap pixmap; + pixmap.convertFromImage(image, QPixmap::AutoColor|QPixmap::ThresholdDither|QPixmap::AvoidDither); + pair = new Parser::ImagePixmap; + pair->mImage = image; + pair->mPixmap = pixmap; + mImageCache.insert(filenameOld, pair); + return pair; +} + +bool Parser::exist(const QString &i) const +{ + return (bool)find(i); +} -- cgit v1.2.1