kivio

kivio_pluginmanager.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2003 Peter Simonsson
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 #include "kivio_pluginmanager.h"
00020 
00021 #include <kdebug.h>
00022 #include <kparts/plugin.h>
00023 
00024 #include "kivio_plugin.h"
00025 
00026 namespace Kivio {
00027   PluginManager::PluginManager(KivioView* parent, const char* name) : QObject(parent, name)
00028   {
00029     m_activeTool = 0;
00030     m_defaultTool = 0;
00031     m_delegateEvents = true;
00032   }
00033   
00034   PluginManager::~PluginManager()
00035   {
00036   }
00037   
00038   bool PluginManager::delegateEvent(QEvent* e)
00039   {
00040     if(activeTool() && m_delegateEvents) {
00041       return activeTool()->processEvent(e);
00042     }
00043     
00044     return false;
00045   }
00046   
00047   Kivio::MouseTool* PluginManager::activeTool()
00048   {
00049     return m_activeTool;
00050   }
00051   
00052   Kivio::MouseTool* PluginManager::defaultTool()
00053   {
00054     return m_defaultTool;
00055   }
00056 
00057   void PluginManager::activateDefaultTool()
00058   {
00059     if(defaultTool()) {
00060       kdDebug(43000) << "Default tool activated! " << defaultTool()->name() << endl;
00061       defaultTool()->setActivated(true);
00062     }
00063   }
00064   
00065   void PluginManager::activate(Kivio::MouseTool* tool)
00066   {
00067     if(tool != m_activeTool) {
00068       if(m_activeTool) {
00069         kdDebug(43000) << "Deactivate tool: " << m_activeTool->name() << endl;
00070         m_activeTool->setActivated(false);
00071       }
00072       
00073       kdDebug(43000) << "Activate new tool: " << tool->name() << endl;
00074       m_activeTool = tool;
00075     }
00076   }
00077 
00078   void PluginManager::setDefaultTool(Kivio::MouseTool* tool)
00079   {
00080     m_defaultTool = tool;
00081     kdDebug(43000) << "New default tool: " << tool->name() << endl;
00082   }
00083 
00084   Kivio::Plugin* PluginManager::findPlugin(const QString& name)
00085   {
00086     QPtrList<KParts::Plugin> plugins = KParts::Plugin::pluginObjects(parent());
00087     KParts::Plugin* p = plugins.first();
00088     bool found = false;
00089     
00090     while(p && !found) {
00091       if(p->name() == name) {
00092         found = true;
00093       } else {
00094         p = plugins.next();
00095       }
00096     }
00097     
00098     return static_cast<Kivio::Plugin*>(p);
00099   }
00100 }
00101 
00102 #include "kivio_pluginmanager.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys