messagingapp/msgutils/unidatautils/unidatamodelloader/src/unidatamodelloader.cpp
changeset 25 84d9eb65b26f
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 // LOCAL CONSTANTS
       
    29 const QString MMS_PLUGIN("unimmsdataplugin.qtplugin");
       
    30 const QString SMS_PLUGIN("unismsdataplugin.qtplugin");
       
    31 const QString BIO_PLUGIN("unibiomessagedataplugin.qtplugin");
       
    32 
       
    33 
       
    34 //---------------------------------------------------------------
       
    35 //UniDataModelLoader::UniDataModelLoader()
       
    36 //@see header
       
    37 //---------------------------------------------------------------
       
    38 UniDataModelLoader::UniDataModelLoader()	
       
    39 {
       
    40 }
       
    41 
       
    42 //---------------------------------------------------------------
       
    43 //UniDataModelLoader::~UniDataModelLoader()
       
    44 //@see header
       
    45 //---------------------------------------------------------------
       
    46 UniDataModelLoader::~UniDataModelLoader()
       
    47 {
       
    48     // unload all qt-plugins
       
    49     int count = mPluginLoaderList.count();
       
    50     for (int i = 0; i < count; i++)
       
    51     {
       
    52         mPluginLoaderList.at(i)->unload();
       
    53     }
       
    54     mPluginLoaderList.clear();
       
    55 }
       
    56 
       
    57 //---------------------------------------------------------------
       
    58 //UniDataModelLoader::getDataModelPlugin()
       
    59 //@see header
       
    60 //---------------------------------------------------------------
       
    61 UniDataModelPluginInterface* UniDataModelLoader::getDataModelPlugin(
       
    62                                                                     ConvergedMessage::MessageType messageType)
       
    63 {
       
    64    #ifdef _DEBUG
       
    65     QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath));
       
    66     dir.cd("messaging\\datamodel");
       
    67 #else
       
    68     // plugins directory setting for HARDWARE IMAGE
       
    69     QDir dir("Z:\\resource\\qt\\plugins\\messaging\\datamodel");
       
    70 #endif
       
    71 
       
    72     QString pluginPath = dir.absolutePath();
       
    73 #ifdef _DEBUG_TRACES_
       
    74     qDebug() << "Enter LoadPlugin path = " << pluginPath;
       
    75 #endif
       
    76 
       
    77     // get the list of all plugins...
       
    78     QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Readable);
       
    79     QString filePath = QString();
       
    80     foreach (QFileInfo entry, entries)
       
    81         {
       
    82             if (messageType == ConvergedMessage::Sms && entry.fileName()
       
    83                     == SMS_PLUGIN)
       
    84             {
       
    85                 filePath = entry.absoluteFilePath();
       
    86                 break;
       
    87             }
       
    88             else if (messageType == ConvergedMessage::Mms && entry.fileName()
       
    89                     == MMS_PLUGIN)
       
    90             {
       
    91                 filePath = entry.absoluteFilePath();
       
    92                 break;
       
    93             }
       
    94             else if (messageType == ConvergedMessage::BioMsg && entry.fileName()
       
    95                     == BIO_PLUGIN)
       
    96             {
       
    97                 filePath = entry.absoluteFilePath();
       
    98                 break;
       
    99             }
       
   100         }
       
   101 
       
   102     if (!filePath.isEmpty())
       
   103     {
       
   104         QPluginLoader* loader = new QPluginLoader(filePath);
       
   105         UniDataModelPluginInterface* dataModelPluginInterface = qobject_cast<
       
   106                 UniDataModelPluginInterface*> (loader->instance());
       
   107         if (dataModelPluginInterface)
       
   108         {
       
   109             mPluginLoaderList << loader;
       
   110             return dataModelPluginInterface;
       
   111         }
       
   112     }
       
   113     return NULL;
       
   114 }