|
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: Menu delete collection item state |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbmessagebox.h> |
|
19 #include <hbaction.h> |
|
20 #include <hsmenuservice.h> |
|
21 #include <hsshortcutservice.h> |
|
22 |
|
23 #include "hsuninstallitemstate.h" |
|
24 #include "hsmenuevent.h" |
|
25 |
|
26 /*! |
|
27 \class HsUninstallItemState |
|
28 \ingroup group_hsworkerstateplugin |
|
29 \brief Uninstall Item State. |
|
30 Deletes app from collection. |
|
31 */ |
|
32 |
|
33 /*! |
|
34 Constructor. |
|
35 \param parent Owner. |
|
36 */ |
|
37 HsUninstallItemState::HsUninstallItemState(QState *parent) : |
|
38 QState(parent), |
|
39 mItemId(0), |
|
40 mUninstallMessage(NULL), |
|
41 mConfirmAction(NULL) |
|
42 { |
|
43 construct(); |
|
44 } |
|
45 |
|
46 /*! |
|
47 Destructor. |
|
48 */ |
|
49 HsUninstallItemState::~HsUninstallItemState() |
|
50 { |
|
51 cleanUp(); // in case of throw |
|
52 } |
|
53 |
|
54 /*! |
|
55 Constructs contained objects. |
|
56 */ |
|
57 void HsUninstallItemState::construct() |
|
58 { |
|
59 setObjectName(this->parent()->objectName() |
|
60 + "/UninstallItemState"); |
|
61 setProperty(HS_SERVICES_REGISTRATION_KEY, QList<QVariant> () |
|
62 << SHORTCUT_SERVICE_KEY); |
|
63 connect(this, SIGNAL(exited()), SLOT(cleanUp())); |
|
64 } |
|
65 |
|
66 /*! |
|
67 Sets entry event. |
|
68 \param event entry event. |
|
69 */ |
|
70 void HsUninstallItemState::onEntry(QEvent *event) |
|
71 { |
|
72 HSMENUTEST_FUNC_ENTRY("HsUninstallItemState::onEntry"); |
|
73 QState::onEntry(event); |
|
74 qDebug("HsUninstallItemState::onEntry()"); |
|
75 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
|
76 QVariantMap data = menuEvent->data(); |
|
77 |
|
78 mItemId = data.value(itemIdKey()).toInt(); |
|
79 |
|
80 QString message; |
|
81 if (shortcutService()->isItemShortcutWidget(mItemId)) { |
|
82 message.append( |
|
83 hbTrId("txt_applib_dialog_uninstalls_1_and_deletes_all_sh").arg( |
|
84 HsMenuService::getName(mItemId))); |
|
85 } else { |
|
86 message.append( |
|
87 hbTrId("txt_applib_dialog_1_will_be_removed_from_phone_c").arg( |
|
88 HsMenuService::getName(mItemId))); |
|
89 } |
|
90 |
|
91 // create and show message box |
|
92 mUninstallMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
|
93 mUninstallMessage->setAttribute(Qt::WA_DeleteOnClose); |
|
94 |
|
95 mUninstallMessage->setText(message); |
|
96 |
|
97 mUninstallMessage->clearActions(); |
|
98 mConfirmAction = new HbAction(hbTrId("txt_common_button_ok"), mUninstallMessage); |
|
99 mUninstallMessage->addAction(mConfirmAction); |
|
100 |
|
101 HbAction *secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), mUninstallMessage); |
|
102 mUninstallMessage->addAction(secondaryAction); |
|
103 |
|
104 mUninstallMessage->open(this, SLOT(uninstallMessageFinished(HbAction*))); |
|
105 |
|
106 HSMENUTEST_FUNC_EXIT("HsUninstallItemState::onEntry"); |
|
107 } |
|
108 |
|
109 /*! |
|
110 Action after closed confirmation dialog. |
|
111 \param finishedAction chosen action. |
|
112 \retval void |
|
113 */ |
|
114 void HsUninstallItemState::uninstallMessageFinished(HbAction* finishedAction) |
|
115 { |
|
116 if (finishedAction == mConfirmAction) { |
|
117 HsMenuService::executeAction(mItemId, removeActionIdentifier()); |
|
118 } |
|
119 emit exit(); |
|
120 } |
|
121 |
|
122 /*! |
|
123 Convenience method returning the shortcut service. |
|
124 \since S60 ?S60_version. |
|
125 \return Shortcut Service. |
|
126 */ |
|
127 HsShortcutService *HsUninstallItemState::shortcutService() const |
|
128 { |
|
129 return property(SHORTCUT_SERVICE_KEY).value<HsShortcutService *> (); |
|
130 } |
|
131 |
|
132 /*! |
|
133 Slot launched after state has exited and in destructor. |
|
134 \retval void |
|
135 */ |
|
136 void HsUninstallItemState::cleanUp() |
|
137 { |
|
138 // Close messagebox if App key was pressed |
|
139 if (mUninstallMessage) { |
|
140 disconnect(mUninstallMessage, SIGNAL(finished(HbAction*)), this, SLOT(uninstallMessageFinished(HbAction*))); |
|
141 mUninstallMessage->close(); |
|
142 mUninstallMessage = NULL; |
|
143 } |
|
144 |
|
145 mConfirmAction = NULL; |
|
146 mItemId = 0; |
|
147 } |