KDED
kbuildimageiofactory.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE libraries 00002 * Copyright (C) 2000 Waldo Bastian <bastian@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., 51 Franklin Street, Fifth Floor, 00016 * Boston, MA 02110-1301, USA. 00017 **/ 00018 00019 #include "ksycoca.h" 00020 #include "ksycocadict.h" 00021 #include "kresourcelist.h" 00022 00023 #include <kglobal.h> 00024 #include <kstandarddirs.h> 00025 #include <kdebug.h> 00026 #include <klocale.h> 00027 #include <assert.h> 00028 00029 #include <kimageiofactory.h> 00030 #include <kbuildimageiofactory.h> 00031 00032 KBuildImageIOFactory::KBuildImageIOFactory() : 00033 KImageIOFactory() 00034 { 00035 m_resourceList = new KSycocaResourceList(); 00036 m_resourceList->add( "services", "*.kimgio" ); 00037 } 00038 00039 // return all service types for this factory 00040 // i.e. first arguments to m_resourceList->add() above 00041 QStringList KBuildImageIOFactory::resourceTypes() 00042 { 00043 return QStringList() << "services"; 00044 } 00045 00046 KBuildImageIOFactory::~KBuildImageIOFactory() 00047 { 00048 delete m_resourceList; 00049 } 00050 00051 KSycocaEntry * 00052 KBuildImageIOFactory::createEntry( const QString& file, const char *resource ) 00053 { 00054 QString fullPath = locate( resource, file); 00055 00056 KImageIOFormat *format = new KImageIOFormat(fullPath); 00057 return format; 00058 } 00059 00060 void 00061 KBuildImageIOFactory::addEntry(KSycocaEntry *newEntry, const char *resource) 00062 { 00063 KSycocaFactory::addEntry(newEntry, resource); 00064 00065 KImageIOFormat *format = (KImageIOFormat *) newEntry; 00066 rPath += format->rPaths; 00067 00068 // Since Qt doesn't allow us to unregister image formats 00069 // we have to make sure not to add them a second time. 00070 // This typically happens when the sycoca database is updated 00071 // incremenatally 00072 for( KImageIOFormatList::ConstIterator it = formatList->begin(); 00073 it != formatList->end(); 00074 ++it ) 00075 { 00076 KImageIOFormat *_format = (*it); 00077 if (format->mType == _format->mType) 00078 { 00079 // Already in list 00080 format = 0; 00081 break; 00082 } 00083 } 00084 if (format) 00085 formatList->append( format ); 00086 } 00087 00088 00089 void 00090 KBuildImageIOFactory::saveHeader(QDataStream &str) 00091 { 00092 KSycocaFactory::saveHeader(str); 00093 00094 str << mReadPattern << mWritePattern << rPath; 00095 } 00096 00097 void 00098 KBuildImageIOFactory::save(QDataStream &str) 00099 { 00100 rPath.sort(); 00101 // Remove duplicates from rPath: 00102 QString last; 00103 for(QStringList::Iterator it = rPath.begin(); 00104 it != rPath.end(); ) 00105 { 00106 QStringList::Iterator it2 = it++; 00107 if (*it2 == last) 00108 { 00109 // remove duplicate 00110 rPath.remove(it2); 00111 } 00112 else 00113 { 00114 last = *it2; 00115 } 00116 } 00117 mReadPattern = createPattern( KImageIO::Reading ); 00118 mWritePattern = createPattern( KImageIO::Writing ); 00119 00120 KSycocaFactory::save(str); 00121 } 00122