Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / cpp / Sample / Tizen C++ / SystemApp / SystemApp / project / src / SettingInfoForm.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.tizenopensource.org/license
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "FormManager.h"
19 #include "SettingInfoForm.h"
20 #include "CustomListElement.h"
21
22 using namespace Osp::Base;
23 using namespace Osp::Ui;
24 using namespace Osp::Ui::Controls;
25 using namespace Osp::System;
26 using namespace Osp::Graphics;
27
28 const int NumberOfSettingElement = 21;
29
30 SettingInfoForm::SettingInfoForm(void)
31         : __pSlidableListSettingInfo(null)
32         , __pLabel(null)
33         , __pListView(null)
34         , listElements()
35 {
36
37 }
38
39 SettingInfoForm::~SettingInfoForm(void)
40 {
41
42 }
43
44 bool
45 SettingInfoForm::Initialize()
46 {
47         Construct(L"IDF_SETTING_INFO_FORM");
48         SetName(String(L"SettingInfoForm"));
49         SettingInfo::SetSettingEventListener((ISettingEventListener*) this);
50
51         __pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL_SETTING_INFO"));
52         __pListView = new ListView();
53         __pListView->Construct(Rectangle(0, 70, GetClientAreaBounds().width, GetClientAreaBounds().height - 80), true, false);
54         __pListView->SetItemProvider(*this);
55         __pListView->AddListViewItemEventListener(*this);
56
57         listElements.Construct(NumberOfSettingElement);
58
59         AddControl(*__pListView);
60
61         return true;
62 }
63
64 result
65 SettingInfoForm::OnInitializing(void)
66 {
67         result r = E_SUCCESS;
68
69         Footer* pFooter = GetFooter();
70         FormManager::MakeSystemAppFooter(this, pFooter, FormManager::REQUEST_FORM_SETTING_INFO);
71
72         return r;
73 }
74
75 result
76 SettingInfoForm::OnTerminating(void)
77 {
78         result r = E_SUCCESS;
79
80         return r;
81 }
82
83 void
84 SettingInfoForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
85 {
86         switch (actionId)
87         {
88         default:
89         {
90                 Frame *pFrame = Osp::App::Application::GetInstance()->GetAppFrame()->GetFrame();
91                 FormManager* pFormManager = static_cast<FormManager*>(pFrame->GetControl(String(L"FormManager")));
92                 if (pFormManager != null)
93                 {
94                         pFormManager->SendUserEvent(static_cast<RequestId>(actionId), null);
95                 }
96                 else
97                 {
98                         AppLog("FormManager getting has failed.");
99                 }
100                 return;
101         }
102         }
103
104         RequestRedraw(true);
105 }
106
107 void
108 SettingInfoForm::OnSettingChanged(Osp::Base::String& key)
109 {
110         String szEvent;
111         szEvent = "Event: ";
112         szEvent.Append(key);
113         __pLabel->SetText(szEvent);
114         __pListView->UpdateList();
115
116         Draw();
117         Show();
118
119 }
120
121 void
122 SettingInfoForm::OnListViewContextItemStateChanged(Osp::Ui::Controls::ListView& listView,
123         int index,
124         int elementId,
125         Osp::Ui::Controls::ListContextItemStatus state)
126 {
127 }
128
129 void
130 SettingInfoForm::OnListViewItemStateChanged(Osp::Ui::Controls::ListView& listView,
131         int index,
132         int elementId,
133         Osp::Ui::Controls::ListItemStatus status)
134 {
135 }
136
137 void
138 SettingInfoForm::OnListViewItemSwept(Osp::Ui::Controls::ListView& listView,
139         int index,
140         Osp::Ui::Controls::SweepDirection direction)
141 {
142 }
143
144 Osp::Ui::Controls::ListItemBase*
145 SettingInfoForm::CreateItem(int index, int itemWidth)
146 {
147         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
148         CustomItem* pItem = new CustomItem();
149
150         String szTitle;
151         String szDescription;
152         int nResult;
153         bool bResult;
154         CustomListElement* pCustomListElement;
155         pItem->Construct(Osp::Graphics::Dimension(itemWidth, 100), style);
156         int height = 90;
157         switch (index)
158         {
159         case 0:
160         {
161
162                 szTitle = "24HourFormatSelected";
163                 SettingInfo::GetValue(szTitle, bResult);
164                 if (bResult == true)
165                         szDescription = "Enabled";
166                 else
167                         szDescription = "Disabled";
168
169                 break;
170         }
171
172         case 1:
173         {
174                 szTitle = "Country";
175                 SettingInfo::GetValue(szTitle, szDescription);
176                 break;
177         }
178
179         case 2:
180         {
181                 szTitle = "DataRoamingEnabled";
182                 SettingInfo::GetValue(szTitle, bResult);
183                 if (bResult == true)
184                         szDescription = "Enabled";
185                 else
186                         szDescription = "Disabled";
187                 break;
188         }
189
190         case 3:
191         {
192                 szTitle = "GPSEnabled";
193                 SettingInfo::GetValue(szTitle, bResult);
194                 if (bResult == true)
195                         szDescription = "Enabled";
196                 else
197                         szDescription = "Disabled";
198                 break;
199         }
200
201         case 4:
202         {
203                 szTitle = "Language";
204                 SettingInfo::GetValue(szTitle, szDescription);
205                 break;
206         }
207
208         case 5:
209         {
210                 szTitle = "PacketServiceAllowed";
211                 SettingInfo::GetValue(szTitle, bResult);
212                 if (bResult == true)
213                         szDescription = "Enabled";
214                 else
215                         szDescription = "Disabled";
216                 break;
217         }
218
219         case 6:
220         {
221                 szTitle = "SilentMode";
222                 SettingInfo::GetValue(szTitle, bResult);
223                 if (bResult == true)
224                         szDescription = "Enabled";
225                 else
226                         szDescription = "Disabled";
227                 break;
228         }
229
230         case 7:
231         {
232                 szTitle = "TouchVibrationLevel";
233                 SettingInfo::GetValue(szTitle, nResult);
234                 szDescription = "";
235                 szDescription.Append(nResult);
236                 break;
237         }
238
239         case 8:
240         {
241                 szTitle = "WPSEnabled";
242                 SettingInfo::GetValue(szTitle, bResult);
243                 if (bResult == true)
244                         szDescription = "Enabled";
245                 else
246                         szDescription = "Disabled";
247                 break;
248         }
249
250         case 9:
251         {
252                 szTitle = "FlightModeEnabled";
253                 SettingInfo::GetValue(szTitle, bResult);
254                 if (bResult == true)
255                         szDescription = "Enabled";
256                 else
257                         szDescription = "Disabled";
258                 break;
259         }
260
261         case 10:
262         {
263                 szTitle = "FontType";
264                 SettingInfo::GetValue(szTitle, szDescription);
265                 break;
266         }
267
268         case 11:
269         {
270                 szTitle = "FontSize";
271                 SettingInfo::GetValue(szTitle, szDescription);
272                 break;
273         }
274
275         case 12:
276         {
277                 szTitle = "Theme";
278                 SettingInfo::GetValue(szTitle, szDescription);
279                 break;
280         }
281
282         case 13:
283         {
284                 szTitle = "MediaSoundVolume";
285                 SettingInfo::GetValue(szTitle, nResult);
286                 szDescription = "";
287                 szDescription.Append(nResult);
288                 break;
289         }
290
291         case 14:
292         {
293                 szTitle = "NotificationSoundVolume";
294                 SettingInfo::GetValue(szTitle, nResult);
295                 szDescription = "";
296                 szDescription.Append(nResult);
297                 break;
298         }
299
300         case 15:
301         {
302                 szTitle = "Ringtone";
303                 SettingInfo::GetValue(szTitle, szDescription);
304                 break;
305         }
306
307         case 16:
308         {
309                 szTitle = "RingtoneSoundVolume";
310                 SettingInfo::GetValue(szTitle, nResult);
311                 szDescription = "";
312                 szDescription.Append(nResult);
313                 break;
314         }
315
316         case 17:
317         {
318                 szTitle = "SystemSoundVolume";
319                 SettingInfo::GetValue(szTitle, nResult);
320                 szDescription = "";
321                 szDescription.Append(nResult);
322                 break;
323         }
324
325         case 18:
326         {
327                 szTitle = "Wallpaper";
328                 SettingInfo::GetValue(szTitle, szDescription);
329                 break;
330         }
331
332         case 19:
333         {
334                 szTitle = "TimeFormat";
335                 SettingInfo::GetValue(szTitle, szDescription);
336                 break;
337         }
338
339         case 20:
340         {
341                 szTitle = "DateFormat";
342                 SettingInfo::GetValue(szTitle, szDescription);
343                 szTitle = "DateFormat (Setting menu)";
344                 if (szDescription == "dd MMM. yyyy" || szDescription == "dd/MM/yyyy" || szDescription == "d MMM. yyyy"
345                         || szDescription == "dd.MM.yyyy")
346                         szDescription.Append(" (DD/MM/YYYY)");
347                 else if (szDescription == "MMM. d yyyy" || szDescription == "MM/dd/yyyy" || szDescription == "MM.dd.yyyy"
348                         || szDescription == "MMM. dd yyyy")
349                         szDescription.Append(" (MM/DD/YYYY)");
350                 else if (szDescription == "yyyy/dd/MM" || szDescription == "yyyy d MMM." || szDescription == "yyyy.dd.MM"
351                         || szDescription == "yyyy.MM.dd")
352                         szDescription.Append(" (YYYY/DD/MM)");
353                 else if (szDescription == "yyyy/MM/dd" || szDescription == "yyyy MMM. d" || szDescription == "yyyy.MM.dd"
354                         || szDescription == "yyyy MMM. dd")
355                         szDescription.Append(" (YYYY/MM/DD)");
356                 break;
357         }
358
359         default:
360                 break;
361         }
362
363         listElements.RemoveAt(index, true);
364
365         pCustomListElement = new CustomListElement();
366         pCustomListElement->SetTitleDescription(szTitle, szDescription);
367         listElements.InsertAt(*((Object*) pCustomListElement), index);
368         pItem->AddElement(Rectangle(0, 0, GetClientAreaBounds().width, height), ID_FORMAT_CUSTOM, *(static_cast<ICustomElement*>(pCustomListElement)));
369
370         return pItem;
371 }
372
373 bool
374 SettingInfoForm::DeleteItem(int index, Osp::Ui::Controls::ListItemBase* pItem, int itemWidth)
375 {
376         listElements.RemoveAt(index, true);
377
378         delete pItem;
379         pItem = null;
380
381         return true;
382 }
383
384 int
385 SettingInfoForm::GetItemCount(void)
386 {
387         return NumberOfSettingElement;
388 }