File indexing completed on 2024-05-12 16:35:05

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
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 "VideoShapeFactory.h"
0022 
0023 #include "VideoShape.h"
0024 #include "VideoShapeConfigWidget.h"
0025 #include "VideoCollection.h"
0026 #include "VideoDebug.h"
0027 
0028 #include <KoDocumentResourceManager.h>
0029 #include <KoXmlNS.h>
0030 #include "KoShapeBasedDocumentBase.h"
0031 #include <KoShapeLoadingContext.h>
0032 #include <KoIcon.h>
0033 
0034 #include <klocalizedstring.h>
0035 
0036 VideoShapeFactory::VideoShapeFactory()
0037     : KoShapeFactoryBase(VIDEOSHAPEID, i18n("Video"))
0038 {
0039     setToolTip(i18n("Video, embedded or fullscreen"));
0040     setIconName(koIconName("video-x-generic"));
0041     setXmlElementNames(KoXmlNS::draw, QStringList("plugin"));
0042     setLoadingPriority(2);
0043 }
0044 
0045 KoShape *VideoShapeFactory::createDefaultShape(KoDocumentResourceManager *documentResources) const
0046 {
0047     VideoShape * defaultShape = new VideoShape();
0048     defaultShape->setShapeId(VIDEOSHAPEID);
0049     if (documentResources) {
0050           Q_ASSERT(documentResources->hasResource(VideoCollection::ResourceId));
0051           QVariant vc = documentResources->resource(VideoCollection::ResourceId);
0052           defaultShape->setVideoCollection(static_cast<VideoCollection*>(vc.value<void*>()));
0053     }
0054     return defaultShape;
0055 }
0056 
0057 bool VideoShapeFactory::supports(const KoXmlElement &e, KoShapeLoadingContext &context) const
0058 {
0059     Q_UNUSED(context);
0060     if (e.localName() != "plugin" || e.namespaceURI() != KoXmlNS::draw) {
0061         return false;
0062     }
0063     return e.attribute("mime-type") == "application/vnd.sun.star.media";
0064 }
0065 
0066 void VideoShapeFactory::newDocumentResourceManager(KoDocumentResourceManager *manager) const
0067 {
0068     QVariant variant;
0069     variant.setValue<void*>(new VideoCollection(manager));
0070     manager->setResource(VideoCollection::ResourceId, variant);
0071 }
0072 
0073 QList<KoShapeConfigWidgetBase*> VideoShapeFactory::createShapeOptionPanels()
0074 {
0075     QList<KoShapeConfigWidgetBase*> panels;
0076     panels.append(new VideoShapeConfigWidget());
0077     return panels;
0078 }