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)
42 ContentUpdateEventListener::~ContentUpdateEventListener(void)
45 __pContentManager->RemoveContentUpdateEventListener(*this);
46 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
49 ContentUpdateEventListener*
50 ContentUpdateEventListener::GetInstance(void)
53 if (__pContentUpdateEventListener == null)
57 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
59 return __pContentUpdateEventListener;
62 void ContentUpdateEventListener::AddContentListener(void)
64 __pContentManager->AddContentUpdateEventListener(*this);
67 void ContentUpdateEventListener::RemoveContentListener(void)
69 __pContentManager->RemoveContentUpdateEventListener(*this);
73 ContentUpdateEventListener::Construct(void)
77 __pContentManager = new (std::nothrow) ContentManager();
78 __pContentManager->Construct();
79 __pContentManager->AddContentUpdateEventListener(*this);
81 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
86 ContentUpdateEventListener::CreateInstance(void)
89 __pContentUpdateEventListener = new (std::nothrow) ContentUpdateEventListener();
90 result r = __pContentUpdateEventListener->Construct();
91 if (IsFailed(r) == true)
93 delete __pContentUpdateEventListener;
94 __pContentUpdateEventListener = null;
95 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
100 std::atexit(DestroyInstance);
101 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
105 ContentUpdateEventListener::DestroyInstance(void)
107 AppLogDebug("ENTER");
109 delete __pContentUpdateEventListener;
110 __pContentUpdateEventListener = null;
112 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
116 ContentUpdateEventListener::GetChangeNotificationStatus()
118 AppLogDebug("ENTER");
120 return __changeNotificationReceived;
124 ContentUpdateEventListener::ResumeOperation()
126 AppLogDebug("ENTER");
127 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
128 FileListPresentationModel::GetInstance()->OnContentDeleted();
129 __changeNotificationReceived = false;
134 ContentUpdateEventListener::GetDirecotyNameFromFullPath(const String& fullPath)const
136 AppLogDebug("ENTER");
137 if (fullPath == null)
139 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
143 String delim(DIRECTORY_SEPARATOR);
144 StringTokenizer st(fullPath,delim);
147 while (st.HasMoreTokens())
150 st.GetNextToken(token);
153 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
159 ContentUpdateEventListener::OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
161 AppLogDebug("ENTER");
162 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
164 Tizen::Content::ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
165 String path = cntInfo->GetContentPath();
166 String dirName = GetDirecotyNameFromFullPath(path);
168 FileListPresentationModel* pFileListPM = FileListPresentationModel::GetInstance();
169 pFileListPM->AddDirectoryIfNew(dirName);
170 AlbumListPresentationModel::GetInstance()->OnContentCreated();
171 pFileListPM->OnContentCreated();
178 ContentUpdateEventListener::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
180 AppLogDebug("ENTER");
182 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
184 AlbumListPresentationModel::GetInstance()->OnContentUpdated();
185 FileListPresentationModel::GetInstance()->OnContentUpdated();
191 ContentUpdateEventListener::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
193 AppLogDebug("ENTER");
195 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
197 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
198 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
200 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
201 FileListPresentationModel::GetInstance()->OnContentDeleted();
205 __changeNotificationReceived = true;
213 ContentUpdateEventListener::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
215 AppLogDebug("ENTER");
217 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
218 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
220 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
221 FileListPresentationModel::GetInstance()->OnContentDeleted();
222 AlbumListPresentationModel::GetInstance()->OnContentScanCompleted( directoryPath );
226 __changeNotificationReceived = true;