NABI issues N_SE-50115, N_SE-50067, N_SE-49946, N_SE-49897, N_SE-49884, N_SE-48837...
[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->AddActionEventListener(*this);
60
61         SetFormBackEventListener(this);
62 }
63
64 result
65 LocaleLanguageForm::OnInitializing(void)
66 {
67         CreateHeader(ResourceManager::GetString(L"IDS_ST_HEADER_DISPLAY_LANGUAGE"));
68         CreateTableView();
69
70         SettingInfo::GetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, __previousSelectedLanguage);
71         return SettingInfo::AddSettingEventListener(*this);
72 }
73
74 result
75 LocaleLanguageForm::OnTerminating(void)
76 {
77         SettingInfo::RemoveSettingEventListener(*this);
78         __pTableView = null;
79
80         delete __pLanguageDataList;
81         __pLanguageDataList = null;
82
83         SetFormBackEventListener(null);
84         return E_SUCCESS;
85 }
86
87 void
88 LocaleLanguageForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
89 {
90         String langCode;
91
92         if (pArgs != null)
93         {
94                 __pLanguageDataList = static_cast<ArrayList*>(pArgs->GetItemsN(0, pArgs->GetCount()));
95         }
96         __pTableView->UpdateTableView();
97 }
98
99 void
100 LocaleLanguageForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
101 {
102 }
103
104 void
105 LocaleLanguageForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
106 {
107         SceneManager* pSceneManager = SceneManager::GetInstance();
108         AppAssert(pSceneManager);
109
110         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
111 }
112
113 int
114 LocaleLanguageForm::GetGroupCount(void)
115 {
116         // Temporary code due to the UI Framework defect
117         if (!__pLanguageDataList)
118         {
119                 return 0;
120         }
121
122         AppLogDebug("ENTER");
123         return ID_GROUP_COUNT;
124 }
125
126 int
127 LocaleLanguageForm::GetItemCount(int groupIndex)
128 {
129         // Temporary code due to the UI Framework defect
130         if (!__pLanguageDataList)
131         {
132                 return 0;
133         }
134
135         int itemCount = __pLanguageDataList->GetCount();
136
137         AppLogDebug("GetItemCount %d", itemCount);
138
139         return itemCount;
140 }
141
142 TableViewGroupItem*
143 LocaleLanguageForm::CreateGroupItem(int groupIndex, int itemWidth)
144 {
145         AppLogDebug("ENTER");
146
147         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
148         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
149         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
150         Rectangle itemMainRectangle;
151         String groupText;
152         Label* pLabel = null;
153
154         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
155
156         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
157         itemHeight = Y_GROUP_DEFAULT;
158
159         ItemTypeOneLine(itemMainRectangle);
160
161         RelativeLayout relativeLayout;
162         relativeLayout.Construct();
163
164         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
165         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
166
167         pLabel = new (std::nothrow) Label();
168         pLabel->Construct(itemMainRectangle, groupText);
169         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
170         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
171         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
172         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
173
174         pItem->AddControl(pLabel);
175         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
176         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
177         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
178         pItem->SetEnabled(false);
179
180         return pItem;
181 }
182
183 TableViewItem*
184 LocaleLanguageForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
185 {
186         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
187
188         Rectangle itemMainRectangle;
189         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
190         String itemMainText;
191         String fontReturnValue;
192         Label* pLabel = null;
193         int fontSize = GetFontSize();
194         TableViewItem* pItem = new (std::nothrow) TableViewItem();
195         String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
196
197         ItemTypeOneLine(itemMainRectangle);
198         if (fontSize > FONT_MAIN_TEXT_SIZE_LARGE)
199         {
200                 itemMainRectangle.height = itemMainRectangle.height + H_FONT_HEIGHT_GAP;
201         }
202         itemWidth = itemMainRectangle.width;
203
204         if (pKey && pKey->GetLength() > 0)
205         {
206                 StringTokenizer stringTokenizer(*pKey, L"/");
207                 stringTokenizer.GetNextToken(itemMainText);
208         }
209
210         RelativeLayout relativeLayout;
211         relativeLayout.Construct();
212
213         pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
214         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
215
216         pLabel = new (std::nothrow) Label();
217         pLabel->Construct(itemMainRectangle, itemMainText);
218         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
219
220         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
221         pLabel->SetTextColor(COLOR_MAIN_TEXT);
222
223         pItem->AddControl(pLabel);
224         relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
225         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
226         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
227
228         return pItem;
229 }
230
231 bool
232 LocaleLanguageForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
233 {
234         AppLogDebug("ENTER");
235
236         delete pItem;
237         pItem = null;
238
239         return true;
240 }
241
242 bool
243 LocaleLanguageForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
244 {
245         AppLogDebug("ENTER");
246
247         delete pItem;
248         pItem = null;
249
250         return true;
251 }
252
253 void
254 LocaleLanguageForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
255 {
256         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
257
258         SceneManager* pSceneManager = SceneManager::GetInstance();
259         AppAssert(pSceneManager);
260
261         bool ttsStatus = false;
262         result r = E_FAILURE;
263
264         String langCode;
265         String* pKey = static_cast<String*>(__pLanguageDataList->GetAt(itemIndex));
266
267         StringTokenizer stringTokenizer(*pKey, L"/");
268
269         for (int i = 0; i <= (stringTokenizer.GetTokenCount()); i++)
270         {
271                 stringTokenizer.GetNextToken(langCode);
272         }
273
274         r = SettingInfo::GetValue(SETTING_INFO_KEY_TTS, ttsStatus);
275         if (r == E_SUCCESS && ttsStatus)
276         {
277                 if (langCode.CompareTo(L"eng_GB") != 0 && langCode.CompareTo(L"eng_PH") != 0 && langCode.CompareTo(L"eng_US") != 0
278                                 && langCode.CompareTo(L"spa_ES") != 0 && langCode.CompareTo(L"spa_MX") !=0
279                                 && langCode.CompareTo(L"fra_CA") != 0 && langCode.CompareTo(L"fra_FR") != 0
280                                 && langCode.CompareTo(L"deu_DE") != 0 && langCode.CompareTo(L"ita_IT") != 0 && langCode.CompareTo(L"kor_KR") != 0)
281                 {
282                         // TTS on, language other than eng_GB, eng_PH, eng_US, spa_ES, spa_MX, fra_CA, fra_FR, deu_DE,ita_IT, kor_KR are not supported
283                         ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
284                         return;
285                 }
286         }
287
288         if(langCode.CompareTo(__previousSelectedLanguage) != 0)
289         {
290                 if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, langCode) != E_SUCCESS)
291                 {
292                         AppLogDebug("set langCode[%ls] result[%s]", langCode.GetPointer(), GetErrorMessage(GetLastResult()));
293                 }
294         }
295         else
296         {
297                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
298         }
299
300         __previousSelectedLanguage = langCode;
301 }
302
303 void
304 LocaleLanguageForm::OnSettingChanged(Tizen::Base::String& key)
305 {
306         if (key.Equals(SETTING_INFO_KEY_LOCALE_LANGUAGE, false))
307         {
308                 SceneManager* pSceneManager = SceneManager::GetInstance();
309                 AppAssert(pSceneManager);
310
311                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
312         }
313 }
314
315 int
316 LocaleLanguageForm::GetDefaultGroupItemHeight(void)
317 {
318         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
319 }
320
321 int
322 LocaleLanguageForm::GetDefaultItemHeight(void)
323 {
324         return H_GROUP_ITEM_DEFAULT;
325 }
326
327 void
328 LocaleLanguageForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
329 {
330 }
331
332 void
333 LocaleLanguageForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
334 {
335 }
336
337 void
338 LocaleLanguageForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
339 {
340 }
341
342 void
343 LocaleLanguageForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
344 {
345 }