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)
47 __pContentManager->RemoveContentUpdateEventListener(*this);
48 delete __pContentManager;
49 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
52 ContentUpdateEventListener*
53 ContentUpdateEventListener::GetInstance(void)
56 if (__pContentUpdateEventListener == null)
60 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
62 return __pContentUpdateEventListener;
65 void ContentUpdateEventListener::AddContentListener(void)
67 __pContentManager->AddContentUpdateEventListener(*this);
70 void ContentUpdateEventListener::RemoveContentListener(void)
72 __pContentManager->RemoveContentUpdateEventListener(*this);
76 ContentUpdateEventListener::Construct(void)
80 __pContentManager = new (std::nothrow) ContentManager();
81 __pContentManager->Construct();
82 __pContentManager->AddContentUpdateEventListener(*this);
84 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
89 ContentUpdateEventListener::CreateInstance(void)
92 __pContentUpdateEventListener = new (std::nothrow) ContentUpdateEventListener();
93 result r = __pContentUpdateEventListener->Construct();
94 if (IsFailed(r) == true)
96 delete __pContentUpdateEventListener;
97 __pContentUpdateEventListener = null;
98 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
103 std::atexit(DestroyInstance);
104 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
108 ContentUpdateEventListener::DestroyInstance(void)
110 AppLogDebug("ENTER");
112 delete __pContentUpdateEventListener;
113 __pContentUpdateEventListener = null;
115 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
119 ContentUpdateEventListener::GetChangeNotificationStatus()
121 AppLogDebug("ENTER");
123 return __changeNotificationReceived;
127 ContentUpdateEventListener::ResumeOperation()
129 AppLogDebug("ENTER");
130 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
131 FileListPresentationModel::GetInstance()->OnContentDeleted();
132 __changeNotificationReceived = false;
137 ContentUpdateEventListener::GetDirecotyNameFromFullPath(const String& fullPath)const
139 AppLogDebug("ENTER");
140 if (fullPath == null)
142 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
146 String delim(DIRECTORY_SEPARATOR);
147 StringTokenizer st(fullPath,delim);
150 while (st.HasMoreTokens())
153 st.GetNextToken(token);
156 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
162 ContentUpdateEventListener::OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
164 AppLogDebug("ENTER");
165 if ( !__isTimerActive && ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO) )
167 Tizen::Content::ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
169 if ( cntInfo != NULL)
171 String path = cntInfo->GetContentPath();
172 String dirName = GetDirecotyNameFromFullPath(path);
174 FileListPresentationModel* pFileListPM = FileListPresentationModel::GetInstance();
175 pFileListPM->AddDirectoryIfNew(dirName);
176 AlbumListPresentationModel::GetInstance()->OnContentCreated();
177 pFileListPM->OnContentCreated();
185 ContentUpdateEventListener::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
187 AppLogDebug("ENTER");
189 if ( !__isTimerActive && ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO) )
191 AlbumListPresentationModel::GetInstance()->OnContentUpdated();
192 FileListPresentationModel::GetInstance()->OnContentUpdated();
196 FileListPresentationModel::GetInstance()->OnContentUpdated(contentId);
202 ContentUpdateEventListener::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
204 AppLogDebug("ENTER");
206 if ( !__isTimerActive && ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO) )
208 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
209 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
211 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
212 FileListPresentationModel::GetInstance()->OnContentDeleted();
216 __changeNotificationReceived = true;
224 ContentUpdateEventListener::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
226 AppLogDebug("ENTER");
228 if ( __isTimerActive )
230 AlbumListPresentationModel::GetInstance()->OnContentScanCompleted( directoryPath );
233 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
234 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
236 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
237 FileListPresentationModel::GetInstance()->OnContentDeleted();
238 AlbumListPresentationModel::GetInstance()->OnContentScanCompleted(directoryPath);
242 bool renameHandled = AlbumListPresentationModel::GetInstance()->OnContentScanCompleted(directoryPath);
245 __changeNotificationReceived = true;
252 ContentUpdateEventListener::SetTimerActive(void)
254 __isTimerActive = true;
258 ContentUpdateEventListener::ReSetTimerActive(void)
260 __isTimerActive = false;