~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/modules/kjofol-skin/parser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "parser.h"
 
2
#include <kurl.h>
 
3
#include <qtextstream.h>
 
4
#include <qimage.h>
 
5
#include <noatunapp.h>
 
6
#include "kjprefs.h"
 
7
 
 
8
Parser::Parser()
 
9
{
 
10
        mImageCache.setAutoDelete(true);
 
11
        setAutoDelete(true);
 
12
}
 
13
 
 
14
void Parser::conserveMemory()
 
15
{
 
16
        mImageCache.clear();
 
17
}
 
18
 
 
19
void Parser::open(const QString &file)
 
20
{
 
21
        clear();
 
22
        mImageCache.clear();
 
23
        mDir=KURL(file).directory();
 
24
        QFile f(file);
 
25
        f.open(IO_ReadOnly);
 
26
 
 
27
        f.at(0);
 
28
        QTextStream stream(&f);
 
29
        while (!stream.eof())
 
30
        {
 
31
                QString line=stream.readLine();
 
32
                line=line.simplifyWhiteSpace();
 
33
                if ((!line.length()) || line[0]=='#')
 
34
                        continue;
 
35
                QStringList *l=new QStringList(QStringList::split(" ", line));
 
36
                QString first=l->first();       
 
37
                insert(first, l);       
 
38
        }
 
39
}
 
40
 
 
41
QString Parser::fileItem(const QString &i) const
 
42
{
 
43
        return dir()+'/'+i;
 
44
}
 
45
 
 
46
QString Parser::dir() const
 
47
{
 
48
        return mDir;
 
49
}
 
50
 
 
51
Parser::ImagePixmap* Parser::getPair(const QString &filenameOld) const
 
52
{
 
53
        // is it in there?
 
54
        ImagePixmap *pair;
 
55
        {
 
56
                pair=mImageCache.find(filenameOld);
 
57
                if (pair)
 
58
                        return pair;
 
59
        }
 
60
        
 
61
        QString filename=fileItem(filenameOld);
 
62
 
 
63
        QImage image;
 
64
 
 
65
        if (filename.right(4).lower()!=".png")
 
66
                image=QImage(filenameNoCase(filename));
 
67
        else
 
68
                image=NoatunApp::readPNG(filenameNoCase(filename));
 
69
 
 
70
        //add to the cache
 
71
        QPixmap pixmap;
 
72
        pixmap.convertFromImage(image, QPixmap::AutoColor|QPixmap::ThresholdDither|QPixmap::AvoidDither);
 
73
        pair=new Parser::ImagePixmap;
 
74
        pair->mImage=image;
 
75
        pair->mPixmap=pixmap;
 
76
        mImageCache.insert(filenameOld, pair);
 
77
        return pair;
 
78
}
 
79
 
 
80
bool Parser::exist(const QString &i) const
 
81
{
 
82
        return (bool)find(i);
 
83
}
 
84
 
 
85