CCategoryStorage class is separated from mediadata.cpp 27/36627/1 accepted/tizen/tv/20150312.010753 submit/tizen_tv/20150311.041629
authorKim Tae Soo <taesoo46.kim@samsung.com>
Wed, 11 Mar 2015 04:10:11 +0000 (13:10 +0900)
committerKim Tae Soo <taesoo46.kim@samsung.com>
Wed, 11 Mar 2015 04:10:11 +0000 (13:10 +0900)
Change-Id: I039b7fc52dd4fbee3527a623f7c5c215369f4f88
Signed-off-by: Kim Tae Soo <taesoo46.kim@samsung.com>
CMakeLists.txt
include/CategoryStorage.h [new file with mode: 0644]
src/data/CategoryStorage.cpp [new file with mode: 0644]
src/data/mediadata.cpp

index bedf5db..c68dd9d 100644 (file)
@@ -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 (file)
index 0000000..662a41c
--- /dev/null
@@ -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 (file)
index 0000000..7e7b946
--- /dev/null
@@ -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 <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 "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;
+}
index 88b41a2..6893576 100644 (file)
 #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