Warning, file /office/calligra/libs/main/KoFilterEntry.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
0003    Copyright     2007       David Faure <faure@kde.org>
0004 
0005 This library is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU Library General Public
0007 License as published by the Free Software Foundation; either
0008 version 2 of the License, or (at your option) any later version.
0009 
0010 This library is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013 Library General Public License for more details.
0014 
0015 You should have received a copy of the GNU Library General Public License
0016 along with this library; see the file COPYING.LIB.  If not, write to
0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018 Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "KoFilterEntry.h"
0022 
0023 #include "KoDocument.h"
0024 #include "KoFilter.h"
0025 
0026 #include <MainDebug.h>
0027 #include <KoPluginLoader.h>
0028 #include <KoConfig.h> // CALLIGRA_OLD_PLUGIN_METADATA
0029 
0030 #include <kpluginfactory.h>
0031 #include <QFile>
0032 
0033 #include <limits.h> // UINT_MAX
0034 
0035 
0036 KoFilterEntry::KoFilterEntry(QPluginLoader *loader)
0037         : m_loader(loader)
0038 {
0039     QJsonObject metadata = loader->metaData().value("MetaData").toObject();
0040 #ifdef CALLIGRA_OLD_PLUGIN_METADATA
0041     import = metadata.value("X-KDE-Import").toString().split(',');
0042     export_ = metadata.value("X-KDE-Export").toString().split(',');
0043     int w = metadata.value("X-KDE-Weight").toString().toInt();
0044 #else
0045     import = metadata.value("X-KDE-Import").toVariant().toStringList();
0046     export_ = metadata.value("X-KDE-Export").toVariant().toStringList();
0047     int w = metadata.value("X-KDE-Weight").toInt();
0048 #endif
0049     weight = w < 0 ? UINT_MAX : static_cast<unsigned int>(w);
0050     available = metadata.value("X-KDE-Available").toString();
0051 }
0052 
0053 KoFilterEntry::~KoFilterEntry()
0054 {
0055     delete m_loader;
0056 }
0057 
0058 QString KoFilterEntry::fileName() const
0059 {
0060     return m_loader->fileName();
0061 }
0062 
0063 QList<KoFilterEntry::Ptr> KoFilterEntry::query()
0064 {
0065     QList<KoFilterEntry::Ptr> lst;
0066 
0067     QList<QPluginLoader *> offers = KoPluginLoader::pluginLoaders(QStringLiteral("calligra/formatfilters"));
0068 
0069     QList<QPluginLoader *>::ConstIterator it = offers.constBegin();
0070     unsigned int max = offers.count();
0071     //debugFilter <<"Query returned" << max <<" offers";
0072     for (unsigned int i = 0; i < max; i++) {
0073         //debugFilter <<"   desktopEntryPath=" << (*it)->entryPath()
0074         //               << "   library=" << (*it)->library() << endl;
0075         // Append converted offer
0076         lst.append(KoFilterEntry::Ptr(new KoFilterEntry(*it)));
0077         // Next service
0078         it++;
0079     }
0080 
0081     return lst;
0082 }
0083 
0084 KoFilter* KoFilterEntry::createFilter(KoFilterChain* chain, QObject* parent)
0085 {
0086     KLibFactory *factory = qobject_cast<KLibFactory *>(m_loader->instance());
0087 
0088     if (!factory) {
0089         warnMain << m_loader->errorString();
0090         return 0;
0091     }
0092 
0093     QObject* obj = factory->create<KoFilter>(parent);
0094     if (!obj || !obj->inherits("KoFilter")) {
0095         delete obj;
0096         return 0;
0097     }
0098 
0099     KoFilter* filter = static_cast<KoFilter*>(obj);
0100     filter->m_chain = chain;
0101     return filter;
0102 }
0103