KDECore
kprotocolinfofactory.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Torben Weis <weis@kde.org> 00003 Copyright (C) 2003 Waldo Bastian <bastian@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 #include <kstandarddirs.h> 00021 #include <kglobal.h> 00022 #include <kapplication.h> 00023 #include <kdebug.h> 00024 #include <ksycoca.h> 00025 #include <ksycocadict.h> 00026 00027 #include "kprotocolinfofactory.h" 00028 00029 00030 KProtocolInfoFactory* KProtocolInfoFactory::_self = 0; 00031 00032 KProtocolInfoFactory::KProtocolInfoFactory() : KSycocaFactory( KST_KProtocolInfoFactory ) 00033 { 00034 _self = this; 00035 } 00036 00037 KProtocolInfoFactory::~KProtocolInfoFactory() 00038 { 00039 _self = 0; 00040 } 00041 00042 00043 KProtocolInfo* 00044 KProtocolInfoFactory::createEntry(int offset) 00045 { 00046 KProtocolInfo *info = 0; 00047 KSycocaType type; 00048 QDataStream *str = KSycoca::self()->findEntry(offset, type); 00049 switch (type) 00050 { 00051 case KST_KProtocolInfo: 00052 info = new KProtocolInfo(*str, offset); 00053 break; 00054 default: 00055 return 0; 00056 } 00057 if (!info->isValid()) 00058 { 00059 delete info; 00060 info = 0; 00061 } 00062 return info; 00063 } 00064 00065 00066 QStringList KProtocolInfoFactory::protocols() 00067 { 00068 QStringList res; 00069 00070 KSycocaEntry::List list = allEntries(); 00071 for( KSycocaEntry::List::Iterator it = list.begin(); 00072 it != list.end(); 00073 ++it) 00074 { 00075 KSycocaEntry *entry = (*it).data(); 00076 KProtocolInfo *info = static_cast<KProtocolInfo *>(entry); 00077 00078 res.append( info->name() ); 00079 } 00080 00081 return res; 00082 } 00083 00084 KProtocolInfo * 00085 KProtocolInfoFactory::findProtocol(const QString &protocol) 00086 { 00087 if (!m_sycocaDict) return 0; // Error! 00088 00089 QMap<QString,KProtocolInfo::Ptr>::iterator it = m_cache.find(protocol); 00090 if (it != m_cache.end()) 00091 return (*it); 00092 00093 int offset; 00094 00095 offset = m_sycocaDict->find_string( protocol ); 00096 00097 if (!offset) return 0; // Not found; 00098 00099 KProtocolInfo *info = createEntry(offset); 00100 00101 if (info && (info->name() != protocol)) 00102 { 00103 // No it wasn't... 00104 delete info; 00105 info = 0; // Not found 00106 } 00107 m_cache.insert(protocol,info); 00108 return info; 00109 } 00110 00111 void KProtocolInfoFactory::virtual_hook( int id, void* data ) 00112 { KSycocaFactory::virtual_hook( id, data ); } 00113