• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaComponents

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • plasmacomponents
plasmacomponentsplugin.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011 by Marco Martin <mart@kde.org>
3 
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "plasmacomponentsplugin.h"
21 
22 #include <QtDeclarative/qdeclarative.h>
23 #include <QtDeclarative/QDeclarativeEngine>
24 #include <QtDeclarative/QDeclarativeContext>
25 #include <QtDeclarative/QDeclarativeItem>
26 
27 #include "qrangemodel.h"
28 
29 #include <KSharedConfig>
30 #include <KDebug>
31 #include <KGlobal>
32 
33 #include <kdeclarative.h>
34 
35 #include "enums.h"
36 #include "qmenu.h"
37 #include "qmenuitem.h"
38 #include "fullscreensheet.h"
39 #include "units.h"
40 
41 Q_EXPORT_PLUGIN2(plasmacomponentsplugin, PlasmaComponentsPlugin)
42 
43 class BKSingleton
44 {
45 public:
46  EngineBookKeeping self;
47 };
48 K_GLOBAL_STATIC(BKSingleton, privateBKSelf)
49 
50 EngineBookKeeping::EngineBookKeeping()
51 {
52 }
53 
54 EngineBookKeeping *EngineBookKeeping::self()
55 {
56  return &privateBKSelf->self;
57 }
58 
59 QDeclarativeEngine *EngineBookKeeping::engine() const
60 {
61  //for components creation, any engine will do, as long is valid
62  if (m_engines.isEmpty()) {
63  kWarning() << "No engines found, this should never happen";
64  return 0;
65  } else {
66  return m_engines.values().first();
67  }
68 }
69 
70 void EngineBookKeeping::insertEngine(QDeclarativeEngine *engine)
71 {
72  connect(engine, SIGNAL(destroyed(QObject *)),
73  this, SLOT(engineDestroyed(QObject *)));
74  m_engines.insert(engine);
75 }
76 
77 void EngineBookKeeping::engineDestroyed(QObject *deleted)
78 {
79  m_engines.remove(static_cast<QDeclarativeEngine *>(deleted));
80 }
81 
82 
83 
84 void PlasmaComponentsPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
85 {
86  QDeclarativeExtensionPlugin::initializeEngine(engine, uri);
87  EngineBookKeeping::self()->insertEngine(engine);
88 
89  QDeclarativeContext *context = engine->rootContext();
90  Units *units = new Units(context);
91  context->setContextProperty("units", units);
92 }
93 
94 void PlasmaComponentsPlugin::registerTypes(const char *uri)
95 {
96  Q_ASSERT(uri == QLatin1String("org.kde.plasma.components"));
97 
98  //platform specific c++ components
99  const QString target = KDeclarative::componentsTarget();
100  if (target == KDeclarative::defaultComponentsTarget()) {
101  qmlRegisterType<QMenuProxy>(uri, 0, 1, "Menu");
102  qmlRegisterType<QMenuItem>(uri, 0, 1, "MenuItem");
103  } else {
104  qmlRegisterType<FullScreenSheet>(uri, 0, 1, "Sheet");
105  }
106 
107  qmlRegisterType<Plasma::QRangeModel>(uri, 0, 1, "RangeModel");
108 
109  qmlRegisterUncreatableType<DialogStatus>(uri, 0, 1, "DialogStatus", "");
110  qmlRegisterUncreatableType<PageOrientation>(uri, 0, 1, "PageOrientation", "");
111  qmlRegisterUncreatableType<PageStatus>(uri, 0, 1, "PageStatus", "");
112  qmlRegisterUncreatableType<Units>(uri, 0, 1, "Units", "");
113 }
114 
115 
116 #include "plasmacomponentsplugin.moc"
117 
QDeclarativeContext::setContextProperty
void setContextProperty(const QString &name, QObject *value)
QDeclarativeEngine
qmenu.h
EngineBookKeeping::engine
QDeclarativeEngine * engine() const
Definition: plasmacomponentsplugin.cpp:59
qmenuitem.h
fullscreensheet.h
QDeclarativeEngine::rootContext
QDeclarativeContext * rootContext() const
QSet::insert
const_iterator insert(const T &value)
PlasmaComponentsPlugin::registerTypes
void registerTypes(const char *uri)
Definition: plasmacomponentsplugin.cpp:94
EngineBookKeeping
Definition: plasmacomponentsplugin.h:30
QSet::values
QList< T > values() const
QObject
QDeclarativeContext
qrangemodel.h
QString
EngineBookKeeping::self
static EngineBookKeeping * self()
Definition: plasmacomponentsplugin.cpp:54
units.h
plasmacomponentsplugin.h
Units
Definition: units.h:27
enums.h
QSet::remove
bool remove(const T &value)
QLatin1String
QSet::isEmpty
bool isEmpty() const
EngineBookKeeping::insertEngine
void insertEngine(QDeclarativeEngine *engine)
Definition: plasmacomponentsplugin.cpp:70
PlasmaComponentsPlugin
Definition: plasmacomponentsplugin.h:48
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QDeclarativeExtensionPlugin::initializeEngine
virtual void initializeEngine(QDeclarativeEngine *engine, const char *uri)
QObject::destroyed
void destroyed(QObject *obj)
PlasmaComponentsPlugin::initializeEngine
void initializeEngine(QDeclarativeEngine *engine, const char *uri)
Definition: plasmacomponentsplugin.cpp:84
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaComponents

Skip menu "PlasmaComponents"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

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