79 // --------------------------------------------------------------------------- |
79 // --------------------------------------------------------------------------- |
80 // Deletes the given mailbox or displays a list of available mailboxes and |
80 // Deletes the given mailbox or displays a list of available mailboxes and |
81 // allows the user to mark multiple mailboxes for deletion if aId is NullId. |
81 // allows the user to mark multiple mailboxes for deletion if aId is NullId. |
82 // --------------------------------------------------------------------------- |
82 // --------------------------------------------------------------------------- |
83 // |
83 // |
84 |
|
85 void CFSEmailUiMailboxDeleter::DeleteMailboxL() |
84 void CFSEmailUiMailboxDeleter::DeleteMailboxL() |
86 { |
85 { |
87 // Make sure that FSMailServer is running so that the mailboxes will also |
86 iMailboxesToDelete.Reset(); |
|
87 |
|
88 // Get the deletable mailboxes. |
|
89 RPointerArray<CFSMailBox> mailboxes; |
|
90 const TInt mailboxCount = GetDeletableMailboxesLC( mailboxes ); |
|
91 |
|
92 TBool res( EFalse ); |
|
93 |
|
94 if( mailboxCount == 1 ) |
|
95 { |
|
96 res = DeleteSingleMailboxL( mailboxes ); |
|
97 } |
|
98 else if( mailboxCount > 1 ) |
|
99 { |
|
100 res = DeleteMultipleMailboxesL( mailboxes ); |
|
101 } |
|
102 |
|
103 CleanupStack::PopAndDestroy(); // mailboxes |
|
104 |
|
105 if ( res ) |
|
106 { |
|
107 DoDeleteSelectedMailboxesL(); |
|
108 } |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // DeleteMailboxL() |
|
113 // Deletes the given mailbox. Displays also a confirmation dialog. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void CFSEmailUiMailboxDeleter::DeleteMailboxL( const TFSMailMsgId& aMailboxId ) |
|
117 { |
|
118 iMailboxesToDelete.Reset(); |
|
119 |
|
120 // Get the deletable mailboxes. |
|
121 RPointerArray<CFSMailBox> mailboxes; |
|
122 const TInt mailboxCount = GetDeletableMailboxesLC( mailboxes ); |
|
123 |
|
124 // Make sure that it is allowed to delete the mailbox with the given ID. |
|
125 CFSMailBox* mailbox = NULL; |
|
126 |
|
127 for ( TInt i( 0 ); i < mailboxCount; ++i ) |
|
128 { |
|
129 mailbox = mailboxes[i]; |
|
130 |
|
131 if ( mailbox && mailbox->GetId() == aMailboxId ) |
|
132 { |
|
133 // The mailbox can be deleted. |
|
134 break; |
|
135 } |
|
136 |
|
137 mailbox = NULL; |
|
138 } |
|
139 |
|
140 if ( !mailbox ) |
|
141 { |
|
142 // Either no mailbox with the given ID exist or it is not allowed to |
|
143 // be deleted. |
|
144 // TODO Display an error message? |
|
145 CleanupStack::PopAndDestroy(); // mailboxes |
|
146 return; |
|
147 } |
|
148 |
|
149 TBool response = ConfirmMailboxDeletionL( 1, mailbox->GetName() ); |
|
150 CleanupStack::PopAndDestroy(); // mailboxes |
|
151 |
|
152 if ( !response ) |
|
153 { |
|
154 // User did not confirm the deletion. |
|
155 return; |
|
156 } |
|
157 |
|
158 iMailboxesToDelete.AppendL( aMailboxId ); |
|
159 DoDeleteSelectedMailboxesL(); |
|
160 } |
|
161 |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // GetDeletableMailboxesLC() |
|
165 // Returns the mailboxes that can be deleted. |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 TInt CFSEmailUiMailboxDeleter::GetDeletableMailboxesLC( |
|
169 RPointerArray<CFSMailBox>& aMailboxes ) |
|
170 { |
|
171 // Make sure that FSMailServer is running so that the mailboxes will also |
88 // be removed from MCE. |
172 // be removed from MCE. |
89 TFsEmailUiUtility::EnsureFsMailServerIsRunning( CCoeEnv::Static()->WsSession() ); |
173 TFsEmailUiUtility::EnsureFsMailServerIsRunning( |
90 |
174 CCoeEnv::Static()->WsSession() ); |
91 iMailboxesToDelete.Reset(); |
175 |
92 |
176 CleanupResetAndDestroyClosePushL( aMailboxes ); |
93 // Get mailbox count |
177 |
94 RPointerArray<CFSMailBox> mailboxes; |
178 // Get the mailboxes. |
95 CleanupResetAndDestroyClosePushL( mailboxes ); |
|
96 |
|
97 TFSMailMsgId id; |
179 TFSMailMsgId id; |
98 User::LeaveIfError( iMailClient.ListMailBoxes( id, mailboxes ) ); |
180 User::LeaveIfError( iMailClient.ListMailBoxes( id, aMailboxes ) ); |
99 |
181 |
100 CFSMailBox* mailBox = NULL; |
182 CFSMailBox* mailbox = NULL; |
101 |
183 |
102 // Filter out mailboxes that can't be deleted. |
184 // Filter out mailboxes that can't be deleted. |
103 for( TInt i(0); i < mailboxes.Count(); ) |
185 const TInt mailboxCount( aMailboxes.Count() ); |
104 { |
186 |
105 mailBox = mailboxes[i]; |
187 for( TInt i( 0 ); i < mailboxCount; ) |
106 if( !mailBox->HasCapability( EFSMBoxCapaCanBeDeleted ) ) |
188 { |
|
189 mailbox = aMailboxes[i]; |
|
190 |
|
191 if( !mailbox->HasCapability( EFSMBoxCapaCanBeDeleted ) ) |
107 { |
192 { |
108 delete mailBox; |
193 delete mailbox; |
109 mailboxes.Remove( i ); |
194 aMailboxes.Remove( i ); |
110 } |
195 } |
111 else |
196 else |
112 { |
197 { |
113 ++i; |
198 ++i; |
114 } |
199 } |
115 } |
200 } |
116 |
201 |
117 TBool res( EFalse ); |
202 return aMailboxes.Count(); |
118 |
203 } |
119 if( mailboxes.Count() == 1 ) |
204 |
120 { |
|
121 res = DeleteSingleMailboxL( mailboxes ); |
|
122 } |
|
123 else if( mailboxes.Count() > 1 ) |
|
124 { |
|
125 res = DeleteMultipleMailboxesL( mailboxes ); |
|
126 } |
|
127 |
|
128 CleanupStack::PopAndDestroy(); // mailboxes |
|
129 |
|
130 if( res && ( iMailboxesToDelete.Count() > 0 ) ) |
|
131 { |
|
132 // Start wait note. |
|
133 iWaitDialog = new (ELeave) CAknWaitDialog( |
|
134 (REINTERPRET_CAST(CEikDialog**, &iWaitDialog)), EFalse ); |
|
135 iWaitDialog->PrepareLC( R_FS_WAIT_NOTE_REMOVING_MAILBOX ); |
|
136 iWaitDialog->SetCallback( this ); |
|
137 iWaitDialog->RunLD(); |
|
138 |
|
139 // Set email indicator off. |
|
140 TFsEmailUiUtility::ToggleEmailIconL(EFalse); |
|
141 |
|
142 // Delete first mailbox in queue. |
|
143 DoDeleteNextMailboxL(); |
|
144 } |
|
145 } |
|
146 |
205 |
147 // --------------------------------------------------------------------------- |
206 // --------------------------------------------------------------------------- |
148 // DeleteSingleMailboxL |
207 // DeleteSingleMailboxL |
149 // --------------------------------------------------------------------------- |
208 // --------------------------------------------------------------------------- |
150 // |
209 // |
213 |
273 |
214 CleanupStack::PopAndDestroy( selections ); |
274 CleanupStack::PopAndDestroy( selections ); |
215 |
275 |
216 return res; |
276 return res; |
217 } |
277 } |
|
278 |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // DoDeleteSelectedMailboxesL() |
|
282 // Deletes the selected mailboxes i.e. those of which IDs are in the |
|
283 // iMailboxesToDelete array. |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 void CFSEmailUiMailboxDeleter::DoDeleteSelectedMailboxesL() |
|
287 { |
|
288 if ( iMailboxesToDelete.Count() < 1 ) |
|
289 { |
|
290 // Nothing to delete! |
|
291 return; |
|
292 } |
|
293 |
|
294 // Start wait note. |
|
295 iWaitDialog = new ( ELeave ) CAknWaitDialog( |
|
296 ( REINTERPRET_CAST( CEikDialog**, &iWaitDialog ) ), EFalse ); |
|
297 iWaitDialog->PrepareLC( R_FS_WAIT_NOTE_REMOVING_MAILBOX ); |
|
298 iWaitDialog->SetCallback( this ); |
|
299 iWaitDialog->RunLD(); |
|
300 |
|
301 // Set email indicator off. |
|
302 TFsEmailUiUtility::ToggleEmailIconL( EFalse ); |
|
303 |
|
304 // Delete first mailbox in queue. |
|
305 DoDeleteNextMailboxL(); |
|
306 } |
|
307 |
218 |
308 |
219 // --------------------------------------------------------------------------- |
309 // --------------------------------------------------------------------------- |
220 // CreateMarkIconLC |
310 // CreateMarkIconLC |
221 // --------------------------------------------------------------------------- |
311 // --------------------------------------------------------------------------- |
222 // |
312 // |