|
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 "nmuiheaders.h" |
|
19 |
|
20 static const QString NmSettingsPluginFolderPath("/resource/qt/plugins/nmail/uiext"); |
|
21 |
|
22 /*! |
|
23 \class NmUiExtensionManager |
|
24 \brief Handles ui extension plugins |
|
25 */ |
|
26 |
|
27 /*! |
|
28 Creates list of folder paths where plug-ins can be loaded from. |
|
29 \return folder path list. |
|
30 */ |
|
31 QStringList NmUiExtensionManager::pluginFolders() |
|
32 { |
|
33 NM_FUNCTION; |
|
34 |
|
35 QStringList pluginDirectories; |
|
36 QFileInfoList driveList = QDir::drives(); |
|
37 |
|
38 foreach(const QFileInfo &driveInfo, driveList) { |
|
39 QString pluginDirectory = |
|
40 driveInfo.absolutePath() + NmSettingsPluginFolderPath; |
|
41 NMLOG(QString("fileInfo.absoluteFilePath() : %1").arg(pluginDirectory)); |
|
42 if (QFileInfo(pluginDirectory).exists()) { |
|
43 pluginDirectories.append(pluginDirectory); |
|
44 } |
|
45 } |
|
46 |
|
47 return pluginDirectories; |
|
48 } |
|
49 |
|
50 NmUiExtensionManager::NmUiExtensionManager() |
|
51 { |
|
52 NM_FUNCTION; |
|
53 |
|
54 // load the protocol extension plugins |
|
55 loadExtensionPlugins(); |
|
56 } |
|
57 |
|
58 /*! |
|
59 Destructor |
|
60 */ |
|
61 NmUiExtensionManager::~NmUiExtensionManager() |
|
62 { |
|
63 NM_FUNCTION; |
|
64 |
|
65 // delete plugins from array |
|
66 qDeleteAll(mExtensions.begin(), mExtensions.end()); |
|
67 mExtensions.clear(); |
|
68 |
|
69 qDeleteAll(mPluginLoaders.begin(), mPluginLoaders.end()); |
|
70 mPluginLoaders.clear(); |
|
71 } |
|
72 |
|
73 /*! |
|
74 Calls all extensions |
|
75 */ |
|
76 void NmUiExtensionManager::getActions( |
|
77 const NmActionRequest &menuRequest, |
|
78 QList<NmAction*> &actionList) |
|
79 { |
|
80 NM_FUNCTION; |
|
81 |
|
82 for (int i = 0; i < mExtensions.count(); i++) { |
|
83 NmUiExtensionInterface *interface = mExtensions[i]; |
|
84 interface->getActions(menuRequest, actionList); |
|
85 } |
|
86 } |
|
87 /*! |
|
88 Loads plug-ins which implements NmUiExtensionInterface and are registered |
|
89 to <code>/resource/qt/plugins/nmail/uiext</code> folder. |
|
90 */ |
|
91 void NmUiExtensionManager::loadExtensionPlugins() |
|
92 { |
|
93 NM_FUNCTION; |
|
94 |
|
95 QStringList directories(pluginFolders()); |
|
96 foreach (const QString &directoryPath, directories) { |
|
97 QDir directory(directoryPath); |
|
98 QFileInfoList fileList(directory.entryInfoList()); |
|
99 |
|
100 foreach (const QFileInfo &fileInfo, fileList) { |
|
101 NM_COMMENT(QString("Plugin absolute FilePath : %1").arg(fileInfo.absoluteFilePath())); |
|
102 QScopedPointer<QPluginLoader> loader( |
|
103 new QPluginLoader(fileInfo.absoluteFilePath())); |
|
104 mPluginLoaders.append(loader.data()); |
|
105 loader.take(); |
|
106 } |
|
107 } |
|
108 |
|
109 NmUiExtensionInterface *interface(NULL); |
|
110 foreach (QPluginLoader *loader, mPluginLoaders) { |
|
111 NM_COMMENT(QString("Plugin fileName() : %1").arg(loader->fileName())); |
|
112 QString fileName = loader->fileName(); |
|
113 QObject *pluginInstance = loader->instance(); |
|
114 interface = qobject_cast<NmUiExtensionInterface*>(pluginInstance); |
|
115 if (interface) { |
|
116 mExtensions.append(interface); |
|
117 } |
|
118 } |
|
119 } |
|
120 |
|
121 |