Data: added the channel data for channel favorite 51/44751/1 accepted/tizen/tv/20150728.070600 submit/tizen/20150728.063352
authorHyojung Jo <hj903.jo@samsung.com>
Mon, 27 Jul 2015 10:22:04 +0000 (19:22 +0900)
committerHyojung Jo <hj903.jo@samsung.com>
Mon, 27 Jul 2015 10:22:04 +0000 (19:22 +0900)
Change-Id: I0312a47b0d53a40f8e047bed19d18e8915ce2775
Signed-off-by: Hyojung Jo <hj903.jo@samsung.com>
CMakeLists.txt
include/datamgr.h
packaging/org.tizen.favorite.spec
src/data/channel.c [new file with mode: 0644]
src/grid/grid_tv.c

index a7ebb6d..fa84ed3 100644 (file)
@@ -27,6 +27,7 @@ pkg_check_modules(PKGS REQUIRED
                glib-2.0
                aul
                capi-web-bookmark
+               tv-service
                )
 
 IF(NOT DEFINED PACKAGE_NAME)
@@ -53,6 +54,7 @@ ENDIF(NOT DEFINED PACKAGEDIR)
 
 SET(SRCS
        src/main.c
+       src/data/channel.c
        src/data/app.c
        src/data/media.c
        src/data/web.c
index 83f8ef0..1aba63f 100644 (file)
@@ -5,7 +5,7 @@
 #include <Elementary.h>
 
 enum item_type {
-       ITEM_TV,
+       ITEM_CHANNEL,
        ITEM_MOVIE,
        ITEM_PHOTO,
        ITEM_VIDEO,
@@ -32,6 +32,7 @@ struct datamgr {
        bool (*action)(Elm_Object_Item *it);
 };
 
+struct datamgr *get_channel_datamgr(void);
 struct datamgr *get_media_datamgr(void);
 struct datamgr *get_apps_datamgr(void);
 struct datamgr *get_webs_datamgr(void);
index 9ae47ce..a7b8908 100644 (file)
@@ -16,6 +16,7 @@ BuildRequires: pkgconfig(capi-content-media-content)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(capi-web-bookmark)
+BuildRequires: pkgconfig(tv-service)
 
 %define _appdir /usr/apps/%{name}
 %define _bindir %{_appdir}/bin
diff --git a/src/data/channel.c b/src/data/channel.c
new file mode 100644 (file)
index 0000000..d6e5e1a
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2015 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 <glib.h>
+#include <Elementary.h>
+#include <tv_service_proxy_channel_info.h>
+#include <app_debug.h>
+
+#include "define.h"
+#include "datamgr.h"
+
+struct channel_data {
+       char *name;
+       long major;
+       long minor;
+};
+
+static void _channel_favorite_list_foreach(gpointer data, gpointer user_data)
+{
+       struct channel_data *cdata;
+       TvServiceChannel *channel;
+       Eina_List **l;
+
+       if (!data || !user_data) {
+               _ERR("Data is NULL.");
+               return;
+       }
+
+       channel = (TvServiceChannel *)data;
+       l = (Eina_List **)user_data;
+
+       cdata = calloc(1, sizeof(*cdata));
+       if (!cdata) {
+               _ERR("Calloc failed.");
+               return;
+       }
+
+       cdata->major = channel->major;
+       cdata->minor = channel->minor;
+
+       if (channel->program_name)
+               cdata->name = strdup(channel->program_name);
+
+       *l = eina_list_append(*l, cdata);
+}
+
+static Eina_List *_get_favorites(enum item_type type)
+{
+       GList *id_list = NULL;
+       Eina_List *l = NULL;
+       int r;
+
+       if (type != ITEM_CHANNEL)
+               return NULL;
+
+       r = tv_service_channel_info_create();
+       if (r != TVS_ERROR_OK) {
+               _ERR("Tv Service channel info create failed.");
+               return NULL;
+       }
+
+       r = tv_service_get_channel_list(TV_SERVICE_CHANNEL_MODE_FAVORITE,
+                       TV_SERVICE_ANTENNA_TYPE_ALL, &id_list);
+       if (r != TVS_ERROR_OK) {
+               _ERR("Tv Service Get channel list failed.");
+               tv_service_channel_info_destroy();
+               return NULL;
+       }
+
+       if (!id_list) {
+               tv_service_channel_info_destroy();
+               return NULL;
+       }
+
+       g_list_foreach(id_list, _channel_favorite_list_foreach, &l);
+
+       tv_service_free_channel_list(id_list);
+       tv_service_channel_info_destroy();
+
+       return l;
+}
+
+static char *_get_channel_title(struct channel_data *cdata)
+{
+       char str[SIZE_STR];
+
+       if (!cdata || !cdata->name) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+
+       if (cdata->minor > 0)
+               snprintf(str, sizeof(str), "%ld-%ld %s", cdata->major,
+                               cdata->minor, cdata->name);
+       else
+               snprintf(str, sizeof(str), "%ld %s", cdata->major, cdata->name);
+
+       return strdup(str);
+}
+
+static char *_get_data(void *data, enum data_type type)
+{
+       struct channel_data *cdata;
+
+       if (!data) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+       cdata = data;
+
+       switch (type) {
+       case DATA_NAME:
+               return _get_channel_title(cdata);
+
+       default:
+               _ERR("Invalid data type.");
+               return NULL;
+       }
+
+}
+
+static void _free_favorites(Eina_List *list)
+{
+       struct channel_data *cdata;
+
+       if (!list)
+               return;
+
+       EINA_LIST_FREE(list, cdata) {
+               if (!cdata)
+                       continue;
+
+               free(cdata->name);
+               free(cdata);
+
+               cdata = NULL;
+       }
+}
+
+static bool _action(Elm_Object_Item *it)
+{
+       /* It will be implemented later. */
+
+       return true;
+}
+
+static struct datamgr _dmgr = {
+       .get_data = _get_data,
+       .get_count = NULL,
+       .get_favorites = _get_favorites,
+       .free_favorites = _free_favorites,
+       .action = _action,
+};
+
+struct datamgr *get_channel_datamgr(void)
+{
+       return &_dmgr;
+}
index 7c3e246..fab325b 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "define.h"
 #include "grid.h"
+#include "datamgr.h"
 
 #define STR_TV "TV"
 #define STYLE_TV "style.tv"
@@ -50,17 +51,27 @@ static struct grid_class _gclass = {
 
 static Eina_List *_create_item_list(void)
 {
-       /* It will be implemented later. */
+       struct datamgr *dmgr;
 
-       return NULL;
+       dmgr = get_channel_datamgr();
+       if (!dmgr || !dmgr->get_favorites)
+               return NULL;
+
+       return dmgr->get_favorites(ITEM_CHANNEL);
 }
 
 static void _destroy_item_list(Eina_List *list)
 {
+       struct datamgr *dmgr;
+
        if (!list)
                return;
 
-       /* It will be implemented later. */
+       dmgr = get_channel_datamgr();
+       if (!dmgr || !dmgr->free_favorites)
+               return;
+
+       dmgr->free_favorites(list);
 }
 
 static struct grid_data _gdata = {