Modification to manage album list using CAlbumStorage class. 92/36692/1 accepted/tizen/tv/20150312.061520 submit/tizen_tv/20150312.045445
authorKim Tae Soo <taesoo46.kim@samsung.com>
Thu, 12 Mar 2015 03:11:10 +0000 (12:11 +0900)
committerKim Tae Soo <taesoo46.kim@samsung.com>
Thu, 12 Mar 2015 03:11:10 +0000 (12:11 +0900)
Change-Id: Ifa3e99c9ec5a1d45aefc91a0f58dbd5688bcbae0
Signed-off-by: Kim Tae Soo <taesoo46.kim@samsung.com>
CMakeLists.txt
include/AlbumStorage.h [new file with mode: 0644]
include/mediadata.h
src/data/AlbumStorage.cpp [new file with mode: 0644]
src/data/mediadata.cpp

index 173cc4c..31ace97 100644 (file)
@@ -88,6 +88,7 @@ SET(SRCS src/main.cpp
         src/data/bus.cpp
         src/data/CategoryStorage.cpp
         src/data/SongStorage.cpp
+        src/data/AlbumStorage.cpp
 )
 
 SET(TARGET_EDJ "${PROJECT_NAME}.edj")
diff --git a/include/AlbumStorage.h b/include/AlbumStorage.h
new file mode 100644 (file)
index 0000000..517214f
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ALBUM_STORAGE_H__
+#define __ALBUM_STORAGE_H__
+
+#include "SongStorage.h"
+
+class CAlbumStorage {
+private:
+       Eina_List *elList;
+       filter_h m_filter;
+       CAlbumSongStorage *m_storageAlbumSong;
+
+private:
+       static bool sm_CbOnEachAlbum(media_album_h ah, void *dt);
+       bool m_OnEachAlbum(media_album_h ah);
+       virtual bool m_GetAlbumList(void);
+
+public:
+       CAlbumStorage(CAlbumSongStorage *storageAlbumSong) {
+               elList = NULL;
+               m_storageAlbumSong = storageAlbumSong;
+       }
+       virtual ~CAlbumStorage() {}
+
+       Eina_List *List(void);
+       void Delete(void);
+
+       bool Update(filter_h filter);
+};
+
+#endif //__ALBUM_STORAGE_H__
\ No newline at end of file
index 3e9f4a6..8648e8b 100644 (file)
@@ -46,14 +46,11 @@ private:
 private:
        static bool sm_CbTotalDuration(media_info_h md_h, void *dt);
        static bool sm_CbEachFolderData(media_folder_h folder_h, void *dt);
-       static bool sm_CbEachAlbumData(media_album_h album_h, void *dt);
        static bool sm_CbPlaylist(media_playlist_h ph, void *dt);
 
 private:
        bool m_HandleEachFolderData(media_folder_h folder_h);
-       bool m_HandleEachAlbumData(media_album_h album_h);
        void m_DeleteFolderList(void);
-       void m_DeleteAlbumList(void);
        void m_DeleteCategoryList(ECategoryType type);
 
        bool m_CreateFilter(void);
@@ -61,7 +58,6 @@ private:
 
        void m_GetCategoryList(ECategoryType type);
        int m_GetFolderList(void);
-       int m_GetAlbumList(void);
        void m_UpdateLists(void);
 
 public:
diff --git a/src/data/AlbumStorage.cpp b/src/data/AlbumStorage.cpp
new file mode 100644 (file)
index 0000000..b02eaa2
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <Eina.h>
+#include <media_content.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <string.h>
+#include "dbg.h"
+#include "i18n.h"
+#include "define.h"
+
+#include <AppCommon.h>
+#include "song_info.h"
+#include "album_info.h"
+#include "category_info.h"
+#include "folder_info.h"
+#include "SongStorage.h"
+#include "AlbumStorage.h"
+#include "common.h"
+
+
+bool CAlbumStorage::sm_CbOnEachAlbum(media_album_h ah, void *dt)
+{
+       CAlbumStorage *root = (CAlbumStorage *)dt;
+       bool r = false;
+       if (root)
+               r = root->m_OnEachAlbum(ah);
+
+       return r;
+}
+
+
+bool CAlbumStorage::m_OnEachAlbum(media_album_h ah)
+{
+       _CREATE_BEGIN {
+               CAlbumInfo *alinfo = NULL;
+               CSongInfo *songInfo = NULL;
+               Eina_List *l = NULL;
+               void *obj = NULL;
+               int albumId;
+               char *name;
+               char *artist;
+               int songCount;
+               char *genre;
+               char *thumbnailPath;
+
+               _CHECK(alinfo = new CAlbumInfo)
+               _CHECK(alinfo->Create())
+               _CHECK(media_album_get_album_id(ah, &albumId) == MEDIA_CONTENT_ERROR_NONE)
+               _CHECK(media_album_get_name(ah, &name) == MEDIA_CONTENT_ERROR_NONE)
+               _CHECK(media_album_get_artist(ah, &artist) == MEDIA_CONTENT_ERROR_NONE)
+               _CHECK(media_album_get_media_count_from_db(alinfo->AlbumId(), m_filter, &songCount))
+
+               _WHEN_SUCCESS{
+                       alinfo->SetAlbumId(albumId);
+                       alinfo->SetName(name);
+                       alinfo->SetArtist(artist);
+                       alinfo->SetSongCount(songCount);
+
+                       m_storageAlbumSong->Update(alinfo, m_filter);
+
+                       EINA_LIST_FOREACH(m_storageAlbumSong->List(), l, obj) {
+                               songInfo = (CSongInfo *)obj;
+                               genre = songInfo->Genre();
+                               if (genre) {
+                                       alinfo->SetGenre(genre);
+                                       break;
+                               }
+                       }
+
+                       EINA_LIST_FOREACH(m_storageAlbumSong->List(), l, obj) {
+                               songInfo = (CSongInfo *)obj;
+                               thumbnailPath = songInfo->ThumbnailPath();
+                               if (thumbnailPath) {
+                                       alinfo->SetThumbnailPath(thumbnailPath);
+                                       break;
+                               }
+                       }
+
+                       elList = eina_list_append(elList, alinfo);
+               }
+
+               _CHECK_FAIL{}
+               _CHECK_FAIL{}
+               _CHECK_FAIL{}
+               _CHECK_FAIL{}
+               _CHECK_FAIL{ alinfo->Destroy(); }
+               _CHECK_FAIL{ delete alinfo; }
+       } _CREATE_END_AND_CATCH{ return false; }
+
+       return true;
+}
+
+
+bool CAlbumStorage::m_GetAlbumList(void)
+{
+       int r;
+
+       r = media_album_foreach_album_from_db(m_filter,
+               sm_CbOnEachAlbum, (void *)this);
+       if (r != MEDIA_CONTENT_ERROR_NONE) {
+               _ERR("Media album foreach album from db failed");
+               return false;
+       }
+
+       return true;
+}
+
+
+Eina_List *CAlbumStorage::List(void)
+{
+       return elList;
+}
+
+
+void CAlbumStorage::Delete(void)
+{
+       if (!elList)
+               return;
+
+       CAlbumInfo *alinfo = NULL;
+       void *obj = NULL;
+
+       EINA_LIST_FREE(elList, obj) {
+               alinfo = (CAlbumInfo *)obj;
+               alinfo->Destroy();
+               delete alinfo;
+       }
+
+       elList = NULL;
+}
+
+
+bool CAlbumStorage::Update(filter_h filter)
+{
+       m_filter = filter;
+
+       Delete();
+       m_GetAlbumList();
+       return true;
+}
\ No newline at end of file
index 9cf3bb9..e08035c 100644 (file)
@@ -30,6 +30,7 @@
 #include "folder_info.h"
 #include "CategoryStorage.h"
 #include "SongStorage.h"
+#include "AlbumStorage.h"
 #include "mediadata.h"
 #include "common.h"
 
 #define MUSIC_STR_UNKNOWN              N_("Unknown")
 
 
