Fix for 45039
[apps/osp/Gallery.git] / src / GlContentUpdateEventListener.cpp
index 1704d0f..6093b72 100644 (file)
@@ -1,7 +1,7 @@
 //
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
  * @brief              This is the implementation file for ContentUpdateEventListener class.
  */
 
+#include <FApp.h>
+#include <FUi.h>
 #include "GlContentUpdateEventListener.h"
 #include "GlFileListPresentationModel.h"
 #include "GlAlbumListPresentationModel.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
 using namespace Tizen::Content;
 
 ContentUpdateEventListener* ContentUpdateEventListener::__pContentUpdateEventListener = null;
 
 ContentUpdateEventListener::ContentUpdateEventListener(void)
        : __pContentManager(null)
-       ,__isSingleFileUpdate(false)
+       , __changeNotificationReceived(false)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT");
@@ -41,6 +44,7 @@ ContentUpdateEventListener::~ContentUpdateEventListener(void)
 {
        AppLogDebug("ENTER");
        __pContentManager->RemoveContentUpdateEventListener(*this);
+       delete __pContentManager;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -57,6 +61,16 @@ ContentUpdateEventListener::GetInstance(void)
        return __pContentUpdateEventListener;
 }
 
+void ContentUpdateEventListener::AddContentListener(void)
+{
+       __pContentManager->AddContentUpdateEventListener(*this);
+}
+
+void ContentUpdateEventListener::RemoveContentListener(void)
+{
+       __pContentManager->RemoveContentUpdateEventListener(*this);
+}
+
 result
 ContentUpdateEventListener::Construct(void)
 {
@@ -100,13 +114,64 @@ ContentUpdateEventListener::DestroyInstance(void)
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
+bool
+ContentUpdateEventListener::GetChangeNotificationStatus()
+{
+       AppLogDebug("ENTER");
+       AppLogDebug("EXIT");
+       return __changeNotificationReceived;
+}
+
+void
+ContentUpdateEventListener::ResumeOperation()
+{
+       AppLogDebug("ENTER");
+       AlbumListPresentationModel::GetInstance()->OnContentDeleted();
+       FileListPresentationModel::GetInstance()->OnContentDeleted();
+       __changeNotificationReceived = false;
+       AppLogDebug("EXIT");
+}
+
+String
+ContentUpdateEventListener::GetDirecotyNameFromFullPath(const String& fullPath)const
+{
+       AppLogDebug("ENTER");
+       if (fullPath == null)
+       {
+               AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
+
+               return null;
+       }
+       String delim(DIRECTORY_SEPARATOR);
+       StringTokenizer st(fullPath,delim);
+       String token;
+       String tokenPrev;
+       while (st.HasMoreTokens())
+       {
+               tokenPrev = token;
+               st.GetNextToken(token);
+       }
+
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+       return tokenPrev;
+}
+
 void
 ContentUpdateEventListener::OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
 {
        AppLogDebug("ENTER");
-       __isSingleFileUpdate = true;
-       AlbumListPresentationModel::GetInstance()->OnContentCreated();
-       FileListPresentationModel::GetInstance()->OnContentCreated();
+       if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
+       {
+               Tizen::Content::ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
+               String path = cntInfo->GetContentPath();
+               String dirName = GetDirecotyNameFromFullPath(path);
+
+               FileListPresentationModel* pFileListPM = FileListPresentationModel::GetInstance();
+               pFileListPM->AddDirectoryIfNew(dirName);
+               AlbumListPresentationModel::GetInstance()->OnContentCreated();
+               pFileListPM->OnContentCreated();
+       }
 
        AppLogDebug("EXIT");
 }
@@ -115,10 +180,12 @@ void
 ContentUpdateEventListener::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
 {
        AppLogDebug("ENTER");
-       __isSingleFileUpdate = true;
-       AlbumListPresentationModel::GetInstance()->OnContentUpdated();
-       FileListPresentationModel::GetInstance()->OnContentUpdated();
-
+       
+       if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
+       {
+               AlbumListPresentationModel::GetInstance()->OnContentUpdated();
+               FileListPresentationModel::GetInstance()->OnContentUpdated();
+       }
        AppLogDebug("EXIT");
 }
 
@@ -126,10 +193,21 @@ void
 ContentUpdateEventListener::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
 {
        AppLogDebug("ENTER");
-       __isSingleFileUpdate = true;
-       AlbumListPresentationModel::GetInstance()->OnContentDeleted();
-       FileListPresentationModel::GetInstance()->OnContentDeleted();
 
+       if ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO)
+       {
+               Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
+               if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
+               {
+                       AlbumListPresentationModel::GetInstance()->OnContentDeleted();
+                       FileListPresentationModel::GetInstance()->OnContentDeleted();
+               }
+               else
+               {
+                       __changeNotificationReceived = true;
+               }
+
+       }
        AppLogDebug("EXIT");
 }
 
@@ -137,14 +215,18 @@ void
 ContentUpdateEventListener::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
 {
        AppLogDebug("ENTER");
-       if (__isSingleFileUpdate == false)
+
+       Tizen::App::UiApp* appPtr = Tizen::App::UiApp::GetInstance();
+       if (appPtr->GetAppUiState() == Tizen::App::APP_UI_STATE_FOREGROUND)
        {
                AlbumListPresentationModel::GetInstance()->OnContentDeleted();
                FileListPresentationModel::GetInstance()->OnContentDeleted();
+               AlbumListPresentationModel::GetInstance()->OnContentScanCompleted( directoryPath );
        }
        else
        {
-               __isSingleFileUpdate = false;
-       }
+               __changeNotificationReceived = true;
+       }\r
+
        AppLogDebug("EXIT");
 }