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: CMCSOrganize implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwvariant.h> |
|
20 #include "mcsmenu.h" |
|
21 #include "mcsmenuitem.h" |
|
22 #include "mcsorganizeimpl.h" |
|
23 #include "mcsservice.h" |
|
24 #include "mcsmenuopwatcher.h" |
|
25 #include "mcsoperationmanager.h" |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // two-phased constructor |
|
29 // --------------------------------------------------------------------------- |
|
30 CMCSOrganizeImpl* CMCSOrganizeImpl::NewL( RMenu& aMCS, MMCSCallback* aCallback, |
|
31 RMcsOperationManager& aOperationManager ) |
|
32 { |
|
33 CMCSOrganizeImpl* self = new (ELeave) CMCSOrganizeImpl( 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 CMCSOrganizeImpl::~CMCSOrganizeImpl() |
|
45 { |
|
46 Cancel(); |
|
47 iList.Close(); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // default constructor |
|
52 // --------------------------------------------------------------------------- |
|
53 CMCSOrganizeImpl::CMCSOrganizeImpl( RMenu& aMCS, MMCSCallback* aCallback, |
|
54 RMcsOperationManager& aOperationManager ) : |
|
55 CActive( EPriorityStandard ), |
|
56 iCallback( aCallback ), |
|
57 iMCS( aMCS ), |
|
58 iOperationManager(aOperationManager) |
|
59 { |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // second phase constructor |
|
64 // --------------------------------------------------------------------------- |
|
65 void CMCSOrganizeImpl::ConstructL() |
|
66 { |
|
67 iIsSingle = ETrue; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Organize |
|
72 // --------------------------------------------------------------------------- |
|
73 void CMCSOrganizeImpl::OrganizeL( |
|
74 TInt aItemId, TInt aBeforeItemId ) |
|
75 { |
|
76 if( !iCallback ) |
|
77 { |
|
78 User::Leave( KErrArgument ); |
|
79 } |
|
80 |
|
81 iItemId = aItemId; |
|
82 iBeforeItemId = aBeforeItemId; |
|
83 iIsSingle = ETrue; |
|
84 |
|
85 CActiveScheduler::Add ( this ); |
|
86 ActivateRequest( KErrNone ); |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // Organize |
|
91 // --------------------------------------------------------------------------- |
|
92 void CMCSOrganizeImpl::OrganizeL( const RArray<TInt>& aList, |
|
93 TInt aFolderId, TInt aBeforeItemId ) |
|
94 { |
|
95 if( !iCallback ) |
|
96 { |
|
97 User::Leave( KErrArgument ); |
|
98 } |
|
99 |
|
100 iList.Reset(); |
|
101 //iList = aList; |
|
102 for( TInt idx = 0; idx < aList.Count(); idx++ ) |
|
103 { |
|
104 TInt value = aList[idx]; |
|
105 iList.AppendL( value ); |
|
106 } |
|
107 iFolderId = aFolderId; |
|
108 iBeforeItemId = aBeforeItemId; |
|
109 iIsSingle = EFalse; |
|
110 |
|
111 CActiveScheduler::Add ( this ); |
|
112 ActivateRequest( KErrNone ); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // Organize |
|
117 // --------------------------------------------------------------------------- |
|
118 void CMCSOrganizeImpl::OrganizeL() |
|
119 { |
|
120 CMCSMenuOpWatcher* watcherAO = CMCSMenuOpWatcher::NewL( *this, |
|
121 iOperationManager ); |
|
122 CMenuOperation* operation = NULL; |
|
123 |
|
124 CleanupStack::PushL( watcherAO ); |
|
125 iOperationManager.AddL( watcherAO ); |
|
126 CleanupStack::Pop( watcherAO );// we pop item from cleanupstack because |
|
127 //ownership was transfered to operation manager |
|
128 |
|
129 if( iIsSingle ) |
|
130 { |
|
131 TInt id = ( TInt )iItemId; |
|
132 operation = iMCS.ReorderL( id, iBeforeItemId, watcherAO->iStatus ); |
|
133 } |
|
134 else |
|
135 { |
|
136 TInt folder = ( iFolderId == 0 ) ? iMCS.RootFolderL() : iFolderId; |
|
137 operation = iMCS.MoveToFolderL( iList, folder, iBeforeItemId, |
|
138 watcherAO->iStatus ); |
|
139 } |
|
140 watcherAO->Watch( *operation); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // Inherited from CActive class |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CMCSOrganizeImpl::DoCancel() |
|
148 { |
|
149 // TRequestStatus* temp = &iStatus; |
|
150 // User::RequestComplete( temp, KErrCancel ); |
|
151 TRAP_IGNORE( iCallback->NotifyResultL( KErrCancel, NULL )); |
|
152 // NotifyRequestResult( err ); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // Inherited from CActive class |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CMCSOrganizeImpl::RunL() |
|
160 { |
|
161 TInt err = iStatus.Int(); |
|
162 |
|
163 if ( err == KErrNone ) |
|
164 { |
|
165 TRAP( err, OrganizeL() ); |
|
166 } |
|
167 if(err != KErrNone) |
|
168 { |
|
169 NotifyRequestResult( err ); |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CMCSOrganizeImpl::RunError |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 TInt CMCSOrganizeImpl::RunError(TInt aError) |
|
178 { |
|
179 NotifyRequestResult( aError ); |
|
180 if ( (aError != KErrDiskFull) && (aError != KErrNoMemory)) |
|
181 { |
|
182 aError = KErrNone; |
|
183 } |
|
184 return aError; |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // Activates the asynchronous request |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CMCSOrganizeImpl::ActivateRequest( TInt aReason ) |
|
192 { |
|
193 iStatus = KRequestPending; |
|
194 SetActive(); |
|
195 TRequestStatus* temp = &iStatus; |
|
196 User::RequestComplete( temp, aReason ); |
|
197 } |
|
198 |
|
199 // -------------------------------------------------------------------------------------------------------- |
|
200 // Notifies callback the result for asynchronous request. |
|
201 // -------------------------------------------------------------------------------------------------------- |
|
202 // |
|
203 void CMCSOrganizeImpl::NotifyRequestResult( TInt aReason ) |
|
204 { |
|
205 iOperationManager.Remove( this );//remove it |
|
206 //from operation manager |
|
207 if ( iCallback ) |
|
208 { |
|
209 TRAP_IGNORE( iCallback->NotifyResultL( aReason, NULL ) ); |
|
210 // iCallback deletes itself. |
|
211 } |
|
212 delete this; |
|
213 |
|
214 } |
|
215 |
|
216 // -------------------------------------------------------------------------------------------------------- |
|
217 // Notifies callback the result for asynchronous request. |
|
218 // -------------------------------------------------------------------------------------------------------- |
|
219 // |
|
220 void CMCSOrganizeImpl::MenuOpCompletedL(TInt aStatus ) |
|
221 { |
|
222 NotifyRequestResult( aStatus ); |
|
223 } |
|