• Skip to content
  • Skip to link menu
KDE 4.2 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 
00069 private: // only for KMimeType
00070     friend class KMimeType;
00071     friend class KMimeFileParserTest;
00072 
00080     QList<KMimeType::Ptr> findFromFileName(const QString &filename, QString *matchingExtension = 0);
00081 
00082     enum WhichPriority { LowPriorityRules, HighPriorityRules, AllRules };
00092     KMimeType::Ptr findFromContent(QIODevice* device, WhichPriority whichPriority, int* accuracy, QByteArray& beginning);
00093 
00098     bool checkMimeTypes();
00099 
00100 protected:
00104     QMap<QString, QString>& aliases();
00105 
00106 public:
00111     KMimeType::List allMimeTypes();
00112 
00116     static KMimeTypeFactory * self();
00117 
00121     QList<KMimeMagicRule> parseMagicFile(QIODevice* file, const QString& fileName) const;
00122 
00126     static bool matchFileName( const QString &filename, const QString &pattern );
00127 
00128 protected:
00129     virtual KMimeType *createEntry(int offset) const;
00130 
00131 protected: // accessed by KBuildMimeTypeFactory
00133     int m_fastPatternOffset;
00135     int m_highWeightPatternOffset;
00137     int m_lowWeightPatternOffset;
00138 
00139     KSycocaDict* m_fastPatternDict;
00140 
00141     struct OtherPattern
00142     {
00143         OtherPattern(const QString& pat, qint32 off, qint32 w)
00144             : pattern(pat), offset(off), weight(w) {}
00145         QString pattern;
00146         qint32 offset;
00147         qint32 weight;
00148     };
00149     typedef QList<OtherPattern> OtherPatternList;
00150 
00151 private:
00152     // Read magic files
00153     void parseMagic();
00154 
00155     QList<KMimeType::Ptr> findFromFileNameHelper(const QString &filename, QString *matchingExtension);
00156     QList<KMimeType::Ptr> findFromFastPatternDict(const QString &extension);
00166     void findFromOtherPatternList(QList<KMimeType::Ptr>& matchingMimeTypes,
00167                                   const QString &filename,
00168                                   QString& foundExt,
00169                                   bool highWeight);
00170 
00171     OtherPatternList m_highWeightPatterns;
00172     OtherPatternList m_lowWeightPatterns;
00173 
00174     QMap<QString, QString> m_aliases; // alias -> canonicalName
00175 
00176     bool m_highWeightPatternsLoaded;
00177     bool m_lowWeightPatternsLoaded;
00178     bool m_magicFilesParsed;
00179     QList<KMimeMagicRule> m_magicRules;
00180 
00181     static KMimeTypeFactory *_self;
00182 
00183 private:
00184     // d pointer: useless since this header is not installed
00185     //class KMimeTypeFactoryPrivate* d;
00186 };
00187 
00188 #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
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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