fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kded / kmimefileparser.h
blobe22a0d55316a63f4aa0b31fb271d207ce0ffa3de
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>
25 class QIODevice;
26 class QString;
27 class KMimeTypeFactory;
29 class KMimeFileParser
31 public:
32 explicit KMimeFileParser( KMimeTypeFactory* mimeTypeFactory );
34 // Read globs (patterns) files
35 void parseGlobs();
37 // Separate method, for unit test
38 void parseGlobs(const QStringList&);
40 struct Glob {
41 Glob(int w = 50, const QString& pat = QString() ) : weight(w), pattern(pat) {}
42 int weight;
43 QString pattern;
45 class GlobList : public QList<Glob>
47 public:
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)
53 return true;
54 return false;
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; }
69 private:
70 KMimeTypeFactory* m_mimeTypeFactory;
71 AllGlobs m_mimeTypeGlobs;
72 QStringList m_allMimeTypes;
75 #endif /* KMIMEFILEPARSER_H */