-rw-r--r-- | library/mimetype.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/library/mimetype.cpp b/library/mimetype.cpp index c6a4453..9fab160 100644 --- a/library/mimetype.cpp +++ b/library/mimetype.cpp | |||
@@ -15,12 +15,13 @@ | |||
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_MIMEEXT | ||
21 | #include "mimetype.h" | 22 | #include "mimetype.h" |
22 | #include "applnk.h" | 23 | #include "applnk.h" |
23 | #include "resource.h" | 24 | #include "resource.h" |
24 | #include "qpeapplication.h" | 25 | #include "qpeapplication.h" |
25 | #include <qfile.h> | 26 | #include <qfile.h> |
26 | #include <qdict.h> | 27 | #include <qdict.h> |
@@ -43,12 +44,13 @@ public: | |||
43 | QImage unscaledIcon = Resource::loadImage( icon ); | 44 | QImage unscaledIcon = Resource::loadImage( icon ); |
44 | regIcon.convertFromImage( unscaledIcon.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); | 45 | regIcon.convertFromImage( unscaledIcon.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); |
45 | bigIcon.convertFromImage( unscaledIcon.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ) ); | 46 | bigIcon.convertFromImage( unscaledIcon.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ) ); |
46 | } | 47 | } |
47 | } | 48 | } |
48 | QString id; | 49 | QString id; |
50 | QString extension; | ||
49 | QString desc; | 51 | QString desc; |
50 | QPixmap regIcon; | 52 | QPixmap regIcon; |
51 | QPixmap bigIcon; | 53 | QPixmap bigIcon; |
52 | AppLnk app; | 54 | AppLnk app; |
53 | }; | 55 | }; |
54 | 56 | ||
@@ -56,12 +58,13 @@ class MimeType::Dict : public QDict<MimeTypeData> { | |||
56 | public: | 58 | public: |
57 | Dict() {} | 59 | Dict() {} |
58 | }; | 60 | }; |
59 | 61 | ||
60 | MimeType::Dict* MimeType::d=0; | 62 | MimeType::Dict* MimeType::d=0; |
61 | static QMap<QString,QString> *typeFor = 0; | 63 | static QMap<QString,QString> *typeFor = 0; |
64 | static QMap<QString,QString> *extFor = 0; | ||
62 | 65 | ||
63 | MimeType::Dict& MimeType::dict() | 66 | MimeType::Dict& MimeType::dict() |
64 | { | 67 | { |
65 | if ( !d ) { | 68 | if ( !d ) { |
66 | d = new Dict; | 69 | d = new Dict; |
67 | d->setAutoDelete(TRUE); | 70 | d->setAutoDelete(TRUE); |
@@ -93,12 +96,18 @@ QString MimeType::description() const | |||
93 | QPixmap MimeType::pixmap() const | 96 | QPixmap MimeType::pixmap() const |
94 | { | 97 | { |
95 | MimeTypeData* d = data(i); | 98 | MimeTypeData* d = data(i); |
96 | return d ? d->regIcon : QPixmap(); | 99 | return d ? d->regIcon : QPixmap(); |
97 | } | 100 | } |
98 | 101 | ||
102 | QString MimeType::extension() const | ||
103 | { | ||
104 | loadExtensions(); | ||
105 | return *(*extFor).find(i); | ||
106 | } | ||
107 | |||
99 | QPixmap MimeType::bigPixmap() const | 108 | QPixmap MimeType::bigPixmap() const |
100 | { | 109 | { |
101 | MimeTypeData* d = data(i); | 110 | MimeTypeData* d = data(i); |
102 | return d ? d->bigIcon : QPixmap(); | 111 | return d ? d->bigIcon : QPixmap(); |
103 | } | 112 | } |
104 | 113 | ||
@@ -125,12 +134,13 @@ void MimeType::clear() | |||
125 | d = 0; | 134 | d = 0; |
126 | } | 135 | } |
127 | 136 | ||
128 | void MimeType::loadExtensions() | 137 | void MimeType::loadExtensions() |
129 | { | 138 | { |
130 | if ( !typeFor ) { | 139 | if ( !typeFor ) { |
140 | extFor = new QMap<QString,QString>; | ||
131 | typeFor = new QMap<QString,QString>; | 141 | typeFor = new QMap<QString,QString>; |
132 | loadExtensions("/etc/mime.types"); | 142 | loadExtensions("/etc/mime.types"); |
133 | loadExtensions(QPEApplication::qpeDir()+"etc/mime.types"); | 143 | loadExtensions(QPEApplication::qpeDir()+"etc/mime.types"); |
134 | } | 144 | } |
135 | } | 145 | } |
136 | 146 | ||
@@ -142,15 +152,18 @@ void MimeType::loadExtensions(const QString& filename) | |||
142 | QRegExp space("[ \t]+"); | 152 | QRegExp space("[ \t]+"); |
143 | while (!in.atEnd()) { | 153 | while (!in.atEnd()) { |
144 | QStringList tokens = QStringList::split(space, in.readLine()); | 154 | QStringList tokens = QStringList::split(space, in.readLine()); |
145 | QStringList::ConstIterator it = tokens.begin(); | 155 | QStringList::ConstIterator it = tokens.begin(); |
146 | if ( it != tokens.end() ) { | 156 | if ( it != tokens.end() ) { |
147 | QString id = *it; ++it; | 157 | QString id = *it; ++it; |
148 | while (it != tokens.end()) { | 158 | if ( it != tokens.end() ) { |
149 | (*typeFor)[*it] = id; | 159 | (*extFor)[id] = *it; |
150 | ++it; | 160 | while (it != tokens.end()) { |
161 | (*typeFor)[*it] = id; | ||
162 | ++it; | ||
163 | } | ||
151 | } | 164 | } |
152 | } | 165 | } |
153 | } | 166 | } |
154 | } | 167 | } |
155 | } | 168 | } |
156 | 169 | ||