• 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
backend.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) 2009 Alexander Rieder <alexanderrieder@gmail.com>
19  */
20 
21 #include "backend.h"
22 using namespace Cantor;
23 
24 #include <kservicetypetrader.h>
25 #include <kservice.h>
26 #include <kdebug.h>
27 #include <kxmlguifactory.h>
28 #include <kplugininfo.h>
29 
30 #include "extension.h"
31 
32 class Cantor::BackendPrivate
33 {
34  public:
35  QString name;
36  QString comment;
37  QString icon;
38  QString url;
39  bool enabled;
40 };
41 
42 Backend::Backend(QObject* parent, const QList<QVariant> args) : QObject(parent),
43  d(new BackendPrivate)
44 {
45  Q_UNUSED(args)
46  d->enabled=true;
47 }
48 
49 Backend::~Backend()
50 {
51  delete d;
52 }
53 
54 QString Backend::name() const
55 {
56  return d->name;
57 }
58 
59 QString Backend::comment() const
60 {
61  return d->comment;
62 }
63 
64 QString Backend::description() const
65 {
66  return comment();
67 }
68 
69 QString Backend::icon() const
70 {
71  return d->icon;
72 }
73 
74 QString Backend::url() const
75 {
76  return d->url;
77 }
78 
79 KUrl Backend::helpUrl() const
80 {
81  return KUrl();
82 }
83 
84 bool Backend::isEnabled() const
85 {
86  return d->enabled&&requirementsFullfilled();
87 }
88 
89 void Backend::setEnabled(bool enabled)
90 {
91  d->enabled=enabled;
92 }
93 
94 static QList<Backend*> backendCache;
95 
96 QStringList Backend::listAvailableBackends()
97 {
98  QList<Backend* > backends=availableBackends();
99  QStringList l;
100  foreach(Backend* b, backends)
101  {
102  if(b->isEnabled())
103  l<<b->name();
104  }
105 
106  return l;
107 }
108 
109 QList<Backend*> Backend::availableBackends()
110 {
111  //if we already have all backends Cached, just return the cache.
112  //otherwise create the available backends
113  if(!backendCache.isEmpty())
114  {
115  return backendCache;
116  }
117 
118  KService::List services;
119  KServiceTypeTrader* trader = KServiceTypeTrader::self();
120  QString error;
121 
122  services = trader->query("Cantor/Backend");
123 
124  foreach (const KService::Ptr &service, services)
125  {
126  Backend* backend=service->createInstance<Backend>(0, QVariantList(), &error);
127  if(backend==0)
128  {
129  kDebug()<<"error: "<<error;
130  continue;
131  }
132 
133  KPluginInfo info(service);
134  backend->d->name=info.name();
135  backend->d->comment=info.comment();
136  backend->d->icon=info.icon();
137  backend->d->url=info.website();
138  backendCache<<backend;
139  }
140  return backendCache;
141 }
142 
143 Backend* Backend::createBackend(const QString& name)
144 {
145  QList<Backend*> backends=availableBackends();
146  foreach(Backend* b, backends)
147  {
148  if(b->name().toLower()==name.toLower() || b->id().toLower()==name.toLower())
149  return b;
150  }
151 
152  return 0;
153 }
154 
155 QWidget* Backend::settingsWidget(QWidget* parent) const
156 {
157  Q_UNUSED(parent)
158  return 0;
159 }
160 
161 KConfigSkeleton* Backend::config() const
162 {
163  return 0;
164 }
165 
166 
167 QStringList Backend::extensions() const
168 {
169  QList<Extension*> extensions=findChildren<Extension*>(QRegExp(".*Extension"));
170  QStringList names;
171  foreach(Extension* e, extensions)
172  names<<e->objectName();
173  return names;
174 }
175 
176 Extension* Backend::extension(const QString& name) const
177 {
178  return findChild<Extension*>(name);
179 }
180 
181 bool Backend::requirementsFullfilled() const
182 {
183  return true;
184 }
Cantor::Backend::description
virtual QString description() const
Returns a longer description of the Backend, e.g.
Definition: backend.cpp:64
QWidget
Cantor::Backend::~Backend
virtual ~Backend()
Destructor.
Definition: backend.cpp:49
Cantor::Backend::id
virtual QString id() const =0
Returns a unique string to identify this backend.
Cantor::Backend::requirementsFullfilled
virtual bool requirementsFullfilled() const
Returns wether all of this backends requirements are fulfiled, or if some are missing.
Definition: backend.cpp:181
backendCache
static QList< Backend * > backendCache
Definition: backend.cpp:94
KConfigSkeleton
Cantor::Backend::settingsWidget
virtual QWidget * settingsWidget(QWidget *parent) const
Returns a Widget for configuring this backend.
Definition: backend.cpp:155
Cantor::Backend::extension
Extension * extension(const QString &name) const
Returns an Extension of this backend for the given name, or null if the Backend doesn't have an exten...
Definition: backend.cpp:176
QRegExp
Cantor::Backend::comment
QString comment() const
Returns a short comment about the backend.
Definition: backend.cpp:59
QObject
QObject::objectName
objectName
QString
QList
QStringList
Cantor::Backend::createBackend
static Backend * createBackend(const QString &name)
Returns the backend with the given name, or null if it isn't found.
Definition: backend.cpp:143
Cantor::Backend::helpUrl
virtual KUrl helpUrl() const
Returns an Url pointing to the Help of the Backend The method should be overwritten by all Backends(w...
Definition: backend.cpp:79
QString::toLower
QString toLower() const
extension.h
Cantor::Backend::listAvailableBackends
static QStringList listAvailableBackends()
Returns a list of the names of all the installed and enabled backends.
Definition: backend.cpp:96
Cantor::Backend::name
QString name() const
Returns the name of the backend.
Definition: backend.cpp:54
Cantor::Backend::extensions
QStringList extensions() const
Returns a list of the names of all the Extensions supported by this backend.
Definition: backend.cpp:167
Cantor::Backend::url
QString url() const
Returns the Url of the Homepage for the Backend.
Definition: backend.cpp:74
Cantor::Backend::icon
QString icon() const
Returns the icon to use with this backend.
Definition: backend.cpp:69
Cantor::Backend::Backend
Backend(QObject *parent=0, const QList< QVariant > args=QList< QVariant >())
Create a new Backend.
Definition: backend.cpp:42
Cantor::Backend::config
virtual KConfigSkeleton * config() const
Returns a KConfig object, containing all the settings, the backend might need.
Definition: backend.cpp:161
Cantor::Extension
This is the base class for all Extensions.
Definition: extension.h:43
Cantor::Backend::setEnabled
void setEnabled(bool enabled)
Enables/disables this backend.
Definition: backend.cpp:89
backend.h
Cantor::Backend
The Backend class provides access to information about the backend.
Definition: backend.h:52
Cantor::Backend::isEnabled
bool isEnabled() const
Returns if the backend should be enabled (shown in the Backend dialog)
Definition: backend.cpp:84
Cantor::Backend::availableBackends
static QList< Backend * > availableBackends()
Returns Pointers to all the installed backends.
Definition: backend.cpp:109
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