Fix memory leaks
[apps/osp/Gallery.git] / src / GlSettingPresentationModel.cpp
index 0230200..e140215 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
 //
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Io;
-using namespace std;
 
 static const int DEFAULT_VALUE_EFFECT_SLIDE = 0;
 static const int DEFAULT_VALUE_INTERVAL = 3;
+static const int DEFAULT_VALUE_REPEAT = 0;
+static const int DEFAULT_VALUE_SHUFFLE = 0;
 
 const wchar_t* GALLERY_APP_ID = L"ijudt7w61q.Gallery";
 
 const wchar_t* PATH_DATA_DIRECTORY = L"data/";
 const wchar_t* PATH_GALLERY_DEFAULT_SETTINGS = L"GalleryDefaultSettings.ini";
-const wchar_t* PATH_GALLERY_SETTINGS = L"GalleryUserSettings.ini";
 
 const wchar_t* SECTION_GALLERY = L"GALLRY_SETTING";
 const wchar_t* SECTION_IMAGE_VIEWER = L"IMAGE_VIEWER_SETTING";
@@ -42,12 +42,13 @@ const wchar_t* SECTION_VIDEO_PLAYER = L"VIDEO_PLAYER_SETTING";
 
 const wchar_t* SLIDESHOW_INTERVAL_VALUE = L"SLIDESHOW_INTERVAL_VALUE";
 const wchar_t* TRANSITION_EFFECT_VALUE = L"TRANSITION_EFFECT_VALUE";
+const wchar_t* REPEAT_VALUE = L"REPEAT_VALUE";
+const wchar_t* SHUFFLE_VALUE = L"SHUFFLE_VALUE";
 
 SettingPresentationModel* SettingPresentationModel::__pPresentationModelInstance = null;
 
 SettingPresentationModel::SettingPresentationModel(void)
