14 * Description: Menu delete collection item state |
14 * Description: Menu delete collection item state |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <hbmessagebox.h> |
18 #include <hbmessagebox.h> |
|
19 #include <hbaction.h> |
19 #include <hsmenuservice.h> |
20 #include <hsmenuservice.h> |
20 #include <hsmenueventfactory.h> |
21 #include <hsmenueventfactory.h> |
21 |
22 |
22 #include "hsdeletecollectionitemstate.h" |
23 #include "hsdeletecollectionitemstate.h" |
23 #include "hsmenuevent.h" |
24 #include "hsmenuevent.h" |
32 /*! |
33 /*! |
33 Constructor. |
34 Constructor. |
34 \param parent Owner. |
35 \param parent Owner. |
35 */ |
36 */ |
36 HsDeleteCollectionItemState::HsDeleteCollectionItemState(QState *parent) : |
37 HsDeleteCollectionItemState::HsDeleteCollectionItemState(QState *parent) : |
37 QState(parent) |
38 QState(parent), |
|
39 mItemId(0), |
|
40 mCollectionId(0), |
|
41 mDeleteMessage(NULL), |
|
42 mConfirmAction(NULL) |
38 { |
43 { |
39 construct(); |
44 construct(); |
40 } |
45 } |
41 |
46 |
42 /*! |
47 /*! |
43 Destructor. |
48 Destructor. |
44 */ |
49 */ |
45 HsDeleteCollectionItemState::~HsDeleteCollectionItemState() |
50 HsDeleteCollectionItemState::~HsDeleteCollectionItemState() |
46 { |
51 { |
|
52 cleanUp(); // in case of throw |
47 } |
53 } |
48 |
54 |
49 // --------------------------------------------------------------------------- |
55 /*! |
50 // --------------------------------------------------------------------------- |
56 Constructs contained objects. |
51 // |
57 */ |
52 void HsDeleteCollectionItemState::construct() |
58 void HsDeleteCollectionItemState::construct() |
53 { |
59 { |
54 setObjectName(this->parent()->objectName() |
60 setObjectName(this->parent()->objectName() |
55 + "/DeleteCollectionItemState"); |
61 + "/DeleteCollectionItemState"); |
|
62 connect(this, SIGNAL(exited()), SLOT(cleanUp())); |
56 } |
63 } |
57 |
64 |
58 // --------------------------------------------------------------------------- |
65 /*! |
59 // --------------------------------------------------------------------------- |
66 Sets entry event. |
60 // |
67 \param event entry event. |
|
68 */ |
61 #ifdef COVERAGE_MEASUREMENT |
69 #ifdef COVERAGE_MEASUREMENT |
62 #pragma CTC SKIP |
70 #pragma CTC SKIP |
63 #endif //COVERAGE_MEASUREMENT |
71 #endif //COVERAGE_MEASUREMENT |
64 void HsDeleteCollectionItemState::onEntry(QEvent *event) |
72 void HsDeleteCollectionItemState::onEntry(QEvent *event) |
65 { |
73 { |
67 QState::onEntry(event); |
75 QState::onEntry(event); |
68 qDebug("CollectionState::onEntry()"); |
76 qDebug("CollectionState::onEntry()"); |
69 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
77 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
70 QVariantMap data = menuEvent->data(); |
78 QVariantMap data = menuEvent->data(); |
71 |
79 |
72 const int itemId = data.value(itemIdKey()).toInt(); |
80 mItemId = data.value(itemIdKey()).toInt(); |
73 |
81 mCollectionId = data.value(collectionIdKey()).toInt(); |
74 const int collectionId = data.value(collectionIdKey()).toInt(); |
|
75 |
82 |
76 QString message; |
83 QString message; |
77 message.append( |
84 message.append( |
78 hbTrId("txt_applib_dialog_remove_1_from_collection").arg( |
85 hbTrId("txt_applib_dialog_remove_1_from_collection").arg( |
79 HsMenuService::getName(itemId))); |
86 HsMenuService::getName(mItemId))); |
80 |
87 |
81 if (HbMessageBox::question(message, hbTrId( |
88 // create and show message box |
82 "txt_common_button_ok"), hbTrId("txt_common_button_cancel"))) { |
89 mDeleteMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
83 HsMenuService::removeApplicationFromCollection(itemId, collectionId); |
90 mDeleteMessage->setAttribute(Qt::WA_DeleteOnClose); |
84 } |
91 |
|
92 mDeleteMessage->setText(message); |
|
93 |
|
94 mDeleteMessage->clearActions(); |
|
95 mConfirmAction = new HbAction(hbTrId("txt_common_button_ok"), mDeleteMessage); |
|
96 mDeleteMessage->addAction(mConfirmAction); |
|
97 |
|
98 HbAction *secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), mDeleteMessage); |
|
99 mDeleteMessage->addAction(secondaryAction); |
|
100 |
|
101 mDeleteMessage->open(this, SLOT(deleteMessageFinished(HbAction*))); |
|
102 |
85 HSMENUTEST_FUNC_EXIT("HsDeleteCollectionItemState::onEntry"); |
103 HSMENUTEST_FUNC_EXIT("HsDeleteCollectionItemState::onEntry"); |
86 } |
104 } |
87 #ifdef COVERAGE_MEASUREMENT |
105 #ifdef COVERAGE_MEASUREMENT |
88 #pragma CTC ENDSKIP |
106 #pragma CTC ENDSKIP |
89 #endif //COVERAGE_MEASUREMENT |
107 #endif //COVERAGE_MEASUREMENT |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void HsDeleteCollectionItemState::deleteMessageFinished(HbAction* finishedAction) |
|
113 { |
|
114 if (mItemId !=0 ) { // (work-around for crash if more then one action is selected in HbDialog) |
|
115 |
|
116 if (finishedAction == mConfirmAction) { |
|
117 HsMenuService::removeApplicationFromCollection(mItemId, mCollectionId); |
|
118 } |
|
119 mItemId = 0; |
|
120 emit exit(); |
|
121 } else { |
|
122 // (work-around for crash if more then one action is selected in HbDialog) |
|
123 qWarning("Another signal finished was emited."); |
|
124 } |
|
125 } |
|
126 |
|
127 /*! |
|
128 Slot launched after state has exited and in destructor. |
|
129 \retval void |
|
130 */ |
|
131 void HsDeleteCollectionItemState::cleanUp() |
|
132 { |
|
133 // Close messagebox if App key was pressed |
|
134 if (mDeleteMessage) { |
|
135 mDeleteMessage->close(); |
|
136 } |
|
137 |
|
138 mDeleteMessage = NULL; |
|
139 mConfirmAction= NULL; |
|
140 mItemId = 0; |
|
141 mCollectionId = 0; |
|
142 } |