13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 #include <QApplication> |
|
19 #include <QDir> |
18 #include <QMap> |
20 #include <QMap> |
19 #include <QScopedPointer> |
21 #include <QScopedPointer> |
20 #include <QString> |
22 #include <QString> |
21 #include <qservice.h> |
23 #include <qservice.h> |
22 #include <qstringlist.h> |
24 #include <qstringlist.h> |
23 #include <qservicemanager.h> |
25 #include <qservicemanager.h> |
24 |
26 |
25 #include "cahandler.h" |
27 #include "cahandler.h" |
26 #include "caqtsfhandlerloader.h" |
28 #include "caqtsfhandlerloader.h" |
27 #include "caclient_defines.h" |
29 #include "caclient_defines.h" |
28 #include "caapphandler.h" |
|
29 #include "caurlhandler.h" |
|
30 #include "catapphandler.h" |
|
31 #include "cas60handleradapter.h" |
|
32 |
30 |
33 QTM_USE_NAMESPACE |
31 QTM_USE_NAMESPACE |
34 |
32 |
35 /*! |
33 /*! |
36 \class CaQtSfHandlerLoader |
34 \class CaQtSfHandlerLoader |
37 \ingroup |
35 \ingroup |
38 \brief Loads handlers implementation |
36 \brief Loads handlers implementation |
39 |
37 |
40 The purpose of the class is to find Qt SF plugins implementing command handlers. |
38 The purpose of the class is to find Qt SF plugins implementing command handlers. |
41 Temporarily because of issues with Qt SF this is replaced by immediate object |
39 Temporarily because of issues with Qt SF this is replaced by immediate object |
42 creation. |
40 creation. |
43 \sa CaHandlerLoader |
41 \sa CaHandlerLoader |
44 */ |
42 */ |
45 |
43 |
46 /*! |
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 /*! |
47 Loads handler implementations appropriate for the requested entry type name and command. |
79 Loads handler implementations appropriate for the requested entry type name and command. |
48 |
80 |
49 The caller takes ownership of the returned pointer. |
81 The caller takes ownership of the returned pointer. |
50 |
82 |
51 \param entryTypeName Entry type name. |
83 \param entryTypeName Entry type name. |
52 \param commandName Name of the command to be handled. |
84 \param commandName Name of the command to be handled. |
53 \return A pointer to handler serving the entry type and command if found, NULL otherwise. |
85 \return A pointer to handler serving the entry type and command if found, NULL otherwise. |
54 */ |
86 */ |
55 CaHandler *CaQtSfHandlerLoader::loadHandler(const QString &entryTypeName, |
87 CaHandler *CaQtSfHandlerLoader::loadHandler(const QString &entryTypeName, |
56 const QString &commandName) |
88 const QString &commandName) |
57 { |
89 { |
58 Q_UNUSED(commandName); |
90 Q_UNUSED(commandName); |
59 |
91 |
60 CaHandler *implementation(0); |
92 QString typeName(entryTypeName); |
61 |
93 if (entryTypeName == WIDGET_ENTRY_TYPE_NAME |
62 if (entryTypeName == APPLICATION_ENTRY_TYPE_NAME |
94 || entryTypeName == PACKAGE_ENTRY_TYPE_NAME) { |
63 || entryTypeName == WIDGET_ENTRY_TYPE_NAME) { |
95 typeName = QString(APPLICATION_ENTRY_TYPE_NAME); |
64 implementation = new CaS60HandlerAdapter<CCaAppHandler>; |
|
65 } else if (entryTypeName == URL_ENTRY_TYPE_NAME) { |
|
66 implementation = new CaS60HandlerAdapter<CCaUrlHandler>; |
|
67 } else if (entryTypeName == TEMPLATED_APPLICATION_ENTRY_TYPE_NAME) { |
|
68 implementation = new CaTappHandler; |
|
69 } |
96 } |
70 |
97 |
71 return implementation; |
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; |
72 } |
112 } |
73 |
113 |
74 |
114 |