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.
18 * @file StWallpaperAlbumListDetailForm.cpp
19 * @brief This is the implementation file for WallpaperAlbumListDetailForm class.
24 #include "StSettingScenesList.h"
26 #include "StWallpaperAlbumListDetailForm.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Content;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Io;
34 using namespace Tizen::System;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
39 static const int MAX_UNDER_FILE_SIZE = 334;
40 static const int MAX_OVER_FILE_SIZE = 158;
41 static const int FOLDER_BITMAP_MAX = 6;
42 static const int W_LARGE_SIZE_TEXT_GAP = 110;
43 static const int W_HUGE_SIZE_PORTRAIT_TEXT_GAP = 90;
44 static const int W_HUGE_SIZE_LANDSCAPE_TEXT_GAP = 220;
45 static const int LINE_COUNT_DEFAULT = 1;
47 static const int BASE_FORM_DEFAULT_MARGIN = 32;
49 static const String IMAGE_VIEWER_APP_ID = L"tizen.imageviewer";
50 static const String IMAGE_VIEWER_CROP_OPERATION_ID = L"http://tizen.org/appcontrol/operation/image/crop";
52 WallpaperAlbumListDetailForm::WallpaperAlbumListDetailForm(void)
53 : __isRunningAppControl(false)
56 , __pPresentationModel(null)
57 , __pIconListView(null)
58 , __pAlbumPathList(null)
62 WallpaperAlbumListDetailForm::~WallpaperAlbumListDetailForm(void)
67 WallpaperAlbumListDetailForm::Initialize(void)
70 Form::Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
71 SetOrientationAutoMode();
72 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 return GetLastResult();
77 WallpaperAlbumListDetailForm::SetOrientationAutoMode(void)
79 this->SetOrientation(ORIENTATION_AUTOMATIC_FOUR_DIRECTION);
80 this->AddOrientationEventListener(*this);
84 WallpaperAlbumListDetailForm::UpdateIconListView(void)
86 bool createIconListView = true;
89 createIconListView = false;
91 if (__pIconListView != null)
93 if (createIconListView)
95 __pIconListView->UpdateList();
100 int controlCount = GetControlCount();
101 for (int i = 0; i < controlCount; i++)
103 RemoveControl(GetControl(0));
105 // RemoveAllControls();
107 if (createIconListView)
109 CreateIconListView();
113 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
116 Rectangle clientRect = GetClientAreaBounds();
117 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
119 int bitmapWidth = pBitmp->GetWidth();
120 int bitmapHeight = pBitmp->GetHeight();
121 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
122 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
123 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
125 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
126 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
128 Label* pLabel = new (std::nothrow) Label();
129 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
130 pLabel->SetName(NO_CONTENTS);
131 pLabel->SetBackgroundBitmap(*pBitmp);
133 yPos = yPos + bitmapHeight;
135 Label* pLabelNoContents = new (std::nothrow) Label();
136 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
137 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
138 pLabelNoContents->SetTextColor(textColor);
139 pLabelNoContents->SetText(labelText);
142 AddControl(pLabelNoContents);
148 WallpaperAlbumListDetailForm::GetHeightForStringArea(const Tizen::Base::String source, int width, int fontSize) const
154 int lineCount = LINE_COUNT_DEFAULT;
155 int margin = BASE_FORM_DEFAULT_MARGIN + RELATIVE_LAYOUT_RIGHT_MARGIN;
156 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
158 OrientationStatus orientationStatus = GetOrientationStatus();
159 if (((orientationStatus == ORIENTATION_STATUS_PORTRAIT)
160 || (orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE))
161 && (fontSize == FONT_MAIN_TEXT_SIZE_HUGE))
163 width -= W_HUGE_SIZE_PORTRAIT_TEXT_GAP;
165 else if (((orientationStatus == ORIENTATION_STATUS_LANDSCAPE)
166 || (orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
167 && (fontSize == FONT_MAIN_TEXT_SIZE_HUGE))
169 width -= W_HUGE_SIZE_LANDSCAPE_TEXT_GAP;
171 width -= W_LARGE_SIZE_TEXT_GAP;
173 int boudwidth = width - margin;
174 font.Construct(FONT_STYLE_PLAIN, fontSize);
176 for (int i = 0; i < source.GetLength(); i++)
178 temp.Append(source[i]);
179 font.GetTextExtent(temp, temp.GetLength(), dim);
180 if (dim.width > boudwidth)
183 temp.Append(source[i]);
188 return dim.height * lineCount;
192 WallpaperAlbumListDetailForm::CreateHeader(const Tizen::Base::String& textTitle)
194 Header* pHeader = GetHeader();
196 pHeader->SetStyle(HEADER_STYLE_TITLE);
197 pHeader->SetTitleText(textTitle);
201 WallpaperAlbumListDetailForm::CreateFooter(void)
203 Footer* pFooter = GetFooter();
206 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
207 pFooter->SetBackButton();
209 SetFormBackEventListener(this);
213 WallpaperAlbumListDetailForm::OnInitializing(void)
215 __pPresentationModel = WallpaperAlbumListPresentationModel::GetInstance();
217 AddFocusEventListener(*this);
223 WallpaperAlbumListDetailForm::OnTerminating(void)
225 AppLogDebug("ENTER");
227 if (__pPresentationModel != null)
229 __pPresentationModel = null;
232 if (__pIconListView != null)
234 __pIconListView = null;
237 if (__pAlbumPathList != null)
239 delete __pAlbumPathList;
240 __pAlbumPathList = null;
247 WallpaperAlbumListDetailForm::GetItemCount(void)
253 WallpaperAlbumListDetailForm::CreateItem(int index)
255 AppLogDebug("ENTER : index(%d)", index);
257 Bitmap* pBitmap = __pPresentationModel->CreateDetailMergeBitmapN(index);
261 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
262 pIconListview->Construct(*pBitmap);
266 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
267 return pIconListview;
270 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
275 WallpaperAlbumListDetailForm::DeleteItem(int index, IconListViewItem* pItem)
282 WallpaperAlbumListDetailForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
284 AppLogDebug("ENTER");
286 if (__isRunningAppControl)
288 AppLogDebug("busy status");
292 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
294 IList* pContentIdList = __pPresentationModel->GetContentIdList();
295 __pContentId = static_cast<ContentId*>(pContentIdList->GetAt(index));
297 extraData.Construct();
298 String typeKey = L"http://tizen.org/appcontrol/data/image/crop_mode";
299 String typeVal = L"fit_to_screen";
300 extraData.Add(&typeKey, &typeVal);
302 ContentManager pContentManager;
303 pContentManager.Construct();
304 ImageContentInfo* pImageContentInfo = static_cast<ImageContentInfo*>(pContentManager.GetContentInfoN(*__pContentId));
306 Rectangle rect = GetClientAreaBounds();
307 if (pImageContentInfo == null)
309 AppLogDebug("pImageContentInfo is null");
312 String uri = String(L"file://") + pImageContentInfo->GetContentPath();
314 AppControl* pAc = AppManager::FindAppControlN(IMAGE_VIEWER_APP_ID, IMAGE_VIEWER_CROP_OPERATION_ID);
317 if (pAc->Start(&uri, null, &extraData, this) == E_SUCCESS)
319 __isRunningAppControl = true;
325 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
329 WallpaperAlbumListDetailForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
331 if (__isRunningAppControl)
333 AppLogDebug("busy status");
336 SceneManager* pSceneManager = SceneManager::GetInstance();
337 AppAssert(pSceneManager);
339 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
343 WallpaperAlbumListDetailForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
347 __pAlbumPathList = static_cast<ArrayList*>(pArgs);
350 if (__pPresentationModel == null)
352 __pPresentationModel = WallpaperAlbumListPresentationModel::GetInstance();
354 SetAllAlbumPathList();
355 __pPresentationModel->InitializeFileList(__pAlbumPathList);
356 __itemCount = __pPresentationModel->GetFileCount();
358 UpdateIconListView();
359 CreateHeader(ResourceManager::GetString(L"IDS_MP_BODY_ADD_IMAGE"));
364 WallpaperAlbumListDetailForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
369 WallpaperAlbumListDetailForm::CreateIconListView(void)
371 int itemRectLineSize = 0;
373 if (__itemCount < FOLDER_BITMAP_MAX)
375 itemRectLineSize = MAX_UNDER_FILE_SIZE;
379 itemRectLineSize = MAX_OVER_FILE_SIZE;
381 Dimension itemSize(itemRectLineSize, itemRectLineSize);
383 __pIconListView = new (std::nothrow) IconListView();
384 __pIconListView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), itemSize);
385 __pIconListView->SetItemProvider(*this);
386 __pIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
387 __pIconListView->AddIconListViewItemEventListener(*this);
389 AddControl(__pIconListView);
395 WallpaperAlbumListDetailForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
397 if (__pIconListView == null)
399 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
402 Rectangle clientRect = GetClientAreaBounds();
403 Rectangle labelBound = pLabel->GetBounds();
405 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
406 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
408 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
409 yPos = yPos + pLabel->GetBounds().height;
410 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
411 if (pTextLabel != null)
413 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
419 __pIconListView->SetBounds(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
425 WallpaperAlbumListDetailForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
427 if (requestId == FRFRESH_REQUEST_EVENT)
429 __pPresentationModel->InitializeAlbumInfoList();
430 SetAllAlbumPathList();
431 __pPresentationModel->InitializeFileList(__pAlbumPathList);
432 __itemCount = __pPresentationModel->GetFileCount();
433 UpdateIconListView();
436 pArgs->RemoveAll(true);
443 WallpaperAlbumListDetailForm::OnAppControlCompleteResponseReceived(const AppId& appId, const Tizen::Base::String& operationId, AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
445 if (appId.Equals(IMAGE_VIEWER_APP_ID)
446 && operationId.Equals(IMAGE_VIEWER_CROP_OPERATION_ID))
448 if (appControlResult == APP_CTRL_RESULT_SUCCEEDED)
451 AppLogDebug("Image crop succeeded.");
452 String* pStr = WallpaperAlbumListPresentationModel::GetInstance()->GetHomeLockArgument();
453 if (pStr->Equals(L"0", true))
457 else if (pStr->Equals(L"1", true))
461 else if (pStr->Equals(L"2", true))
467 IMapEnumerator* pEnum = pExtraData->GetMapEnumeratorN();
468 while (pEnum->MoveNext() == E_SUCCESS)
470 String* pKey = dynamic_cast<String*>(pEnum->GetKey());
471 if (pKey != null && *pKey == L"http://tizen.org/appcontrol/data/selected")
473 IList* pValueList = dynamic_cast<IList*>(pEnum->GetValue());
476 String dstPath = Application::GetInstance()->GetAppSharedPath() + PATH_DATA_DIRECTORY;
477 String srcPath = L"";
478 String srcFileExtention = L"";
479 String* pSrcPath = dynamic_cast<String*>(pValueList->GetAt(0));
480 if (pSrcPath != null)
484 if (srcPath.IsEmpty() == false)
486 srcFileExtention = File::GetFileExtension(srcPath);
493 dstPath.Append(L"home.");
494 dstPath.Append(srcFileExtention);
495 File::Copy(srcPath, dstPath, false);
496 AppLog("FilePath = %S", dstPath.GetPointer());
497 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN, dstPath) != E_SUCCESS)
499 AppLogDebug("Wallpaper Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
506 dstPath.Append(L"/lock.");
507 dstPath.Append(srcFileExtention);
508 File::Copy(srcPath, dstPath, false);
510 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN_LOCK, dstPath) != E_SUCCESS)
512 AppLogDebug("Wallpaper Lock Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
519 dstPath.Append(L"homelock.");
520 dstPath.Append(srcFileExtention);
521 File::Copy(srcPath, dstPath, false);
523 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN, dstPath) != E_SUCCESS)
525 AppLogDebug("Wallpaper Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
528 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN_LOCK, dstPath) != E_SUCCESS)
530 AppLogDebug("Wallpaper Lock Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
538 SceneManager* pSceneManager = SceneManager::GetInstance();
539 AppAssert(pSceneManager);
540 IListT<SceneId>* sceneList = pSceneManager->GetSceneHistoryN();
541 pSceneManager->ClearSceneHistory();
543 while (sceneIndex < sceneList->GetCount())
545 String* pSceneId = new (std::nothrow) String();
546 sceneList->GetAt(sceneIndex++, *pSceneId);
547 if (pSceneId->Equals(IDSCN_WALLPAPER_ALBUM_LIST, true) == true)
549 if (pSceneManager->IsSceneAlive(*pSceneId) == true)
551 pSceneManager->DestroyScene(*pSceneId);
557 pSceneManager->AddToSceneHistory(*pSceneId);
560 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
568 else if (appControlResult == APP_CTRL_RESULT_FAILED)
570 AppLog("Image crop failed.");
572 else if (appControlResult == APP_CTRL_RESULT_CANCELED)
574 AppLog("Image crop was canceled.");
576 else if (appControlResult == APP_CTRL_RESULT_TERMINATED)
578 AppLog("Image crop was terminated.");
580 else if (appControlResult == APP_CTRL_RESULT_ABORTED)
582 AppLog("Image crop was aborted.");
585 __isRunningAppControl = false;
587 __pPresentationModel->InitializeAlbumInfoList();
588 SetAllAlbumPathList();
589 __pPresentationModel->InitializeFileList(__pAlbumPathList);
590 __itemCount = __pPresentationModel->GetFileCount();
591 UpdateIconListView();
596 WallpaperAlbumListDetailForm::SetAllAlbumPathList(void)
598 String isAllAlbum = *static_cast<String*>(__pAlbumPathList->GetAt(0));
600 String allAlbumsString = ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS");
601 if (isAllAlbum.Equals(allAlbumsString, true) == false)
603 AppLogDebug("__pAlbumPathList is not AllAlbum");
607 delete __pAlbumPathList;
608 __pAlbumPathList = null;
609 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
610 if (pAlbumInfoList == null)
612 AppLogDebug("pAlbumInfoList is null");
616 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(0));
617 if (pAlbumInfo == null)
619 AppLogDebug("pAlbumInfo is null");
623 ArrayList* pAlbumPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
624 pAlbumPathList->Construct();
625 pAlbumPathList->Add(*(new (std::nothrow) String(allAlbumsString)));
626 for (int i = 0; i < pAlbumInfo->GetDirectoryCount(); i++)
628 pAlbumPathList->Add(*(new (std::nothrow) String(pAlbumInfo->GetDirectory(i))));
630 __pAlbumPathList = pAlbumPathList;
634 WallpaperAlbumListDetailForm::OnFocusGained(const Tizen::Ui::Control& source)
636 __isRunningAppControl = false;
640 WallpaperAlbumListDetailForm::OnFocusLost(const Tizen::Ui::Control& source)