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

rocs/RocsCore

  • sources
  • kde-4.12
  • kdeedu
  • rocs
  • RocsCore
  • LoadSave
GraphFileBackendManager.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2010-2011 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2010 Wagner Reck <wagner.reck@gmail.com>
5  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (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
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "GraphFileBackendManager.h"
22 
23 #include "GraphFilePluginInterface.h"
24 #include "RocsGraphFileFormatPlugin.h"
25 
26 #include <KServiceTypeTrader>
27 #include <KPluginInfo>
28 #include <KDebug>
29 
30 class GraphFileBackendManagerPrivate
31 {
32 public:
33  GraphFileBackendManagerPrivate() {
34  backendInfo = KPluginInfo::fromServices(KServiceTypeTrader::self()->query("Rocs/GraphFilePlugin"));
35  }
36 
37  ~GraphFileBackendManagerPrivate()
38  { }
39 
40  KPluginInfo::List backendInfo;
41  QList<GraphFilePluginInterface*> backends;
42  GraphFilePluginInterface* defaultGraphFilePlugin;
43 };
44 
45 
46 GraphFileBackendManager * GraphFileBackendManager::instance = 0;
47 
48 
49 GraphFileBackendManager * GraphFileBackendManager::self()
50 {
51  if (GraphFileBackendManager::instance == 0) {
52  GraphFileBackendManager::instance = new GraphFileBackendManager;
53  }
54  return GraphFileBackendManager::instance;
55 }
56 
57 
58 GraphFileBackendManager::GraphFileBackendManager()
59 {
60  d = new GraphFileBackendManagerPrivate();
61  loadBackends();
62 }
63 
64 
65 GraphFileBackendManager::~GraphFileBackendManager()
66 {
67  delete d;
68 }
69 
70 
71 QList<GraphFilePluginInterface*> GraphFileBackendManager::backends() const
72 {
73  return d->backends;
74 }
75 
76 
77 QList<GraphFilePluginInterface*> GraphFileBackendManager::backends(PluginType type) const
78 {
79  QList<GraphFilePluginInterface*> backends;
80  foreach(GraphFilePluginInterface* backend, d->backends) {
81  switch(type) {
82  case Import:
83  if (backend->pluginCapability() == GraphFilePluginInterface::ImportOnly
84  || backend->pluginCapability() == GraphFilePluginInterface::ImportAndExport)
85  {
86  backends.append(backend);
87  }
88  break;
89  case Export:
90  if (backend->pluginCapability() == GraphFilePluginInterface::ExportOnly
91  || backend->pluginCapability() == GraphFilePluginInterface::ImportAndExport)
92  {
93  backends.append(backend);
94  }
95  break;
96  default:
97  break;
98  }
99  }
100  return backends;
101 }
102 
103 
104 void GraphFileBackendManager::loadBackends()
105 {
106  // remove all present backends
107  foreach(GraphFilePluginInterface * f, d->backends) {
108  delete f;
109  }
110  d->backends.clear();
111 
112  // load dynamic backends
113  KService::List offers = KServiceTypeTrader::self()->query("Rocs/GraphFilePlugin");
114  KService::List::const_iterator iter;
115  for (iter = offers.constBegin(); iter < offers.constEnd(); ++iter) {
116  KService::Ptr service = *iter;
117  KPluginFactory *factory = KPluginLoader(service->library()).factory();
118 
119  if (!factory) {
120  kError(5001) << "KPluginFactory could not load the plugin: " << service->library();
121  continue;
122  }
123 
124  GraphFilePluginInterface *plugin = factory->create<GraphFilePluginInterface>(this);
125 
126  if (plugin) {
127  d->backends.append(plugin);
128  } else {
129  kWarning() << "Could not load backend: " << service->name();
130  }
131  }
132 
133  // load static plugins
134  GraphFilePluginInterface *plugin = new RocsGraphFileFormatPlugin(this);
135  d->backends.append(plugin);
136  d->defaultGraphFilePlugin = plugin;
137 }
138 
139 
140 GraphFilePluginInterface* GraphFileBackendManager::backendByExtension(QString ext)
141 {
142  foreach(GraphFilePluginInterface * p, d->backends) {
143  if (p->extensions().join(";").contains(ext, Qt::CaseInsensitive)) {
144  return p;
145  }
146  }
147  return 0;
148 }
149 
150 
151 GraphFilePluginInterface* GraphFileBackendManager::defaultBackend()
152 {
153  return d->defaultGraphFilePlugin;
154 }
GraphFilePluginInterface.h
GraphFilePluginInterface::ExportOnly
Definition: GraphFilePluginInterface.h:67
GraphFileBackendManager
The GraphFileBackendMananger is a singleton class that provides backends for graph file writing and r...
Definition: GraphFileBackendManager.h:37
GraphFileBackendManager::backendByExtension
GraphFilePluginInterface * backendByExtension(QString ext)
Returns an arbitrary loaded plugin that can handle extension ext.
Definition: GraphFileBackendManager.cpp:140
RocsGraphFileFormatPlugin.h
GraphFileBackendManager::self
static GraphFileBackendManager * self()
Returns self reference to backend manager.
Definition: GraphFileBackendManager.cpp:49
GraphFileBackendManager::defaultBackend
GraphFilePluginInterface * defaultBackend()
Returns the default backend used for serialization/loading of graph files.
Definition: GraphFileBackendManager.cpp:151
GraphFileBackendManager::PluginType
PluginType
Selector for graph file backend with specific capability.
Definition: GraphFileBackendManager.h:44
GraphFilePluginInterface::extensions
virtual const QStringList extensions() const =0
File extensions that are common for this file type.
RocsGraphFileFormatPlugin
class RocsGraphFileFormatPlugin: Import and Export Plugin for internal graph format.
Definition: RocsGraphFileFormatPlugin.h:115
GraphFileBackendManager::Import
Definition: GraphFileBackendManager.h:45
GraphFileBackendManager::backends
QList< GraphFilePluginInterface * > backends() const
Returns list of loaded backends.
Definition: GraphFileBackendManager.cpp:71
GraphFilePluginInterface::ImportAndExport
Definition: GraphFilePluginInterface.h:68
GraphFileBackendManager.h
GraphFilePluginInterface::ImportOnly
Definition: GraphFilePluginInterface.h:66
GraphFilePluginInterface::pluginCapability
virtual PluginType pluginCapability() const
Returns PluginType to indicate whether the plugin only provides import, only export or both capabilit...
Definition: GraphFilePluginInterface.cpp:59
GraphFilePluginInterface
This class provides an interface for graph file format plugins.
Definition: GraphFilePluginInterface.h:42
GraphFileBackendManager::Export
Definition: GraphFileBackendManager.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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