summaryrefslogtreecommitdiff
path: root/library/mimetype.cpp
Unidiff
Diffstat (limited to 'library/mimetype.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/mimetype.cpp13
1 files changed, 13 insertions, 0 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> {
56public: 58public:
57 Dict() {} 59 Dict() {}
58}; 60};
59 61
60MimeType::Dict* MimeType::d=0; 62MimeType::Dict* MimeType::d=0;
61static QMap<QString,QString> *typeFor = 0; 63static QMap<QString,QString> *typeFor = 0;
64static QMap<QString,QString> *extFor = 0;
62 65
63MimeType::Dict& MimeType::dict() 66MimeType::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
93QPixmap MimeType::pixmap() const 96QPixmap 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
102QString MimeType::extension() const
103{
104 loadExtensions();
105 return *(*extFor).find(i);
106}
107
99QPixmap MimeType::bigPixmap() const 108QPixmap 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
128void MimeType::loadExtensions() 137void 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,20 +152,23 @@ 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;
158 if ( it != tokens.end() ) {
159 (*extFor)[id] = *it;
148 while (it != tokens.end()) { 160 while (it != tokens.end()) {
149 (*typeFor)[*it] = id; 161 (*typeFor)[*it] = id;
150 ++it; 162 ++it;
151 } 163 }
152 } 164 }
153 } 165 }
154 } 166 }
155} 167}
168}
156 169
157void MimeType::init( const QString& ext_or_id ) 170void MimeType::init( const QString& ext_or_id )
158{ 171{
159 if ( ext_or_id[0] != '/' && ext_or_id.contains('/') ) { 172 if ( ext_or_id[0] != '/' && ext_or_id.contains('/') ) {
160 i = ext_or_id.lower(); 173 i = ext_or_id.lower();
161 } else { 174 } else {