|
1 /* |
|
2 * Copyright (c) 2008 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 "mcsmenu.h" |
|
19 #include "mcsmenuitem.h" |
|
20 |
|
21 #include "mcsdeleteitem.h" |
|
22 #include "mcscallback.h" |
|
23 #include "mcsservice.h" |
|
24 #include "mcsmenuopwatcher.h" |
|
25 #include "mcsoperationmanager.h" |
|
26 |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // two-phased constructor |
|
30 // --------------------------------------------------------------------------- |
|
31 CMCSDeleteItem* CMCSDeleteItem::NewL( RMenu& aMenu, |
|
32 MMCSCallback* aCallback, RMcsOperationManager& aOperationManager ) |
|
33 { |
|
34 CMCSDeleteItem* self = new (ELeave) CMCSDeleteItem( aMenu, aCallback, |
|
35 aOperationManager ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // destructor |
|
44 // --------------------------------------------------------------------------- |
|
45 CMCSDeleteItem::~CMCSDeleteItem() |
|
46 { |
|
47 Cancel(); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // default constructor |
|
52 // --------------------------------------------------------------------------- |
|
53 CMCSDeleteItem::CMCSDeleteItem( RMenu& aMenu, MMCSCallback* aCallback, |
|
54 RMcsOperationManager& aOperationManager ) : |
|
55 CActive( EPriorityStandard ), |
|
56 iCallback( aCallback ), |
|
57 iMCS( aMenu ), |
|
58 iOperationManager(aOperationManager) |
|
59 { |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // second phase constructor |
|
64 // --------------------------------------------------------------------------- |
|
65 void CMCSDeleteItem::ConstructL() |
|
66 { |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Async delete item |
|
71 // --------------------------------------------------------------------------- |
|
72 void CMCSDeleteItem::DeleteItemL(TInt aItemId) |
|
73 { |
|
74 iItemId = aItemId; |
|
75 if( !iCallback ) |
|
76 { |
|
77 User::Leave( KErrArgument ); |
|
78 } |
|
79 CActiveScheduler::Add ( this ); |
|
80 ActivateRequest( KErrNone ); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // Inherited from CActive class |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CMCSDeleteItem::DoCancel() |
|
88 { |
|
89 //TRequestStatus* temp = &iStatus; |
|
90 //User::RequestComplete( temp, KErrCancel ); |
|
91 TRAP_IGNORE( iCallback->NotifyResultL( KErrCancel, NULL )); |
|
92 //NotifyRequestResult( err ); |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // Inherited from CActive class |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CMCSDeleteItem::RunL() |
|
100 { |
|
101 TInt err = iStatus.Int(); |
|
102 if ( err == KErrNone ) |
|
103 { |
|
104 CMCSMenuOpWatcher* watcherAO = CMCSMenuOpWatcher::NewL( *this, |
|
105 iOperationManager ); |
|
106 CleanupStack::PushL( watcherAO ); |
|
107 iOperationManager.AddL( watcherAO ); |
|
108 CleanupStack::Pop( watcherAO );// we pop item from cleanupstack because |
|
109 //ownership was transfered to operation manager |
|
110 |
|
111 CMenuOperation* operation = iMCS.RemoveL( iItemId , watcherAO->iStatus ); |
|
112 |
|
113 watcherAO->Watch( *operation ); |
|
114 } |
|
115 else |
|
116 { |
|
117 NotifyRequestResult( err ); |
|
118 } |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CMCSDeleteItem::RunError |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CMCSDeleteItem::RunError(TInt aError) |
|
126 { |
|
127 NotifyRequestResult( aError ); |
|
128 if ( (aError != KErrDiskFull) && (aError != KErrNoMemory)) |
|
129 { |
|
130 aError = KErrNone; |
|
131 } |
|
132 return aError; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Activates the asynchronous request |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CMCSDeleteItem::ActivateRequest( TInt aReason ) |
|
140 { |
|
141 iStatus = KRequestPending; |
|
142 SetActive(); |
|
143 TRequestStatus* temp = &iStatus; |
|
144 User::RequestComplete( temp, aReason ); |
|
145 } |
|
146 |
|
147 // -------------------------------------------------------------------------------------------------------- |
|
148 // Notifies callback the result for asynchronous request. |
|
149 // -------------------------------------------------------------------------------------------------------- |
|
150 // |
|
151 void CMCSDeleteItem::NotifyRequestResult( TInt aReason ) |
|
152 { |
|
153 iOperationManager.Remove( this );//remove it |
|
154 //from operation manager |
|
155 |
|
156 if ( iCallback ) |
|
157 { |
|
158 TRAP_IGNORE(iCallback->NotifyResultL( aReason ));//, NULL); |
|
159 } |
|
160 |
|
161 delete this; |
|
162 } |
|
163 |
|
164 // -------------------------------------------------------------------------------------------------------- |
|
165 // Notifies callback the result for asynchronous request. |
|
166 // -------------------------------------------------------------------------------------------------------- |
|
167 // |
|
168 void CMCSDeleteItem::MenuOpCompletedL(TInt aStatus ) |
|
169 { |
|
170 NotifyRequestResult( aStatus ); |
|
171 } |
|
172 |
|
173 // End of file |