[Tux4kids-commits] r1150 - in tux4kids-admin/trunk/tux4kids-admin: plugins src

Michał Świtakowski swistakers-guest at alioth.debian.org
Mon Jul 6 21:43:38 UTC 2009


Author: swistakers-guest
Date: 2009-07-06 21:43:36 +0000 (Mon, 06 Jul 2009)
New Revision: 1150

Modified:
   tux4kids-admin/trunk/tux4kids-admin/plugins/pluginInterface.h
   tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp
   tux4kids-admin/trunk/tux4kids-admin/src/pluginManager.cpp
   tux4kids-admin/trunk/tux4kids-admin/src/pluginManager.h
   tux4kids-admin/trunk/tux4kids-admin/src/pluginManagerDialog.ui
Log:
PluginManager prepared to load/unload plugins in runtime

Modified: tux4kids-admin/trunk/tux4kids-admin/plugins/pluginInterface.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/plugins/pluginInterface.h	2009-07-06 18:20:17 UTC (rev 1149)
+++ tux4kids-admin/trunk/tux4kids-admin/plugins/pluginInterface.h	2009-07-06 21:43:36 UTC (rev 1150)
@@ -16,7 +16,7 @@
 
 protected:
 
-	QWidget *m_mainWidget = 0;
+	QWidget *m_mainWidget;
 };
 
 Q_DECLARE_INTERFACE(PluginInterface, "org.Tux4Kids.Tux4KidsPluginInterface/0.0.2");

Modified: tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp	2009-07-06 18:20:17 UTC (rev 1149)
+++ tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp	2009-07-06 21:43:36 UTC (rev 1150)
@@ -1,9 +1,11 @@
 #include <QDebug>
+#include <QApplication>
 
 #include "mainController.h"
 
 MainController::MainController()
 {
+	m_pluginManager.setPluginsPath(qApp->applicationDirPath() + "/plugins");
 	m_pluginManager.loadPlugins();
 
 	if (m_pluginManager.empty()) {

Modified: tux4kids-admin/trunk/tux4kids-admin/src/pluginManager.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/pluginManager.cpp	2009-07-06 18:20:17 UTC (rev 1149)
+++ tux4kids-admin/trunk/tux4kids-admin/src/pluginManager.cpp	2009-07-06 21:43:36 UTC (rev 1150)
@@ -1,12 +1,11 @@
-#include <QPluginLoader>
 #include <QDir>
 #include <QDebug>
-#include <QApplication>
 
 #include "pluginManager.h"
 
-PluginManager::PluginManager()
+PluginManager::PluginManager(QString pluginsPath, QObject *parent) : QAbstractListModel(parent)
 {
+	m_pluginsPath = pluginsPath;
 }
 
 int PluginManager::rowCount(const QModelIndex &parent) const
@@ -23,7 +22,12 @@
 		return QVariant();
 
 	if (role == Qt::DisplayRole) {
-		return plugins.at(index.row())->name();
+		QString result = pluginNames.at(index.row());
+		if (plugins.at(index.row())->isLoaded()) {
+			result += " (loaded)";
+		} else {
+			result += " (not loaded)";
+		}
 	}
 
 	return QVariant();
@@ -32,18 +36,22 @@
 void PluginManager::loadPlugins()
 {
 	PluginInterface *pluginInterface;
-	QDir pluginsDir(qApp->applicationDirPath() + "/plugins");
+	QDir pluginsDir(m_pluginsPath);
 
 	foreach (QString fileName, pluginsDir.entryList(QDir::Files))
 	{
-		QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
-		QObject *plugin = pluginLoader.instance();
+		QPluginLoader *pluginLoader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName));
+		QObject *plugin = pluginLoader->instance();
 		if (plugin)
 		{
 			pluginInterface = qobject_cast<PluginInterface *>(plugin);
 			if (pluginInterface)
 			{
-				plugins.append(pluginInterface);
+				pluginNames.append(pluginInterface->name());
+				plugins.append(pluginLoader);
+				delete pluginInterface;
+				pluginLoader->unload();
+				delete pluginLoader;
 			}
 		}
 	}
@@ -53,3 +61,19 @@
 {
 	return plugins.empty();
 }
+
+void PluginManager::setPluginsPath(QString pluginsPath)
+{
+	m_pluginsPath = pluginsPath;
+}
+
+bool PluginManager::load(int index)
+{
+	return plugins.at(index)->load();
+}
+
+bool PluginManager::unload(int index)
+{
+	return plugins.at(index)->unload();
+}
+

Modified: tux4kids-admin/trunk/tux4kids-admin/src/pluginManager.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/pluginManager.h	2009-07-06 18:20:17 UTC (rev 1149)
+++ tux4kids-admin/trunk/tux4kids-admin/src/pluginManager.h	2009-07-06 21:43:36 UTC (rev 1150)
@@ -2,6 +2,8 @@
 #define PLUGINMANAGER_H
 
 #include <QAbstractListModel>
+#include <QPluginLoader>
+#include <QStringList>
 
 #include "pluginInterface.h"
 
@@ -11,15 +13,21 @@
 	Q_OBJECT
 
 public:
-	PluginManager();
+	PluginManager(QString pluginsPath = QString(), QObject *parent = 0);
 
 	int rowCount(const QModelIndex &parent = QModelIndex()) const;
 	QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 	bool empty() const;
 	void loadPlugins();
+	void setPluginsPath(QString pluginsPath);
+	bool load(int index);
+	bool unload(int index);
 
 private:
-	QList<PluginInterface *> plugins;
+	QString m_pluginsPath;
+	QList<QPluginLoader *> plugins;
+	QStringList pluginNames;
+	//QList<PluginInterface *> loadedPlugins;
 
 
 };

Modified: tux4kids-admin/trunk/tux4kids-admin/src/pluginManagerDialog.ui
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/pluginManagerDialog.ui	2009-07-06 18:20:17 UTC (rev 1149)
+++ tux4kids-admin/trunk/tux4kids-admin/src/pluginManagerDialog.ui	2009-07-06 21:43:36 UTC (rev 1150)
@@ -5,24 +5,63 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>300</height>
+    <width>564</width>
+    <height>451</height>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>Dialog</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout" >
+  <layout class="QVBoxLayout" name="verticalLayout_3" >
    <item>
-    <widget class="QLabel" name="label" >
-     <property name="text" >
-      <string>Loaded plugins</string>
-     </property>
-    </widget>
+    <layout class="QVBoxLayout" name="verticalLayout_2" >
+     <item>
+      <widget class="QLabel" name="label" >
+       <property name="text" >
+        <string>Plugins</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout" >
+       <item>
+        <widget class="QListView" name="pluginsList" />
+       </item>
+       <item>
+        <layout class="QVBoxLayout" name="verticalLayout" >
+         <item>
+          <widget class="QPushButton" name="loadButton" >
+           <property name="text" >
+            <string>Load</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QPushButton" name="unloadButton" >
+           <property name="text" >
+            <string>Unload</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <spacer name="verticalSpacer" >
+           <property name="orientation" >
+            <enum>Qt::Vertical</enum>
+           </property>
+           <property name="sizeHint" stdset="0" >
+            <size>
+             <width>20</width>
+             <height>40</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </item>
+    </layout>
    </item>
-   <item>
-    <widget class="QListView" name="pluginsList" />
-   </item>
   </layout>
  </widget>
  <resources/>




More information about the Tux4kids-commits mailing list