krita

kis_tool_registry.cc

00001 /*
00002  *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kdebug.h"
00020 #include <kaction.h>
00021 #include <kparts/plugin.h>
00022 #include <kservice.h>
00023 #include <ktrader.h>
00024 #include <kparts/componentfactory.h>
00025 
00026 #include "kis_generic_registry.h"
00027 #include "kis_types.h"
00028 #include "kis_tool_registry.h"
00029 #include "kis_tool.h"
00030 #include "kis_tool_factory.h"
00031 #include "kis_canvas_subject.h"
00032 #include "kis_id.h"
00033 #include "kis_debug_areas.h"
00034 
00035 KisToolRegistry *KisToolRegistry::m_singleton = 0;
00036 
00037 KisToolRegistry::KisToolRegistry()
00038 {
00039     // Load all modules: color models, paintops, filters
00040     KTrader::OfferList offers = KTrader::self()->query(QString::fromLatin1("Krita/Tool"),
00041                                                          QString::fromLatin1("(Type == 'Service') and "
00042                                                                              "([X-Krita-Version] == 2)"));
00043 
00044     KTrader::OfferList::ConstIterator iter;
00045 
00046     for(iter = offers.begin(); iter != offers.end(); ++iter)
00047     {
00048         KService::Ptr service = *iter;
00049         int errCode = 0;
00050         KParts::Plugin* plugin =
00051              KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, 0, QStringList(), &errCode);
00052         if ( plugin )
00053             kdDebug(DBG_AREA_PLUGINS) << "found plugin " << service->property("Name").toString() << "\n";
00054         else {
00055             kdDebug(41006) << "found plugin " << service->property("Name").toString() << ", " << errCode << "\n";
00056             if( errCode == KParts::ComponentFactory::ErrNoLibrary)
00057             {
00058                 kdWarning(41006) << " Error loading plugin was : ErrNoLibrary " << KLibLoader::self()->lastErrorMessage() << endl;
00059             }
00060         }
00061 
00062     }
00063 
00064 }
00065 
00066 KisToolRegistry::~KisToolRegistry()
00067 {
00068 }
00069 
00070 KisToolRegistry* KisToolRegistry::instance()
00071 {
00072      if(KisToolRegistry::m_singleton == 0)
00073      {
00074          KisToolRegistry::m_singleton = new KisToolRegistry();
00075      }
00076     return KisToolRegistry::m_singleton;
00077 }
00078 
00079 
00080 
00081 vKisTool KisToolRegistry::createTools(KActionCollection * ac, KisCanvasSubject *subject) const
00082 {
00083     Q_ASSERT(subject);
00084 
00085     vKisTool tools;
00086 
00087     KisIDList factories = listKeys();
00088 
00089     for (KisIDList::Iterator it = factories.begin(); it != factories.end(); ++it )
00090     {
00091         KisToolFactorySP f = get(*it);
00092 
00093         KisTool * tool = f->createTool(ac);
00094         subject->attach(tool);
00095         tools.push_back(tool);
00096     }
00097 
00098     subject->notifyObservers();
00099 
00100     return tools;
00101 }
00102 
00103 KisTool * KisToolRegistry::createTool(KActionCollection * ac, KisCanvasSubject * subject, KisID & id) const
00104 {
00105     KisToolFactorySP f = get(id);
00106     KisTool * t = f->createTool(ac);
00107     subject->attach(t);
00108     return t;
00109 }
00110 
00111 #include "kis_tool_registry.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys