emailuis/nmailui/src/nmuiextensionmanager.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "nmuiheaders.h"
       
    19 
       
    20 /*!
       
    21     \class NmUiExtensionManager
       
    22     \brief Handles ui extension plugins
       
    23  */
       
    24 NmUiExtensionManager::NmUiExtensionManager()
       
    25 {
       
    26     // load the protocol extension plugins
       
    27     loadExtensionPlugins();
       
    28 }
       
    29 
       
    30 /*!
       
    31     Destructor
       
    32  */
       
    33 NmUiExtensionManager::~NmUiExtensionManager()
       
    34 {
       
    35     // delete plugins from array
       
    36     qDeleteAll(mExtensions.begin(), mExtensions.end());
       
    37     mExtensions.clear();
       
    38 
       
    39     qDeleteAll(mPluginLoaders.begin(), mPluginLoaders.end());
       
    40     mPluginLoaders.clear();
       
    41 }
       
    42 
       
    43 /*!
       
    44     Calls all extensions
       
    45  */
       
    46 void NmUiExtensionManager::getActions(
       
    47     const NmActionRequest &menuRequest,
       
    48     QList<NmAction*> &actionList)
       
    49 {
       
    50     for (int i = 0; i < mExtensions.count(); i++) {
       
    51     	NmUiExtensionInterface* interface = mExtensions[i];
       
    52         interface->getActions(menuRequest, actionList);
       
    53     }
       
    54 }
       
    55 
       
    56 /*!
       
    57     Loads predifened plugins implementing the NmUiExtensionInterface interface
       
    58  */
       
    59 void NmUiExtensionManager::loadExtensionPlugins()
       
    60 {
       
    61 
       
    62 #ifdef Q_OS_SYMBIAN
       
    63     // Note: In Symbian the plugin stub files (.qtplugin) must be used whenever
       
    64     // a path to plugin is needed - Symbian platform security.
       
    65     const QString KTestPluginExtensionName = "nmtestpluginextension.qtplugin";
       
    66     const QString KImapPluginExtensionName = "nmimapclientplugin.qtplugin";
       
    67     const QString KPopPluginExtensionName  = "nmpopclientplugin.qtplugin";
       
    68     const QString KEasPluginExtensionName = "nmeasclientplugin.qtplugin";
       
    69     const QString KPluginDirectory = "c:\\resource\\plugins";
       
    70     QDir pluginDir = QDir(KPluginDirectory);
       
    71 #else
       
    72     #define NM_WINS_ENV
       
    73     const QString KTestPluginExtensionName = "nmtestpluginextension.dll";
       
    74     const QString KImapPluginExtensionName = "nmimapclientplugin.dll";
       
    75     const QString KPopPluginExtensionName  = "nmpopclientplugin.dll";
       
    76     QDir pluginDir = QDir(QApplication::applicationDirPath());
       
    77 #endif
       
    78 
       
    79     
       
    80     // Each plugin should be mapped to separate QPluginLoader   
       
    81     QPluginLoader *testPluginLoader = new QPluginLoader(
       
    82             pluginDir.absoluteFilePath(KTestPluginExtensionName));
       
    83     testPluginLoader->load();
       
    84     QObject *testPluginInstance(NULL); 
       
    85     if (testPluginLoader && testPluginLoader->isLoaded()){
       
    86         testPluginInstance = testPluginLoader->instance();    
       
    87     }
       
    88 
       
    89     QPluginLoader *imapPluginLoader = new QPluginLoader(
       
    90             pluginDir.absoluteFilePath(KImapPluginExtensionName));
       
    91     QObject *imapPluginInstance = imapPluginLoader->instance();
       
    92 
       
    93     QPluginLoader *popPluginLoader = new QPluginLoader(
       
    94             pluginDir.absoluteFilePath(KPopPluginExtensionName));
       
    95     QObject *popPluginInstance = popPluginLoader->instance();
       
    96 
       
    97 #ifndef NM_WINS_ENV
       
    98     QPluginLoader *easPluginLoader = new QPluginLoader(
       
    99             pluginDir.absoluteFilePath(KEasPluginExtensionName));
       
   100     QObject *easPluginInstance = easPluginLoader->instance();
       
   101 #endif
       
   102 
       
   103     if(testPluginInstance) {
       
   104         NmUiExtensionInterface *interface = qobject_cast<NmUiExtensionInterface*>(testPluginInstance);
       
   105         if (interface) {
       
   106             mExtensions.append(interface);
       
   107         }
       
   108 
       
   109         // Store QPluginLoader instances to keep plugins alive.
       
   110         // If QPluginLoader instance for a plugin is deleted, then there
       
   111         // is a risk that some component outside will load and unload
       
   112         // plugin, which will lead into situation where plugin is deleted.
       
   113         // This means that instance in mPluginArray will be invalid.
       
   114         mPluginLoaders.append(testPluginLoader);
       
   115     } else {
       
   116         // We don't have proper plugin instance, so we don't need it's loader.
       
   117         delete testPluginLoader;
       
   118         testPluginLoader = NULL;
       
   119     }
       
   120     
       
   121     if(imapPluginInstance) {
       
   122         NmUiExtensionInterface *interface = qobject_cast<NmUiExtensionInterface*>(imapPluginInstance);
       
   123         if (interface) {
       
   124             mExtensions.append(interface);
       
   125         }
       
   126         mPluginLoaders.append(imapPluginLoader);
       
   127     } else {
       
   128         // We don't have proper plugin instance, so we don't need it's loader.
       
   129         delete imapPluginLoader;
       
   130         imapPluginLoader = NULL;
       
   131     }
       
   132     
       
   133     if(popPluginInstance) {
       
   134         NmUiExtensionInterface *interface = qobject_cast<NmUiExtensionInterface*>(popPluginInstance);
       
   135         if (interface) {
       
   136             mExtensions.append(interface);
       
   137         }
       
   138         mPluginLoaders.append(popPluginLoader);
       
   139     } else {
       
   140         // We don't have proper plugin instance, so we don't need it's loader.
       
   141         delete popPluginLoader;
       
   142         popPluginLoader = NULL;
       
   143     }
       
   144 
       
   145 #ifndef NM_WINS_ENV
       
   146     if(easPluginInstance) {
       
   147         NmUiExtensionInterface *interface = qobject_cast<NmUiExtensionInterface*>(easPluginInstance);
       
   148         if (interface) {
       
   149             mExtensions.append(interface);
       
   150         }
       
   151         mPluginLoaders.append(easPluginLoader);
       
   152     } else {
       
   153         // We don't have proper plugin instance, so we don't need it's loader.
       
   154         delete easPluginLoader;
       
   155         easPluginLoader = NULL;
       
   156     }
       
   157 #endif    
       
   158 
       
   159 }
       
   160 
       
   161