kontact Library API Documentation

plugin.cpp

00001 /* 00002 This file is part of KDE Kontact. 00003 00004 Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org> 00005 Copyright (c) 2002-2003 Daniel Molkentin <molkentin@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 Boston, MA 02111-1307, USA. 00021 */ 00022 00023 #include <qobjectlist.h> 00024 00025 #include <dcopclient.h> 00026 #include <kaboutdata.h> 00027 #include <kglobal.h> 00028 #include <kparts/componentfactory.h> 00029 #include <kdebug.h> 00030 #include <kinstance.h> 00031 #include <krun.h> 00032 00033 #include "core.h" 00034 #include "plugin.h" 00035 00036 using namespace Kontact; 00037 00038 class Plugin::Private 00039 { 00040 public: 00041 Kontact::Core *core; 00042 DCOPClient *dcopClient; 00043 QPtrList<KAction> *newActions; 00044 QString identifier; 00045 QString title; 00046 QString icon; 00047 QString executableName; 00048 QCString partLibraryName; 00049 KParts::Part *part; 00050 }; 00051 00052 00053 Plugin::Plugin( Kontact::Core *core, QObject *parent, const char *name ) 00054 : QObject( parent, name ), d( new Private ) 00055 { 00056 KGlobal::locale()->insertCatalogue(name); 00057 00058 d->core = core; 00059 d->dcopClient = 0; 00060 d->newActions = new QPtrList<KAction>; 00061 d->part = 0; 00062 } 00063 00064 00065 Plugin::~Plugin() 00066 { 00067 delete d->part; 00068 delete d->dcopClient; 00069 delete d; 00070 } 00071 00072 void Plugin::setIdentifier( const QString &identifier ) 00073 { 00074 d->identifier = identifier; 00075 } 00076 00077 QString Plugin::identifier() const 00078 { 00079 return d->identifier; 00080 } 00081 00082 void Plugin::setTitle( const QString &title ) 00083 { 00084 d->title = title; 00085 } 00086 00087 QString Plugin::title() const 00088 { 00089 return d->title; 00090 } 00091 00092 void Plugin::setIcon( const QString &icon ) 00093 { 00094 d->icon = icon; 00095 } 00096 00097 QString Plugin::icon() const 00098 { 00099 return d->icon; 00100 } 00101 00102 void Plugin::setExecutableName( const QString& bin ) 00103 { 00104 d->executableName = bin; 00105 } 00106 00107 QString Plugin::executableName() const 00108 { 00109 return d->executableName; 00110 } 00111 00112 void Plugin::setPartLibraryName( const QCString &libName ) 00113 { 00114 d->partLibraryName = libName; 00115 } 00116 00117 KParts::Part *Plugin::loadPart() 00118 { 00119 return core()->createPart( d->partLibraryName ); 00120 } 00121 00122 const KAboutData *Plugin::aboutData() 00123 { 00124 kdDebug(5601) << "Plugin::aboutData(): libname: " << d->partLibraryName << endl; 00125 00126 const KInstance *instance = 00127 KParts::Factory::partInstanceFromLibrary( d->partLibraryName ); 00128 00129 if ( instance ) { 00130 return instance->aboutData(); 00131 } else { 00132 kdError() << "Plugin::aboutData(): Can't load instance for " 00133 << title() << endl; 00134 return 0; 00135 } 00136 } 00137 00138 KParts::Part *Plugin::part() 00139 { 00140 if ( !d->part ) { 00141 d->part = createPart(); 00142 if( d->part ) { 00143 connect( d->part, SIGNAL( destroyed() ), SLOT( partDestroyed() ) ); 00144 core()->partLoaded( this, d->part ); 00145 } 00146 } 00147 return d->part; 00148 } 00149 00150 QString Plugin::tipFile() const 00151 { 00152 return QString::null; 00153 } 00154 00155 00156 DCOPClient* Plugin::dcopClient() const 00157 { 00158 if ( !d->dcopClient ) { 00159 d->dcopClient = new DCOPClient(); 00160 // ### Note: maybe we could use executableName().latin1() instead here. 00161 // But this requires that dcopClient is NOT called by the constructor, 00162 // and is called by some new virtual void init() later on. 00163 d->dcopClient->registerAs( name(), false ); 00164 } 00165 00166 return d->dcopClient; 00167 } 00168 00169 void Plugin::insertNewAction( KAction *action ) 00170 { 00171 d->newActions->append( action ); 00172 } 00173 00174 QPtrList<KAction> *Plugin::newActions() const 00175 { 00176 return d->newActions; 00177 } 00178 00179 Kontact::Core *Plugin::core() const 00180 { 00181 return d->core; 00182 } 00183 00184 void Plugin::select() 00185 { 00186 } 00187 00188 void Plugin::configUpdated() 00189 { 00190 } 00191 00192 void Plugin::partDestroyed() 00193 { 00194 d->part = 0; 00195 } 00196 00197 void Plugin::bringToForeground() 00198 { 00199 if (!d->executableName.isEmpty()) 00200 KRun::runCommand(d->executableName); 00201 } 00202 00203 void Plugin::virtual_hook( int, void* ) { 00204 //BASE::virtual_hook( id, data ); 00205 } 00206 00207 #include "plugin.moc" 00208 00209 // vim: sw=2 et sts=2 tw=80
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:45 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003