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

cantor/src/lib

  • sources
  • kde-4.14
  • kdeedu
  • cantor
  • src
  • lib
panelpluginhandler.cpp
Go to the documentation of this file.
1 /*
2  This program is free software; you can redistribute it and/or
3  modify it under the terms of the GNU General Public License
4  as published by the Free Software Foundation; either version 2
5  of the License, or (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor,
15  Boston, MA 02110-1301, USA.
16 
17  ---
18  Copyright (C) 2010 Alexander Rieder <alexanderrieder@gmail.com>
19  */
20 
21 #include "panelpluginhandler.h"
22 using namespace Cantor;
23 
24 #include <kdebug.h>
25 #include <kservice.h>
26 #include <kservicetypetrader.h>
27 #include <kplugininfo.h>
28 
29 #include "session.h"
30 #include "panelplugin.h"
31 #include "backend.h"
32 
33 class Cantor::PanelPluginHandlerPrivate
34 {
35  public:
36  QList<Cantor::PanelPlugin*> plugins;
37  Cantor::Session* session;
38 };
39 
40 PanelPluginHandler::PanelPluginHandler( QObject* parent ) : QObject(parent) ,
41  d(new PanelPluginHandlerPrivate)
42 {
43  setObjectName("PanelPluginHandler");
44  d->session=0;
45 }
46 
47 PanelPluginHandler::~PanelPluginHandler()
48 {
49  delete d;
50 }
51 
52 void PanelPluginHandler::loadPlugins()
53 {
54  if(d->session==0)
55  return;
56  kDebug()<<"loading panel plugins for session of type "<<d->session->backend()->name();
57 
58  KService::List services;
59  KServiceTypeTrader* trader = KServiceTypeTrader::self();
60 
61  services = trader->query("Cantor/PanelPlugin");
62 
63  foreach (const KService::Ptr &service, services)
64  {
65  QString error;
66 
67  kDebug()<<"found service"<<service->name();
68  Cantor::PanelPlugin* plugin=service->createInstance<Cantor::PanelPlugin>(this, QVariantList(), &error);
69  if (plugin==0)
70  {
71  kDebug()<<"error loading panelplugin"<<service->name()<<": "<<error;
72  continue;
73  }
74 
75  kDebug()<<"created it";
76 
77  KPluginInfo info(service);
78  plugin->setPluginInfo(info);
79 
80  kDebug()<<"plugin "<<service->name()<<" requires "<<plugin->requiredExtensions();
81  bool supported=true;
82  foreach(const QString& req, plugin->requiredExtensions())
83  supported=supported && d->session->backend()->extensions().contains(req);
84 
85  supported=supported && ( (d->session->backend()->capabilities() & plugin->requiredCapabilities()) == plugin->requiredCapabilities());
86  kDebug()<<"plugin "<<service->name()<<" is "<<(supported ? "":" not ")<<" supported";
87 
88  if(supported)
89  {
90  d->plugins.append(plugin);
91  plugin->setSession(d->session);
92  }else
93  {
94  plugin->deleteLater();
95  }
96  }
97 
98  emit pluginsChanged();
99 }
100 
101 void PanelPluginHandler::setSession(Session* session)
102 {
103  qDeleteAll(d->plugins);
104  d->plugins.clear();
105  d->session=session;
106  loadPlugins();
107 }
108 
109 QList<PanelPlugin*> PanelPluginHandler::plugins()
110 {
111  return d->plugins;
112 }
113 
114 void PanelPluginHandler::addPlugin(PanelPlugin* plugin)
115 {
116  d->plugins.append(plugin);
117 }
118 
119 #include "panelpluginhandler.moc"
Cantor::PanelPluginHandler::~PanelPluginHandler
~PanelPluginHandler()
Definition: panelpluginhandler.cpp:47
Cantor::PanelPlugin::requiredExtensions
QStringList requiredExtensions()
Returns a list of all extensions, the current backend must provide to make this PanelPlugin work...
Definition: panelplugin.cpp:65
Cantor::PanelPluginHandler::plugins
QList< PanelPlugin * > plugins()
Definition: panelpluginhandler.cpp:109
panelplugin.h
session.h
Cantor::PanelPluginHandler::addPlugin
void addPlugin(PanelPlugin *plugin)
Definition: panelpluginhandler.cpp:114
panelpluginhandler.h
Cantor::PanelPluginHandler::pluginsChanged
void pluginsChanged()
Cantor::PanelPlugin::setSession
void setSession(Session *session)
sets the session this plugin operates on
Definition: panelplugin.cpp:85
QObject
QObject::setObjectName
void setObjectName(const QString &name)
Cantor::PanelPlugin::name
QString name()
Returns the name of the plugin.
Definition: panelplugin.cpp:75
Cantor::PanelPluginHandler::PanelPluginHandler
PanelPluginHandler(QObject *parent)
Definition: panelpluginhandler.cpp:40
QObject::deleteLater
void deleteLater()
QString
QList
Cantor::PanelPlugin
A plugin provides some additional features for the worksheet.
Definition: panelplugin.h:40
Cantor::PanelPluginHandler::setSession
void setSession(Session *session)
Definition: panelpluginhandler.cpp:101
backend.h
Cantor::PanelPlugin::requiredCapabilities
virtual Backend::Capabilities requiredCapabilities()
Returns the capabilities, the current backend must provide to make this PanelPlugin work...
Definition: panelplugin.cpp:70
Cantor::PanelPlugin::setPluginInfo
void setPluginInfo(KPluginInfo info)
Sets the properties of this PanelPlugin accodring to KPluginInfo.
Definition: panelplugin.cpp:58
Cantor::Session
The Session object is the main class used to interact with a Backend.
Definition: session.h:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

cantor/src/lib

Skip menu "cantor/src/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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