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 ClkStopWatchPresentationModel.cpp
20 * @brief Describes how the StopWatch works.
27 #include "ClkAlarmPresentationModel.h"
28 #include "ClkStopWatchPresentationModel.h"
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
34 StopWatchPresentationModel* StopWatchPresentationModel::__pInstance = NULL;
36 StopWatchPresentationModel::StopWatchPresentationModel()
37 :__checkFlagKey("lapCheckFlag")
38 ,__LapCountKey("stopWatchLapCount")
39 ,__millisecondTextKey("stopWatchMilliSecond")
41 ,__restartTick("stopWatchRestartTick")
42 ,__startTick("stopWatchStartTick")
43 ,__statusKey("stopWatchStatus")
44 ,__stopTick("stopWatchStopTick")
45 ,__tempTick("stopWatchTempTick")
46 ,__tmpTicker("stopWatchTmpTicker")
47 ,__watchTextKey("stopWatchText")
52 StopWatchPresentationModel::~StopWatchPresentationModel()
58 StopWatchPresentationModel::SetStopWatchValue(int& status, String& startTick, String& tempTick, String& restartTick, String& stopTick, String& milliSecondText, String& watchText)
62 String currentStopWatchValue;
63 String currentTimeValue;
64 DataServiceProvider* pDataServiceProvider= DataServiceProvider::GetInstance();
65 pDataServiceProvider->GetCurrentDateTime(currentTime);
67 if (__pAppRegistry == null)
69 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
72 r = __pAppRegistry->Set(__statusKey, status);
74 if (r == E_KEY_NOT_FOUND)
76 __pAppRegistry->Add(__statusKey, status);
79 r = __pAppRegistry->Set(__startTick, startTick);
81 if (r == E_KEY_NOT_FOUND)
83 __pAppRegistry->Add(__startTick, startTick);
86 r = __pAppRegistry->Set(__tempTick, tempTick);
88 if (r == E_KEY_NOT_FOUND)
90 __pAppRegistry->Add(__tempTick, tempTick);
93 r = __pAppRegistry->Set(__restartTick, restartTick);
95 if (r == E_KEY_NOT_FOUND)
97 __pAppRegistry->Add(__restartTick, restartTick);
100 r = __pAppRegistry->Set(__stopTick, stopTick);
102 if (r == E_KEY_NOT_FOUND)
104 __pAppRegistry->Add(__stopTick, stopTick);
107 r = __pAppRegistry->Set(__millisecondTextKey, milliSecondText);
109 if (r == E_KEY_NOT_FOUND)
111 __pAppRegistry->Add(__millisecondTextKey, milliSecondText);
114 r = __pAppRegistry->Set(__watchTextKey, watchText);
116 if (r == E_KEY_NOT_FOUND)
118 __pAppRegistry->Add(__watchTextKey, watchText);
121 __pAppRegistry->Save();
125 StopWatchPresentationModel::GetStopWatchValue(int& status, String& startTick, String& tempTick, String& restartTick, String& stopTick, String& milliSecondText, String& watchText)
127 AppLog("StopWatchPresentationModel::GetStopWatchValue");
128 result r = E_FAILURE;
131 if (__pAppRegistry == null)
133 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
136 r = __pAppRegistry->Get(__statusKey, status);
140 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
143 r = __pAppRegistry->Get(__startTick, startTick);
147 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
150 r = __pAppRegistry->Get(__tempTick, tempTick);
154 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
157 r = __pAppRegistry->Get(__restartTick, restartTick);
161 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
164 r = __pAppRegistry->Get(__stopTick, stopTick);
168 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
171 r = __pAppRegistry->Get(__millisecondTextKey, milliSecondText);
175 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
178 r = __pAppRegistry->Get(__watchTextKey, watchText);
182 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
188 StopWatchPresentationModel::SetStopWatchLaps(ArrayList& watchTextList, ArrayList& lapTimeTextList, String& tempTicker, int& checkFlag)
190 result r = E_FAILURE;
191 int watchTextCount = watchTextList.GetCount();
192 String* watchText = null;
193 String watchTextKey ;
194 String* lapTimeText = null;
195 String lapTimeTextKey;
197 for (int count = 0; count < watchTextCount; count++)
199 watchTextKey.Clear();
200 lapTimeTextKey.Clear();
202 watchText = static_cast<String *>(watchTextList.GetAt(count));
203 watchTextKey.Append("watchText");
204 watchTextKey.Append(count);
206 lapTimeText = static_cast<String *>(lapTimeTextList.GetAt(count));
207 lapTimeTextKey.Append("lapTimeText");
208 lapTimeTextKey.Append(count);
210 r = __pAppRegistry->Set(watchTextKey, *watchText);
212 if (r == E_KEY_NOT_FOUND)
214 __pAppRegistry->Add(watchTextKey, *watchText);
217 r = __pAppRegistry->Set(lapTimeTextKey, *lapTimeText);
219 if (r == E_KEY_NOT_FOUND)
221 __pAppRegistry->Add(lapTimeTextKey, *lapTimeText);
225 r = __pAppRegistry->Set(__LapCountKey, watchTextCount);
227 if (r == E_KEY_NOT_FOUND)
229 __pAppRegistry->Add(__LapCountKey, watchTextCount);
232 r = __pAppRegistry->Set(__tmpTicker, tempTicker);
234 if (r == E_KEY_NOT_FOUND)
236 __pAppRegistry->Add(__tmpTicker, tempTicker);
239 r = __pAppRegistry->Set(__checkFlagKey, checkFlag);
241 if (r == E_KEY_NOT_FOUND)
243 __pAppRegistry->Add(__checkFlagKey, checkFlag);
245 __pAppRegistry->Save();
249 StopWatchPresentationModel::GetStopWatchLaps(ArrayList& lapsList, ArrayList& lapTimeTextList, String& tempTicker, int& checkFlag)
251 result r = E_FAILURE;
253 String watchTextKey ;
254 String lapTimeTextKey;
255 String *watchText = new String();
256 String *lapTimeText = new String();
257 r = __pAppRegistry->Get(__LapCountKey, lapCount);
261 AppLog("StopWatchPresentationModel::GetStopWatchLaps result = %s", GetErrorMessage(r));
264 for(int count = 0; count < lapCount; count++)
266 watchTextKey.Clear();
267 lapTimeTextKey.Clear();
269 watchTextKey.Append("watchText");
270 watchTextKey.Append(count);
272 lapTimeTextKey.Append("lapTimeText");
273 lapTimeTextKey.Append(count);
275 r = __pAppRegistry->Get(watchTextKey, *watchText);
279 lapsList.InsertAt((new (std::nothrow) String(*watchText)), count);
282 r = __pAppRegistry->Get(lapTimeTextKey, *lapTimeText);
286 lapTimeTextList.InsertAt((new (std::nothrow) String(*lapTimeText)), count);
289 r = __pAppRegistry->Get(__tmpTicker, tempTicker);
293 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
296 r = __pAppRegistry->Get(__checkFlagKey, checkFlag);
300 AppLog("StopWatchPresentationModel::GetStopWatchValue result = %s", GetErrorMessage(r));
310 StopWatchPresentationModel*
311 StopWatchPresentationModel::GetInstance(void)
313 if (__pInstance == null)
322 StopWatchPresentationModel::SetStatus(int& status)
324 result r = E_FAILURE;
326 if (__pAppRegistry == null)
328 __pAppRegistry = UiApp::GetInstance()->GetAppRegistry();
331 r = __pAppRegistry->Set(__statusKey, status);
333 if (r == E_KEY_NOT_FOUND)
335 __pAppRegistry->Add(__statusKey, status);
340 StopWatchPresentationModel::Construct(void)
346 StopWatchPresentationModel::CreateInstance(void)
348 __pInstance = new (std::nothrow) StopWatchPresentationModel();
349 result r = __pInstance->Construct();
358 std::atexit(DestroyInstance);
362 StopWatchPresentationModel::DestroyInstance(void)