74 qDebug("HsUninstallItemState::onEntry()"); |
87 qDebug("HsUninstallItemState::onEntry()"); |
75 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
88 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
76 QVariantMap data = menuEvent->data(); |
89 QVariantMap data = menuEvent->data(); |
77 |
90 |
78 mItemId = data.value(itemIdKey()).toInt(); |
91 mItemId = data.value(itemIdKey()).toInt(); |
79 |
92 QSharedPointer<CaEntry> entry = CaService::instance()->getEntry(mItemId); |
|
93 QString appType = entry->attribute(swTypeKey()); |
|
94 if (!appType.compare(javaSwType())) { |
|
95 // java |
|
96 createUninstallJavaMessage(); |
|
97 } else { |
|
98 // other |
|
99 createUninstallMessage(); |
|
100 } |
|
101 |
|
102 subscribeForMemoryCardRemove(); |
|
103 |
|
104 HSMENUTEST_FUNC_EXIT("HsUninstallItemState::onEntry"); |
|
105 } |
|
106 |
|
107 /*! |
|
108 Action after closed confirmation dialog. |
|
109 \param finishedAction chosen action. |
|
110 \retval void |
|
111 */ |
|
112 void HsUninstallItemState::uninstallMessageFinished(HbAction* finishedAction) |
|
113 { |
|
114 if (finishedAction == mConfirmAction) { |
|
115 HsMenuService::executeAction(mItemId, removeActionIdentifier()); |
|
116 } |
|
117 emit exit(); |
|
118 } |
|
119 |
|
120 /*! |
|
121 Return information about a component: component name, a list of names |
|
122 of applications in this component and a delete message. |
|
123 \param[out] componentName component name. |
|
124 \param[out] applicationsNames a list of names of applications. |
|
125 \param[out] confirmationMessage delete message. |
|
126 \retval true if there is no error. |
|
127 */ |
|
128 bool HsUninstallItemState::getApplicationsNames(QString &componentName, |
|
129 QStringList &applicationsNames, |
|
130 QString &confirmationMessage) |
|
131 { |
|
132 componentName.clear(); |
|
133 applicationsNames.clear(); |
|
134 confirmationMessage.clear(); |
|
135 |
|
136 QSharedPointer<CaService> service = CaService::instance(); |
|
137 QSharedPointer<CaEntry> entry = service->getEntry(mItemId); |
|
138 const int componentId = |
|
139 entry->attribute(componentIdAttributeName()).toInt(); |
|
140 |
|
141 QSharedPointer<CaSoftwareRegistry> softwareRegistry = |
|
142 CaSoftwareRegistry::create(); |
|
143 QStringList appUids; |
|
144 bool retval = softwareRegistry->getUninstallDetails(componentId, |
|
145 componentName, |
|
146 appUids, |
|
147 confirmationMessage); |
|
148 if (retval) { |
|
149 CaQuery query; |
|
150 foreach (QString uid, appUids) { |
|
151 query.setAttribute(applicationUidEntryKey(), uid); |
|
152 QList< QSharedPointer<CaEntry> > entries = |
|
153 service->getEntries(query); |
|
154 if (entries.length() > 0) { |
|
155 applicationsNames << entries[0]->text(); |
|
156 } |
|
157 } |
|
158 if (applicationsNames.length()==1 |
|
159 && applicationsNames[0]==componentName) { |
|
160 applicationsNames.clear(); |
|
161 } |
|
162 } |
|
163 return retval; |
|
164 } |
|
165 |
|
166 /*! |
|
167 Subscribe for memory card remove. |
|
168 */ |
|
169 void HsUninstallItemState::subscribeForMemoryCardRemove() |
|
170 { |
|
171 CaNotifierFilter filter; |
|
172 filter.setIds(QList<int>() << mItemId); |
|
173 mNotifier = CaService::instance()->createNotifier(filter); |
|
174 mNotifier->setParent(this); |
|
175 connect(mNotifier, |
|
176 SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
177 SIGNAL(exit())); |
|
178 } |
|
179 |
|
180 /*! |
|
181 Slot launched after state has exited and in destructor. |
|
182 \retval void |
|
183 */ |
|
184 void HsUninstallItemState::cleanUp() |
|
185 { |
|
186 // Close messagebox if App key was pressed |
|
187 if (mUninstallMessage) { |
|
188 disconnect(mUninstallMessage, SIGNAL(finished(HbAction*)), |
|
189 this, SLOT(uninstallMessageFinished(HbAction*))); |
|
190 mUninstallMessage->close(); |
|
191 mUninstallMessage = NULL; |
|
192 } |
|
193 |
|
194 if (mUninstallJavaMessage) { |
|
195 disconnect(mUninstallJavaMessage, SIGNAL(finished(HbAction*)), this, SLOT(uninstallMessageFinished(HbAction*))); |
|
196 mUninstallJavaMessage->close(); |
|
197 mUninstallJavaMessage = NULL; |
|
198 } |
|
199 |
|
200 delete mNotifier; |
|
201 mNotifier = NULL; |
|
202 mConfirmAction = NULL; |
|
203 mItemId = 0; |
|
204 } |
|
205 |
|
206 /*! |
|
207 Method create uninstall confirmation message. |
|
208 \retval void |
|
209 */ |
|
210 void HsUninstallItemState::createUninstallMessage() |
|
211 { |
|
212 CaQuery parentsQuery; |
|
213 parentsQuery.setChildId(mItemId); |
|
214 parentsQuery.setEntryTypeNames(QStringList(collectionTypeName())); |
|
215 QList<int> parentsIds = CaService::instance()->getEntryIds( |
|
216 parentsQuery); |
80 QString message; |
217 QString message; |
81 if (shortcutService()->isItemShortcutWidget(mItemId)) { |
218 if (HsShortcutService::instance()->isItemShortcutWidget(mItemId) || (parentsIds.count() > 0)) { |
82 message.append( |
219 message.append( |
83 hbTrId("txt_applib_dialog_uninstalls_1_and_deletes_all_sh").arg( |
220 HbParameterLengthLimiter("txt_applib_dialog_uninstalls_1_and_deletes_all_sh").arg( |
84 HsMenuService::getName(mItemId))); |
221 HsMenuService::getName(mItemId))); |
85 } else { |
222 } else { |
86 message.append( |
223 message.append( |
87 hbTrId("txt_applib_dialog_1_will_be_removed_from_phone_c").arg( |
224 HbParameterLengthLimiter("txt_applib_dialog_1_will_be_removed_from_phone_c").arg( |
88 HsMenuService::getName(mItemId))); |
225 HsMenuService::getName(mItemId))); |
89 } |
226 } |
90 |
227 |
91 // create and show message box |
228 // create and show message box |
92 mUninstallMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
229 mUninstallMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
93 mUninstallMessage->setAttribute(Qt::WA_DeleteOnClose); |
230 mUninstallMessage->setAttribute(Qt::WA_DeleteOnClose); |
94 |
231 |
95 mUninstallMessage->setText(message); |
232 mUninstallMessage->setText(message); |
96 |
233 |
97 mUninstallMessage->clearActions(); |
234 mUninstallMessage->clearActions(); |
98 mConfirmAction = new HbAction(hbTrId("txt_common_button_ok"), mUninstallMessage); |
235 mConfirmAction = new HbAction(hbTrId("txt_common_button_ok"), |
|
236 mUninstallMessage); |
99 mUninstallMessage->addAction(mConfirmAction); |
237 mUninstallMessage->addAction(mConfirmAction); |
100 |
238 |
101 HbAction *secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), mUninstallMessage); |
239 HbAction *secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), |
|
240 mUninstallMessage); |
102 mUninstallMessage->addAction(secondaryAction); |
241 mUninstallMessage->addAction(secondaryAction); |
103 |
242 |
104 mUninstallMessage->open(this, SLOT(uninstallMessageFinished(HbAction*))); |
243 mUninstallMessage->open(this, SLOT(uninstallMessageFinished(HbAction*))); |
105 |
244 } |
106 HSMENUTEST_FUNC_EXIT("HsUninstallItemState::onEntry"); |
245 |
107 } |
246 /*! |
108 |
247 Method create uninstall confirmation dialog for java. |
109 /*! |
|
110 Action after closed confirmation dialog. |
|
111 \param finishedAction chosen action. |
|
112 \retval void |
248 \retval void |
113 */ |
249 */ |
114 void HsUninstallItemState::uninstallMessageFinished(HbAction* finishedAction) |
250 void HsUninstallItemState::createUninstallJavaMessage() |
115 { |
251 { |
116 if (finishedAction == mConfirmAction) { |
252 HbDocumentLoader loader; |
117 HsMenuService::executeAction(mItemId, removeActionIdentifier()); |
253 bool loadStatusOk = false; |
118 } |
254 mObjectList = loader.load(HS_UNINSTALL_DIALOG_LAYOUT, &loadStatusOk); |
119 emit exit(); |
255 |
120 } |
256 Q_ASSERT_X(loadStatusOk, |
121 |
257 HS_UNINSTALL_DIALOG_LAYOUT, |
122 /*! |
258 "Error while loading docml file."); |
123 Convenience method returning the shortcut service. |
259 |
124 \since S60 ?S60_version. |
260 QString componentName; |
125 \return Shortcut Service. |
261 QStringList applicationsNames; |
126 */ |
262 QString detailsMessage; |
127 HsShortcutService *HsUninstallItemState::shortcutService() const |
263 getApplicationsNames(componentName, applicationsNames, detailsMessage); |
128 { |
264 |
129 return property(SHORTCUT_SERVICE_KEY).value<HsShortcutService *> (); |
265 QString section; |
130 } |
266 if (applicationsNames.isEmpty() && detailsMessage.isEmpty()) { |
131 |
267 mDialogType = UninstallDialogDefinition01; |
132 /*! |
268 section = QString("uninstallDialogDefinition01"); |
133 Slot launched after state has exited and in destructor. |
269 mObjectList = loader.load( |
134 \retval void |
270 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk); |
135 */ |
271 } else if ( (!applicationsNames.isEmpty()) && (!detailsMessage.isEmpty())) { |
136 void HsUninstallItemState::cleanUp() |
272 mDialogType = UninstallDialogDefinition02; |
137 { |
273 section = QString("uninstallDialogDefinition02"); |
138 // Close messagebox if App key was pressed |
274 mObjectList = loader.load( |
139 if (mUninstallMessage) { |
275 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk); |
140 disconnect(mUninstallMessage, SIGNAL(finished(HbAction*)), this, SLOT(uninstallMessageFinished(HbAction*))); |
276 } else if ( (!applicationsNames.isEmpty() && detailsMessage.isEmpty())) { |
141 mUninstallMessage->close(); |
277 mDialogType = UninstallDialogDefinition03; |
142 mUninstallMessage = NULL; |
278 section = QString("uninstallDialogDefinition03"); |
143 } |
279 mObjectList = loader.load( |
144 |
280 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk); |
145 mConfirmAction = NULL; |
281 } else if (applicationsNames.isEmpty() && (!detailsMessage.isEmpty())) { |
146 mItemId = 0; |
282 mDialogType = UninstallDialogDefinition04; |
147 } |
283 section = QString("uninstallDialogDefinition04"); |
|
284 mObjectList = loader.load( |
|
285 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk); |
|
286 } |
|
287 |
|
288 mUninstallJavaMessage = |
|
289 qobject_cast<HbDialog*>( |
|
290 loader.findWidget(HS_UNINSTALL_DIALOG_NAME)); |
|
291 |
|
292 HbLabel* iconLabel = |
|
293 qobject_cast<HbLabel*>( |
|
294 loader.findWidget(HS_UNINSTALL_DIALOG_CONFIRMATION_DIALOG_ICON)); |
|
295 QSharedPointer<CaEntry> entry2 = CaService::instance()->getEntry(mItemId); |
|
296 HbIcon icon = entry2->makeIcon(); |
|
297 iconLabel->setIcon(icon); |
|
298 |
|
299 HbLabel* textLabel = |
|
300 qobject_cast<HbLabel*>( |
|
301 loader.findWidget(HS_UNINSTALL_DIALOG_CONFIRMATION_DIALOG_LABEL)); |
|
302 textLabel->setPlainText(textLabel->plainText().arg(componentName)); |
|
303 |
|
304 HbLabel* detailsUninstalLabel; |
|
305 if ((mDialogType == UninstallDialogDefinition02) || |
|
306 (mDialogType == UninstallDialogDefinition04)) { |
|
307 detailsUninstalLabel= qobject_cast<HbLabel*>( |
|
308 loader.findWidget(HS_UNINSTALL_DIALOG_DELETE_LABEL)); |
|
309 detailsUninstalLabel->setPlainText(detailsMessage); |
|
310 } |
|
311 |
|
312 HbLabel* listView; |
|
313 QString applicationsList; |
|
314 QString newLine("\n"); |
|
315 if ((mDialogType == UninstallDialogDefinition02) || |
|
316 (mDialogType == UninstallDialogDefinition03)) { |
|
317 listView = qobject_cast<HbLabel*>( |
|
318 loader.findWidget(HS_UNINSTALL_DIALOG_LIST_VIEW_LABEL)); |
|
319 |
|
320 for (int i=0; i<applicationsNames.count(); i++) { |
|
321 applicationsList = applicationsList + applicationsNames[i] + newLine; |
|
322 } |
|
323 listView->setPlainText(applicationsList); |
|
324 } |
|
325 |
|
326 mUninstallJavaMessage->setAttribute(Qt::WA_DeleteOnClose); |
|
327 mUninstallJavaMessage->setTimeout(HbPopup::NoTimeout); |
|
328 mConfirmAction = qobject_cast<HbAction*>(loader.findObject( |
|
329 HS_UNINSTALL_DIALOG_CONFIRMATION_ACTION)); |
|
330 |
|
331 mUninstallJavaMessage->open(this, SLOT(uninstallMessageFinished(HbAction*))); |
|
332 } |