29 #include "koglobals.h"
30 #include "koidentitymanager.h"
32 #include <calendar/plugin.h>
33 #include <korganizer/part.h>
35 #include <klibloader.h>
37 #include <tdeconfig.h>
38 #include <kxmlguifactory.h>
39 #include <kstandarddirs.h>
40 #include <tdelocale.h>
44 KOCore *KOCore::mSelf = 0;
46 KOCore *KOCore::self()
56 : mCalendarDecorationsLoaded( false ), mIdentityManager( 0 )
65 TDETrader::OfferList KOCore::availablePlugins(
const TQString &type,
int version )
69 constraint = TQString(
"[X-TDE-PluginInterfaceVersion] == %1")
70 .arg( TQString::number( version ) );
73 return TDETrader::self()->query( type, constraint );
76 TDETrader::OfferList KOCore::availablePlugins()
78 return availablePlugins( KOrg::Plugin::serviceType(),
79 KOrg::Plugin::interfaceVersion() );
82 TDETrader::OfferList KOCore::availableCalendarDecorations()
84 return availablePlugins( KOrg::CalendarDecoration::serviceType(),
85 KOrg::CalendarDecoration::interfaceVersion() );
88 TDETrader::OfferList KOCore::availableParts()
90 return availablePlugins( KOrg::Part::serviceType(),
91 KOrg::Part::interfaceVersion() );
94 TDETrader::OfferList KOCore::availablePrintPlugins()
96 return availablePlugins( KOrg::PrintPlugin::serviceType(),
97 KOrg::PrintPlugin::interfaceVersion() );
100 KOrg::Plugin *KOCore::loadPlugin( KService::Ptr service )
102 kdDebug(5850) <<
"loadPlugin: library: " << service->library() << endl;
104 if ( !service->hasServiceType( KOrg::Plugin::serviceType() ) ) {
108 KLibFactory *factory = KLibLoader::self()->factory(
109 service->library().latin1() );
112 kdDebug(5850) <<
"KOCore::loadPlugin(): Factory creation failed" << endl;
116 KOrg::PluginFactory *pluginFactory =
117 static_cast<KOrg::PluginFactory *
>( factory );
119 if ( !pluginFactory ) {
120 kdDebug(5850) <<
"KOCore::loadPlugin(): Cast to KOrg::PluginFactory failed" << endl;
124 return pluginFactory->create();
127 KOrg::Plugin *KOCore::loadPlugin(
const TQString &name )
129 TDETrader::OfferList list = availablePlugins();
130 TDETrader::OfferList::ConstIterator it;
131 for( it = list.begin(); it != list.end(); ++it ) {
132 if ( (*it)->desktopEntryName() == name ) {
133 return loadPlugin( *it );
141 kdDebug(5850) <<
"loadCalendarDecoration: library: " << service->library() << endl;
143 KLibFactory *factory = KLibLoader::self()->factory(service->library().latin1());
146 kdDebug(5850) <<
"KOCore::loadCalendarDecoration(): Factory creation failed" << endl;
150 KOrg::CalendarDecorationFactory *pluginFactory =
151 static_cast<KOrg::CalendarDecorationFactory *
>(factory);
153 if (!pluginFactory) {
154 kdDebug(5850) <<
"KOCore::loadCalendarDecoration(): Cast failed" << endl;
158 return pluginFactory->create();
163 TDETrader::OfferList list = availableCalendarDecorations();
164 TDETrader::OfferList::ConstIterator it;
165 for( it = list.begin(); it != list.end(); ++it ) {
166 if ( (*it)->desktopEntryName() == name ) {
167 return loadCalendarDecoration( *it );
173 KOrg::Part *KOCore::loadPart( KService::Ptr service,
KOrg::MainWindow *parent )
175 kdDebug(5850) <<
"loadPart: library: " << service->library() << endl;
177 if ( !service->hasServiceType( KOrg::Part::serviceType() ) ) {
181 KLibFactory *factory = KLibLoader::self()->factory(
182 service->library().latin1() );
185 kdDebug(5850) <<
"KOCore::loadPart(): Factory creation failed" << endl;
189 KOrg::PartFactory *pluginFactory =
190 static_cast<KOrg::PartFactory *
>( factory );
192 if ( !pluginFactory ) {
193 kdDebug(5850) <<
"KOCore::loadPart(): Cast failed" << endl;
197 return pluginFactory->create( parent );
202 kdDebug(5850) <<
"loadPart: print plugin in library: " << service->library() << endl;
204 if ( !service->hasServiceType( KOrg::PrintPlugin::serviceType() ) ) {
208 KLibFactory *factory = KLibLoader::self()->factory(
209 service->library().latin1() );
212 kdDebug(5850) <<
"KOCore::loadPrintPlugin(): Factory creation failed" << endl;
216 KOrg::PrintPluginFactory *pluginFactory =
217 static_cast<KOrg::PrintPluginFactory *
>( factory );
219 if ( !pluginFactory ) {
220 kdDebug(5850) <<
"KOCore::loadPrintPlugins(): Cast failed" << endl;
224 return pluginFactory->create();
227 void KOCore::addXMLGUIClient( TQWidget *wdg, KXMLGUIClient *guiclient )
229 mXMLGUIClients.insert( wdg, guiclient );
232 void KOCore::removeXMLGUIClient( TQWidget *wdg )
234 mXMLGUIClients.remove( wdg );
237 KXMLGUIClient* KOCore::xmlguiClient( TQWidget *wdg )
const
239 TQWidget *topLevel = wdg->topLevelWidget();
240 TQMap<TQWidget*, KXMLGUIClient*>::ConstIterator it = mXMLGUIClients.find( topLevel );
241 if ( it != mXMLGUIClients.end() )
247 KOrg::Part *KOCore::loadPart(
const TQString &name,
KOrg::MainWindow *parent )
249 TDETrader::OfferList list = availableParts();
250 TDETrader::OfferList::ConstIterator it;
251 for( it = list.begin(); it != list.end(); ++it ) {
252 if ( (*it)->desktopEntryName() == name ) {
253 return loadPart( *it, parent );
261 TDETrader::OfferList list = availablePrintPlugins();
262 TDETrader::OfferList::ConstIterator it;
263 for( it = list.begin(); it != list.end(); ++it ) {
264 if ( (*it)->desktopEntryName() == name ) {
265 return loadPrintPlugin( *it );
271 KOrg::CalendarDecoration::List KOCore::calendarDecorations()
273 if ( !mCalendarDecorationsLoaded ) {
274 TQStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
276 mCalendarDecorations.clear();
277 TDETrader::OfferList plugins = availableCalendarDecorations();
278 TDETrader::OfferList::ConstIterator it;
279 for( it = plugins.begin(); it != plugins.end(); ++it ) {
280 if ( (*it)->hasServiceType(
"Calendar/Decoration") ) {
281 TQString name = (*it)->desktopEntryName();
282 if ( selectedPlugins.find( name ) != selectedPlugins.end() ) {
284 mCalendarDecorations.append( d );
288 mCalendarDecorationsLoaded =
true;
291 return mCalendarDecorations;
296 KOrg::Part::List parts;
298 TQStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
300 TDETrader::OfferList plugins = availableParts();
301 TDETrader::OfferList::ConstIterator it;
302 for( it = plugins.begin(); it != plugins.end(); ++it ) {
303 if ( selectedPlugins.find( (*it)->desktopEntryName() ) !=
304 selectedPlugins.end() ) {
305 KOrg::Part *part = loadPart( *it, parent );
308 kdError() <<
"KOCore::loadParts(): parent has no mainGuiClient."
312 parts.append( part );
320 KOrg::PrintPlugin::List KOCore::loadPrintPlugins()
322 KOrg::PrintPlugin::List loadedPlugins;
324 TQStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
326 TDETrader::OfferList plugins = availablePrintPlugins();
327 TDETrader::OfferList::ConstIterator it;
328 for( it = plugins.begin(); it != plugins.end(); ++it ) {
329 if ( selectedPlugins.find( (*it)->desktopEntryName() ) !=
330 selectedPlugins.end() ) {
332 if ( part ) loadedPlugins.append( part );
335 return loadedPlugins;
338 void KOCore::unloadPlugins()
341 for( plugin = mCalendarDecorations.first(); plugin;
342 plugin = mCalendarDecorations.next() ) {
345 mCalendarDecorations.clear();
346 mCalendarDecorationsLoaded =
false;
349 void KOCore::unloadParts(
KOrg::MainWindow *parent, KOrg::Part::List &parts )
352 for( part = parts.first(); part; part = parts.next() ) {
360 KOrg::Part::List &parts )
362 KXMLGUIFactory *factory = parent->
mainGuiClient()->factory();
365 unloadParts( parent, parts );
366 KOrg::Part::List list = loadParts( parent );
373 void KOCore::reloadPlugins()
375 mCalendarDecorationsLoaded =
false;
378 calendarDecorations();
381 KPIM::IdentityManager* KOCore::identityManager()
383 if ( !mIdentityManager )
384 mIdentityManager =
new KOrg::IdentityManager;
385 return mIdentityManager;
This class provides the interface for a date dependent decoration.
interface for korganizer main window
virtual KXMLGUIClient * mainGuiClient()=0
Return XML GUI client of this main window.
Base class for KOrganizer printing classes.