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

korganizer

  • sources
  • kde-4.14
  • 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 "prefs/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 CalendarSupport::Plugin *KOCore::loadPlugin( KService::Ptr service )
85 {
86  kDebug() << service->library();
87 
88  if ( !service->hasServiceType( CalendarSupport::Plugin::serviceType() ) ) {
89  return 0;
90  }
91 
92  KPluginLoader loader( *service );
93  KPluginFactory *factory = loader.factory();
94 
95  if ( !factory ) {
96  kDebug() << "Factory creation failed";
97  return 0;
98  }
99 
100  CalendarSupport::PluginFactory *pluginFactory =
101  static_cast<CalendarSupport::PluginFactory *>( factory );
102 
103  if ( !pluginFactory ) {
104  kDebug() << "Cast failed";
105  return 0;
106  }
107 
108  return pluginFactory->createPluginFactory();
109 }
110 
111 CalendarSupport::Plugin *KOCore::loadPlugin( const QString &name )
112 {
113  KService::List list = availablePlugins();
114  KService::List::ConstIterator it;
115  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
116  if ( (*it)->desktopEntryName() == name ) {
117  return loadPlugin( *it );
118  }
119  }
120  return 0;
121 }
122 
123 EventViews::CalendarDecoration::Decoration *KOCore::loadCalendarDecoration( KService::Ptr service )
124 {
125  KPluginLoader loader( *service );
126  KPluginFactory *factory = loader.factory();
127 
128  if ( !factory ) {
129  kDebug() << "Factory creation failed";
130  return 0;
131  }
132 
133  EventViews::CalendarDecoration::DecorationFactory *pluginFactory =
134  static_cast<EventViews::CalendarDecoration::DecorationFactory *>( factory );
135 
136  if ( !pluginFactory ) {
137  kDebug() << "Cast failed";
138  return 0;
139  }
140 
141  return pluginFactory->createPluginFactory();
142 }
143 
144 EventViews::CalendarDecoration::Decoration *KOCore::loadCalendarDecoration( const QString &name )
145 {
146  KService::List list = availableCalendarDecorations();
147  KService::List::ConstIterator it;
148  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
149  if ( (*it)->desktopEntryName() == name ) {
150  return loadCalendarDecoration( *it );
151  }
152  }
153  return 0;
154 }
155 
156 KOrg::Part *KOCore::loadPart( KService::Ptr service, KOrg::MainWindow *parent )
157 {
158  kDebug() << service->library();
159 
160  if ( !service->hasServiceType( KOrg::Part::serviceType() ) ) {
161  return 0;
162  }
163 
164  KPluginLoader loader( *service );
165  KPluginFactory *factory = loader.factory();
166 
167  if ( !factory ) {
168  kDebug() << "Factory creation failed";
169  return 0;
170  }
171 
172  KOrg::PartFactory *pluginFactory =
173  static_cast<KOrg::PartFactory *>( factory );
174 
175  if ( !pluginFactory ) {
176  kDebug() << "Cast failed";
177  return 0;
178  }
179 
180  return pluginFactory->createPluginFactory( parent );
181 }
182 
183 void KOCore::addXMLGUIClient( QWidget *wdg, KXMLGUIClient *guiclient )
184 {
185  mXMLGUIClients.insert( wdg, guiclient );
186 }
187 
188 void KOCore::removeXMLGUIClient( QWidget *wdg )
189 {
190  mXMLGUIClients.remove( wdg );
191 }
192 
193 KXMLGUIClient *KOCore::xmlguiClient( QWidget *wdg ) const
194 {
195  if ( !wdg ) {
196  return 0;
197  }
198 
199  QWidget *topLevel = wdg->topLevelWidget();
200  QMap<QWidget*, KXMLGUIClient*>::ConstIterator it = mXMLGUIClients.find( topLevel );
201  if ( it != mXMLGUIClients.constEnd() ) {
202  return it.value();
203  }
204 
205  return 0;
206 }
207 
208 KOrg::Part *KOCore::loadPart( const QString &name, KOrg::MainWindow *parent )
209 {
210  KService::List list = availableParts();
211  KService::List::ConstIterator it;
212  for ( it = list.constBegin(); it != list.constEnd(); ++it ) {
213  if ( (*it)->desktopEntryName() == name ) {
214  return loadPart( *it, parent );
215  }
216  }
217  return 0;
218 }
219 
220 EventViews::CalendarDecoration::Decoration::List KOCore::loadCalendarDecorations()
221 {
222  if ( !mCalendarDecorationsLoaded ) {
223  QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
224 
225  mCalendarDecorations.clear();
226  KService::List plugins = availableCalendarDecorations();
227  KService::List::ConstIterator it;
228  for ( it = plugins.constBegin(); it != plugins.constEnd(); ++it ) {
229  if ( (*it)->hasServiceType( EventViews::CalendarDecoration::Decoration::serviceType() ) ) {
230  QString name = (*it)->desktopEntryName();
231  if ( selectedPlugins.contains( name ) ) {
232  EventViews::CalendarDecoration::Decoration *d = loadCalendarDecoration(*it);
233  mCalendarDecorations.append( d );
234  }
235  }
236  }
237  mCalendarDecorationsLoaded = true;
238  }
239 
240  return mCalendarDecorations;
241 }
242 
243 KOrg::Part::List KOCore::loadParts( KOrg::MainWindow *parent )
244 {
245  KOrg::Part::List parts;
246 
247  QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
248 
249  KService::List plugins = availableParts();
250  KService::List::ConstIterator it;
251  for ( it = plugins.constBegin(); it != plugins.constEnd(); ++it ) {
252  if ( selectedPlugins.contains( (*it)->desktopEntryName() ) ) {
253  KOrg::Part *part = loadPart( *it, parent );
254  if ( part ) {
255  if ( !parent->mainGuiClient() ) {
256  kError() << "parent has no mainGuiClient.";
257  } else {
258  parent->mainGuiClient()->insertChildClient( part );
259  parts.append( part );
260  }
261  }
262  }
263  }
264  return parts;
265 }
266 
267 void KOCore::unloadPlugins()
268 {
269  qDeleteAll( mCalendarDecorations );
270  mCalendarDecorations.clear();
271  mCalendarDecorationsLoaded = false;
272 }
273 
274 void KOCore::unloadParts( KOrg::MainWindow *parent, KOrg::Part::List &parts )
275 {
276  foreach ( KOrg::Part *part, parts ) {
277  parent->mainGuiClient()->removeChildClient( part );
278  delete part;
279  }
280  parts.clear();
281 }
282 
283 KOrg::Part::List KOCore::reloadParts( KOrg::MainWindow *parent, KOrg::Part::List &parts )
284 {
285  KXMLGUIFactory *factory = parent->mainGuiClient()->factory();
286  factory->removeClient( parent->mainGuiClient() );
287 
288  unloadParts( parent, parts );
289  KOrg::Part::List list = loadParts( parent );
290 
291  factory->addClient( parent->mainGuiClient() );
292 
293  return list;
294 }
295 
296 void KOCore::reloadPlugins()
297 {
298  // TODO: does this still apply?
299  // Plugins should be unloaded, but e.g. komonthview keeps using the old ones
300  unloadPlugins();
301  loadCalendarDecorations();
302 }
303 
304 KPIMIdentities::IdentityManager *KOCore::identityManager()
305 {
306  if ( !mIdentityManager ) {
307  mIdentityManager = new CalendarSupport::IdentityManager;
308  }
309  return mIdentityManager;
310 }
KOrg::Part::interfaceVersion
static int interfaceVersion()
Definition: part.h:37
QList::clear
void clear()
QWidget
KOCore::reloadPlugins
void reloadPlugins()
Definition: kocore.cpp:296
KOCore::availablePlugins
KService::List availablePlugins()
Definition: kocore.cpp:67
KOCore::xmlguiClient
KXMLGUIClient * xmlguiClient(QWidget *) const
Definition: kocore.cpp:193
KOCore::loadCalendarDecorations
EventViews::CalendarDecoration::Decoration::List loadCalendarDecorations()
Definition: kocore.cpp:220
KOCore::loadParts
KOrg::Part::List loadParts(KOrg::MainWindow *parent)
Definition: kocore.cpp:243
QMap
KOrg::Part::serviceType
static QString serviceType()
Definition: part.h:42
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
KOCore::unloadParts
void unloadParts(KOrg::MainWindow *parent, KOrg::Part::List &parts)
Unload the parts in &p parts for this main window.
Definition: kocore.cpp:274
KOCore::identityManager
KPIMIdentities::IdentityManager * identityManager()
Definition: kocore.cpp:304
KOrg::Part
Definition: part.h:34
QString::number
QString number(int n, int base)
QList::append
void append(const T &value)
QWidget::topLevelWidget
QWidget * topLevelWidget() const
KOrg::PartFactory
Definition: part.h:72
koprefs.h
KOCore::KOCore
KOCore()
Definition: kocore.cpp:46
KOCore::~KOCore
~KOCore()
Definition: kocore.cpp:51
QMap::constEnd
const_iterator constEnd() const
KOCore::unloadPlugins
void unloadPlugins()
Definition: kocore.cpp:267
d
#define d
QString
QList
KOrg::MainWindow
interface for korganizer main window
Definition: mainwindow.h:44
KOCore::availableParts
KService::List availableParts()
Definition: kocore.cpp:79
QStringList
KOCore::loadPlugin
CalendarSupport::Plugin * loadPlugin(KService::Ptr service)
Definition: kocore.cpp:84
KOCore::reloadParts
KOrg::Part::List reloadParts(KOrg::MainWindow *parent, KOrg::Part::List &parts)
Unloads the parts from the main window.
Definition: kocore.cpp:283
KOrg::MainWindow::mainGuiClient
virtual KXMLGUIClient * mainGuiClient()=0
Return XML GUI client of this main window.
KOCore::addXMLGUIClient
void addXMLGUIClient(QWidget *, KXMLGUIClient *guiclient)
Definition: kocore.cpp:183
KOPrefs::instance
static KOPrefs * instance()
Get instance of KOPrefs.
Definition: koprefs.cpp:68
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KOCore::removeXMLGUIClient
void removeXMLGUIClient(QWidget *)
Definition: kocore.cpp:188
QMap::insert
iterator insert(const Key &key, const T &value)
KOrg::PartFactory::createPluginFactory
virtual Part * createPluginFactory(MainWindow *parent)=0
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
KPluginFactory
QMap::find
iterator find(const Key &key)
KOCore::loadPart
KOrg::Part * loadPart(KService::Ptr, KOrg::MainWindow *parent)
Definition: kocore.cpp:156
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:123
KOCore
Definition: kocore.h:40
QMap::value
const T value(const Key &key) const
QMap::remove
int remove(const Key &key)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:59 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
  • pimprint

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