|
1 /* |
|
2 * Copyright (c) 2010 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 <QPluginLoader> |
|
19 #include <QDir> |
|
20 #include <QScopedPointer> |
|
21 #include <HbView> |
|
22 #include <QVariant> |
|
23 #include <nmdatamanager.h> |
|
24 #include <nmicons.h> |
|
25 #include <nmcommon.h> |
|
26 |
|
27 #include "nmmailboxsettingsmanager.h" |
|
28 #include "nmsettingsplugininterface.h" |
|
29 |
|
30 |
|
31 /*! |
|
32 \class NmMailboxSettingsManager |
|
33 \brief Provides access to mailbox settings through the setting plug-ins. |
|
34 |
|
35 */ |
|
36 |
|
37 |
|
38 // ======== HELPER FUNCTIONS ======== |
|
39 |
|
40 /*! |
|
41 Creates list of folder paths where plug-ins can be loaded from. |
|
42 \return folder path list. |
|
43 */ |
|
44 QStringList pluginFolders() |
|
45 { |
|
46 NM_FUNCTION; |
|
47 |
|
48 const QString nmSettingsPluginFolderPath("resource/qt/plugins/nmail/settings"); |
|
49 QStringList pluginDirectories; |
|
50 QFileInfoList driveList = QDir::drives(); |
|
51 |
|
52 foreach(const QFileInfo &driveInfo, driveList) { |
|
53 QString pluginDirectory = |
|
54 driveInfo.absolutePath() + nmSettingsPluginFolderPath; |
|
55 |
|
56 if (QFileInfo(pluginDirectory).exists()) { |
|
57 pluginDirectories.append(pluginDirectory); |
|
58 } |
|
59 } |
|
60 |
|
61 return pluginDirectories; |
|
62 } |
|
63 |
|
64 |
|
65 // ======== MEMBER FUNCTIONS ======== |
|
66 |
|
67 /*! |
|
68 Contructor of NmMailboxSettingsManager. |
|
69 */ |
|
70 NmMailboxSettingsManager::NmMailboxSettingsManager() |
|
71 : mDataManager(0) |
|
72 { |
|
73 NM_FUNCTION; |
|
74 |
|
75 QScopedPointer<NmDataManager> dataManager(new NmDataManager()); |
|
76 loadPlugins(); |
|
77 mDataManager = dataManager.take(); |
|
78 } |
|
79 |
|
80 |
|
81 /*! |
|
82 Destructor of NmMailboxSettingsManager. |
|
83 */ |
|
84 NmMailboxSettingsManager::~NmMailboxSettingsManager() |
|
85 { |
|
86 NM_FUNCTION; |
|
87 |
|
88 unloadPlugins(); |
|
89 qDeleteAll(mPluginLoaders); |
|
90 mPluginLoaders.clear(); |
|
91 NmIcons::freeIcons(); |
|
92 delete mDataManager; |
|
93 } |
|
94 |
|
95 |
|
96 /*! |
|
97 Populates the given list with available mailboxes. |
|
98 |
|
99 \param mailboxList List to be popuplated with mailbox entries. |
|
100 |
|
101 */ |
|
102 void NmMailboxSettingsManager::listMailboxes(QList<NmMailbox *> &mailboxList) |
|
103 { |
|
104 NM_FUNCTION; |
|
105 |
|
106 mDataManager->listMailboxes(mailboxList); |
|
107 } |
|
108 |
|
109 |
|
110 /*! |
|
111 Returns a branded icon for the given mailbox id. |
|
112 |
|
113 \param mailboxId Id of the mailbox. |
|
114 \return Icon for the mailbox. |
|
115 */ |
|
116 HbIcon &NmMailboxSettingsManager::mailboxIcon(const NmId &mailboxId) const |
|
117 { |
|
118 NM_FUNCTION; |
|
119 |
|
120 Q_UNUSED(mailboxId); |
|
121 // TODO: use some branding feature when it is available. |
|
122 return NmIcons::getIcon(NmIcons::NmIconDefaultMailbox); |
|
123 } |
|
124 |
|
125 |
|
126 /*! |
|
127 Populates the given data form model with setting items from the correct |
|
128 plug-in. |
|
129 |
|
130 \param model Model to be populated with the setting items. |
|
131 \param form The form where the setting items are placed. |
|
132 \param mailboxId Id of the mailbox which's settings are to be populated to |
|
133 the model. |
|
134 */ |
|
135 void NmMailboxSettingsManager::populateModel(HbDataFormModel &model, |
|
136 HbDataForm &form, const NmId &mailboxId) const |
|
137 { |
|
138 NM_FUNCTION; |
|
139 |
|
140 NmSettingsPluginInterface *plugin = 0; |
|
141 |
|
142 foreach (QPluginLoader *loader, mPluginLoaders) { |
|
143 QObject *pluginInstance = loader->instance(); |
|
144 plugin = qobject_cast<NmSettingsPluginInterface *>(pluginInstance); |
|
145 |
|
146 if (plugin && plugin->populateModel(model, form, mailboxId)) { |
|
147 |
|
148 // We need to disconnect possible previous connections, because we only have |
|
149 // one instance of every plugin. This way we can be sure that signal is send to |
|
150 // correct object. |
|
151 pluginInstance->disconnect(SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType))); |
|
152 pluginInstance->disconnect(SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant))); |
|
153 pluginInstance->disconnect(SIGNAL(goOnline(const NmId &))); |
|
154 pluginInstance->disconnect(SIGNAL(goOffline(const NmId &))); |
|
155 pluginInstance->disconnect(this, SIGNAL(aboutToClose()), pluginInstance, SLOT(aboutToClose())); |
|
156 |
|
157 connect(pluginInstance, SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)), |
|
158 this, SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType))); |
|
159 |
|
160 connect(pluginInstance, SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)), |
|
161 this, SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant))); |
|
162 |
|
163 connect(pluginInstance, SIGNAL(goOnline(const NmId &)), |
|
164 this, SIGNAL(goOnline(const NmId &))); |
|
165 |
|
166 connect(pluginInstance, SIGNAL(goOffline(const NmId &)), |
|
167 this, SIGNAL(goOffline(const NmId &))); |
|
168 |
|
169 connect(this, SIGNAL(aboutToClose()), |
|
170 pluginInstance, SLOT(aboutToClose())); |
|
171 |
|
172 break; |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 |
|
178 /*! |
|
179 Loads plug-ins which implements NmSettingsPluginInterface and are registered |
|
180 to <code>/resource/qt/plugins/nmail/settings</code> folder. |
|
181 */ |
|
182 void NmMailboxSettingsManager::loadPlugins() |
|
183 { |
|
184 NM_FUNCTION; |
|
185 |
|
186 QStringList directories(pluginFolders()); |
|
187 |
|
188 foreach (const QString &directoryPath, directories) { |
|
189 QDir directory(directoryPath); |
|
190 QFileInfoList fileList(directory.entryInfoList()); |
|
191 |
|
192 foreach (const QFileInfo &fileInfo, fileList) { |
|
193 QScopedPointer<QPluginLoader> loader( |
|
194 new QPluginLoader(fileInfo.absoluteFilePath())); |
|
195 mPluginLoaders.append(loader.data()); |
|
196 loader.take(); |
|
197 } |
|
198 } |
|
199 } |
|
200 |
|
201 |
|
202 /*! |
|
203 Unloads plug-ins to ensure that the root component is deleted. |
|
204 */ |
|
205 void NmMailboxSettingsManager::unloadPlugins() |
|
206 { |
|
207 NM_FUNCTION; |
|
208 |
|
209 foreach (QPluginLoader *loader, mPluginLoaders) { |
|
210 loader->unload(); |
|
211 } |
|
212 } |
|
213 |
|
214 // End of file. |