From 47d455dd55be855e4cc691c32f687f723d9247ee Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- ksvg/core/CanvasFactory.cpp | 176 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 ksvg/core/CanvasFactory.cpp (limited to 'ksvg/core/CanvasFactory.cpp') diff --git a/ksvg/core/CanvasFactory.cpp b/ksvg/core/CanvasFactory.cpp new file mode 100644 index 00000000..ca2822b2 --- /dev/null +++ b/ksvg/core/CanvasFactory.cpp @@ -0,0 +1,176 @@ +/* + Copyright (C) 2003 KSVG Team + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +#include +#include +#include + +#include "KSVGCanvas.h" +#include "CanvasFactory.h" + +using namespace KSVG; + +CanvasFactory *CanvasFactory::s_factory = 0; + +CanvasFactory::CanvasFactory() +{ + m_canvasList.setAutoDelete(true); +} + +CanvasFactory::~CanvasFactory() +{ +} + +CanvasFactory *CanvasFactory::self() +{ + if(!s_factory) + s_factory = new CanvasFactory(); + + return s_factory; +} + +void CanvasFactory::cleanup() +{ + m_canvasList.clear(); +} + +void CanvasFactory::queryCanvas() +{ + m_canvasList.clear(); + + QValueList traderList = KTrader::self()->query("KSVG/Renderer", "(Type == 'Service')"); + KTrader::OfferList::Iterator it(traderList.begin()); + for( ; it != traderList.end(); ++it) + { + KService::Ptr ptr = (*it); + + QString name = ptr->property("Name").toString(); + QString internal = ptr->property("X-KSVG-InternalName").toString(); + if(name.isEmpty() || internal.isEmpty()) + continue; + + CanvasInfo *cinfo = new CanvasInfo(); + cinfo->service = ptr; + cinfo->canvas = 0; + cinfo->name = name; + cinfo->internal = internal; + + m_canvasList.append(cinfo); + } + + if(m_canvasList.isEmpty()) + { + kdError(26001) << "Couldn't load any canvas!!! FATAL ERROR." << endl; + return; + } +} + +KSVGCanvas *CanvasFactory::loadCanvas(int width, int height) +{ + queryCanvas(); + + KSimpleConfig *config = new KSimpleConfig("ksvgpluginrc", false); + config->setGroup("Canvas"); + QString load = config->readEntry("ActiveCanvas", "libart"); + delete config; + + QPtrListIterator it(m_canvasList); + CanvasInfo *info = it.current(); + while((info = it.current()) != 0) + { + if(info->internal == load) + { + QStringList args; + args.prepend(QString::number(width)); + args.prepend(QString::number(height)); + + info->canvas = KParts::ComponentFactory::createInstanceFromLibrary(QFile::encodeName(info->service->library()), 0, 0, args); + + if(info->canvas) + return info->canvas; + else + { + kdError(26001) << "Failed to load canvas: " << load << " FATAL ERROR." << endl; + break; + } + } + + ++it; + } + + return 0; +} + +int CanvasFactory::itemInList(KSVGCanvas *canvas) +{ + QPtrListIterator it(m_canvasList); + CanvasInfo *info = it.current(); + unsigned int i = 0; + while((info = it.current()) != 0) + { + if(info->canvas == canvas) + return i; + + i++; + ++it; + } + + return 0; +} + +QString CanvasFactory::internalNameFor(const QString &name) +{ + QPtrListIterator it(m_canvasList); + CanvasInfo *info = it.current(); + while((info = it.current()) != 0) + { + if(info->name == name) + return info->internal; + + ++it; + } + + return QString::null; +} + +void CanvasFactory::deleteCanvas(KSVGCanvas *canvas) +{ + QPtrListIterator it(m_canvasList); + CanvasInfo *info = it.current(); + while((info = it.current()) != 0) + { + if(info->canvas == canvas) + { + delete info->canvas; + info->canvas = 0; + } + + ++it; + } +} + +QPtrList CanvasFactory::canvasList() +{ + return m_canvasList; +} + +// vim:ts=4:noet -- cgit v1.2.1