kio Library API Documentation

kprotocolinfofactory.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 1999 Torben Weis <weis@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 version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include <kstandarddirs.h>
00020 #include <kglobal.h>
00021 #include <kapplication.h>
00022 #include <kdebug.h>
00023 #include <kprotocolmanager.h>
00024 
00025 #include "kprotocolinfofactory.h"
00026 
00027 #include "ksycoca.h"
00028 #include "ksycocadict.h"
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   if (protocol == m_lastProtocol) return m_lastInfo;
00090 
00091   int offset;
00092 
00093   offset = m_sycocaDict->find_string( protocol );
00094 
00095   if (!offset) return 0; // Not found;
00096 
00097   KProtocolInfo *info = createEntry(offset);
00098 
00099   if (info && (info->name() != protocol))
00100   {
00101      // No it wasn't...
00102      delete info;
00103      info = 0; // Not found
00104   }
00105   m_lastProtocol = protocol;
00106   m_lastInfo = info;
00107   return info;
00108 }
00109 
00110 KProtocolInfo *
00111 KProtocolInfoFactory::findProtocol(const KURL &url)
00112 {
00113   QString dummy;
00114   QString protocol = KProtocolManager::slaveProtocol(url, dummy);
00115   return findProtocol(protocol);
00116 }
00117 
00118 void KProtocolInfoFactory::virtual_hook( int id, void* data )
00119 { KSycocaFactory::virtual_hook( id, data ); }
00120 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:31 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001