Commit 660a6710 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add KisImportExportManager::createFilterForMimeType

This creates a new KisImportExportFilter object that can be used
to access the default and saved configuration, to create a
filter configuration widget, and after fixing the weirdness with
the filter chain stuff, convert to and from a KisDocument.
parent cae87507
......@@ -31,9 +31,11 @@ Boston, MA 02110-1301, USA.
#include <QPluginLoader>
#include <QFileInfo>
#include <QMessageBox>
#include <QJsonObject>
#include <klocalizedstring.h>
#include <ksqueezedtextlabel.h>
#include <kpluginfactory.h>
#include "KoProgressUpdater.h"
#include "KoJsonTrader.h"
......@@ -258,6 +260,45 @@ QStringList KisImportExportManager::mimeFilter(Direction direction)
return QStringList();
}
KisImportExportFilter *KisImportExportManager::filterForMimeType(const QString &mimetype, KisImportExportManager::Direction direction)
{
int weight = 0;
KisImportExportFilter *filter = 0;
KoJsonTrader trader;
QList<QPluginLoader *>list = trader.query("Krita/FileFilter", "");
Q_FOREACH(QPluginLoader *loader, list) {
QJsonObject json = loader->metaData().value("MetaData").toObject();
if (json.value("X-KDE-Export").toString().split(",").contains(mimetype)) {
KLibFactory *factory = qobject_cast<KLibFactory *>(loader->instance());
if (!factory) {
warnUI << loader->errorString();
continue;
}
QObject* obj = factory->create<KisImportExportFilter>(0);
if (!obj || !obj->inherits("KisImportExportFilter")) {
delete obj;
continue;
}
KisImportExportFilter *f = static_cast<KisImportExportFilter*>(obj);
if (!f) {
delete obj;
continue;
}
int w = json.value("X-KDE-Weight").toInt();
if (w > weight) {
filter = f;
weight = w;
}
}
}
return filter;
}
void KisImportExportManager::importErrorHelper(const QString& mimeType, const bool suppressDialog)
{
// ###### FIXME: use KLibLoader::lastErrorMessage() here
......
......@@ -28,6 +28,7 @@ Boston, MA 02110-1301, USA.
#include <QUrl>
#include "KisFilterGraph.h"
#include "KisImportExportFilter.h"
#include "kritaui_export.h"
class KisFilterChain;
......@@ -112,6 +113,15 @@ public:
*/
static QStringList mimeFilter(Direction direction);
/**
* @brief filterForMimeType loads the relevant import/export plugin and returns it. The caller
* is responsible for deleting it!
* @param mimetype the mimetype we want to import/export. If there's more than one plugin, the one
* with the highest weight as defined in the json description will be taken
* @param direction import or export
* @return a pointer to the filter plugin or 0 if none could be found
*/
static KisImportExportFilter *filterForMimeType(const QString &mimetype, Direction direction);
/**
* Set the filter manager is batch mode (no dialog shown)
......
......@@ -37,6 +37,7 @@
#include <kis_config_widget.h>
#include <KisDocument.h>
#include <QHBoxLayout>
#include <KisImportExportFilter.h>
DlgAnimaterionRenderer::DlgAnimaterionRenderer(KisImageWSP image, QWidget *parent)
: KoDialog(parent)
......@@ -231,44 +232,17 @@ void DlgAnimaterionRenderer::sequenceMimeTypeSelected(int index)
m_frameExportConfigurationWidget = 0;
}
QString mimetype = m_page->cmbMimetype->itemData(index).toString();
KoJsonTrader trader;
QList<QPluginLoader *>list = trader.query("Krita/FileFilter", "");
Q_FOREACH(QPluginLoader *loader, list) {
QJsonObject json = loader->metaData().value("MetaData").toObject();
if (json.value("X-KDE-Export").toString().split(",").contains(mimetype)) {
KLibFactory *factory = qobject_cast<KLibFactory *>(loader->instance());
if (!factory) {
warnUI << loader->errorString();
continue;
}
QObject* obj = factory->create<KisImportExportFilter>(0);
if (!obj || !obj->inherits("KisImportExportFilter")) {
delete obj;
continue;
}
KisImportExportFilter *filter(static_cast<KisImportExportFilter*>(obj));
if (!filter) {
delete obj;
continue;
}
m_frameExportConfigurationWidget = filter->createConfigurationWidget(m_page->grpExportOptions, KisDocument::nativeFormatMimeType(), mimetype.toLatin1());
qDebug() << ">>>>" << loader->fileName() << mimetype << "has widget:" << m_frameExportConfigurationWidget;
if (m_frameExportConfigurationWidget) {
m_sequenceConfigLayout->addWidget(m_frameExportConfigurationWidget);
// XXX: Use the saved config here?
m_frameExportConfigurationWidget->setConfiguration(filter->defaultConfiguration());
m_frameExportConfigurationWidget->show();
resize(sizeHint());
}
delete filter;
break;
KisImportExportFilter *filter = KisImportExportManager::filterForMimeType(mimetype, KisImportExportManager::Export);
if (filter) {
m_frameExportConfigurationWidget = filter->createConfigurationWidget(m_page->grpExportOptions, KisDocument::nativeFormatMimeType(), mimetype.toLatin1());
if (m_frameExportConfigurationWidget) {
m_sequenceConfigLayout->addWidget(m_frameExportConfigurationWidget);
// XXX: Use the saved config here?
m_frameExportConfigurationWidget->setConfiguration(filter->defaultConfiguration());
m_frameExportConfigurationWidget->show();
resize(sizeHint());
}
delete filter;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment