[Tux4kids-commits] r1134 - tux4kids-admin/trunk/src
Michał Świtakowski
swistakers-guest at alioth.debian.org
Thu Jul 2 21:57:36 UTC 2009
Author: swistakers-guest
Date: 2009-07-02 21:57:35 +0000 (Thu, 02 Jul 2009)
New Revision: 1134
Added:
tux4kids-admin/trunk/src/pluginManager.cpp
tux4kids-admin/trunk/src/pluginManager.h
Modified:
tux4kids-admin/trunk/src/mainController.cpp
tux4kids-admin/trunk/src/mainController.h
tux4kids-admin/trunk/src/src.pro
Log:
added plugin manager
Modified: tux4kids-admin/trunk/src/mainController.cpp
===================================================================
--- tux4kids-admin/trunk/src/mainController.cpp 2009-07-02 21:13:09 UTC (rev 1133)
+++ tux4kids-admin/trunk/src/mainController.cpp 2009-07-02 21:57:35 UTC (rev 1134)
@@ -1,21 +1,13 @@
#include <QDebug>
-#include <QDir>
-#include <QApplication>
-#include <QPluginLoader>
#include "mainController.h"
MainController::MainController()
{
- loadPlugins();
+ pluginManager.loadPlugins();
- if (plugins.isEmpty()) {
+ if (pluginManager.empty()) {
qDebug() << tr("Failed to load plugins");
- } else {
- qDebug() << tr("Loaded plugins: ");
- foreach(PluginInterface *plugin, plugins) {
- qDebug() << plugin->name();
- }
}
}
@@ -23,23 +15,3 @@
{
}
-void MainController::loadPlugins()
-{
- PluginInterface *pluginInterface;
- QDir pluginsDir(qApp->applicationDirPath() + "/plugins");
-
- foreach (QString fileName, pluginsDir.entryList(QDir::Files))
- {
- QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
- QObject *plugin = pluginLoader.instance();
- if (plugin)
- {
- pluginInterface = qobject_cast<PluginInterface *>(plugin);
- if (pluginInterface)
- {
- plugins.append(pluginInterface);
- }
- }
- }
-}
-
Modified: tux4kids-admin/trunk/src/mainController.h
===================================================================
--- tux4kids-admin/trunk/src/mainController.h 2009-07-02 21:13:09 UTC (rev 1133)
+++ tux4kids-admin/trunk/src/mainController.h 2009-07-02 21:57:35 UTC (rev 1134)
@@ -4,7 +4,7 @@
#include <QObject>
#include <QList>
-#include "pluginInterface.h"
+#include "pluginManager.h"
class MainController : public QObject
{
@@ -15,9 +15,8 @@
~MainController();
private:
- QList<PluginInterface *> plugins;
- void loadPlugins();
+ PluginManager pluginManager;
};
#endif // MAINCONTROLLER_H
Added: tux4kids-admin/trunk/src/pluginManager.cpp
===================================================================
--- tux4kids-admin/trunk/src/pluginManager.cpp (rev 0)
+++ tux4kids-admin/trunk/src/pluginManager.cpp 2009-07-02 21:57:35 UTC (rev 1134)
@@ -0,0 +1,55 @@
+#include <QPluginLoader>
+#include <QDir>
+#include <QDebug>
+#include <QApplication>
+
+#include "pluginManager.h"
+
+PluginManager::PluginManager()
+{
+}
+
+int PluginManager::rowCount(const QModelIndex &parent) const
+{
+ return plugins.size();
+}
+
+QVariant PluginManager::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() >= rowCount())
+ return QVariant();
+
+ if (role == Qt::DisplayRole) {
+ return plugins.at(index.row())->name();
+ }
+
+ return QVariant();
+}
+
+void PluginManager::loadPlugins()
+{
+ PluginInterface *pluginInterface;
+ QDir pluginsDir(qApp->applicationDirPath() + "/plugins");
+
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files))
+ {
+ QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
+ QObject *plugin = pluginLoader.instance();
+ if (plugin)
+ {
+ pluginInterface = qobject_cast<PluginInterface *>(plugin);
+ if (pluginInterface)
+ {
+ plugins.append(pluginInterface);
+ }
+ }
+ }
+}
+
+bool PluginManager::empty() const
+{
+ return plugins.empty();
+}
Added: tux4kids-admin/trunk/src/pluginManager.h
===================================================================
--- tux4kids-admin/trunk/src/pluginManager.h (rev 0)
+++ tux4kids-admin/trunk/src/pluginManager.h 2009-07-02 21:57:35 UTC (rev 1134)
@@ -0,0 +1,27 @@
+#ifndef PLUGINMANAGER_H
+#define PLUGINMANAGER_H
+
+#include <QAbstractListModel>
+
+#include "pluginInterface.h"
+
+
+class PluginManager : public QAbstractListModel
+{
+ Q_OBJECT
+
+public:
+ PluginManager();
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ bool empty() const;
+ void loadPlugins();
+
+private:
+ QList<PluginInterface *> plugins;
+
+
+};
+
+#endif // PLUGINMANAGER_H
Modified: tux4kids-admin/trunk/src/src.pro
===================================================================
--- tux4kids-admin/trunk/src/src.pro 2009-07-02 21:13:09 UTC (rev 1133)
+++ tux4kids-admin/trunk/src/src.pro 2009-07-02 21:57:35 UTC (rev 1134)
@@ -1,16 +1,11 @@
TARGET = ../tux4kids-admin
TEMPLATE = app
-INCLUDEPATH += ../plugins/
-
+INCLUDEPATH += ../plugins/
SOURCES += main.cpp \
mainWindow.cpp \
- mainController.cpp
-
+ mainController.cpp \
+ pluginManager.cpp
HEADERS += mainWindow.h \
- mainController.h
-
+ mainController.h \
+ pluginManager.h
FORMS += mainWindow.ui
-
-# Uncomment to use GCOV
-# QMAKE_CXXFLAGS+=-fprofile-arcs -ftest-coverage
-
More information about the Tux4kids-commits
mailing list