2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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
8 // http://floralicense.org/license/
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.
18 * @file ClCalendarApp.cpp
19 * @brief This is the implementation file for the CalendarApp class.
24 #include "ClCalendarApp.h"
25 #include "ClMainFrame.h"
26 #include "ClResourceManager.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Io;
32 using namespace Tizen::Social;
33 using namespace Tizen::System;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
39 const int MIN_MEMORY_NEEDED = 1048576;
41 CalendarApp::CalendarApp(void)
42 : __type(OPERATION_TYPE_MAIN)
43 , __requestId(INVALID_REQUEST_ID)
44 , __initialScene(IDSCN_MONTH)
46 , __pInitialSceneArgument(null)
50 CalendarApp::~CalendarApp(void)
53 delete __pInitialSceneArgument;
57 CalendarApp::CreateInstance(void)
59 // Create the instance through the constructor.
60 return new (std::nothrow) CalendarApp();
64 CalendarApp::GetExportVcsFilePath(void)
67 SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
70 path.Format(30, VCS_EXPORT_PATH, currentTime.GetYear(), currentTime.GetMonth(), currentTime.GetDay(),
71 currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond());
73 if (File::IsFileExist(path) == true)
80 countString.Format(5, L"-%3d", ++count);
82 nextPath.Insert(countString, path.GetLength() - 4);
83 } while (File::IsFileExist(nextPath) == true);
87 path = Application::GetInstance()->GetAppSharedPath() + path;
93 CalendarApp::GetArgument(const String& key) const
99 return static_cast<const String*>(__pArgs->GetValue(key));
103 CalendarApp::GetInitialScene(void) const
105 return __initialScene;
109 CalendarApp::GetInitialSceneArgumentN(void) const
111 ArrayList* pArgs = null;
112 if (__pInitialSceneArgument != null)
114 pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
115 pArgs->Construct(__pInitialSceneArgument->GetCount());
116 IEnumerator* pEnum = __pInitialSceneArgument->GetEnumeratorN();
117 while (pEnum->MoveNext() == E_SUCCESS)
119 if (dynamic_cast<const CalEvent*>(pEnum->GetCurrent()) != null)
121 pArgs->Add(new (std::nothrow) CalEvent(static_cast<const CalEvent&>(*pEnum->GetCurrent())));
123 else if (dynamic_cast<const CalTodo*>(pEnum->GetCurrent()) != null)
125 pArgs->Add(new (std::nothrow) CalTodo(static_cast<const CalTodo&>(*pEnum->GetCurrent())));
134 CalendarApp::GetMimeType(void) const
140 CalendarApp::GetOperationType(void) const
146 CalendarApp::GetRequestId(void) const
152 CalendarApp::GetUri(void) const
158 CalendarApp::AddCalendarAppStatusChangedEventListener(ICalendarAppStatusChangedEventListener& listener)
160 __listeners.Add(&listener);
164 CalendarApp::RemoveCalendarAppStatusChangedEventListener(ICalendarAppStatusChangedEventListener& listener)
166 __listeners.Remove(listener);
170 CalendarApp::OnAppInitializing(AppRegistry& appRegistry)
172 // Set AppControl Provider
173 AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
179 CalendarApp::OnAppInitialized(void)
182 MainFrame* pMainFrame = new (std::nothrow) MainFrame();
184 pMainFrame->Construct();
185 AddFrame(*pMainFrame);
187 if (__type == OPERATION_TYPE_MAIN)
189 // Set SettingInfo event listener
190 SettingInfo::AddSettingEventListener(*this);
193 //Get Current Language Reigon Info
194 SettingInfo::GetValue(KEY_SYSTEM_LANGUAGE, __currentDisplayLang);
195 SettingInfo::GetValue(KEY_SYSTEM_COUNTRY, __currentRegion);
196 AppManager::GetInstance()->AddActiveAppEventListener(*this);
202 CalendarApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
204 AppManager::GetInstance()->RemoveActiveAppEventListener(*this);
209 CalendarApp::OnForeground(void)
211 IEnumerator* pEnum = __listeners.GetEnumeratorN();
212 while (pEnum->MoveNext() == E_SUCCESS)
214 static_cast<ICalendarAppStatusChangedEventListener*>(pEnum->GetCurrent())->OnForeground();
218 AppAssertf(GetAppFrame() != null && GetAppFrame()->GetFrame() != null, "[E_FAILURE] Unable to get frame.");
220 // Todo: temporary solution for appcontrol.
221 if (!GetAppFrame()->GetFrame()->IsEnabled())
223 GetAppFrame()->GetFrame()->SetEnabled(true);
224 GetAppFrame()->GetFrame()->Invalidate(true);
229 CalendarApp::OnBackground(void)
231 IEnumerator* pEnum = __listeners.GetEnumeratorN();
232 while (pEnum->MoveNext() == E_SUCCESS)
234 static_cast<ICalendarAppStatusChangedEventListener*>(pEnum->GetCurrent())->OnBackground();
236 GetAppFrame()->GetFrame()->SetEnabled(true);
241 CalendarApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUriData,
242 const String* pMimeType, const IMap* pExtraData)
244 AppLogDebug("%ls", operationId.GetPointer());
245 if (pMimeType != null)
247 __mimeType = *pMimeType;
248 AppLogDebug("MimeType : %ls", __mimeType.GetPointer());
250 if (pUriData != null)
252 __uriScheme = *pUriData;
253 AppLogDebug("Uri : %ls", __uriScheme.GetPointer());
257 if (pExtraData != null)
259 HashMap* pArgs = new (std::nothrow) HashMap(SingleObjectDeleter);
260 pArgs->Construct(pExtraData->GetCount());
261 IMapEnumerator* pEnum = pExtraData->GetMapEnumeratorN();
262 while (pEnum->MoveNext() == E_SUCCESS)
264 const String* pKey = dynamic_cast<const String*>(pEnum->GetKey());
265 const String* pValue = dynamic_cast<const String*>(pEnum->GetValue());
266 if (pKey != null && pValue != null)
268 AppLogDebug("Add key:%ls, value:%ls", pKey->GetPointer(), pValue->GetPointer());
269 pArgs->Add(new (std::nothrow) String(*pKey), new (std::nothrow) String (*pValue));
276 bool requestFailed = true;
277 if (operationId == ID_OPERATION_MAIN)
279 requestFailed = false;
281 else if (operationId == ID_OPERATION_VIEW)
283 if (__uriScheme.StartsWith(FILE_URL_HEADER, 0) == true)
285 String path = __uriScheme;
286 path.Replace(FILE_URL_HEADER, L"");
288 __pInitialSceneArgument = ResourceManager::ParseVcsFileN(path);
289 __initialScene = IDSCN_VCS_SELECTOR;
290 __mimeType = MIME_TYPE_VCALENDAR;
291 __type = OPERATION_TYPE_VIEW;
292 requestFailed = false;
296 else if (operationId == ID_OPERATION_SOCIAL_PICK)
298 const String* pItemType = GetArgument(KEY_SOCIAL_ITEM_TYPE);
299 if (pItemType != null)
301 if (pItemType->Equals(VALUE_CALENDAR_EVENT_TYPE, false) == true)
303 __initialScene = IDSCN_EVENT_SELECTOR;
304 __type = OPERATION_TYPE_PICK;
305 requestFailed = false;
307 else if (pItemType->Equals(VALUE_CALENDAR_TODO_TYPE, false) == true)
309 __initialScene = IDSCN_TASK_SELECTOR;
310 __type = OPERATION_TYPE_PICK;
311 requestFailed = false;
315 else if (operationId == ID_OPERATION_SOCIAL_VIEW)
317 const String* pItemType = GetArgument(KEY_SOCIAL_ITEM_TYPE);
318 if (pItemType != null)
320 if (pItemType->Equals(VALUE_CALENDAR_EVENT_TYPE, false) == true)
322 __initialScene = IDSCN_EVENT_DETAILS;
323 __type = OPERATION_TYPE_VIEW;
324 requestFailed = false;
326 else if (pItemType->Equals(VALUE_CALENDAR_TODO_TYPE, false) == true)
328 __initialScene = IDSCN_TASK_DETAILS;
329 __type = OPERATION_TYPE_VIEW;
330 requestFailed = false;
334 else if (operationId == ID_OPERATION_SOCIAL_EDIT)
336 const String* pItemType = GetArgument(KEY_SOCIAL_ITEM_TYPE);
337 if (pItemType != null)
339 if (pItemType->Equals(VALUE_CALENDAR_EVENT_TYPE, false) == true)
341 __initialScene = IDSCN_EVENT_EDITOR;
342 __type = OPERATION_TYPE_EDIT;
343 requestFailed = false;
350 result r = AppControlProviderManager::GetInstance()->SendAppControlResult(__requestId, APP_CTRL_RESULT_FAILED, null);
351 AppLogDebugIf(r != E_SUCCESS, "[%s] Unable to return result.", GetErrorMessage(r));
357 CalendarApp::OnSettingChanged(String& key)
359 AppLogDebug("key: %ls", key.GetPointer());
360 String changedLanguage;
361 String changedRegion;
362 SettingInfo::GetValue(KEY_SYSTEM_LANGUAGE, changedLanguage);
363 SettingInfo::GetValue(KEY_SYSTEM_COUNTRY, changedRegion);
364 if (key == KEY_SYSTEM_LANGUAGE
365 || key == KEY_SYSTEM_COUNTRY
366 || key == KEY_SYSTEM_TIME_ZONE
367 || key == L"http://tizen.org/setting/font.size")
369 if (!(key == KEY_SYSTEM_LANGUAGE && __currentDisplayLang.Equals(changedLanguage)) && !(key == KEY_SYSTEM_COUNTRY &&
370 __currentRegion.Equals(changedRegion)))
372 if (__type != OPERATION_TYPE_MAIN)
374 result r = AppControlProviderManager::GetInstance()->SendAppControlResult(__requestId, APP_CTRL_RESULT_TERMINATED, null);
375 AppLogDebugIf(r != E_SUCCESS, "[%s] Unable to return result.", GetErrorMessage(r));
383 CalendarApp::OnActiveAppChanged(const Tizen::Base::String& appId)
385 if(GetAppId().Equals(appId) == true)
387 AppLogDebug("OnActiveAppChanged %ls",appId.GetPointer());
388 long long mem = GetAvailableMemory();
389 AppLogDebug("%lld",mem);
390 if(mem < MIN_MEMORY_NEEDED)
392 MessageBox LowMemory;
394 LowMemory.Construct(L"",ResourceManager::GetString(IDS_COM_POP_NOT_ENOUGH_MEMORY_DELETE_SOME_ITEMS), MSGBOX_STYLE_OK);
396 // Calls ShowAndWait() : Draws and Shows itself and processes events
397 LowMemory.ShowAndWait(modalResult);
405 CalendarApp::GetAvailableMemory(void)
407 result r = E_SUCCESS;
409 String key(L"http://tizen.org/runtime/storage.available.internal");
410 long long allocatedMemory = 0;
412 r = RuntimeInfo::GetValue(key, allocatedMemory);
413 TryCatch(r == E_SUCCESS, , "MyRuntimeInfo: Failed to get value");
415 return allocatedMemory;