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 , __changeNotificationReceived(false)
43 ContentUpdateEventListener::~ContentUpdateEventListener(void)
46 __pContentManager->RemoveContentUpdateEventListener(*this);
47 delete __pContentManager;
48 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
51 ContentUpdateEventListener*
52 ContentUpdateEventListener::GetInstance(void)
55 if (__pContentUpdateEventListener == null)
59 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
61 return __pContentUpdateEventListener;
64 void ContentUpdateEventListener::AddContentListener(void)
66 __pContentManager->AddContentUpdateEventListener(*this);
69 void ContentUpdateEventListener::RemoveContentListener(void)
71 __pContentManager->RemoveContentUpdateEventListener(*this);
75 ContentUpdateEventListener::Construct(void)
79 __pContentManager = new (std::nothrow) ContentManager();
80 __pContentManager->Construct();
81 __pContentManager->AddContentUpdateEventListener(*this);
83 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
88 ContentUpdateEventListener::CreateInstance(void)
91 __pContentUpdateEventListener = new (std::nothrow) ContentUpdateEventListener();
92 result r = __pContentUpdateEventListener->Construct();
93 if (IsFailed(r) == true)
95 delete __pContentUpdateEventListener;
96 __pContentUpdateEventListener = null;
97 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
102 std::atexit(DestroyInstance);
103 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
107 ContentUpdateEventListener::DestroyInstance(void)
109 AppLogDebug("ENTER");
111 delete __pContentUpdateEventListener;
112 __pContentUpdateEventListener = null;
114 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
118 ContentUpdateEventListener::GetChangeNotificationStatus()
120 AppLogDebug("ENTER");
122 return __changeNotificationReceived;
126 ContentUpdateEventListener::ResumeOperation()
128 AppLogDebug("ENTER");
129 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
130 FileListPresentationModel::GetInstance()->OnContentDeleted();
131 __changeNotificationReceived = false;
136 ContentUpdateEventListener::GetDirecotyNameFromFullPath(const String& fullPath)const
138 AppLogDebug("ENTER");
139 if (fullPath == null)
141 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
145 String delim(DIRECTORY_SEPARATOR);
146 StringTokenizer st(fullPath,delim);
149 while (st.HasMoreTokens())
152 st.GetNextToken(token);
155 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
161 ContentUpdateEventListener::OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
163 AppLogDebug("ENTER");
164 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
166 Tizen::Content::ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
167 String path = cntInfo->GetContentPath();
168 String dirName = GetDirecotyNameFromFullPath(path);
170 FileListPresentationModel* pFileListPM = FileListPresentationModel::GetInstance();
171 pFileListPM->AddDirectoryIfNew(dirName);
172 AlbumListPresentationModel::GetInstance()->OnContentCreated();
173 pFileListPM->OnContentCreated();
180 ContentUpdateEventListener::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
182 AppLogDebug("ENTER");
184 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
186 AlbumListPresentationModel::GetInstance()->OnContentUpdated();
187 FileListPresentationModel::GetInstance()->OnContentUpdated();
193 ContentUpdateEventListener::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
195 AppLogDebug("ENTER");
197 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
199 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
200 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
202 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
203 FileListPresentationModel::GetInstance()->OnContentDeleted();
207 __changeNotificationReceived = true;
215 ContentUpdateEventListener::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
217 AppLogDebug("ENTER");
219 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
220 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
222 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
223 FileListPresentationModel::GetInstance()->OnContentDeleted();
224 AlbumListPresentationModel::GetInstance()->OnContentScanCompleted( directoryPath );
228 __changeNotificationReceived = true;