Fixed prevent issue
[apps/osp/Gallery.git] / src / GlContentUpdateEventListener.cpp
index 1704d0f..75eb02f 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)
+       , __isTimerActive(false)
+       , __changeNotificationReceived(false)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT");
@@ -41,6 +45,7 @@ ContentUpdateEventListener::~ContentUpdateEventListener(void)
 {
        AppLogDebug("ENTER");
        __pContentManager->RemoveContentUpdateEventListener(*this);
+       delete __pContentManager;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -57,6 +62,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 +115,68 @@ 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 ( !__isTimerActive && ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO) )
+       {
+               Tizen::Content::ContentInfo* cntInfo = __pContentManager->GetContentInfoN(contentId);
+
+               if ( cntInfo != NULL)
+               {
+                       String path = cntInfo->GetContentPath();
+                       String dirName = GetDirecotyNameFromFullPath(path);
+
+                       FileListPresentationModel* pFileListPM = FileListPresentationModel::GetInstance();
+                       pFileListPM->AddDirectoryIfNew(dirName);
+                       AlbumListPresentationModel::GetInstance()->OnContentCreated();
+                       pFileListPM->OnContentCreated();
+               }
+       }
 
        AppLogDebug("EXIT");
 }
@@ -115,10 +185,16 @@ void
 ContentUpdateEventListener::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
 {
        AppLogDebug("ENTER");
-       __isSingleFileUpdate = true;
-       AlbumListPresentationModel::GetInstance()->OnContentUpdated();
-       FileListPresentationModel::GetInstance()->OnContentUpdated();
-
+       
+       if ( !__isTimerActive && ( contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO) )
+       {
+               AlbumListPresentationModel::GetInstance()->OnContentUpdated();
+               FileListPresentationModel::GetInstance()->OnContentUpdated();
+       }
+       else
+       {
+               FileListPresentationModel::GetInstance()->OnContentUpdated(contentId);
+       }
        AppLogDebug("EXIT");
 }
 
@@ -126,10 +202,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 ( !__isTimerActive && ( 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 +224,38 @@ void
 ContentUpdateEventListener::OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r)
 {
        AppLogDebug("ENTER");
-       if (__isSingleFileUpdate == false)
+
+       if ( __isTimerActive )
+       {
+               AlbumListPresentationModel::GetInstance()->OnContentScanCompleted( directoryPath );
+               return;
+       }
+       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;
-       }
+               bool renameHandled = AlbumListPresentationModel::GetInstance()->OnContentScanCompleted(directoryPath);
+               if (!renameHandled)
+               {
+                       __changeNotificationReceived = true;
+               }
+       }\r
+
        AppLogDebug("EXIT");
 }
+void
+ContentUpdateEventListener::SetTimerActive(void)
+{
+       __isTimerActive = true;
+}
+
+void
+ContentUpdateEventListener::ReSetTimerActive(void)
+{
+       __isTimerActive = false;
+}