• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDECore

kmimeglobsfileparser_p.h

Go to the documentation of this file.
00001 /*  This file is part of the KDE libraries
00002  *  Copyright 2007, 2010 David Faure <faure@kde.org>
00003  *
00004  *  This library is free software; you can redistribute it and/or
00005  *  modify it under the terms of the GNU Library General Public
00006  *  License as published by the Free Software Foundation; either
00007  *  version 2 of the License, or (at your option) any later version.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #ifndef KMIMEGLOBSFILEPARSER_P_H
00021 #define KMIMEGLOBSFILEPARSER_P_H
00022 
00023 #include <kdebug.h>
00024 #include <QtCore/QStringList>
00025 #include <QtCore/QHash>
00026 class QIODevice;
00027 class QString;
00028 
00032 class KMimeGlobsFileParser
00033 {
00034 public:
00035     explicit KMimeGlobsFileParser();
00036 
00037     class AllGlobs;
00038 
00039     // Read globs (patterns) files
00040     AllGlobs parseGlobs();
00041 
00042     // Separate method, for unit test
00043     AllGlobs parseGlobs(const QStringList&);
00044 
00045     struct Glob {
00046         Glob(const QString& mime, int w = 50, const QString& pat = QString(), int _flags = 0)
00047             : weight(w), flags(_flags), pattern(pat), mimeType(mime) {}
00048         int weight;
00049         int flags;
00050         QString pattern;
00051         QString mimeType;
00052     };
00053 
00054     class GlobList : public QList<Glob>
00055     {
00056     public:
00057         bool hasPattern(const QString& mime, const QString& pattern) const {
00058             const_iterator it = begin();
00059             const const_iterator myend = end();
00060             for (; it != myend; ++it)
00061                 if ((*it).pattern == pattern && (*it).mimeType == mime)
00062                     return true;
00063             return false;
00064         }
00065         // "noglobs" is very rare occurence, so it's ok if it's slow
00066         void removeMime(const QString& mime) {
00067             QMutableListIterator<Glob> it(*this);
00068             while (it.hasNext()) {
00069                 if (it.next().mimeType == mime)
00070                     it.remove();
00071             }
00072         }
00073     };
00074 
00075     typedef QHash<QString, QStringList> PatternsMap; // mimetype -> patterns
00076 
00085     class AllGlobs
00086     {
00087     public:
00088         void addGlob(const Glob& glob);
00089         void removeMime(const QString& mime);
00090         PatternsMap patternsMap() const; // for KMimeTypeFactory
00091 
00092         QHash<QString, QStringList> m_fastPatterns; // example: "doc" -> "application/msword", "text/plain"
00093         GlobList m_highWeightGlobs;
00094         GlobList m_lowWeightGlobs; // <= 50, including the non-fast 50 patterns
00095     };
00096     enum Format { OldGlobs, Globs2WithWeight };
00097 
00098     static AllGlobs parseGlobFiles(const QStringList& globFiles, QStringList& parsedFiles);
00099     static bool parseGlobFile(QIODevice* file, Format format, AllGlobs& globs);
00100 
00101 private:
00102     AllGlobs m_mimeTypeGlobs;
00103 };
00104 
00105 #endif /* KMIMEFILEPARSER_H */
00106 

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal