kocore.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qwidget.h>
00025
00026 #include <klibloader.h>
00027 #include <kdebug.h>
00028 #include <kconfig.h>
00029
00030 #include <calendar/plugin.h>
00031 #include <korganizer/part.h>
00032
00033 #include "koprefs.h"
00034
00035 #include "kocore.h"
00036
00037 KOCore *KOCore::mSelf = 0;
00038
00039 KOCore *KOCore::self()
00040 {
00041 if (!mSelf) {
00042 mSelf = new KOCore;
00043 }
00044
00045 return mSelf;
00046 }
00047
00048 KOCore::KOCore() :
00049 mCalendarDecorationsLoaded( false ), mHolidays( 0 )
00050 {
00051 KGlobal::config()->setGroup("General");
00052 QString calSystem = KGlobal::config()->readEntry( "CalendarSystem", "gregorian" );
00053 mCalendarSystem = KCalendarSystemFactory::create( calSystem );
00054 }
00055
00056 KTrader::OfferList KOCore::availablePlugins(const QString &type)
00057 {
00058 return KTrader::self()->query(type);
00059 }
00060
00061 KOrg::Plugin *KOCore::loadPlugin(KService::Ptr service)
00062 {
00063 kdDebug() << "loadPlugin: library: " << service->library() << endl;
00064
00065 if ( !service->hasServiceType( "Calendar/Plugin" ) ) {
00066 return 0;
00067 }
00068
00069 KLibFactory *factory = KLibLoader::self()->factory(service->library());
00070
00071 if (!factory) {
00072 kdDebug() << "KOCore::loadPlugin(): Factory creation failed" << endl;
00073 return 0;
00074 }
00075
00076 KOrg::PluginFactory *pluginFactory = static_cast<KOrg::PluginFactory *>(factory);
00077
00078 if (!pluginFactory) {
00079 kdDebug() << "KOCore::loadPlugin(): Cast to KOrg::PluginFactory failed" << endl;
00080 return 0;
00081 }
00082
00083 return pluginFactory->create();
00084 }
00085
00086 KOrg::Plugin *KOCore::loadPlugin(const QString &name)
00087 {
00088 KTrader::OfferList list = availablePlugins("Calendar/Plugin");
00089 KTrader::OfferList::ConstIterator it;
00090 for(it = list.begin(); it != list.end(); ++it) {
00091 if ((*it)->desktopEntryName() == name) {
00092 return loadPlugin(*it);
00093 }
00094 }
00095 return 0;
00096 }
00097
00098 KOrg::CalendarDecoration *KOCore::loadCalendarDecoration(KService::Ptr service)
00099 {
00100 kdDebug() << "loadCalendarDecoration: library: " << service->library() << endl;
00101
00102 KLibFactory *factory = KLibLoader::self()->factory(service->library());
00103
00104 if (!factory) {
00105 kdDebug() << "KOCore::loadCalendarDecoration(): Factory creation failed" << endl;
00106 return 0;
00107 }
00108
00109 KOrg::CalendarDecorationFactory *pluginFactory =
00110 static_cast<KOrg::CalendarDecorationFactory *>(factory);
00111
00112 if (!pluginFactory) {
00113 kdDebug() << "KOCore::loadCalendarDecoration(): Cast failed" << endl;
00114 return 0;
00115 }
00116
00117 return pluginFactory->create();
00118 }
00119
00120 KOrg::CalendarDecoration *KOCore::loadCalendarDecoration(const QString &name)
00121 {
00122 KTrader::OfferList list = availablePlugins("Calendar/Decoration");
00123 KTrader::OfferList::ConstIterator it;
00124 for(it = list.begin(); it != list.end(); ++it) {
00125 if ((*it)->desktopEntryName() == name) {
00126 return loadCalendarDecoration(*it);
00127 }
00128 }
00129 return 0;
00130 }
00131
00132 KOrg::Part *KOCore::loadPart(KService::Ptr service, KOrg::MainWindow *parent)
00133 {
00134 kdDebug() << "loadPart: library: " << service->library() << endl;
00135
00136 if ( !service->hasServiceType( "KOrganizer/Part" ) ) {
00137 return 0;
00138 }
00139
00140 KLibFactory *factory = KLibLoader::self()->factory(service->library());
00141
00142 if (!factory) {
00143 kdDebug() << "KOCore::loadPart(): Factory creation failed" << endl;
00144 return 0;
00145 }
00146
00147 KOrg::PartFactory *pluginFactory =
00148 static_cast<KOrg::PartFactory *>(factory);
00149
00150 if (!pluginFactory) {
00151 kdDebug() << "KOCore::loadPart(): Cast failed" << endl;
00152 return 0;
00153 }
00154
00155 return pluginFactory->create(parent);
00156 }
00157
00158 KOrg::Part *KOCore::loadPart(const QString &name,KOrg::MainWindow *parent)
00159 {
00160 KTrader::OfferList list = availablePlugins("KOrg::MainWindow/Part");
00161 KTrader::OfferList::ConstIterator it;
00162 for(it = list.begin(); it != list.end(); ++it) {
00163 if ((*it)->desktopEntryName() == name) {
00164 return loadPart(*it,parent);
00165 }
00166 }
00167 return 0;
00168 }
00169
00170 KOrg::CalendarDecoration::List KOCore::calendarDecorations()
00171 {
00172 if (!mCalendarDecorationsLoaded) {
00173 QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
00174
00175 mCalendarDecorations.clear();
00176 KTrader::OfferList plugins = availablePlugins("Calendar/Decoration");
00177 KTrader::OfferList::ConstIterator it;
00178 for(it = plugins.begin(); it != plugins.end(); ++it) {
00179 if ((*it)->hasServiceType("Calendar/Decoration")) {
00180 QString name = (*it)->desktopEntryName();
00181 if ( selectedPlugins.find( name ) != selectedPlugins.end() ) {
00182 KOrg::CalendarDecoration *d = loadCalendarDecoration(*it);
00183 mCalendarDecorations.append( d );
00184 if ( name == "holidays" ) mHolidays = d;
00185 }
00186 }
00187 }
00188 mCalendarDecorationsLoaded = true;
00189 }
00190
00191 return mCalendarDecorations;
00192 }
00193
00194 KOrg::Part::List KOCore::loadParts( KOrg::MainWindow *parent )
00195 {
00196 KOrg::Part::List parts;
00197
00198 QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
00199
00200 KTrader::OfferList plugins = availablePlugins("KOrganizer/Part");
00201 KTrader::OfferList::ConstIterator it;
00202 for(it = plugins.begin(); it != plugins.end(); ++it) {
00203 if (selectedPlugins.find((*it)->desktopEntryName()) != selectedPlugins.end()) {
00204 KOrg::Part *part = loadPart(*it,parent);
00205 if ( part ) {
00206 parent->guiFactory()->addClient( part );
00207 parts.append( part );
00208 }
00209 }
00210 }
00211 return parts;
00212 }
00213
00214 void KOCore::unloadPlugins()
00215 {
00216 KOrg::CalendarDecoration *plugin;
00217 for( plugin=mCalendarDecorations.first(); plugin; plugin=mCalendarDecorations.next() ) {
00218 delete plugin;
00219 }
00220 mCalendarDecorations.clear();
00221 mCalendarDecorationsLoaded = false;
00222 mHolidays = 0;
00223 }
00224
00225 void KOCore::unloadParts( KOrg::MainWindow *parent, KOrg::Part::List& parts )
00226 {
00227 KOrg::Part *part;
00228 for( part=parts.first(); part; part=parts.next() ) {
00229 parent->guiFactory()->removeClient( part );
00230 delete part;
00231 }
00232 parts.clear();
00233 }
00234
00235 KOrg::Part::List KOCore::reloadParts( KOrg::MainWindow *parent, KOrg::Part::List& parts )
00236 {
00237 unloadParts( parent, parts );
00238 return loadParts( parent );
00239 }
00240
00241 void KOCore::reloadPlugins()
00242 {
00243 mCalendarDecorationsLoaded = false;
00244
00245 unloadPlugins();
00246 calendarDecorations();
00247 }
00248
00249 QString KOCore::holiday(const QDate &date)
00250 {
00251 calendarDecorations();
00252 if (mHolidays)
00253 return mHolidays->shortText(date);
00254 else
00255 return QString::null;
00256 }
00257
00258 KCalendarSystem* KOCore::calendarSystem() {
00259 return mCalendarSystem;
00260 }
This file is part of the documentation for kdelibs Version 3.1.4.