plugin.cpp
1 /*
2  This file is part of KDE Kontact.
3 
4  Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org>
5  Copyright (c) 2002-2003 Daniel Molkentin <molkentin@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include <tqobjectlist.h>
24 
25 #include <dcopclient.h>
26 #include <tdeaboutdata.h>
27 #include <tdeglobal.h>
28 #include <tdeparts/componentfactory.h>
29 #include <kdebug.h>
30 #include <kinstance.h>
31 #include <krun.h>
32 
33 #include "core.h"
34 #include "plugin.h"
35 
36 using namespace Kontact;
37 
38 class Plugin::Private
39 {
40  public:
41  Kontact::Core *core;
42  DCOPClient *dcopClient;
43  TQPtrList<TDEAction> *newActions;
44  TQPtrList<TDEAction> *syncActions;
45  TQString identifier;
46  TQString title;
47  TQString icon;
48  TQString executableName;
49  TQCString partLibraryName;
50  bool hasPart;
51  KParts::ReadOnlyPart *part;
52  bool disabled;
53 };
54 
55 
56 Plugin::Plugin( Kontact::Core *core, TQObject *parent, const char *name )
57  : KXMLGUIClient( core ), TQObject( parent, name ), d( new Private )
58 {
59  core->factory()->addClient( this );
60  TDEGlobal::locale()->insertCatalogue(name);
61 
62  d->core = core;
63  d->dcopClient = 0;
64  d->newActions = new TQPtrList<TDEAction>;
65  d->syncActions = new TQPtrList<TDEAction>;
66  d->hasPart = true;
67  d->part = 0;
68  d->disabled = false;
69 }
70 
71 
72 Plugin::~Plugin()
73 {
74  delete d->part;
75  delete d->dcopClient;
76  delete d;
77 }
78 
79 void Plugin::setIdentifier( const TQString &identifier )
80 {
81  d->identifier = identifier;
82 }
83 
84 TQString Plugin::identifier() const
85 {
86  return d->identifier;
87 }
88 
89 void Plugin::setTitle( const TQString &title )
90 {
91  d->title = title;
92 }
93 
94 TQString Plugin::title() const
95 {
96  return d->title;
97 }
98 
99 void Plugin::setIcon( const TQString &icon )
100 {
101  d->icon = icon;
102 }
103 
104 TQString Plugin::icon() const
105 {
106  return d->icon;
107 }
108 
109 void Plugin::setExecutableName( const TQString& bin )
110 {
111  d->executableName = bin;
112 }
113 
114 TQString Plugin::executableName() const
115 {
116  return d->executableName;
117 }
118 
119 void Plugin::setPartLibraryName( const TQCString &libName )
120 {
121  d->partLibraryName = libName;
122 }
123 
124 KParts::ReadOnlyPart *Plugin::loadPart()
125 {
126  return core()->createPart( d->partLibraryName );
127 }
128 
129 const TDEAboutData *Plugin::aboutData()
130 {
131  kdDebug(5601) << "Plugin::aboutData(): libname: " << d->partLibraryName << endl;
132 
133  const TDEInstance *instance =
134  KParts::Factory::partInstanceFromLibrary( d->partLibraryName );
135 
136  if ( instance ) {
137  return instance->aboutData();
138  } else {
139  kdError() << "Plugin::aboutData(): Can't load instance for "
140  << title() << endl;
141  return 0;
142  }
143 }
144 
145 KParts::ReadOnlyPart *Plugin::part()
146 {
147  if ( !d->part ) {
148  d->part = createPart();
149  if ( d->part ) {
150  connect( d->part, TQ_SIGNAL( destroyed() ), TQ_SLOT( partDestroyed() ) );
151  core()->partLoaded( this, d->part );
152  }
153  }
154  return d->part;
155 }
156 
157 TQString Plugin::tipFile() const
158 {
159  return TQString();
160 }
161 
162 
163 DCOPClient* Plugin::dcopClient() const
164 {
165  if ( !d->dcopClient ) {
166  d->dcopClient = new DCOPClient();
167  // ### Note: maybe we could use executableName().latin1() instead here.
168  // But this requires that dcopClient is NOT called by the constructor,
169  // and is called by some new virtual void init() later on.
170  d->dcopClient->registerAs( name(), false );
171  }
172 
173  return d->dcopClient;
174 }
175 
176 void Plugin::insertNewAction( TDEAction *action )
177 {
178  d->newActions->append( action );
179 }
180 
181 void Plugin::insertSyncAction( TDEAction *action )
182 {
183  d->syncActions->append( action );
184 }
185 
186 TQPtrList<TDEAction> *Plugin::newActions() const
187 {
188  return d->newActions;
189 }
190 
191 TQPtrList<TDEAction> *Plugin::syncActions() const
192 {
193  return d->syncActions;
194 }
195 
196 Kontact::Core *Plugin::core() const
197 {
198  return d->core;
199 }
200 
202 {
203 }
204 
206 {
207 }
208 
209 void Plugin::partDestroyed()
210 {
211  d->part = 0;
212 }
213 
215 {
216  configUpdated();
217 }
218 
220 {
221  if (!d->executableName.isEmpty())
222  KRun::runCommand(d->executableName);
223 }
224 
226 {
227  return d->hasPart;
228 }
229 
231 {
232  d->hasPart = hasPart;
233 }
234 
235 void Kontact::Plugin::setDisabled( bool disabled )
236 {
237  d->disabled = disabled;
238 }
239 
240 bool Kontact::Plugin::disabled() const
241 {
242  return d->disabled;
243 }
244 
245 void Kontact::Plugin::loadProfile( const TQString& )
246 {
247 }
248 
249 void Kontact::Plugin::saveToProfile( const TQString& ) const
250 {
251 }
252 
253 void Plugin::virtual_hook( int, void* ) {
254  //BASE::virtual_hook( id, data );
255 }
256 
257 #include "plugin.moc"
This class provides the interface to the Kontact core for the plugins.
Definition: core.h:42
Plugin(Core *core, TQObject *parent, const char *name)
Creates a new Plugin, note that name parameter name is required if you want your plugin to do dcop vi...
Definition: plugin.cpp:56
virtual const TDEAboutData * aboutData()
Reimplement this method if you want to add your credits to the Kontact about dialog.
Definition: plugin.cpp:129
KParts::ReadOnlyPart * part()
You can use this method if you need to access the current part.
Definition: plugin.cpp:145
DCOPClient * dcopClient() const
Retrieve the current DCOP Client for the plugin.
Definition: plugin.cpp:163
TQString executableName() const
Returns the name of the binary (if existant).
Definition: plugin.cpp:114
TQString title() const
Returns the localized title.
Definition: plugin.cpp:94
virtual KParts::ReadOnlyPart * createPart()=0
Reimplement and return the part here.
void slotConfigUpdated()
internal usage
Definition: plugin.cpp:214
void insertNewAction(TDEAction *action)
Insert "New" action.
Definition: plugin.cpp:176
virtual bool showInSideBar() const
Returns whether the plugin provides a part that should be shown in the sidebar.
Definition: plugin.cpp:225
void setTitle(const TQString &title)
Sets the localized title.
Definition: plugin.cpp:89
void setIcon(const TQString &icon)
Sets the icon name.
Definition: plugin.cpp:99
TQPtrList< TDEAction > * syncActions() const
FIXME: write API doc for Kontact::Plugin::syncActions().
Definition: plugin.cpp:191
virtual void bringToForeground()
Reimplement this method if your application needs a different approach to be brought in the foregroun...
Definition: plugin.cpp:219
void setPartLibraryName(const TQCString &)
Set name of library which contains the KPart used by this plugin.
Definition: plugin.cpp:119
void setIdentifier(const TQString &identifier)
Sets the identifier.
Definition: plugin.cpp:79
void insertSyncAction(TDEAction *action)
Insert "Sync" action.
Definition: plugin.cpp:181
virtual TQString tipFile() const
Reimplement this method and return the a path relative to "data" to the tips file.
Definition: plugin.cpp:157
virtual void select()
This function is called when the plugin is selected by the user before the widget of the KPart belong...
Definition: plugin.cpp:201
TQString identifier() const
Returns the identifier.
Definition: plugin.cpp:84
TQString icon() const
Returns the icon name.
Definition: plugin.cpp:104
virtual void configUpdated()
This function is called whenever the config dialog has been closed successfully.
Definition: plugin.cpp:205
void setShowInSideBar(bool hasPart)
Set if the plugin provides a part that should be shown in the sidebar.
Definition: plugin.cpp:230
TQPtrList< TDEAction > * newActions() const
FIXME: write API doc for Kontact::Plugin::newActions().
Definition: plugin.cpp:186
void setExecutableName(const TQString &bin)
Sets the name of executable (if existant).
Definition: plugin.cpp:109