From 8e9e296fd54d92f71f53d1c029520d0e54662612 Mon Sep 17 00:00:00 2001 From: Kim Tae Soo Date: Wed, 11 Mar 2015 13:10:11 +0900 Subject: [PATCH] CCategoryStorage class is separated from mediadata.cpp Change-Id: I039b7fc52dd4fbee3527a623f7c5c215369f4f88 Signed-off-by: Kim Tae Soo --- CMakeLists.txt | 1 + include/CategoryStorage.h | 58 ++++++++++++++ src/data/CategoryStorage.cpp | 180 +++++++++++++++++++++++++++++++++++++++++++ src/data/mediadata.cpp | 162 +------------------------------------- 4 files changed, 242 insertions(+), 159 deletions(-) create mode 100644 include/CategoryStorage.h create mode 100644 src/data/CategoryStorage.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bedf5db..c68dd9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ SET(SRCS src/main.cpp src/data/category_info.cpp src/data/folder_info.cpp src/data/bus.cpp + src/data/CategoryStorage.cpp ) SET(TARGET_EDJ "${PROJECT_NAME}.edj") diff --git a/include/CategoryStorage.h b/include/CategoryStorage.h new file mode 100644 index 0000000..662a41c --- /dev/null +++ b/include/CategoryStorage.h @@ -0,0 +1,58 @@ +/* + * 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 __CATEGORY_STORAGE_H__ +#define __CATEGORY_STORAGE_H__ + + +class CCategoryStorage { +protected: + Eina_List *elList; + +public: + CCategoryStorage() { elList = NULL; } + virtual ~CCategoryStorage() {} + + void SetList(Eina_List *el); + Eina_List *List(void); + void Delete(void); + + virtual bool Update(void) = 0; +}; + +class CArtistStorage : public CCategoryStorage { +public: + virtual bool Update(void); +}; + +class CGenreStorage : public CCategoryStorage { +public: + virtual bool Update(void); +}; + +class CPlaylistStorage : public CCategoryStorage { +private: + static bool sm_CbPlaylistMember(int memb_id, media_info_h mdh, void *dt); + static bool sm_CbEachPlaylist(media_playlist_h ph, void *dt); + bool m_OnEachPlaylist(media_playlist_h ph); + int m_GetPlaylistList(void); + +public: + virtual bool Update(void); +}; + + +#endif // __CATEGORY_STORAGE_H__ \ No newline at end of file diff --git a/src/data/CategoryStorage.cpp b/src/data/CategoryStorage.cpp new file mode 100644 index 0000000..7e7b946 --- /dev/null +++ b/src/data/CategoryStorage.cpp @@ -0,0 +1,180 @@ +/* + * 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 +#include +#include +#include +#include +#include "dbg.h" +#include "i18n.h" +#include "define.h" + +#include +#include "song_info.h" +#include "album_info.h" +#include "category_info.h" +#include "folder_info.h" +#include "CategoryStorage.h" +#include "common.h" + + +void CCategoryStorage::SetList(Eina_List *el) +{ + elList = el; +} + + +Eina_List *CCategoryStorage::List(void) +{ + return elList; +} + + +void CCategoryStorage::Delete(void) +{ + if (!elList) + return; + + CCategoryInfo *catinfo = NULL; + void *obj = NULL; + + EINA_LIST_FREE(elList, obj) { + catinfo = (CCategoryInfo *)obj; + catinfo->Destroy(); + delete catinfo; + } + + elList = NULL; +} + + +bool CArtistStorage::Update(void) +{ + return true; +} + + +bool CGenreStorage::Update(void) +{ + return true; +} + + +bool CPlaylistStorage::sm_CbPlaylistMember(int memb_id, media_info_h mdh, void *dt) +{ + CCategoryInfo *catinfo = (CCategoryInfo *)dt; + CCategoryInfo::CListMember *member = NULL; + char *id = NULL; + + if (!mdh || !catinfo) + return false; + + if (media_info_get_media_id(mdh, &id) != MEDIA_CONTENT_ERROR_NONE) { + _ERR(" Failed to get media id "); + return false; + } + + char *thumb; + if (!catinfo->ThumbnailPath()) { + if (media_info_get_thumbnail_path(mdh, &thumb) != MEDIA_CONTENT_ERROR_NONE) + _ERR("Media thumbnail path Fetch error"); + catinfo->SetThumbnailPath(thumb); + } + + member = new CCategoryInfo::CListMember; + if (!member) { + free(id); + return false; + } + + member->memberId = memb_id; + member->mediaId = id; + + catinfo->SetMember(member); + + return true; +} + + +bool CPlaylistStorage::sm_CbEachPlaylist(media_playlist_h ph, void *dt) +{ + CPlaylistStorage *root = (CPlaylistStorage *)dt; + + if (!root) + return false; + + root->m_OnEachPlaylist(ph); + + return true; +} + + +bool CPlaylistStorage::m_OnEachPlaylist(media_playlist_h ph) +{ + if (!ph) + return false; + + _CREATE_BEGIN{ + CCategoryInfo *catinfo = NULL; + char *tmpStr = NULL; + int categoryId = 0; + int songCount = 0; + _CHECK(catinfo = new CCategoryInfo) + _CHECK(catinfo->Create()) + _CHECK(media_playlist_get_name(ph, &tmpStr) == MEDIA_CONTENT_ERROR_NONE) + _CHECK(media_playlist_get_playlist_id(ph, &categoryId) == MEDIA_CONTENT_ERROR_NONE) + _CHECK(media_playlist_get_media_count_from_db(catinfo->CategoryId(), NULL, &songCount) == MEDIA_CONTENT_ERROR_NONE) + _CHECK(media_playlist_foreach_media_from_db(catinfo->CategoryId(), NULL, + sm_CbPlaylistMember, (void *)catinfo) == MEDIA_CONTENT_ERROR_NONE) + + _WHEN_SUCCESS{ + catinfo->SetName(tmpStr); + catinfo->SetCategoryId(categoryId); + catinfo->SetSongCount(songCount); + elList = eina_list_append(elList, catinfo); + } + + _CHECK_FAIL{ /* */ } + _CHECK_FAIL{ /* */ } + _CHECK_FAIL{ /* */ } + _CHECK_FAIL{ /* */ } + _CHECK_FAIL{ catinfo->Destroy(); } + _CHECK_FAIL{ delete catinfo; catinfo = NULL; } + }_CREATE_END_AND_CATCH{ return false; } + + return true; +} + + +int CPlaylistStorage::m_GetPlaylistList(void) +{ + if (media_playlist_foreach_playlist_from_db(NULL, sm_CbEachPlaylist, this)) { + _ERR(" Get each playlist failed "); + return false; + } + + return true; +} + + +bool CPlaylistStorage::Update(void) +{ + Delete(); + m_GetPlaylistList(); + return true; +} diff --git a/src/data/mediadata.cpp b/src/data/mediadata.cpp index 88b41a2..6893576 100644 --- a/src/data/mediadata.cpp +++ b/src/data/mediadata.cpp @@ -28,15 +28,16 @@ #include "album_info.h" #include "category_info.h" #include "folder_info.h" +#include "CategoryStorage.h" #include "mediadata.h" #include "common.h" #define MEDIA_CONDITION_MUSIC "(MEDIA_TYPE=3)" #define MEDIA_CONDITION_INTERNAL "(MEDIA_STORAGE_TYPE=0)" #define MEDIA_CONDITION_EXTERNAL "(MEDIA_STORAGE_TYPE=1)" - #define MUSIC_STR_UNKNOWN N_("Unknown") + enum songlist_type { E_ALL_SONGS, E_ALBUM_SONGS, @@ -46,161 +47,6 @@ enum songlist_type { }; -class CStorage { -protected: - Eina_List *elList; - -public: - CStorage() { - elList = NULL; - } - virtual ~CStorage() { - - } - - void SetList(Eina_List *el) { - elList = el; - } - Eina_List *List(void) { - return elList; - } - - void Delete(void) { - if (!elList) - return; - - CCategoryInfo *catinfo = NULL; - void *obj = NULL; - - EINA_LIST_FREE(elList, obj) { - catinfo = (CCategoryInfo *)obj; - catinfo->Destroy(); - delete catinfo; - } - - elList = NULL; - } - virtual bool Update(void) = 0; -}; - - -class CArtistStorage : public CStorage { -public: - virtual bool Update(void) { - return true; - } -}; - -class CGenreStorage : public CStorage { -public: - virtual bool Update(void) { - return true; - } -}; - -class CPlaylistStorage : public CStorage { -private: - static bool sm_CbPlaylistMember(int memb_id, media_info_h mdh, void *dt) - { - CCategoryInfo *catinfo = (CCategoryInfo *)dt; - CCategoryInfo::CListMember *member = NULL; - char *id = NULL; - - if (!mdh || !catinfo) - return false; - - if (media_info_get_media_id(mdh, &id) != MEDIA_CONTENT_ERROR_NONE) { - _ERR(" Failed to get media id "); - return false; - } - - char *thumb; - if (!catinfo->ThumbnailPath()) { - if (media_info_get_thumbnail_path(mdh, &thumb) != MEDIA_CONTENT_ERROR_NONE) - _ERR("Media thumbnail path Fetch error"); - catinfo->SetThumbnailPath(thumb); - } - - member = new CCategoryInfo::CListMember; - if (!member) { - free(id); - return false; - } - - member->memberId = memb_id; - member->mediaId = id; - - catinfo->SetMember(member); - - return true; - } - - static bool sm_CbEachPlaylist(media_playlist_h ph, void *dt) - { - CPlaylistStorage *root = (CPlaylistStorage *)dt; - - if (!root) - return false; - - root->m_OnEachPlaylist(ph); - - return true; - } - bool m_OnEachPlaylist(media_playlist_h ph) - { - if (!ph) - return false; - - _CREATE_BEGIN{ - CCategoryInfo *catinfo = NULL; - char *tmpStr = NULL; - int categoryId = 0; - int songCount = 0; - _CHECK(catinfo = new CCategoryInfo) - _CHECK(catinfo->Create()) - _CHECK(media_playlist_get_name(ph, &tmpStr) == MEDIA_CONTENT_ERROR_NONE) - _CHECK(media_playlist_get_playlist_id(ph, &categoryId) == MEDIA_CONTENT_ERROR_NONE) - _CHECK(media_playlist_get_media_count_from_db(catinfo->CategoryId(), NULL, &songCount) == MEDIA_CONTENT_ERROR_NONE) - _CHECK(media_playlist_foreach_media_from_db(catinfo->CategoryId(), NULL, - sm_CbPlaylistMember, (void *)catinfo) == MEDIA_CONTENT_ERROR_NONE) - - _WHEN_SUCCESS{ - catinfo->SetName(tmpStr); - catinfo->SetCategoryId(categoryId); - catinfo->SetSongCount(songCount); - elList = eina_list_append(elList, catinfo); - } - - _CHECK_FAIL{ /* */ } - _CHECK_FAIL{ /* */ } - _CHECK_FAIL{ /* */ } - _CHECK_FAIL{ /* */ } - _CHECK_FAIL{ catinfo->Destroy(); } - _CHECK_FAIL{ delete catinfo; catinfo = NULL; } - }_CREATE_END_AND_CATCH{ return false; } - - return true; - } - - int m_GetPlaylistList(void) - { - if (media_playlist_foreach_playlist_from_db(NULL, sm_CbEachPlaylist, this)) { - _ERR(" Get each playlist failed "); - return false; - } - - return true; - } - -public: - virtual bool Update(void) { - Delete(); - m_GetPlaylistList(); - return true; - } -}; - - struct SMediadata { Eina_List *songlist; Eina_List *folderlist; @@ -236,8 +82,6 @@ struct SMediadata { }; - - bool CPlaylistMgr::Alloc(const char *name, Eina_List *elIdList) { ASSERT(name); @@ -929,7 +773,7 @@ void CMediadata::m_GetCategoryList(ECategoryType type) if (!m->albumlist) return; - CStorage *stg = NULL; + CCategoryStorage *stg = NULL; if (type == CAT_TYPE_ARTIST) stg = m->storageArtist; else -- 2.7.4