kivio

kivio_plugin_stencil_spawner.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include <config.h>
00021 #include "kivio_plugin_stencil_spawner.h"
00022 #include <kparts/part.h>
00023 #include <kparts/componentfactory.h>
00024 #include "kiviostencilfactory.h"
00025 #include "kivio_intra_stencil_data.h"
00026 #include "kivio_common.h"
00027 #include "kivio_stencil.h"
00028 
00029 #include <qdom.h>
00030 #include <qfileinfo.h>
00031 #include <kdebug.h>
00032 
00033 KivioPluginStencilSpawner::KivioPluginStencilSpawner( KivioStencilSpawnerSet *pSet )
00034     : KivioStencilSpawner( pSet ),
00035       m_handle(NULL)
00036 {
00037     pNewStencil = NULL;
00038 }
00039 
00040 KivioPluginStencilSpawner::~KivioPluginStencilSpawner()
00041 {
00042 }
00043 
00044 bool KivioPluginStencilSpawner::load( const QString &f )
00045 {
00046   QFileInfo lib(f);
00047   
00048   if( lib.exists())
00049   {
00050     m_fileName = lib.baseName();
00051   } else {
00052     return false;
00053   }
00054 
00055   fac = KParts::ComponentFactory::createInstanceFromLibrary<KivioStencilFactory>(m_fileName.local8Bit());
00056 
00057   if( !fac)
00058   {
00059     kdDebug(43000) << "Failed to load: " << m_fileName << endl;
00060     return false;
00061   }
00062   
00063   // Get the icon
00064   m_pIcon = fac->GetIcon();
00065 
00066   // Get the info
00067   m_pSInfo = fac->GetSpawnerInfo();
00068 
00069   return true;
00070 }
00071 
00072 QDomElement KivioPluginStencilSpawner::saveXML( QDomDocument &doc )
00073 {
00074     QDomElement spawnE = doc.createElement("KivioPluginStencilSpawner");
00075 
00076     XmlWriteString( spawnE, "id", m_pInfo->id() );
00077 
00078     return spawnE;
00079 }
00080 
00081 KivioStencil *KivioPluginStencilSpawner::newStencil()
00082 {
00083     KivioStencil *pStencil = fac->NewStencil();
00084 
00085     pStencil->setSpawner(this);
00086     return pStencil;
00087 }
00088 
00089 
00090 KivioStencil *KivioPluginStencilSpawner::newStencil(const QString& arg)
00091 {
00092     KivioStencil *pStencil = fac->NewStencil(arg);
00093 
00094     pStencil->setSpawner(this);
00095     return pStencil;
00096 }
00097 KivioStencilSpawnerInfo *KivioPluginStencilSpawner::info()
00098 {
00099     return m_pSInfo;
00100 }
KDE Home | KDE Accessibility Home | Description of Access Keys