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., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include <tqobjectlist.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 TQPtrList<KAction> *newActions; 00044 TQPtrList<KAction> *syncActions; 00045 TQString identifier; 00046 TQString title; 00047 TQString icon; 00048 TQString executableName; 00049 TQCString partLibraryName; 00050 bool hasPart; 00051 KParts::ReadOnlyPart *part; 00052 bool disabled; 00053 }; 00054 00055 00056 Plugin::Plugin( Kontact::Core *core, TQObject *parent, const char *name ) 00057 : KXMLGUIClient( core ), TQObject( parent, name ), d( new Private ) 00058 { 00059 core->factory()->addClient( this ); 00060 KGlobal::locale()->insertCatalogue(name); 00061 00062 d->core = core; 00063 d->dcopClient = 0; 00064 d->newActions = new TQPtrList<KAction>; 00065 d->syncActions = new TQPtrList<KAction>; 00066 d->hasPart = true; 00067 d->part = 0; 00068 d->disabled = false; 00069 } 00070 00071 00072 Plugin::~Plugin() 00073 { 00074 delete d->part; 00075 delete d->dcopClient; 00076 delete d; 00077 } 00078 00079 void Plugin::setIdentifier( const TQString &identifier ) 00080 { 00081 d->identifier = identifier; 00082 } 00083 00084 TQString Plugin::identifier() const 00085 { 00086 return d->identifier; 00087 } 00088 00089 void Plugin::setTitle( const TQString &title ) 00090 { 00091 d->title = title; 00092 } 00093 00094 TQString Plugin::title() const 00095 { 00096 return d->title; 00097 } 00098 00099 void Plugin::setIcon( const TQString &icon ) 00100 { 00101 d->icon = icon; 00102 } 00103 00104 TQString Plugin::icon() const 00105 { 00106 return d->icon; 00107 } 00108 00109 void Plugin::setExecutableName( const TQString& bin ) 00110 { 00111 d->executableName = bin; 00112 } 00113 00114 TQString Plugin::executableName() const 00115 { 00116 return d->executableName; 00117 } 00118 00119 void Plugin::setPartLibraryName( const TQCString &libName ) 00120 { 00121 d->partLibraryName = libName; 00122 } 00123 00124 KParts::ReadOnlyPart *Plugin::loadPart() 00125 { 00126 return core()->createPart( d->partLibraryName ); 00127 } 00128 00129 const KAboutData *Plugin::aboutData() 00130 { 00131 kdDebug(5601) << "Plugin::aboutData(): libname: " << d->partLibraryName << endl; 00132 00133 const KInstance *instance = 00134 KParts::Factory::partInstanceFromLibrary( d->partLibraryName ); 00135 00136 if ( instance ) { 00137 return instance->aboutData(); 00138 } else { 00139 kdError() << "Plugin::aboutData(): Can't load instance for " 00140 << title() << endl; 00141 return 0; 00142 } 00143 } 00144 00145 KParts::ReadOnlyPart *Plugin::part() 00146 { 00147 if ( !d->part ) { 00148 d->part = createPart(); 00149 if ( d->part ) { 00150 connect( d->part, TQT_SIGNAL( destroyed() ), TQT_SLOT( partDestroyed() ) ); 00151 core()->partLoaded( this, d->part ); 00152 } 00153 } 00154 return d->part; 00155 } 00156 00157 TQString Plugin::tipFile() const 00158 { 00159 return TQString(); 00160 } 00161 00162 00163 DCOPClient* Plugin::dcopClient() const 00164 { 00165 if ( !d->dcopClient ) { 00166 d->dcopClient = new DCOPClient(); 00167 // ### Note: maybe we could use executableName().latin1() instead here. 00168 // But this requires that dcopClient is NOT called by the constructor, 00169 // and is called by some new virtual void init() later on. 00170 d->dcopClient->registerAs( name(), false ); 00171 } 00172 00173 return d->dcopClient; 00174 } 00175 00176 void Plugin::insertNewAction( KAction *action ) 00177 { 00178 d->newActions->append( action ); 00179 } 00180 00181 void Plugin::insertSyncAction( KAction *action ) 00182 { 00183 d->syncActions->append( action ); 00184 } 00185 00186 TQPtrList<KAction> *Plugin::newActions() const 00187 { 00188 return d->newActions; 00189 } 00190 00191 TQPtrList<KAction> *Plugin::syncActions() const 00192 { 00193 return d->syncActions; 00194 } 00195 00196 Kontact::Core *Plugin::core() const 00197 { 00198 return d->core; 00199 } 00200 00201 void Plugin::select() 00202 { 00203 } 00204 00205 void Plugin::configUpdated() 00206 { 00207 } 00208 00209 void Plugin::partDestroyed() 00210 { 00211 d->part = 0; 00212 } 00213 00214 void Plugin::slotConfigUpdated() 00215 { 00216 configUpdated(); 00217 } 00218 00219 void Plugin::bringToForeground() 00220 { 00221 if (!d->executableName.isEmpty()) 00222 KRun::runCommand(d->executableName); 00223 } 00224 00225 bool Kontact::Plugin::showInSideBar() const 00226 { 00227 return d->hasPart; 00228 } 00229 00230 void Kontact::Plugin::setShowInSideBar( bool hasPart ) 00231 { 00232 d->hasPart = hasPart; 00233 } 00234 00235 void Kontact::Plugin::setDisabled( bool disabled ) 00236 { 00237 d->disabled = disabled; 00238 } 00239 00240 bool Kontact::Plugin::disabled() const 00241 { 00242 return d->disabled; 00243 } 00244 00245 void Kontact::Plugin::loadProfile( const TQString& ) 00246 { 00247 } 00248 00249 void Kontact::Plugin::saveToProfile( const TQString& ) const 00250 { 00251 } 00252 00253 void Plugin::virtual_hook( int, void* ) { 00254 //BASE::virtual_hook( id, data ); 00255 } 00256 00257 #include "plugin.moc" 00258 00259 // vim: sw=2 et sts=2 tw=80