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 delete __pContentManager;
47 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
50 ContentUpdateEventListener*
51 ContentUpdateEventListener::GetInstance(void)
54 if (__pContentUpdateEventListener == null)
58 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
60 return __pContentUpdateEventListener;
63 void ContentUpdateEventListener::AddContentListener(void)
65 __pContentManager->AddContentUpdateEventListener(*this);
68 void ContentUpdateEventListener::RemoveContentListener(void)
70 __pContentManager->RemoveContentUpdateEventListener(*this);
74 ContentUpdateEventListener::Construct(void)
78 __pContentManager = new (std::nothrow) ContentManager();
79 __pContentManager->Construct();
80 __pContentManager->AddContentUpdateEventListener(*this);
82 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
87 ContentUpdateEventListener::CreateInstance(void)
90 __pContentUpdateEventListener = new (std::nothrow) ContentUpdateEventListener();
91 result r = __pContentUpdateEventListener->Construct();
92 if (IsFailed(r) == true)
94 delete __pContentUpdateEventListener;
95 __pContentUpdateEventListener = null;
96 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
101 std::atexit(DestroyInstance);
102 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
106 ContentUpdateEventListener::DestroyInstance(void)
108 AppLogDebug("ENTER");
110 delete __pContentUpdateEventListener;
111 __pContentUpdateEventListener = null;
113 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
117 ContentUpdateEventListener::GetChangeNotificationStatus()
119 AppLogDebug("ENTER");
121 return __changeNotificationReceived;
125 ContentUpdateEventListener::ResumeOperation()
127 AppLogDebug("ENTER");
128 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
129 FileListPresentationModel::GetInstance()->OnContentDeleted();
130 __changeNotificationReceived = false;
135 ContentUpdateEventListener::GetDirecotyNameFromFullPath(const String& fullPath)const
137 AppLogDebug("ENTER");
138 if (fullPath == null)
140 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
144 String delim(DIRECTORY_SEPARATOR);
145 StringTokenizer st(fullPath,delim);
148 while (st.HasMoreTokens())
151 st.GetNextToken(token);
154 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
160 ContentUpdateEventListener::OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
162 AppLogDebug("ENTER");
163 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
165 Tizen::Content::ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
166 String path = cntInfo->GetContentPath();
167 String dirName = GetDirecotyNameFromFullPath(path);
169 FileListPresentationModel* pFileListPM = FileListPresentationModel::GetInstance();
170 pFileListPM->AddDirectoryIfNew(dirName);
171 AlbumListPresentationModel::GetInstance()->OnContentCreated();
172 pFileListPM->OnContentCreated();
179 ContentUpdateEventListener::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
181 AppLogDebug("ENTER");
183 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
185 AlbumListPresentationModel::GetInstance()->OnContentUpdated();
186 FileListPresentationModel::GetInstance()->OnContentUpdated();
192 ContentUpdateEventListener::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
194 AppLogDebug("ENTER");
196 if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
198 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
199 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
201 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
202 FileListPresentationModel::GetInstance()->OnContentDeleted();
206 __changeNotificationReceived = true;
214 ContentUpdateEventListener::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
216 AppLogDebug("ENTER");
218 Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
219 if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
221 AlbumListPresentationModel::GetInstance()->OnContentDeleted();
222 FileListPresentationModel::GetInstance()->OnContentDeleted();
223 AlbumListPresentationModel::GetInstance()->OnContentScanCompleted( directoryPath );
227 __changeNotificationReceived = true;