• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

kmimetypefactory.h

Go to the documentation of this file.
00001 /*  This file is part of the KDE libraries
00002  *  Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
00003  *  Copyright (C) 2006-2007 David Faure <faure@kde.org>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation;
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 KMIMETYPEFACTORY_H
00021 #define KMIMETYPEFACTORY_H
00022 
00023 #include <assert.h>
00024 
00025 #include <QtCore/QStringList>
00026 
00027 #include "ksycocafactory.h"
00028 #include "kmimetype.h"
00029 #include "kmimemagicrule_p.h"
00030 
00031 class KSycoca;
00032 
00041 class KDECORE_EXPORT KMimeTypeFactory : public KSycocaFactory
00042 {
00043     K_SYCOCAFACTORY( KST_KMimeTypeFactory )
00044 public:
00048     KMimeTypeFactory();
00049 
00050     virtual ~KMimeTypeFactory();
00051 
00055     virtual KSycocaEntry *createEntry(const QString &, const char *) const
00056     { assert(0); return 0; }
00057 
00062     virtual KMimeType::Ptr findMimeTypeByName(const QString &_name, KMimeType::FindByNameOption options = KMimeType::DontResolveAlias);
00063 
00067     QString resolveAlias(const QString& mime) const;
00068 
00072     QStringList parents(const QString& mime);
00073 
00074 private: // only for KMimeType
00075     friend class KMimeType;
00076     friend class KMimeFileParserTest;
00077 
00085     QList<KMimeType::Ptr> findFromFileName(const QString &filename, QString *matchingExtension = 0);
00086 
00087     enum WhichPriority { LowPriorityRules, HighPriorityRules, AllRules };
00097     KMimeType::Ptr findFromContent(QIODevice* device, WhichPriority whichPriority, int* accuracy, QByteArray& beginning);
00098 
00103     bool checkMimeTypes();
00104 
00105 protected:
00106     typedef QHash<QString, QString> AliasesMap;
00110     AliasesMap& aliases() { return m_aliases; }
00111 
00112     typedef QHash<QString, QStringList> ParentsMap;
00116     ParentsMap& parentsMap() { return m_parents; }
00117 
00118 public:
00123     KMimeType::List allMimeTypes();
00124 
00128     static KMimeTypeFactory * self();
00129 
00133     QList<KMimeMagicRule> parseMagicFile(QIODevice* file, const QString& fileName) const;
00134 
00138     static bool matchFileName( const QString &filename, const QString &pattern );
00139 
00140 protected:
00141     virtual KMimeType *createEntry(int offset) const;
00142 
00143 protected: // accessed by KBuildMimeTypeFactory
00145     int m_fastPatternOffset;
00147     int m_highWeightPatternOffset;
00149     int m_lowWeightPatternOffset;
00151     int m_parentsMapOffset;
00152 
00153     KSycocaDict* m_fastPatternDict;
00154 
00155     struct OtherPattern
00156     {
00157         OtherPattern(const QString& pat, qint32 off, qint32 w)
00158             : pattern(pat), offset(off), weight(w) {}
00159         QString pattern;
00160         qint32 offset;
00161         qint32 weight;
00162     };
00163     typedef QList<OtherPattern> OtherPatternList;
00164 
00165 private:
00166     // Read magic files
00167     void parseMagic();
00168 
00169     QList<KMimeType::Ptr> findFromFileNameHelper(const QString &filename, QString *matchingExtension);
00170     QList<KMimeType::Ptr> findFromFastPatternDict(const QString &extension);
00180     void findFromOtherPatternList(QList<KMimeType::Ptr>& matchingMimeTypes,
00181                                   const QString &filename,
00182                                   QString& foundExt,
00183                                   bool highWeight);
00184 
00185     OtherPatternList m_highWeightPatterns;
00186     OtherPatternList m_lowWeightPatterns;
00187 
00188     AliasesMap m_aliases; // alias -> canonicalName
00189     ParentsMap m_parents;
00190 
00191     bool m_highWeightPatternsLoaded;
00192     bool m_lowWeightPatternsLoaded;
00193     bool m_parentsMapLoaded;
00194     bool m_magicFilesParsed;
00195     QList<KMimeMagicRule> m_magicRules;
00196 
00197 private:
00198     // d pointer: useless since this header is not installed
00199     //class KMimeTypeFactoryPrivate* d;
00200 };
00201 
00202 #endif

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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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