merge with master
[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.0 (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 "GlAlbumListPresentationModel.h"
23 #include "GlBaseForm.h"
24 #include "GlBasePanel.h"
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::GetUriData(void) const
80 {
81         AppLogDebug("ENTER");
82         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
83         return __uriData;
84 }
85
86 String
87 GalleryApp::GetMimeType(void) const
88 {
89         AppLogDebug("ENTER");
90         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
91         return __mimeType;
92 }
93
94 const IMap*
95 GalleryApp::GetAppControlArguments(void) const
96 {
97         AppLogDebug("ENTER");
98         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
99
100         return __pArguments;
101 }
102
103 void
104 GalleryApp::SendAppControlResult(AppCtrlResult appControlResult, IMap* pExtraData)
105 {
106         AppLogDebug("ENTER");
107         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
108         pAppManager->SendAppControlResult(__requestId, appControlResult, pExtraData);
109         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
110 }
111
112 bool
113 GalleryApp::OnAppInitializing(AppRegistry& appRegistry)
114 {
115         AppLogDebug("ENTER");
116         AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
117         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
118
119         return true;
120 }
121
122 bool
123 GalleryApp::OnAppInitialized(void)
124 {
125         AppLogDebug("ENTER");
126         MainFrame* pMainFrame = new (std::nothrow) MainFrame();
127         pMainFrame->Construct();
128         AddFrame(*pMainFrame);
129
130         SettingInfo::AddSettingEventListener(*this);
131         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
132
133         return true;
134 }
135
136 bool
137 GalleryApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
138 {
139         AppLogDebug("ENTER");
140         AlbumListPresentationModel* pAlbumListPresentationModel = AlbumListPresentationModel::GetInstance();
141         if (pAlbumListPresentationModel != null)
142         {
143                 pAlbumListPresentationModel->ClearThumbnailRequests(true);
144         }
145         FileListPresentationModel* pFileListPresentationModel = FileListPresentationModel::GetInstance();
146         if (pFileListPresentationModel != null)
147         {
148                 pFileListPresentationModel->ClearThumbnailRequests(true);
149         }
150
151         Thread::Sleep(1000);
152
153         delete __pArguments;
154         __pArguments = null;
155
156         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
157
158         return true;
159 }
160
161 void
162 GalleryApp::OnForeground(void)
163 {
164         AppLogDebug("ENTER");
165         static bool bFirst = true;
166         if (bFirst)
167         {
168                 bFirst = false;
169                 return;
170         }
171
172         MainFrame* pMainFrame = dynamic_cast<MainFrame*>(GetFrameAt(0));
173         pMainFrame->SetEnabled(true);
174         pMainFrame->Invalidate(true);
175
176         SceneManager* pSceneManager = SceneManager::GetInstance();
177         AppAssert(pSceneManager);
178
179         Scene* pScene = pSceneManager->GetCurrentScene();
180         AppAssert(pSceneManager);
181
182         BasePanel* pBasePanel = dynamic_cast<BasePanel*>(pScene->GetPanel());
183         BaseForm* pBaseForm = dynamic_cast<BaseForm*>(pScene->GetForm());
184
185         if(pBasePanel != null  )
186         {
187                 pBasePanel->OnUpdateContentList();
188         }
189         else
190         {
191                 if (pBaseForm != null)
192                 {
193                         pBaseForm->OnUpdateContentList();
194                 }
195         }
196         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
197 }
198
199 void
200 GalleryApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId,
201                 const String* pUriData, const String* pMimeType, const IMap* pExtraData)
202 {
203         AppLogDebug("ENTER");
204         __requestId = reqId;
205         __operationId = operationId;
206
207         if (pUriData != null)
208         {
209                 __uriData = *pUriData;
210         }
211         if (pMimeType != null)
212         {
213                 __mimeType = *pMimeType;
214         }
215         if (pExtraData != null)
216         {
217                 HashMap* pArguments = new (std::nothrow) HashMap(SingleObjectDeleter);
218                 pArguments->Construct();
219
220                 const String* pKey = null;
221                 const String* pValue = null;
222                 IList* pKeyList = pExtraData->GetKeysN();
223
224                 int loopCount = pKeyList->GetCount();
225                 for (int i = 0; i < loopCount; ++i)
226                 {
227                         pKey = static_cast<const String*>(pKeyList->GetAt(i));
228                         pValue = static_cast<const String*>(pExtraData->GetValue(*pKey));
229
230                         if (pValue != null && pKey->CompareTo(APPCONTROL_RESULT_KEY_LEGACY_RESULT) != 0)
231                         {
232                                 pArguments->Add(new (std::nothrow) String(*pKey), new (std::nothrow) String(*pValue));
233                         }
234                 }
235                 __pArguments = pArguments;
236                 delete pKeyList;
237         }
238         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
239 }
240
241 void
242 GalleryApp::OnSettingChanged(String& key)
243 {
244         AppLogDebug("ENTER");
245         if (key.CompareTo(PARAM_LANGUAGE) == 0 || key.CompareTo(PARAM_LOCALE) == 0)
246         {
247                 UiApp::GetInstance()->Terminate();
248         }
249         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
250 }
251
252 void
253 GalleryApp::SetFrameEnabled(bool enabled)
254 {
255         MainFrame* pMainFrame = dynamic_cast<MainFrame*>(GetFrameAt(0));
256         pMainFrame->SetEnabled(enabled);
257 }