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