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

KDED

kbuildmimetypefactory.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE libraries
00002  *  Copyright 1999-2007 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 #include "kbuildmimetypefactory.h"
00021 #include "kmimetyperepository_p.h"
00022 #include "ksycoca.h"
00023 #include "ksycocadict_p.h"
00024 #include "kresourcelist.h"
00025 
00026 #include <kglobal.h>
00027 #include <kstandarddirs.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 #include <assert.h>
00031 #include <QtCore/QHash>
00032 
00033 KBuildMimeTypeFactory::KBuildMimeTypeFactory() :
00034     KMimeTypeFactory()
00035 {
00036     m_resourceList = new KSycocaResourceList;
00037     // We want all xml files under xdgdata-mime - but not packages/*.xml
00038     m_resourceList->add( "xdgdata-mime", "*.xml" );
00039 }
00040 
00041 // return all resource types for this factory
00042 // i.e. first arguments to m_resourceList->add() above
00043 QStringList KBuildMimeTypeFactory::resourceTypes()
00044 {
00045     return QStringList() << "xdgdata-mime";
00046 }
00047 
00048 KBuildMimeTypeFactory::~KBuildMimeTypeFactory()
00049 {
00050     delete m_resourceList;
00051 }
00052 
00053 KMimeTypeFactory::MimeTypeEntry::Ptr KBuildMimeTypeFactory::findMimeTypeEntryByName(const QString &_name, KMimeType::FindByNameOption options)
00054 {
00055     assert (KSycoca::self()->isBuilding());
00056 
00057     QString name = _name;
00058     if (options & KMimeType::ResolveAliases) {
00059         name = KMimeTypeRepository::self()->canonicalName(_name);
00060     }
00061 
00062     // We're building a database - the mime type must be in memory
00063     KSycocaEntry::Ptr servType = m_entryDict->value( name );
00064     return MimeTypeEntry::Ptr::staticCast( servType );
00065 }
00066 
00067 KSycocaEntry::List KBuildMimeTypeFactory::allEntries() const
00068 {
00069     assert (KSycoca::self()->isBuilding());
00070     KSycocaEntry::List lst;
00071     KSycocaEntryDict::Iterator itmime = m_entryDict->begin();
00072     const KSycocaEntryDict::Iterator endmime = m_entryDict->end();
00073     for( ; itmime != endmime ; ++itmime )
00074         lst.append( *itmime );
00075     return lst;
00076 }
00077 
00078 KSycocaEntry* KBuildMimeTypeFactory::createEntry(const QString &file, const char *resource) const
00079 {
00080     Q_UNUSED(resource);
00081 
00082     // file=text/plain.xml  ->  name=plain.xml dirName=text
00083     const int pos = file.lastIndexOf('/');
00084     if (pos == -1) // huh?
00085         return 0;
00086     const QString dirName = file.left(pos);
00087     if (dirName == "packages") // special subdir
00088         return 0;
00089 
00090     const int dot = file.lastIndexOf('.');
00091     if (dot == -1) // huh?
00092         return 0;
00093     const QString name = file.left(dot);
00094 
00095     //kDebug() << "Creating mimetype" << name << "from file" << file;
00096 
00097     MimeTypeEntry* e = new MimeTypeEntry(file, name);
00098     return e;
00099 }
00100 
00101 void KBuildMimeTypeFactory::saveHeader(QDataStream &str)
00102 {
00103     KSycocaFactory::saveHeader(str);
00104 }
00105 
00106 void KBuildMimeTypeFactory::save(QDataStream &str)
00107 {
00108     KSycocaFactory::save(str);
00109 
00110     str << (qint32) 0;
00111 
00112     const int endOfFactoryData = str.device()->pos();
00113 
00114     // Update header (pass #3)
00115     saveHeader(str);
00116 
00117     // Seek to end.
00118     str.device()->seek(endOfFactoryData);
00119 }
00120 
00121 void KBuildMimeTypeFactory::createFakeMimeType(const QString& name)
00122 {
00123    const QString file = name; // hack
00124    KSycocaEntry::Ptr entry = m_entryDict->value(file);
00125    if (!entry) {
00126        MimeTypeEntry* e = new MimeTypeEntry(file, name);
00127        entry = e;
00128    }
00129 
00130    Q_ASSERT(entry && entry->isValid());
00131    addEntry(entry);
00132 }

KDED

Skip menu "KDED"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • 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