kivio_plugin_stencil_spawner.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include <config.h>
21#include "kivio_plugin_stencil_spawner.h"
22#include <tdeparts/part.h>
23#include <tdeparts/componentfactory.h>
24#include "kiviostencilfactory.h"
25#include "kivio_intra_stencil_data.h"
26#include "kivio_common.h"
27#include "kivio_stencil.h"
28
29#include <tqdom.h>
30#include <tqfileinfo.h>
31#include <kdebug.h>
32
33KivioPluginStencilSpawner::KivioPluginStencilSpawner( KivioStencilSpawnerSet *pSet )
34 : KivioStencilSpawner( pSet ),
35 m_handle(NULL)
36{
37 pNewStencil = NULL;
38}
39
40KivioPluginStencilSpawner::~KivioPluginStencilSpawner()
41{
42}
43
44bool KivioPluginStencilSpawner::load( const TQString &f )
45{
46 TQFileInfo lib(f);
47
48 if( lib.exists())
49 {
50 m_fileName = lib.baseName();
51 } else {
52 return false;
53 }
54
55 fac = KParts::ComponentFactory::createInstanceFromLibrary<KivioStencilFactory>(m_fileName.local8Bit());
56
57 if( !fac)
58 {
59 kdDebug(43000) << "Failed to load: " << m_fileName << endl;
60 return false;
61 }
62
63 // Get the icon
64 m_pIcon = fac->GetIcon();
65
66 // Get the info
67 m_pSInfo = fac->GetSpawnerInfo();
68
69 return true;
70}
71
72TQDomElement KivioPluginStencilSpawner::saveXML( TQDomDocument &doc )
73{
74 TQDomElement spawnE = doc.createElement("KivioPluginStencilSpawner");
75
76 XmlWriteString( spawnE, "id", m_pInfo->id() );
77
78 return spawnE;
79}
80
81KivioStencil *KivioPluginStencilSpawner::newStencil()
82{
83 KivioStencil *pStencil = fac->NewStencil();
84
85 pStencil->setSpawner(this);
86 return pStencil;
87}
88
89
90KivioStencil *KivioPluginStencilSpawner::newStencil(const TQString& arg)
91{
92 KivioStencil *pStencil = fac->NewStencil(arg);
93
94 pStencil->setSpawner(this);
95 return pStencil;
96}
97KivioStencilSpawnerInfo *KivioPluginStencilSpawner::info()
98{
99 return m_pSInfo;
100}