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 QString identifier;
00045 QString title;
00046 QString icon;
00047 QString executableName;
00048 QCString partLibraryName;
00049 bool hasPart;
00050 KParts::ReadOnlyPart *part;
00051 };
00052
00053
00054 Plugin::Plugin( Kontact::Core *core, QObject *parent, const char *name )
00055 : KXMLGUIClient( core ), QObject( parent, name ), d( new Private )
00056 {
00057 core->factory()->addClient( this );
00058 KGlobal::locale()->insertCatalogue(name);
00059
00060 d->core = core;
00061 d->dcopClient = 0;
00062 d->newActions = new QPtrList<KAction>;
00063 d->hasPart = true;
00064 d->part = 0;
00065 }
00066
00067
00068 Plugin::~Plugin()
00069 {
00070 delete d->part;
00071 delete d->dcopClient;
00072 delete d;
00073 }
00074
00075 void Plugin::setIdentifier( const QString &identifier )
00076 {
00077 d->identifier = identifier;
00078 }
00079
00080 QString Plugin::identifier() const
00081 {
00082 return d->identifier;
00083 }
00084
00085 void Plugin::setTitle( const QString &title )
00086 {
00087 d->title = title;
00088 }
00089
00090 QString Plugin::title() const
00091 {
00092 return d->title;
00093 }
00094
00095 void Plugin::setIcon( const QString &icon )
00096 {
00097 d->icon = icon;
00098 }
00099
00100 QString Plugin::icon() const
00101 {
00102 return d->icon;
00103 }
00104
00105 void Plugin::setExecutableName( const QString& bin )
00106 {
00107 d->executableName = bin;
00108 }
00109
00110 QString Plugin::executableName() const
00111 {
00112 return d->executableName;
00113 }
00114
00115 void Plugin::setPartLibraryName( const QCString &libName )
00116 {
00117 d->partLibraryName = libName;
00118 }
00119
00120 KParts::ReadOnlyPart *Plugin::loadPart()
00121 {
00122 return core()->createPart( d->partLibraryName );
00123 }
00124
00125 const KAboutData *Plugin::aboutData()
00126 {
00127 kdDebug(5601) << "Plugin::aboutData(): libname: " << d->partLibraryName << endl;
00128
00129 const KInstance *instance =
00130 KParts::Factory::partInstanceFromLibrary( d->partLibraryName );
00131
00132 if ( instance ) {
00133 return instance->aboutData();
00134 } else {
00135 kdError() << "Plugin::aboutData(): Can't load instance for "
00136 << title() << endl;
00137 return 0;
00138 }
00139 }
00140
00141 KParts::ReadOnlyPart *Plugin::part()
00142 {
00143 if ( !d->part ) {
00144 d->part = createPart();
00145 if ( d->part ) {
00146 connect( d->part, SIGNAL( destroyed() ), SLOT( partDestroyed() ) );
00147 core()->partLoaded( this, d->part );
00148 }
00149 }
00150 return d->part;
00151 }
00152
00153 QString Plugin::tipFile() const
00154 {
00155 return QString::null;
00156 }
00157
00158
00159 DCOPClient* Plugin::dcopClient() const
00160 {
00161 if ( !d->dcopClient ) {
00162 d->dcopClient = new DCOPClient();
00163
00164
00165
00166 d->dcopClient->registerAs( name(), false );
00167 }
00168
00169 return d->dcopClient;
00170 }
00171
00172 void Plugin::insertNewAction( KAction *action )
00173 {
00174 d->newActions->append( action );
00175 }
00176
00177 QPtrList<KAction> *Plugin::newActions() const
00178 {
00179 return d->newActions;
00180 }
00181
00182 Kontact::Core *Plugin::core() const
00183 {
00184 return d->core;
00185 }
00186
00187 void Plugin::select()
00188 {
00189 }
00190
00191 void Plugin::configUpdated()
00192 {
00193 }
00194
00195 void Plugin::partDestroyed()
00196 {
00197 d->part = 0;
00198 }
00199
00200 void Plugin::slotConfigUpdated()
00201 {
00202 configUpdated();
00203 }
00204
00205 void Plugin::bringToForeground()
00206 {
00207 if (!d->executableName.isEmpty())
00208 KRun::runCommand(d->executableName);
00209 }
00210
00211 bool Kontact::Plugin::showInSideBar() const
00212 {
00213 return d->hasPart;
00214 }
00215
00216 void Kontact::Plugin::setShowInSideBar( bool hasPart )
00217 {
00218 d->hasPart = hasPart;
00219 }
00220
00221 void Plugin::virtual_hook( int, void* ) {
00222
00223 }
00224
00225 #include "plugin.moc"
00226
00227
|