From 13adeca584ed21c7b8e7fcdc11cbe6ac01cf86af Mon Sep 17 00:00:00 2001 From: SungWan Kim Date: Mon, 15 Apr 2013 15:06:25 +0900 Subject: [PATCH] Add export function to SettingForm. Change-Id: I32f22b53b5adc2883c571ae6d82a03eadc4d00a6 Signed-off-by: SungWan Kim --- inc/ClCalendarSelectorPopup.h | 2 +- inc/ClSettingForm.h | 9 ++ res/screen-size-normal/IDL_IMPORT_FORM.xml | 2 +- src/ClCalendarSelectorPopup.cpp | 27 ++-- src/ClImportForm.cpp | 32 +++- src/ClSettingForm.cpp | 233 ++++++++++++++++++++++++----- 6 files changed, 253 insertions(+), 52 deletions(-) diff --git a/inc/ClCalendarSelectorPopup.h b/inc/ClCalendarSelectorPopup.h index 19e76db..4f827d9 100644 --- a/inc/ClCalendarSelectorPopup.h +++ b/inc/ClCalendarSelectorPopup.h @@ -34,7 +34,7 @@ class CalendarSelectorPopup { public: result Initialize(void); - void RequestCalendar(CalendarSelectorPopupStyle style, Tizen::Ui::Control* pTarget = null); + void RequestCalendar(CalendarSelectorPopupStyle style, Tizen::Ui::Control* pTarget = null, bool readOnly = false); CalendarSelectorPopup(void); virtual ~CalendarSelectorPopup(void); diff --git a/inc/ClSettingForm.h b/inc/ClSettingForm.h index 179e3fe..765f6aa 100644 --- a/inc/ClSettingForm.h +++ b/inc/ClSettingForm.h @@ -24,8 +24,11 @@ #include #include +#include #include +class CalendarSelectorPopup; + class SettingForm : public Tizen::Ui::Controls::Form , public virtual Tizen::App::IAppControlResponseListener @@ -42,6 +45,7 @@ public: virtual result OnInitializing(void); virtual result OnTerminating(void); + virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs); virtual void OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData); @@ -82,12 +86,17 @@ private: Tizen::Ui::Controls::TableViewItem* CreateExportItemN(int itemWidth); void CollapseGroup(int sectionIndex); void ExpandGroup(int sectionIndex); + result ExportCalendar(Tizen::Social::RecordId calendarId, const Tizen::Base::String& path); + const Tizen::Base::String GetExportFilePath(const Tizen::Base::String& path, const Tizen::Base::String& calendarName, + const Tizen::Base::String& ending); private: Tizen::Ui::Controls::SectionTableView* __pTableView; Tizen::Ui::Controls::Label* __pLabelLockTimeZone; Tizen::Ui::Controls::Label* __pLabelFirstDayOfWeek; Tizen::Ui::Controls::Label* __pLabelFirstDayOfWeekExpandIcon; + CalendarSelectorPopup* __pCalendarSelectorPopup; + Tizen::Social::RecordId __exportCalendarId; int __descriptionItemHeight; bool __isLockTimeZoneSet; bool __isFirstDayOfWeekSelectionItemExpanded; diff --git a/res/screen-size-normal/IDL_IMPORT_FORM.xml b/res/screen-size-normal/IDL_IMPORT_FORM.xml index efc4757..d2f8207 100644 --- a/res/screen-size-normal/IDL_IMPORT_FORM.xml +++ b/res/screen-size-normal/IDL_IMPORT_FORM.xml @@ -24,7 +24,7 @@ - + diff --git a/src/ClCalendarSelectorPopup.cpp b/src/ClCalendarSelectorPopup.cpp index 91ad974..c1e6d5a 100644 --- a/src/ClCalendarSelectorPopup.cpp +++ b/src/ClCalendarSelectorPopup.cpp @@ -87,7 +87,7 @@ CalendarSelectorPopup::Initialize(void) } void -CalendarSelectorPopup::RequestCalendar(CalendarSelectorPopupStyle style, Control* pTarget) +CalendarSelectorPopup::RequestCalendar(CalendarSelectorPopupStyle style, Control* pTarget, bool readOnly) { if (__pCalendars != null) { @@ -103,30 +103,37 @@ CalendarSelectorPopup::RequestCalendar(CalendarSelectorPopupStyle style, Control { case CALENDAR_SELECTOR_POPUP_STYLE_EVENT: filter.AppendInt(FI_CONJ_OP_NONE, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_EVENT_ONLY); + filter.AppendInt(FI_CONJ_OP_OR, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_EVENT_AND_TODO); break; case CALENDAR_SELECTOR_POPUP_STYLE_TODO: filter.AppendInt(FI_CONJ_OP_NONE, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_TODO_ONLY); + filter.AppendInt(FI_CONJ_OP_OR, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_EVENT_AND_TODO); break; case CALENDAR_SELECTOR_POPUP_STYLE_ALL: - filter.AppendInt(FI_CONJ_OP_NONE, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_EVENT_AND_TODO); + filter.AppendInt(FI_CONJ_OP_NONE, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_EVENT_ONLY); + filter.AppendInt(FI_CONJ_OP_OR, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_TODO_ONLY); + filter.AppendInt(FI_CONJ_OP_OR, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_EVENT_AND_TODO); break; } __pCalendars = calendarbook.SearchN(filter); TryReturnVoid(__pCalendars != null, "[E_FAILURE] Unable to get calendar list."); - IEnumerator* pEnum = __pCalendars->GetEnumeratorN(); - int index = 0; - while (pEnum->MoveNext() == E_SUCCESS) + if (readOnly == false) { - if (static_cast(pEnum->GetCurrent())->GetRecordId() == ID_DEFAULT_BIRTHDAY_CALENDAR) + IEnumerator* pEnum = __pCalendars->GetEnumeratorN(); + int index = 0; + while (pEnum->MoveNext() == E_SUCCESS) { - __pCalendars->RemoveAt(index, true); - break; + if (static_cast(pEnum->GetCurrent())->GetRecordId() == ID_DEFAULT_BIRTHDAY_CALENDAR) + { + __pCalendars->RemoveAt(index, true); + break; + } + ++index; } - ++index; + delete pEnum; } - delete pEnum; if (__pCalendars->GetCount() > 0) { diff --git a/src/ClImportForm.cpp b/src/ClImportForm.cpp index c611dee..578d729 100644 --- a/src/ClImportForm.cpp +++ b/src/ClImportForm.cpp @@ -360,7 +360,7 @@ ImportForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& cur AppLogDebug("Enter."); if (pArgs != null) { - if (dynamic_cast(pArgs->GetAt(0)) != null || dynamic_cast(pArgs->GetAt(0)) != null) + if (pArgs->GetCount() == 0 || dynamic_cast(pArgs->GetAt(0)) != null || dynamic_cast(pArgs->GetAt(0)) != null) { __pList = pArgs; pArgs = null; @@ -369,7 +369,15 @@ ImportForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& cur } __pListViewContents->UpdateList(); - GetFooter()->SetItemEnabled(0, IsNoItemChecked() == false); + if (IsAllItemAdded() == true) + { + GetHeader()->RemoveAllButtons(); + GetFooter()->RemoveAllItems(); + } + else + { + GetFooter()->SetItemEnabled(0, IsNoItemChecked() == false); + } AppLogDebug("Exit."); } @@ -468,6 +476,11 @@ ImportForm::IsAllItemAdded(void) const bool ImportForm::IsAllItemChecked(void) const { + if (__pList == null) + { + return true; + } + int index = 0; IEnumerator* pEnum = __pList->GetEnumeratorN(); while (pEnum->MoveNext() == E_SUCCESS) @@ -503,6 +516,11 @@ ImportForm::IsAllItemChecked(void) const bool ImportForm::IsEventItemChecked(void) const { + if (__pList == null) + { + return true; + } + int index = 0; IEnumerator* pEnum = __pList->GetEnumeratorN(); while (pEnum->MoveNext() == E_SUCCESS) @@ -528,6 +546,11 @@ ImportForm::IsEventItemChecked(void) const bool ImportForm::IsNoItemChecked(void) const { + if (__pList == null) + { + return false; + } + int index = 0; IEnumerator* pEnum = __pList->GetEnumeratorN(); while (pEnum->MoveNext() == E_SUCCESS) @@ -563,6 +586,11 @@ ImportForm::IsNoItemChecked(void) const bool ImportForm::IsTodoItemChecked(void) const { + if (__pList == null) + { + return true; + } + int index = 0; IEnumerator* pEnum = __pList->GetEnumeratorN(); while (pEnum->MoveNext() == E_SUCCESS) diff --git a/src/ClSettingForm.cpp b/src/ClSettingForm.cpp index 2167d1e..384a6b4 100644 --- a/src/ClSettingForm.cpp +++ b/src/ClSettingForm.cpp @@ -20,9 +20,10 @@ */ #include -#include +#include #include #include "ClCalendarApp.h" +#include "ClCalendarSelectorPopup.h" #include "ClResourceManager.h" #include "ClSettingForm.h" #include "ClTypes.h" @@ -31,23 +32,19 @@ using namespace Tizen::App; using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Graphics; +using namespace Tizen::Io; using namespace Tizen::Social; using namespace Tizen::System; using namespace Tizen::Ui; using namespace Tizen::Ui::Controls; using namespace Tizen::Ui::Scenes; -// This options is used for import/export function development. -//#define _ENABLE_IMPORT_EXPORT_ - enum { GROUP_ITEM_INDEX = -1, // GROUP_LOCK_TIME_ZONE = 0, GROUP_FIRST_DAY_OF_WEEK, -#ifdef _ENABLE_IMPORT_EXPORT_ GROUP_IMPORT_EXPORT, -#endif GROUP_COUNT, // LOCK_TIME_ZONE_ITEM_ONOFF = 0, @@ -61,11 +58,9 @@ enum FIRST_DAY_OF_WEEK_ITEM_COUNT_EXPANDED, FIRST_DAY_OF_WEEK_ITEM_COUNT_COLLAPSED = FIRST_DAY_OF_WEEK_ITEM_SUNDAY, -#ifdef _ENABLE_IMPORT_EXPORT_ IMPORT_EXPORT_ITEM_IMPORT = 0, -// IMPORT_EXPORT_ITEM_EXPORT, + IMPORT_EXPORT_ITEM_EXPORT, IMPORT_EXPORT_ITEM_COUNT -#endif }; static const int H_ITEM = 112; @@ -95,6 +90,8 @@ SettingForm::SettingForm(void) , __pLabelLockTimeZone(null) , __pLabelFirstDayOfWeek(null) , __pLabelFirstDayOfWeekExpandIcon(null) + , __pCalendarSelectorPopup(null) + , __exportCalendarId(INVALID_RECORD_ID) , __descriptionItemHeight(-1) , __isLockTimeZoneSet(false) , __isFirstDayOfWeekSelectionItemExpanded(false) @@ -123,51 +120,121 @@ SettingForm::OnInitializing(void) __pTableView->SetGroupedLookEnabled(true); __pTableView->AddSectionTableViewItemEventListener(*this); + __pCalendarSelectorPopup = new (std::nothrow) CalendarSelectorPopup(); + __pCalendarSelectorPopup->Initialize(); + return E_SUCCESS; } result SettingForm::OnTerminating(void) { + delete __pCalendarSelectorPopup; return E_SUCCESS; } void +SettingForm::OnUserEventReceivedN(RequestId requestId, IList* pArgs) +{ + switch (requestId) + { + case IDA_CALENDAR_SELECTOR_POPUP_DONE: + if (pArgs != null) + { + __exportCalendarId = static_cast(pArgs->GetAt(0))->value; + + String mimeType = MIME_TYPE_DIRECTORY; + AppControl* pApp = AppManager::FindAppControlN(L"tizen.filemanager", ID_OPERATION_PICK); + if (pApp != null) + { + pApp->Start(null, &mimeType, null, this); + delete pApp; + } + + // Todo: Change upper codes to below codes. +// String mimeType = MIME_TYPE_DIRECTORY; +// AppControl::FindAndStart(ID_OPERATION_PICK, null, &mimeType, null, null, this); + } + break; + } + + if (pArgs != null) + { + pArgs->RemoveAll(true); + delete pArgs; + } +} + +void SettingForm::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData) { AppLogDebug("Enter."); AppLogDebug("AppId : %ls", appId.GetPointer()); AppLogDebug("OperationId : %ls", operationId.GetPointer()); - if (appControlResult == APP_CTRL_RESULT_SUCCEEDED) + TryReturnVoid(appControlResult == APP_CTRL_RESULT_SUCCEEDED, "[E_FAILURE] AppControl returns exceptions(%d).", appControlResult); + + if (operationId.Equals(ID_OPERATION_PICK, false) == true && pExtraData != null) { - if (operationId.Equals(ID_OPERATION_PICK, false) == true && pExtraData != null) + const IList* pPaths = dynamic_cast(pExtraData->GetValue(String(KEY_DATA_SELECTED))); + if ((pPaths != null && pPaths->GetCount() > 0) == false) { - const IList* pPaths = dynamic_cast(pExtraData->GetValue(String(KEY_DATA_SELECTED))); - if (pPaths != null && pPaths->GetCount() > 0) + MessageBox msgBox; + msgBox.Construct(L"", ResourceManager::GetString(IDS_RSSR_BODY_FAILED_TO_IMPORT_FILE), MSGBOX_STYLE_NONE, MESSAGE_BOX_TIME_OUT); + int modalResult; + msgBox.ShowAndWait(modalResult); + AppLogDebug("Exit."); + return; + } + + IEnumerator* pEnum = pPaths->GetEnumeratorN(); + while (pEnum->MoveNext() == E_SUCCESS) + { + const String* pPath = dynamic_cast(pEnum->GetCurrent()); + if (pPath != null) { - IList* pList = ResourceManager::ParseVcsFileN(static_cast(*pPaths->GetAt(0))); - if (pList != null) + Directory dir; + File file; + if (dir.Construct(*pPath) == E_SUCCESS) { - SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_IMPORT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList); + // Export Calendar + if (ExportCalendar(__exportCalendarId, *pPath) == E_SUCCESS) + { + MessageBox msgBox; + msgBox.Construct(L"", ResourceManager::GetString(IDS_EMAIL_BODY_COMPLETE), MSGBOX_STYLE_NONE, MESSAGE_BOX_TIME_OUT); + int modalResult; + msgBox.ShowAndWait(modalResult); + } + else + { + MessageBox msgBox; + msgBox.Construct(L"", ResourceManager::GetString(IDS_COM_POP_SAVING_FAILED), MSGBOX_STYLE_NONE, MESSAGE_BOX_TIME_OUT); + int modalResult; + msgBox.ShowAndWait(modalResult); + } + __exportCalendarId = INVALID_RECORD_ID; } else { - MessageBox msgBox; - msgBox.Construct(L"", ResourceManager::GetString(IDS_RSSR_BODY_FAILED_TO_IMPORT_FILE), MSGBOX_STYLE_NONE, MESSAGE_BOX_TIME_OUT); - int modalResult; - msgBox.ShowAndWait(modalResult); + // Import File + IList* pList = ResourceManager::ParseVcsFileN(static_cast(*pPaths->GetAt(0))); + if (pList != null) + { + SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_IMPORT, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList); + } + else + { + MessageBox msgBox; + msgBox.Construct(L"", ResourceManager::GetString(IDS_RSSR_BODY_FAILED_TO_IMPORT_FILE), MSGBOX_STYLE_NONE, MESSAGE_BOX_TIME_OUT); + int modalResult; + msgBox.ShowAndWait(modalResult); + } } } - else - { - MessageBox msgBox; - msgBox.Construct(L"", ResourceManager::GetString(IDS_RSSR_BODY_FAILED_TO_IMPORT_FILE), MSGBOX_STYLE_NONE, MESSAGE_BOX_TIME_OUT); - int modalResult; - msgBox.ShowAndWait(modalResult); - } } + delete pEnum; } + AppLogDebug("Exit."); } @@ -202,10 +269,8 @@ SettingForm::GetItemCount(int sectionIndex) // return (__isLockTimeZoneSet == true) ? LOCK_TIME_ZONE_ITEM_COUNT_ON : LOCK_TIME_ZONE_ITEM_COUNT_OFF; case GROUP_FIRST_DAY_OF_WEEK: return (__isFirstDayOfWeekSelectionItemExpanded == true) ? FIRST_DAY_OF_WEEK_ITEM_COUNT_EXPANDED : FIRST_DAY_OF_WEEK_ITEM_COUNT_COLLAPSED; -#ifdef _ENABLE_IMPORT_EXPORT_ case GROUP_IMPORT_EXPORT: return IMPORT_EXPORT_ITEM_COUNT; -#endif } return 0; } @@ -241,19 +306,17 @@ SettingForm::CreateItem(int sectionIndex, int itemIndex, int itemWidth) break; } break; -#ifdef _ENABLE_IMPORT_EXPORT_ case GROUP_IMPORT_EXPORT: switch (itemIndex) { case IMPORT_EXPORT_ITEM_IMPORT: pItem = CreateImportItemN(itemWidth); break; -// case IMPORT_EXPORT_ITEM_EXPORT: -// pItem = CreateExportItemN(itemWidth); -// break; + case IMPORT_EXPORT_ITEM_EXPORT: + pItem = CreateExportItemN(itemWidth); + break; } break; -#endif } return pItem; @@ -403,7 +466,6 @@ SettingForm::OnSectionTableViewItemStateChanged(SectionTableView& tableView, int } } break; -#ifdef _ENABLE_IMPORT_EXPORT_ case GROUP_IMPORT_EXPORT: switch (itemIndex) { @@ -422,11 +484,11 @@ SettingForm::OnSectionTableViewItemStateChanged(SectionTableView& tableView, int // AppControl::FindAndStart(ID_OPERATION_PICK, null, &mimeType, null, null, this); break; } -// case IMPORT_EXPORT_ITEM_EXPORT: -// break; + case IMPORT_EXPORT_ITEM_EXPORT: + __pCalendarSelectorPopup->RequestCalendar(CALENDAR_SELECTOR_POPUP_STYLE_ALL, this, true); + break; } break; -#endif } break; case TABLE_VIEW_ITEM_STATUS_CHECKED: @@ -724,3 +786,98 @@ SettingForm::ExpandGroup(int sectionIndex) break; } } + +result +SettingForm::ExportCalendar(RecordId calendarId, const String& path) +{ + Calendarbook calendarbook; + calendarbook.Construct(); + + Calendar* pCalendar = calendarbook.GetCalendarN(calendarId); + TryReturn(pCalendar != null, E_FAILURE, "[E_FAILURE] Unable to get calendar."); + + result r = E_SUCCESS; + IList* pEvents = null; + IList* pTodos = null; + if ((pCalendar->GetItemType() & CALENDAR_ITEM_TYPE_EVENT_ONLY) != 0) + { + CalendarbookFilter filter(CB_FI_TYPE_EVENT); + filter.AppendInt(FI_CONJ_OP_NONE, EVENT_FI_PR_CALENDAR_ID, FI_CMP_OP_EQUAL, calendarId); + pEvents = calendarbook.SearchN(filter); + TryReturn(pEvents != null, E_FAILURE, "[E_FAILURE] Unable to get events from calendar(ID=%d).", calendarId); + } + + if ((pCalendar->GetItemType() & CALENDAR_ITEM_TYPE_TODO_ONLY) != 0) + { + CalendarbookFilter filter(CB_FI_TYPE_TODO); + filter.AppendInt(FI_CONJ_OP_NONE, TODO_FI_PR_CALENDAR_ID, FI_CMP_OP_EQUAL, calendarId); + pTodos = calendarbook.SearchN(filter); + TryCatch(pTodos != null, r = E_FAILURE, "[E_FAILURE] Unable to get todos from calendar(ID=%d).", calendarId); + } + + if (pEvents != null && pTodos != null) + { + result rTmp = Calendarbook::ExportEventsToVcalendar(*pEvents, GetExportFilePath(path, pCalendar->GetName(), L"Event")); + if (rTmp != E_SUCCESS) + { + r = rTmp; + AppLogDebug("[%s] Unable to export events.", GetErrorMessage(r)); + } + + rTmp = Calendarbook::ExportTodosToVcalendar(*pTodos, GetExportFilePath(path, pCalendar->GetName(), L"Todo")); + if (rTmp != E_SUCCESS) + { + r = rTmp; + AppLogDebug("[%s] Unable to export todos.", GetErrorMessage(r)); + } + } + else if (pEvents != null) + { + r = Calendarbook::ExportEventsToVcalendar(*pEvents, GetExportFilePath(path, pCalendar->GetName(), L"")); + AppLogDebugIf(r != E_SUCCESS, "[%s] Unable to export events.", GetErrorMessage(r)); + } + else + { + r = Calendarbook::ExportTodosToVcalendar(*pTodos, GetExportFilePath(path, pCalendar->GetName(), L"")); + AppLogDebugIf(r != E_SUCCESS, "[%s] Unable to export todos.", GetErrorMessage(r)); + } + +CATCH: + if (pEvents != null) + { + pEvents->RemoveAll(true); + delete pEvents; + } + if (pTodos != null) + { + pTodos->RemoveAll(true); + delete pTodos; + } + delete pCalendar; + return r; +} + +const String +SettingForm::GetExportFilePath(const String& path, const String& calendarName, const String& ending) +{ + String tmpPath = path; + if (tmpPath.EndsWith(L"/") == false) + { + tmpPath.Append(L"/"); + } + + tmpPath.Append(calendarName); + tmpPath.Append(L"-"); + tmpPath.Append(ending); + + int count = 0; + String vcsPath = tmpPath + L".vcs"; + while (File::IsFileExist(vcsPath) == true) + { + String countString; + countString.Format(5, L"-%03d", ++count); + vcsPath = tmpPath + countString + L".vcs"; + } + + return vcsPath; +} -- 2.7.4