Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / data / my_tools / jj / rsa / apps / osp / Settings / src / StLanguageForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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
42 static const int ID_GROUP_LANGUAGE_ITEM_COUNT = 49;
43
44 LocaleLanguageForm::LocaleLanguageForm(void)
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 __languageDataList;
82         __languageDataList = 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                 __languageDataList = 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         AppLogDebug("ENTER");
118         return ID_GROUP_COUNT;
119 }
120
121 int
122 LocaleLanguageForm::GetItemCount(int groupIndex)
123 {
124         int itemCount = __languageDataList->GetCount();
125
126         AppLogDebug("GetItemCount %d", itemCount);
127
128         return itemCount;
129 }
130
131 TableViewGroupItem*
132 LocaleLanguageForm::CreateGroupItem(int groupIndex, int itemWidth)
133 {
134         AppLogDebug("ENTER");
135
136         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
137         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
138         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
139         Rectangle itemRectangle;
140         String groupText;
141         Label* pLabel = null;
142         
143         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
144
145         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
146         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
147
148         ItemTypeOneLine(itemRectangle);
149
150         RelativeLayout relativeLayout;
151         relativeLayout.Construct();
152
153         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
154         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
155
156         pLabel = new (std::nothrow) Label();
157         pLabel->Construct(itemRectangle, groupText);
158         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
159         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
160         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
161         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
162
163         pItem->AddControl(*pLabel);
164         relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
165         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
166         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
167         pItem->SetEnabled(false);
168
169         return pItem;
170 }
171
172 TableViewItem*
173 LocaleLanguageForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
174 {
175         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
176
177         Rectangle itemRectangle;
178         Rectangle itemSecondLineTextRect;
179         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
180         String itemText;
181         String secondLineText;
182         String fontReturnValue;
183         Label* pLabel = null;
184         int fontSize = GetFontSize();
185         TableViewItem* pItem = new (std::nothrow) TableViewItem();
186         String* pKey = static_cast<String*>(__languageDataList->GetAt(itemIndex));
187
188         ItemTypeOneLine(itemRectangle);
189         itemWidth = itemRectangle.width;
190
191         StringTokenizer stringTokenizer(*pKey, L"/");
192         stringTokenizer.GetNextToken(itemText);
193
194         RelativeLayout relativeLayout;
195         relativeLayout.Construct();
196
197         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
198         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
199
200         pLabel = new (std::nothrow) Label();
201         pLabel->Construct(itemRectangle, itemText);
202         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
203
204         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
205         pLabel->SetTextColor(COLOR_MAIN_TEXT);
206
207         pItem->AddControl(*pLabel);
208         relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
209         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
210         relativeLayout.SetRelation(*pLabel, *pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
211
212         return pItem;
213 }
214
215 bool
216 LocaleLanguageForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
217 {
218         AppLogDebug("ENTER");
219
220         delete pItem;
221         pItem = null;
222
223         return true;
224 }
225
226 bool
227 LocaleLanguageForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
228 {
229         AppLogDebug("ENTER");
230
231         delete pItem;
232         pItem = null;
233
234         return true;
235 }
236
237 void
238 LocaleLanguageForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
239 {
240         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
241
242         SceneManager* pSceneManager = SceneManager::GetInstance();
243         AppAssert(pSceneManager);
244
245         String langCode;
246         String* pKey = static_cast<String*>(__languageDataList->GetAt(itemIndex));
247
248         StringTokenizer stringTokenizer(*pKey, L"/");
249
250         for (int i = 0; i <= (stringTokenizer.GetTokenCount()); i++)
251         {
252                 stringTokenizer.GetNextToken(langCode);
253         }
254
255         if (SettingInfo::SetValue(SETTING_INFO_KEY_LOCALE_LANGUAGE, langCode) != E_SUCCESS)
256         {
257                 AppLogDebug("set langCode[%ls] result[%s]", langCode.GetPointer(), GetErrorMessage(GetLastResult()));
258         }
259 }
260
261 void
262 LocaleLanguageForm::OnSettingChanged(Tizen::Base::String& key)
263 {
264         if (key.Equals(SETTING_INFO_KEY_LOCALE_LANGUAGE, false))
265         {
266                 SceneManager* pSceneManager = SceneManager::GetInstance();
267                 AppAssert(pSceneManager);
268
269                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
270         }
271 }
272
273 int
274 LocaleLanguageForm::GetDefaultGroupItemHeight(void)
275 {
276         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
277 }
278
279 int
280 LocaleLanguageForm::GetDefaultItemHeight(void)
281 {
282         return H_GROUP_ITEM_DEFAULT;
283 }
284
285 void
286 LocaleLanguageForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
287 {
288 }
289
290 void
291 LocaleLanguageForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
292 {
293 }
294
295 void
296 LocaleLanguageForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
297 {
298 }
299
300 void
301 LocaleLanguageForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
302 {
303 }