contentstorage/caclient/s60/src/caqtsfhandlerloader.cpp
changeset 96 5d243a69bdda
parent 95 c739008478cc
child 97 1e962b12a8db
equal deleted inserted replaced
95:c739008478cc 96:5d243a69bdda
     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 #include <QApplication>
       
    19 #include <QDir>
       
    20 #include <QMap>
       
    21 #include <QScopedPointer>
       
    22 #include <QString>
       
    23 #include <qservice.h>
       
    24 #include <qstringlist.h>
       
    25 #include <qservicemanager.h>
       
    26 
       
    27 #include "cahandler.h"
       
    28 #include "caqtsfhandlerloader.h"
       
    29 #include "caclient_defines.h"
       
    30 
       
    31 QTM_USE_NAMESPACE
       
    32 
       
    33 /*!
       
    34     \class CaQtSfHandlerLoader
       
    35     \ingroup
       
    36     \brief Loads handlers implementation
       
    37 
       
    38     The purpose of the class is to find Qt SF plugins implementing command handlers.
       
    39     Temporarily because of issues with Qt SF this is replaced by immediate object
       
    40     creation.
       
    41     \sa CaHandlerLoader
       
    42 */
       
    43 
       
    44 /*!
       
    45     Constructor.
       
    46 */
       
    47 CaQtSfHandlerLoader::CaQtSfHandlerLoader()
       
    48 {
       
    49     registerPlugins();
       
    50 }
       
    51 
       
    52 /*!
       
    53     Load plugins for command handling.
       
    54 */
       
    55 void CaQtSfHandlerLoader::registerPlugins() const
       
    56 {
       
    57     const QString pluginPath("hsresources/plugins/commandhandler");
       
    58     const QFileInfoList drives = QDir::drives();
       
    59     
       
    60     foreach(QFileInfo drive, drives) {
       
    61         const QString driveLetter = drive.absolutePath();
       
    62         const QString pluginAbsolutePath = driveLetter + pluginPath;
       
    63         const QDir pluginDir(pluginAbsolutePath);
       
    64         if(QDir(pluginDir).exists()) {
       
    65             const QFileInfoList fileInfos = 
       
    66                 pluginDir.entryInfoList(QStringList("*.xml"));
       
    67             
       
    68             QApplication::addLibraryPath(pluginAbsolutePath);
       
    69             
       
    70             QServiceManager serviceManager;
       
    71             foreach(QFileInfo fileInfo, fileInfos) {
       
    72                 serviceManager.addService(fileInfo.absoluteFilePath());
       
    73             }
       
    74         }
       
    75     }
       
    76 }
       
    77 
       
    78 /*!
       
    79     Loads handler implementations appropriate for the requested entry type name and command.
       
    80 
       
    81     The caller takes ownership of the returned pointer.
       
    82 
       
    83     \param entryTypeName Entry type name.
       
    84     \param commandName Name of the command to be handled.
       
    85     \return A pointer to handler serving the entry type and command if found, NULL otherwise.
       
    86 */
       
    87 CaHandler *CaQtSfHandlerLoader::loadHandler(const QString &entryTypeName,
       
    88         const QString &commandName)
       
    89 {
       
    90     Q_UNUSED(commandName);
       
    91 
       
    92     QString typeName(entryTypeName);
       
    93     if (entryTypeName == WIDGET_ENTRY_TYPE_NAME
       
    94         || entryTypeName == PACKAGE_ENTRY_TYPE_NAME) {
       
    95         typeName = QString(APPLICATION_ENTRY_TYPE_NAME);
       
    96     }
       
    97 
       
    98     QServiceManager serviceManager;
       
    99     QServiceFilter serviceFilter("com.nokia.homescreen.ICommandHandler");
       
   100     serviceFilter.setCustomAttribute("entryTypeName", typeName);
       
   101     QList<QServiceInterfaceDescriptor> serviceInterfaceDescriptorList =
       
   102         serviceManager.findInterfaces(serviceFilter);
       
   103     CaHandler *interfaceHandler = NULL;
       
   104     if (!serviceInterfaceDescriptorList.isEmpty()) {
       
   105         QServiceInterfaceDescriptor serviceInterfaceDescriptor =
       
   106             serviceInterfaceDescriptorList[0];
       
   107          QObject *handler =
       
   108             serviceManager.loadInterface(serviceInterfaceDescriptor);
       
   109          interfaceHandler = qobject_cast<CaHandler *>(handler);
       
   110     }
       
   111     return interfaceHandler;
       
   112 }
       
   113 
       
   114