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

KDECore

  • kdecore
  • sycoca
kprotocolinfofactory.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Torben Weis <weis@kde.org>
3  Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
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 "kprotocolinfofactory.h"
21 
22 #include <kstandarddirs.h>
23 #include <kdebug.h>
24 #include <ksycoca.h>
25 #include <ksycocadict_p.h>
26 
27 K_GLOBAL_STATIC(KSycocaFactorySingleton<KProtocolInfoFactory>, kProtocolInfoFactoryInstance)
28 
29 KProtocolInfoFactory::KProtocolInfoFactory() : KSycocaFactory( KST_KProtocolInfoFactory )
30 {
31  kProtocolInfoFactoryInstance->instanceCreated(this);
32 }
33 
34 KProtocolInfoFactory::~KProtocolInfoFactory()
35 {
36  if (kProtocolInfoFactoryInstance.exists())
37  kProtocolInfoFactoryInstance->instanceDestroyed(this);
38 }
39 
40 KProtocolInfo*
41 KProtocolInfoFactory::createEntry(int offset) const
42 {
43  KProtocolInfo *info = 0;
44  KSycocaType type;
45  QDataStream *str = KSycoca::self()->findEntry(offset, type);
46  switch (type)
47  {
48  case KST_KProtocolInfo:
49  info = new KProtocolInfo(*str, offset);
50  break;
51  default:
52  return 0;
53  }
54  if (!info->isValid())
55  {
56  delete info;
57  info = 0;
58  }
59  return info;
60 }
61 
62 
63 QStringList KProtocolInfoFactory::protocols() const
64 {
65  QStringList res;
66  const KSycocaEntry::List list = allEntries();
67  for( KSycocaEntry::List::const_iterator it = list.begin();
68  it != list.end();
69  ++it) {
70  const KSycocaEntry *entry = (*it).data();
71  const KProtocolInfo *info = static_cast<const KProtocolInfo *>(entry);
72  res.append( info->name() );
73  }
74  return res;
75 }
76 
77 KProtocolInfo::List KProtocolInfoFactory::allProtocols() const
78 {
79  KProtocolInfo::List result;
80  const KSycocaEntry::List list = allEntries();
81  for( KSycocaEntry::List::ConstIterator it = list.begin();
82  it != list.end();
83  ++it) {
84  if ((*it)->isType(KST_KProtocolInfo)) {
85  result.append(KProtocolInfo::Ptr::staticCast(*it));
86  }
87  }
88  return result;
89 }
90 
91 KProtocolInfo::Ptr KProtocolInfoFactory::findProtocol(const QString &protocol)
92 {
93  if (!sycocaDict()) return KProtocolInfo::Ptr(); // Error!
94 
95  QMap<QString,KProtocolInfo::Ptr>::iterator it = m_cache.find(protocol);
96  if (it != m_cache.end())
97  return *it;
98 
99  int offset;
100 
101  offset = sycocaDict()->find_string( protocol );
102 
103  if (!offset) return KProtocolInfo::Ptr(); // Not found;
104 
105  KProtocolInfo::Ptr info(createEntry(offset));
106 
107  if (info && (info->name() != protocol))
108  {
109  // No it wasn't...
110  return KProtocolInfo::Ptr(); // Not found
111  }
112  m_cache.insert(protocol,info);
113  return info;
114 }
115 
116 void KProtocolInfoFactory::virtual_hook( int id, void* data )
117 { KSycocaFactory::virtual_hook( id, data ); }
118 
119 KProtocolInfoFactory* KProtocolInfoFactory::self()
120 {
121  return kProtocolInfoFactoryInstance->self();
122 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Jul 16 2013 17:47:34 by doxygen 1.8.1.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.10.5 API Reference

Skip menu "kdelibs-4.10.5 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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