emailuis/nmailui/src/nmuiextensionmanager.cpp
changeset 18 578830873419
child 20 ecc8def7944a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/emailuis/nmailui/src/nmuiextensionmanager.cpp	Fri Apr 16 14:51:52 2010 +0300
@@ -0,0 +1,161 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "nmuiheaders.h"
+
+/*!
+    \class NmUiExtensionManager
+    \brief Handles ui extension plugins
+ */
+NmUiExtensionManager::NmUiExtensionManager()
+{
+    // load the protocol extension plugins
+    loadExtensionPlugins();
+}
+
+/*!
+    Destructor
+ */
+NmUiExtensionManager::~NmUiExtensionManager()
+{
+    // delete plugins from array
+    qDeleteAll(mExtensions.begin(), mExtensions.end());
+    mExtensions.clear();
+
+    qDeleteAll(mPluginLoaders.begin(), mPluginLoaders.end());
+    mPluginLoaders.clear();
+}
+
+/*!
+    Calls all extensions
+ */
+void NmUiExtensionManager::getActions(
+    const NmActionRequest &menuRequest,
+    QList<NmAction*> &actionList)
+{
+    for (int i = 0; i < mExtensions.count(); i++) {
+    	NmUiExtensionInterface* interface = mExtensions[i];
+        interface->getActions(menuRequest, actionList);
+    }
+}
+
+/*!
+    Loads predifened plugins implementing the NmUiExtensionInterface interface
+ */
+void NmUiExtensionManager::loadExtensionPlugins()
+{
+
+#ifdef Q_OS_SYMBIAN
+    // Note: In Symbian the plugin stub files (.qtplugin) must be used whenever
+    // a path to plugin is needed - Symbian platform security.
+    const QString KTestPluginExtensionName = "nmtestpluginextension.qtplugin";
+    const QString KImapPluginExtensionName = "nmimapclientplugin.qtplugin";
+    const QString KPopPluginExtensionName  = "nmpopclientplugin.qtplugin";
+    const QString KEasPluginExtensionName = "nmeasclientplugin.qtplugin";
+    const QString KPluginDirectory = "c:\\resource\\plugins";
+    QDir pluginDir = QDir(KPluginDirectory);
+#else
+    #define NM_WINS_ENV
+    const QString KTestPluginExtensionName = "nmtestpluginextension.dll";
+    const QString KImapPluginExtensionName = "nmimapclientplugin.dll";
+    const QString KPopPluginExtensionName  = "nmpopclientplugin.dll";
+    QDir pluginDir = QDir(QApplication::applicationDirPath());
+#endif
+
+    
+    // Each plugin should be mapped to separate QPluginLoader   
+    QPluginLoader *testPluginLoader = new QPluginLoader(
+            pluginDir.absoluteFilePath(KTestPluginExtensionName));
+    testPluginLoader->load();
+    QObject *testPluginInstance(NULL); 
+    if (testPluginLoader && testPluginLoader->isLoaded()){
+        testPluginInstance = testPluginLoader->instance();    
+    }
+
+    QPluginLoader *imapPluginLoader = new QPluginLoader(
+            pluginDir.absoluteFilePath(KImapPluginExtensionName));
+    QObject *imapPluginInstance = imapPluginLoader->instance();
+
+    QPluginLoader *popPluginLoader = new QPluginLoader(
+            pluginDir.absoluteFilePath(KPopPluginExtensionName));
+    QObject *popPluginInstance = popPluginLoader->instance();
+
+#ifndef NM_WINS_ENV
+    QPluginLoader *easPluginLoader = new QPluginLoader(
+            pluginDir.absoluteFilePath(KEasPluginExtensionName));
+    QObject *easPluginInstance = easPluginLoader->instance();
+#endif
+
+    if(testPluginInstance) {
+        NmUiExtensionInterface *interface = qobject_cast<NmUiExtensionInterface*>(testPluginInstance);
+        if (interface) {
+            mExtensions.append(interface);
+        }
+
+        // Store QPluginLoader instances to keep plugins alive.
+        // If QPluginLoader instance for a plugin is deleted, then there
+        // is a risk that some component outside will load and unload
+        // plugin, which will lead into situation where plugin is deleted.
+        // This means that instance in mPluginArray will be invalid.
+        mPluginLoaders.append(testPluginLoader);
+    } else {
+        // We don't have proper plugin instance, so we don't need it's loader.
+        delete testPluginLoader;
+        testPluginLoader = NULL;
+    }
+    
+    if(imapPluginInstance) {
+        NmUiExtensionInterface *interface = qobject_cast<NmUiExtensionInterface*>(imapPluginInstance);
+        if (interface) {
+            mExtensions.append(interface);
+        }
+        mPluginLoaders.append(imapPluginLoader);
+    } else {
+        // We don't have proper plugin instance, so we don't need it's loader.
+        delete imapPluginLoader;
+        imapPluginLoader = NULL;
+    }
+    
+    if(popPluginInstance) {
+        NmUiExtensionInterface *interface = qobject_cast<NmUiExtensionInterface*>(popPluginInstance);
+        if (interface) {
+            mExtensions.append(interface);
+        }
+        mPluginLoaders.append(popPluginLoader);
+    } else {
+        // We don't have proper plugin instance, so we don't need it's loader.
+        delete popPluginLoader;
+        popPluginLoader = NULL;
+    }
+
+#ifndef NM_WINS_ENV
+    if(easPluginInstance) {
+        NmUiExtensionInterface *interface = qobject_cast<NmUiExtensionInterface*>(easPluginInstance);
+        if (interface) {
+            mExtensions.append(interface);
+        }
+        mPluginLoaders.append(easPluginLoader);
+    } else {
+        // We don't have proper plugin instance, so we don't need it's loader.
+        delete easPluginLoader;
+        easPluginLoader = NULL;
+    }
+#endif    
+
+}
+
+