Fixed automatic screen transition in movemail form while sending an email
[apps/native/preloaded/Email.git] / src / EmMailListForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        EmMailListForm.cpp
19  * @brief       Keeps the implementation of Inbox Form
20  */
21
22 #include "EmEmailApp.h"
23 #include "EmMailListForm.h"
24 #include "EmEmailSettingPresentationModel.h"
25 #include "EmStateInfo.h"
26
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Io;
32 using namespace Tizen::Locales;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Animations;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38
39 MailListForm::MailListForm(void)
40         : __accountId(-1)
41         , __mailboxId(-1)
42         , __groupCount(0)
43         , __downloadAttachments(0)
44         , __groupIndex(-1)
45         , __itemIndex(-1)
46         , __headerTouchPosition(-1)
47         , __waitForDelete(false)
48         , __waitForMove(false)
49         , __futureAction(EmailTypesNS::NONE)
50         , __userCancelledAttachmentDownload(false)
51         , __mailboxType(EMAIL_MAILBOX_TYPE_INBOX)
52         , __mailboxViewType(INBOX_VIEW)
53         , __pFolderContextMenuItemsList(null)
54         , __pAttachmentDownloadHandleMap(null)
55         , __pSortByIcon(null)
56         , __pDeleteAllIcon(null)
57         , __pAddAccountIcon(null)
58         , __pMarkReadUnreadIcon(null)
59         , __pBlockIcon(null)
60         , __pAllAccountsIcon(null)
61         , __pHeaderAllAccountsIcon(null)
62         , __pFavouriteIcon(null)
63         , __pSortByPopupCloseButton(null)
64         , __pMarkAllAsPopupCloseButton(null)
65         , __pSetAllAsPopupCancelButton(null)
66         , __pMoreOptionMenu(null)
67         , __pFolderContextMenu(null)
68         , __pAccountsContextMenu(null)
69         , __pMailGroupedListView(null)
70         , __pSelectedLabel(null)
71         , __pSortByListView(null)
72         , __pMarkAllAsListView(null)
73         , __pSetAllAsListView(null)
74         , __pAccountsListView(null)
75         , __pAccountsListPanel(null)
76         , __pSortByPopup(null)
77         , __pMarkAllAsPopup(null)
78         , __pSetAllAsPopup(null)
79         , __pDeleteConfirmationPopup(null)
80         , __pAttachmentDownloadFailedPopup(null)
81         , __pMoveOrDeleteFailedPopup(null)
82         , __pProgressPopup(null)
83         , __pDownloadAttachmentsPopup(null)
84         , __pSortByListViewItemProvider(null)
85         , __pMarkAllAsListViewItemProvider(null)
86         , __pSetAllAsListViewItemProvider(null)
87         , __pBaseListViewItemProvider(null)
88         , __pPresentationModel(null)
89         , __mode(NORMAL_MODE)
90         , __viewByType(SORT_BY_DATE)
91 {
92         __pPresentationModel = InboxPresentationModel::GetInstance();
93 }
94
95 MailListForm::~MailListForm(void)
96 {
97         // Empty Implementation
98 }
99
100 result
101 MailListForm::Initialize(void)
102 {
103         AppLogDebug("ENTER");
104
105         result r = Construct(IDL_INBOX_LIST_FORM);
106
107         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
108         return r;
109 }
110
111 void
112 MailListForm::InitMoreOptionMenu(void)
113 {
114         AppLogDebug("ENTER");
115
116         __pMoreOptionMenu = new (std::nothrow) OptionMenu();
117         __pMoreOptionMenu->Construct();
118         __pMoreOptionMenu->AddActionEventListener(*this);
119         __pMoreOptionMenu->SetShowState(false);
120
121         AppLogDebug("EXIT");
122 }
123
124 void
125 MailListForm::InitFolderContextMenu(void)
126 {
127         AppLogDebug("ENTER");
128
129         int xPosition = 0;
130         int yPosition = 0;
131         Footer* pFooter = GetFooter();
132         Rectangle tmpRect;
133
134         if (pFooter != null)
135         {
136                 pFooter->AddActionEventListener(*this);
137                 pFooter->GetPosition(xPosition, yPosition);
138                 tmpRect = pFooter->GetButtonBounds(BUTTON_POSITION_RIGHT);
139
140                 xPosition = xPosition + (2*pFooter->GetWidth()/3);
141         }
142
143         __pFolderContextMenu = new (std::nothrow) ContextMenu();
144         __pFolderContextMenu->Construct(Point(xPosition,yPosition), CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
145         __pFolderContextMenu->SetAnchorPosition(Point(xPosition, yPosition));
146         __pFolderContextMenu->AddActionEventListener(*this);
147         __pFolderContextMenu->SetShowState(false);
148
149         AppLogDebug("EXIT");
150 }
151
152 void
153 MailListForm::InitAccountsContextMenu(void)
154 {
155         AppLogDebug("ENTER");
156
157         __pAccountsContextMenu = new (std::nothrow) ContextMenu();
158         __pAccountsContextMenu->Construct(Point(0, GetHeader()->GetHeight()), CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_AUTO);
159         __pAccountsContextMenu->AddActionEventListener(*this);
160         __pAccountsContextMenu->SetShowState(false);
161
162         AppLogDebug("EXIT");
163 }
164
165 void
166 MailListForm::InitDeleteConfirmationPopup(void)
167 {
168         AppLogDebug("ENTER");
169
170         __pDeleteConfirmationPopup = new (std::nothrow) Popup();
171         __pDeleteConfirmationPopup->Construct(L"IDL_POPUP_DELETE");
172         __pDeleteConfirmationPopup->SetPropagatedKeyEventListener(this);
173
174         Button* pDeleteButton = static_cast<Button*>(__pDeleteConfirmationPopup->GetControl(L"IDC_BUTTON_DELETE", true));
175         pDeleteButton->AddActionEventListener(*this);
176         pDeleteButton->SetActionId(IDA_INBOX_FORM_DELETE_CONFIRMATION_YES);
177
178         Button* pCancelButton = static_cast<Button*>(__pDeleteConfirmationPopup->GetControl(L"IDC_BUTTON_CANCEL", true));
179         pCancelButton->AddActionEventListener(*this);
180         pCancelButton->SetActionId(IDA_INBOX_FORM_DELETE_CONFIRMATION_NO);
181
182         AppLogDebug("EXIT");
183 }
184
185 void
186 MailListForm::InitAttachmentDownloadFailedPopup(void)
187 {
188         AppLogDebug("ENTER");
189
190         __pAttachmentDownloadFailedPopup = new Popup();
191         __pAttachmentDownloadFailedPopup->Construct(L"IDL_POPUP_ATTACHMENT_FAILED");
192
193         Button* pOkButton = static_cast<Button*>(__pAttachmentDownloadFailedPopup->GetControl(L"IDC_BUTTON_OK", true));
194         pOkButton->AddActionEventListener(*this);
195         pOkButton->SetActionId(IDA_ATTACHMENT_DOWNLOAD_FAILED_OK);
196
197         AppLogDebug("EXIT");
198 }
199
200 void
201 MailListForm::InitMoveOrDeleteFailedPopup(void)
202 {
203         AppLogDebug("ENTER");
204
205         __pMoveOrDeleteFailedPopup = new Popup();
206         __pMoveOrDeleteFailedPopup->Construct(L"IDL_POPUP_MOVE_OR_DELETE_FAILED");
207
208         Button* pOkButton = static_cast<Button*>(__pMoveOrDeleteFailedPopup->GetControl(L"IDC_BUTTON_OK", true));
209         pOkButton->AddActionEventListener(*this);
210         pOkButton->SetActionId(IDA_MOVE_OR_DELETE_FAILED_OK);
211
212         AppLogDebug("EXIT");
213 }
214
215 void
216 MailListForm::SetDeleteConfirmationPopupTitle(const String& title)
217 {
218         AppLogDebug("ENTER, title:(%ls)", title.GetPointer());
219
220         if (__pDeleteConfirmationPopup == null)
221         {
222                 InitDeleteConfirmationPopup();
223         }
224
225         Label* pTitleLabel = static_cast<Label*>(__pDeleteConfirmationPopup->GetControl(L"IDC_LABEL_TITLE", true));
226         pTitleLabel->SetText(title);
227
228         AppLogDebug("EXIT");
229 }
230
231 void
232 MailListForm::SetMoveOrDeleteFailedPopupTitle(const String& title)
233 {
234         AppLogDebug("ENTER, title:(%ls)", title.GetPointer());
235
236         if (__pMoveOrDeleteFailedPopup == null)
237         {
238                 InitMoveOrDeleteFailedPopup();
239         }
240
241         Label* pTitleLabel = static_cast<Label*>(__pMoveOrDeleteFailedPopup->GetControl(L"IDC_LABEL_TITLE", true));
242         pTitleLabel->SetText(title);
243
244         AppLogDebug("EXIT");
245 }
246
247 result
248 MailListForm::LoadIcons(void)
249 {
250         AppLogDebug("ENTER");
251
252         result r = E_SUCCESS;
253
254         __pSortByIcon = AppResource::GetInstance()->GetBitmapN(IDB_SORT_BY);
255         r = GetLastResult();
256         TryCatch(r == E_SUCCESS, , "[%s] Failed to get Sort by icon", GetErrorMessage(r));
257
258         __pDeleteAllIcon = AppResource::GetInstance()->GetBitmapN(IDB_DELETE_ALL);
259         r = GetLastResult();
260         TryCatch(r == E_SUCCESS, , "[%s] Failed to get Delete all icon", GetErrorMessage(r));
261
262         __pAddAccountIcon = AppResource::GetInstance()->GetBitmapN(IDB_ADD_ACCOUNT);
263         r = GetLastResult();
264         TryCatch(r == E_SUCCESS, , "[%s] Failed to get Add account icon", GetErrorMessage(r));
265
266         __pSettingsIcon = AppResource::GetInstance()->GetBitmapN(IDB_SETTINGS);
267         r = GetLastResult();
268         TryCatch(r == E_SUCCESS, , "[%s] Failed to get Add account icon", GetErrorMessage(r));
269
270         __pMarkReadUnreadIcon = AppResource::GetInstance()->GetBitmapN(IDB_MARK_UNREAD);
271         r = GetLastResult();
272         TryCatch(r == E_SUCCESS, , "[%s] Failed to get mark as unread icon", GetErrorMessage(r));
273
274         __pBlockIcon = AppResource::GetInstance()->GetBitmapN(IDB_BLOCK);
275         r = GetLastResult();
276         TryCatch(r == E_SUCCESS, , "[%s] Failed to get block icon", GetErrorMessage(r));
277
278         __pAllAccountsIcon = AppResource::GetInstance()->GetBitmapN(IDB_ALL_ACCOUNTS);
279         r = GetLastResult();
280         TryCatch(r == E_SUCCESS, , "[%s] Failed to get all accounts icon", GetErrorMessage(r));
281
282         __pHeaderAllAccountsIcon = AppResource::GetInstance()->GetBitmapN(IDB_HEADER_ALL_ACCOUNTS_ICON);
283         r = GetLastResult();
284         TryCatch(r == E_SUCCESS, , "[%s] Failed to get all accounts headericon", GetErrorMessage(r));
285
286         __pFavouriteIcon = AppResource::GetInstance()->GetBitmapN(IDB_FAVOURITES);
287         r = GetLastResult();
288         TryCatch(r == E_SUCCESS, , "[%s] Failed to get favourites icon", GetErrorMessage(r));
289
290         CATCH:
291         AppLogDebug("EXIT");
292         return r;
293 }
294
295 result
296 MailListForm::OnInitializing(void)
297 {
298         AppLogDebug("ENTER");
299
300         result r = E_SUCCESS;
301         Rectangle clientRect = GetClientAreaBounds();
302         Header* pHeader = GetHeader();
303
304         SetOrientation(ORIENTATION_AUTOMATIC_FOUR_DIRECTION);
305         AddOrientationEventListener(*this);
306
307         if (pHeader != null)
308         {
309                 pHeader->AddActionEventListener(*this);
310                 pHeader->AddTouchEventListener(*this);
311         }
312
313         SetFormBackEventListener(this);
314         SetFormMenuEventListener(this);
315
316         __pBaseListViewItemProvider = new (std::nothrow) EmailBaseListViewItemProvider(__pPresentationModel, false);
317         TryCatch(__pBaseListViewItemProvider != null, r = E_FAILURE,"Failed to create Grouped listview item provider");
318
319         __pMailGroupedListView = dynamic_cast<GroupedListView*>(GetControl(IDC_INBOX_GROUPEDLISTVIEW));
320         TryCatch(__pMailGroupedListView != null, r = E_FAILURE,"Failed to get Grouped listview");
321
322         __pMailGroupedListView->AddGroupedListViewItemEventListener(*this);
323
324         __pSelectedLabel = dynamic_cast<Label*>(GetControl(IDC_INBOX_SELECTED_LABEL));
325         TryCatch(__pSelectedLabel != null, r = E_FAILURE,"Failed to get selected label");
326
327         __pSelectedLabel->SetShowState(false);
328
329         __pAccountsListPanel = dynamic_cast<Panel*>(GetControl(IDC_INBOX_ACCOUNTS_LIST_PANEL));
330         TryCatch(__pAccountsListPanel != null, r = E_FAILURE,"Failed to get accounts list panel");
331
332         __pAccountsListPanel->AddTouchEventListener(*this);
333         __pAccountsListPanel->SetShowState(false);
334
335         __pAccountsListView = dynamic_cast<ListView*>(GetControl(IDC_INBOX_ACCOUNTS_LISTVIEW, true));
336         TryCatch(__pAccountsListView != null, r = E_FAILURE,"Failed to get accounts list view");
337
338         __pAccountsListView->AddListViewItemEventListener(*this);
339
340         __pFolderContextMenuItemsList = new (std::nothrow) ArrayList();
341         TryCatch(__pFolderContextMenuItemsList != null, r = E_FAILURE,"Failed to create folder context menu items map");
342
343         r = __pFolderContextMenuItemsList->Construct();
344         TryCatch(r == E_SUCCESS, r = E_FAILURE,"Failed to construct folder context menu items map");
345
346         __pFolderContextMenuItemsList->InsertAt(new (std::nothrow) String(Utils::GetResourceString(L"IDS_EMAIL_BODY_INBOX"))    , INBOX_VIEW);
347 //      __pFolderContextMenuItemsList->InsertAt(new (std::nothrow) String(L"Starred"), FAVORITES_VIEW);
348         __pFolderContextMenuItemsList->InsertAt(new (std::nothrow) String(Utils::GetResourceString(L"IDS_EMAIL_BODY_DRAFTS"))   , DRAFTS_VIEW);
349         __pFolderContextMenuItemsList->InsertAt(new (std::nothrow) String(Utils::GetResourceString(L"IDS_EMAIL_BODY_SENTBOX"))  , SENTBOX_VIEW);
350         __pFolderContextMenuItemsList->InsertAt(new (std::nothrow) String(Utils::GetResourceString(L"IDS_EMAIL_BODY_SHOW_ALL_FOLDERS_ABB")), ALL_FOLDERS_VIEW);
351
352         __pProgressPopup = new (std::nothrow) ProgressPopup();
353         __pProgressPopup->Construct(false, false);
354
355         SetControlAlwaysOnTop(*__pSelectedLabel, true);
356
357         r = LoadIcons();
358         TryCatch(r == E_SUCCESS, r = E_FAILURE, "Load icons failed");
359         __pMailGroupedListView->SetSize(clientRect.width, clientRect.height);
360
361         InitFolderContextMenu();
362         InitAccountsContextMenu();
363         __prevOrientation = GetOrientationStatus();
364         CATCH:
365         AppLogDebug("EXIT");
366         return r;
367 }
368
369 result
370 MailListForm::OnTerminating(void)
371 {
372         AppLogDebug("ENTER");
373         result r = E_SUCCESS;
374
375         if (__pAccountsContextMenu != null)
376         {
377                 __pAccountsContextMenu->RemoveAllControls();
378                 delete __pAccountsContextMenu;
379                 __pAccountsContextMenu = null;
380         }
381
382         delete __pSortByIcon;
383         delete __pDeleteAllIcon;
384         delete __pAddAccountIcon;
385         delete __pAllAccountsIcon;
386         delete __pHeaderAllAccountsIcon;
387         delete __pMarkReadUnreadIcon;
388         delete __pBlockIcon;
389         delete __pFavouriteIcon;
390         delete __pSettingsIcon;
391
392         __pFolderContextMenuItemsList->RemoveAll(true);
393         delete __pFolderContextMenuItemsList;
394
395         delete __pProgressPopup;
396         __pProgressPopup = null;
397
398         if (__pBaseListViewItemProvider != null)
399         {
400                 delete __pBaseListViewItemProvider;
401                 __pBaseListViewItemProvider = null;
402         }
403
404         if (__pFolderContextMenu != null)
405         {
406                 __pFolderContextMenu->RemoveAllItems();
407                 delete __pFolderContextMenu;
408                 __pFolderContextMenu = null;
409         }
410
411         if (__pMoreOptionMenu != null)
412         {
413                 __pMoreOptionMenu->RemoveAllItems();
414                 delete __pMoreOptionMenu;
415                 __pMoreOptionMenu = null;
416         }
417
418         if (__pDownloadAttachmentsPopup != null)
419         {
420                 delete __pDownloadAttachmentsPopup;
421                 __pDownloadAttachmentsPopup = null;
422         }
423
424         if (__pSortByPopup != null)
425         {
426                 __pSortByPopup->RemoveAllControls();
427                 delete __pSortByPopup;
428                 __pSortByPopup = null;
429         }
430
431         if (__pSortByListViewItemProvider != null)
432         {
433                 delete __pSortByListViewItemProvider;
434                 __pSortByListViewItemProvider = null;
435         }
436
437         if (__pMarkAllAsPopup != null)
438         {
439                 __pMarkAllAsPopup->RemoveAllControls();
440                 delete __pMarkAllAsPopup;
441                 __pMarkAllAsPopup = null;
442         }
443
444         if (__pMarkAllAsListViewItemProvider != null)
445         {
446                 delete __pMarkAllAsListViewItemProvider;
447                 __pMarkAllAsListViewItemProvider = null;
448         }
449
450         if (__pSetAllAsPopup != null)
451         {
452                 __pSetAllAsPopup->RemoveAllControls();
453                 delete __pSetAllAsPopup;
454                 __pSetAllAsPopup = null;
455         }
456
457         if (__pSetAllAsListViewItemProvider != null)
458         {
459                 delete __pSetAllAsListViewItemProvider;
460                 __pSetAllAsListViewItemProvider = null;
461         }
462
463         if (__pDeleteConfirmationPopup != null)
464         {
465                 __pDeleteConfirmationPopup->RemoveAllControls();
466                 delete __pDeleteConfirmationPopup;
467                 __pDeleteConfirmationPopup = null;
468         }
469
470         if (__pAttachmentDownloadFailedPopup != null)
471         {
472                 __pAttachmentDownloadFailedPopup->RemoveAllControls();
473                 delete __pAttachmentDownloadFailedPopup;
474                 __pAttachmentDownloadFailedPopup = null;
475         }
476
477         AppLogDebug("EXIT : r = %s", GetErrorMessage(r));
478         return r;
479 }
480
481 result
482 MailListForm::CreateSortByPopup(void)
483 {
484         AppLogDebug("ENTER");
485         result r = E_SUCCESS;
486
487         /*-- 'Sort by' popup and child controls --*/
488         __pSortByPopup = new (std::nothrow) Popup();
489         TryCatch(__pSortByPopup != null, r = E_FAILURE,"Failed to create view as popup");
490
491         r = __pSortByPopup->Construct(true, Dimension(W_VIEW_AS_POPUP, H_VIEW_AS_POPUP));
492         TryCatch(r == E_SUCCESS, r = E_FAILURE,"[%s] Failed to construct view as popup", GetErrorMessage(r));
493         __pSortByPopup->SetPropagatedKeyEventListener(this);
494
495         __pSortByPopup->SetTitleText(Utils::GetResourceString(L"IDS_EMAIL_OPT_VIEW"));
496
497         __pSortByListViewItemProvider = new (std::nothrow) SortByListViewItemProvider();
498         __pSortByListViewItemProvider->SetEventListener(this);
499
500         __pSortByPopupCloseButton = new (std::nothrow) Button();
501         TryCatch(__pSortByPopupCloseButton != null, r = E_FAILURE,"Failed to create popup close button");
502
503         r = __pSortByPopupCloseButton->Construct(Rectangle(0, 0, W_POPUP_CLOSE_BUTTON, H_POPUP_CLOSE_BUTTON), Utils::GetResourceString(L"IDS_EMAIL_SK3_CANCEL"));
504         TryCatch(r == E_SUCCESS, r = E_FAILURE, "[%s] Failed to construct popup close button", GetErrorMessage(r));
505
506         __pSortByPopupCloseButton->SetActionId(IDA_INBOX_FORM_BTN_POPUP_CANCEL);
507         __pSortByPopupCloseButton->AddActionEventListener(*this);
508         __pSortByPopup->AddControl(__pSortByPopupCloseButton);
509
510         __pSortByListView = new (std::nothrow) ListView();
511         TryCatch(__pSortByListView != null, r = GetLastResult(), "Failed to create ListView Control For Popup");
512
513         r = __pSortByListView->Construct(Rectangle(0, 0, W_VIEW_AS_POPUP, H_VIEW_AS_POPUP), true, SCROLL_STYLE_FADE_OUT);
514         TryCatch(r == E_SUCCESS, r = E_FAILURE, "[%s] Failed to construct SortBy ListView", GetErrorMessage(r));
515
516         __pSortByListView->AddListViewItemEventListener(*__pSortByListViewItemProvider);
517         __pSortByListView->SetItemProvider(*__pSortByListViewItemProvider);
518         __pSortByPopup->AddControl(__pSortByListView);
519
520         CATCH:
521         AppLogDebug("EXIT");
522         return r;
523 }
524
525 result
526 MailListForm::CreateMarkAllAsPopup(void)
527 {
528         AppLogDebug("ENTER");
529         result r = E_SUCCESS;
530
531         /*-- Popup and child controls of 'Mark all as' popup --*/
532         __pMarkAllAsPopup = new (std::nothrow) Popup();
533         TryCatch(__pMarkAllAsPopup != null, r = E_FAILURE,"Failed to create mark all as popup");
534
535         r = __pMarkAllAsPopup->Construct(true, Dimension(W_VIEW_AS_POPUP, H_MARK_ALL_AS_POPUP));
536         TryCatch(r == E_SUCCESS, r = E_FAILURE,"[%s] Failed to construct mark all as popup", GetErrorMessage(r));
537         __pMarkAllAsPopup->SetPropagatedKeyEventListener(this);
538
539         __pMarkAllAsPopup->SetTitleText(Utils::GetResourceString(L"IDS_EMAIL_OPT_MARK_ALL_AS_ABB"));
540
541         __pMarkAllAsListViewItemProvider = new (std::nothrow) MarkAllAsListViewItemProvider();
542         __pMarkAllAsListViewItemProvider->SetEventListener(this);
543
544         __pMarkAllAsPopupCloseButton = new (std::nothrow) Button();
545         TryCatch(__pMarkAllAsPopupCloseButton != null, r = E_FAILURE,"Failed to create mark all as popup close button");
546
547         r = __pMarkAllAsPopupCloseButton->Construct(Rectangle(0, 0, W_POPUP_CLOSE_BUTTON, H_POPUP_CLOSE_BUTTON), Utils::GetResourceString(L"IDS_EMAIL_SK3_CANCEL"));
548         TryCatch(r == E_SUCCESS, r = E_FAILURE, "[%s] Failed to construct mark all as popup close button", GetErrorMessage(r));
549
550         __pMarkAllAsPopupCloseButton->SetActionId(IDA_INBOX_FORM_BTN_MARK_ALL_AS_POPUP_CLOSE);
551         __pMarkAllAsPopupCloseButton->AddActionEventListener(*this);
552         __pMarkAllAsPopup->AddControl(__pMarkAllAsPopupCloseButton);
553
554         __pMarkAllAsListView = new (std::nothrow) ListView();
555         TryCatch(__pMarkAllAsListView != null, r = GetLastResult(), "Failed to create ListView Control For Mark all as Popup");
556
557         r = __pMarkAllAsListView->Construct(Rectangle(0, 0, W_VIEW_AS_POPUP, H_MARK_ALL_AS_POPUP), true, SCROLL_STYLE_FADE_OUT);
558         TryCatch(r == E_SUCCESS, r = E_FAILURE, "[%s] Failed to construct Mark all as ListView", GetErrorMessage(r));
559
560         __pMarkAllAsListView->AddListViewItemEventListener(*__pMarkAllAsListViewItemProvider);
561         __pMarkAllAsListView->SetItemProvider(*__pMarkAllAsListViewItemProvider);
562         __pMarkAllAsPopup->AddControl(__pMarkAllAsListView);
563
564         CATCH:
565         AppLogDebug("EXIT");
566         return r;
567 }
568
569 result
570 MailListForm::CreateSetAllAsPopup(void)
571 {
572         AppLogDebug("ENTER");
573         result r = E_SUCCESS;
574
575         /*-- Popup and child controls of 'Set all as' popup --*/
576         __pSetAllAsPopup = new (std::nothrow) Popup();
577         TryCatch(__pSetAllAsPopup != null, r = E_FAILURE,"Failed to create set all as popup");
578
579         r = __pSetAllAsPopup->Construct(true, Dimension(W_VIEW_AS_POPUP, H_MARK_ALL_AS_POPUP));
580         TryCatch(r == E_SUCCESS, r = E_FAILURE,"[%s] Failed to construct set all as popup", GetErrorMessage(r));
581         __pSetAllAsPopup->SetPropagatedKeyEventListener(this);
582
583         __pSetAllAsPopup->SetTitleText(Utils::GetResourceString(L"IDS_EMAIL_OPT_SET_ALL_AS_ABB"));
584
585         __pSetAllAsListViewItemProvider = new (std::nothrow) SetAllAsListViewItemProvider();
586         __pSetAllAsListViewItemProvider->SetEventListener(this);
587
588         __pSetAllAsPopupCancelButton = new (std::nothrow) Button();
589         TryCatch(__pSetAllAsPopupCancelButton != null, r = E_FAILURE,"Failed to create set all as popup cancel button");
590
591         r = __pSetAllAsPopupCancelButton->Construct(Rectangle(0, 0, W_POPUP_CLOSE_BUTTON, H_POPUP_CLOSE_BUTTON), Utils::GetResourceString(L"IDS_EMAIL_SK3_CANCEL"));
592         TryCatch(r == E_SUCCESS, r = E_FAILURE, "[%s] Failed to construct set all as popup cancel button", GetErrorMessage(r));
593
594         __pSetAllAsPopupCancelButton->SetActionId(IDA_INBOX_FORM_BTN_SET_ALL_AS_POPUP_CANCEL);
595         __pSetAllAsPopupCancelButton->AddActionEventListener(*this);
596         __pSetAllAsPopup->AddControl(__pSetAllAsPopupCancelButton);
597
598         __pSetAllAsListView = new (std::nothrow) ListView();
599         TryCatch(__pSetAllAsListView != null, r = GetLastResult(), "Failed to create ListView Control For Set all as Popup");
600
601         r = __pSetAllAsListView->Construct(Rectangle(0, 0, W_VIEW_AS_POPUP, H_MARK_ALL_AS_POPUP), true, SCROLL_STYLE_FADE_OUT);
602         TryCatch(r == E_SUCCESS, r = E_FAILURE, "[%s] Failed to construct Set all as ListView", GetErrorMessage(r));
603
604         __pSetAllAsListView->AddListViewItemEventListener(*__pSetAllAsListViewItemProvider);
605         __pSetAllAsListView->SetItemProvider(*__pSetAllAsListViewItemProvider);
606         __pSetAllAsPopup->AddControl(__pSetAllAsListView);
607
608         CATCH:
609         AppLogDebug("EXIT");
610         return r;
611 }
612
613 void
614 MailListForm::UnCheckAllListviewItems(void)
615 {
616         AppLogDebug("ENTER");
617
618         int itemCount;
619         int groupCount = __pMailGroupedListView->GetGroupCount();
620
621         for (int i=0; i<groupCount; i++)
622         {
623                 itemCount = __pMailGroupedListView->GetItemCountAt(i);
624
625                 for (int j=0; j<itemCount; j++)
626                 {
627                         if (__pMailGroupedListView->IsItemChecked(i, j) == true)
628                         {
629                                 __pMailGroupedListView->SetItemChecked(i, j, false);
630                         }
631                 }
632         }
633
634         AppLogDebug("EXIT");
635 }
636
637 void
638 MailListForm::CheckSelectedListviewItems(void)
639 {
640         AppLogDebug("ENTER");
641         int mailId;
642         int itemCount;
643         int groupCount = __pMailGroupedListView->GetGroupCount();
644         EmailMessageListItem* pMail = null;
645         HashMap* pSelectedMailsMap = new (std::nothrow) HashMap();
646         pSelectedMailsMap->Construct();
647
648         for (int i = 0; i < __pPresentationModel->GetNumberOfSelectedItems(); i++)
649         {
650                 pMail = __pPresentationModel->GetSelectedMailAtIndex(i);
651                 mailId = pMail->GetMailId();
652                 pSelectedMailsMap->Add(new (std::nothrow) Integer(mailId), new (std::nothrow) Integer(mailId));
653         }
654
655         __pPresentationModel->ClearSelectedMailList();
656
657         for (int groupIndex = 0; groupIndex < groupCount; groupIndex++)
658         {
659                 itemCount = __pMailGroupedListView->GetItemCountAt(groupIndex);
660
661                 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
662                 {
663                         pMail = __pPresentationModel->GetMailData(groupIndex, itemIndex);
664                         mailId = pMail->GetMailId();
665
666                         AppLogDebug("Got mailId:(%d)", mailId);
667                         if (pSelectedMailsMap->ContainsKey(Integer(mailId)))
668                         {
669                                 AppLogDebug("Setting groupIndex:(%d), itemIndex:(%d) to checked state", groupIndex, itemIndex);
670                                 __pMailGroupedListView->SetItemChecked(groupIndex, itemIndex, true);
671                                 __pPresentationModel->AddSelectedMail(groupIndex, itemIndex);
672                         }
673                 }
674         }
675
676         pSelectedMailsMap->RemoveAll(true);
677         delete pSelectedMailsMap;
678         Invalidate(true);
679         AppLogDebug("EXIT");
680 }
681
682 void
683 MailListForm::OnFormBackRequested(Form& source)
684 {
685         AppLogDebug("ENTER");
686         result r = E_SUCCESS;
687
688         if (__pAccountsListPanel->GetShowState() == false)
689         {
690                 if (__mode == NORMAL_MODE)
691                 {
692                         if (__accountId != -1)
693                         {
694                                 if (__mailboxType == EMAIL_MAILBOX_TYPE_USER_DEFINED || __mailboxType == EMAIL_MAILBOX_TYPE_ALL_EMAILS || __mailboxType == EMAIL_MAILBOX_TYPE_SEARCH_RESULT || __mailboxType == EMAIL_MAILBOX_TYPE_FLAGGED)
695                                 {
696                                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
697                                 }
698                                 else
699                                 {
700                                         __pPresentationModel->FetchData(__accountId);
701                                 }
702                         }
703                         else
704                         {
705                                 __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
706                         }
707
708                         __pPresentationModel->SortBy(SORT_BY_DATE);
709                         r = Scenes::SceneManager::GetInstance()->GoBackward(BackwardSceneTransition());
710
711                         if (r == E_UNDERFLOW)
712                         {
713                                 App::GetInstance()->Terminate();
714                         }
715                 }
716                 else if (__mode == EDIT_MODE)
717                 {
718                         UnCheckAllListviewItems();
719                         GoToNormalMode(false);
720                         __pPresentationModel->ClearSelectedMailList();
721                 }
722         }
723         else
724         {
725                 Header* pHeader = GetHeader();
726
727                 if (__mode != EDIT_MODE)
728                 {
729                         pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
730                 }
731
732                 pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
733                 GetFooter()->SetEnabled(true);
734
735                 __pMailGroupedListView->SetEnabled(true);
736                 __pAccountsListPanel->SetShowState(false);
737
738                 GetFooter()->Invalidate(true);
739                 pHeader->Invalidate(true);
740         }
741
742         AppLogDebug("EXIT");
743 }
744
745 void
746 MailListForm::OnFormMenuRequested(Form& source)
747 {
748         AppLogDebug("ENTER");
749
750         if (__pAccountsListPanel->GetShowState() == false)
751         {
752                 __pPresentationModel->SetSelectionModes();
753
754                 if (__pMoreOptionMenu == null)
755                 {
756                         InitMoreOptionMenu();
757                 }
758
759                 PopulateMoreOptionMenu(__mode, __pPresentationModel->GetSelectionMode(), __pPresentationModel->GetFavouriteSelectionMode());
760                 __pMoreOptionMenu->SetShowState(true);
761                 __pMoreOptionMenu->Show();
762         }
763
764         AppLogDebug("EXIT");
765 }
766
767 void
768 MailListForm::GoToEditMode(void)
769 {
770         FooterItem deleteItem;
771         FooterItem moveItem;
772         __mode = EDIT_MODE;
773
774         GetFooter()->RemoveAllItems();
775         deleteItem.Construct(IDA_INBOX_FORM_FOOTER_DELETE_BUTTON);
776         deleteItem.SetText(Utils::GetResourceString(L"IDS_EMAIL_HEADER_DELETE"));
777         GetFooter()->InsertItemAt(0, deleteItem);
778
779         if (__mailboxType != EMAIL_MAILBOX_TYPE_DRAFT && __mailboxType != EMAIL_MAILBOX_TYPE_OUTBOX)
780         {
781                 moveItem.Construct(IDA_INBOX_FORM_FOOTER_MOVE_BUTTON);
782                 moveItem.SetText(Utils::GetResourceString(L"IDS_EMAIL_SK_MOVE"));
783                 GetFooter()->InsertItemAt(1, moveItem);
784         }
785
786         GetHeader()->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
787         ControlAnimator* pAnimator = __pSelectedLabel->GetControlAnimator();
788         pAnimator->StopAllAnimations();
789         result r = pAnimator->StartUserAnimation(ANIMATION_TARGET_ALPHA, IntegerAnimation(0, 1, 250, ANIMATION_INTERPOLATOR_LINEAR));
790         AppLogDebug("EmailApp: Error message in StartUserAnimation %s", GetErrorMessage(r));
791
792         __pMailGroupedListView->SetSize(__pMailGroupedListView->GetWidth(), this->GetClientAreaBounds().height -__pSelectedLabel->GetHeight());
793
794         Invalidate(true);
795 }
796
797 void
798 MailListForm::GoToNormalMode(bool animationFlag)
799 {
800         AppLogDebug("ENTER, flag:(%d)", animationFlag);
801
802         FooterItem composeItem;
803         FooterItem folderItem;
804
805         __mode = NORMAL_MODE;
806
807         GetFooter()->RemoveAllItems();
808         composeItem.Construct(IDA_INBOX_FORM_FOOTER_COMPOSE_BUTTON);
809         composeItem.SetText(Utils::GetResourceString(L"IDS_EMAIL_SK_COMPOSE"));
810
811         folderItem.Construct(IDA_INBOX_FORM_FOOTER_FOLDER_BUTTON);
812         folderItem.SetText(Utils::GetResourceString(L"IDS_EMAIL_HEADER_FOLDERS"));
813
814         GetFooter()->InsertItemAt(0, composeItem);
815         GetFooter()->InsertItemAt(1, folderItem);
816
817         if (__pAccountsListPanel->GetShowState() == false)
818         {
819                 GetHeader()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
820         }
821
822         if (animationFlag)
823         {
824                 ControlAnimator* pAnimator = __pSelectedLabel->GetControlAnimator();
825                 pAnimator->StopAllAnimations();
826                 result r = pAnimator->StartUserAnimation(ANIMATION_TARGET_ALPHA, IntegerAnimation(1, 0, 250, ANIMATION_INTERPOLATOR_LINEAR));
827                 AppLogDebug("Result of StartUserAnimation %s", GetErrorMessage(r));
828         }
829         else
830         {
831                 __pSelectedLabel->SetShowState(false);
832         }
833
834         __pMailGroupedListView->SetSize(__pMailGroupedListView->GetWidth(), this->GetClientAreaBounds().height);
835
836         Invalidate(true);
837
838         AppLogDebug("EXIT");
839 }
840
841 void
842 MailListForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
843 {
844         AppLogDebug("ENTER, groupIndex:(%d), itemIndex:(%d), elementId:(%d), status:(%d)", groupIndex, itemIndex, elementId, status);
845
846         EmailMessageListItem* pMail = null;
847         ArrayList* pArgs = null;
848         AppLogDebug("Item status:(%d), elementId:(%d)", status, elementId);
849
850         if (elementId == IDA_BASE_LISTVIEW_ITEM_PROVIDER_EMPTY_ELEMENT ||
851                         elementId == IDA_BASE_LISTVIEW_ITEM_PROVIDER_SUBJECT_ELEMENT ||
852                         elementId == IDA_BASE_LISTVIEW_ITEM_PROVIDER_RECIPIENT_ELEMENT ||
853                         elementId == IDA_BASE_LISTVIEW_ITEM_PROVIDER_MESSAGE_ELEMENT ||
854                         elementId == IDA_BASE_LISTVIEW_ITEM_PROVIDER_DATE_ELEMENT ||
855                         elementId == IDA_BASE_LISTVIEW_ITEM_PROVIDER_ATTACH_ELEMENT)
856         {
857                 pArgs = new (std::nothrow) ArrayList();
858                 pArgs->Construct();
859                 pMail = __pPresentationModel->GetMailData(groupIndex, itemIndex);
860
861                 if (__mailboxType != EMAIL_MAILBOX_TYPE_DRAFT)
862                 {
863                         if (!pMail->isFlagsSeenField())
864                         {
865                                 __pPresentationModel->SetFlag(groupIndex, itemIndex, EMAIL_FLAGS_SEEN_FIELD, true, true);
866                         }
867
868                         StateInfo* pStateInfo = new (std::nothrow) StateInfo();
869                         pStateInfo->accountId = __accountId;
870                         pStateInfo->mailboxId = __mailboxId;
871                         pStateInfo->pPresentationModel = __pPresentationModel;
872                         pStateInfo->mailboxType = __mailboxType;
873                         pStateInfo->mailId = pMail->GetMailId();
874                         pArgs->Add(pStateInfo);
875
876                         Scenes::SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EMAIL_DETAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
877                 }
878                 else
879                 {
880                         EmailMessageItem* pDetailedMail = __pPresentationModel->GetCompleteMailDataN(pMail->GetMailId());
881
882                         if (pDetailedMail != null && pDetailedMail->GetHasAttachment() == true && IsAttachmentDownload(pDetailedMail) == false)
883                         {
884                                 __futureAction = EmailTypesNS::COMPOSE_AFTER_DOWNLOAD;
885                                 __groupIndex = groupIndex;
886                                 __itemIndex = itemIndex;
887                                 DownloadAllAttachments(pDetailedMail, EMAIL_DRAFT_DOWNLOAD);
888                         }
889                         else if (pDetailedMail != null)
890                         {
891                                 String mailBody;
892                                 String tmpText;
893                                 String fileName;
894                                 String emailId;
895
896                                 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
897
898                                 pStateInfo->accountId = __accountId;
899                                 pStateInfo->mailboxId = __mailboxId;
900                                 pStateInfo->pPresentationModel = __pPresentationModel;
901                                 pStateInfo->mailboxType = __mailboxType;
902
903                                 //                      pArgs->Add(new (std::nothrow) Integer(__accountId));
904                                 //                      pArgs->Add(new (std::nothrow) Integer(__mailboxId));
905                                 //                      pArgs->Add(__pPresentationModel);
906                                 //                      pArgs->Add(new (std::nothrow) Integer(__mailboxType));
907
908                                 Utils::BuildEmailIdStringFromFullAddress(pDetailedMail->GetFullAddressTo(), emailId);
909                                 //                      pArgs->Add(new (std::nothrow) String(emailId)); // to field
910                                 pStateInfo->toFieldValue = emailId;
911
912                                 Utils::BuildEmailIdStringFromFullAddress(pDetailedMail->GetFullAddressCc(), emailId);
913                                 //                      pArgs->Add(new (std::nothrow) String(emailId)); // cc field
914                                 pStateInfo->ccFieldValue = emailId;
915
916                                 Utils::BuildEmailIdStringFromFullAddress(pDetailedMail->GetFullAddressBcc(), emailId);
917                                 //                      pArgs->Add(new (std::nothrow) String(emailId)); // bcc field
918                                 pStateInfo->bccFieldValue = emailId;
919
920                                 //                      pArgs->Add(new (std::nothrow) String(pDetailedMail->GetSubject())); // subject field
921                                 pStateInfo->subjectFieldValue = pDetailedMail->GetSubject();
922
923                                 fileName.Append(pDetailedMail->GetFilePathPlain());
924
925                                 if (fileName.IsEmpty() == false)
926                                 {
927                                         File file;
928                                         result r = file.Construct(fileName, L"r");
929
930                                         if (r == E_SUCCESS)
931                                         {
932                                                 while (file.Read(tmpText) == E_SUCCESS)
933                                                 {
934                                                         mailBody.Append(tmpText);
935                                                 }
936                                         }
937                                 }
938
939                                 //                      pArgs->Add(new (std::nothrow) String(mailBody));
940                                 pStateInfo->bodyFieldValue = mailBody;
941
942                                 tmpText.Clear();
943                                 if (pDetailedMail->GetHasAttachment() == true)
944                                 {
945                                         String destFilePath;
946                                         EmailAttachment* pTmpAttachment = null;
947                                         ArrayList* pAttachmentList = __pPresentationModel->GetAllAttachmentListN(pMail->GetMailId());
948
949                                         for (int i=0; i<pAttachmentList->GetCount(); i++)
950                                         {
951                                                 pTmpAttachment = static_cast<EmailAttachment*>(pAttachmentList->GetAt(i));
952
953                                                 destFilePath.Clear();
954                                                 destFilePath.Append(App::GetInstance()->GetAppSharedPath()+L"data/");
955                                                 destFilePath.Append(pTmpAttachment->GetAttachmentName());
956
957                                                 if (File::Copy(pTmpAttachment->GetAttachmentPath(), destFilePath, false) == E_SUCCESS)
958                                                 {
959                                                         EmailMailboxManager::GetInstance()->DeleteAttachment(pTmpAttachment->GetAttachmentId());
960                                                         tmpText.Append(destFilePath);
961                                                         tmpText.Append(IDS_DELIM_SEMICOLON);
962                                                 }
963                                         }
964                                 }
965                                 //                      pArgs->Add(new (std::nothrow) String(tmpText));
966                                 pStateInfo->attachmentsPath = tmpText;
967
968                                 if (__pPresentationModel->IsMailSelected(pMail))
969                                 {
970                                         __pPresentationModel->RemoveMailFromSelectedMailList(pMail);
971                                         //                              pArgs->Add(new (std::nothrow) Boolean(true));
972                                         pStateInfo->isMailSelected = true;
973                                 }
974
975                                 pArgs->Add(pStateInfo);
976
977                                 EmailMailboxManager::GetInstance()->DeleteMailMessage(pMail->GetMailboxId(), pMail->GetMailId(), false);
978
979                                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EMAIL_COMPOSER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
980                         }
981                 }
982
983                 __pMailGroupedListView->SetItemChecked(groupIndex, itemIndex, false);
984         }
985         else if (elementId == IDA_INBOX_FORM_FORMAT_IMPORTANT)
986         {
987                 pMail = __pPresentationModel->GetMailData(groupIndex, itemIndex);
988
989                 if (pMail != null && pMail->isFlagsFlaggedField())
990                 {
991                         __pPresentationModel->SetFlag(pMail, EMAIL_FLAGS_FLAGGED_FIELD, false, true);
992                 }
993                 else
994                 {
995                         __pPresentationModel->SetFlag(pMail, EMAIL_FLAGS_FLAGGED_FIELD, true, true);
996                 }
997
998                 if (pMail != null && __pPresentationModel->IsMailSelected(pMail) == true)
999                 {
1000                         __pMailGroupedListView->SetItemChecked(groupIndex, itemIndex, true);
1001                 }
1002                 else
1003                 {
1004                         __pMailGroupedListView->SetItemChecked(groupIndex, itemIndex, false);
1005                 }
1006
1007                 __pMailGroupedListView->RefreshList(groupIndex, itemIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1008
1009                 if (__pPresentationModel->GetSortType() == SORT_BY_IMPORTANT)
1010                 {
1011                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
1012                         {
1013                                 UnCheckAllListviewItems();
1014                         }
1015
1016                         __pPresentationModel->SortBy(SORT_BY_IMPORTANT);
1017                         __pMailGroupedListView->UpdateList();
1018
1019                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
1020                         {
1021                                 CheckSelectedListviewItems();
1022                         }
1023                 }
1024         }
1025         else if (status == LIST_ITEM_STATUS_CHECKED)
1026         {
1027                 String text;
1028
1029                 if (__pPresentationModel->GetNumberOfSelectedItems() == 0)
1030                 {
1031                         int tmpItemIndex, tmpGroupIndex;
1032
1033                         GoToEditMode();
1034
1035                         // If the last item in the list was clicked, scroll it up a little bit so its not hidden by the toast.
1036                         __pMailGroupedListView->GetBottomDrawnItemIndex(tmpGroupIndex, tmpItemIndex);
1037
1038                         if (itemIndex == tmpItemIndex && groupIndex == tmpGroupIndex)
1039                         {
1040                                 __pMailGroupedListView->ScrollToItem(groupIndex, itemIndex, LIST_SCROLL_ITEM_ALIGNMENT_BOTTOM);
1041                         }
1042                 }
1043
1044                 __pPresentationModel->AddSelectedMail(groupIndex, itemIndex);
1045
1046                 if (__pPresentationModel->GetNumberOfSelectedItems() != 0)
1047                 {
1048                         text.Append(Utils::GetResourceString(L"IDS_COM_OPT_SELECTED"));
1049                         text.Append(L"\x200E");
1050                         text.Append(L" (");
1051                         text.Append(__pPresentationModel->GetNumberOfSelectedItems());
1052                         text.Append(L")");
1053                         text.Append(L"\x200E");
1054                         __pSelectedLabel->SetText(text);
1055                         __pSelectedLabel->Invalidate(true);
1056                 }
1057         }
1058         else if (status == LIST_ITEM_STATUS_UNCHECKED)
1059         {
1060                 String text;
1061
1062                 if (__pPresentationModel->GetNumberOfSelectedItems() == 1)
1063                 {
1064                         GoToNormalMode(true);
1065                 }
1066
1067                 __pPresentationModel->RemoveSelectedMail(groupIndex, itemIndex);
1068
1069                 if (__pPresentationModel->GetNumberOfSelectedItems() != 0)
1070                 {
1071                         text.Append(Utils::GetResourceString(L"IDS_COM_OPT_SELECTED"));
1072                         text.Append(L"\x200E");
1073                         text.Append(L" (");
1074                         text.Append(__pPresentationModel->GetNumberOfSelectedItems());
1075                         text.Append(L")");
1076                         text.Append(L"\x200E");
1077                         __pSelectedLabel->SetText(text);
1078                         __pSelectedLabel->Invalidate(true);
1079                 }
1080         }
1081
1082         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
1083         return;
1084 }
1085
1086 void
1087 MailListForm::OnGroupedListViewItemSwept(GroupedListView& listView, int groupIndex, int itemIndex, SweepDirection direction)
1088 {
1089         // Empty implementation
1090 }
1091
1092 void
1093 MailListForm::OnGroupedListViewContextItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListContextItemStatus status)
1094 {
1095         AppLogDebug("ENTER, groupIndex:(%d), itemIndex:(%d), elementId:(%d), status:(%d)", groupIndex, itemIndex, elementId, status);
1096
1097         ArrayList* pArgs = new (std::nothrow) ArrayList();
1098
1099         if (elementId == IDA_INBOX_FORM_REPLY_BUTTON)
1100         {
1101                 if (pArgs != null && E_SUCCESS == pArgs->Construct())
1102                 {
1103                         String emailId;
1104                         String body = L"";
1105                         EmailMessageListItem* pMail = __pPresentationModel->GetMailData(groupIndex, itemIndex);
1106                         EmailMessageItem* pDetailedMail = __pPresentationModel->GetCompleteMailDataN(pMail->GetMailId());
1107                         EmailAccount* pAccount = EmailSettingsProvider::GetInstance()->GetAccountById(__accountId);
1108                         StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1109
1110                         pStateInfo->accountId = __accountId;
1111                         pStateInfo->mailboxId = __mailboxId;
1112                         pStateInfo->pPresentationModel = __pPresentationModel;
1113                         pStateInfo->mailboxType = __mailboxType;
1114                         pStateInfo->ccFieldValue = L"";
1115                         pStateInfo->bccFieldValue = L"";
1116
1117                         if (pDetailedMail != null)
1118                         {
1119                                 String subject = L"Re: ";
1120                                 subject.Append(pDetailedMail->GetSubject());
1121                                 pStateInfo->subjectFieldValue = subject;
1122
1123                                 if (__mailboxType == EMAIL_MAILBOX_TYPE_OUTBOX || __mailboxType == EMAIL_MAILBOX_TYPE_SENTBOX)
1124                                 {
1125                                         String emailIds;
1126                                         Utils::BuildEmailIdStringFromFullAddress(pDetailedMail->GetFullAddressTo(), emailIds);
1127                                         pStateInfo->toFieldValue = emailIds;
1128
1129                                         Utils::BuildEmailIdStringFromFullAddress(pDetailedMail->GetFullAddressCc(), emailIds);
1130                                         pStateInfo->ccFieldValue = emailIds;
1131                                 }
1132                                 else
1133                                 {
1134                                         pStateInfo->toFieldValue = pDetailedMail->GetEmailAddressSender();
1135                                 }
1136
1137                                 if (pAccount->GetOptions()->GetReplyWithBody() == true)
1138                                 {
1139                                         body.Append(L"\n\n----Original Message----\n");
1140                                         body.Append(L"From: ");
1141                                         body.Append(pDetailedMail->GetFullAddressFrom());
1142                                         body.Append(L"\nSent: ");
1143                                         body.Append(pDetailedMail->GetLocalDateTime().ToString());
1144                                         body.Append(L"\nTo: ");
1145                                         Utils::ExtractEmailIdFromFullAddress(pDetailedMail->GetFullAddressTo(), emailId);
1146                                         body.Append(emailId);
1147                                         body.Append(L"\nSubject: ");
1148                                         body.Append(pDetailedMail->GetSubject());
1149
1150                                         String mailBody;
1151                                         File file;
1152                                         result r = file.Construct(pDetailedMail->GetFilePathPlain(), L"r");
1153
1154                                         if (r == E_SUCCESS)
1155                                         {
1156                                                 while (file.Read(mailBody) == E_SUCCESS)
1157                                                 {
1158                                                         body.Append(mailBody);
1159                                                 }
1160                                         }
1161                                 }
1162                         }
1163
1164                         pStateInfo->bodyFieldValue = body;
1165                         pStateInfo->attachmentsPath = L"";
1166
1167                         pArgs->Add(pStateInfo);
1168
1169                         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EMAIL_COMPOSER), pArgs);
1170                 }
1171         }
1172         else if (elementId == IDA_INBOX_FORM_MARK_AS_READ_BUTTON)
1173         {
1174                 __pPresentationModel->SetFlag(groupIndex, itemIndex, EMAIL_FLAGS_SEEN_FIELD, true, true);
1175                 __pMailGroupedListView->RefreshList(groupIndex, itemIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1176
1177                 if (__viewByType == SORT_BY_UNREAD)
1178                 {
1179                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
1180                         {
1181                                 UnCheckAllListviewItems();
1182                         }
1183
1184                         __pPresentationModel->SortBy(SORT_BY_UNREAD);
1185                         __pMailGroupedListView->UpdateList();
1186
1187                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
1188                         {
1189                                 CheckSelectedListviewItems();
1190                         }
1191                 }
1192         }
1193         else if (elementId == IDA_INBOX_FORM_MARK_AS_UNREAD_BUTTON)
1194         {
1195                 __pPresentationModel->SetFlag(groupIndex, itemIndex, EMAIL_FLAGS_SEEN_FIELD, false, true);
1196                 __pMailGroupedListView->RefreshList(groupIndex, itemIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
1197
1198                 if (__viewByType == SORT_BY_UNREAD)
1199                 {
1200                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
1201                         {
1202                                 UnCheckAllListviewItems();
1203                         }
1204
1205                         __pPresentationModel->SortBy(SORT_BY_UNREAD);
1206                         __pMailGroupedListView->UpdateList();
1207
1208                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
1209                         {
1210                                 CheckSelectedListviewItems();
1211                         }
1212                 }
1213         }
1214         else if (elementId == IDA_INBOX_FORM_FORWARD_BUTTON)
1215         {
1216                 EmailMessageListItem* pMail = __pPresentationModel->GetMailData(groupIndex, itemIndex);
1217                 EmailMessageItem* pDetailedMail = __pPresentationModel->GetCompleteMailDataN(pMail->GetMailId());
1218                 EmailAccount* pAccount = EmailSettingsProvider::GetInstance()->GetAccountById(__accountId);
1219
1220                 if (pDetailedMail != null && pDetailedMail->GetHasAttachment() == true && pAccount->GetOptions()->GetForwardWithFiles() == true && IsAttachmentDownload(pDetailedMail) == false)
1221                 {
1222                         __futureAction = EmailTypesNS::FORWARD_AFTER_DOWNLOAD;
1223                         __groupIndex = groupIndex;
1224                         __itemIndex = itemIndex;
1225                         DownloadAllAttachments(pDetailedMail, EMAIL_SWIPE_FORWARD);
1226                 }
1227                 else
1228                 {
1229                         ArrayList* pArgs = new (std::nothrow) ArrayList();
1230
1231                         if (pArgs != null && E_SUCCESS == pArgs->Construct())
1232                         {
1233                                 String emailId;
1234                                 String tmpSubject;
1235                                 String fullAddressFrom;
1236                                 String localDateTime;
1237                                 String fullAddressTo;
1238                                 String filePathPlain;
1239                                 String attachmentStr = L"";
1240                                 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1241
1242                                 pStateInfo->accountId = __accountId;
1243                                 pStateInfo->mailboxId = __mailboxId;
1244                                 pStateInfo->pPresentationModel = __pPresentationModel;
1245                                 pStateInfo->mailboxType = __mailboxType;
1246                                 pStateInfo->toFieldValue = L"";
1247                                 pStateInfo->ccFieldValue = L"";
1248                                 pStateInfo->bccFieldValue = L"";
1249
1250 //                              pArgs->Add(new (std::nothrow) Integer(__accountId));
1251 //                              pArgs->Add(new (std::nothrow) Integer(__mailboxId));
1252 //                              pArgs->Add(__pPresentationModel);
1253 //                              pArgs->Add(new (std::nothrow) Integer(__mailboxType));
1254
1255 //                              pArgs->Add(new (std::nothrow) String(L"")); // to field
1256 //                              pArgs->Add(new (std::nothrow) String(L"")); // cc field
1257 //                              pArgs->Add(new (std::nothrow) String(L"")); // bcc field
1258
1259                                 if (pDetailedMail != null)
1260                                 {
1261                                         tmpSubject = pDetailedMail->GetSubject();
1262                                         fullAddressFrom = pDetailedMail->GetFullAddressFrom();
1263                                         localDateTime = pDetailedMail->GetLocalDateTime().ToString();
1264                                         fullAddressTo = pDetailedMail->GetFullAddressTo();
1265                                         filePathPlain = pDetailedMail->GetFilePathPlain();
1266
1267                                         if (pDetailedMail->GetHasAttachment() == true && pAccount->GetOptions()->GetForwardWithFiles() == true)
1268                                         {
1269                                                 ArrayList* pAttachments = __pPresentationModel->GetAllAttachmentListN(pDetailedMail->GetMailId());
1270
1271                                                 for (int i=0; i < pAttachments->GetCount(); i++)
1272                                                 {
1273                                                         attachmentStr.Append(static_cast<EmailAttachment*>(pAttachments->GetAt(i))->GetAttachmentPath());
1274                                                         attachmentStr.Append(';');
1275                                                 }
1276                                         }
1277
1278                                         delete pDetailedMail;
1279                                 }
1280
1281                                 String subject = L"Fwd: ";
1282                                 subject.Append(tmpSubject);
1283 //                              pArgs->Add(subject); // subject field
1284                                 pStateInfo->subjectFieldValue = subject;
1285
1286                                 String body = L"\n\n----Original Message----\n";
1287                                 body.Append(L"From: ");
1288                                 body.Append(fullAddressFrom);
1289                                 body.Append(L"\nSent: ");
1290                                 body.Append(localDateTime);
1291                                 body.Append(L"\nTo: ");
1292                                 Utils::ExtractEmailIdFromFullAddress(fullAddressTo, emailId);
1293                                 body.Append(emailId);
1294                                 body.Append(L"\nSubject: ");
1295                                 body.Append(tmpSubject);
1296                                 body.Append(L"\n");
1297
1298                                 if (filePathPlain.IsEmpty() == false)
1299                                 {
1300                                         String mailBody;
1301                                         File file;
1302                                         result r = file.Construct(filePathPlain, L"r");
1303
1304                                         if (r == E_SUCCESS)
1305                                         {
1306                                                 while (file.Read(mailBody) == E_SUCCESS)
1307                                                 {
1308                                                         body.Append(mailBody);
1309                                                 }
1310                                         }
1311                                 }
1312
1313 //                              pArgs->Add(body); // body field
1314 //                              pArgs->Add(attachmentStr); // attachments field
1315
1316                                 pStateInfo->bodyFieldValue = body;
1317                                 pStateInfo->attachmentsPath = attachmentStr;
1318
1319                                 pArgs->Add(pStateInfo);
1320                         }
1321
1322                         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EMAIL_COMPOSER), pArgs);
1323                 }
1324         }
1325         else if (elementId == IDA_INBOX_FORM_DELETE_BUTTON)
1326         {
1327                 EmailMessageListItem* pMsg = __pPresentationModel->GetMailData(groupIndex, itemIndex);
1328
1329                 if (pMsg != null)
1330                 {
1331                         EmailApp::GetInstance()->SetShowDeletePopupStatus(EMAIL_SWIPE_DELETE, pMsg->GetMailId());
1332
1333                         SetDeleteConfirmationPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_Q"));
1334
1335                         __pDeleteConfirmationPopup->SetShowState(true);
1336                         __pDeleteConfirmationPopup->Show();
1337                 }
1338         }
1339
1340         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
1341         return;
1342 }
1343
1344 void
1345 MailListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
1346 {
1347         AppLogDebug("ENTER, actionId:(%d)", actionId);
1348         result r = E_SUCCESS;
1349
1350         if (actionId == IDA_INBOX_FORM_HEADER_SEARCH_BUTTON)
1351         {
1352                 ArrayList* pArgs = new (std::nothrow) ArrayList();
1353                 pArgs->Construct();
1354
1355                 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1356
1357                 pStateInfo->accountId = __accountId;
1358                 pStateInfo->mailboxId = __mailboxId;
1359                 pStateInfo->pPresentationModel = __pPresentationModel;
1360                 pStateInfo->mailboxType = __mailboxType;
1361
1362                 pArgs->Add(pStateInfo);
1363
1364                 SearchPresentationModel* pSearchPresentationModel = SearchPresentationModel::GetInstance();
1365
1366                 if (pSearchPresentationModel != null)
1367                 {
1368                         BasePresentationModel* pBasePresentationModel = pSearchPresentationModel->GetPresentationModel();
1369
1370                         if (pBasePresentationModel != null)
1371                         {
1372                                 pBasePresentationModel->FetchData(__accountId, true);
1373                                 pSearchPresentationModel->Initialize(pBasePresentationModel);
1374                                 pSearchPresentationModel->PerformSearch(L"");
1375                         }
1376                 }
1377
1378                 result r = SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SEARCH, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
1379                 AppLogDebug("Result of go forward:(%s)", GetErrorMessage(r));
1380         }
1381         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_INBOX)
1382         {
1383                 __mailboxViewType = INBOX_VIEW;
1384                 __mailboxId = __pPresentationModel->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_INBOX);
1385                 __mailboxType = EMAIL_MAILBOX_TYPE_INBOX;
1386
1387                 if (__accountId > 0)
1388                 {
1389                         __mailboxId = __pPresentationModel->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_INBOX);
1390                         __pPresentationModel = InboxPresentationModel::GetInstance();
1391                         __pPresentationModel->FetchData(__accountId);
1392                         __pPresentationModel->SortBy(__viewByType);
1393                         __pBaseListViewItemProvider->SetPresentationModel(__pPresentationModel);
1394                 }
1395                 else if (__accountId == -1)
1396                 {
1397                         __mailboxId = -1;
1398                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
1399                         __pPresentationModel->SortBy(__viewByType);
1400                 }
1401
1402                 PopulateHeader();
1403                 __pMailGroupedListView->UpdateList();
1404                 UnCheckAllListviewItems();
1405         }
1406 //      else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_FAVORITES)
1407 //      {
1408 //              __mailboxViewType = FAVORITES_VIEW;
1409 //
1410 //              __mailboxId = -1;
1411 //              __mailboxType = EMAIL_MAILBOX_TYPE_FLAGGED;
1412 //              __pPresentationModel = AllMailsPresentationModel::GetInstance();
1413 //              __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
1414 //              __pPresentationModel->SortBy(__viewByType);
1415 //              __pMailGroupedListView->UpdateList();
1416 //              UnCheckAllListviewItems();
1417 //              PopulateHeader();
1418 //      }
1419         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_DRAFTS)
1420         {
1421                 __mailboxViewType = DRAFTS_VIEW;
1422
1423                 __mailboxId = __pPresentationModel->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_DRAFT);
1424                 __mailboxType = EMAIL_MAILBOX_TYPE_DRAFT;
1425
1426                 if (__accountId > 0)
1427                 {
1428                         __mailboxId = __pPresentationModel->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_DRAFT);
1429                         __pPresentationModel = DraftListPresentationModel::GetInstance();
1430                         __pPresentationModel->FetchData(__accountId);
1431                         __pPresentationModel->SortBy(__viewByType);
1432                         __pBaseListViewItemProvider->SetPresentationModel(__pPresentationModel);
1433                 }
1434                 else if (__accountId == -1)
1435                 {
1436                         __mailboxId = -1;
1437                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
1438                         __pPresentationModel->SortBy(__viewByType);
1439                 }
1440
1441                 PopulateHeader();
1442                 __pMailGroupedListView->UpdateList();
1443                 UnCheckAllListviewItems();
1444         }
1445         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_SENTBOX)
1446         {
1447                 __mailboxViewType = SENTBOX_VIEW;
1448
1449                 __mailboxId = __pPresentationModel->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_SENTBOX);
1450                 __mailboxType = EMAIL_MAILBOX_TYPE_SENTBOX;
1451
1452                 if (__accountId > 0)
1453                 {
1454                         __mailboxId = __pPresentationModel->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_SENTBOX);
1455                         __pPresentationModel = SentboxPresentationModel::GetInstance();
1456                         __pPresentationModel->FetchData(__accountId);
1457                         __pPresentationModel->SortBy(__viewByType);
1458                         __pBaseListViewItemProvider->SetPresentationModel(__pPresentationModel);
1459                 }
1460                 else if (__accountId == -1)
1461                 {
1462                         __mailboxId = -1;
1463                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
1464                         __pPresentationModel->SortBy(__viewByType);
1465                 }
1466
1467                 PopulateHeader();
1468                 __pMailGroupedListView->UpdateList();
1469                 UnCheckAllListviewItems();
1470         }
1471         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_ALL_FOLDERS)
1472         {
1473                 __mailboxViewType = ALL_FOLDERS_VIEW;
1474
1475                 ArrayList* pArgs = new (std::nothrow) ArrayList();
1476                 pArgs->Construct();
1477
1478                 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1479
1480                 pStateInfo->accountId = __accountId;
1481                 pStateInfo->mailboxId = __mailboxId;
1482                 pStateInfo->pPresentationModel = __pPresentationModel;
1483                 pStateInfo->mailboxType = __mailboxType;
1484
1485                 pArgs->Add(pStateInfo);
1486
1487                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_FOLDERS_VIEW, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
1488         }
1489         else if (actionId == IDA_INBOX_FORM_HEADER_UPDATE_BUTTON)
1490         {
1491                 EmailMailboxManager* pMgr = EmailMailboxManager::GetInstance();
1492
1493                 pMgr->SyncHeader(__accountId, __mailboxId);
1494         }
1495         else if (actionId == IDA_INBOX_FORM_FOOTER_COMPOSE_BUTTON)
1496         {
1497                 ArrayList* pArgs = new (std::nothrow) ArrayList();
1498                 pArgs->Construct();
1499
1500                 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1501
1502                 pStateInfo->accountId = __accountId;
1503                 pStateInfo->mailboxId = __mailboxId;
1504                 pStateInfo->pPresentationModel = __pPresentationModel;
1505                 pStateInfo->mailboxType = __mailboxType;
1506                 pStateInfo->toFieldValue = L"";
1507                 pStateInfo->ccFieldValue = L"";
1508                 pStateInfo->bccFieldValue = L"";
1509                 pStateInfo->subjectFieldValue = L"";
1510                 pStateInfo->bodyFieldValue = L"";
1511                 pStateInfo->attachmentsPath = L"";
1512
1513                 pArgs->Add(pStateInfo);
1514
1515                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EMAIL_COMPOSER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
1516         }
1517         else if (actionId == IDA_INBOX_FORM_FOOTER_FOLDER_BUTTON)
1518         {
1519                 PopulateFolderContextMenu();
1520
1521                 __pFolderContextMenu->SetFocusable(true);
1522                 __pFolderContextMenu->SetShowState(true);
1523                 __pFolderContextMenu->Show();
1524         }
1525         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_SORT_BY)
1526         {
1527                 InitSortByPopup(POPUP_LISTVIEW_ITEM_COUNT);
1528
1529                 __pSortByPopup->SetShowState(true);
1530                 __pSortByPopup->Show();
1531         }
1532         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_DELETE_ALL)
1533         {
1534                 SetDeleteConfirmationPopupTitle(Utils::GetResourceString(L"IDS_EMAIL_POP_DELETE_ALL_Q"));
1535
1536                 __pDeleteConfirmationPopup->SetShowState(true);
1537                 __pDeleteConfirmationPopup->Show();
1538
1539                 EmailApp::GetInstance()->SetShowDeletePopupStatus(EMAIL_DELETE_ALL, -1);
1540         }
1541         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_ADD_ACCOUNT)
1542         {
1543                 ArrayList* pArgs = new (std::nothrow) ArrayList();
1544                 pArgs->Construct();
1545
1546                 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1547
1548                 pStateInfo->accountId = __accountId;
1549                 pStateInfo->mailboxId = __mailboxId;
1550                 pStateInfo->pPresentationModel = __pPresentationModel;
1551                 pStateInfo->mailboxType = __mailboxType;
1552
1553                 pArgs->Add(pStateInfo);
1554
1555                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_ADD_ACCOUNT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
1556         }
1557         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_SETTINGS)
1558         {
1559                 ArrayList* pArgs = new (std::nothrow) ArrayList();
1560                 pArgs->Construct();
1561
1562                 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1563
1564                 pStateInfo->accountId = __accountId;
1565                 pStateInfo->mailboxId = __mailboxId;
1566                 pStateInfo->pPresentationModel = __pPresentationModel;
1567                 pStateInfo->mailboxType = __mailboxType;
1568
1569                 pArgs->Add(pStateInfo);
1570
1571                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EMAIL_SETTING, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
1572         }
1573         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_MARK_UNREAD)
1574         {
1575                 __pPresentationModel->SetFlag(EMAIL_FLAGS_SEEN_FIELD, false, true);
1576                 UnCheckAllListviewItems();
1577                 GoToNormalMode(true);
1578                 __pPresentationModel->ClearSelectedMailList();
1579         }
1580         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_MARK_READ)
1581         {
1582                 __pPresentationModel->SetFlag(EMAIL_FLAGS_SEEN_FIELD, true, true);
1583                 UnCheckAllListviewItems();
1584                 GoToNormalMode(true);
1585                 __pPresentationModel->ClearSelectedMailList();
1586
1587                 if (__viewByType == SORT_BY_UNREAD)
1588                 {
1589                         __pPresentationModel->SortBy(SORT_BY_UNREAD);
1590                         __pMailGroupedListView->UpdateList();
1591                 }
1592         }
1593         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_MARK_ALL_AS)
1594         {
1595                 InitMarkAllAsPopup();
1596                 __pMarkAllAsPopup->SetShowState(true);
1597                 __pMarkAllAsPopup->Show();
1598         }
1599         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_SET_UNFAVOURITES)
1600         {
1601                 __pPresentationModel->SetFlag(EMAIL_FLAGS_FLAGGED_FIELD, false, true);
1602                 UnCheckAllListviewItems();
1603                 GoToNormalMode(true);
1604                 __pPresentationModel->ClearSelectedMailList();
1605
1606                 if (__viewByType == SORT_BY_IMPORTANT)
1607                 {
1608                         __pPresentationModel->SortBy(SORT_BY_IMPORTANT);
1609                         __pMailGroupedListView->UpdateList();
1610                 }
1611         }
1612         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_SET_FAVOURITES)
1613         {
1614                 __pPresentationModel->SetFlag(EMAIL_FLAGS_FLAGGED_FIELD, true, true);
1615                 UnCheckAllListviewItems();
1616                 GoToNormalMode(true);
1617                 __pPresentationModel->ClearSelectedMailList();
1618         }
1619         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_SET_ALL_AS)
1620         {
1621                 InitSetAllAsPopup();
1622                 __pSetAllAsPopup->SetShowState(true);
1623                 __pSetAllAsPopup->Show();
1624         }
1625         else if (actionId == IDA_INBOX_FORM_BTN_POPUP_CANCEL)
1626         {
1627                 __pSortByPopup->SetShowState(false);
1628                 Invalidate(true);
1629         }
1630         else if (actionId == IDA_INBOX_FORM_FOOTER_MOVE_BUTTON)
1631         {
1632                 ArrayList* pArgs = new (std::nothrow) ArrayList();
1633                 pArgs->Construct();
1634
1635                 if (__mailboxId != -1)
1636                 {
1637                         StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1638
1639                         pStateInfo->accountId = __accountId;
1640                         pStateInfo->mailboxId = __mailboxId;
1641                         pStateInfo->pPresentationModel = __pPresentationModel;
1642                         pStateInfo->mailboxType = __mailboxType;
1643
1644                         pArgs->Add(pStateInfo);
1645
1646                         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_MOVEMAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
1647                 }
1648                 else
1649                 {
1650                         int isMultipleAccountsItemsSelected = __pPresentationModel->IsMultipleAccountsSelected();
1651
1652                         if (isMultipleAccountsItemsSelected > 0)
1653                         {
1654                                 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
1655
1656                                 pStateInfo->accountId = isMultipleAccountsItemsSelected;;
1657                                 pStateInfo->mailboxId = __mailboxId;
1658                                 pStateInfo->pPresentationModel = __pPresentationModel;
1659                                 pStateInfo->mailboxType = __mailboxType;
1660
1661                                 pArgs->Add(pStateInfo);
1662
1663                                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_MOVEMAIL, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
1664                         }
1665                         else
1666                         {
1667                                 int modRes;
1668                                 MessageBox msgBox;
1669                                 msgBox.Construct(Utils::GetResourceString(L"IDS_COM_POP_ERROR"), L"Unable to move emails from multiple accounts at once!", MSGBOX_STYLE_OK, 300000);
1670                                 msgBox.ShowAndWait(modRes);
1671                                 __pPresentationModel->ClearSelectedMailList();
1672                                 UnCheckAllListviewItems();
1673                                 GoToNormalMode(true);
1674                         }
1675                 }
1676         }
1677         else if (actionId == IDA_INBOX_FORM_BTN_MARK_ALL_AS_POPUP_CLOSE)
1678         {
1679                 __pMarkAllAsPopup->SetShowState(false);
1680                 Invalidate(true);
1681         }
1682         else if (actionId == IDA_INBOX_FORM_BTN_SET_ALL_AS_POPUP_CANCEL)
1683         {
1684                 __pSetAllAsPopup->SetShowState(false);
1685                 Invalidate(true);
1686         }
1687         else if (actionId == IDA_INBOX_FORM_FOOTER_DELETE_BUTTON)
1688         {
1689                 EmailApp::GetInstance()->SetShowDeletePopupStatus(EMAIL_SELECTED_DELETE, -1);
1690
1691                 SetDeleteConfirmationPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_Q"));
1692                 __pDeleteConfirmationPopup->SetShowState(true);
1693                 __pDeleteConfirmationPopup->Show();
1694         }
1695         else if (actionId == IDA_INBOX_FORM_CONTEXT_MENU_BLOCK)
1696         {
1697                 __pPresentationModel->BlockEmails();
1698
1699                 if (__accountId == -1)
1700                 {
1701                         r = __pPresentationModel->MoveMail(EMAIL_MAILBOX_TYPE_SPAMBOX);
1702                 }
1703                 else
1704                 {
1705                         int mailboxId = EmailMailboxManager::GetInstance()->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_SPAMBOX);
1706                         r = __pPresentationModel->MoveMail(mailboxId);
1707                 }
1708
1709                 if (r == E_SUCCESS)
1710                 {
1711                         ShowPopUp(Utils::GetResourceString(L"IDS_BLOCKING"));
1712                         __waitForMove = true;
1713                 }
1714                 else
1715                 {
1716                         EmailApp::GetInstance()->SetMoveOrDeleteFailedPopupStatus(true);
1717                         SetMoveOrDeleteFailedPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_MOVING_FAILED"));
1718                         __pMoveOrDeleteFailedPopup->SetShowState(true);
1719                         __pMoveOrDeleteFailedPopup->Show();
1720                         UnCheckAllListviewItems();
1721                         GoToNormalMode(true);
1722                         Invalidate(true);
1723                 }
1724         }
1725         else if (actionId == IDA_INBOX_FORM_DELETE_CONFIRMATION_NO)
1726         {
1727                 EmailApp::GetInstance()->ClearShowDeletePopupStatus();
1728
1729                 __pDeleteConfirmationPopup->SetShowState(false);
1730                 Invalidate(true);
1731         }
1732         else if (actionId == IDA_INBOX_FORM_DELETE_CONFIRMATION_YES)
1733         {
1734                 __pDeleteConfirmationPopup->SetShowState(false);
1735                 Invalidate(true);
1736
1737                 int mailId;
1738                 DeletionMode mode;
1739                 if (EmailApp::GetInstance()->GetShowDeletePopupStatus(mailId, mode) == true)
1740                 {
1741                         if (mode == EMAIL_SWIPE_DELETE)
1742                         {
1743                                 int groupIndex, itemIndex;
1744                                 __pPresentationModel->GetMailIndex(mailId, groupIndex, itemIndex);
1745
1746                                 EmailApp::GetInstance()->ClearShowDeletePopupStatus();
1747
1748                                 if (groupIndex != -1 && itemIndex != -1 && groupIndex <= __pPresentationModel->GetGroupCount()-1 && itemIndex <= __pPresentationModel->GetItemCount(groupIndex)-1)
1749                                 {
1750                                         if (__accountId == -1)
1751                                         {
1752                                                 if (__mailboxType == EMAIL_MAILBOX_TYPE_TRASH)
1753                                                 {
1754                                                         __pPresentationModel->DeleteMail(groupIndex, itemIndex, false);
1755                                                 }
1756                                                 else
1757                                                 {
1758                                                         r = __pPresentationModel->MoveMail(groupIndex, itemIndex, EMAIL_MAILBOX_TYPE_TRASH);
1759                                                 }
1760                                         }
1761                                         else
1762                                         {
1763                                                 email_mailbox_type_e mailboxType = __pPresentationModel->GetMailboxType(__mailboxId);
1764
1765                                                 if (mailboxType == EMAIL_MAILBOX_TYPE_TRASH)
1766                                                 {
1767                                                         __pPresentationModel->DeleteMail(groupIndex, itemIndex, false);
1768                                                 }
1769                                                 else
1770                                                 {
1771                                                         int mailboxId = EmailMailboxManager::GetInstance()->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_TRASH);
1772                                                         r = __pPresentationModel->MoveMail(groupIndex, itemIndex, mailboxId);
1773                                                 }
1774                                         }
1775
1776
1777                                         if (r == E_SUCCESS)
1778                                         {
1779                                                 ShowPopUp(Utils::GetResourceString(L"IDS_EMAIL_POP_DELETING_ING"));
1780                                                 __waitForDelete = true;
1781                                         }
1782                                         else
1783                                         {
1784                                                 EmailApp::GetInstance()->SetMoveOrDeleteFailedPopupStatus(false);
1785                                                 SetMoveOrDeleteFailedPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_FAILED"));
1786                                                 __pMoveOrDeleteFailedPopup->SetShowState(true);
1787                                                 __pMoveOrDeleteFailedPopup->Show();
1788                                                 Invalidate(true);
1789                                         }
1790                                 }
1791                         }
1792                         else if (mode == EMAIL_DELETE_ALL)
1793                         {
1794                                 int itemCount;
1795                                 int groupCount = __pMailGroupedListView->GetGroupCount();
1796
1797                                 EmailApp::GetInstance()->ClearShowDeletePopupStatus();
1798
1799                                 __pDeleteConfirmationPopup->SetShowState(false);
1800                                 Invalidate(true);
1801
1802                                 for (int groupIndex = 0; groupIndex < groupCount; groupIndex++)
1803                                 {
1804                                         itemCount = __pMailGroupedListView->GetItemCountAt(groupIndex);
1805
1806                                         for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
1807                                         {
1808                                                 __pPresentationModel->AddSelectedMail(groupIndex, itemIndex);
1809                                         }
1810                                 }
1811
1812                                 if (__accountId == -1)
1813                                 {
1814                                         if (__mailboxType == EMAIL_MAILBOX_TYPE_TRASH)
1815                                         {
1816                                                 __pPresentationModel->DeleteMail(false, true);
1817                                         }
1818                                         else
1819                                         {
1820                                                 r = __pPresentationModel->MoveMail(EMAIL_MAILBOX_TYPE_TRASH);
1821                                         }
1822                                 }
1823                                 else
1824                                 {
1825                                         email_mailbox_type_e mailboxType = __pPresentationModel->GetMailboxType(__mailboxId);
1826
1827                                         if (mailboxType == EMAIL_MAILBOX_TYPE_TRASH)
1828                                         {
1829                                                 __pPresentationModel->DeleteMail(false);
1830                                         }
1831                                         else
1832                                         {
1833                                                 int mailboxId = EmailMailboxManager::GetInstance()->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_TRASH);
1834                                                 r = __pPresentationModel->MoveMail(mailboxId);
1835                                         }
1836                                 }
1837
1838                                 if (r == E_SUCCESS)
1839                                 {
1840                                         ShowPopUp(Utils::GetResourceString(L"IDS_EMAIL_POP_DELETING_ING"));
1841                                         __waitForDelete = true;
1842                                 }
1843                                 else
1844                                 {
1845                                         EmailApp::GetInstance()->SetMoveOrDeleteFailedPopupStatus(false);
1846                                         SetMoveOrDeleteFailedPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_FAILED"));
1847                                         __pMoveOrDeleteFailedPopup->SetShowState(true);
1848                                         __pMoveOrDeleteFailedPopup->Show();
1849                                         Invalidate(true);
1850                                 }
1851                         }
1852                         else if (mode == EMAIL_SELECTED_DELETE)
1853                         {
1854                                 EmailApp::GetInstance()->ClearShowDeletePopupStatus();
1855
1856                                 __pDeleteConfirmationPopup->SetShowState(false);
1857                                 Invalidate(true);
1858
1859                                 if (__accountId == -1)
1860                                 {
1861                                         if (__mailboxType == EMAIL_MAILBOX_TYPE_TRASH)
1862                                         {
1863                                                 __pPresentationModel->DeleteMail(false, true);
1864                                         }
1865                                         else
1866                                         {
1867                                                 r = __pPresentationModel->MoveMail(EMAIL_MAILBOX_TYPE_TRASH);
1868                                         }
1869                                 }
1870                                 else
1871                                 {
1872                                         email_mailbox_type_e mailboxType = __pPresentationModel->GetMailboxType(__mailboxId);
1873
1874                                         if (mailboxType == EMAIL_MAILBOX_TYPE_TRASH)
1875                                         {
1876                                                 __pPresentationModel->DeleteMail(false);
1877                                         }
1878                                         else
1879                                         {
1880                                                 int mailboxId = EmailMailboxManager::GetInstance()->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_TRASH);
1881                                                 r = __pPresentationModel->MoveMail(mailboxId);
1882                                         }
1883                                 }
1884
1885                                 if (r == E_SUCCESS)
1886                                 {
1887                                         ShowPopUp(Utils::GetResourceString(L"IDS_EMAIL_POP_DELETING_ING"));
1888                                         __waitForDelete = true;
1889                                 }
1890                                 else
1891                                 {
1892                                         EmailApp::GetInstance()->SetMoveOrDeleteFailedPopupStatus(false);
1893                                         SetMoveOrDeleteFailedPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_FAILED"));
1894                                         __pMoveOrDeleteFailedPopup->SetShowState(true);
1895                                         __pMoveOrDeleteFailedPopup->Show();
1896                                         UnCheckAllListviewItems();
1897                                         GoToNormalMode(true);
1898                                         Invalidate(true);
1899                                 }
1900                         }
1901                 }
1902         }
1903         else if (actionId == IDA_ATTACHMENT_DOWNLOAD_FAILED_OK)
1904         {
1905                 EmailApp::GetInstance()->SetDownloadFailedPopupStatus(false);
1906
1907                 __pAttachmentDownloadFailedPopup->SetShowState(false);
1908                 Invalidate(true);
1909         }
1910         else if (actionId == IDA_MOVE_OR_DELETE_FAILED_OK)
1911         {
1912                 EmailApp::GetInstance()->ClearMoveOrDeleteFailedPopupStatus();
1913
1914                 __pMoveOrDeleteFailedPopup->SetShowState(false);
1915                 Invalidate(true);
1916         }
1917
1918         AppLogDebug("EXIT");
1919 }
1920
1921 void
1922 MailListForm::InitSortByPopup(int count)
1923 {
1924         AppLogDebug("ENTER");
1925
1926         int xPos, yPos;
1927         Rectangle popupBounds;
1928
1929         email_mailbox_type_e mailboxType = __pPresentationModel->GetMailboxType(__mailboxId);
1930
1931         if (__pSortByPopup == null)
1932         {
1933                 CreateSortByPopup();
1934         }
1935
1936         if (mailboxType == EMAIL_MAILBOX_TYPE_SENTBOX || mailboxType == EMAIL_MAILBOX_TYPE_DRAFT)
1937         {
1938                 __pSortByListViewItemProvider->SetViewBySenderOrRecipient(false);
1939         }
1940         else
1941         {
1942                 __pSortByListViewItemProvider->SetViewBySenderOrRecipient(true);
1943         }
1944
1945         popupBounds = __pSortByPopup->GetClientAreaBounds();
1946
1947         xPos = (popupBounds.width-W_POPUP_CLOSE_BUTTON)/2;
1948         yPos = popupBounds.height - GENERIC_OFFSET_16 - H_POPUP_CLOSE_BUTTON;
1949
1950         __pSortByPopupCloseButton->SetPosition(xPos, yPos);
1951
1952         __pSortByListView->SetPosition(0, 0);
1953
1954         xPos = popupBounds.width;
1955         yPos = popupBounds.height - H_POPUP_CLOSE_BUTTON - (2*GENERIC_OFFSET_16);
1956         __pSortByListView->SetSize(xPos, yPos);
1957
1958         __pSortByListView->SetItemChecked(0, false);
1959         __pSortByListView->SetItemChecked(1, false);
1960         __pSortByListView->SetItemChecked(2, false);
1961         __pSortByListView->SetItemChecked(3, false);
1962
1963         __pSortByListView->UpdateList();
1964         __pSortByListView->SetItemChecked(__viewByType, true);
1965         __pSortByListView->Invalidate(true);
1966
1967         AppLogDebug("EXIT");
1968         return;
1969 }
1970
1971 void
1972 MailListForm::InitMarkAllAsPopup(void)
1973 {
1974         AppLogDebug("ENTER");
1975
1976         int xPos, yPos;
1977         Rectangle popupBounds;
1978
1979         if (__pMarkAllAsPopup == null)
1980         {
1981                 CreateMarkAllAsPopup();
1982         }
1983
1984         popupBounds = __pMarkAllAsPopup->GetClientAreaBounds();
1985         AppLogDebug("Got popup bounds:(%d),(%d),(%d),(%d)", popupBounds.x,popupBounds.y,popupBounds.width,popupBounds.height);
1986
1987         xPos = (popupBounds.width-W_POPUP_CLOSE_BUTTON)/2;
1988         yPos = popupBounds.height - GENERIC_OFFSET_16 - H_POPUP_CLOSE_BUTTON;
1989
1990         __pMarkAllAsPopupCloseButton->SetPosition(xPos, yPos);
1991         __pMarkAllAsListView->SetPosition(0, 0);
1992
1993         xPos = popupBounds.width;
1994         yPos = popupBounds.height - H_POPUP_CLOSE_BUTTON - (2*GENERIC_OFFSET_16);
1995         __pMarkAllAsListView->SetSize(xPos, yPos);
1996         __pMarkAllAsListView->UpdateList();
1997         __pMarkAllAsListView->Invalidate(true);
1998
1999         AppLogDebug("EXIT");
2000         return;
2001 }
2002
2003 void
2004 MailListForm::InitSetAllAsPopup(void)
2005 {
2006         AppLogDebug("ENTER");
2007
2008         int xPos, yPos;
2009         Rectangle popupBounds;
2010
2011         if (__pSetAllAsPopup == null)
2012         {
2013                 CreateSetAllAsPopup();
2014         }
2015
2016         popupBounds = __pSetAllAsPopup->GetClientAreaBounds();
2017         AppLogDebug("Got popup bounds:(%d),(%d),(%d),(%d)", popupBounds.x,popupBounds.y,popupBounds.width,popupBounds.height);
2018
2019         xPos = (popupBounds.width-W_POPUP_CLOSE_BUTTON)/2;
2020         yPos = popupBounds.height - GENERIC_OFFSET_16 - H_POPUP_CLOSE_BUTTON;
2021
2022         __pSetAllAsPopupCancelButton->SetPosition(xPos, yPos);
2023         __pSetAllAsListView->SetPosition(0, 0);
2024
2025         xPos = popupBounds.width;
2026         yPos = popupBounds.height - H_POPUP_CLOSE_BUTTON - (2*GENERIC_OFFSET_16);
2027         __pSetAllAsListView->SetSize(xPos, yPos);
2028         __pSetAllAsListView->UpdateList();
2029         __pSetAllAsListView->Invalidate(true);
2030
2031         AppLogDebug("EXIT");
2032         return;
2033 }
2034
2035 void
2036 MailListForm::OnSortTypeChanged(SortType viewByType)
2037 {
2038         AppLogDebug("ENTER");
2039
2040         __viewByType = viewByType;
2041         __pPresentationModel->SortBy(__viewByType);
2042         __pMailGroupedListView->UpdateList();
2043
2044         __pSortByPopup->SetShowState(false);
2045         Invalidate(true);
2046
2047         AppLogDebug("EXIT");
2048 }
2049
2050 void
2051 MailListForm::OnMarkAllAsOptionChanged(int selectedOption)
2052 {
2053         AppLogDebug("ENTER");
2054
2055         if (selectedOption == 0)
2056         {
2057                 __pPresentationModel->SetFlag(EMAIL_FLAGS_SEEN_FIELD, true, true);
2058         }
2059         else if (selectedOption == 1)
2060         {
2061                 __pPresentationModel->SetFlag(EMAIL_FLAGS_SEEN_FIELD, false, true);
2062         }
2063
2064         UnCheckAllListviewItems();
2065         GoToNormalMode(true);
2066         __pPresentationModel->ClearSelectedMailList();
2067         __pMarkAllAsPopup->SetShowState(false);
2068         Invalidate(true);
2069         AppLogDebug("EXIT");
2070 }
2071
2072 void
2073 MailListForm::OnSetAllAsOptionChanged(int selectedOption)
2074 {
2075         AppLogDebug("ENTER");
2076
2077         if (selectedOption == 0)
2078         {
2079                 __pPresentationModel->SetFlag(EMAIL_FLAGS_FLAGGED_FIELD, true, true);
2080         }
2081         else if (selectedOption == 1)
2082         {
2083                 __pPresentationModel->SetFlag(EMAIL_FLAGS_FLAGGED_FIELD, false, true);
2084         }
2085
2086         UnCheckAllListviewItems();
2087         GoToNormalMode(true);
2088         __pPresentationModel->ClearSelectedMailList();
2089         __pSetAllAsPopup->SetShowState(false);
2090         Invalidate(true);
2091         AppLogDebug("EXIT");
2092 }
2093
2094 void
2095 MailListForm::PopulateHeader()
2096 {
2097         Bitmap* pLogo = null;
2098         Header* pHeader = GetHeader();
2099
2100 //      pHeader->RemoveAllItems();
2101
2102         if (__accountId > 0)
2103         {
2104                 EmailAccount* pAccount = __pPresentationModel->GetAccountById(__accountId);
2105                 EmailMailbox* pMailbox = __pPresentationModel->GetMailboxById(__mailboxId);
2106
2107                 if (pAccount != null && pMailbox != null)
2108                 {
2109                         String headerLogoPath = L"header_images/";
2110                         headerLogoPath.Append(File::GetFileName(pAccount->GetLogoIconPath()));
2111                         pLogo = App::GetInstance()->GetAppResource()->GetBitmapN(headerLogoPath);
2112                         pHeader->SetTitleIcon(pLogo);
2113                         pHeader->SetTitleText(pAccount->GetAccountName());
2114                         pHeader->SetDescriptionText(pMailbox->GetMailboxAlias());
2115                         delete pLogo;
2116                 }
2117         }
2118         else
2119         {
2120                 pHeader->SetTitleIcon(__pHeaderAllAccountsIcon);
2121                 pHeader->SetTitleText(Utils::GetResourceString(L"IDS_EMAIL_BODY_ALL_ACCOUNTS"));
2122
2123                 switch(__mailboxType)
2124                 {
2125                 case EMAIL_MAILBOX_TYPE_INBOX:
2126                 {
2127                         pHeader->SetDescriptionText(Utils::GetResourceString(L"IDS_EMAIL_BODY_INBOX"));
2128                 }
2129                 break;
2130
2131                 case EMAIL_MAILBOX_TYPE_SENTBOX:
2132                 {
2133                         pHeader->SetDescriptionText(Utils::GetResourceString(L"IDS_EMAIL_BODY_SENTBOX"));
2134                 }
2135                 break;
2136
2137                 case EMAIL_MAILBOX_TYPE_DRAFT:
2138                 {
2139                         pHeader->SetDescriptionText(Utils::GetResourceString(L"IDS_EMAIL_BODY_DRAFTS"));
2140                 }
2141                 break;
2142
2143                 case EMAIL_MAILBOX_TYPE_TRASH:
2144                 {
2145                         pHeader->SetDescriptionText(Utils::GetResourceString(L"IDS_EMAIL_BODY_TRASH"));
2146                 }
2147                 break;
2148
2149                 case EMAIL_MAILBOX_TYPE_SPAMBOX:
2150                 {
2151                         pHeader->SetDescriptionText(Utils::GetResourceString(L"IDS_EMAIL_BODY_SPAMBOX"));
2152                 }
2153                 break;
2154
2155                 case EMAIL_MAILBOX_TYPE_OUTBOX:
2156                 {
2157                         pHeader->SetDescriptionText(Utils::GetResourceString(L"IDS_EMAIL_HEADER_OUTBOX"));
2158                 }
2159                 break;
2160
2161                 case EMAIL_MAILBOX_TYPE_FLAGGED:
2162                 {
2163                         pHeader->SetDescriptionText(L"Starred");
2164                 }
2165                 break;
2166
2167                 default:
2168                         break;
2169                 }
2170         }
2171
2172         pHeader->Invalidate(true);
2173         return;
2174 }
2175
2176 BasePresentationModel*
2177 MailListForm::GetPresentationModelForMailboxType(int mailboxId)
2178 {
2179         BasePresentationModel* pModel = InboxPresentationModel::GetInstance();
2180
2181         email_mailbox_type_e mailboxType = pModel->GetMailboxType(mailboxId);
2182
2183         switch (mailboxType)
2184         {
2185
2186         case EMAIL_MAILBOX_TYPE_DRAFT:
2187                 pModel = DraftListPresentationModel::GetInstance();
2188                 break;
2189
2190         case EMAIL_MAILBOX_TYPE_OUTBOX:
2191                 pModel = OutboxPresentationModel::GetInstance();
2192                 break;
2193
2194         case EMAIL_MAILBOX_TYPE_SENTBOX:
2195                 pModel = SentboxPresentationModel::GetInstance();
2196                 break;
2197
2198         case EMAIL_MAILBOX_TYPE_SPAMBOX:
2199                 pModel = SpamPresentationModel::GetInstance();
2200                 break;
2201
2202         case EMAIL_MAILBOX_TYPE_TRASH:
2203                 pModel = TrashPresentationModel::GetInstance();
2204                 break;
2205
2206         default:
2207                 break;
2208         }
2209
2210         return pModel;
2211 }
2212
2213 void
2214 MailListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
2215 {
2216         AppLogDebug("ENTER");
2217
2218         if (pArgs != null)
2219         {
2220                 StateInfo* pStateInfo = static_cast<StateInfo*>(pArgs->GetAt(0));
2221
2222                 __accountId = pStateInfo->accountId;
2223                 __mailboxId = pStateInfo->mailboxId;
2224                 __pPresentationModel = pStateInfo->pPresentationModel;
2225                 __mailboxType = pStateInfo->mailboxType;
2226
2227                 if (__mailboxType != EMAIL_MAILBOX_TYPE_USER_DEFINED && __accountId != -1)
2228                 {
2229                         EmailMailbox* pTmpMailbox = static_cast<EmailMailbox*>(__pPresentationModel->GetMailboxByType(__accountId, __mailboxType));
2230
2231                         if (pTmpMailbox != null && __mailboxId != pTmpMailbox->GetMailboxId())
2232                         {
2233                                 __mailboxId = pTmpMailbox->GetMailboxId();
2234                         }
2235                 }
2236         
2237                 pArgs->RemoveAll(true);
2238                 delete pArgs;
2239         }
2240         else
2241         {
2242                 __accountId = __pPresentationModel->GetDefaultAccountId();
2243                 __mailboxId = __pPresentationModel->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_INBOX);
2244                 __pPresentationModel = InboxPresentationModel::GetInstance();
2245                 __mailboxType = EMAIL_MAILBOX_TYPE_INBOX;
2246         }
2247
2248         if (__accountId != -1)
2249         {
2250                 if (__mailboxType == EMAIL_MAILBOX_TYPE_USER_DEFINED || __mailboxType == EMAIL_MAILBOX_TYPE_ALL_EMAILS || __mailboxType == EMAIL_MAILBOX_TYPE_SEARCH_RESULT || __mailboxType == EMAIL_MAILBOX_TYPE_FLAGGED)
2251                 {
2252                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2253                 }
2254                 else
2255                 {
2256                         __pPresentationModel->FetchData(__accountId);
2257                 }
2258         }
2259         else
2260         {
2261                 __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2262         }
2263
2264         switch (__mailboxType)
2265         {
2266         case EMAIL_MAILBOX_TYPE_USER_DEFINED: // fall through
2267         case EMAIL_MAILBOX_TYPE_ALL_EMAILS:   // fall through
2268         case EMAIL_MAILBOX_TYPE_SEARCH_RESULT:
2269                 __mailboxViewType = ALL_FOLDERS_VIEW;
2270                 break;
2271
2272         case EMAIL_MAILBOX_TYPE_INBOX:
2273                 __mailboxViewType = INBOX_VIEW;
2274                 break;
2275
2276         case EMAIL_MAILBOX_TYPE_DRAFT:
2277                 __mailboxViewType = DRAFTS_VIEW;
2278                 break;
2279
2280         case EMAIL_MAILBOX_TYPE_SENTBOX:
2281                 __mailboxViewType = SENTBOX_VIEW;
2282                 break;
2283
2284 //      case EMAIL_MAILBOX_TYPE_FLAGGED:
2285 //              __mailboxViewType = FAVORITES_VIEW;
2286 //              break;
2287
2288         default:
2289                 break;
2290         }
2291
2292         PopulateHeader();
2293         __viewByType = __pPresentationModel->GetSortType();
2294         __pBaseListViewItemProvider->SetPresentationModel(__pPresentationModel);
2295         __pPresentationModel->SortBy(__pPresentationModel->GetSortType());
2296
2297         __pMailGroupedListView->SetItemProvider(*__pBaseListViewItemProvider);
2298         __pMailGroupedListView->UpdateList();
2299
2300         __pAccountsListView->SetItemProvider(*this);
2301
2302         __waitForMove = false;
2303         __waitForDelete = false;
2304
2305         CheckSelectedListviewItems();
2306
2307         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
2308         {
2309                 String text;
2310                 text.Append(Utils::GetResourceString(L"IDS_COM_OPT_SELECTED"));
2311                 text.Append(L"\x200E");
2312                 text.Append(L" (");
2313                 text.Append(__pPresentationModel->GetNumberOfSelectedItems());
2314                 text.Append(L")");
2315                 text.Append(L"\x200E");
2316                 __pSelectedLabel->SetText(text);
2317                 __pSelectedLabel->Invalidate(true);
2318
2319                 if (__mode != EDIT_MODE)
2320                 {
2321                         GoToEditMode();
2322                         SetFocus();
2323                 }
2324         }
2325         else
2326         {
2327                 if (__mode != NORMAL_MODE)
2328                 {
2329                         GoToNormalMode(false);
2330                         SetFocus();
2331                 }
2332
2333                 UnCheckAllListviewItems();
2334         }
2335
2336         int mailId;
2337         DeletionMode mode;
2338
2339         if (EmailApp::GetInstance()->GetShowDeletePopupStatus(mailId, mode) == true)
2340         {
2341                 bool hideDelPopup = false;
2342
2343                 if (mode == EMAIL_DELETE_ALL)
2344                 {
2345                         if (__pPresentationModel->GetItemCount(0) > 0)
2346                         {
2347                                 SetDeleteConfirmationPopupTitle(Utils::GetResourceString(L"IDS_EMAIL_POP_DELETE_ALL_Q"));
2348                                 __pDeleteConfirmationPopup->SetShowState(true);
2349                                 __pDeleteConfirmationPopup->Show();
2350                         }
2351                         else
2352                         {
2353                                 hideDelPopup = true;
2354                         }
2355                 }
2356                 else if (mode == EMAIL_SELECTED_DELETE)
2357                 {
2358                         if (__pPresentationModel->CheckIfSelectedMailExists() == true)
2359                         {
2360                                 SetDeleteConfirmationPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_Q"));
2361                                 __pDeleteConfirmationPopup->SetShowState(true);
2362                                 __pDeleteConfirmationPopup->Show();
2363                         }
2364                         else
2365                         {
2366                                 hideDelPopup = true;
2367                         }
2368                 }
2369                 else
2370                 {
2371                         int groupIndex, itemIndex;
2372                         __pPresentationModel->GetMailIndex(mailId, groupIndex, itemIndex);
2373
2374                         if (groupIndex != -1 && itemIndex != -1 && groupIndex <= __pPresentationModel->GetGroupCount()-1 && itemIndex <= __pPresentationModel->GetItemCount(groupIndex)-1)
2375                         {
2376                                 SetDeleteConfirmationPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_Q"));
2377
2378                                 __pDeleteConfirmationPopup->SetShowState(true);
2379                                 __pDeleteConfirmationPopup->Show();
2380                         }
2381                         else
2382                         {
2383                                 hideDelPopup = true;
2384                         }
2385                 }
2386
2387                 if (hideDelPopup == true)
2388                 {
2389                         EmailApp::GetInstance()->ClearShowDeletePopupStatus();
2390                 }
2391         }
2392
2393         int downloadMailId;
2394         DownloadInitiatorMode downloadMode;
2395
2396         if (EmailApp::GetInstance()->GetDownloadAttachmentPopupStatus(downloadMailId, downloadMode) == true)
2397         {
2398                 if (downloadMode == EMAIL_SWIPE_FORWARD)
2399                 {
2400                         int groupIndex = -1;
2401                         int itemIndex = -1;
2402                         EmailMessageItem* pDetailedMail = __pPresentationModel->GetCompleteMailDataN(downloadMailId);
2403
2404                         if (pDetailedMail != null)
2405                         {
2406                                 DownloadAllAttachments(pDetailedMail, EMAIL_SWIPE_FORWARD);
2407                                 __pPresentationModel->GetMailIndex(downloadMailId, groupIndex, itemIndex);
2408                                 __futureAction = EmailTypesNS::FORWARD_AFTER_DOWNLOAD;
2409                                 __groupIndex = groupIndex;
2410                                 __itemIndex = itemIndex;
2411                         }
2412                 }
2413                 else if (downloadMode == EMAIL_DRAFT_DOWNLOAD)
2414                 {
2415                         int groupIndex = -1;
2416                         int itemIndex = -1;
2417                         EmailMessageItem* pDetailedMail = __pPresentationModel->GetCompleteMailDataN(downloadMailId);
2418
2419                         if (pDetailedMail != null)
2420                         {
2421                                 DownloadAllAttachments(pDetailedMail, EMAIL_DRAFT_DOWNLOAD);
2422                                 __pPresentationModel->GetMailIndex(downloadMailId, groupIndex, itemIndex);
2423                                 __futureAction = EmailTypesNS::COMPOSE_AFTER_DOWNLOAD;
2424                                 __groupIndex = groupIndex;
2425                                 __itemIndex = itemIndex;
2426                         }
2427                 }
2428         }
2429
2430         if (EmailApp::GetInstance()->GetDownloadFailedPopupStatus() == true)
2431         {
2432                 EmailApp::GetInstance()->ClearDownloadAttachmentPopupStatus();
2433
2434                 if (__pAttachmentDownloadFailedPopup == null)
2435                 {
2436                         InitAttachmentDownloadFailedPopup();
2437                 }
2438
2439                 __pAttachmentDownloadFailedPopup->SetShowState(true);
2440                 __pAttachmentDownloadFailedPopup->Show();
2441         }
2442
2443         bool isMoveFailed;
2444
2445         if (EmailApp::GetInstance()->GetMoveOrDeleteFailedPopupStatus(isMoveFailed) == true)
2446         {
2447                 if (isMoveFailed)
2448                 {
2449                         SetMoveOrDeleteFailedPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_MOVING_FAILED"));
2450                 }
2451                 else
2452                 {
2453                         SetMoveOrDeleteFailedPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_FAILED"));
2454                 }
2455
2456                 __pMoveOrDeleteFailedPopup->SetShowState(true);
2457                 __pMoveOrDeleteFailedPopup->Show();
2458         }
2459
2460         AppLogDebug("EXIT");
2461         return;
2462 }
2463
2464 void
2465 MailListForm::ShowPopUp(const String& popupTitle)
2466 {
2467         AppLogDebug("ENTER");
2468
2469         __pProgressPopup->SetTitleText(popupTitle);
2470         __pProgressPopup->SetShowState(true);
2471         __pProgressPopup->Show();
2472
2473         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
2474 }
2475
2476 void
2477 MailListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
2478 {
2479         AppLogDebug("ENTER, currentSceneId:(%ls), nextSceneId:(%ls)", currentSceneId.GetPointer(), nextSceneId.GetPointer());
2480
2481         UnCheckAllListviewItems();
2482
2483         if (__pDeleteConfirmationPopup != null)
2484         {
2485                 __pDeleteConfirmationPopup->RemoveAllControls();
2486                 delete __pDeleteConfirmationPopup;
2487                 __pDeleteConfirmationPopup = null;
2488         }
2489
2490         if (__pAttachmentDownloadFailedPopup != null)
2491         {
2492                 __pAttachmentDownloadFailedPopup->RemoveAllControls();
2493                 delete __pAttachmentDownloadFailedPopup;
2494                 __pAttachmentDownloadFailedPopup = null;
2495         }
2496
2497         if (__pDownloadAttachmentsPopup != null)
2498         {
2499                 delete __pDownloadAttachmentsPopup;
2500                 __pDownloadAttachmentsPopup = null;
2501         }
2502
2503         if (__pMoveOrDeleteFailedPopup != null)
2504         {
2505                 __pMoveOrDeleteFailedPopup->RemoveAllControls();
2506                 delete __pMoveOrDeleteFailedPopup;
2507                 __pMoveOrDeleteFailedPopup = null;
2508         }
2509
2510         if (__pSortByPopup != null)
2511         {
2512                 __pSortByPopup->RemoveAllControls();
2513                 delete __pSortByPopup;
2514                 __pSortByPopup = null;
2515         }
2516
2517         if (__pSortByListViewItemProvider != null)
2518         {
2519                 delete __pSortByListViewItemProvider;
2520                 __pSortByListViewItemProvider = null;
2521         }
2522
2523         if (__pMarkAllAsPopup != null)
2524         {
2525                 __pMarkAllAsPopup->RemoveAllControls();
2526                 delete __pMarkAllAsPopup;
2527                 __pMarkAllAsPopup = null;
2528         }
2529
2530         if (__pMarkAllAsListViewItemProvider != null)
2531         {
2532                 delete __pMarkAllAsListViewItemProvider;
2533                 __pMarkAllAsListViewItemProvider = null;
2534         }
2535
2536         if (__pSetAllAsPopup != null)
2537         {
2538                 __pSetAllAsPopup->RemoveAllControls();
2539                 delete __pSetAllAsPopup;
2540                 __pSetAllAsPopup = null;
2541         }
2542
2543         if (__pSetAllAsListViewItemProvider != null)
2544         {
2545                 delete __pSetAllAsListViewItemProvider;
2546                 __pSetAllAsListViewItemProvider = null;
2547         }
2548
2549         /*if (__pMoreOptionMenu != null)
2550         {
2551                 __pMoreOptionMenu->RemoveAllItems();
2552                 delete __pMoreOptionMenu;
2553                 __pMoreOptionMenu = null;
2554         }*/
2555
2556         AppLogDebug("EXIT");
2557 }
2558
2559 void
2560 MailListForm::OnUserEventReceivedN(RequestId requestId, IList *pArgs)
2561 {
2562         AppLogDebug("ENTER, requestId:(%d), pArgs:(%x)", requestId, pArgs);
2563         AppLogDebugIf(pArgs != null, "pArgs count:(%d)", pArgs->GetCount());
2564
2565         result r = E_SUCCESS;
2566
2567         if (requestId == IDA_NOTI_MAIL_ADD || requestId == IDA_NOTI_MAIL_UPDATE)
2568         {
2569                 if (pArgs != null && pArgs->GetCount() >= 3)
2570                 {
2571                         if (requestId == IDA_NOTI_MAIL_UPDATE)
2572                         {
2573                                 int groupIndex=0, itemIndex=0;
2574                                 int mailId = static_cast<Integer*>(pArgs->GetAt(1))->ToInt();
2575                                 AppLogDebug("Got mail Id:(%d)", mailId);
2576
2577                                 __pPresentationModel->GetMailIndex(mailId, groupIndex, itemIndex);
2578                                 AppLogDebug("Got groupIndex:(%d), itemIndex:(%d)", groupIndex, itemIndex);
2579
2580                                 EmailMessageListItem* pMsg = static_cast<EmailMessageListItem*>(__pPresentationModel->GetMailData(groupIndex, itemIndex));
2581                                 AppLogDebugIf(pMsg == null, "pMsg was null");
2582
2583                                 if (pMsg != null)
2584                                 {
2585                                         int mailIdToBeAdded = 0;
2586                                         if (__pPresentationModel->IsMailSelected(pMsg))
2587                                         {
2588                                                 mailIdToBeAdded = pMsg->GetMailId();
2589                                                 __pPresentationModel->RemoveMailFromSelectedMailList(pMsg);
2590                                         }
2591
2592                                         if (__accountId == -1)
2593                                         {
2594                                                 r = __pPresentationModel->GetData()->Remove(*pMsg);
2595                                         }
2596                                         else
2597                                         {
2598                                                 if (__mailboxType == EMAIL_MAILBOX_TYPE_USER_DEFINED || __mailboxType == EMAIL_MAILBOX_TYPE_ALL_EMAILS || __mailboxType == EMAIL_MAILBOX_TYPE_SEARCH_RESULT || __mailboxType == EMAIL_MAILBOX_TYPE_FLAGGED)
2599                                                 {
2600                                                         r = __pPresentationModel->GetData()->Remove(*pMsg);
2601                                                 }
2602                                                 else
2603                                                 {
2604                                                         r = __pPresentationModel->GetData()->Remove(*pMsg, true);
2605                                                 }
2606                                         }
2607                                         AppLogDebug("Result r:(%s)", GetErrorMessage(r));
2608
2609                                         __pPresentationModel->UpdateUnreadCount(__accountId);
2610 //                                      __pPresentationModel->FetchData(__accountId, true);
2611
2612                                         if (__accountId == -1)
2613                                         {
2614                                                 __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2615                                         }
2616                                         else
2617                                         {
2618                                                 if (__mailboxType == EMAIL_MAILBOX_TYPE_USER_DEFINED || __mailboxType == EMAIL_MAILBOX_TYPE_ALL_EMAILS || __mailboxType == EMAIL_MAILBOX_TYPE_SEARCH_RESULT || __mailboxType == EMAIL_MAILBOX_TYPE_FLAGGED)
2619                                                 {
2620                                                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2621                                                 }
2622                                                 else
2623                                                 {
2624                                                         __pPresentationModel->FetchData(__accountId, true);
2625                                                 }
2626                                         }
2627
2628                                         __pPresentationModel->SortBy(__viewByType);
2629                                         __pMailGroupedListView->UpdateList();
2630
2631                                         if (mailIdToBeAdded > 0)
2632                                         {
2633                                                 EmailMessageListItem* pTmpMsg = __pPresentationModel->GetMailData(mailIdToBeAdded);
2634
2635                                                 if (pTmpMsg != null)
2636                                                 {
2637                                                         __pPresentationModel->AddMailToSelectedMailList(pTmpMsg);
2638                                                 }
2639                                         }
2640
2641                                         Invalidate(true);
2642                                 }
2643                         }
2644                         else if (requestId == IDA_NOTI_MAIL_ADD)
2645                         {
2646                                 int mailboxId = static_cast<Integer*>(pArgs->GetAt(2))->ToInt();
2647                                 AppLogDebug("Current mailboxId:(%d), got mailboxId:(%d)", __mailboxId, mailboxId);
2648
2649                                 if (mailboxId == __mailboxId)
2650                                 {
2651                                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
2652                                         {
2653                                                 UnCheckAllListviewItems();
2654                                         }
2655
2656                                         __pPresentationModel->UpdateUnreadCount(__accountId);
2657 //                                      __pPresentationModel->FetchData(__accountId, true);
2658
2659                                         if (__accountId == -1)
2660                                         {
2661                                                 __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2662                                         }
2663                                         else
2664                                         {
2665                                                 if (__mailboxType == EMAIL_MAILBOX_TYPE_USER_DEFINED || __mailboxType == EMAIL_MAILBOX_TYPE_ALL_EMAILS || __mailboxType == EMAIL_MAILBOX_TYPE_SEARCH_RESULT || __mailboxType == EMAIL_MAILBOX_TYPE_FLAGGED)
2666                                                 {
2667                                                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2668                                                 }
2669                                                 else
2670                                                 {
2671                                                         __pPresentationModel->FetchData(__accountId, true);
2672                                                 }
2673                                         }
2674
2675                                         __pPresentationModel->SortBy(__viewByType);
2676                                         __pMailGroupedListView->UpdateList();
2677
2678                                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
2679                                         {
2680                                                 CheckSelectedListviewItems();
2681                                         }
2682
2683                                         Invalidate(true);
2684                                 }
2685                         }
2686
2687                         pArgs->RemoveAll(true);
2688                         delete pArgs;
2689                 }
2690         }
2691         else if (requestId == IDA_NOTI_MAIL_FIELD_UPDATE && pArgs != null)
2692         {
2693                 int mailId;
2694                 int groupIndex=0, itemIndex=0;
2695
2696                 __pPresentationModel->UpdateUnreadCount(__accountId);
2697
2698                 for (int i=0; i<pArgs->GetCount(); i++)
2699                 {
2700                         mailId = static_cast<Integer*>(pArgs->GetAt(i))->ToInt();
2701                         __pPresentationModel->GetMailIndex(mailId, groupIndex, itemIndex);
2702                         __pMailGroupedListView->RefreshList(groupIndex, itemIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
2703                 }
2704
2705                 if (__mailboxType == EMAIL_MAILBOX_TYPE_OUTBOX)
2706                 {
2707                         UnCheckAllListviewItems();
2708
2709                         if (__accountId == -1)
2710                         {
2711                                 __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2712                         }
2713                         else
2714                         {
2715                                 if (__mailboxType == EMAIL_MAILBOX_TYPE_USER_DEFINED || __mailboxType == EMAIL_MAILBOX_TYPE_ALL_EMAILS || __mailboxType == EMAIL_MAILBOX_TYPE_SEARCH_RESULT || __mailboxType == EMAIL_MAILBOX_TYPE_FLAGGED)
2716                                 {
2717                                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2718                                 }
2719                                 else
2720                                 {
2721                                         __pPresentationModel->FetchData(__accountId);
2722                                 }
2723                         }
2724                 }
2725
2726                 if (__viewByType == SORT_BY_UNREAD || __viewByType == SORT_BY_IMPORTANT)
2727                 {
2728                         __pPresentationModel->SortBy(__viewByType);
2729                         __pMailGroupedListView->UpdateList();
2730                 }
2731
2732                 if (__mailboxType == EMAIL_MAILBOX_TYPE_OUTBOX)
2733                 {
2734                         CheckSelectedListviewItems();
2735
2736                         if (__pPresentationModel->GetNumberOfSelectedItems() > 0)
2737                         {
2738                                 String text;
2739
2740                                 if (__mode != EDIT_MODE)
2741                                 {
2742                                         GoToEditMode();
2743                                 }
2744
2745                                 text.Append(Utils::GetResourceString(L"IDS_COM_OPT_SELECTED"));
2746                                 text.Append(L"\x200E");
2747                                 text.Append(L" (");
2748                                 text.Append(__pPresentationModel->GetNumberOfSelectedItems());
2749                                 text.Append(L")");
2750                                 text.Append(L"\x200E");
2751                                 __pSelectedLabel->SetText(text);
2752                                 __pSelectedLabel->Invalidate(true);
2753                         }
2754                         else
2755                         {
2756                                 if (__mode == EDIT_MODE && __pMoreOptionMenu != null && __pMoreOptionMenu->GetShowState() == true)
2757                                 {
2758                                         __pMoreOptionMenu->SetShowState(false);
2759                                         __pMoreOptionMenu->Invalidate(true);
2760                                 }
2761                                 else if (__mode == NORMAL_MODE && __pMoreOptionMenu != null && __pMoreOptionMenu->GetShowState() == true && __pPresentationModel->GetGroupCount() == 0)
2762                                 {
2763                                         __pMoreOptionMenu->SetShowState(false);
2764                                         PopulateMoreOptionMenu(__mode, __pPresentationModel->GetSelectionMode(), __pPresentationModel->GetFavouriteSelectionMode());
2765                                         __pMoreOptionMenu->SetShowState(true);
2766                                         __pMoreOptionMenu->Show();
2767                                 }
2768
2769                                 if (__mode == EDIT_MODE)
2770                                 {
2771                                         GoToNormalMode(true);
2772                                 }
2773
2774                                 if (__pDeleteConfirmationPopup != null && __pDeleteConfirmationPopup->GetShowState() == true)
2775                                 {
2776                                         EmailApp::GetInstance()->ClearShowDeletePopupStatus();
2777
2778                                         __pDeleteConfirmationPopup->SetShowState(false);
2779                                         Invalidate(true);
2780                                 }
2781                         }
2782                 }
2783
2784                 pArgs->RemoveAll(true);
2785                 delete pArgs;
2786                 Invalidate(true);
2787         }
2788         else if (requestId == IDA_NOTI_MAIL_MOVE_FINISHED || requestId == IDA_NOTI_DELETE_FINISHED)
2789         {
2790                 __pPresentationModel->UpdateUnreadCount(__accountId);
2791
2792                 if (__accountId == -1)
2793                 {
2794                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2795                 }
2796                 else
2797                 {
2798                         if (__mailboxType == EMAIL_MAILBOX_TYPE_USER_DEFINED || __mailboxType == EMAIL_MAILBOX_TYPE_ALL_EMAILS || __mailboxType == EMAIL_MAILBOX_TYPE_SEARCH_RESULT || __mailboxType == EMAIL_MAILBOX_TYPE_FLAGGED)
2799                         {
2800                                 __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType);
2801                         }
2802                         else
2803                         {
2804                                 __pPresentationModel->FetchData(__accountId);
2805                         }
2806                 }
2807
2808                 __pPresentationModel->SortBy(__viewByType);
2809
2810                 if (__waitForDelete == true || __waitForMove == true)
2811                 {
2812                         if (__waitForDelete == true)
2813                         {
2814                                 __waitForDelete = false;
2815                         }
2816
2817                         if (__waitForMove == true)
2818                         {
2819                                 __waitForMove = false;
2820                         }
2821
2822                         UnCheckAllListviewItems();
2823
2824                         HidePopUp();
2825                         __pPresentationModel->ClearSelectedMailList();
2826
2827                         if (__mode != NORMAL_MODE)
2828                         {
2829                                 GoToNormalMode(true);
2830                         }
2831                 }
2832
2833                 if (__pPresentationModel->GetNumberOfSelectedItems() == 0)
2834                 {
2835                         UnCheckAllListviewItems();
2836
2837                         HidePopUp();
2838
2839                         if (__mode != NORMAL_MODE)
2840                         {
2841                                 GoToNormalMode(true);
2842                         }
2843                 }
2844
2845                 __pMailGroupedListView->UpdateList();
2846         }
2847         else if (requestId == IDA_NOTI_MAIL_MOVE_FAIL)
2848         {
2849                 if (__waitForDelete == true || __waitForMove == true)
2850                 {
2851                         if (__waitForDelete == true)
2852                         {
2853                                 __waitForDelete = false;
2854                                 EmailApp::GetInstance()->SetMoveOrDeleteFailedPopupStatus(false);
2855                                 SetMoveOrDeleteFailedPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_DELETE_FAILED"));
2856                         }
2857
2858                         if (__waitForMove == true)
2859                         {
2860                                 __waitForMove = false;
2861                                 EmailApp::GetInstance()->SetMoveOrDeleteFailedPopupStatus(true);
2862                                 SetMoveOrDeleteFailedPopupTitle(Utils::GetResourceString(L"IDS_COM_POP_MOVING_FAILED"));
2863                         }
2864
2865                         HidePopUp();
2866
2867                         __pMoveOrDeleteFailedPopup->SetShowState(true);
2868                         __pMoveOrDeleteFailedPopup->Show();
2869                         Invalidate(true);
2870                 }
2871         }
2872         else if (requestId == IDA_NOTI_DOWNLOAD_FINISH)
2873         {
2874                 __pPresentationModel->UpdateUnreadCount(__accountId);
2875                 __pPresentationModel->FetchData(__accountId, true);
2876                 __pPresentationModel->SortBy(__viewByType);
2877                 __pMailGroupedListView->UpdateList();
2878         }
2879         else if ((requestId == IDA_NOTI_DOWNLOAD_ATTACH_START ||
2880                         requestId == IDA_NOTI_DOWNLOAD_ATTACH_FINISH ||
2881                         requestId == IDA_NOTI_DOWNLOAD_ATTACH_FAIL) && pArgs != null)
2882         {
2883                 if (__downloadAttachments > 0)
2884                 {
2885                         if (requestId == IDA_NOTI_DOWNLOAD_ATTACH_FAIL)
2886                         {
2887                                 if (__userCancelledAttachmentDownload == false)
2888                                 {
2889                                         EmailApp::GetInstance()->ClearDownloadAttachmentPopupStatus();
2890                                         EmailApp::GetInstance()->SetDownloadFailedPopupStatus(true);
2891
2892                                         if (__pAttachmentDownloadFailedPopup == null)
2893                                         {
2894                                                 InitAttachmentDownloadFailedPopup();
2895                                         }
2896
2897                                         __pAttachmentDownloadFailedPopup->SetShowState(true);
2898                                         __pAttachmentDownloadFailedPopup->Show();
2899                                 }
2900
2901                                 OnProgressPopupCanceled();
2902                                 __userCancelledAttachmentDownload = false;
2903                         }
2904                         else
2905                         {
2906                                 if (requestId == IDA_NOTI_DOWNLOAD_ATTACH_FINISH)
2907                                 {
2908                                         __downloadAttachments--;
2909                                         AppLogDebug("Decrementing download attachment count to:(%d)", __downloadAttachments);
2910                                 }
2911
2912                                 if (__downloadAttachments == 0)
2913                                 {
2914                                         EmailApp::GetInstance()->ClearDownloadAttachmentPopupStatus();
2915
2916                                         if (__futureAction == EmailTypesNS::FORWARD_AFTER_DOWNLOAD)
2917                                         {
2918                                                 OnGroupedListViewContextItemStateChanged(*__pMailGroupedListView, __groupIndex, __itemIndex, IDA_INBOX_FORM_FORWARD_BUTTON, LIST_CONTEXT_ITEM_STATUS_SELECTED);
2919                                         }
2920                                         else if (__futureAction == EmailTypesNS::COMPOSE_AFTER_DOWNLOAD)
2921                                         {
2922                                                 OnGroupedListViewItemStateChanged(*__pMailGroupedListView, __groupIndex, __itemIndex, IDA_BASE_LISTVIEW_ITEM_PROVIDER_EMPTY_ELEMENT, LIST_ITEM_STATUS_SELECTED);
2923                                         }
2924
2925                                         OnProgressPopupCanceled();
2926                                 }
2927                         }
2928                 }
2929         }
2930         else if (requestId == IDA_INBOX_FORM_FOOTER_DELETE_BUTTON)
2931         {
2932                 OnActionPerformed(*(GetFooter()), IDA_INBOX_FORM_FOOTER_DELETE_BUTTON);
2933         }
2934         else if (requestId == IDA_INBOX_FORM_CONTEXT_MENU_DELETE_ALL)
2935         {
2936                 OnActionPerformed(*(GetFooter()), IDA_INBOX_FORM_CONTEXT_MENU_DELETE_ALL);
2937         }
2938
2939         AppLogDebug("EXIT");
2940         return;
2941 }
2942
2943 void
2944 MailListForm::HidePopUp(void)
2945 {
2946         AppLogDebug("ENTER");
2947
2948         if (__pProgressPopup != null)
2949         {
2950                 __pProgressPopup->SetShowState(false);
2951         }
2952
2953         Invalidate(true);
2954
2955         AppLogDebug("EXIT");
2956 }
2957
2958 void
2959 MailListForm::PopulateMoreOptionMenu(Mode mode, SelectionMode selectionMode, FavouriteSelectionMode favouriteSelectionMode)
2960 {
2961         AppLogDebug("ENTER");
2962
2963         __pMoreOptionMenu->RemoveAllItems();
2964
2965         switch(mode)
2966         {
2967         case NORMAL_MODE:
2968
2969                 __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_VIEW"), IDA_INBOX_FORM_CONTEXT_MENU_SORT_BY, *__pSortByIcon);
2970
2971                 if (__pPresentationModel->GetGroupCount() != 0)
2972                 {
2973                         __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_DELETE_ALL"), IDA_INBOX_FORM_CONTEXT_MENU_DELETE_ALL, *__pDeleteAllIcon);
2974                 }
2975
2976                 __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_MA_HEADER_ADD_ACCOUNT"), IDA_INBOX_FORM_CONTEXT_MENU_ADD_ACCOUNT, *__pAddAccountIcon);
2977                 __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT2_SETTINGS"), IDA_INBOX_FORM_CONTEXT_MENU_SETTINGS, *__pSettingsIcon);
2978                 break;
2979
2980         case EDIT_MODE:
2981                 if (selectionMode == SELECTION_READ)
2982                 {
2983                         __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_MARK_AS_UNREAD"), IDA_INBOX_FORM_CONTEXT_MENU_MARK_UNREAD, *__pMarkReadUnreadIcon);
2984                 }
2985                 else if (selectionMode == SELECTION_UNREAD)
2986                 {
2987                         __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_MARK_AS_READ"), IDA_INBOX_FORM_CONTEXT_MENU_MARK_READ, *__pMarkReadUnreadIcon);
2988                 }
2989                 else if (selectionMode == SELECTION_MIXED)
2990                 {
2991                         __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_MARK_ALL_AS_ABB"), IDA_INBOX_FORM_CONTEXT_MENU_MARK_ALL_AS, *__pMarkReadUnreadIcon);
2992                 }
2993
2994                 if (__mailboxType != EMAIL_MAILBOX_TYPE_OUTBOX)
2995                 {
2996                         if (favouriteSelectionMode == FAVOURITE_SELECTION_FAVOURITE)
2997                         {
2998                                 __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_UNMARK_AS_FAVOURITES_ABB1"), IDA_INBOX_FORM_CONTEXT_MENU_SET_UNFAVOURITES, *__pFavouriteIcon);
2999                         }
3000                         else if (favouriteSelectionMode == FAVOURITE_SELECTION_UNFAVOURITE)
3001                         {
3002                                 __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_SET_AS_FAVOURITES_ABB"), IDA_INBOX_FORM_CONTEXT_MENU_SET_FAVOURITES, *__pFavouriteIcon);
3003                         }
3004                         else if (favouriteSelectionMode == FAVOURITE_SELECTION_MIXED)
3005                         {
3006                                 __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_SET_ALL_AS_ABB"), IDA_INBOX_FORM_CONTEXT_MENU_SET_ALL_AS, *__pFavouriteIcon);
3007                         }
3008                 }
3009
3010                 if (__mailboxType != EMAIL_MAILBOX_TYPE_SPAMBOX && __mailboxType != EMAIL_MAILBOX_TYPE_DRAFT && __mailboxType != EMAIL_MAILBOX_TYPE_OUTBOX && __mailboxType != EMAIL_MAILBOX_TYPE_SENTBOX)
3011                 {
3012                         __pMoreOptionMenu->AddItem(Utils::GetResourceString(L"IDS_EMAIL_OPT_BLOCK"), IDA_INBOX_FORM_CONTEXT_MENU_BLOCK, *__pBlockIcon);
3013                 }
3014
3015                 break;
3016         }
3017
3018         AppLogDebug("EXIT");
3019 }
3020
3021 void
3022 MailListForm::PopulateFolderContextMenu(void)
3023 {
3024         int xPosition, yPosition;
3025         Footer* pFooter = GetFooter();
3026
3027         if (pFooter != null)
3028         {
3029                 pFooter->GetPosition(xPosition, yPosition);
3030                 xPosition = xPosition + (2*pFooter->GetWidth()/3);
3031                 __pFolderContextMenu->SetAnchorPosition(Point(xPosition, yPosition));
3032         }
3033
3034         __pFolderContextMenu->RemoveAllItems();
3035
3036         for (int  i=0; i<__pFolderContextMenuItemsList->GetCount(); i++)
3037         {
3038                 if (__mailboxViewType == ALL_FOLDERS_VIEW || __mailboxViewType != i)
3039                 {
3040 //                      if ((__accountId > 0 && i != FAVORITES_VIEW) || (__accountId == -1 /*&& i != ALL_FOLDERS_VIEW*/))
3041                         {
3042                                 __pFolderContextMenu->AddItem(*static_cast<String*>(__pFolderContextMenuItemsList->GetAt(i)), IDA_INBOX_FORM_CONTEXT_MENU_FOLDER_VIEW+i);
3043                         }
3044                 }
3045         }
3046 }
3047
3048 void
3049 MailListForm::OnTouchPressed(const Control& source, const Point& currentPosition, const TouchEventInfo & touchInfo)
3050 {
3051         AppLogDebug("source touch position %d %d", currentPosition.x, currentPosition.y);
3052         __headerTouchPosition = currentPosition.y;
3053 }
3054
3055 void
3056 MailListForm::OnTouchReleased(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
3057 {
3058         int hashCode = source.GetHashCode();
3059         AppLogDebug("source touch position %d %d", currentPosition.x, currentPosition.y);
3060
3061         Header* pHeader = GetHeader();
3062
3063 //      if (hashCode == pHeader->GetHashCode() && (GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE || __headerTouchPosition > 10) && __pAccountsListPanel->GetShowState() == false)
3064         if (hashCode == pHeader->GetHashCode() && (GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE || __headerTouchPosition == currentPosition.y || __headerTouchPosition > 10) && __pAccountsListPanel->GetShowState() == false)
3065 //      if (hashCode == pHeader->GetHashCode() && __headerTouchPosition ==  currentPosition.y && __pAccountsListPanel->GetShowState() == false)
3066         {
3067                 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
3068                 pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, false);
3069                 GetFooter()->SetEnabled(false);
3070
3071 //              if(__mode == EDIT_MODE)
3072 //              {
3073 //                      __pAccountsListPanel->SetSize(Dimension(__pAccountsListPanel->GetWidth(), __pAccountsListPanel->GetHeight() - __pSelectedLabel->GetHeight()));
3074 //              }
3075
3076                 __pAccountsListView->UpdateList();
3077
3078                 __pMailGroupedListView->SetEnabled(false);
3079                 __pAccountsListPanel->SetShowState(true);
3080         }
3081         else if (hashCode == pHeader->GetHashCode() && __pAccountsListPanel->GetShowState() == true)
3082         {
3083                 if (__mode != EDIT_MODE)
3084                 {
3085                         pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
3086                 }
3087                 else
3088                 {
3089                         __pAccountsListPanel->SetSize(Dimension(__pAccountsListPanel->GetWidth(), __pAccountsListPanel->GetHeight() + __pSelectedLabel->GetHeight()));
3090                 }
3091
3092                 pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
3093                 GetFooter()->SetEnabled(true);
3094
3095                 __pMailGroupedListView->SetEnabled(true);
3096                 __pMailGroupedListView->Invalidate(true);
3097                 __pAccountsListPanel->SetShowState(false);
3098         }
3099         else if (hashCode == __pAccountsListPanel->GetHashCode())
3100         {
3101                 if (__mode != EDIT_MODE)
3102                 {
3103                         pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
3104                 }
3105                 else
3106                 {
3107                         __pAccountsListPanel->SetSize(Dimension(__pAccountsListPanel->GetWidth(), __pAccountsListPanel->GetHeight() + __pSelectedLabel->GetHeight()));
3108                 }
3109
3110                 pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
3111                 GetFooter()->SetEnabled(true);
3112
3113                 __pMailGroupedListView->SetEnabled(true);
3114                 __pMailGroupedListView->Invalidate(true);
3115                 __pAccountsListPanel->SetShowState(false);
3116         }
3117
3118         GetFooter()->Invalidate(true);
3119         pHeader->Invalidate(true);
3120 }
3121
3122 void
3123 MailListForm::OnTouchMoved(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
3124 {
3125
3126 }
3127
3128 void
3129 MailListForm::OnTouchFocusIn(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
3130 {
3131
3132 }
3133
3134 void
3135 MailListForm::OnTouchFocusOut(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
3136 {
3137
3138 }
3139
3140 int
3141 MailListForm::GetItemCount(void)
3142 {
3143         AppLogDebug("ENTER");
3144         int height;
3145         int count = __pPresentationModel->GetAccountCount();
3146         int listViewWidth = __pAccountsListView->GetWidth();
3147
3148         if (count > 1)
3149         {
3150                 // Include an 'All Accounts' item as well
3151                 count++;
3152         }
3153
3154         height = count*H_ACCOUNTCUSTOM_ITEM;
3155         if (height >= __pAccountsListPanel->GetHeight() - (GENERIC_OFFSET_16))
3156         {
3157                 height = __pAccountsListPanel->GetHeight() - (GENERIC_OFFSET_16);
3158         }
3159
3160         if (__mode == EDIT_MODE && height >= __pAccountsListPanel->GetHeight() - (GENERIC_OFFSET_16) - __pSelectedLabel->GetHeight())
3161         {
3162                 height = height - __pSelectedLabel->GetHeight();
3163         }
3164
3165         __pAccountsListView->SetSize(listViewWidth, height);
3166
3167         AppLogDebug("EXIT");
3168         return count;
3169 }
3170
3171 ListItemBase*
3172 MailListForm::CreateItem(int index, int itemWidth)
3173 {
3174         AppLogDebug("ENTER");
3175         AppResource* pAppResource = Tizen::App::Application::GetInstance()->GetAppResource();
3176         Bitmap* pTextBackground = pAppResource->GetBitmapN(IDB_UNREADCOUNT_BACKGROUND, BITMAP_PIXEL_FORMAT_ARGB8888);
3177         Bitmap* pTextPressedBackground = pAppResource->GetBitmapN(IDB_UNREADCOUNT_PRESSED_BACKGROUND, BITMAP_PIXEL_FORMAT_ARGB8888);
3178         CustomItem* pItem = new (std::nothrow) CustomItem();
3179         pItem->Construct(Dimension(itemWidth, H_ACCOUNTCUSTOM_ITEM), LIST_ANNEX_STYLE_NORMAL);
3180
3181         EmailAccount* pAccount = null;
3182
3183         if (__pPresentationModel->GetAccountCount() > 1)
3184         {
3185                 if (index == 0)
3186                 {
3187                         pItem->AddElement(Rectangle(32, 24, 64, 64), 2, *__pAllAccountsIcon);
3188                         pItem->AddElement(Rectangle(112,0,itemWidth-218, 112), 3, Utils::GetResourceString(L"IDS_EMAIL_BODY_ALL_ACCOUNTS"), 40, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), false);
3189                 }
3190                 else
3191                 {
3192                         pAccount = __pPresentationModel->GetAccountByIndex(index-1);
3193
3194                         if (pAccount != null)
3195                         {
3196                                 AccountColorCustomListElement* pAccountColor = new (std::nothrow) AccountColorCustomListElement();
3197                                 pAccountColor->SetAccountId(pAccount->GetAccountId());
3198
3199                                 pItem->AddElement(Rectangle(0,4,16,104), 1, *pAccountColor);
3200
3201                                 Bitmap* pAccountLogo = App::GetInstance()->GetAppResource()->GetBitmapN(File::GetFileName(pAccount->GetLogoIconPath()));
3202                                 pItem->AddElement(Rectangle(32, 24, 64, 64), 2, *pAccountLogo);
3203                                 delete pAccountLogo;
3204
3205                                 pItem->AddElement(Rectangle(112,0,itemWidth-218, 70), 3, pAccount->GetAccountName(), 40, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), false);
3206                                 pItem->AddElement(Rectangle(112,65,itemWidth-218, 40), 4, pAccount->GetUserEmailAddress(), 32, Color::GetColor(COLOR_ID_GREY), Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), true);
3207
3208
3209                                 pItem->AddElement(Rectangle(itemWidth-80,24,50,50), 6, *pTextBackground, pTextPressedBackground);
3210
3211                                 if (__pPresentationModel->GetUnreadCount(pAccount) > 99)
3212                                 {
3213                                         pItem->AddElement(Rectangle(itemWidth-80,24,50,50), 5, Integer::ToString(__pPresentationModel->GetUnreadCount(pAccount)), 28, COLOR_LIST_UNREAD_COUNT_BG_NORMAL, COLOR_LIST_UNREAD_COUNT_BG_PRESSED, null);
3214                                 }
3215                                 else if (__pPresentationModel->GetUnreadCount(pAccount) > 9)
3216                                 {
3217                                         pItem->AddElement(Rectangle(itemWidth-70,24,40,50), 5, Integer::ToString(__pPresentationModel->GetUnreadCount(pAccount)), 28, COLOR_LIST_UNREAD_COUNT_BG_NORMAL, COLOR_LIST_UNREAD_COUNT_BG_PRESSED, null);
3218                                 }
3219                                 else
3220                                 {
3221                                         pItem->AddElement(Rectangle(itemWidth-65,24,40,50), 5, Integer::ToString(__pPresentationModel->GetUnreadCount(pAccount)), 28, COLOR_LIST_UNREAD_COUNT_BG_NORMAL, COLOR_LIST_UNREAD_COUNT_BG_PRESSED, null);
3222                                 }
3223                         }
3224                 }
3225         }
3226         else
3227         {
3228                 pAccount = __pPresentationModel->GetAccountByIndex(index);
3229
3230                 if (pAccount != null)
3231                 {
3232                         AccountColorCustomListElement* pAccountColor = new (std::nothrow) AccountColorCustomListElement();
3233                         pAccountColor->SetAccountId(pAccount->GetAccountId());
3234
3235                         __pPresentationModel->UpdateUnreadCount(pAccount->GetAccountId());
3236
3237                         pItem->AddElement(Rectangle(0,4,16,104), 1, *pAccountColor);
3238
3239                         Bitmap* pAccountLogo = App::GetInstance()->GetAppResource()->GetBitmapN(File::GetFileName(pAccount->GetLogoIconPath()));
3240                         pItem->AddElement(Rectangle(32, 24, 64, 64), 2, *pAccountLogo);
3241                         delete pAccountLogo;
3242
3243                         pItem->AddElement(Rectangle(112,0,itemWidth-218, 70), 3, pAccount->GetAccountName(), 40, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), false);
3244                         pItem->AddElement(Rectangle(112,65,itemWidth-218, 40), 4, pAccount->GetUserEmailAddress(), 32, Color::GetColor(COLOR_ID_GREY), Color::GetColor(COLOR_ID_WHITE), Color::GetColor(COLOR_ID_WHITE), true);
3245
3246                         pItem->AddElement(Rectangle(itemWidth-80,24,50,50), 6, *pTextBackground, pTextPressedBackground);
3247
3248                         if (__pPresentationModel->GetUnreadCount(pAccount) > 99)
3249                         {
3250                                 pItem->AddElement(Rectangle(itemWidth-80,24,50,50), 5, Integer::ToString(__pPresentationModel->GetUnreadCount(pAccount)), 28, COLOR_LIST_UNREAD_COUNT_BG_NORMAL, COLOR_LIST_UNREAD_COUNT_BG_PRESSED, null);
3251                         }
3252                         else if (__pPresentationModel->GetUnreadCount(pAccount) > 9)
3253                         {
3254                                 pItem->AddElement(Rectangle(itemWidth-70,24,40,50), 5, Integer::ToString(__pPresentationModel->GetUnreadCount(pAccount)), 28, COLOR_LIST_UNREAD_COUNT_BG_NORMAL, COLOR_LIST_UNREAD_COUNT_BG_PRESSED, null);
3255                         }
3256                         else
3257                         {
3258                                 pItem->AddElement(Rectangle(itemWidth-65,24,40,50), 5, Integer::ToString(__pPresentationModel->GetUnreadCount(pAccount)), 28, COLOR_LIST_UNREAD_COUNT_BG_NORMAL, COLOR_LIST_UNREAD_COUNT_BG_PRESSED, null);
3259                         }
3260                 }
3261         }
3262
3263         delete pTextBackground;
3264         delete pTextPressedBackground;
3265
3266         AppLogDebug("EXIT");
3267         return pItem;
3268 }
3269
3270 bool
3271 MailListForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
3272 {
3273         AppLogDebug("ENTER");
3274         CustomItem* pCustomItem = null;
3275
3276         if (pItem != null)
3277         {
3278                 pCustomItem = static_cast<CustomItem*>(pItem);
3279
3280                 pCustomItem->RemoveAllElements();
3281                 delete pCustomItem;
3282         }
3283
3284         AppLogDebug("EXIT");
3285         return true;
3286 }
3287
3288 void
3289 MailListForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
3290 {
3291         AppLogDebug("ENTER");
3292
3293         if (__mode == EDIT_MODE)
3294         {
3295                 GoToNormalMode(true);
3296                 UnCheckAllListviewItems();
3297                 __pPresentationModel->ClearSelectedMailList();
3298         }
3299
3300         if (__pPresentationModel->GetAccountCount() > 1)
3301         {
3302                 if (index == 0)
3303                 {
3304                         __accountId = -1;
3305                         __mailboxId = -1;
3306                         __mailboxType = EMAIL_MAILBOX_TYPE_INBOX;
3307                         __pPresentationModel = AllMailsPresentationModel::GetInstance();
3308                         __pBaseListViewItemProvider->SetPresentationModel(__pPresentationModel);
3309                         __pPresentationModel->FetchData(__accountId, __mailboxId, __mailboxType); // Fetches data from all accounts corresponding to the mailbox type
3310                 }
3311                 else
3312                 {
3313                         EmailAccount* pAccount = __pPresentationModel->GetAccountByIndex(index-1);
3314
3315                         if (pAccount != null)
3316                         {
3317                                 __accountId = pAccount->GetAccountId();
3318                                 __pPresentationModel = InboxPresentationModel::GetInstance();
3319                                 __pBaseListViewItemProvider->SetPresentationModel(__pPresentationModel);
3320                                 __mailboxId = __pPresentationModel->GetMailboxIdByType(__accountId, EMAIL_MAILBOX_TYPE_INBOX);
3321                                 __pPresentationModel->FetchData(__accountId); // Fetches data for the account id
3322                                 __mailboxType = EMAIL_MAILBOX_TYPE_INBOX;
3323                         }
3324                 }
3325
3326                 __mailboxViewType = INBOX_VIEW;
3327                 __pPresentationModel->SortBy(__viewByType);
3328
3329                 __pMailGroupedListView->UpdateList();
3330
3331                 PopulateHeader();
3332
3333                 GetHeader()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
3334                 GetHeader()->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
3335                 GetFooter()->SetEnabled(true);
3336
3337                 GetHeader()->Invalidate(true);
3338                 GetFooter()->Invalidate(true);
3339
3340                 __pAccountsListPanel->SetShowState(false);
3341 //              __pAccountsListPanel->GetControlAnimator()->StartUserAnimation(ANIMATION_TARGET_ALPHA, IntegerAnimation(1, 0, 250, ANIMATION_INTERPOLATOR_LINEAR));
3342                 __pMailGroupedListView->SetEnabled(true);
3343                 SetFocus();
3344         }
3345         else
3346         {
3347                 GetHeader()->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
3348                 GetHeader()->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
3349                 GetFooter()->SetEnabled(true);
3350
3351                 GetHeader()->Invalidate(true);
3352                 GetFooter()->Invalidate(true);
3353
3354                 __pAccountsListPanel->SetShowState(false);
3355 //              __pAccountsListPanel->GetControlAnimator()->StartUserAnimation(ANIMATION_TARGET_ALPHA, IntegerAnimation(1, 0, 250, ANIMATION_INTERPOLATOR_LINEAR));
3356                 __pMailGroupedListView->SetEnabled(true);
3357                 SetFocus();
3358         }
3359
3360         AppLogDebug("EXIT");
3361 }
3362
3363 void
3364 MailListForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
3365 {
3366
3367 }
3368
3369 void
3370 MailListForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus status)
3371 {
3372
3373 }
3374
3375 void
3376 MailListForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
3377 {
3378         AppLogDebug("ENTER");
3379
3380         if (__mode == EDIT_MODE)
3381         {
3382                 FloatDimension d = FloatDimension(__pMailGroupedListView->GetWidthF(), this->GetClientAreaBoundsF().height -__pSelectedLabel->GetHeightF());
3383                 __pMailGroupedListView->SetSize(CoordinateSystem::AlignToDevice(d));
3384
3385 //              __pMailGroupedListView->SetSize(__pMailGroupedListView->GetWidth(), this->GetClientAreaBounds().height -__pSelectedLabel->GetHeight());
3386
3387                 if(__pAccountsListPanel->GetShowState() == true)
3388                 {
3389                         __pAccountsListPanel->SetSize(Dimension(__pAccountsListPanel->GetWidth(), __pAccountsListPanel->GetHeight() - __pSelectedLabel->GetHeight()));
3390                 }
3391
3392         }
3393         else
3394         {
3395                  if(!(((__prevOrientation == ORIENTATION_STATUS_PORTRAIT) && (orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)) ||
3396                 ((__prevOrientation == ORIENTATION_STATUS_PORTRAIT_REVERSE) && (orientationStatus == ORIENTATION_STATUS_PORTRAIT))))
3397                          __pMailGroupedListView->SetSize(__pMailGroupedListView->GetWidth(), this->GetClientAreaBounds().height);
3398         }
3399
3400         if (__pAccountsListPanel->GetShowState() == true)
3401         {
3402                 __pAccountsListPanel->Invalidate(true);
3403                 __pAccountsListView->UpdateList();
3404         }
3405
3406         __prevOrientation = orientationStatus;
3407         AppLogDebug("EXIT");
3408         return;
3409 }
3410
3411 void
3412 MailListForm::OnProgressPopupCanceled(void)
3413 {
3414         AppLogDebug("ENTER");
3415
3416         if (__pDownloadAttachmentsPopup != null && __pDownloadAttachmentsPopup->GetShowState() == true)
3417         {
3418                 AppLogDebug("User cancelled download of attachments");
3419
3420                 if (__pAttachmentDownloadHandleMap != null)
3421                 {
3422                         IMapEnumerator* pMapEnum = __pAttachmentDownloadHandleMap->GetMapEnumeratorN();
3423
3424                         if (pMapEnum != null)
3425                         {
3426                                 while (!IsFailed(pMapEnum->MoveNext()))
3427                                 {
3428                                         int accountId = static_cast<Integer*>(pMapEnum->GetKey())->ToInt();
3429                                         int handle = static_cast<Integer*>(pMapEnum->GetValue())->ToInt();
3430                                         __pPresentationModel->CancelJob(accountId, handle, EMAIL_CANCELED_BY_USER);
3431                                 }
3432                                 delete pMapEnum;
3433                         }
3434                 }
3435
3436                 if (__pAttachmentDownloadHandleMap != null)
3437                 {
3438                         __pAttachmentDownloadHandleMap->RemoveAll(true);
3439                         delete __pAttachmentDownloadHandleMap;
3440                         __pAttachmentDownloadHandleMap = null;
3441                 }
3442
3443                 __futureAction = EmailTypesNS::NONE;
3444                 __downloadAttachments = 0;
3445                 __userCancelledAttachmentDownload = true;
3446
3447                 if (__pDownloadAttachmentsPopup != null)
3448                 {
3449                         __pDownloadAttachmentsPopup->SetShowState(false);
3450                 }
3451
3452                 EmailApp::GetInstance()->ClearDownloadAttachmentPopupStatus();
3453                 Invalidate(true);
3454         }
3455
3456         AppLogDebug("EXIT");
3457 }
3458
3459 bool
3460 MailListForm::IsAttachmentDownload(const EmailMessageItem* pDetailedMail)
3461 {
3462         AppLogDebug("ENTER, pDetailedMsg:(%x)", pDetailedMail);
3463         AppLogDebugIf(pDetailedMail != null, "mailId:(%d)", pDetailedMail->GetMailId());
3464
3465         ArrayList* pAttachments = __pPresentationModel->GetAllAttachmentListN(pDetailedMail->GetMailId());
3466
3467         for (int i=0; i<pAttachments->GetCount(); i++)
3468         {
3469                 EmailAttachment* pTmpAttachment = static_cast<EmailAttachment*>(pAttachments->GetAt(i));
3470
3471                 if (pTmpAttachment->GetSaveStatus() == false)
3472                 {
3473                         pAttachments->RemoveAll(true);
3474                         delete pAttachments;
3475
3476                         AppLogDebug("EXIT, returning false");
3477                         return false;
3478                 }
3479         }
3480
3481         pAttachments->RemoveAll(true);
3482         delete pAttachments;
3483
3484         AppLogDebug("EXIT, returning true");
3485         return true;
3486 }
3487
3488 void
3489 MailListForm::DownloadAllAttachments(const EmailMessageItem* pDetailedMail, DownloadInitiatorMode downloadMode)
3490 {
3491         AppLogDebug("ENTER, pDetailedMsg:(%x)", pDetailedMail);
3492         AppLogDebugIf(pDetailedMail != null, "mailId:(%d)", pDetailedMail->GetMailId());
3493
3494         result r = E_SUCCESS;
3495
3496         __downloadAttachments = 0;
3497
3498         if (__pDownloadAttachmentsPopup == null)
3499         {
3500                 __pDownloadAttachmentsPopup = new (std::nothrow) ProgressPopup();
3501                 __pDownloadAttachmentsPopup->Construct(true, false);
3502                 __pDownloadAttachmentsPopup->SetTitleText(Utils::GetResourceString(L"IDS_EMAIL_POP_DOWNLOADING_ATTACHMENT_ING"));
3503                 __pDownloadAttachmentsPopup->AddProgressPopupEventListener(*this);
3504         }
3505
3506         __pDownloadAttachmentsPopup->SetShowState(true);
3507         __pDownloadAttachmentsPopup->Show();
3508         EmailApp::GetInstance()->SetDownloadAttachmentPopupStatus(pDetailedMail->GetMailId(), downloadMode);
3509
3510         if (__pAttachmentDownloadHandleMap == null)
3511         {
3512                 __pAttachmentDownloadHandleMap = new (std::nothrow) HashMap();
3513                 __pAttachmentDownloadHandleMap->Construct();
3514         }
3515
3516         __pAttachmentDownloadHandleMap->RemoveAll(true);
3517
3518         ArrayList* pAttachments = __pPresentationModel->GetAllAttachmentListN(pDetailedMail->GetMailId());
3519
3520         for (int i=0; i<pAttachments->GetCount(); i++)
3521         {
3522                 int handle;
3523                 EmailAttachment* pTmpAttachment = static_cast<EmailAttachment*>(pAttachments->GetAt(i));
3524
3525                 if (pTmpAttachment->GetSaveStatus() == false)
3526                 {
3527                         __downloadAttachments++;
3528                         r = __pPresentationModel->DownloadAttachment(pDetailedMail->GetMailId(), i+1, handle);
3529
3530                         if (r == E_SUCCESS)
3531                         {
3532                                 AppLogDebug("Adding accountId:(%d), handle:(%d) to map", pDetailedMail->GetAccountId(), handle);
3533                                 r = __pAttachmentDownloadHandleMap->Add(new (std::nothrow) Integer(pDetailedMail->GetAccountId()), new (std::nothrow) Integer(handle));
3534                                 AppLogDebugIf(r != E_SUCCESS, "Failed to add attachment download handle to map");
3535                         }
3536                 }
3537         }
3538
3539         pAttachments->RemoveAll(true);
3540         delete pAttachments;
3541
3542         AppLogDebug("EXIT, download attachment count:(%d)", __downloadAttachments);
3543 }
3544
3545 bool
3546 MailListForm::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
3547 {
3548         AppLogDebug("ENTER, keyCode:(%d)", keyEventInfo.GetKeyCode());
3549         AppLogDebug("EXIT");
3550         return false;
3551 }
3552
3553 bool
3554 MailListForm::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
3555 {
3556         AppLogDebug("ENTER, keyCode:(%d)", keyEventInfo.GetKeyCode());
3557
3558         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
3559         {
3560                 if (__pDeleteConfirmationPopup != null && __pDeleteConfirmationPopup->GetShowState() == true)
3561                 {
3562                         AppLogDebug("Delete popup");
3563                         EmailApp::GetInstance()->ClearShowDeletePopupStatus();
3564
3565                         __pDeleteConfirmationPopup->SetShowState(false);
3566                         Invalidate(true);
3567                 }
3568                 else if (__pSortByPopup != null && __pSortByPopup->GetShowState() == true)
3569                 {
3570                         AppLogDebug("sort by popup");
3571                         __pSortByPopup->SetShowState(false);
3572                         Invalidate(true);
3573                 }
3574                 else if (__pMarkAllAsPopup != null && __pMarkAllAsPopup->GetShowState() == true)
3575                 {
3576                         AppLogDebug("Mark all as popup");
3577                         __pMarkAllAsPopup->SetShowState(false);
3578                         Invalidate(true);
3579                 }
3580                 else if (__pSetAllAsPopup != null && __pSetAllAsPopup->GetShowState() == true)
3581                 {
3582                         AppLogDebug("set all as popup");
3583                         __pSetAllAsPopup->SetShowState(false);
3584                         Invalidate(true);
3585                 }
3586         }
3587
3588         AppLogDebug("EXIT");
3589         return false;
3590 }
3591
3592 bool
3593 MailListForm::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
3594 {
3595         AppLogDebug("ENTER, keyCode:(%d)", keyEventInfo.GetKeyCode());
3596         AppLogDebug("EXIT");
3597         return false;
3598 }
3599
3600 bool
3601 MailListForm::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
3602 {
3603         AppLogDebug("ENTER, keyCode:(%d)", keyEventInfo.GetKeyCode());
3604         AppLogDebug("EXIT");
3605         return false;
3606 }