File indexing completed on 2024-12-08 09:38:55

0001 /*
0002     Large image displaying library.
0003 
0004     Copyright (C) 2004 Maks Orlovich (maksim@kde.org)
0005 
0006     Permission is hereby granted, free of charge, to any person obtaining a copy
0007     of this software and associated documentation files (the "Software"), to deal
0008     in the Software without restriction, including without limitation the rights
0009     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0010     copies of the Software, and to permit persons to whom the Software is
0011     furnished to do so, subject to the following conditions:
0012 
0013     The above copyright notice and this permission notice shall be included in
0014     all copies or substantial portions of the Software.
0015 
0016     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0017     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0018     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
0019     AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
0020     AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0021     CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0022 
0023 */
0024 
0025 #ifndef LOADER_DATABASE_H
0026 #define LOADER_DATABASE_H
0027 
0028 #include "imageloaderprovider.h"
0029 #include "qimageioloader.h"
0030 #include <QStringList>
0031 #include <QVector>
0032 
0033 namespace khtmlImLoad
0034 {
0035 
0036 class ImageLoader;
0037 
0038 class LoaderDatabase
0039 {
0040 public:
0041     LoaderDatabase() {}
0042 
0043     unsigned int numLoaders()
0044     {
0045         return efficientProviders.size() + foreignProviders.size();
0046     }
0047 
0048     QStringList supportedMimeTypes()
0049     {
0050         //### FIXME/TODO: this should be more dynamic
0051         QStringList ret;
0052         ret << QLatin1String("image/jpg") << QLatin1String("image/jpeg")
0053             << QLatin1String("image/png") << QLatin1String("image/gif")
0054             << QImageIOLoaderProvider::mimeTypes();
0055         return ret;
0056     }
0057 
0058     void registerLoaderProvider(ImageLoaderProvider *provider)
0059     {
0060         if (provider->type() == ImageLoaderProvider::Efficient) {
0061             efficientProviders.append(provider);
0062         } else {
0063             foreignProviders.append(provider);
0064         }
0065     }
0066 
0067     ImageLoader *loaderFor(const QByteArray &prefix)
0068     {
0069         ImageLoader *toRet;
0070         for (int c = 0; c < efficientProviders.size(); c++) {
0071             toRet = efficientProviders[c]->loaderFor(prefix);
0072             if (toRet) {
0073                 return toRet;
0074             }
0075         }
0076 
0077         for (int c = 0; c < foreignProviders.size(); c++) {
0078             toRet = foreignProviders[c]->loaderFor(prefix);
0079             if (toRet) {
0080                 return toRet;
0081             }
0082         }
0083 
0084         return nullptr;
0085     }
0086 
0087     ~LoaderDatabase()
0088     {
0089         for (int c = 0; c < efficientProviders.size(); c++) {
0090             delete efficientProviders[c];
0091         }
0092 
0093         for (int c = 0; c < foreignProviders.size(); c++) {
0094             delete foreignProviders[c];
0095         }
0096     }
0097 private:
0098     QVector<ImageLoaderProvider *> efficientProviders;
0099     QVector<ImageLoaderProvider *> foreignProviders;
0100 };
0101 
0102 }
0103 
0104 #endif