-       :__pDefaultGalleryRegistry(null)
-       ,__pAppGalleryRegistry(null)
+       : __pDefaultGalleryRegistry(null)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -56,6 +57,7 @@ SettingPresentationModel::SettingPresentationModel(void)
 SettingPresentationModel::~SettingPresentationModel(void)
 {
        AppLogDebug("ENTER");
+       delete __pDefaultGalleryRegistry;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -76,59 +78,14 @@ result
 SettingPresentationModel::Construct(void)
 {
        AppLogDebug("ENTER");
-       int valueRegistryNumber = 0;
-       String valueRegistryString = L"";
-       AppManager* pAppManager = AppManager::GetInstance();
-       TryReturn(pAppManager != null, E_FAILURE, "Failed to get AppManager");
-       String pathGallerySetting =
-                       pAppManager->GetAppSharedPath(GALLERY_APP_ID) + PATH_DATA_DIRECTORY + PATH_GALLERY_SETTINGS;
-       AppLogDebug("pathGallerySetting(%ls)", pathGallerySetting.GetPointer());
-
-       __pDefaultGalleryRegistry = new (std::nothrow) Registry();
-       __pAppGalleryRegistry = new (std::nothrow) Registry();
-
        result r = CreateDefaultRegistry();
        TryCatch(r == E_SUCCESS, , "CreateDefaultRegistry() failed[%s]", GetErrorMessage(r));
 
-       if (File::IsFileExist(pathGallerySetting) == true)
-       {
-               AppLogDebug("Already exist camcorder settings file");
-
-               __pAppGalleryRegistry->Construct(pathGallerySetting, "r+");
-       }
-       else
-       {
-               __pAppGalleryRegistry->Construct(pathGallerySetting, "w+");
-               r = __pAppGalleryRegistry->AddSection(SECTION_IMAGE_VIEWER);
-               TryCatch(r == E_SUCCESS, , "Registry::AddSection() failed[%s]", GetErrorMessage(r));
-
-               r = __pDefaultGalleryRegistry->GetValue(SECTION_IMAGE_VIEWER, SLIDESHOW_INTERVAL_VALUE,
-                               valueRegistryNumber);
-               TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
-               r = __pAppGalleryRegistry->AddValue(SECTION_IMAGE_VIEWER, SLIDESHOW_INTERVAL_VALUE, valueRegistryNumber);
-               TryCatch(r == E_SUCCESS, , "Registry::AddValue() failed[%s]", GetErrorMessage(r));
-
-               r = __pDefaultGalleryRegistry->GetValue(SECTION_IMAGE_VIEWER, TRANSITION_EFFECT_VALUE,
-                               valueRegistryString);
-               TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
-               r = __pAppGalleryRegistry->AddValue(SECTION_IMAGE_VIEWER, TRANSITION_EFFECT_VALUE, valueRegistryString);
-               TryCatch(r == E_SUCCESS, , "Registry::AddValue() failed[%s]", GetErrorMessage(r));
-
-               r = __pAppGalleryRegistry->Flush();
-               TryCatch(r == E_SUCCESS, , "Registry::Flush() failed[%s]", GetErrorMessage(r));
-               r = __pDefaultGalleryRegistry->Flush();
-               TryCatch(r == E_SUCCESS, , "Registry::Flush() failed[%s]", GetErrorMessage(r));
-       }
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return r;
 
 CATCH:
-       delete __pDefaultGalleryRegistry;
-       __pDefaultGalleryRegistry = null;
-
-       delete __pAppGalleryRegistry;
-       __pAppGalleryRegistry = null;
        AppLogDebug("EXIT with exception(%s)", GetErrorMessage(GetLastResult()));
 
        return r;
@@ -168,7 +125,7 @@ result
 SettingPresentationModel::GetValue(const String& strSectionName, const String& entryName, int& value) const
 {
        AppLogDebug("ENTER");
-       result r = __pAppGalleryRegistry->GetValue(strSectionName, entryName, value);
+       result r = __pDefaultGalleryRegistry->GetValue(strSectionName, entryName, value);
        TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
@@ -184,7 +141,7 @@ result
 SettingPresentationModel::GetValue(const String& strSectionName, const String& entryName, String& value) const
 {
        AppLogDebug("ENTER");
-       result r = __pAppGalleryRegistry->GetValue(strSectionName, entryName, value);
+       result r = __pDefaultGalleryRegistry->GetValue(strSectionName, entryName, value);
        TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
@@ -200,9 +157,9 @@ result
 SettingPresentationModel::SetValue(const String& strSectionName, const String& entryName, const int value)
 {
        AppLogDebug("ENTER");
-       result r= __pAppGalleryRegistry->SetValue(strSectionName, entryName, value);
+       result r= __pDefaultGalleryRegistry->SetValue(strSectionName, entryName, value);
        TryCatch(r == E_SUCCESS, , "Registry::SetValue() failed[%s]", GetErrorMessage(r));
-       r = __pAppGalleryRegistry->Flush();
+       r = __pDefaultGalleryRegistry->Flush();
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return r;
@@ -217,9 +174,9 @@ result
 SettingPresentationModel::SetValue(const String& strSectionName, const String& entryName, const String& value)
 {
        AppLogDebug("ENTER");
-       result r = __pAppGalleryRegistry->SetValue(strSectionName, entryName, value);
+       result r = __pDefaultGalleryRegistry->SetValue(strSectionName, entryName, value);
        TryCatch(r == E_SUCCESS, , "Registry::SetValue() failed[%s]", GetErrorMessage(r));
-       r = __pAppGalleryRegistry->Flush();
+       r = __pDefaultGalleryRegistry->Flush();
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return r;
@@ -241,6 +198,7 @@ SettingPresentationModel::CreateDefaultRegistry(void)
                        pAppManager->GetAppSharedPath(GALLERY_APP_ID) + PATH_DATA_DIRECTORY + PATH_GALLERY_DEFAULT_SETTINGS;
        AppLogDebug("pathGalleryDefaultSetting(%ls)", pathGalleryDefaultSetting.GetPointer());
 
+       __pDefaultGalleryRegistry = new (std::nothrow) Registry();
        if (File::IsFileExist(pathGalleryDefaultSetting))
        {
                AppLogDebug("Already exist default settings file");
@@ -263,40 +221,24 @@ SettingPresentationModel::CreateDefaultRegistry(void)
                                DEFAULT_VALUE_EFFECT_SLIDE);
                TryCatch(r == E_SUCCESS, , "Registry::AddValue() failed[%s]", GetErrorMessage(r));
 
-               r = __pDefaultGalleryRegistry->Flush();
-               TryCatch(r == E_SUCCESS, , "Registry::Flush() failed[%s]", GetErrorMessage(r));
-       }
-       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
-
-       return r;
-
-CATCH:
-       AppLogDebug("EXIT with exception(%s)", GetErrorMessage(GetLastResult()));
-
-       return r;
-}
+               r = __pDefaultGalleryRegistry->AddValue(SECTION_IMAGE_VIEWER, REPEAT_VALUE,
+                               DEFAULT_VALUE_REPEAT);
+               TryCatch(r == E_SUCCESS, , "Registry::AddValue() failed[%s]", GetErrorMessage(r));
 
-result
-SettingPresentationModel::ResetGallerySettingsRegistry(void)
-{
-       AppLogDebug("ENTER");
-       AppManager* pAppManager = AppManager::GetInstance();
-       TryReturn(pAppManager != null, E_FAILURE, "Failed to get AppManager");
-       String pathGallerySetting =
-                       pAppManager->GetAppSharedPath(GALLERY_APP_ID) + PATH_DATA_DIRECTORY + PATH_GALLERY_SETTINGS;
+               r = __pDefaultGalleryRegistry->AddValue(SECTION_IMAGE_VIEWER, SHUFFLE_VALUE,
+                               DEFAULT_VALUE_SHUFFLE);
+               TryCatch(r == E_SUCCESS, , "Registry::AddValue() failed[%s]", GetErrorMessage(r));
 
-       if (File::IsFileExist(pathGallerySetting))
-       {
-               File::Remove(pathGallerySetting);
+               r = __pDefaultGalleryRegistry->Flush();
+               TryCatch(r == E_SUCCESS, , "Registry::Flush() failed[%s]", GetErrorMessage(r));
        }
-
-       result r = Construct();
-       TryCatch(r == E_SUCCESS, , "CameraSettingsPresentationModel::Construct() failed[%s]", GetErrorMessage(r));
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return r;
 
 CATCH:
+       delete __pDefaultGalleryRegistry;
+       __pDefaultGalleryRegistry = null;
        AppLogDebug("EXIT with exception(%s)", GetErrorMessage(GetLastResult()));
 
        return r;