messagingapp/msgutils/unidatamodelloader/src/unidatamodelloader.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     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: Plugin Loader class
       
    15  *
       
    16  */
       
    17 
       
    18 // System Includes
       
    19 
       
    20 #include <QDir>
       
    21 #include "debugtraces.h"
       
    22 
       
    23 #include <QLibraryInfo>
       
    24 #include <QPluginLoader>
       
    25 #include "unidatamodelloader.h"
       
    26 #include "unidatamodelplugininterface.h"
       
    27 
       
    28 //---------------------------------------------------------------
       
    29 //UniDataModelLoader::UniDataModelLoader()
       
    30 //@see header
       
    31 //---------------------------------------------------------------
       
    32 UniDataModelLoader::UniDataModelLoader()
       
    33 {
       
    34 }
       
    35 
       
    36 //---------------------------------------------------------------
       
    37 //UniDataModelLoader::~UniDataModelLoader()
       
    38 //@see header
       
    39 //---------------------------------------------------------------
       
    40 UniDataModelLoader::~UniDataModelLoader()
       
    41 {
       
    42     QMap<QString, UniDataModelPluginInterface*>::iterator mapItor;
       
    43     for (mapItor = mDataModelPluginMap.begin(); mapItor
       
    44             != mDataModelPluginMap.end(); ++mapItor)
       
    45     {
       
    46 #ifdef _DEBUG_TRACES_
       
    47         qDebug() << "Deleting Handler id:" << mapItor.key();
       
    48 #endif
       
    49         UniDataModelPluginInterface* handler = mapItor.value();
       
    50         if (handler)
       
    51             delete handler;
       
    52     }
       
    53     mDataModelPluginMap.clear();
       
    54 }
       
    55 
       
    56 //---------------------------------------------------------------
       
    57 //UniDataModelLoader::loadPlugins()
       
    58 //@see header
       
    59 //---------------------------------------------------------------
       
    60 void UniDataModelLoader::loadPlugins()
       
    61 {
       
    62     // plugins directory setting for EMULATOR
       
    63 #ifdef __WINS__
       
    64     QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath));
       
    65     dir.cd("messaging\\datamodel");
       
    66 #else
       
    67     // plugins directory setting for HARDWARE IMAGE
       
    68     QDir dir("Z:\\resource\\qt\\plugins\\messaging\\datamodel");
       
    69 #endif
       
    70     QString pluginPath = dir.absolutePath();
       
    71 #ifdef _DEBUG_TRACES_
       
    72     qDebug() << "Enter LoadPlugin path = " << pluginPath;
       
    73 #endif
       
    74 
       
    75     // load the plugins
       
    76     QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Readable);
       
    77     foreach (QFileInfo entry, entries) 
       
    78         {
       
    79             QPluginLoader loader(entry.absoluteFilePath());
       
    80             // Check if plugin is already loaded...
       
    81             if (!loader.isLoaded())
       
    82             {
       
    83                 UniDataModelPluginInterface* datamodelPlugin = qobject_cast<
       
    84                         UniDataModelPluginInterface*> (loader.instance());
       
    85                 if (datamodelPlugin)
       
    86                 {
       
    87                 	  UniDataModelPluginInterface* pluginInstance = qobject_cast<
       
    88                         UniDataModelPluginInterface*> (datamodelPlugin->createInstance());                        
       
    89                     QString mType = pluginInstance->messageType();
       
    90                     QDEBUG_WRITE_FORMAT("plugin added to map", mType);
       
    91                     mDataModelPluginMap.insert(mType, pluginInstance);
       
    92                 }
       
    93             }
       
    94 
       
    95         }
       
    96 }
       
    97 
       
    98 //---------------------------------------------------------------
       
    99 //UniDataModelLoader::getDataModelPlugin()
       
   100 //@see header
       
   101 //---------------------------------------------------------------
       
   102 UniDataModelPluginInterface* UniDataModelLoader::getDataModelPlugin(
       
   103                                                                     const QString& messageType)
       
   104 {
       
   105     if (mDataModelPluginMap.contains(messageType))
       
   106     {
       
   107 		QDEBUG_WRITE_FORMAT("getDataModelPlugin messageType is present ", messageType);
       
   108         return mDataModelPluginMap[messageType];
       
   109     }
       
   110     return NULL;
       
   111 }