2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
24 #include "EmNativeMailboxManager.h"
25 #include "EmEmailApp.h"
26 #include "EmMainFrame.h"
27 #include "EmFormFactory.h"
29 #include "EmMailSyncThread.h"
30 #include "EmEmailSettingPresentationModel.h"
31 #include "EmInboxPresentationModel.h"
32 #include "EmManualSetUpForm.h"
33 #include "EmStateInfo.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Utility;
38 using namespace Tizen::Io;
39 using namespace Tizen::System;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Ui::Scenes;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Base::Collection;
46 EmailApp* EmailApp::__application = null;
48 EmailApp::EmailApp(void)
49 : __downloadBodyHandle(0)
50 , __downloadBodyAccountId(-1)
51 , __returnAppControlResult(false)
52 , __frameDisabled(false)
53 , __showDeletePopup(false)
54 , __showDownloadAttachmentPopup(false)
55 , __showDownloadFailedPopup(false)
56 , __isMoveFailed(false)
57 , __showMoveOrDeleteFailedPopup(false)
59 , __downloadMailId(-1)
60 , __appControlRequestId(0)
61 , __opId(EMAIL_OPERATION_NONE)
62 , __appControlResult(APP_CTRL_RESULT_FAILED)
65 // Empty Implementation
68 EmailApp::~EmailApp(void)
70 // Empty Implementation
74 EmailApp::CreateInstance(void)
76 __application = new (std::nothrow) EmailApp();
77 // Create the instance through the constructor.
82 EmailApp::GetInstance(void)
88 EmailApp::OnAppInitializing(AppRegistry& appRegistry)
91 // Initialize Frame and App specific data.
92 // The App's permanent data and context can be obtained from the appRegistry.
94 // If this method is successful, return true; otherwise, return false.
95 // If this method returns false, the App will be terminated.
97 // Uncomment the following statement to listen to the screen on/off events.
98 // PowerManager::SetScreenEventListener(*this);
100 AppLogDebug("ENTER");
102 result r = E_SUCCESS;
103 r = AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
104 AppLogDebug("SetAppControlProviderEventListener result:(%s)", GetErrorMessage(r));
111 EmailApp::OnAppInitialized(void)
113 AppLogDebug("ENTER");
119 result r = E_SUCCESS;
121 String languageKey = L"http://tizen.org/setting/locale.language";
122 String timeFormatKey = L"http://tizen.org/setting/locale.time.format.24hour";
124 String backButtonKey = L"http://tizen.org/feature/input.keys.back";
125 String menuButtonKey = L"http://tizen.org/feature/input.keys.menu";
128 EmailFrame* pEmailFrame = new (std::nothrow) EmailFrame();
129 pEmailFrame->Construct();
130 pEmailFrame->SetName(IDS_EMAIL_TEXT);
131 AddFrame(*pEmailFrame);
133 mem = GetAvailableMemory();
134 AppLogDebug("%lld",mem);
136 if(mem < MIN_MEMORY_NEEDED)
138 MessageBox LowMemory;
140 //LowMemory.Construct(Utils::GetResourceString(L"IDS_COM_BODY_WARNING"), L"Memory Low, Delete some data", MSGBOX_STYLE_NONE,1000);
141 LowMemory.Construct(Utils::GetResourceString(L"IDS_COM_BODY_WARNING"), Utils::GetResourceString(L"IDS_COM_POP_NOT_ENOUGH_MEMORY"), MSGBOX_STYLE_NONE,1000);
143 // Calls ShowAndWait() : Draws and Shows itself and processes events
144 LowMemory.ShowAndWait(modalResult);
149 if (email_service_begin() != EMAIL_ERROR_NONE)
151 AppLogDebug("Email service begin failed!");
152 msgBox.Construct("Error!", "Launch failed due to Email Service error!", MSGBOX_STYLE_OK, 300000);
153 msgBox.ShowAndWait(modRes);
157 if ((res=email_open_db()) != EMAIL_ERROR_NONE)
159 AppLogDebug("Open db failed with error:(%d)", res);
160 msgBox.Construct("Error!", "Launch failed due to DB error!", MSGBOX_STYLE_OK, 300000);
161 msgBox.ShowAndWait(modRes);
165 MailNotificationThread* pNotiThread = MailNotificationThread::GetInstance();
166 pNotiThread->Start();
168 SceneManager* pSceneManager = SceneManager::GetInstance();
171 if (__opId == EMAIL_OPERATION_COMPOSE)
173 if (EmailSettingsProvider::GetInstance()->GetDefaultAccountId() > 0)
175 AppLogDebug("Args count:(%d)", __pArgs->GetCount());
176 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_EMAIL_COMPOSER), __pArgs);
177 AppLogDebug("Result of goforward:(%s)", GetErrorMessage(r));
181 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ADD_ACCOUNT), __pArgs);
182 AppLogDebug("Result of goforward:(%s)", GetErrorMessage(r));
185 else if (__opId == EMAIL_OPERATION_SETTINGS)
187 // Create Email settings manager...
188 EmailSettingsProvider* pMailSettingsProvider = EmailSettingsProvider::GetInstance();
190 if (pMailSettingsProvider == null)
192 AppLogDebug("Manager initialization failed!");
193 AppLogDebug("EXIT, returning false");
197 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_EMAIL_SETTING));
199 else if (__opId == EMAIL_OPERATION_ADD_ACCOUNT)
201 // Create Email settings manager...
202 EmailSettingsProvider* pMailSettingsProvider = EmailSettingsProvider::GetInstance();
204 if (pMailSettingsProvider == null)
206 AppLogDebug("Manager initialization failed!");
207 AppLogDebug("EXIT, returning false");
211 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ADD_ACCOUNT));
213 else if (__opId == EMAIL_OPERATION_ACCOUNT_CONFIG)
215 EmailAccount* pTmpAccount = EmailSettingsProvider::GetInstance()->GetAccountById(__accountId);
217 ArrayList* pArgs = new ArrayList();
220 pArgs->Add(pTmpAccount);
222 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ACCOUNT_CONFIG), pArgs);
224 else if (__opId == EMAIL_OPERATION_NONE)
227 Orientation frameOrientation;
229 // Create Email settings provider...
230 EmailSettingsProvider* pMailSettingsProvider = EmailSettingsProvider::GetInstance();
232 // Create Email Mailbox manager...
233 EmailMailboxManager* pMailboxManager = EmailMailboxManager::GetInstance();
235 if (pMailSettingsProvider == null || pMailboxManager == null)
237 AppLogDebug("Manager initialization failed!");
238 AppLogDebug("EXIT, returning false");
242 accountId = pMailSettingsProvider->GetDefaultAccountId();
245 Frame* pFrame = GetInstance()->GetFrame(IDS_EMAIL_TEXT);
249 frameOrientation = pFrame->GetOrientation();
251 AppLogDebug("check orientation:(%d)", frameOrientation);
252 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_INBOX));
257 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ADD_ACCOUNT));
261 SettingInfo::GetValue(languageKey, __currentDisplayLanguage);
262 SettingInfo::GetValue(timeFormatKey, __is24HourFormat);
263 SettingInfo::AddSettingEventListener(*this);
265 AppLogDebug("EXIT, returning true");
270 EmailApp::OnAppWillTerminate(void)
278 EmailApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
280 AppLogDebug("ENTER");
282 if (__returnAppControlResult == true)
284 AppControlProviderManager::GetInstance()->SendAppControlResult(__appControlRequestId, __appControlResult, null);
287 if(email_close_db() != EMAIL_ERROR_NONE)
289 AppLogDebug("Error closing DB!");
292 if(email_service_end() != EMAIL_ERROR_NONE)
294 AppLogDebug("Error ending email service");
304 EmailApp::OnForeground(void)
307 // Start or resume drawing when the application is moved to the foreground.
308 AppLogDebug("ENTER");
310 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
314 Form* pForm = pFrame->GetCurrentForm();
318 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
319 pForm->SendUserEvent(IDA_EMAIL_APP_FOREGROUND, null);
327 EmailApp::OnBackground(void)
329 AppLogDebug("ENTER");
337 EmailApp::OnLowMemory(void)
340 // Free unused resources or close the application.
344 EmailApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
347 // Handle any changes in battery level here.
348 // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
352 EmailApp::OnScreenOn(void)
355 // Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
359 EmailApp::OnScreenOff(void)
362 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
363 // to enter the sleep mode to save the battery.
364 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
365 // callback before the device enters the sleep mode.
366 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
370 EmailApp::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
372 AppLogDebug("ENTER, requestId:(%d)", requestId);
374 if (requestId == IDA_NOTI_DELETE_FINISHED)
376 if (pArgs != null && pArgs->GetCount() == 2)
378 int accountId = static_cast<Integer*>(pArgs->GetAt(0))->ToInt();
379 String* pData = static_cast<String*>(pArgs->GetAt(1));
383 EmailMailboxManager::GetInstance()->RemoveData(accountId, pData);
386 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
389 Form* pForm = pFrame->GetCurrentForm();
392 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
393 pForm->SendUserEvent(requestId, null);
398 else if (requestId == IDA_NOTI_MAIL_MOVE_FINISHED)
400 AppLogDebug("EmailApp::mail data modified");
402 if (requestId == IDA_NOTI_MAIL_MOVE_FINISHED && pArgs != null)
404 int fromMailboxId = static_cast<Integer*>(pArgs->GetAt(1))->ToInt();
405 int toMailboxId = static_cast<Integer*>(pArgs->GetAt(2))->ToInt();
406 HashMap* pMailIdMap = static_cast<HashMap*>(pArgs->GetAt(3));
408 EmailMailboxManager::GetInstance()->MoveData(fromMailboxId, toMailboxId, pMailIdMap);
410 pMailIdMap->RemoveAll(true);
411 pArgs->RemoveAll(true);
415 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
418 Form* pForm = pFrame->GetCurrentForm();
421 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
422 pForm->SendUserEvent(requestId, null);
426 else if (requestId == IDA_NOTI_MAIL_MOVE_FAIL)
428 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
431 Form* pForm = pFrame->GetCurrentForm();
434 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
435 pForm->SendUserEvent(requestId, null);
439 else if (requestId == IDA_VALIDATE_AND_CREATE_ACCOUNT_FINISH && pArgs != null)
441 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
444 Form* pForm = static_cast<Form *>(pFrame->GetCurrentForm());
447 if (pForm->GetName().Equals(IDL_LOGIN_FORM, true) == false &&
448 pForm->GetName().Equals(IDL_MANUAL_SETUP_FORM, true) == false)
450 pArgs->RemoveAll(true);
454 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
455 pForm->SendUserEvent(IDA_VALIDATE_AND_CREATE_ACCOUNT_FINISH, pArgs);
459 else if (requestId == IDA_VALIDATE_AND_CREATE_ACCOUNT_FAIL)
461 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
464 Form* pForm = static_cast<Form *>(pFrame->GetCurrentForm());
467 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
468 pForm->SendUserEvent(IDA_VALIDATE_AND_CREATE_ACCOUNT_FAIL, null);
472 else if (requestId == IDA_VALIDATE_ACCOUNT_FINISH)
474 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
477 Form* pForm = static_cast<Form *>(pFrame->GetCurrentForm());
480 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
481 pForm->SendUserEvent(IDA_VALIDATE_ACCOUNT_FINISH, pArgs);
485 else if (requestId == IDA_VALIDATE_ACCOUNT_FAIL)
487 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
490 Form* pForm = static_cast<Form *>(pFrame->GetCurrentForm());
493 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
494 pForm->SendUserEvent(IDA_VALIDATE_ACCOUNT_FAIL, null);
498 else if (requestId == IDA_NOTI_MAIL_ADD && pArgs != null)
500 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
503 Form* pForm = pFrame->GetCurrentForm();
506 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
507 pForm->SendUserEvent(IDA_NOTI_MAIL_ADD, pArgs);
511 else if (requestId == IDA_NOTI_DOWNLOAD_BODY_FAIL)
513 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
516 Form* pForm = pFrame->GetCurrentForm();
519 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
520 pForm->SendUserEvent(IDA_NOTI_DOWNLOAD_BODY_FAIL, null);
524 else if (requestId == IDA_NOTI_DOWNLOAD_BODY_FINISH)
526 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
529 Form* pForm = pFrame->GetCurrentForm();
532 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
533 pForm->SendUserEvent(IDA_NOTI_DOWNLOAD_BODY_FINISH, null);
537 else if (requestId == IDA_NOTI_DOWNLOAD_ATTACH_START)
539 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
542 Form* pForm = pFrame->GetCurrentForm();
545 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
546 pForm->SendUserEvent(IDA_NOTI_DOWNLOAD_ATTACH_START, pArgs);
550 else if (requestId == IDA_NOTI_DOWNLOAD_ATTACH_FINISH || requestId == IDA_NOTI_DOWNLOAD_ATTACH_FAIL)
552 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
555 Form* pForm = pFrame->GetCurrentForm();
558 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
559 pForm->SendUserEvent(requestId, pArgs);
563 else if (requestId == IDA_NOTI_DOWNLOAD_FINISH && pArgs != null)
565 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
569 Form* pForm = pFrame->GetCurrentForm();
572 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
573 pForm->SendUserEvent(IDA_NOTI_DOWNLOAD_FINISH, pArgs);
577 else if (requestId == IDA_NOTI_MAIL_UPDATE || requestId == IDA_NOTI_MAIL_FIELD_UPDATE)
579 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
583 Form* pForm = pFrame->GetCurrentForm();
586 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
587 pForm->SendUserEvent(requestId, pArgs);
591 else if (requestId == IDA_SYNC_IMAP_MAILBOX_LIST_FINISH || requestId == IDA_SYNC_IMAP_MAILBOX_LIST_FAIL)
593 Frame* pFrame = GetFrame(IDS_EMAIL_TEXT);
597 Form* pForm = pFrame->GetCurrentForm();
600 AppLogDebug("Sending user event to form:(%ls)", pForm->GetName().GetPointer());
601 pForm->SendUserEvent(requestId, pArgs);
610 ParseURI(const String* pBaseUri, ArrayList* pArgs)
612 AppLogDebug("ENTER");
622 String hname, hvalue, dHValue;
625 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
627 result r = E_SUCCESS;
629 if (pBaseUri != null)
631 baseUri.SetUri(*pBaseUri);
632 encodedURI = baseUri.GetEncodedSchemeSpecificPart();
634 //set the text after 'mailto:' as part of 'to' email address
635 encodedURI.Insert(L"to=",0);
637 // Replace only the very first '?' with an '&'
638 r = encodedURI.IndexOf(L'?',0,index);
641 encodedURI.SetCharAt(L'&',index);
644 StringTokenizer strTok(encodedURI, L"&");
645 while (strTok.HasMoreTokens())
647 strTok.GetNextToken(token);
649 AppLogDebug("Got token:(%ls)", token.GetPointer());
651 // extract pairs of the form 'hname=hvalue'
652 r = token.IndexOf(L'=', 0, index);
655 r = token.SubString(0,index, hname);
656 r |= token.SubString(index+1, hvalue);
658 AppLogDebug("Got hname:(%ls), hvalue:(%ls)", hname.GetPointer(), hvalue.GetPointer());
660 if (r == E_SUCCESS && hname.IsEmpty() == false)
662 if (hname.Equals(L"to", false) == true && hvalue.IsEmpty() == false)
664 UrlDecoder::Decode(hvalue, L"UTF-8", dHValue);
665 strTo.Append(dHValue);
668 else if (hname.Equals(L"cc", false) == true && hvalue.IsEmpty() == false)
670 UrlDecoder::Decode(hvalue, L"UTF-8", dHValue);
671 strCc.Append(dHValue);
674 else if (hname.Equals(L"bcc", false) == true && hvalue.IsEmpty() == false)
676 UrlDecoder::Decode(hvalue, L"UTF-8", dHValue);
677 strBcc.Append(dHValue);
680 else if (hname.Equals(L"subject", false) == true)
682 UrlDecoder::Decode(hvalue, L"UTF-8", dHValue);
684 strSubject.Append(dHValue);
686 else if (hname.Equals(L"body", false) == true && hvalue.IsEmpty() == false)
688 if (strBody.IsEmpty() == true && hvalue.IsEmpty() == false)
690 strBody.Append(hvalue);
692 else if (strBody.IsEmpty() == false && hvalue.IsEmpty() == false)
694 strBody.Append(L"%0D%0A");
695 strBody.Append(hvalue);
697 else if (strBody.IsEmpty() == false && hvalue.IsEmpty() == true)
699 strBody.Append(L"%0D%0A");
706 if (strBody.IsEmpty() == false)
708 UrlDecoder::Decode(strBody, L"UTF-8", dHValue);
709 strBody.Clear(); strBody.Append(dHValue);
713 Utils::BuildEmailIdStringFromCSV(strTo, token);
714 // pArgs->Add(new (std::nothrow) String(token)); // To
715 pStateInfo->toFieldValue = token;
717 Utils::BuildEmailIdStringFromCSV(strCc, token);
718 // pArgs->Add(new (std::nothrow) String(token)); // Cc
719 pStateInfo->ccFieldValue = token;
721 Utils::BuildEmailIdStringFromCSV(strBcc, token);
722 // pArgs->Add(new (std::nothrow) String(token)); // Bcc
723 pStateInfo->bccFieldValue = token;
725 // pArgs->Add(new (std::nothrow) String(strSubject)); // Subject
726 // pArgs->Add(new (std::nothrow) String(strBody)); // Body
727 // pArgs->Add(new (std::nothrow) String()); // Attachments
729 pStateInfo->subjectFieldValue = strSubject;
730 pStateInfo->bodyFieldValue = strBody;
731 pStateInfo->attachmentsPath = L"";
733 pArgs->Add(pStateInfo);
735 AppLogDebug("to:(%ls)", strTo.GetPointer());
736 AppLogDebug("cc:(%ls)", strCc.GetPointer());
737 AppLogDebug("bcc:(%ls)", strBcc.GetPointer());
738 AppLogDebug("subj:(%ls)", strSubject.GetPointer());
739 AppLogDebug("body:(%ls)", strBody.GetPointer());
746 EmailApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUriData, const String* pMimeType, const IMap* pExtraData)
748 AppLogDebug("ENTER, reqID:(%ld), operationID:(%ls)", reqId, operationId.GetPointer());
749 AppLogDebug("===", Utils::ParseExtraData(pExtraData));
751 __appControlRequestId = reqId;
753 if (operationId.Equals(IDS_TIZEN_OPERATIONID_COMPOSE, true))
755 __opId = EMAIL_OPERATION_COMPOSE;
757 AppLogDebug("Going to compose scene");
759 const String* pTmpVal = null;
760 const ArrayList* pTmpArr = null;
761 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
763 __pArgs = new (std::nothrow) ArrayList();
764 __pArgs->Construct();
768 pTmpVal = static_cast<const String*>(pExtraData->GetValue(String(IDS_APPCONTROL_REQUEST_KEY_TO)));
771 String tmpStr(*pTmpVal);
772 tmpStr.Replace(L",", IDS_DELIM_SEMICOLON);
773 // __pArgs->Add(new (std::nothrow) String(tmpStr));
774 pStateInfo->toFieldValue = tmpStr;
778 // __pArgs->Add(new (std::nothrow) String());
779 pStateInfo->toFieldValue = L"";
782 pTmpVal = static_cast<const String*>(pExtraData->GetValue(String(IDS_APPCONTROL_REQUEST_KEY_CC)));
785 String tmpStr(*pTmpVal);
786 tmpStr.Replace(L",", IDS_DELIM_SEMICOLON);
787 // __pArgs->Add(new (std::nothrow) String(tmpStr));
788 pStateInfo->ccFieldValue = tmpStr;
792 // __pArgs->Add(new (std::nothrow) String());
793 pStateInfo->ccFieldValue = L"";
796 pTmpVal = static_cast<const String*>(pExtraData->GetValue(String(IDS_APPCONTROL_REQUEST_KEY_BCC)));
799 String tmpStr(*pTmpVal);
800 tmpStr.Replace(L",", IDS_DELIM_SEMICOLON);
801 // __pArgs->Add(new (std::nothrow) String(tmpStr));
802 pStateInfo->bccFieldValue = tmpStr;
806 // __pArgs->Add(new (std::nothrow) String());
807 pStateInfo->bccFieldValue = L"";
810 pTmpVal = static_cast<const String*>(pExtraData->GetValue(String(IDS_APPCONTROL_REQUEST_KEY_SUBJECT)));
813 // __pArgs->Add(new (std::nothrow) String(*pTmpVal));
814 pStateInfo->subjectFieldValue = *pTmpVal;
818 // __pArgs->Add(new (std::nothrow) String());
819 pStateInfo->subjectFieldValue = L"";
822 pTmpVal = static_cast<const String*>(pExtraData->GetValue(String(IDS_APPCONTROL_REQUEST_KEY_TEXT)));
825 // __pArgs->Add(new (std::nothrow) String(*pTmpVal));
826 pStateInfo->bodyFieldValue = *pTmpVal;
830 // __pArgs->Add(new (std::nothrow) String());
831 pStateInfo->bodyFieldValue = L"";
834 pTmpArr = static_cast<const ArrayList*>(pExtraData->GetValue(String(IDS_APPCONTROL_REQUEST_KEY_ATTACH)));
840 for (int i=0; i<pTmpArr->GetCount(); i++)
843 tmpVal.Append(*static_cast<const String*>(pTmpArr->GetAt(i)));
846 val.Append(IDS_DELIM_SEMICOLON);
849 // __pArgs->Add(new (std::nothrow) String(val));
850 pStateInfo->attachmentsPath = val;
854 // __pArgs->Add(new (std::nothrow) String());
855 pStateInfo->attachmentsPath = L"";
858 pTmpVal = static_cast<const String*>(pExtraData->GetValue(String(IDS_APPCONTROL_REQUEST_KEY_RETURN_RESULT)));
859 if (pTmpVal != null && pTmpVal->Equals(L"true", false) == true)
861 SetAppControlResult(APP_CTRL_RESULT_SUCCEEDED);
863 __pArgs->Add(pStateInfo);
865 else if (pUriData != null)
867 AppLogDebug("Parsing uridata");
869 //handle mailto uri scheme...
870 const String* pBaseUri = pUriData;
871 ParseURI(pBaseUri, __pArgs);
875 AppLogDebug("ExtraData and pUriData were null");
876 // __pArgs->Add(new (std::nothrow) String());
877 // __pArgs->Add(new (std::nothrow) String());
878 // __pArgs->Add(new (std::nothrow) String());
879 // __pArgs->Add(new (std::nothrow) String());
880 // __pArgs->Add(new (std::nothrow) String());
881 // __pArgs->Add(new (std::nothrow) String());
882 __pArgs->Add(pStateInfo);
885 else if (operationId.Equals(IDS_TIZEN_OPERATIONID_ACCOUNT_ADD, true))
887 AppLogDebug("Going to add account scene");
888 __opId = EMAIL_OPERATION_ADD_ACCOUNT;
890 else if (operationId.Equals(IDS_TIZEN_OPERATIONID_ACCOUNT_CONFIGURE, true))
892 AppLogDebug("Going to account config scene");
893 __opId = EMAIL_OPERATION_ACCOUNT_CONFIG;
895 if (pExtraData != null)
897 Integer::Parse(*static_cast<const String*>(pExtraData->GetValue(String(IDS_TIZEN_APPCONTROL_KEY_ACCOUNT_ID))), __accountId);
898 AppLogDebug("Got Account DB account id:(%d)", __accountId);
900 IMapEnumerator* pMapEnum = EmailSettingsProvider::GetInstance()->GetAccountListN();
902 if (pMapEnum != null)
904 while (!IsFailed(pMapEnum->MoveNext()))
906 EmailAccount* pAccount = dynamic_cast<EmailAccount*>(pMapEnum->GetValue());
908 if (pAccount != null && pAccount->GetAccountSvcId() == __accountId)
910 __accountId = pAccount->GetAccountId();
919 AppLogDebug("ExtraData was null");
922 else if (operationId.Equals(IDS_TIZEN_OPERATIONID_CONFIGURE, true))
924 AppLogDebug("Going to configure scene");
925 __opId = EMAIL_OPERATION_SETTINGS;
927 else if (operationId.Equals(IDS_TIZEN_OPERATIONID_SHARE_TEXT, true))
929 __opId = EMAIL_OPERATION_COMPOSE;
931 const String* pTmpVal = null;
932 StateInfo* pStateInfo = new (std::nothrow) StateInfo();
934 __pArgs = new (std::nothrow) ArrayList();
935 __pArgs->Construct();
939 pTmpVal = static_cast<const String*>(pExtraData->GetValue(String(IDS_APPCONTROL_REQUEST_KEY_SHARE_TEXT)));
943 pStateInfo->bodyFieldValue = *pTmpVal;
947 SetAppControlResult(APP_CTRL_RESULT_SUCCEEDED);
948 __pArgs->Add(pStateInfo);
956 EmailApp::GetOperationType(void)
962 EmailApp::SetAppControlResult(AppCtrlResult appCtrlResult)
964 __returnAppControlResult = true;
965 __appControlResult = appCtrlResult;
970 EmailApp::IsReturnResultSet(void)
972 return __returnAppControlResult;
976 EmailApp::OnSettingChanged(String& key)
978 AppLogDebug("ENTER, key:(%ls)", key.GetPointer());
980 String languageSettingKey = L"http://tizen.org/setting/locale.language";
981 String timeFormatKey = L"http://tizen.org/setting/locale.time.format.24hour";
982 String fontSettingKey = L"http://tizen.org/setting/font.size";
983 String languageSelected;
986 if (key.Equals(languageSettingKey, false) == true)
988 SettingInfo::GetValue(languageSettingKey, languageSelected);
990 if (__currentDisplayLanguage.Equals(languageSelected, false) == false)
992 Application::Terminate();
996 if (key.Equals(timeFormatKey, false) == true)
998 SettingInfo::GetValue(timeFormatKey, is24HourFormat);
1000 if (__is24HourFormat != is24HourFormat)
1002 Application::Terminate();
1006 if (key.Equals(fontSettingKey, false) == true)
1008 Application::Terminate();
1011 AppLogDebug("EXIT");
1015 EmailApp::DisableFrame(void)
1017 AppLogDebug("ENTER");
1019 __frameDisabled = true;
1020 GetAppFrame()->GetFrame()->SetEnabled(false);
1022 AppLogDebug("EXIT");
1026 EmailApp::EnableFrame(void)
1028 AppLogDebug("ENTER");
1030 if (__frameDisabled)
1032 AppLogDebug("Enabling frame");
1033 GetAppFrame()->GetFrame()->SetEnabled(true);
1034 GetAppFrame()->GetFrame()->Invalidate(true);
1035 __frameDisabled = false;
1038 AppLogDebug("EXIT");
1042 EmailApp::GetShowDeletePopupStatus(int& mailId, DeletionMode& delMode)
1044 AppLogDebug("Returning bool:(%d), mailId:(%d)", __showDeletePopup, __mailId);
1046 delMode = __delMode;
1049 return __showDeletePopup;
1053 EmailApp::SetShowDeletePopupStatus(DeletionMode delMode, const int mailId)
1055 AppLogDebug("ENTER, delMode:(%d), mailId:(%d)", delMode, mailId);
1057 __delMode = delMode;
1059 __showDeletePopup = true;
1061 AppLogDebug("EXIT");
1065 EmailApp::ClearShowDeletePopupStatus(void)
1067 AppLogDebug("Cleared show delete popup status");
1070 __showDeletePopup = false;
1074 EmailApp::GetDownloadBodyPopupStatus(int& accountId, int& handle)
1076 accountId = __downloadBodyAccountId;
1077 handle = __downloadBodyHandle;
1079 return __downloadBodyHandle;
1083 EmailApp::SetDownloadBodyPopupStatus(int accountId, int handle)
1085 __downloadBodyAccountId = accountId;
1086 __downloadBodyHandle = handle;
1092 EmailApp::ClearDownloadBodyPopupStatus(void)
1094 __downloadBodyAccountId = 0;
1095 __downloadBodyHandle = 0;
1101 EmailApp::GetDownloadAttachmentPopupStatus(int& mailId, DownloadInitiatorMode& forwardMode)
1103 AppLogDebug("ENTER");
1105 mailId = __downloadMailId;
1106 forwardMode = __downloadMode;
1108 AppLogDebug("EXIT maildId:(%d), forwardMode:(%d)", mailId, forwardMode);
1109 return __showDownloadAttachmentPopup;
1113 EmailApp::SetDownloadAttachmentPopupStatus(const int mailId, DownloadInitiatorMode downloadMode)
1115 AppLogDebug("ENTER");
1117 __downloadMailId = mailId;
1118 __downloadMode = downloadMode;
1119 __showDownloadAttachmentPopup = true;
1121 AppLogDebug("EXIT");
1125 EmailApp::ClearDownloadAttachmentPopupStatus(void)
1127 AppLogDebug("ENTER");
1129 __downloadMailId = -1;
1130 __showDownloadAttachmentPopup = false;
1132 AppLogDebug("EXIT");
1136 EmailApp::SetDownloadFailedPopupStatus(bool showPopup)
1138 AppLogDebug("ENTER");
1140 __showDownloadFailedPopup = showPopup;
1142 AppLogDebug("EXIT");
1146 EmailApp::GetDownloadFailedPopupStatus(void)
1148 AppLogDebug("ENTER & EXIT");
1149 return __showDownloadFailedPopup;
1153 EmailApp::SetMoveOrDeleteFailedPopupStatus(bool isMoveFailed)
1155 AppLogDebug("ENTER");
1157 __showMoveOrDeleteFailedPopup = true;
1158 __isMoveFailed = isMoveFailed;
1160 AppLogDebug("EXIT");
1164 EmailApp::GetMoveOrDeleteFailedPopupStatus(bool& isMoveFailed)
1166 AppLogDebug("ENTER");
1168 isMoveFailed = __isMoveFailed;
1170 AppLogDebug("EXIT");
1171 return __showMoveOrDeleteFailedPopup;
1175 EmailApp::ClearMoveOrDeleteFailedPopupStatus(void)
1177 AppLogDebug("ENTER");
1179 __showMoveOrDeleteFailedPopup = false;
1180 __isMoveFailed = false;
1182 AppLogDebug("EXIT");
1186 EmailApp::GetAvailableMemory(void)
1188 AppLogDebug("ENTER");
1190 result r = E_SUCCESS;
1192 String key(L"http://tizen.org/runtime/storage.available.internal");
1193 long long allocatedMemory = 0;
1195 r = RuntimeInfo::GetValue(key, allocatedMemory);
1196 TryCatch(r == E_SUCCESS, , "MyRuntimeInfo: Failed to get value");
1198 AppLogDebug("EXIT, allocatedMemory:(%ll)", allocatedMemory);
1199 return allocatedMemory;
1202 AppLogDebug("EXIT, allocatedMemory:(0)");
1207 EmailApp::RegisterScenes(void)
1209 AppLogDebug("ENTER");
1211 result r = E_SUCCESS;
1212 SceneManager* pSceneManager = SceneManager::GetInstance();
1214 static EmailFormFactory formFactory;
1215 r = pSceneManager->RegisterFormFactory(formFactory);
1216 AppLogDebugIf(r != E_SUCCESS, "Failed to register form factory");
1218 r |= pSceneManager->RegisterScene(IDSCN_ADD_ACCOUNT, ADD_ACCOUNT_FORM, L"");
1219 r |= pSceneManager->RegisterScene(IDSCN_INBOX, INBOX_FORM, L"");
1220 r |= pSceneManager->RegisterScene(IDSCN_EMAIL_COMPOSER, EMAIL_COMPOSER_FORM, L"");
1221 r |= pSceneManager->RegisterScene(IDSCN_EMAIL_DETAIL, EMAIL_DETAIL_FORM, L"");
1222 r |= pSceneManager->RegisterScene(IDSCN_MOVEMAIL, MOVEMAIL_FORM, L"");
1223 r |= pSceneManager->RegisterScene(IDSCN_MOVEMAIL_SELECTED, MOVEMAIL_SELECTED_FORM, L"");
1224 r |= pSceneManager->RegisterScene(IDSCN_EMAIL_SETTING, EMAIL_SETTING_FORM, L"");
1225 r |= pSceneManager->RegisterScene(IDSCN_ADD_ADDRESS, ADD_ADDRESS_FORM, L"");
1226 r |= pSceneManager->RegisterScene(IDSCN_EMAIL_BLOCK, BLOCK_EMAIL_FORM, L"");
1227 r |= pSceneManager->RegisterScene(IDSCN_ACCOUNT_SETTING, ACCOUNT_SETTING_FORM, L"");
1228 r |= pSceneManager->RegisterScene(IDSCN_ADD_SUBJECT, ADD_SUBJECT_FORM, L"");
1229 r |= pSceneManager->RegisterScene(IDSCN_DELETE_ADDRESS_SUBJECT, DELETE_ADDRESS_SUBJECT_FORM, L"");
1230 r |= pSceneManager->RegisterScene(IDSCN_SETTING_SETUP_MAILBOX, SETTING_SETUP_MAILBOX_FORM, L"");
1231 r |= pSceneManager->RegisterScene(IDSCN_ADD_ACCOUNT_MANUAL_SETUP, ADD_ACCOUNT_MANUAL_SETUP_FORM, L"");
1232 r |= pSceneManager->RegisterScene(IDSCN_SEARCH, SEARCH_FORM, L"");
1233 r |= pSceneManager->RegisterScene(IDSCN_SPLIT_VIEW, SPLIT_VIEW_FORM, L"");
1234 r |= pSceneManager->RegisterScene(IDSCN_FOLDERS_VIEW, FOLDERS_VIEW_FORM, L"");
1235 r |= pSceneManager->RegisterScene(IDSCN_ACCOUNT_CONFIG, ACCOUNT_CONFIG_FORM, L"");
1237 AppLogDebugIf(r != E_SUCCESS, "Failed to register scene");
1239 AppLogDebug("EXIT");