• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
kocore.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program 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
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of Qt, and distribute the resulting executable,
23  without including the source code for Qt in the source distribution.
24 */
25 
26 #include "kocore.h"
27 #include "koprefs.h"
28 
29 #include <calendarsupport/identitymanager.h>
30 
31 #include <KDebug>
32 #include <KServiceTypeTrader>
33 #include <KXMLGUIFactory>
34 
35 KOCore *KOCore::mSelf = 0;
36 
37 KOCore *KOCore::self()
38 {
39  if ( !mSelf ) {
40  mSelf = new KOCore;
41  }
42 
43  return mSelf;
44 }
45 
46 KOCore::KOCore()
47  : mCalendarDecorationsLoaded( false ), mIdentityManager( 0 )
48 {
49 }
50 
51 KOCore::~KOCore()
52 {
53  mSelf = 0;
54 }
55 
56 KService::List KOCore::availablePlugins( const QString &type, int version )
57 {
58  QString constraint;
59  if ( version >= 0 ) {
60  constraint =
61  QString::fromLatin1( "[X-KDE-PluginInterfaceVersion] == %1" ).arg( QString::number( version ) );
62  }
63 
64  return KServiceTypeTrader::self()->query( type, constraint );
65 }
66 
67 KService::List KOCore::availablePlugins()
68 {
69  return availablePlugins( CalendarSupport::Plugin::serviceType(),
70  CalendarSupport::Plugin::interfaceVersion() );
71 }
72 
73 KService::List KOCore::availableCalendarDecorations()
74 {
75  return availablePlugins( EventViews::CalendarDecoration::Decoration::serviceType(),
76  EventViews::CalendarDecoration::Decoration::interfaceVersion() );
77 }
78 
79 KService::List KOCore::availableParts()
80 {
81  return availablePlugins( KOrg::Part::serviceType(), KOrg::Part::interfaceVersion() );
82 }
83 
84 KService::List KOCore::availablePrintPlugins()
85 {
86  return
87  availablePlugins( KOrg::PrintPlugin::serviceType(), KOrg::PrintPlugin::interfaceVersion() );
88 }
89 
90 CalendarSupport::Plugin *KOCore::loadPlugin( KService::Ptr service )
91 {
92  kDebug() << service->library();
93 
94  if ( !service->hasServiceType( CalendarSupport::Plugin::serviceType() ) ) {
95  return 0;
96  }
97 
98  KPluginLoader loader( *service );
99  KPluginFactory *factory = loader.factory();
100 
101  if ( !factory ) {
102  kDebug() << "Factory creation failed";
103  return 0;
104  }
105 
106  CalendarSupport::PluginFactory *pluginFactory =
107  static_cast<CalendarSupport::PluginFactory *>( factory );
108 
109  if ( !pluginFactory ) {
110  kDebug() << "Cast failed";
111  return 0;
112  }
113 
114  return pluginFactory->createPluginFactory();
115 }
116 
117 CalendarSupport::Plugin *KOCore::loadPlugin( const QString &name )
118 {
119  KService::List list = availablePlugins();
120  KService::List::ConstIterator it;
121  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
122  if ( (*it)->desktopEntryName() == name ) {
123  return loadPlugin( *it );
124  }
125  }
126  return 0;
127 }
128 
129 EventViews::CalendarDecoration::Decoration *KOCore::loadCalendarDecoration( KService::Ptr service )
130 {
131  KPluginLoader loader( *service );
132  KPluginFactory *factory = loader.factory();
133 
134  if ( !factory ) {
135  kDebug() << "Factory creation failed";
136  return 0;
137  }
138 
139  EventViews::CalendarDecoration::DecorationFactory *pluginFactory =
140  static_cast<EventViews::CalendarDecoration::DecorationFactory *>( factory );
141 
142  if ( !pluginFactory ) {
143  kDebug() << "Cast failed";
144  return 0;
145  }
146 
147  return pluginFactory->createPluginFactory();
148 }
149 
150 EventViews::CalendarDecoration::Decoration *KOCore::loadCalendarDecoration( const QString &name )
151 {
152  KService::List list = availableCalendarDecorations();
153  KService::List::ConstIterator it;
154  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
155  if ( (*it)->desktopEntryName() == name ) {
156  return loadCalendarDecoration( *it );
157  }
158  }
159  return 0;
160 }
161 
162 KOrg::Part *KOCore::loadPart( KService::Ptr service, KOrg::MainWindow *parent )
163 {
164  kDebug() << service->library();
165 
166  if ( !service->hasServiceType( KOrg::Part::serviceType() ) ) {
167  return 0;
168  }
169 
170  KPluginLoader loader( *service );
171  KPluginFactory *factory = loader.factory();
172 
173  if ( !factory ) {
174  kDebug() << "Factory creation failed";
175  return 0;
176  }
177 
178  KOrg::PartFactory *pluginFactory =
179  static_cast<KOrg::PartFactory *>( factory );
180 
181  if ( !pluginFactory ) {
182  kDebug() << "Cast failed";
183  return 0;
184  }
185 
186  return pluginFactory->createPluginFactory( parent );
187 }
188 
189 KOrg::PrintPlugin *KOCore::loadPrintPlugin( KService::Ptr service )
190 {
191  kDebug() << service->library();
192 
193  if ( !service->hasServiceType( KOrg::PrintPlugin::serviceType() ) ) {
194  return 0;
195  }
196 
197  KPluginLoader loader( *service );
198  KPluginFactory *factory = loader.factory();
199 
200  if ( !factory ) {
201  kDebug() << "Factory creation failed";
202  return 0;
203  }
204 
205  KOrg::PrintPluginFactory *pluginFactory =
206  static_cast<KOrg::PrintPluginFactory *>( factory );
207 
208  if ( !pluginFactory ) {
209  kDebug() << "Cast failed";
210  return 0;
211  }
212 
213  return pluginFactory->createPluginFactory();
214 }
215 
216 void KOCore::addXMLGUIClient( QWidget *wdg, KXMLGUIClient *guiclient )
217 {
218  mXMLGUIClients.insert( wdg, guiclient );
219 }
220 
221 void KOCore::removeXMLGUIClient( QWidget *wdg )
222 {
223  mXMLGUIClients.remove( wdg );
224 }
225 
226 KXMLGUIClient *KOCore::xmlguiClient( QWidget *wdg ) const
227 {
228  if ( !wdg ) {
229  return 0;
230  }
231 
232  QWidget *topLevel = wdg->topLevelWidget();
233  QMap<QWidget*, KXMLGUIClient*>::ConstIterator it = mXMLGUIClients.find( topLevel );
234  if ( it != mXMLGUIClients.constEnd() ) {
235  return it.value();
236  }
237 
238  return 0;
239 }
240 
241 KOrg::Part *KOCore::loadPart( const QString &name, KOrg::MainWindow *parent )
242 {
243  KService::List list = availableParts();
244  KService::List::ConstIterator it;
245  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
246  if ( (*it)->desktopEntryName() == name ) {
247  return loadPart( *it, parent );
248  }
249  }
250  return 0;
251 }
252 
253 KOrg::PrintPlugin *KOCore::loadPrintPlugin( const QString &name )
254 {
255  KService::List list = availablePrintPlugins();
256  KService::List::ConstIterator it;
257  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
258  if ( (*it)->desktopEntryName() == name ) {
259  return loadPrintPlugin( *it );
260  }
261  }
262  return 0;
263 }
264 
265 EventViews::CalendarDecoration::Decoration::List KOCore::loadCalendarDecorations()
266 {
267  if ( !mCalendarDecorationsLoaded ) {
268  QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
269 
270  mCalendarDecorations.clear();
271  KService::List plugins = availableCalendarDecorations();
272  KService::List::ConstIterator it;
273  for ( it = plugins.constBegin(); it != plugins.constEnd(); ++it ) {
274  if ( (*it)->hasServiceType( EventViews::CalendarDecoration::Decoration::serviceType() ) ) {
275  QString name = (*it)->desktopEntryName();
276  if ( selectedPlugins.contains( name ) ) {
277  EventViews::CalendarDecoration::Decoration *d = loadCalendarDecoration(*it);
278  mCalendarDecorations.append( d );
279  }
280  }
281  }
282  mCalendarDecorationsLoaded = true;
283  }
284 
285  return mCalendarDecorations;
286 }
287 
288 KOrg::Part::List KOCore::loadParts( KOrg::MainWindow *parent )
289 {
290  KOrg::Part::List parts;
291 
292  QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
293 
294  KService::List plugins = availableParts();
295  KService::List::ConstIterator it;
296  for ( it = plugins.constBegin(); it != plugins.constEnd(); ++it ) {
297  if ( selectedPlugins.contains( (*it)->desktopEntryName() ) ) {
298  KOrg::Part *part = loadPart( *it, parent );
299  if ( part ) {
300  if ( !parent->mainGuiClient() ) {
301  kError() << "parent has no mainGuiClient.";
302  } else {
303  parent->mainGuiClient()->insertChildClient( part );
304  parts.append( part );
305  }
306  }
307  }
308  }
309  return parts;
310 }
311 
312 KOrg::PrintPlugin::List KOCore::loadPrintPlugins()
313 {
314  KOrg::PrintPlugin::List loadedPlugins;
315 
316  EventViews::PrefsPtr viewPrefs = KOPrefs::instance()->eventViewsPreferences();
317  QStringList selectedPlugins = viewPrefs->selectedPlugins();
318 
319  KService::List plugins = availablePrintPlugins();
320  KService::List::ConstIterator it;
321  for ( it = plugins.constBegin(); it != plugins.constEnd(); ++it ) {
322  if ( selectedPlugins.contains( (*it)->desktopEntryName() ) ) {
323  KOrg::PrintPlugin *part = loadPrintPlugin( *it );
324  if ( part ) {
325  loadedPlugins.append( part );
326  }
327  }
328  }
329  return loadedPlugins;
330 }
331 
332 void KOCore::unloadPlugins()
333 {
334  qDeleteAll( mCalendarDecorations );
335  mCalendarDecorations.clear();
336  mCalendarDecorationsLoaded = false;
337 }
338 
339 void KOCore::unloadParts( KOrg::MainWindow *parent, KOrg::Part::List &parts )
340 {
341  foreach ( KOrg::Part *part, parts ) {
342  parent->mainGuiClient()->removeChildClient( part );
343  delete part;
344  }
345  parts.clear();
346 }
347 
348 KOrg::Part::List KOCore::reloadParts( KOrg::MainWindow *parent, KOrg::Part::List &parts )
349 {
350  KXMLGUIFactory *factory = parent->mainGuiClient()->factory();
351  factory->removeClient( parent->mainGuiClient() );
352 
353  unloadParts( parent, parts );
354  KOrg::Part::List list = loadParts( parent );
355 
356  factory->addClient( parent->mainGuiClient() );
357 
358  return list;
359 }
360 
361 void KOCore::reloadPlugins()
362 {
363  // TODO: does this still apply?
364  // Plugins should be unloaded, but e.g. komonthview keeps using the old ones
365  unloadPlugins();
366  loadCalendarDecorations();
367 }
368 
369 KPIMIdentities::IdentityManager *KOCore::identityManager()
370 {
371  if ( !mIdentityManager ) {
372  mIdentityManager = new CalendarSupport::IdentityManager;
373  }
374  return mIdentityManager;
375 }
KOrg::Part::interfaceVersion
static int interfaceVersion()
Definition: part.h:37
KOCore::reloadPlugins
void reloadPlugins()
Definition: kocore.cpp:361
KOCore::availablePlugins
KService::List availablePlugins()
Definition: kocore.cpp:67
KOPrefs::eventViewsPreferences
EventViews::PrefsPtr eventViewsPreferences() const
Definition: koprefs.cpp:135
KOCore::availablePrintPlugins
KService::List availablePrintPlugins()
Definition: kocore.cpp:84
KOCore::xmlguiClient
KXMLGUIClient * xmlguiClient(QWidget *) const
Definition: kocore.cpp:226
KOCore::loadCalendarDecorations
EventViews::CalendarDecoration::Decoration::List loadCalendarDecorations()
Definition: kocore.cpp:265
KOCore::loadParts
KOrg::Part::List loadParts(KOrg::MainWindow *parent)
Definition: kocore.cpp:288
KOrg::Part::serviceType
static QString serviceType()
Definition: part.h:42
QWidget
KOCore::unloadParts
void unloadParts(KOrg::MainWindow *parent, KOrg::Part::List &parts)
Unload the parts in &p parts for this main window.
Definition: kocore.cpp:339
KOrg::PrintPlugin::List
QList< PrintPlugin * > List
Definition: printplugin.h:69
KOCore::loadPrintPlugin
KOrg::PrintPlugin * loadPrintPlugin(KService::Ptr service)
Definition: kocore.cpp:189
KOCore::loadPrintPlugins
KOrg::PrintPlugin::List loadPrintPlugins()
Definition: kocore.cpp:312
KOrg::PrintPluginFactory::createPluginFactory
virtual PrintPlugin * createPluginFactory()=0
KOCore::identityManager
KPIMIdentities::IdentityManager * identityManager()
Definition: kocore.cpp:369
KOrg::Part
Definition: part.h:34
KOrg::Part::List
QList< Part * > List
Definition: part.h:47
KOrg::PrintPlugin
Base class for KOrganizer printing classes.
Definition: printplugin.h:62
KOrg::PartFactory
Definition: part.h:72
koprefs.h
KOCore::KOCore
KOCore()
Definition: kocore.cpp:46
KOCore::~KOCore
~KOCore()
Definition: kocore.cpp:51
KOCore::unloadPlugins
void unloadPlugins()
Definition: kocore.cpp:332
KOrg::MainWindow
interface for korganizer main window
Definition: mainwindow.h:44
KOCore::availableParts
KService::List availableParts()
Definition: kocore.cpp:79
KOCore::loadPlugin
CalendarSupport::Plugin * loadPlugin(KService::Ptr service)
Definition: kocore.cpp:90
KOrg::PrintPluginFactory
Definition: printplugin.h:186
KOCore::reloadParts
KOrg::Part::List reloadParts(KOrg::MainWindow *parent, KOrg::Part::List &parts)
Unloads the parts from the main window.
Definition: kocore.cpp:348
KOrg::MainWindow::mainGuiClient
virtual KXMLGUIClient * mainGuiClient()=0
Return XML GUI client of this main window.
KOPrefsBase::mSelectedPlugins
QStringList mSelectedPlugins
Definition: koprefs_base.h:3187
KOCore::addXMLGUIClient
void addXMLGUIClient(QWidget *, KXMLGUIClient *guiclient)
Definition: kocore.cpp:216
KOPrefs::instance
static KOPrefs * instance()
Get instance of KOPrefs.
Definition: koprefs.cpp:68
KOCore::removeXMLGUIClient
void removeXMLGUIClient(QWidget *)
Definition: kocore.cpp:221
KOrg::PrintPlugin::serviceType
static QString serviceType()
Definition: printplugin.h:72
KOrg::PartFactory::createPluginFactory
virtual Part * createPluginFactory(MainWindow *parent)=0
KPluginFactory
KOCore::loadPart
KOrg::Part * loadPart(KService::Ptr, KOrg::MainWindow *parent)
Definition: kocore.cpp:162
kocore.h
KOCore::availableCalendarDecorations
KService::List availableCalendarDecorations()
Definition: kocore.cpp:73
KOCore::self
static KOCore * self()
Definition: kocore.cpp:37
KOCore::loadCalendarDecoration
EventViews::CalendarDecoration::Decoration * loadCalendarDecoration(KService::Ptr service)
Definition: kocore.cpp:129
KOCore
Definition: kocore.h:41
KOrg::PrintPlugin::interfaceVersion
static int interfaceVersion()
Definition: printplugin.h:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal