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