2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.tizenopensource.org/license
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.
20 #include "SettingForm.h"
21 #include "PushClient.h"
23 using namespace Osp::App;
24 using namespace Osp::Base;
25 using namespace Osp::Io;
26 using namespace Osp::Graphics;
27 using namespace Osp::Ui::Controls;
29 #define PUSH_CLIENT_REGISTRY_FILE L"/Home/setting.ini"
30 #define PUSH_CLIENT_REGISTRY_SETTING_SECTION L"Setting"
31 #define PUSH_CLIENT_REGISTRY_USE_PUSH_ENTRY L"UsePush"
33 SettingForm::SettingForm(void) :
34 __pSettingButton(null)
38 SettingForm::~SettingForm(void)
43 SettingForm::Initialize(void)
45 Form::Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER);
51 SettingForm::OnInitializing(void)
55 Header* pHeader = GetHeader();
58 pHeader->SetStyle(HEADER_STYLE_TITLE);
59 pHeader->SetName(L"SettingForm");
60 pHeader->SetTitleText(L"PushClient - Setting");
63 Footer* pFooter = GetFooter();
66 pFooter->SetStyle(FOOTER_STYLE_TAB);
68 FooterItem footerItem1;
69 footerItem1.Construct(ID_FOOTER_MAIN);
70 footerItem1.SetText(L"Main");
71 pFooter->AddItem(footerItem1);
72 pFooter->AddActionEventListener(*this);
75 __pSettingButton = new CheckButton();
76 __pSettingButton->Construct(Rectangle(20, 20, 440, 100), CHECK_BUTTON_STYLE_ONOFF_SLIDING, BACKGROUND_STYLE_DEFAULT, false, L"Use Push Notification");
77 __pSettingButton->SetActionId(ID_BUTTON_CHECKED, ID_BUTTON_UNCHECKED, ID_BUTTON_SELECTED);
78 __pSettingButton->AddActionEventListener(*this);
80 AddControl(*__pSettingButton);
88 SettingForm::OnTerminating(void)
96 SettingForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
98 AppLog("####### OnActionPerformed called with ActionId(%d)! #######", actionId);
104 AppLog("####### Switch to MainForm. #######");
106 PushClient* pApp = static_cast<PushClient*>(Application::GetInstance());
107 pApp->ShowMainForm();
110 case ID_BUTTON_CHECKED:
112 AppLog("####### Enable push notification service. #######");
116 PushClient* pApp = static_cast<PushClient*>(Application::GetInstance());
120 case ID_BUTTON_UNCHECKED:
122 AppLog("####### Disable push notification service. #######");
124 UpdateSetting(false);
126 PushClient* pApp = static_cast<PushClient*>(Application::GetInstance());
136 SettingForm::GetSetting(void)
138 return __pSettingButton->IsSelected();
142 SettingForm::UpdateSetting(bool value)
144 UpdateRegistry(value);
146 __pSettingButton->SetSelected(value);
148 Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
149 if(this == pFrame->GetCurrentForm())
157 SettingForm::CheckRegistry(void)
160 String regFile(PUSH_CLIENT_REGISTRY_FILE);
161 String section(PUSH_CLIENT_REGISTRY_SETTING_SECTION);
162 String entry(PUSH_CLIENT_REGISTRY_USE_PUSH_ENTRY);
164 if (true == File::IsFileExist(regFile))
168 reg.Construct(regFile, false);
169 reg.GetValue(section, entry, value);
171 if (true == (bool)value)
174 UpdateSetting(false);
178 reg.Construct(regFile, true);
179 reg.AddSection(section);
180 reg.AddValue(section, entry, (int)true);
188 SettingForm::UpdateRegistry(bool value)
191 String regFile(PUSH_CLIENT_REGISTRY_FILE);
192 String section(PUSH_CLIENT_REGISTRY_SETTING_SECTION);
193 String entry(PUSH_CLIENT_REGISTRY_USE_PUSH_ENTRY);
195 reg.Construct(regFile, false);
196 reg.SetValue(section, entry, (int)value);