NSE_42316
[apps/osp/Gallery.git] / src / GlGalleryApp.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                GlGalleryApp.cpp
19  * @brief               This is the implementation file for GalleryApp class.
20  */
21
22 #include <FUi.h>
23 #include "GlAlbumListPresentationModel.h"
24 #include "GlContentUpdateEventListener.h"\r
25 #include "GlFileListPresentationModel.h"
26 #include "GlGalleryApp.h"
27 #include "GlMainFrame.h"
28 #include "GlSettingPresentationModel.h"
29 #include "GlTypes.h"
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::System;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
40
41 static const wchar_t* PARAM_LANGUAGE = L"http://tizen.org/setting/locale.language";
42 static const wchar_t* PARAM_LOCALE = L"http://tizen.org/setting/locale.country";
43
44 GalleryApp::GalleryApp(void)
45         : __requestId(0)
46         , __pArguments(null)
47         , __appControlResult(APP_CTRL_RESULT_SUCCEEDED)
48 {
49         AppLogDebug("ENTER");
50         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
51 }
52
53 GalleryApp::~GalleryApp(void)
54 {
55         AppLogDebug("ENTER");
56         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
57 }
58
59 UiApp*
60 GalleryApp::CreateInstance(void)
61 {
62         AppLogDebug("ENTER");
63         UiApp* pUiApp = new (std::nothrow) GalleryApp();
64         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
65
66         return pUiApp;
67 }
68
69 String
70 GalleryApp::GetAppControlOperationId(void) const
71 {
72         AppLogDebug("ENTER");
73         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
74
75         return __operationId;
76 }
77
78 String
79 GalleryApp::GetMimeType(void) const
80 {
81         AppLogDebug("ENTER");
82         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
83         return __mimeType;
84 }
85
86 const IMap*
87 GalleryApp::GetAppControlArguments(void) const
88 {
89         AppLogDebug("ENTER");
90         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
91
92         return __pArguments;
93 }
94
95 void
96 GalleryApp::SendAppControlResult(const AppCtrlResult appControlResult, const IMap* pExtraData)
97 {
98         AppLogDebug("ENTER");
99         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
100         result r = pAppManager->SendAppControlResult(__requestId, appControlResult, pExtraData);
101         if (r == E_MAX_EXCEEDED)
102         {
103                 MessageBox messageBox;
104                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_RCS_BODY_MAXIMUM_NUMBER_OF_FILES_EXCEEDED"),
105                                 MSGBOX_STYLE_NONE, 3000);
106                 int modalResult;
107                 messageBox.ShowAndWait(modalResult);
108         }
109
110         AppLogDebug("appControlResult is %d", appControlResult);
111         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
112 }
113
114 bool
115 GalleryApp::OnAppInitializing(AppRegistry& appRegistry)
116 {
117         AppLogDebug("ENTER");
118         AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
119         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
120
121         return true;
122 }
123
124 bool
125 GalleryApp::OnAppInitialized(void)
126 {
127         AppLogDebug("ENTER");
128         MainFrame* pMainFrame = new (std::nothrow) MainFrame();
129         pMainFrame->Construct();
130         AddFrame(*pMainFrame);
131
132         SettingInfo::AddSettingEventListener(*this);
133         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
134
135         return true;
136 }
137
138 bool
139 GalleryApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
140 {
141         AppLogDebug("ENTER");\r
142         ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();\r
143         if (pContentListener)\r
144         {\r
145                 pContentListener->RemoveContentListener();\r
146         }\r
147         AlbumListPresentationModel* pAlbumListPresentationModel = AlbumListPresentationModel::GetInstance();
148         if (pAlbumListPresentationModel != null)
149         {
150                 pAlbumListPresentationModel->ClearThumbnailRequests(true);
151         }
152         FileListPresentationModel* pFileListPresentationModel = FileListPresentationModel::GetInstance();
153         if (pFileListPresentationModel != null)
154         {
155                 pFileListPresentationModel->ClearThumbnailRequests(true);
156         }
157
158         delete __pArguments;
159         __pArguments = null;
160
161         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
162
163         return true;
164 }
165
166 void
167 GalleryApp::OnForeground(void)
168 {
169         AppLogDebug("ENTER");
170         static bool bFirst = true;
171         if (bFirst)
172         {
173                 bFirst = false;
174                 return;
175         }
176
177         MainFrame* pMainFrame = dynamic_cast<MainFrame*>(GetFrameAt(0));
178         if (pMainFrame)
179         {
180                 pMainFrame->SetEnabled(true);
181                 pMainFrame->Invalidate(true);
182         }
183
184         ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
185         if (pContentListener->GetChangeNotificationStatus() == true)
186         {
187                 pContentListener->ResumeOperation();
188         }
189         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
190 }
191
192 void
193 GalleryApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId,
194                 const String* pUriData, const String* pMimeType, const IMap* pExtraData)
195 {
196         AppLogDebug("ENTER");
197         __requestId = reqId;
198         __operationId = operationId;
199
200         if (pMimeType != null)
201         {
202                 __mimeType = *pMimeType;
203         }
204         if (pExtraData != null)
205         {
206                 HashMap* pArguments = new (std::nothrow) HashMap(SingleObjectDeleter);
207                 pArguments->Construct();
208
209                 const String* pKey = null;
210                 const String* pValue = null;
211                 IList* pKeyList = pExtraData->GetKeysN();
212
213                 int loopCount = pKeyList->GetCount();
214                 for (int i = 0; i < loopCount; ++i)
215                 {
216                         pKey = static_cast<const String*>(pKeyList->GetAt(i));
217                         pValue = static_cast<const String*>(pExtraData->GetValue(*pKey));
218
219                         pArguments->Add(new (std::nothrow) String(*pKey), new (std::nothrow) String(*pValue));
220                 }
221                 __pArguments = pArguments;
222                 delete pKeyList;
223         }
224         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
225 }
226
227 void
228 GalleryApp::OnSettingChanged(String& key)
229 {
230         AppLogDebug("ENTER");
231         if (key.CompareTo(PARAM_LANGUAGE) == 0 || key.CompareTo(PARAM_LOCALE) == 0)
232         {
233                 UiApp::GetInstance()->Terminate();
234         }
235         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
236 }
237
238 void
239 GalleryApp::SetFrameEnabled(const bool enabled)
240 {
241         MainFrame* pMainFrame = dynamic_cast<MainFrame*>(GetFrameAt(0));
242         if (pMainFrame)
243         {
244                 pMainFrame->SetEnabled(enabled);
245         }
246 }
247
248 bool
249 GalleryApp::IsHwKeySupported(void)
250 {
251         AppLogDebug("ENTER");
252
253         bool isHwKeyExist = false;
254         Tizen::System::SystemInfo::GetValue(L"http://tizen.org/feature/input.keys.back", isHwKeyExist);
255
256         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
257
258         return isHwKeyExist;
259 }