controlpanel/src/cpframework/src/cppluginlauncher.cpp
changeset 36 48848d132687
parent 32 20bd089f4aaa
child 37 940f6b67827d
--- a/controlpanel/src/cpframework/src/cppluginlauncher.cpp	Thu Apr 01 03:31:13 2010 +0800
+++ b/controlpanel/src/cpframework/src/cppluginlauncher.cpp	Fri Apr 16 11:40:46 2010 +0800
@@ -17,69 +17,18 @@
 
 #include <cppluginlauncher.h>
 #include <cpplugininterface.h>
+#include <cplauncherinterface.h>
 #include <cppluginplatinterface.h>
-#include <cpsettingformentryitemdata.h>
 #include <QSharedPointer>
 #include <cppluginloader.h>
-#include "cpitemdatahelper.h"
-
+#include <cpbasesettingview.h>
+#include <cpitemdatahelper.h>
+#include "cpviewlauncher.h"
 /*!
     \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) 
-{
-	{
-		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 view in client process. The client must be a orbit based application.
     The pluginFile can either absoulte file path or only file name. 
@@ -92,11 +41,29 @@
 */
 bool CpPluginLauncher::launchCpPluginView(const QString &pluginFile,int index /*= 0*/)
 {
-    QSharedPointer<CpSettingFormEntryItemData> entryItemData(createEntrySettingItem(pluginFile,index));
-    if (!entryItemData.isNull()) {
-        entryItemData->onLaunchView();
-        return true;            
-    }
     return false;
 }
 
+/*!
+    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::launchSettingView(const QString &pluginFile,const QVariant &hint /*= QVariant()*/)
+{
+    CpLauncherInterface *plugin = CpPluginLoader::loadCpLauncherInterface(pluginFile);
+    if (plugin) {
+        CpBaseSettingView *view = plugin->createSettingView(hint);
+        if (view) {
+            CpViewLauncher::launchView(view);
+            return true;
+        }
+    }
+    
+    return false;
+}