3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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://floralicense.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.
19 * @file ClkTimerPresentationModel.cpp
20 * @brief This file contains the definitions of the TimerPresentationModel Class.
27 #include "ClkAlarmPresentationModel.h"
28 #include "ClkTimerPresentationModel.h"
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
33 TimerPresentationModel* TimerPresentationModel::__pInstance = NULL;
35 TimerPresentationModel::TimerPresentationModel()
36 :__focusKey("focusValue")
37 ,__nameKey("timerTime")
39 ,__remainingTimeKey("remainingTime")
40 ,__restartTickKey("restartTick")
41 ,__statusKey("timerStatus")
42 ,__startTickKey("startTick")
43 ,__stopTickKey("stopTick")
44 ,__tempTickKey("tempTick")
45 ,__userSetValueKey("userSetValue")
46 ,__registeredValueKey("registeredValue")
47 ,userValue("00:01:00")
52 TimerPresentationModel::~TimerPresentationModel()
58 TimerPresentationModel::SetTimerValue(const DateTime& remainingTime, int& status, String& startTick, String& tempTick, String& restartTick, String& stopTick, String& userSetValue, String& registeredValue)
63 DataServiceProvider* pDataServiceProvider= DataServiceProvider::GetInstance();
65 if ( pDataServiceProvider == NULL )
70 pDataServiceProvider->GetCurrentDateTime(ringingTime);
71 ringingTime.AddHours(remainingTime.GetHour());
72 ringingTime.AddMinutes(remainingTime.GetMinute());
73 ringingTime.AddSeconds(remainingTime.GetSecond());
74 AppLog("remainingTime = %ls ringing time = %ls", remainingTime.ToString().GetPointer(), ringingTime.ToString().GetPointer());
76 if(__pAppRegistry == null)
78 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
81 r = __pAppRegistry->Set(__remainingTimeKey, remainingTime.ToString());
83 if (r == E_KEY_NOT_FOUND)
85 __pAppRegistry->Add(__remainingTimeKey, remainingTime.ToString());
88 time = ringingTime.ToString();
89 r = __pAppRegistry->Set(__nameKey, time);
91 if (r == E_KEY_NOT_FOUND)
93 __pAppRegistry->Add(__nameKey, time);
96 r = __pAppRegistry->Set(__statusKey, status);
98 if (r == E_KEY_NOT_FOUND)
100 __pAppRegistry->Add(__statusKey, status);
103 r = __pAppRegistry->Set(__startTickKey, startTick);
105 if (r == E_KEY_NOT_FOUND)
107 __pAppRegistry->Add(__startTickKey, startTick);
110 r = __pAppRegistry->Set(__tempTickKey, tempTick);
112 if (r == E_KEY_NOT_FOUND)
114 __pAppRegistry->Add(__tempTickKey, tempTick);
117 r = __pAppRegistry->Set(__restartTickKey, restartTick);
119 if (r == E_KEY_NOT_FOUND)
121 __pAppRegistry->Add(__restartTickKey, restartTick);
124 r = __pAppRegistry->Set(__stopTickKey, stopTick);
126 if (r == E_KEY_NOT_FOUND)
128 __pAppRegistry->Add(__stopTickKey, stopTick);
131 r = __pAppRegistry->Set(__userSetValueKey, userSetValue);
133 if (r == E_KEY_NOT_FOUND)
135 __pAppRegistry->Add(__userSetValueKey, userSetValue);
138 r = __pAppRegistry->Set(__registeredValueKey, registeredValue);
140 if (r == E_KEY_NOT_FOUND)
142 __pAppRegistry->Add(__registeredValueKey, registeredValue);
145 __pAppRegistry->Save();
149 TimerPresentationModel::GetTimerValue(DateTime& timerValue, String& remainingTime, int& status, String& startTick, String& tempTick, String& restartTick, String& stopTick, String& userSetValue, String& registeredValue)
151 AppLog("TimerPresentationModel::GetTimerValue");
152 result r = E_FAILURE;
153 DateTime currentTime;
156 DataServiceProvider* pDataServiceProvider= DataServiceProvider::GetInstance();
158 if(__pAppRegistry == null)
160 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
163 pDataServiceProvider->GetCurrentDateTime(currentTime);
164 r = __pAppRegistry->Get(__nameKey, ringingTime);
168 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
171 DateTime::Parse(ringingTime, time);
172 AppLog("ringing time = %ls remainningTime = %ls currentTime = %ls",ringingTime.GetPointer(), time.ToString().GetPointer(), currentTime.ToString().GetPointer());
174 timerValue.AddHours(time.GetHour() - currentTime.GetHour());
175 timerValue.AddMinutes(time.GetMinute() - currentTime.GetMinute());
176 timerValue.AddSeconds(time.GetSecond() - currentTime.GetSecond());
177 r = __pAppRegistry->Get(__statusKey, status);
181 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
184 AppLog("TimerPresentationModel::GetTimerValue end timerValue = %ls status = %d", timerValue.ToString().GetPointer(), status);
186 r = __pAppRegistry->Get(__userSetValueKey, userSetValue);
190 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
193 r = __pAppRegistry->Get(__remainingTimeKey, remainingTime);
197 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
202 r = __pAppRegistry->Get(__startTickKey, startTick);
206 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
209 r = __pAppRegistry->Get(__tempTickKey, tempTick);
213 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
216 r = __pAppRegistry->Get(__restartTickKey, restartTick);
220 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
223 r = __pAppRegistry->Get(__stopTickKey, stopTick);
227 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
230 r = __pAppRegistry->Get(__registeredValueKey, registeredValue);
234 AppLog("TimerPresentationModel::GetTimerValue result = %s", GetErrorMessage(r));
238 AppLog("TimerPresentationModel::GetTimerValue end");
242 TimerPresentationModel::SetStatus(int& status)
244 result r = E_FAILURE;
246 if (__pAppRegistry == null)
248 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
251 r = __pAppRegistry->Set(__statusKey, status);
253 if (r == E_KEY_NOT_FOUND)
255 __pAppRegistry->Add(__statusKey, status);
260 TimerPresentationModel::SetTimerTime(const DateTime& dateTime)
262 result r = E_FAILURE;
264 if (__pAppRegistry == null)
266 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
269 r = __pAppRegistry->Set(__remainingTimeKey, dateTime.ToString());
271 if (r == E_KEY_NOT_FOUND)
273 __pAppRegistry->Add(__remainingTimeKey, dateTime.ToString());
278 TimerPresentationModel::SetFocus(const int& value)
280 result r = E_FAILURE;
282 if (__pAppRegistry == null)
284 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
287 r = __pAppRegistry->Set(__focusKey, value);
289 if (r == E_KEY_NOT_FOUND)
291 __pAppRegistry->Add(__focusKey, value);
295 TimerPresentationModel::SetRegisteredTime(DateTime& dateTime)
297 result r = E_FAILURE;
300 if (__pAppRegistry == null)
302 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
305 r = __pAppRegistry->Set(__registeredValueKey, dateTime.ToString());
307 if (r == E_KEY_NOT_FOUND)
309 __pAppRegistry->Add(__registeredValueKey, dateTime.ToString());
312 __pAppRegistry->Save();
315 TimerPresentationModel*
316 TimerPresentationModel::GetInstance(void)
318 if (__pInstance == null)
327 TimerPresentationModel::Construct(void)
333 TimerPresentationModel::CreateInstance(void)
335 __pInstance = new (std::nothrow) TimerPresentationModel();
336 result r = __pInstance->Construct();
344 std::atexit(DestroyInstance);
348 TimerPresentationModel::DestroyInstance(void)