messagingapp/msgutils/unieditorplugins/unieditorpluginloader/src/unieditorpluginloader.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:
       
    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 //---------------------------------------------------------------
       
    29 //UniEditorPluginLoader::UniEditorPluginLoader()
       
    30 //@see header
       
    31 //---------------------------------------------------------------
       
    32 UniEditorPluginLoader::UniEditorPluginLoader(QObject* parent) :
       
    33 QObject(parent)
       
    34 {
       
    35 }
       
    36 
       
    37 //---------------------------------------------------------------
       
    38 //UniEditorPluginLoader::~UniEditorPluginLoader()
       
    39 //@see header
       
    40 //---------------------------------------------------------------
       
    41 UniEditorPluginLoader::~UniEditorPluginLoader()
       
    42 {
       
    43     // unload all qt-plugins
       
    44     int count = mPluginLoaderList.count();
       
    45     for(int i=0; i<count; i++)
       
    46     {
       
    47         mPluginLoaderList.at(i)->unload();
       
    48     }
       
    49     mEditorPluginMap.clear();
       
    50 }
       
    51 
       
    52 //---------------------------------------------------------------
       
    53 //UniEditorPluginLoader::loadPlugins()
       
    54 //@see header
       
    55 //---------------------------------------------------------------
       
    56 void UniEditorPluginLoader::loadPlugins()
       
    57 {
       
    58     // plugins directory setting for EMULATOR
       
    59 #ifdef _DEBUG
       
    60     QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath));
       
    61     dir.cd("messaging\\editorplugins");
       
    62 #else
       
    63     // plugins directory setting for HARDWARE IMAGE
       
    64     QDir dir("Z:\\resource\\qt\\plugins\\messaging\\editorplugins");
       
    65 #endif
       
    66 
       
    67     QString pluginPath = dir.absolutePath();
       
    68 #ifdef _DEBUG_TRACES_
       
    69     qDebug() << "Enter LoadPlugin path = " << pluginPath;
       
    70 #endif
       
    71 
       
    72     // load the plugins
       
    73     QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Readable);
       
    74     foreach (QFileInfo entry, entries)
       
    75         {
       
    76             QPluginLoader* loader = new QPluginLoader(entry.absoluteFilePath(), this);
       
    77             UniEditorPluginInterface* editorPlugin =
       
    78                  qobject_cast<UniEditorPluginInterface*> (loader->instance());
       
    79             if (editorPlugin)
       
    80             {
       
    81                 int msgtype = editorPlugin->messageType();
       
    82                 mEditorPluginMap.insert(msgtype, editorPlugin);
       
    83                 mPluginLoaderList << loader;
       
    84             }
       
    85         }
       
    86 }
       
    87 
       
    88 //---------------------------------------------------------------
       
    89 //UniEditorPluginLoader::getUniEditorPlugin()
       
    90 //@see header
       
    91 //---------------------------------------------------------------
       
    92 UniEditorPluginInterface* UniEditorPluginLoader::getUniEditorPlugin(
       
    93 	                          ConvergedMessage::MessageType messageType)
       
    94 {
       
    95     if (mEditorPluginMap.contains(messageType))
       
    96     {
       
    97         return mEditorPluginMap[messageType];
       
    98     }
       
    99     return NULL;
       
   100 }