KDECore
kmimetyperepository_p.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 as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KMIMETYPEREPOSITORY_H 00022 #define KMIMETYPEREPOSITORY_H 00023 00024 #include "kmimemagicrule_p.h" 00025 #include "kmimeglobsfileparser_p.h" 00026 #include "kmimetype.h" 00027 #include <QReadWriteLock> 00028 00036 class KDECORE_EXPORT KMimeTypeRepository 00037 { 00038 public: 00042 static KMimeTypeRepository * self(); 00043 00047 KMimeType::Ptr findMimeTypeByName(const QString &_name, KMimeType::FindByNameOption options = KMimeType::DontResolveAlias); 00048 00052 QString resolveAlias(const QString& mime); 00053 00057 QString canonicalName(const QString& mime); 00058 00062 QStringList parents(const QString& mime); 00063 00064 enum GlobMatchingFlag { 00065 NoFlag = 0, 00066 CaseSensitive = 0x1 00067 }; 00068 00073 QStringList patternsForMimetype(const QString& mimeType); 00074 00078 void checkEssentialMimeTypes(); 00079 00080 KMimeType::Ptr defaultMimeTypePtr(); 00081 00085 bool useFavIcons(); 00086 00087 int sharedMimeInfoVersion(); 00088 00092 static bool matchFileName( const QString &filename, const QString &pattern ); 00093 00094 private: // only for KMimeType and unittests 00095 friend class KMimeType; 00096 friend class KMimeFileParserTest; 00097 friend class KMimeTypeTest; 00098 00106 QStringList findFromFileName(const QString &filename, QString *matchingExtension = 0); 00107 00116 KMimeType::Ptr findFromContent(QIODevice* device, int* accuracy, QByteArray& beginning); 00117 00122 bool checkMimeTypes(); 00123 00124 private: 00125 KMimeTypeRepository(); 00126 ~KMimeTypeRepository(); 00127 00128 typedef QHash<QString, QString> AliasesMap; 00129 const AliasesMap& aliases(); 00130 00134 QList<KMimeMagicRule> parseMagicFile(QIODevice* file, const QString& fileName) const; 00135 00136 // Read magic files 00137 void parseMagic(); 00138 00139 void parseGlobs(); 00140 00150 void findFromOtherPatternList(QStringList& matchingMimeTypes, 00151 const QString &filename, 00152 QString& foundExt, 00153 bool highWeight); 00154 00155 mutable AliasesMap m_aliases; // alias -> canonicalName 00156 00157 typedef QHash<QString, QStringList> ParentsMap; 00158 ParentsMap m_parents; 00159 00160 typedef QHash<QString, QStringList> PatternsMap; 00161 PatternsMap m_patterns; 00162 00163 bool m_parentsMapLoaded; 00164 bool m_magicFilesParsed; 00165 mutable bool m_aliasFilesParsed; 00166 bool m_globsFilesParsed; 00167 bool m_patternsMapCalculated; 00168 bool m_mimeTypesChecked; 00169 bool m_useFavIcons; 00170 bool m_useFavIconsChecked; 00171 int m_sharedMimeInfoVersion; 00172 QList<KMimeMagicRule> m_magicRules; 00173 KMimeGlobsFileParser::AllGlobs m_globs; 00174 KMimeType::Ptr m_defaultMimeType; 00175 QReadWriteLock m_mutex; 00176 }; 00177 00178 #endif /* KMIMETYPEREPOSITORY_H */ 00179
KDE 4.6 API Reference