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 StWallpaperImageSelectForm.cpp
19 * @brief This is the implementation file for WallpaperImageSelectForm class.
24 #include "StSettingScenesList.h"
25 #include "StWallpaperAlbumListPresentationModel.h"
26 #include "StWallpaperImageSelectForm.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 IDA_POPUP_ACTION_ID_BASE = 200;
40 static const int IDA_FOOTER_SAVE = IDA_POPUP_ACTION_ID_BASE + 1;
42 WallpaperImageSelectForm::WallpaperImageSelectForm(void)
48 WallpaperImageSelectForm::~WallpaperImageSelectForm(void)
53 WallpaperImageSelectForm::Initialize(void)
56 Form::Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER);
57 SetOrientationAutoMode();
58 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
59 return GetLastResult();
63 WallpaperImageSelectForm::SetOrientationAutoMode(void)
65 this->SetOrientation(ORIENTATION_AUTOMATIC_FOUR_DIRECTION);
66 this->AddOrientationEventListener(*this);
70 WallpaperImageSelectForm::CreateFooter(void)
72 Footer* pFooter = GetFooter();
75 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
77 FooterItem footerSave;
78 footerSave.Construct(IDA_FOOTER_SAVE);
79 footerSave.SetText(ResourceManager::GetString(L"IDS_ST_BODY_SAVE"));
81 pFooter->AddItem(footerSave);
82 pFooter->AddActionEventListener(*this);
83 pFooter->SetItemEnabled(0, true);
85 SetFormBackEventListener(this);
89 WallpaperImageSelectForm::OnInitializing(void)
91 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE);
93 SetOrientationAutoMode();
98 WallpaperImageSelectForm::OnTerminating(void)
100 AppLogDebug("ENTER");
105 WallpaperImageSelectForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
107 SceneManager* pSceneManager = SceneManager::GetInstance();
108 AppAssert(pSceneManager);
110 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
114 WallpaperImageSelectForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
118 case IDA_FOOTER_SAVE:
120 ContentManager pContentManager;
121 pContentManager.Construct();
122 ImageContentInfo* pImageContentInfo = static_cast<ImageContentInfo*>(pContentManager.GetContentInfoN(*__pContentId));
124 if (pImageContentInfo == null)
126 MessageBox messageBox;
127 int result = E_SUCCESS;
129 messageBox.Construct(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_COM_POP_FAILED"), MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_2_SEC);
130 messageBox.ShowAndWait(result);
132 SceneManager* pSceneManager = SceneManager::GetInstance();
133 AppAssert(pSceneManager);
135 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
139 String dstPath = Application::GetInstance()->GetAppSharedPath() + PATH_DATA_DIRECTORY;
140 String srcPath = pImageContentInfo->GetContentPath();
141 String srcFileExtention = File::GetFileExtension(srcPath);
143 ArrayList* aList = new (std::nothrow) ArrayList(SingleObjectDeleter);
145 aList->Add(new (std::nothrow) String(Integer::ToString(__argIndex)));
151 dstPath.Append(L"home.");
152 dstPath.Append(srcFileExtention);
153 File::Copy(srcPath, dstPath, false);
155 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN, dstPath) != E_SUCCESS)
157 AppLogDebug("Wallpapaer Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
164 dstPath.Append(L"lock.");
165 dstPath.Append(srcFileExtention);
166 File::Copy(srcPath, dstPath, false);
168 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN_LOCK, dstPath) != E_SUCCESS)
170 AppLogDebug("Wallpapaer Lock Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
177 dstPath.Append(L"homelock.");
178 dstPath.Append(srcFileExtention);
179 File::Copy(srcPath, dstPath, false);
181 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN, dstPath) != E_SUCCESS)
183 AppLogDebug("Wallpapaer Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
186 if (SettingInfo::SetValue(RUNTIME_INFO_KEY_WALLPAPER_SCREEN_LOCK, dstPath) != E_SUCCESS)
188 AppLogDebug("Wallpapaer Lock Screen SetValue is Fail [%s]", GetErrorMessage(GetLastResult()));
197 SceneManager* pSceneManager = SceneManager::GetInstance();
198 AppAssert(pSceneManager);
199 IListT<SceneId>* sceneList = pSceneManager->GetSceneHistoryN();
200 pSceneManager->ClearSceneHistory();
202 while (sceneIndex < sceneList->GetCount())
204 String* pSceneId = new (std::nothrow) String();
205 sceneList->GetAt(sceneIndex++, *pSceneId);
206 if ((pSceneId->Equals(IDSCN_WALLPAPER_ALBUM_LIST, true) == true)
207 || (pSceneId->Equals(IDSCN_WALLPAPER_ALBUM_LIST_DETAIL, true) == true))
209 if (pSceneManager->IsSceneAlive(*pSceneId) == true)
211 pSceneManager->DestroyScene(*pSceneId);
217 pSceneManager->AddToSceneHistory(*pSceneId);
220 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), aList);
226 AppLogDebug("no search Tab Selected %d", actionId);
233 WallpaperImageSelectForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
237 String* pStr = WallpaperAlbumListPresentationModel::GetInstance()->GetHomeLockArgument();
238 if (pStr->Equals(L"0", true))
242 else if (pStr->Equals(L"1", true))
246 else if (pStr->Equals(L"2", true))
250 __pContentId = static_cast<ContentId*>(pArgs->GetAt(0));
252 if (__pContentId != null)
259 WallpaperImageSelectForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
264 WallpaperImageSelectForm::CreateImage(void)
266 ContentManager pContentManager;
267 pContentManager.Construct();
268 ImageContentInfo* pImageContentInfo = static_cast<ImageContentInfo*>(pContentManager.GetContentInfoN(*__pContentId));
270 if (pImageContentInfo == null)
272 AppLogDebug("pImageContentInfo is null");
276 Rectangle rect = GetClientAreaBounds();
277 Bitmap* pBitmap = ResourceManager::GetApplicationBitmapN(pImageContentInfo->GetContentPath());
278 Rectangle clientRect = GetClientAreaBounds();
280 float bitmapWidthRate = rect.width / (float)pBitmap->GetWidth();
281 float bitmapHeightRate = rect.height / (float)pBitmap->GetHeight();
284 int bitmapHeight = 0;
286 if (bitmapWidthRate > bitmapHeightRate)
288 bitmapHeight = pBitmap->GetHeight() * bitmapHeightRate;
289 bitmapWidth = pBitmap->GetWidth() * bitmapHeightRate;
293 bitmapHeight = pBitmap->GetHeight() * bitmapWidthRate;
294 bitmapWidth = pBitmap->GetWidth() * bitmapWidthRate;
296 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
297 int yPos = (clientRect.height / LINE_COUNT_2) - (bitmapHeight / DIVIDE_BY_TWO);
299 Label* pLabel = new (std::nothrow) Label();
300 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
301 pLabel->SetName(NO_CONTENTS);
302 pLabel->SetBackgroundBitmap(*pBitmap);
308 WallpaperImageSelectForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
310 Label* pLabel = static_cast<Label*>(GetControl(NO_CONTENTS, true));
311 Rectangle rect = GetClientAreaBounds();
312 ContentManager pContentManager;
313 pContentManager.Construct();
314 ImageContentInfo* pImageContentInfo = static_cast<ImageContentInfo*>(pContentManager.GetContentInfoN(*__pContentId));
315 Bitmap* pBitmap = ResourceManager::GetApplicationBitmapN(pImageContentInfo->GetContentPath());
316 Rectangle clientRect = GetClientAreaBounds();
318 float bitmapWidthRate = rect.width / (float)pBitmap->GetWidth();
319 float bitmapHeightRate = rect.height / (float)pBitmap->GetHeight();
322 int bitmapHeight = 0;
324 if (bitmapWidthRate > bitmapHeightRate)
326 bitmapHeight = pBitmap->GetHeight() * bitmapHeightRate;
327 bitmapWidth = pBitmap->GetWidth() * bitmapHeightRate;
331 bitmapHeight = pBitmap->GetHeight() * bitmapWidthRate;
332 bitmapWidth = pBitmap->GetWidth() * bitmapWidthRate;
334 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
335 int yPos = (clientRect.height / LINE_COUNT_2) - (bitmapHeight / DIVIDE_BY_TWO);
336 pLabel->SetBounds(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight));