kontact
plugin.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 QPtrList<KAction> *syncActions;
00045 QString identifier;
00046 QString title;
00047 QString icon;
00048 QString executableName;
00049 QCString partLibraryName;
00050 bool hasPart;
00051 KParts::ReadOnlyPart *part;
00052 bool disabled;
00053 };
00054
00055
00056 Plugin::Plugin( Kontact::Core *core, QObject *parent, const char *name )
00057 : KXMLGUIClient( core ), QObject( 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 QPtrList<KAction>;
00065 d->syncActions = new QPtrList<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 QString &identifier )
00080 {
00081 d->identifier = identifier;
00082 }
00083
00084 QString Plugin::identifier() const
00085 {
00086 return d->identifier;
00087 }
00088
00089 void Plugin::setTitle( const QString &title )
00090 {
00091 d->title = title;
00092 }
00093
00094 QString Plugin::title() const
00095 {
00096 return d->title;
00097 }
00098
00099 void Plugin::setIcon( const QString &icon )
00100 {
00101 d->icon = icon;
00102 }
00103
00104 QString Plugin::icon() const
00105 {
00106 return d->icon;
00107 }
00108
00109 void Plugin::setExecutableName( const QString& bin )
00110 {
00111 d->executableName = bin;
00112 }
00113
00114 QString Plugin::executableName() const
00115 {
00116 return d->executableName;
00117 }
00118
00119 void Plugin::setPartLibraryName( const QCString &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, SIGNAL( destroyed() ), SLOT( partDestroyed() ) );
00151 core()->partLoaded( this, d->part );
00152 }
00153 }
00154 return d->part;
00155 }
00156
00157 QString Plugin::tipFile() const
00158 {
00159 return QString::null;
00160 }
00161
00162
00163 DCOPClient* Plugin::dcopClient() const
00164 {
00165 if ( !d->dcopClient ) {
00166 d->dcopClient = new DCOPClient();
00167
00168
00169
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 QPtrList<KAction> *Plugin::newActions() const
00187 {
00188 return d->newActions;
00189 }
00190
00191 QPtrList<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 QString& )
00246 {
00247 }
00248
00249 void Kontact::Plugin::saveToProfile( const QString& ) const
00250 {
00251 }
00252
00253 void Plugin::virtual_hook( int, void* ) {
00254
00255 }
00256
00257 #include "plugin.moc"
00258
00259
|