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 RemoveControl(__pIconListView);
101 __pIconListView = null;
103 if (createIconListView)
105 CreateIconListView();
109 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
112 Rectangle clientRect = GetClientAreaBounds();
113 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
115 int bitmapWidth = pBitmp->GetWidth();
116 int bitmapHeight = pBitmp->GetHeight();
117 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
118 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
119 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
121 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
122 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
124 Label* pLabel = new (std::nothrow) Label();
125 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
126 pLabel->SetName(NO_CONTENTS);
127 pLabel->SetBackgroundBitmap(*pBitmp);
129 yPos = yPos + bitmapHeight;
131 Label* pLabelNoContents = new (std::nothrow) Label();
132 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
133 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
134 pLabelNoContents->SetTextColor(textColor);
135 pLabelNoContents->SetText(labelText);
138 AddControl(pLabelNoContents);
144 WallpaperAlbumListDetailForm::GetHeightForStringArea(const Tizen::Base::String source, int width, int fontSize) const
150 int lineCount = LINE_COUNT_DEFAULT;
151 int margin = BASE_FORM_DEFAULT_MARGIN + RELATIVE_LAYOUT_RIGHT_MARGIN;
152 if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
154 OrientationStatus orientationStatus = GetOrientationStatus();
155 if (((orientationStatus == ORIENTATION_STATUS_PORTRAIT)
156 || (orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE))
157 && (fontSize == FONT_MAIN_TEXT_SIZE_HUGE))
159 width -= W_HUGE_SIZE_PORTRAIT_TEXT_GAP;
161 else if (((orientationStatus == ORIENTATION_STATUS_LANDSCAPE)
162 || (orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE))
163 && (fontSize == FONT_MAIN_TEXT_SIZE_HUGE))
165 width -= W_HUGE_SIZE_LANDSCAPE_TEXT_GAP;
167 width -= W_LARGE_SIZE_TEXT_GAP;
169 int boudwidth = width - margin;
170 font.Construct(FONT_STYLE_PLAIN, fontSize);
172 for (int i = 0; i < source.GetLength(); i++)
174 temp.Append(source[i]);
175 font.GetTextExtent(temp, temp.GetLength(), dim);
176 if (dim.width > boudwidth)
179 temp.Append(source[i]);
184 return dim.height * lineCount;
188 WallpaperAlbumListDetailForm::CreateHeader(const Tizen::Base::String& textTitle)
190 Header* pHeader = GetHeader();
192 pHeader->SetStyle(HEADER_STYLE_TITLE);
193 pHeader->SetTitleText(textTitle);
197 WallpaperAlbumListDetailForm::CreateFooter(void)
199 Footer* pFooter = GetFooter();
202 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
205 SetFormBackEventListener(this);
209 WallpaperAlbumListDetailForm::OnInitializing(void)
211 __pPresentationModel = WallpaperAlbumListPresentationModel::GetInstance();
217 WallpaperAlbumListDetailForm::OnTerminating(void)
219 AppLogDebug("ENTER");
221 if (__pPresentationModel != null)
223 __pPresentationModel = null;
226 if (__pIconListView != null)
228 __pIconListView = null;
231 if (__pAlbumPathList != null)
233 delete __pAlbumPathList;
234 __pAlbumPathList = null;
241 WallpaperAlbumListDetailForm::GetItemCount(void)
247 WallpaperAlbumListDetailForm::CreateItem(int index)
249 AppLogDebug("ENTER : index(%d)", index);
251 Bitmap* pBitmap = __pPresentationModel->CreateDetailMergeBitmapN(index);
255 IconListViewItem* pIconListview = new (std::nothrow) IconListViewItem();
256 pIconListview->Construct(*pBitmap);
260 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
261 return pIconListview;
264 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
269 WallpaperAlbumListDetailForm::DeleteItem(int index, IconListViewItem* pItem)
276 WallpaperAlbumListDetailForm::OnIconListViewItemStateChanged(IconListView& view, int index, IconListViewItemStatus status)
278 AppLogDebug("ENTER");
280 if (__isRunningAppControl)
282 AppLogDebug("busy status");
286 if (status == ICON_LIST_VIEW_ITEM_SELECTED)
288 IList* pContentIdList = __pPresentationModel->GetContentIdList();
289 __pContentId = static_cast<ContentId*>(pContentIdList->GetAt(index));
291 extraData.Construct();
292 String typeKey = L"http://tizen.org/appcontrol/data/image/crop_mode";
293 String typeVal = L"fit_to_screen";
294 extraData.Add(&typeKey, &typeVal);
296 ContentManager pContentManager;
297 pContentManager.Construct();
298 ImageContentInfo* pImageContentInfo = static_cast<ImageContentInfo*>(pContentManager.GetContentInfoN(*__pContentId));
300 Rectangle rect = GetClientAreaBounds();
301 if (pImageContentInfo == null)
303 AppLogDebug("pImageContentInfo is null");
306 String uri = String(L"file://") + pImageContentInfo->GetContentPath();
308 AppControl* pAc = AppManager::FindAppControlN(IMAGE_VIEWER_APP_ID, IMAGE_VIEWER_CROP_OPERATION_ID);
311 if (pAc->Start(&uri, null, &extraData, this) == E_SUCCESS)
313 __isRunningAppControl = true;
319 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
323 WallpaperAlbumListDetailForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
325 if (__isRunningAppControl)
327 AppLogDebug("busy status");
330 SceneManager* pSceneManager = SceneManager::GetInstance();
331 AppAssert(pSceneManager);
333 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
337 WallpaperAlbumListDetailForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
341 __pAlbumPathList = static_cast<ArrayList*>(pArgs);
344 if (__pPresentationModel == null)
346 __pPresentationModel = WallpaperAlbumListPresentationModel::GetInstance();
348 SetAllAlbumPathList();
349 __pPresentationModel->InitializeFileList(__pAlbumPathList);
350 __itemCount = __pPresentationModel->GetFileCount();
352 UpdateIconListView();
353 CreateHeader(ResourceManager::GetString(L"IDS_MP_BODY_ADD_IMAGE"));
358 WallpaperAlbumListDetailForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
363 WallpaperAlbumListDetailForm::CreateIconListView(void)
365 int itemRectLineSize = 0;
367 if (__itemCount < FOLDER_BITMAP_MAX)
369 itemRectLineSize = MAX_UNDER_FILE_SIZE;
373 itemRectLineSize = MAX_OVER_FILE_SIZE;
375 Dimension itemSize(itemRectLineSize, itemRectLineSize);
377 __pIconListView = new (std::nothrow) IconListView();
378 __pIconListView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), itemSize);
379 __pIconListView->SetItemProvider(*this);
380 __pIconListView->SetItemBorderStyle(ICON_LIST_VIEW_ITEM_BORDER_STYLE_NONE);
381 __pIconListView->SetTouchAnimationEnabled(false);
382 __pIconListView->AddIconListViewItemEventListener(*this);
384 AddControl(__pIconListView);
390 WallpaperAlbumListDetailForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
392 if (__pIconListView == null)
394 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
397 Rectangle clientRect = GetClientAreaBounds();
398 Rectangle labelBound = pLabel->GetBounds();
400 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
401 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
403 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
404 yPos = yPos + pLabel->GetBounds().height;
405 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
406 if (pTextLabel != null)
408 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
414 __pIconListView->SetBounds(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
420 WallpaperAlbumListDetailForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
422 if (requestId == REFRESH_REQUEST_EVENT)
425 __isRunningAppControl = false;
427 __pPresentationModel->InitializeAlbumInfoList();
428 SetAllAlbumPathList();
429 __pPresentationModel->InitializeFileList(__pAlbumPathList);
430 __itemCount = __pPresentationModel->GetFileCount();
431 UpdateIconListView();
434 pArgs->RemoveAll(true);
441 WallpaperAlbumListDetailForm::OnAppControlCompleteResponseReceived(const AppId& appId, const Tizen::Base::String& operationId, AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
443 if (appId.Equals(IMAGE_VIEWER_APP_ID)
444 && operationId.Equals(IMAGE_VIEWER_CROP_OPERATION_ID))
446 if (appControlResult == APP_CTRL_RESULT_SUCCEEDED)
449 AppLogDebug("Image crop succeeded.");
450 String* pStr = WallpaperAlbumListPresentationModel::GetInstance()->GetHomeLockArgument();
451 if (pStr->Equals(L"0", true))
455 else if (pStr->Equals(L"1", true))
459 else if (pStr->Equals(L"2", true))
465 IMapEnumerator* pEnum = pExtraData->GetMapEnumeratorN();
466 while (pEnum->MoveNext() == E_SUCCESS)
468 String* pKey = dynamic_cast<String*>(pEnum->GetKey());
469 if (pKey != null && *pKey == L"http://tizen.org/appcontrol/data/selected")
471 IList* pValueList = dynamic_cast<IList*>(pEnum->GetValue());
474 String dstPath = Application::GetInstance()->GetAppSharedPath() + PATH_DATA_DIRECTORY;
475 String srcPath = L"";
476 String srcFileExtention = L"";
477 String* pSrcPath = dynamic_cast<String*>(pValueList->GetAt(0));
478 if (pSrcPath != null)
482 if (srcPath.IsEmpty() == false)
484 srcFileExtention = File::GetFileExtension(srcPath);
491 dstPath.Append(L"home.");
492 dstPath.Append(srcFileExtention);
493 File::Copy(srcPath, dstPath, false);
494 AppLog("FilePath = %S", dstPath.GetPointer());
495 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN, dstPath) != E_SUCCESS)
497 AppLogDebug("Wallpaper Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
504 dstPath.Append(L"/lock.");
505 dstPath.Append(srcFileExtention);
506 File::Copy(srcPath, dstPath, false);
508 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN_LOCK, dstPath) != E_SUCCESS)
510 AppLogDebug("Wallpaper Lock Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
517 dstPath.Append(L"homelock.");
518 dstPath.Append(srcFileExtention);
519 File::Copy(srcPath, dstPath, false);
521 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN, dstPath) != E_SUCCESS)
523 AppLogDebug("Wallpaper Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
526 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN_LOCK, dstPath) != E_SUCCESS)
528 AppLogDebug("Wallpaper Lock Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
536 SceneManager* pSceneManager = SceneManager::GetInstance();
537 AppAssert(pSceneManager);
538 IListT<SceneId>* sceneList = pSceneManager->GetSceneHistoryN();
539 pSceneManager->ClearSceneHistory();
541 while (sceneIndex < sceneList->GetCount())
543 String* pSceneId = new (std::nothrow) String();
544 sceneList->GetAt(sceneIndex++, *pSceneId);
545 if (pSceneId->Equals(IDSCN_WALLPAPER_ALBUM_LIST, true) == true)
547 if (pSceneManager->IsSceneAlive(*pSceneId) == true)
549 pSceneManager->DestroyScene(*pSceneId);
555 pSceneManager->AddToSceneHistory(*pSceneId);
558 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
566 else if (appControlResult == APP_CTRL_RESULT_FAILED)
568 AppLog("Image crop failed.");
570 else if (appControlResult == APP_CTRL_RESULT_CANCELED)
572 AppLog("Image crop was canceled.");
574 else if (appControlResult == APP_CTRL_RESULT_TERMINATED)
576 AppLog("Image crop was terminated.");
578 else if (appControlResult == APP_CTRL_RESULT_ABORTED)
580 AppLog("Image crop was aborted.");
583 __isRunningAppControl = false;
589 WallpaperAlbumListDetailForm::SetAllAlbumPathList(void)
591 String isAllAlbum = *static_cast<String*>(__pAlbumPathList->GetAt(0));
593 String allAlbumsString = ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS");
594 if (isAllAlbum.Equals(allAlbumsString, true) == false)
596 AppLogDebug("__pAlbumPathList is not AllAlbum");
600 delete __pAlbumPathList;
601 __pAlbumPathList = null;
602 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
603 if (pAlbumInfoList == null)
605 AppLogDebug("pAlbumInfoList is null");
609 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(0));
610 if (pAlbumInfo == null)
612 AppLogDebug("pAlbumInfo is null");
616 ArrayList* pAlbumPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
617 pAlbumPathList->Construct();
618 pAlbumPathList->Add(new (std::nothrow) String(allAlbumsString));
619 for (int i = 0; i < pAlbumInfo->GetDirectoryCount(); i++)
621 pAlbumPathList->Add(*(new (std::nothrow) String(pAlbumInfo->GetDirectory(i))));
623 __pAlbumPathList = pAlbumPathList;