13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 #include "emailtrace.h" |
|
19 |
18 #include <qservicemanager.h> |
20 #include <qservicemanager.h> |
19 #include <qserviceinterfacedescriptor.h> |
21 #include <qserviceinterfacedescriptor.h> |
20 #include <HbIcon> |
22 #include <HbIcon> |
21 #include <HbApplication> |
23 #include <HbApplication> |
22 #include <QTranslator> |
24 #include <QTranslator> |
23 #include "nmicons.h" |
25 #include "nmicons.h" |
24 #include "nmmailboxregisterinterface.h" |
26 #include "nmmailboxregisterinterface.h" |
25 #include "nmmailboxregisterinterface_p.h" |
27 #include "nmmailboxregisterinterface_p.h" |
26 |
28 |
27 //mandatory keys |
29 //mandatory keys |
28 const QString hsItemName ("item:name"); |
30 const QString hsItemName("item:name"); |
29 const QString hsitemLaunchUri ("item:launchuri"); |
31 const QString hsitemLaunchUri("item:launchuri"); |
30 const QString hsitemPublisherId ("item:publisherId"); |
32 const QString hsitemPublisherId("item:publisherId"); |
31 //not mandatory |
33 //not mandatory |
32 const QString hsItemWidgetUri ("widget:uri"); |
34 const QString hsItemWidgetUri("widget:uri"); |
33 const QString hsItemDescription ("item:description"); |
35 const QString hsItemDescription("item:description"); |
34 //for icon - not mandatory |
36 //for icon - not mandatory |
35 const QString hsIconFileName ("icon:filename");//to display specific icon from file |
37 const QString hsIconFileName("icon:filename");//to display specific icon from file |
36 const QString hsIconName ("icon:name");// HbIcon |
38 const QString hsIconName("icon:name");// HbIcon |
37 const QString hsIconApplicationId ("icon:applicationid"); // icon from associated application |
39 const QString hsIconApplicationId("icon:applicationid"); // icon from associated application |
38 |
40 |
39 //Custom for nmHsWidgets |
41 //Custom for nmHsWidgets |
40 //NmHsWidgetParamAccountId is used to identify what email account will be monitored by |
42 //NmHsWidgetParamAccountId is used to identify what email account will be monitored by |
41 //the registered hs widget |
43 //the registered hs widget |
42 const QString NmHsWidgetParamAccountId ("widgetparam:accountId"); |
44 const QString NmHsWidgetParamAccountId("widgetparam:accountId"); |
43 //same as above but for pushing the widget to homescreen |
45 //same as above but for pushing the widget to homescreen |
44 const QString NmHsAccountId ("accountId"); |
46 const QString NmHsAccountId("accountId"); |
45 //NmHsWidgetParamAccountIconName is used to identify mailbox icon in application library |
47 //NmHsWidgetParamAccountIconName is used to identify mailbox icon in application library |
46 const QString NmHsWidgetParamAccountIconName ("widgetparam:accountIconName"); |
48 const QString NmHsWidgetParamAccountIconName("widgetparam:accountIconName"); |
47 //same as above but for pushing the widget to homescreen |
49 //same as above but for pushing the widget to homescreen |
48 const QString NmHsAccountIconName ("accountIconName"); |
50 const QString NmHsAccountIconName("accountIconName"); |
49 //This is used to identify nmhswidget in homescreen |
51 //This is used to identify nmhswidget in homescreen |
50 const QString NmHsWidget ("nmhswidget"); |
52 const QString NmHsWidget("nmhswidget"); |
51 |
53 |
52 //parameter values |
54 //parameter values |
53 const QString NmPublisherName ("NmMailboxRegisterInterface"); |
55 const QString NmPublisherName("NmMailboxRegisterInterface"); |
54 const QString NmLaunchUri ("appto://0x200255BA?activityname=EmailInboxView&accountId="); |
56 const QString NmLaunchUri("appto://0x200255BA?activityname=EmailInboxView&accountId="); |
55 //URI for the defined service |
57 //URI for the defined service |
56 const QLatin1String interfaceUri("com.nokia.symbian.IEmailRegisterAccount"); |
58 const QLatin1String interfaceUri("com.nokia.symbian.IEmailRegisterAccount"); |
57 |
59 |
58 /** Localization file name*/ |
60 /** Localization file name*/ |
59 const QString KNmRegisterLocFileName = "nmregister_"; |
61 const QString KNmRegisterLocFileName = "nmregister_"; |
60 /** Localization file location*/ |
62 /** Localization file location*/ |
61 const QString KNmRegisterLocLocation = "z:/resource/qt/translations/"; |
63 const QString KNmRegisterLocLocation = "/translations/"; |
62 |
64 |
63 /*! |
65 /*! |
64 Constructor |
66 Constructor |
65 */ |
67 */ |
66 NmMailboxRegisterInterface::NmMailboxRegisterInterface(QObject *parent) : |
68 NmMailboxRegisterInterface::NmMailboxRegisterInterface(QObject *parent) : |
67 QObject(parent), m_d( new NmMailboxRegisterInterfacePrivate(this) ) |
69 QObject(parent), m_d(new NmMailboxRegisterInterfacePrivate(this)) |
68 { |
70 { |
69 } |
71 NM_FUNCTION; |
70 |
72 } |
71 /*! |
73 |
72 Destructor |
74 /*! |
73 */ |
75 Destructor |
|
76 */ |
74 NmMailboxRegisterInterface::~NmMailboxRegisterInterface() |
77 NmMailboxRegisterInterface::~NmMailboxRegisterInterface() |
75 { |
78 { |
|
79 NM_FUNCTION; |
|
80 |
76 delete m_d; |
81 delete m_d; |
77 } |
82 } |
78 |
83 |
79 /*! |
84 /*! |
80 registerNewMailbox |
85 registerNewMailbox |
81 */ |
86 */ |
82 bool NmMailboxRegisterInterface::registerNewMailbox(quint64 accountId, |
87 bool NmMailboxRegisterInterface::registerNewMailbox( |
83 QString accountName, QString accountIconName) |
88 quint64 accountId, |
84 { |
89 QString accountName, |
85 return m_d->registerNewMailbox( accountId, accountName, accountIconName ); |
90 QString accountIconName) |
86 } |
91 { |
87 |
92 NM_FUNCTION; |
88 /*! |
93 |
89 updateMailboxName |
94 return m_d->registerNewMailbox(accountId, accountName, accountIconName); |
90 */ |
95 } |
91 bool NmMailboxRegisterInterface::updateMailboxName(quint64 accountId, |
96 |
92 QString newName) |
97 /*! |
93 { |
98 updateMailboxName |
94 return m_d->updateMailboxName( accountId, newName ); |
99 */ |
95 } |
100 bool NmMailboxRegisterInterface::updateMailboxName(quint64 accountId, QString newName) |
96 |
101 { |
97 |
102 NM_FUNCTION; |
98 /*! |
103 |
99 unregisterMailbox |
104 return m_d->updateMailboxName(accountId, newName); |
100 */ |
105 } |
|
106 |
|
107 /*! |
|
108 unregisterMailbox |
|
109 */ |
101 bool NmMailboxRegisterInterface::unregisterMailbox(quint64 accountId) |
110 bool NmMailboxRegisterInterface::unregisterMailbox(quint64 accountId) |
102 { |
111 { |
103 return m_d->unregisterMailbox( accountId ); |
112 NM_FUNCTION; |
104 } |
113 |
105 |
114 return m_d->unregisterMailbox(accountId); |
106 |
115 } |
107 |
116 |
108 |
117 /*! |
109 |
118 Constructor |
110 /*! |
119 */ |
111 Constructor |
|
112 */ |
|
113 NmMailboxRegisterInterfacePrivate::NmMailboxRegisterInterfacePrivate(QObject *parent) : |
120 NmMailboxRegisterInterfacePrivate::NmMailboxRegisterInterfacePrivate(QObject *parent) : |
114 XQServiceProvider(interfaceUri, parent ), |
121 XQServiceProvider(interfaceUri, parent), |
115 mManager(0), |
122 mManager(new QServiceManager()), |
116 mService(0), |
123 mService(0), |
117 mTranslator(0) |
124 mTranslator(new QTranslator()) |
118 { |
125 { |
119 //commented out until MCL has nmregister files in place here: epoc32/include/platform/qt/translations/ |
126 NM_FUNCTION; |
120 /*mTranslator = new QTranslator(); |
127 } |
|
128 |
|
129 /*! |
|
130 loadMenuClientService() |
|
131 Loads the Menu client service to mService. |
|
132 \return true if mService exists or is succesfully loaded, otherwise false. |
|
133 */ |
|
134 bool NmMailboxRegisterInterfacePrivate::loadMenuClientService() |
|
135 { |
|
136 if (mService){ |
|
137 return true; //service is already loaded |
|
138 } |
|
139 |
|
140 QServiceFilter filter("com.nokia.symbian.IMenuClient"); |
|
141 QList<QServiceInterfaceDescriptor> interfaces = mManager->findInterfaces(filter); |
|
142 if(interfaces.isEmpty()){ |
|
143 return false; //no maching interfaces available |
|
144 } |
|
145 |
|
146 mService = mManager->loadInterface(interfaces.first()); |
|
147 if(!mService){ |
|
148 return false; //loading interface failed |
|
149 } |
|
150 |
|
151 return true; //succesfully loaded the service |
|
152 } |
|
153 |
|
154 /*! |
|
155 Destructor |
|
156 */ |
|
157 NmMailboxRegisterInterfacePrivate::~NmMailboxRegisterInterfacePrivate() |
|
158 { |
|
159 NM_FUNCTION; |
|
160 |
|
161 delete mTranslator; |
|
162 mTranslator = NULL; |
|
163 |
|
164 delete mService; |
|
165 mService = NULL; |
|
166 |
|
167 delete mManager; |
|
168 mManager = NULL; |
|
169 } |
|
170 |
|
171 bool NmMailboxRegisterInterfacePrivate::registerNewMailbox( |
|
172 quint64 accountId, |
|
173 QString accountName, |
|
174 QString accountIconName) |
|
175 { |
|
176 NM_FUNCTION; |
|
177 |
|
178 if(!loadMenuClientService()){ |
|
179 NM_ERROR(1,"loadService() failed!"); |
|
180 return false; |
|
181 } |
|
182 |
|
183 //localization |
121 QString lang = QLocale::system().name(); |
184 QString lang = QLocale::system().name(); |
122 bool loadSucceed = mTranslator->load(KNmRegisterLocFileName + lang, KNmRegisterLocLocation); |
185 bool loadSucceed = mTranslator->load(KNmRegisterLocFileName + lang, KNmRegisterLocLocation); |
123 qDebug() << "NmMailboxRegisterInterfacePrivate mTranslator->load loadSucceed:"<<loadSucceed; |
186 QCoreApplication::installTranslator(mTranslator); |
124 QCoreApplication::installTranslator(mTranslator);*/ |
187 |
125 |
|
126 mManager = new QServiceManager(); |
|
127 QServiceFilter filter("com.nokia.symbian.IMenuClient"); |
|
128 QList<QServiceInterfaceDescriptor> interfaces = mManager->findInterfaces(filter); |
|
129 mService = mManager->loadInterface(interfaces.first()); |
|
130 } |
|
131 |
|
132 /*! |
|
133 Destructor |
|
134 */ |
|
135 NmMailboxRegisterInterfacePrivate::~NmMailboxRegisterInterfacePrivate() |
|
136 { |
|
137 if(mTranslator){ |
|
138 delete mTranslator; |
|
139 mTranslator = NULL; |
|
140 } |
|
141 if (mService) |
|
142 { |
|
143 delete mService; |
|
144 } |
|
145 if (mManager) |
|
146 { |
|
147 delete mManager; |
|
148 } |
|
149 } |
|
150 |
|
151 |
|
152 bool NmMailboxRegisterInterfacePrivate::registerNewMailbox(quint64 accountId, |
|
153 QString accountName, QString accountIconName) |
|
154 { |
|
155 //check that accountIconName is valid otherwise pass default mailbox icon |
188 //check that accountIconName is valid otherwise pass default mailbox icon |
156 HbIcon mailBoxIcon(accountIconName); |
189 HbIcon mailBoxIcon(accountIconName); |
157 if(mailBoxIcon.pixmap().height() == 0){ |
190 if (mailBoxIcon.pixmap().height() == 0) { |
158 mailBoxIcon = NmIcons::getIcon(NmIcons::NmIconDefaultMailbox); |
191 mailBoxIcon = NmIcons::getIcon(NmIcons::NmIconDefaultMailbox); |
159 accountIconName = mailBoxIcon.iconName(); |
192 accountIconName = mailBoxIcon.iconName(); |
160 } |
193 } |
161 |
194 |
162 QMap<QString, QVariant> map; |
195 QMap<QString, QVariant> map; |
163 //------------------------------ |
196 //------------------------------ |
164 map[hsItemName] = accountName; |
197 map[hsItemName] = accountName; |
165 map[hsitemLaunchUri] = formLaunchUri(accountId); |
198 map[hsitemLaunchUri] = formLaunchUri(accountId); |
166 map[hsitemPublisherId] = NmPublisherName; |
199 map[hsitemPublisherId] = NmPublisherName; |
167 map[hsItemWidgetUri] = NmHsWidget; |
200 map[hsItemWidgetUri] = NmHsWidget; |
168 //commented out until MCL has nmregister files in place here: epoc32/include/platform/qt/translations/ |
201 map[hsItemDescription] = hbTrId("txt_mail_widget_dblist_preview_of_recent_mail"); |
169 //map[hsItemDescription] = hbTrId("txt_mail_widget_dblist_preview_of_recent_mail"); |
202 map[hsIconFileName] = accountIconName; |
170 map[hsItemDescription] = "test description for widget"; |
|
171 map[hsIconFileName] = accountIconName; |
|
172 // to add widget params that are mapped to widgets properties |
203 // to add widget params that are mapped to widgets properties |
173 map[NmHsWidgetParamAccountId] = QString::number(accountId); |
204 map[NmHsWidgetParamAccountId] = QString::number(accountId); |
174 map[NmHsWidgetParamAccountIconName] = accountIconName; |
205 map[NmHsWidgetParamAccountIconName] = accountIconName; |
175 //------------------------------ |
206 //------------------------------ |
176 |
207 |
177 bool retVal(false); |
208 bool retVal(false); |
178 |
209 bool ret(false); |
179 bool ret = QMetaObject::invokeMethod( mService,"add", |
210 ret = QMetaObject::invokeMethod( mService,"add", |
180 Qt::DirectConnection, |
211 Qt::DirectConnection, |
181 Q_RETURN_ARG(bool, retVal), |
212 Q_RETURN_ARG(bool, retVal), |
182 Q_ARG(QVariantMap, map)); |
213 Q_ARG(QVariantMap, map)); |
183 |
214 |
184 //Push the registered widget also to homescreen right away |
215 //Push the registered widget also to homescreen right away |
185 bool pushRetVal = pushWidgetToHomescreen(accountId, accountIconName); |
216 bool pushRetVal = pushWidgetToHomescreen(accountId, accountIconName); |
186 |
217 |
187 return (retVal && ret && pushRetVal); |
218 return (retVal && ret && pushRetVal); |
188 } |
219 } |
189 |
220 |
190 bool NmMailboxRegisterInterfacePrivate::updateMailboxName(quint64 accountId, |
221 bool NmMailboxRegisterInterfacePrivate::updateMailboxName(quint64 accountId, QString newName) |
191 QString newName) |
222 { |
192 { |
223 NM_FUNCTION; |
|
224 |
|
225 if(!loadMenuClientService()){ |
|
226 NM_ERROR(1,"loadService() failed!"); |
|
227 return false; |
|
228 } |
|
229 |
193 QMap<QString, QVariant> map; |
230 QMap<QString, QVariant> map; |
194 //------------------------------ |
231 //------------------------------ |
195 map[hsitemLaunchUri] = formLaunchUri(accountId); |
232 map[hsitemLaunchUri] = formLaunchUri(accountId); |
196 map[hsitemPublisherId] = NmPublisherName; |
233 map[hsitemPublisherId] = NmPublisherName; |
197 map[hsItemWidgetUri] = NmHsWidget; |
234 map[hsItemWidgetUri] = NmHsWidget; |
198 map[NmHsWidgetParamAccountId] = QString::number(accountId); |
235 map[NmHsWidgetParamAccountId] = QString::number(accountId); |
199 //------------------------------ |
236 //------------------------------ |
200 |
237 |
201 QList<QVariantMap> list; //list of items that mach the query |
238 QList<QVariantMap> list; //list of items that mach the query |
202 bool retVal(false); |
239 bool retVal(false); |
203 bool ret = QMetaObject::invokeMethod( mService,"getList", |
240 bool ret(false); |
204 Qt::DirectConnection, |
241 ret = QMetaObject::invokeMethod(mService, "getList", |
205 Q_RETURN_ARG(QList<QVariantMap>, list), |
242 Qt::DirectConnection, |
206 Q_ARG(QVariantMap, map)); |
243 Q_RETURN_ARG(QList<QVariantMap> , list), |
207 |
244 Q_ARG(QVariantMap, map)); |
208 |
245 |
209 //Normally there should be only one instance, but just in case |
246 //Normally there should be only one instance, but just in case |
210 while( !list.isEmpty() ) |
247 while (!list.isEmpty()) { |
211 { |
248 //update the account name |
212 //update the account name |
249 list.first()[hsItemName] = newName; |
213 list.first()[hsItemName] = newName; |
250 //commit changes |
214 //commit changes |
251 ret = QMetaObject::invokeMethod( mService,"add", |
215 ret = QMetaObject::invokeMethod( mService,"add", |
252 Qt::DirectConnection, |
216 Qt::DirectConnection, |
253 Q_RETURN_ARG(bool, retVal), |
217 Q_RETURN_ARG(bool, retVal), |
254 Q_ARG(QVariantMap, list.first())); |
218 Q_ARG(QVariantMap, list.first())); |
255 list.removeFirst(); |
219 list.removeFirst(); |
256 } |
220 } |
257 //if either invoke or "getList" or "add" return failure |
221 //if either invoke or "getList" or "add" return failure |
258 return (retVal && ret); |
222 return (retVal && ret); |
259 } |
223 } |
|
224 |
260 |
225 bool NmMailboxRegisterInterfacePrivate::unregisterMailbox(quint64 accountId) |
261 bool NmMailboxRegisterInterfacePrivate::unregisterMailbox(quint64 accountId) |
226 { |
262 { |
|
263 NM_FUNCTION; |
|
264 |
|
265 if(!loadMenuClientService()){ |
|
266 NM_ERROR(1,"loadService() failed!"); |
|
267 return false; |
|
268 } |
227 |
269 |
228 QMap<QString, QVariant> map; |
270 QMap<QString, QVariant> map; |
229 //------------------------------ |
271 //------------------------------ |
230 map[hsitemLaunchUri] = formLaunchUri(accountId); |
272 map[hsitemLaunchUri] = formLaunchUri(accountId); |
231 map[hsitemPublisherId] = NmPublisherName; |
273 map[hsitemPublisherId] = NmPublisherName; |
232 map[hsItemWidgetUri] = NmHsWidget; |
274 map[hsItemWidgetUri] = NmHsWidget; |
233 map[NmHsWidgetParamAccountId] = QString::number(accountId); |
275 map[NmHsWidgetParamAccountId] = QString::number(accountId); |
234 //------------------------------ |
276 //------------------------------ |
235 |
277 |
236 QList<QVariantMap> list; //list of items that mach the query |
278 QList<QVariantMap> list; //list of items that mach the query |
237 bool retVal(false); |
279 bool retVal(false); |
238 bool ret = QMetaObject::invokeMethod( mService,"getList", |
280 bool ret(false); |
239 Qt::DirectConnection, |
281 ret = QMetaObject::invokeMethod(mService, "getList", |
240 Q_RETURN_ARG(QList<QVariantMap>, list), |
282 Qt::DirectConnection, |
241 Q_ARG(QVariantMap, map)); |
283 Q_RETURN_ARG(QList<QVariantMap> , list), |
242 |
284 Q_ARG(QVariantMap, map)); |
243 |
285 |
244 //Normally there should be only one instance, but just in case |
286 //Normally there should be only one instance, but just in case |
245 //Otherwise there will be ghost instances in the application list |
287 //Otherwise there will be ghost instances in the application list |
246 while( !list.isEmpty() ) |
288 while (!list.isEmpty()) { |
247 { |
289 |
248 |
290 //commit changes |
249 //commit changes |
291 ret = QMetaObject::invokeMethod( mService,"remove", |
250 ret = QMetaObject::invokeMethod( mService,"remove", |
292 Qt::DirectConnection, |
251 Qt::DirectConnection, |
293 Q_RETURN_ARG(bool, retVal), |
252 Q_RETURN_ARG(bool, retVal), |
294 Q_ARG(QVariantMap, list.first())); |
253 Q_ARG(QVariantMap, list.first())); |
295 list.removeFirst(); |
254 list.removeFirst(); |
296 } |
255 } |
297 |
256 |
298 return (retVal && ret); |
257 return (retVal && ret); |
299 } |
258 } |
300 |
259 |
301 bool NmMailboxRegisterInterfacePrivate::pushWidgetToHomescreen( |
260 bool NmMailboxRegisterInterfacePrivate::pushWidgetToHomescreen( quint64 accountId, QString accountIconName ) |
302 quint64 accountId, |
261 { |
303 QString accountIconName) |
|
304 { |
|
305 NM_FUNCTION; |
|
306 |
262 // load plugin |
307 // load plugin |
263 QServiceManager manager; |
308 QServiceManager manager; |
264 QServiceFilter filter("com.nokia.symbian.IHomeScreenClient"); |
309 QServiceFilter filter("com.nokia.symbian.IHomeScreenClient"); |
265 filter.setServiceName("hshomescreenclientplugin"); |
310 filter.setServiceName("hshomescreenclientplugin"); |
266 QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(filter); |
311 QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(filter); |
267 |
312 |
268 if(interfaces.isEmpty()) |
313 if (interfaces.isEmpty()) { |
269 { |
|
270 QServiceManager::Error errori = manager.error(); |
|
271 return false; |
314 return false; |
272 } |
315 } |
273 QObject* service = manager.loadInterface( interfaces.first() ); |
316 QObject* service = manager.loadInterface(interfaces.first()); |
274 if(!service){qDebug() << "service is null ";} |
317 if (!service) { |
275 |
318 NM_ERROR(1,"service is null "); |
|
319 return false; |
|
320 } |
|
321 |
276 //-------------------------------- |
322 //-------------------------------- |
277 QVariantHash map; |
323 QVariantHash map; |
278 map[NmHsAccountId] = QString::number(accountId); |
324 map[NmHsAccountId] = QString::number(accountId); |
279 map[NmHsAccountIconName] = accountIconName; |
325 map[NmHsAccountIconName] = accountIconName; |
280 //-------------------------------- |
326 //-------------------------------- |
281 |
327 |
282 // invoke function synchronously |
328 // invoke function synchronously |
283 bool retVal(false); |
329 bool retVal(false); |
284 bool ret = QMetaObject::invokeMethod( service, "addWidget", |
330 bool ret(false); |
285 Qt::DirectConnection, |
331 ret = QMetaObject::invokeMethod( service, "addWidget", |
286 Q_RETURN_ARG(bool, retVal), |
332 Qt::DirectConnection, |
287 Q_ARG(QString, NmHsWidget), |
333 Q_RETURN_ARG(bool, retVal), |
288 Q_ARG(QVariantHash, map)); |
334 Q_ARG(QString, NmHsWidget), |
289 |
335 Q_ARG(QVariantHash, map)); |
290 if(!ret){ |
336 |
291 qDebug()<< "method invoke failed!"; |
337 delete service; |
292 } |
338 service = NULL; |
293 if(!retVal){ |
339 |
294 qDebug() << "addWidget() failed!!"; |
|
295 } |
|
296 |
|
297 if(service) |
|
298 { |
|
299 delete service; |
|
300 } |
|
301 |
|
302 return (retVal && ret); |
340 return (retVal && ret); |
303 } |
341 } |
304 |
342 |
305 QString NmMailboxRegisterInterfacePrivate::formLaunchUri(quint64 accountId) const |
343 QString NmMailboxRegisterInterfacePrivate::formLaunchUri(quint64 accountId) const |
306 { |
344 { |
307 return NmLaunchUri + QString::number(accountId); |
345 return NmLaunchUri + QString::number(accountId); |
308 } |
346 } |