commonimlib/src/chatimplfactory.cpp
author shivsood
Mon, 11 Oct 2010 12:06:54 +0530
changeset 1 6bb5c618bd31
parent 0 59dfe4ae66d0
permissions -rw-r--r--
RCS IM Libraray - Adding readme.txt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     1
/*
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     2
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     3
* All rights reserved.
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     4
* This component and the accompanying materials are made available
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     6
* which accompanies this distribution, and is available
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html."
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     8
* Initial Contributors:
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
     9
* Nokia Corporation - initial contribution.
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    10
* Contributors:
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    11
*
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    12
* Description:
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    13
* RCS IM Library - Initial version
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    14
*
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    15
*/
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    16
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    17
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    18
#include "chatinterfaces.h"
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    19
#include "immanagerfactory.h"
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    20
#include "chatimplfactory.h"
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    21
#include <QtPlugin>
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    22
#include <QDir>
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    23
#include <QLibraryInfo>
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    24
#include <QPluginLoader>
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    25
#include <QCoreApplication>
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    26
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    27
RcsIMLib::MChatContactManagerIntf* ChatImplFactory::createIMManager(QString protocol)
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    28
{
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    29
#ifdef Q_OS_SYMBIAN
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    30
    QDir pluginsDir = QLibraryInfo::location(QLibraryInfo::PluginsPath) + "/IMLIB";
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    31
#else
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    32
    QDir pluginsDir = QCoreApplication::applicationDirPath() + "/resource/qt/plugins/IMLIB";
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    33
#endif
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    34
	/* Now doing a dirty implementation.
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    35
	 * The real thing to do is parse manifests and compare each plugin for
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    36
	 * the protocol string 
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    37
	 */
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    38
	IMManagerFactory* imManagerFact=0;
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    39
    foreach (QString fileName, pluginsDir.entryList(QDir::Files)) 
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    40
	{
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    41
        QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    42
        QObject *plugin = pluginLoader.instance();
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    43
        if (plugin) 
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    44
	    {
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    45
           imManagerFact = qobject_cast<IMManagerFactory *>(plugin);
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    46
           if (imManagerFact && imManagerFact->protocol()==protocol)
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    47
		   {
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    48
		   RcsIMLib::MChatContactManagerIntf* imManager = imManagerFact->createIMManager();
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    49
			   //delete imManagerFact;
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    50
               return imManager;
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    51
		   }
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    52
		   //delete imManagerFact;
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    53
		   imManagerFact = 0;
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    54
        }	
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    55
	}
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    56
	return 0;
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    57
}
59dfe4ae66d0 RCS IM Library - Initial implementation
shivsood
parents:
diff changeset
    58