-enum songlist_type {
-       E_ALL_SONGS,
-       E_ALBUM_SONGS,
-       E_FOLDER_SONGS,
-       E_PLAYLIST_SONGS,
-       E_SINGLE_SONG
-};
-
-
 struct SMediadata {
        Eina_List *folderlist;
-       Eina_List *albumlist;
 
        CSongsSongStorage    *storageSong;
        CAlbumSongStorage    *storageAlbumSong;
@@ -58,6 +49,8 @@ struct SMediadata {
        CPlaylistSongStorage *storagePlaylistSong;
        CSingleSongStorage   *storageSingleSong;
 
+       CAlbumStorage *storageAlbum;
+
        CPlaylistStorage *storagePlaylist;
        CArtistStorage   *storageArtist;
        CGenreStorage    *storageGenre;
@@ -76,6 +69,7 @@ struct SMediadata {
                storageAlbumSong = new CAlbumSongStorage;
                storagePlaylistSong = new CPlaylistSongStorage;
                storageSingleSong = new CSingleSongStorage;
+               storageAlbum = new CAlbumStorage(storageAlbumSong);
                storagePlaylist = new CPlaylistStorage;
                storageArtist = new CArtistStorage;
                storageGenre = new CGenreStorage;
@@ -84,6 +78,7 @@ struct SMediadata {
                delete storageGenre;
                delete storageArtist;
                delete storagePlaylist;
+               delete storageAlbum;
                delete storageSingleSong;
                delete storagePlaylistSong;
                delete storageAlbumSong;
@@ -276,20 +271,6 @@ bool CMediadata::sm_CbEachFolderData(media_folder_h folder_h, void *dt)
 }
 
 
-bool CMediadata::sm_CbEachAlbumData(media_album_h album_h, void *dt)
-{
-       CMediadata *root = (CMediadata *)dt;
-
-       if (!root)
-               return false;
-
-       root->m_HandleEachAlbumData(album_h);
-
-       return true;
-}
-
-
-
 bool CMediadata::sm_CbPlaylist(media_playlist_h ph, void* dt)
 {
        Eina_List **list = (Eina_List **)dt;
@@ -386,89 +367,6 @@ bool CMediadata::m_HandleEachFolderData(media_folder_h folder_h)
 }
 
 
-bool CMediadata::m_HandleEachAlbumData(media_album_h album_h)
-{
-       CAlbumInfo *alinfo = NULL;
-       CSongInfo *songInfo = NULL;
-       void *obj = NULL;
-       char *tmpStr = NULL;
-       int tmpValue;
-       Eina_List *l = NULL;
-       bool ret;
-
-       alinfo = new CAlbumInfo;
-       if (!alinfo) {
-               _ERR("Memory alloc failed");
-               return false;
-       }
-
-       ret = alinfo->Create();
-       if (!ret) {
-               _ERR("CAlbumInfo creation failed");
-               delete alinfo;
-               return false;
-       }
-
-       if (media_album_get_album_id(album_h, &tmpValue) !=
-               MEDIA_CONTENT_ERROR_NONE) {
-               _ERR("Album ID Fetch error");
-               alinfo->Destroy();
-               delete alinfo;
-               return false;
-       }
-       alinfo->SetAlbumId(tmpValue);
-
-       if (media_album_get_name(album_h, &tmpStr) !=
-               MEDIA_CONTENT_ERROR_NONE) {
-               _ERR("Album name Fetch error");
-               alinfo->Destroy();
-               delete alinfo;
-               return false;
-       }
-       alinfo->SetName(tmpStr);
-
-       if (media_album_get_artist(album_h, &tmpStr) !=
-               MEDIA_CONTENT_ERROR_NONE) {
-               _ERR("Album artist Fetch error");
-               alinfo->Destroy();
-               delete alinfo;
-               return false;
-       }
-       alinfo->SetArtist(tmpStr);
-
-       if (media_album_get_media_count_from_db(alinfo->AlbumId(), m->filter, &tmpValue)) {
-               _ERR("Album artist Fetch error");
-               alinfo->Destroy();
-               delete alinfo;
-               return false;
-       }
-       alinfo->SetSongCount(tmpValue);
-
-       m->storageAlbumSong->Update(alinfo, m->filter);
-
-       EINA_LIST_FOREACH(m->storageAlbumSong->List(), l, obj) {
-               songInfo = (CSongInfo *)obj;
-               tmpStr = songInfo->Genre();
-               if (tmpStr) {
-                       alinfo->SetGenre(tmpStr);
-                       break;
-               }
-       }
-
-       EINA_LIST_FOREACH(m->storageAlbumSong->List(), l, obj) {
-               songInfo = (CSongInfo *)obj;
-               tmpStr = songInfo->ThumbnailPath();
-               if (tmpStr) {
-                       alinfo->SetThumbnailPath(tmpStr);
-                       break;
-               }
-       }
-
-       m->albumlist = eina_list_append(m->albumlist, alinfo);
-       return true;
-}
-
-
 void CMediadata::m_DeleteFolderList(void)
 {
        CFolderInfo *finfo = NULL;
@@ -486,23 +384,6 @@ void CMediadata::m_DeleteFolderList(void)
 }
 
 
-void CMediadata::m_DeleteAlbumList(void)
-{
-       if (!m->albumlist)
-               return;
-       CAlbumInfo *alinfo = NULL;
-       void *obj = NULL;
-
-       EINA_LIST_FREE(m->albumlist, obj) {
-               alinfo = (CAlbumInfo *)obj;
-               alinfo->Destroy();
-               delete alinfo;
-       }
-
-       m->albumlist = NULL;
-}
-
-
 void CMediadata::m_DeleteCategoryList(ECategoryType type)
 {
        CCategoryInfo *catinfo = NULL;
@@ -573,7 +454,7 @@ void CMediadata::m_GetCategoryList(ECategoryType type)
        int count;
        bool ret;
 
-       if (!m->albumlist)
+       if (!m->storageAlbum->List())
                return;
 
        CCategoryStorage *stg = NULL;
@@ -584,7 +465,7 @@ void CMediadata::m_GetCategoryList(ECategoryType type)
        char *str;
 
        count = 0;
-       EINA_LIST_FOREACH(m->albumlist, l, obj) {
+       EINA_LIST_FOREACH(m->storageAlbum->List(), l, obj) {
                alinfo = (CAlbumInfo *)obj;
                if (type == CAT_TYPE_ARTIST) {
                        str = alinfo->Artist();
@@ -639,21 +520,6 @@ int CMediadata::m_GetFolderList(void)
 }
 
 
-int CMediadata::m_GetAlbumList(void)
-{
-       int r;
-
-       r = media_album_foreach_album_from_db(m->filter,
-               sm_CbEachAlbumData, (void *)this);
-       if (r != MEDIA_CONTENT_ERROR_NONE) {
-               _ERR("Media album foreach album from db failed");
-               return false;
-       }
-
-       return true;
-}
-
-
 void CMediadata::m_UpdateLists(void)
 {
        bool r;
@@ -665,9 +531,7 @@ void CMediadata::m_UpdateLists(void)
        }
 
        m->storageSong->Update(m->filter);
-
-       m_DeleteAlbumList();
-       m_GetAlbumList();
+       m->storageAlbum->Update(m->filter);
 
        m_DeleteCategoryList(CAT_TYPE_ARTIST);
        m_GetCategoryList(CAT_TYPE_ARTIST);
@@ -712,7 +576,7 @@ void CMediadata::Destroy(void)
        void *obj;
 
        m->storageSong->Delete();
-       m_DeleteAlbumList();
+       m->storageAlbum->Delete();
        m->storageAlbumSong->Delete();
        m_DeleteFolderList();
        m->storageFolderSong->Delete();
@@ -826,7 +690,7 @@ Eina_List *CMediadata::Medialist(int source_type, int listType, void *info)
                return m->storageSong->List();
 
        case LIST_TYPE_ALBUM:
-               return m->albumlist;
+               return m->storageAlbum->List();
 
        case LIST_TYPE_ALBUM_SONG:
                m->storageAlbumSong->Update((CAlbumInfo *)info, m->filter);