Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StHomeAndLockScreenForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                StHomeAndLockScreenForm.cpp
19  * @brief               This is the implementation file for HomeAndLockScreenForm class.
20  */
21
22 #include "StHomeAndLockScreenForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::App::Package;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::System;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 static const int ID_INDEX_HOME_SCREEN_WALLPAPER = 0;
37 static const int ID_INDEX_LOCK_SCREEN_WALLPAPER = 1;
38
39 static const int ID_GROUP_SCREEN_TYPE = 0;
40 static const int ID_ITEM_SCREEN_TYPE = 0;
41 static const int ID_GROUP_SCREEN_TYPE_ITEM_COUNT = 1;
42
43 static const int ID_GROUP_SCREEN_WALLPAPER = 1;
44 static const int ID_ITEM_SCREEN_WALLPAPER = 0;
45 static const int ID_GROUP_SCREEN_WALLPAPER_ITEM_COUNT = 1;
46
47 static const int ID_GROUP_COUNT = 2;
48 static const int ID_GROUP_MAX_ITEM_COUNT = 1;
49
50 HomeAndLockScreenForm::HomeAndLockScreenForm(void)
51 {
52 }
53
54 HomeAndLockScreenForm::~HomeAndLockScreenForm(void)
55 {
56 }
57
58 void
59 HomeAndLockScreenForm::CreateFooter(void)
60 {
61         Footer* pFooter = GetFooter();
62         AppAssert(pFooter);
63
64         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
65         pFooter->SetBackButton();
66         pFooter->AddActionEventListener(*this);
67
68         SetFormBackEventListener(this);
69 }
70
71 result
72 HomeAndLockScreenForm::OnInitializing(void)
73 {
74         return E_SUCCESS;
75 }
76
77 result
78 HomeAndLockScreenForm::OnTerminating(void)
79 {
80         if (__pTableView)
81         {
82                 __pTableView = null;
83                 SetFormBackEventListener(null);
84         }
85         return E_SUCCESS;
86 }
87
88 void
89 HomeAndLockScreenForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
90 {
91         if (pArgs != null)
92         {
93                 SetWallpaperIndex(*static_cast<String*>(pArgs->GetAt(0)));
94                 delete pArgs;
95                 AppLogDebug("Screen Mode[%d] ( home::0 / Lock::1 )", GetWallpaperIndex());
96
97                 CreateHeader(GetTitleText());
98                 CreateFooter();
99                 CreateTableView();
100                 AppLogDebug("ENTER");
101
102                 __pTableView->UpdateTableView();
103         }
104         else if (previousSceneId.Equals(IDSCN_SCREEN_TYPE, false))
105         {
106                 __pTableView->RefreshItem(0,0,TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
107         }
108         else
109         {
110                 AppLogDebug("pArgs Null");
111         }
112 }
113
114 void
115 HomeAndLockScreenForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
116 {
117 }
118
119 void
120 HomeAndLockScreenForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
121 {
122         SceneManager* pSceneManager = SceneManager::GetInstance();
123         AppAssert(pSceneManager);
124
125         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
126 }
127
128 int
129 HomeAndLockScreenForm::GetGroupCount(void)
130 {
131         AppLogDebug("ENTER");
132         return ID_GROUP_COUNT;
133 }
134
135 int
136 HomeAndLockScreenForm::GetItemCount(int groupIndex)
137 {
138         int itemCount = ID_GROUP_MAX_ITEM_COUNT;
139
140         AppLogDebug("GetItemCount %d", itemCount);
141
142         return itemCount;
143 }
144
145 TableViewGroupItem*
146 HomeAndLockScreenForm::CreateGroupItem(int groupIndex, int itemWidth)
147 {
148         AppLogDebug("ENTER");
149
150         int itemHeight = H_GROUP_INDEX_DEFAULT;;
151         int yItemOffset = 0;
152         Rectangle itemMainRectangle;
153         String groupText;
154         Label* pLabel = null;
155
156         groupText = GetGroupText(groupIndex);
157
158         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
159         itemMainRectangle.y = yItemOffset;
160         itemMainRectangle.width = itemWidth;
161         itemMainRectangle.height = itemHeight;
162
163         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
164
165         RelativeLayout relativeLayout;
166         relativeLayout.Construct();
167
168         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
169         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
170
171         pLabel = new (std::nothrow) Label();
172         pLabel->Construct(itemMainRectangle, groupText);
173         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
174         pLabel->SetTextVerticalAlignment(ALIGNMENT_BOTTOM);
175         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
176         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
177
178         pItem->AddControl(pLabel);
179         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
180         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
181         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
182         pItem->SetEnabled(false);
183
184         return pItem;
185 }
186
187 TableViewItem*
188 HomeAndLockScreenForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
189 {
190         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
191
192         Rectangle itemMainRectangle;
193         Rectangle itemSubRectangle;
194         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
195         String itemMainText;
196         String itemSubText;
197         String fontReturnValue;
198         Label* pLabel = null;
199         int itemHeight = 0;
200         int fontSize = GetFontSize();
201
202         itemMainText = GetGroupItemText(groupIndex);
203
204         ItemTypeOneLine(itemMainRectangle);
205         itemHeight = itemMainRectangle.height;
206
207         if (groupIndex == ID_GROUP_SCREEN_TYPE)
208         {
209                 itemSubText = GetGroupItemSelectedText();
210                 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
211                 itemHeight = itemMainRectangle.height + itemSubRectangle.height;
212         }
213
214         TableViewItem* pItem = new (std::nothrow) TableViewItem();
215
216         RelativeLayout relativeLayout;
217         relativeLayout.Construct();
218
219         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
220         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
221
222         pLabel = new (std::nothrow) Label();
223         pLabel->Construct(itemMainRectangle, itemMainText);
224         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
225         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
226         pLabel->SetTextColor(COLOR_MAIN_TEXT);
227
228         pItem->AddControl(pLabel);
229
230         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
231         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
232
233         if (groupIndex == ID_GROUP_SCREEN_TYPE)
234         {
235                 pLabel = new (std::nothrow) Label();
236                 pLabel->Construct(itemSubRectangle, itemSubText);
237                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
238                 pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
239                 pLabel->SetTextColor(COLOR_SUB_TEXT);
240
241                 pItem->AddControl(pLabel);
242
243                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
244                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
245         }
246         return pItem;
247 }
248
249 bool
250 HomeAndLockScreenForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
251 {
252         AppLogDebug("ENTER");
253
254         delete pItem;
255         pItem = null;
256
257         return true;
258 }
259
260 bool
261 HomeAndLockScreenForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
262 {
263         AppLogDebug("ENTER");
264
265         delete pItem;
266         pItem = null;
267
268         return true;
269 }
270
271 void
272 HomeAndLockScreenForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
273 {
274         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
275
276         SceneManager* pSceneManager = SceneManager::GetInstance();
277         AppAssert(pSceneManager);
278
279         ArrayList* pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
280         if (pArgs == null)
281         {
282                 AppLogDebug("pArgs is null");
283         }
284
285         result r = pArgs->Construct();
286         if (IsFailed(r))
287         {
288                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
289         }
290         pArgs->Add(*(new (std::nothrow) String(Integer::ToString(GetWallpaperIndex()))));
291
292         const wchar_t* pSceneName;
293         if (groupIndex == ID_GROUP_SCREEN_WALLPAPER)
294         {
295                 pSceneName = IDSCN_WALLPAPER_ALBUM_LIST;
296         }
297         else
298         {
299                 pSceneName = IDSCN_SCREEN_TYPE;
300         }
301
302         if (pSceneName != null)
303         {
304                 pSceneManager->GoForward(ForwardSceneTransition(pSceneName, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
305         }
306 }
307
308 int
309 HomeAndLockScreenForm::GetDefaultGroupItemHeight(void)
310 {
311         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
312 }
313
314 int
315 HomeAndLockScreenForm::GetDefaultItemHeight(void)
316 {
317         return H_GROUP_ITEM_DEFAULT;
318 }
319
320 void
321 HomeAndLockScreenForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
322 {
323 }
324
325 void
326 HomeAndLockScreenForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
327 {
328         switch (groupIndex)
329         {
330         case ID_GROUP_SCREEN_TYPE:
331                 {
332                         String itemSubText;
333                         Label* pSecondLabel = static_cast<Label*>(pItem->GetControl(1));
334                         itemSubText = GetGroupItemSelectedText();
335                         pSecondLabel->SetText(itemSubText);
336                         pSecondLabel->Invalidate(false);
337                 }
338                 break;
339
340         default:
341                 break;
342         }
343         Invalidate(true);
344 }
345
346 void
347 HomeAndLockScreenForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
348 {
349 }
350
351 void
352 HomeAndLockScreenForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
353 {
354 }
355
356 void
357 HomeAndLockScreenForm::SetWallpaperIndex(Tizen::Base::String& whitchOne)
358 {
359         Integer::Parse(whitchOne, __wallpaperIndex);
360 }
361
362 int
363 HomeAndLockScreenForm::GetWallpaperIndex(void)
364 {
365         return __wallpaperIndex;
366 }
367
368 Tizen::Base::String
369 HomeAndLockScreenForm::GetTitleText(void)
370 {
371         String headerText;
372
373         switch (GetWallpaperIndex())
374         {
375         case ID_INDEX_HOME_SCREEN_WALLPAPER:
376                 {
377                         headerText = ResourceManager::GetString(L"IDS_ST_HEADER_HOME_SCREEN");
378                 }
379                 break;
380
381         case ID_INDEX_LOCK_SCREEN_WALLPAPER:
382                 {
383                         headerText = ResourceManager::GetString(L"IDS_ST_BODY_LOCK_SCREEN");
384                 }
385                 break;
386         }
387
388         return headerText;
389 }
390
391 Tizen::Base::String
392 HomeAndLockScreenForm::GetGroupText(int groupIndex)
393 {
394         String groupText;
395
396         switch (groupIndex)
397         {
398         case ID_GROUP_SCREEN_TYPE:
399                 {
400                         if (GetWallpaperIndex())
401                         {
402                                 groupText = ResourceManager::GetString(L"IDS_ST_BODY_LOCK_SCREEN");
403                         }
404                         else
405                         {
406                                 groupText = ResourceManager::GetString(L"IDS_ST_HEADER_HOME_SCREEN");
407                         }
408                 }
409                 break;
410
411         case ID_GROUP_SCREEN_WALLPAPER:
412                 {
413                         groupText = ResourceManager::GetString(L"IDS_ST_BODY_MAINDISPLAY_WALLPAPER");
414                 }
415                 break;
416         }
417
418         return groupText;
419 }
420
421 Tizen::Base::String
422 HomeAndLockScreenForm::GetGroupItemText(int groupIndex)
423 {
424         String itemMainText;
425
426         switch (groupIndex)
427         {
428         case ID_GROUP_SCREEN_TYPE:
429                 {
430                         if (GetWallpaperIndex())
431                         {
432                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SCREEN_LOCK_TYPE");
433                         }
434                         else
435                         {
436                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_HOME_SCREEN_TYPE");
437                         }
438                 }
439                 break;
440
441         case ID_GROUP_SCREEN_WALLPAPER:
442                 {
443                         if (GetWallpaperIndex())
444                         {
445                                 itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_LOCK_SCREEN_WALLPAPER_M_NOUN");
446                         }
447                         else
448                         {
449                                 itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_HOME_SCREEN_WALLPAPER");
450                         }
451                 }
452                 break;
453         }
454
455         return itemMainText;
456 }
457
458 Tizen::Base::String
459 HomeAndLockScreenForm::GetGroupItemSelectedText(void)
460 {
461         String itemMainText;
462         String screenType;
463         String applicationId;
464
465         if (GetWallpaperIndex() == 0)
466         {
467                 screenType = SETTING_INFO_KEY_SCREEN_TYPE_HOME;
468         }
469         else
470         {
471                 screenType = SETTING_INFO_KEY_SCREEN_TYPE_LOCK;
472         }
473
474         result r = SettingInfo::GetValue(screenType, applicationId);
475         AppLogDebug("GetValue(%ls, ..) result=[%s]", screenType.GetPointer(), GetErrorMessage(r));
476
477         if (!IsFailed(r))
478         {
479                 AppLog("AppId=[%ls]", applicationId.GetPointer());
480
481                 if (applicationId.Equals(L"org.tizen.menu-screen", false))
482                 {
483                         // Preloaded home
484                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DEFAULT_HOME_SCREEN");
485                 }
486                 else if (applicationId.Equals(L"org.tizen.lockscreen", false))
487                 {
488                         // Preloaded lock
489                         itemMainText = ResourceManager::GetString(L"IDS_ST_MBODY_SWIPE");
490                 }
491                 else
492                 {
493                         // Downloaded home/lock
494                         PackageManager* pMgr = PackageManager::GetInstance();
495                         PackageAppInfo* pPackageAppInfo = pMgr->GetPackageAppInfoN(applicationId);
496                         itemMainText = pPackageAppInfo->GetAppDisplayName();
497                 }
498         }
499
500         return itemMainText;
501 }