|
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 <qservicemanager.h> |
|
19 #include <qserviceinterfacedescriptor.h> |
|
20 #include "nmmailboxregisterinterface.h" |
|
21 #include "nmmailboxregisterinterface_p.h" |
|
22 |
|
23 //mandatory keys |
|
24 const QString hsItemName ("item:name"); |
|
25 const QString hsitemLaunchUri ("item:launchuri"); |
|
26 const QString hsitemPublisherId ("item:publisherId"); |
|
27 //not mandatory |
|
28 const QString hsItemWidgetUri ("widget:uri"); |
|
29 const QString hsItemDescription ("item:description"); |
|
30 //for icon - not mandatory |
|
31 const QString hsIconFileName ("icon:filename");//to display specific icon from file |
|
32 const QString hsIconName ("icon:name");// HbIcon |
|
33 const QString hsIconApplicationId ("icon:applicationid"); // icon from associated application |
|
34 |
|
35 //Custom for nmHsWidgets |
|
36 //NmHsWidgetParam is used to identify what email account will be monitored by |
|
37 //the registered hs widget |
|
38 const QString NmHsWidgetParam ("widgetparam:accountId"); |
|
39 //same as above but for pushing the widget to homescreen |
|
40 const QString NmHsAccountId ("accountId"); |
|
41 //This is used to identify nmhswidget in homescreen |
|
42 const QString NmHsWidget ("nmhswidget"); |
|
43 |
|
44 //parameter values |
|
45 const QString NmPublisherName ("NmMailboxRegisterInterface"); |
|
46 const QString NmLaunchUri ("application://0x2002DD17"); |
|
47 //URI for the defined service |
|
48 const QLatin1String interfaceUri("com.nokia.symbian.IEmailRegisterAccount"); |
|
49 |
|
50 |
|
51 |
|
52 /*! |
|
53 Constructor |
|
54 */ |
|
55 NmMailboxRegisterInterface::NmMailboxRegisterInterface(QObject *parent) : |
|
56 QObject(parent), m_d( new NmMailboxRegisterInterfacePrivate(this) ) |
|
57 { |
|
58 } |
|
59 |
|
60 /*! |
|
61 Destructor |
|
62 */ |
|
63 NmMailboxRegisterInterface::~NmMailboxRegisterInterface() |
|
64 { |
|
65 delete m_d; |
|
66 } |
|
67 |
|
68 /*! |
|
69 registerNewMailbox |
|
70 */ |
|
71 bool NmMailboxRegisterInterface::registerNewMailbox(quint64 accountId, |
|
72 QString accountName, QString accountIconName) |
|
73 { |
|
74 return m_d->registerNewMailbox( accountId, accountName, accountIconName ); |
|
75 } |
|
76 |
|
77 /*! |
|
78 updateMailboxName |
|
79 */ |
|
80 bool NmMailboxRegisterInterface::updateMailboxName(quint64 accountId, |
|
81 QString newName) |
|
82 { |
|
83 return m_d->updateMailboxName( accountId, newName ); |
|
84 } |
|
85 |
|
86 |
|
87 /*! |
|
88 unregisterMailbox |
|
89 */ |
|
90 bool NmMailboxRegisterInterface::unregisterMailbox(quint64 accountId) |
|
91 { |
|
92 return m_d->unregisterMailbox( accountId ); |
|
93 } |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 /*! |
|
100 Constructor |
|
101 */ |
|
102 NmMailboxRegisterInterfacePrivate::NmMailboxRegisterInterfacePrivate(QObject *parent) : |
|
103 XQServiceProvider(interfaceUri, parent ), |
|
104 mManager(0), |
|
105 mService(0) |
|
106 { |
|
107 mManager = new QServiceManager(); |
|
108 QServiceFilter filter("com.nokia.symbian.IMenuClient"); |
|
109 QList<QServiceInterfaceDescriptor> interfaces = mManager->findInterfaces(filter); |
|
110 mService = mManager->loadInterface(interfaces.first()); |
|
111 } |
|
112 |
|
113 /*! |
|
114 Destructor |
|
115 */ |
|
116 NmMailboxRegisterInterfacePrivate::~NmMailboxRegisterInterfacePrivate() |
|
117 { |
|
118 if (mService) |
|
119 { |
|
120 delete mService; |
|
121 } |
|
122 if (mManager) |
|
123 { |
|
124 delete mManager; |
|
125 } |
|
126 } |
|
127 |
|
128 |
|
129 bool NmMailboxRegisterInterfacePrivate::registerNewMailbox(quint64 accountId, |
|
130 QString accountName, QString accountIconName) |
|
131 { |
|
132 QMap<QString, QVariant> map; |
|
133 //------------------------------ |
|
134 map[hsItemName] = accountName; |
|
135 map[hsitemLaunchUri] = NmLaunchUri; |
|
136 map[hsitemPublisherId] = NmPublisherName; |
|
137 map[hsItemWidgetUri] = NmHsWidget; |
|
138 map[hsItemDescription] = "test description for widget"; //TODO: Localization |
|
139 map[hsIconFileName] = accountIconName; |
|
140 // to add widget params that are mapped to widgets properties |
|
141 map[NmHsWidgetParam] = QString::number(accountId); |
|
142 //------------------------------ |
|
143 |
|
144 bool retVal(false); |
|
145 |
|
146 bool ret = QMetaObject::invokeMethod( mService,"add", |
|
147 Qt::DirectConnection, |
|
148 Q_RETURN_ARG(bool, retVal), |
|
149 Q_ARG(QVariantMap, map)); |
|
150 |
|
151 //Push the registered widget also to homescreen right away |
|
152 bool pushRetVal = pushWidgetToHomescreen(accountId); |
|
153 |
|
154 return (retVal && ret && pushRetVal); |
|
155 } |
|
156 |
|
157 bool NmMailboxRegisterInterfacePrivate::updateMailboxName(quint64 accountId, |
|
158 QString newName) |
|
159 { |
|
160 QMap<QString, QVariant> map; |
|
161 //------------------------------ |
|
162 map[hsitemLaunchUri] = NmLaunchUri; |
|
163 map[hsitemPublisherId] = NmPublisherName; |
|
164 map[hsItemWidgetUri] = NmHsWidget; |
|
165 map[NmHsWidgetParam] = QString::number(accountId); |
|
166 //------------------------------ |
|
167 |
|
168 QList<QVariantMap> list; //list of items that mach the query |
|
169 bool retVal(false); |
|
170 bool ret = QMetaObject::invokeMethod( mService,"getList", |
|
171 Qt::DirectConnection, |
|
172 Q_RETURN_ARG(QList<QVariantMap>, list), |
|
173 Q_ARG(QVariantMap, map)); |
|
174 |
|
175 |
|
176 //Normally there should be only one instance, but just in case |
|
177 while( !list.isEmpty() ) |
|
178 { |
|
179 //update the account name |
|
180 list.first()[hsItemName] = newName; |
|
181 //commit changes |
|
182 ret = QMetaObject::invokeMethod( mService,"add", |
|
183 Qt::DirectConnection, |
|
184 Q_RETURN_ARG(bool, retVal), |
|
185 Q_ARG(QVariantMap, list.first())); |
|
186 list.removeFirst(); |
|
187 } |
|
188 //if either invoke or "getList" or "add" return failure |
|
189 return (retVal && ret); |
|
190 } |
|
191 |
|
192 bool NmMailboxRegisterInterfacePrivate::unregisterMailbox(quint64 accountId) |
|
193 { |
|
194 |
|
195 QMap<QString, QVariant> map; |
|
196 //------------------------------ |
|
197 map[hsitemLaunchUri] = NmLaunchUri; |
|
198 map[hsitemPublisherId] = NmPublisherName; |
|
199 map[hsItemWidgetUri] = NmHsWidget; |
|
200 map[NmHsWidgetParam] = QString::number(accountId); |
|
201 //------------------------------ |
|
202 |
|
203 QList<QVariantMap> list; //list of items that mach the query |
|
204 bool retVal(false); |
|
205 bool ret = QMetaObject::invokeMethod( mService,"getList", |
|
206 Qt::DirectConnection, |
|
207 Q_RETURN_ARG(QList<QVariantMap>, list), |
|
208 Q_ARG(QVariantMap, map)); |
|
209 |
|
210 |
|
211 //Normally there should be only one instance, but just in case |
|
212 //Otherwise there will be ghost instances in the application list |
|
213 while( !list.isEmpty() ) |
|
214 { |
|
215 |
|
216 //commit changes |
|
217 ret = QMetaObject::invokeMethod( mService,"remove", |
|
218 Qt::DirectConnection, |
|
219 Q_RETURN_ARG(bool, retVal), |
|
220 Q_ARG(QVariantMap, list.first())); |
|
221 list.removeFirst(); |
|
222 } |
|
223 |
|
224 return (retVal && ret); |
|
225 } |
|
226 |
|
227 bool NmMailboxRegisterInterfacePrivate::pushWidgetToHomescreen( quint64 accountId ) |
|
228 { |
|
229 // load plugin |
|
230 QServiceManager manager; |
|
231 QServiceFilter filter("com.nokia.symbian.IHomeScreenClient"); |
|
232 filter.setServiceName("hshomescreenclientplugin"); |
|
233 QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(filter); |
|
234 |
|
235 if(interfaces.isEmpty()) |
|
236 { |
|
237 QServiceManager::Error errori = manager.error(); |
|
238 return false; |
|
239 } |
|
240 QObject* service = manager.loadInterface( interfaces.first() ); |
|
241 if(!service){qDebug() << "service is null ";} |
|
242 |
|
243 //-------------------------------- |
|
244 QVariantHash map; |
|
245 map[NmHsAccountId] = QString::number(accountId); |
|
246 //-------------------------------- |
|
247 |
|
248 // invoke function synchronously |
|
249 bool retVal(false); |
|
250 bool ret = QMetaObject::invokeMethod( service, "addWidget", |
|
251 Qt::DirectConnection, |
|
252 Q_RETURN_ARG(bool, retVal), |
|
253 Q_ARG(QString, NmHsWidget), |
|
254 Q_ARG(QVariantHash, map)); |
|
255 |
|
256 if(!ret){ |
|
257 qDebug()<< "method invoke failed!"; |
|
258 } |
|
259 if(!retVal){ |
|
260 qDebug() << "addWidget() failed!!"; |
|
261 } |
|
262 |
|
263 if(service) |
|
264 { |
|
265 delete service; |
|
266 } |
|
267 |
|
268 return (retVal && ret); |
|
269 } |
|
270 |