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

KDED

  • sources
  • kde-4.12
  • kdelibs
  • kded
kbuildmimetypefactory.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  * Copyright 1999-2007 David Faure <faure@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include "kbuildmimetypefactory.h"
21 #include "kmimetyperepository_p.h"
22 #include "ksycoca.h"
23 #include "ksycocadict_p.h"
24 #include "ksycocaresourcelist.h"
25 
26 #include <kglobal.h>
27 #include <kstandarddirs.h>
28 #include <kdebug.h>
29 #include <klocale.h>
30 #include <assert.h>
31 #include <QtCore/QHash>
32 
33 KBuildMimeTypeFactory::KBuildMimeTypeFactory() :
34  KMimeTypeFactory()
35 {
36  m_resourceList = new KSycocaResourceList;
37  // We want all xml files under xdgdata-mime - but not packages/*.xml
38  m_resourceList->add( "xdgdata-mime", "*.xml" );
39 }
40 
41 // return all resource types for this factory
42 // i.e. first arguments to m_resourceList->add() above
43 QStringList KBuildMimeTypeFactory::resourceTypes()
44 {
45  return QStringList() << "xdgdata-mime";
46 }
47 
48 KBuildMimeTypeFactory::~KBuildMimeTypeFactory()
49 {
50  delete m_resourceList;
51 }
52 
53 KMimeTypeFactory::MimeTypeEntry::Ptr KBuildMimeTypeFactory::findMimeTypeEntryByName(const QString &_name, KMimeType::FindByNameOption options)
54 {
55  assert (KSycoca::self()->isBuilding());
56 
57  QString name = _name;
58  if (options & KMimeType::ResolveAliases) {
59  name = KMimeTypeRepository::self()->canonicalName(_name);
60  }
61 
62  // We're building a database - the mime type must be in memory
63  KSycocaEntry::Ptr servType = m_entryDict->value( name );
64  return MimeTypeEntry::Ptr::staticCast( servType );
65 }
66 
67 KSycocaEntry::List KBuildMimeTypeFactory::allEntries() const
68 {
69  assert (KSycoca::self()->isBuilding());
70  KSycocaEntry::List lst;
71  KSycocaEntryDict::Iterator itmime = m_entryDict->begin();
72  const KSycocaEntryDict::Iterator endmime = m_entryDict->end();
73  for( ; itmime != endmime ; ++itmime )
74  lst.append( *itmime );
75  return lst;
76 }
77 
78 KSycocaEntry* KBuildMimeTypeFactory::createEntry(const QString &file, const char *resource) const
79 {
80  Q_UNUSED(resource);
81 
82  // file=text/plain.xml -> name=plain.xml dirName=text
83  const int pos = file.lastIndexOf('/');
84  if (pos == -1) // huh?
85  return 0;
86  const QString dirName = file.left(pos);
87  if (dirName == "packages") // special subdir
88  return 0;
89 
90  const int dot = file.lastIndexOf('.');
91  if (dot == -1) // huh?
92  return 0;
93  const QString name = file.left(dot);
94 
95  //kDebug() << "Creating mimetype" << name << "from file" << file;
96 
97  MimeTypeEntry* e = new MimeTypeEntry(file, name);
98  return e;
99 }
100 
101 void KBuildMimeTypeFactory::saveHeader(QDataStream &str)
102 {
103  KSycocaFactory::saveHeader(str);
104 }
105 
106 void KBuildMimeTypeFactory::save(QDataStream &str)
107 {
108  KSycocaFactory::save(str);
109 
110  str << (qint32) 0;
111 
112  const int endOfFactoryData = str.device()->pos();
113 
114  // Update header (pass #3)
115  saveHeader(str);
116 
117  // Seek to end.
118  str.device()->seek(endOfFactoryData);
119 }
120 
121 void KBuildMimeTypeFactory::createFakeMimeType(const QString& name)
122 {
123  const QString file = name; // hack
124  KSycocaEntry::Ptr entry = m_entryDict->value(file);
125  if (!entry) {
126  MimeTypeEntry* e = new MimeTypeEntry(file, name);
127  entry = e;
128  }
129 
130  Q_ASSERT(entry && entry->isValid());
131  addEntry(entry);
132 }
KMimeTypeFactory::MimeTypeEntry
KSharedPtr
KMimeTypeFactory::m_entryDict
KSycocaEntryDict * m_entryDict
kdebug.h
name
const char * name(StandardAction id)
KMimeTypeFactory
KMimeTypeFactory::m_resourceList
KSycocaResourceList * m_resourceList
KSycocaResourceList
Definition: ksycocaresourcelist.h:32
kmimetyperepository_p.h
KMimeTypeRepository::self
static KMimeTypeRepository * self()
QString
klocale.h
kglobal.h
KBuildMimeTypeFactory::allEntries
virtual KSycocaEntry::List allEntries() const
Definition: kbuildmimetypefactory.cpp:67
ksycocadict_p.h
KSycocaEntry
KBuildMimeTypeFactory::createFakeMimeType
void createFakeMimeType(const QString &name)
Definition: kbuildmimetypefactory.cpp:121
KBuildMimeTypeFactory::findMimeTypeEntryByName
MimeTypeEntry::Ptr findMimeTypeEntryByName(const QString &_name, KMimeType::FindByNameOption options=KMimeType::DontResolveAlias)
Find a mime type entry in the database file.
Definition: kbuildmimetypefactory.cpp:53
QStringList
KMimeTypeFactory::addEntry
virtual void addEntry(const KSycocaEntry::Ptr &newEntry)
KSycocaResourceList::add
void add(const QString &resource, const QString &filter)
Definition: ksycocaresourcelist.h:37
KBuildMimeTypeFactory::resourceTypes
static QStringList resourceTypes()
Returns all resource types for this factory.
Definition: kbuildmimetypefactory.cpp:43
KBuildMimeTypeFactory::createEntry
virtual KSycocaEntry * createEntry(const QString &file, const char *resource) const
Construct a KMimeType from a config file.
Definition: kbuildmimetypefactory.cpp:78
KBuildMimeTypeFactory::save
virtual void save(QDataStream &str)
Write out mime type specific index files.
Definition: kbuildmimetypefactory.cpp:106
ksycoca.h
KBuildMimeTypeFactory::KBuildMimeTypeFactory
KBuildMimeTypeFactory()
Create factory.
Definition: kbuildmimetypefactory.cpp:33
kstandarddirs.h
KBuildMimeTypeFactory::~KBuildMimeTypeFactory
virtual ~KBuildMimeTypeFactory()
Definition: kbuildmimetypefactory.cpp:48
kbuildmimetypefactory.h
qint32
ksycocaresourcelist.h
KBuildMimeTypeFactory::saveHeader
virtual void saveHeader(QDataStream &str)
Write out header information.
Definition: kbuildmimetypefactory.cpp:101
KMimeTypeRepository::canonicalName
QString canonicalName(const QString &mime)
KSycoca::self
static KSycoca * self()
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDED

Skip menu "KDED"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal