Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StLanguageForm.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                StLanguageForm.cpp
19  * @brief               This is the implementation file for LanguageForm class.
20  */
21
22 #include <FLocales.h>
23 #include "StLanguageForm.h"
24 #include "StResourceManager.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Utility;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Locales;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
37
38 static const int ID_GROUP_LANGUAGE = 0;
39 static const int ID_GROUP_COUNT = 1;
40 static const int ITEM_WIDTH_GAP = 100;
41 static const int H_FONT_HEIGHT_GAP = 20;
42
43 LocaleLanguageForm::LocaleLanguageForm(void)
44         : __pLanguageDataList(null)
45 {
46 }
47
48 LocaleLanguageForm::~LocaleLanguageForm(void)
49 {
50 }
51
52 void
53 LocaleLanguageForm::CreateFooter(void)
54 {
55         Footer* pFooter = GetFooter();
56         AppAssert(pFooter);
57
58         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
59         pFooter->SetBackButton();
60         pFooter->AddActionEventListener(*this);
61
62         SetFormBackEventListener(this);
63 }
64
65 result
66 LocaleLanguageForm::OnInitializing(void)
67 {
68         CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_DISPLAY_LANGUAGE"));
69         CreateFooter();
70         CreateTableView();
71
72         return SettingInfo::AddSettingEventListener(*this);
73 }
74
75 result
76 LocaleLanguageForm::OnTerminating(void)
77 {
78         SettingInfo::RemoveSettingEventListener(*this);
79         __pTableView = null;
80
81         delete __pLanguageDataList;
82         __pLanguageDataList = null;
83
84         SetFormBackEventListener(null);
85         return E_SUCCESS;
86 }
87
88 void
89 LocaleLanguageForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
90 {
91         String langCode;
92
93         if (pArgs != null)
94         {
95                 __pLanguageDataList = static_cast<ArrayList*>(pArgs->GetItemsN(0, pArgs->GetCount()));
96         }
97         __pTableView->UpdateTableView();
98 }
99
100 void
101 LocaleLanguageForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
102 {
103 }
104
105 void
106 LocaleLanguageForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
107 {
108         SceneManager* pSceneManager = SceneManager::GetInstance();
109         AppAssert(pSceneManager);
110
111         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
112 }
113
114 int
115 LocaleLanguageForm::GetGroupCount(void)
116 {
117         // Temporary code due to the UI Framework defect
118         if (!__pLanguageDataList)
119         {
120                 return 0;
121         }
122
123         AppLogDebug("ENTER");
124         return ID_GROUP_COUNT;
125 }
126
127 int
128 LocaleLanguageForm::GetItemCount(int groupIndex)
129 {
130         // Temporary code due to the UI Framework defect
131         if (!__pLanguageDataList)
132         {
133                 return 0;
134         }
135
136         int itemCount = __pLanguageDataList->GetCount();
137
138         AppLogDebug("GetItemCount %d", itemCount);
139
140         return itemCount;
141 }
142
143 TableViewGroupItem*
144 LocaleLanguageForm::CreateGroupItem(int groupIndex, int itemWidth)
145 {
146         AppLogDebug("ENTER");
147
148         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
149         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
150         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
151         Rectangle itemMainRectangle;
152         String groupText;
153         Label* pLabel = null;
154
155         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
156
157         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
158         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
159
160         ItemTypeOneLine(itemMainRectangle);
161
162         RelativeLayout relativeLayout;
163         relativeLayout.Construct();
164
165         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
166         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
167
168         pLabel = new (std::nothrow) Label();
169         pLabel->Construct(itemMainRectangle, groupText);
170         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
171         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
172         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
173         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
174
175         pItem->AddControl(pLabel);
176         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
177         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
178         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
179         pItem->SetEnabled(false);
180
181         return pItem;
182 }
183
184 TableViewItem*
185 LocaleLanguageForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
186 {
187         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
188
189         Rectangle itemMainRectangle;
190         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
191         String itemMainText;
192         String fontReturnValue;
193         Label* pLabel = null;
194         int fontSize = GetFontSize();
195         TableViewItem* pItem = new (std::nothrow) TableViewItem();
196         String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
197
198         ItemTypeOneLine(itemMainRectangle);
199         if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
200         {
201                 itemMainRectangle.height = itemMainRectangle.height + H_FONT_HEIGHT_GAP;
202         }
203         itemWidth = itemMainRectangle.width;
204
205         StringTokenizer stringTokenizer(*pKey, L"/");
206         stringTokenizer.GetNextToken(itemMainText);
207
208         RelativeLayout relativeLayout;
209         relativeLayout.Construct();
210
211         pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
212         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
213
214         pLabel = new (std::nothrow) Label();
215         pLabel->Construct(itemMainRectangle, itemMainText);
216         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
217
218         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
219         pLabel->SetTextColor(COLOR_MAIN_TEXT);
220
221         pItem->AddControl(pLabel);
222         relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
223         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
224         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
225
226         return pItem;
227 }
228
229 bool
230 LocaleLanguageForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
231 {
232         AppLogDebug("ENTER");
233
234         delete pItem;
235         pItem = null;
236
237         return true;
238 }
239
240 bool
241 LocaleLanguageForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
242 {
243         AppLogDebug("ENTER");
244
245         delete pItem;
246         pItem = null;
247
248         return true;
249 }
250
251 void
252 LocaleLanguageForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
253 {
254         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
255
256         SceneManager* pSceneManager = SceneManager::GetInstance();
257         AppAssert(pSceneManager);
258
259         String langCode;
260         String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
261
262         StringTokenizer stringTokenizer(*pKey, L"/");
263
264         for (int i = 0; i <= (stringTokenizer.GetTokenCount()); i++)
265         {
266                 stringTokenizer.GetNextToken(langCode);
267         }
268
269         if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, langCode) != E_SUCCESS)
270         {
271                 AppLogDebug("set langCode[%ls] result[%s]", langCode.GetPointer(), GetErrorMessage(GetLastResult()));
272         }
273 }
274
275 void
276 LocaleLanguageForm::OnSettingChanged(Tizen::Base::String& key)
277 {
278         if (key.Equals(SETTING_INFO_KEY_LOCALE_LANGUAGE, false))
279         {
280                 SceneManager* pSceneManager = SceneManager::GetInstance();
281                 AppAssert(pSceneManager);
282
283                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
284         }
285 }
286
287 int
288 LocaleLanguageForm::GetDefaultGroupItemHeight(void)
289 {
290         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
291 }
292
293 int
294 LocaleLanguageForm::GetDefaultItemHeight(void)
295 {
296         return H_GROUP_ITEM_DEFAULT;
297 }
298
299 void
300 LocaleLanguageForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
301 {
302 }
303
304 void
305 LocaleLanguageForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
306 {
307 }
308
309 void
310 LocaleLanguageForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
311 {
312 }
313
314 void
315 LocaleLanguageForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
316 {
317 }