messagingapp/msgutils/unieditorutils/unieditorpluginloader/src/unieditorpluginloader.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:
       
    15  *
       
    16  */
       
    17 
       
    18 // System Includes
       
    19 
       
    20 #include <QDir>
       
    21 #include "debugtraces.h"
       
    22 
       
    23 #include <QLibraryInfo>
       
    24 #include <QPluginLoader>
       
    25 #include "unieditorpluginloader.h"
       
    26 #include "unieditorplugininterface.h"
       
    27 
       
    28 // LOCAL CONSTANTS
       
    29 const QString MMS_PLUGIN("unieditormmsplugin.qtplugin");
       
    30 const QString SMS_PLUGIN("unieditorsmsplugin.qtplugin");
       
    31 
       
    32 //---------------------------------------------------------------
       
    33 //UniEditorPluginLoader::UniEditorPluginLoader()
       
    34 //@see header
       
    35 //---------------------------------------------------------------
       
    36 UniEditorPluginLoader::UniEditorPluginLoader(QObject* parent) :
       
    37     QObject(parent)
       
    38 {
       
    39 }
       
    40 
       
    41 //---------------------------------------------------------------
       
    42 //UniEditorPluginLoader::~UniEditorPluginLoader()
       
    43 //@see header
       
    44 //---------------------------------------------------------------
       
    45 UniEditorPluginLoader::~UniEditorPluginLoader()
       
    46 {
       
    47     // unload all qt-plugins
       
    48     int count = mPluginLoaderList.count();
       
    49     for (int i = 0; i < count; i++)
       
    50     {
       
    51         mPluginLoaderList.at(i)->unload();
       
    52     }
       
    53     mPluginLoaderList.clear();
       
    54 }
       
    55 
       
    56 
       
    57 //---------------------------------------------------------------
       
    58 //UniEditorPluginLoader::getUniEditorPlugin()
       
    59 //@see header
       
    60 //---------------------------------------------------------------
       
    61 UniEditorPluginInterface* UniEditorPluginLoader::getUniEditorPlugin(
       
    62                                                                     ConvergedMessage::MessageType messageType)
       
    63 {
       
    64 #ifdef _DEBUG
       
    65     QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath));
       
    66     dir.cd("messaging\\editorplugins");
       
    67 #else
       
    68     // plugins directory setting for HARDWARE IMAGE
       
    69     QDir dir("Z:\\resource\\qt\\plugins\\messaging\\editorplugins");
       
    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         }
       
    95 
       
    96     if (!filePath.isEmpty())
       
    97     {
       
    98         QPluginLoader* loader = new QPluginLoader(filePath, this);
       
    99         UniEditorPluginInterface* editorPlugin = qobject_cast<
       
   100                 UniEditorPluginInterface*> (loader->instance());
       
   101         if (editorPlugin)
       
   102         {
       
   103             mPluginLoaderList << loader;
       
   104             return editorPlugin;
       
   105         }
       
   106     }
       
   107     return NULL;
       
   108 }