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 GlContentUpdateEventListener.cpp
19 * @brief This is the implementation file for ContentUpdateEventListener class.
24 #include "GlContentUpdateEventListener.h"
25 #include "GlFileListPresentationModel.h"
26 #include "GlAlbumListPresentationModel.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Utility;
31 using namespace Tizen::Content;
33 ContentUpdateEventListener* ContentUpdateEventListener::__pContentUpdateEventListener = null;
35 ContentUpdateEventListener::ContentUpdateEventListener(void)
36 : __pContentManager(null)
37 , __isTimerActive(false)
38 , __changeNotificationReceived(false)
44 ContentUpdateEventListener::~ContentUpdateEventListener(void)
48 if(__pContentManager != null)
50 __pContentManager->RemoveContentUpdateEventListener(*this);
51 delete __pContentManager;
54 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
57 ContentUpdateEventListener*
58 ContentUpdateEventListener::GetInstance(void)
62 if (__pContentUpdateEventListener == null)
66 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
68 return __pContentUpdateEventListener;
71 void ContentUpdateEventListener::AddContentListener(void)
73 if(__pContentManager != null)
75 __pContentManager->AddContentUpdateEventListener(*this);
79 void ContentUpdateEventListener::RemoveContentListener(void)
81 if(__pContentManager != null)
83 __pContentManager->RemoveContentUpdateEventListener(*this);
88 ContentUpdateEventListener::Construct(void)
92 __pContentManager = new (std::nothrow) ContentManager();
94 if (__pContentManager != null)
96 __pContentManager->Construct();
97 __pContentManager->AddContentUpdateEventListener(*this);
100 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
105 ContentUpdateEventListener::CreateInstance(void)
107 AppLogDebug("ENTER");
108 __pContentUpdateEventListener = new (std::nothrow) ContentUpdateEventListener();
110 if (__pContentUpdateEventListener != null)
112 result r = __pContentUpdateEventListener->Construct();
114 if (IsFailed(r) == true)
116 delete __pContentUpdateEventListener;
117 __pContentUpdateEventListener = null;
118 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
123 std::atexit(DestroyInstance);
124 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
128 ContentUpdateEventListener::DestroyInstance(void)
130 AppLogDebug("ENTER");
132 if (__pContentUpdateEventListener != null)
134 delete __pContentUpdateEventListener;
135 __pContentUpdateEventListener = null;
138 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
142 ContentUpdateEventListener::GetChangeNotificationStatus()
144 AppLogDebug("ENTER");
146 return __changeNotificationReceived;
150 ContentUpdateEventListener::ResumeOperation()
152 AppLogDebug("ENTER");
153 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
154 FileListPresentationModel::GetInstance()->OnContentDeleted();
155 __changeNotificationReceived = false;
160 ContentUpdateEventListener::GetDirecotyNameFromFullPath(const String& fullPath)const
162 AppLogDebug("ENTER");
163 if (fullPath == null)
165 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
169 String delim(DIRECTORY_SEPARATOR);
170 StringTokenizer st(fullPath,delim);
173 while (st.HasMoreTokens())
176 st.GetNextToken(token);
179 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
185 ContentUpdateEventListener::OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
187 AppLogDebug("ENTER");
188 if ( !__isTimerActive && ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO) )
190 Tizen::Content::ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
192 if ( cntInfo != NULL)
194 String path = cntInfo->GetContentPath();
195 String dirName = GetDirecotyNameFromFullPath(path);
197 FileListPresentationModel* pFileListPM = FileListPresentationModel::GetInstance();
198 pFileListPM->AddDirectoryIfNew(dirName);
199 AlbumListPresentationModel::GetInstance()->OnContentCreated();
200 pFileListPM->OnContentCreated();
208 ContentUpdateEventListener::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
210 AppLogDebug("ENTER");
212 if ( !__isTimerActive && ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO) )
214 AlbumListPresentationModel::GetInstance()->OnContentUpdated();
215 FileListPresentationModel::GetInstance()->OnContentUpdated();
219 FileListPresentationModel::GetInstance()->OnContentUpdated(contentId);
225 ContentUpdateEventListener::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
227 AppLogDebug("ENTER");
229 if ( !__isTimerActive && ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO) )
231 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
232 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
234 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
235 FileListPresentationModel::GetInstance()->OnContentDeleted();
239 __changeNotificationReceived = true;
247 ContentUpdateEventListener::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
249 AppLogDebug("ENTER");
251 if ( __isTimerActive )
253 AlbumListPresentationModel::GetInstance()->OnContentScanCompleted( directoryPath );
256 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
257 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
259 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
260 FileListPresentationModel::GetInstance()->OnContentDeleted();
261 AlbumListPresentationModel::GetInstance()->OnContentScanCompleted(directoryPath);
265 bool renameHandled = AlbumListPresentationModel::GetInstance()->OnContentScanCompleted(directoryPath);
268 __changeNotificationReceived = true;
275 ContentUpdateEventListener::SetTimerActive(void)
277 __isTimerActive = true;
281 ContentUpdateEventListener::ReSetTimerActive(void)
283 __isTimerActive = false;