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