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);
168 if ( cntInfo != NULL)
170 String path = cntInfo->GetContentPath();
171 String dirName = GetDirecotyNameFromFullPath(path);
173 FileListPresentationModel* pFileListPM = FileListPresentationModel::GetInstance();
174 pFileListPM->AddDirectoryIfNew(dirName);
175 AlbumListPresentationModel::GetInstance()->OnContentCreated();
176 pFileListPM->OnContentCreated();
184 ContentUpdateEventListener::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
186 AppLogDebug("ENTER");
188 if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
190 AlbumListPresentationModel::GetInstance()->OnContentUpdated();
191 FileListPresentationModel::GetInstance()->OnContentUpdated();
197 ContentUpdateEventListener::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
199 AppLogDebug("ENTER");
201 if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
203 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
204 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
206 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
207 FileListPresentationModel::GetInstance()->OnContentDeleted();
211 __changeNotificationReceived = true;
219 ContentUpdateEventListener::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
221 AppLogDebug("ENTER");
223 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
224 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
226 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
227 FileListPresentationModel::GetInstance()->OnContentDeleted();
228 AlbumListPresentationModel::GetInstance()->OnContentScanCompleted(directoryPath);
232 bool renameHandled = AlbumListPresentationModel::GetInstance()->OnContentScanCompleted(directoryPath);
235 __changeNotificationReceived = true;