1 /* This file is part of the KDE libraries
2 * Copyright 2007 David Faure <faure@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef KDED_KMIMEFILEPARSER_H
21 #define KDED_KMIMEFILEPARSER_H
23 #include <QtCore/QStringList>
24 #include <QtCore/QHash>
27 class KMimeTypeFactory
;
32 explicit KMimeFileParser( KMimeTypeFactory
* mimeTypeFactory
);
34 // Read globs (patterns) files
37 // Separate method, for unit test
38 void parseGlobs(const QStringList
&);
41 Glob(int w
= 50, const QString
& pat
= QString() ) : weight(w
), pattern(pat
) {}
45 class GlobList
: public QList
<Glob
>
48 bool containsPattern(const QString
& pattern
) const {
49 const_iterator it
= begin();
50 const const_iterator myend
= end();
51 for (; it
!= myend
; ++it
)
52 if ((*it
).pattern
== pattern
)
57 enum Format
{ OldGlobs
, Globs2WithWeight
};
59 typedef QHash
<QString
, GlobList
> AllGlobs
;
60 typedef QHashIterator
<QString
, GlobList
> AllGlobsIterator
;
62 static AllGlobs
parseGlobFiles(const QStringList
& globFiles
, QStringList
& parsedFiles
);
63 static AllGlobs
parseGlobFile(QIODevice
* file
, Format format
);
65 // Retrieve the result of the parsing
66 const AllGlobs
& mimeTypeGlobs() const { return m_mimeTypeGlobs
; }
67 const QStringList
& allMimeTypes() const { return m_allMimeTypes
; }
70 KMimeTypeFactory
* m_mimeTypeFactory
;
71 AllGlobs m_mimeTypeGlobs
;
72 QStringList m_allMimeTypes
;
75 #endif /* KMIMEFILEPARSER_H */