controlpanel/src/cpframework/src/cppluginlauncher.cpp
changeset 32 20bd089f4aaa
parent 31 2c9d3aa5bea2
child 36 48848d132687
--- a/controlpanel/src/cpframework/src/cppluginlauncher.cpp	Thu Apr 01 03:17:51 2010 +0800
+++ b/controlpanel/src/cpframework/src/cppluginlauncher.cpp	Thu Apr 01 03:23:37 2010 +0800
@@ -16,36 +16,83 @@
 */
 
 #include <cppluginlauncher.h>
+#include <cpplugininterface.h>
 #include <cppluginplatinterface.h>
 #include <cpsettingformentryitemdata.h>
-#include <qsharedpointer>
-#include "cppluginloader.h"
+#include <QSharedPointer>
+#include <cppluginloader.h>
 #include "cpitemdatahelper.h"
 
-static CpSettingFormEntryItemData *createEntrySettingItem(const QString &pluginFile) 
+/*!
+    \class CpPluginLauncher
+    \brief The CpPluginLauncher class loads a controlpanel plugin at run-time.And display the specify plugin view in client process.
+ */
+
+static CpSettingFormEntryItemData *createEntrySettingItem(const QString &pluginFile,int index = 0) 
 {
-    CpPluginPlatInterface *plugin = CpPluginLoader().loadCpPlugin(pluginFile);
-    if (plugin) {
-        CpItemDataHelper dummy;
-        CpSettingFormItemData *itemData = plugin->createSettingFormItemData(dummy);
-        return qobject_cast<CpSettingFormEntryItemData*>(itemData);
-    }
+	{
+		CpPluginInterface *plugin = CpPluginLoader().loadCpPlugin(pluginFile);
+		if (plugin) {
+			CpItemDataHelper dummy(0);
+			QList<CpSettingFormItemData*> allItemData = plugin->createSettingFormItemData(dummy);
+
+            CpSettingFormItemData *found = 0;
+
+            int size = allItemData.size();
+            for (int i = 0; i < size; ++i) {
+                if (i == index) {
+                    found = allItemData.value(i);
+                }
+                else {
+                    delete allItemData.value(i);
+                }
+            }
+            
+            if (found) {
+                CpSettingFormEntryItemData *entryItemData = qobject_cast<CpSettingFormEntryItemData*>(found);
+                if (entryItemData) {
+                    return entryItemData;
+                }
+                else {
+                    delete found;
+                }
+            }
+		}
+	}
+
+
+	//CpPluginPlatInterface : deprecated!
+	{
+        CpPluginPlatInterface *plugin = CpPluginLoader().loadPlatCpPlugin(pluginFile);
+        if (plugin) {
+            CpItemDataHelper dummy(0);
+            CpSettingFormItemData *itemData = plugin->createSettingFormItemData(dummy);
+            CpSettingFormEntryItemData *entryItemData = qobject_cast<CpSettingFormEntryItemData*>(itemData);
+            if (entryItemData) {
+                return entryItemData;
+            }
+            else {
+                delete itemData;
+            }
+		}
+	}
     
     return 0;
 }
 
 /*!
-    Load and display a plugin with the plugin's related file.
-    The pluginFile can either absoulte file path or only file name. Acceptable format:
-      sampleplugin
-      sampleplugin.qtplugin
-      sampleplugin.dll
-      C:/resource/qt/plugins/controlpanel/sampleplugin.qtplugin
-      C:/resource/qt/plugins/controlpanel/sampleplugin.dll
+    Load and display a plugin view in client process. The client must be a orbit based application.
+    The pluginFile can either absoulte file path or only file name. 
+    Acceptable format:
+        sampleplugin
+        sampleplugin.qtplugin
+        sampleplugin.dll
+        C:/resource/qt/plugins/controlpanel/sampleplugin.qtplugin
+        C:/resource/qt/plugins/controlpanel/sampleplugin.dll
 */
-bool CpPluginLauncher::launchCpPluginView(const QString &pluginFile)
+bool CpPluginLauncher::launchCpPluginView(const QString &pluginFile,int index /*= 0*/)
 {
-    QSharedPointer<CpSettingFormEntryItemData> entryItemData(createEntrySettingItem(pluginFile));
+    QSharedPointer<CpSettingFormEntryItemData> entryItemData(createEntrySettingItem(pluginFile,index));
     if (!entryItemData.isNull()) {
         entryItemData->onLaunchView();
         return true;