Initialize the project.
[platform/framework/web/livebox-viewer.git] / live.viewer / src / main.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <Elementary.h>
18
19 #include <dlog.h>
20 #include <ail.h>
21 #include <app.h>
22 #include <bundle.h>
23
24 #include <livebox.h>
25 #include <livebox-service.h>
26
27 #include "main.h"
28 #include "util.h"
29 #include "debug.h"
30 #include "scroller.h"
31 #include "lb.h"
32
33 static struct info {
34         Evas_Object *window;
35         Evas_Object *scroller;
36 } s_info = {
37         .window = NULL,
38         .scroller = NULL,
39 };
40
41 Evas_Object *main_get_window(void)
42 {
43         return s_info.window;
44 }
45
46 static void click_cb(void *data, Evas_Object *obj, void *event_info)
47 {
48         Elm_Object_Item *item;
49         const char *label;
50
51         item = elm_list_selected_item_get(obj);
52         if (!item)
53                 return;
54
55         label = elm_object_item_part_text_get(item, NULL);
56         if (!label)
57                 return;
58
59         DbgPrint("Label: %s (%s)\n", label, data);
60         if (lb_add(s_info.scroller, data) < 0)
61                 ErrPrint("Failed to add a new livebox\n");
62 }
63
64 static int append_livebox_cb(const char *appid, const char *lbid, int is_prime, void *data)
65 {
66         char *name;
67
68         DbgPrint("%s - %s\n", appid, lbid);
69
70         name = livebox_service_i18n_name(lbid, NULL);
71         if (!name) {
72                 name = strdup(lbid);
73                 if (!name) {
74                         ErrPrint("Heap: %s\n", strerror(errno));
75                         return 0;
76                 }
77         }
78
79         DbgPrint("Name: %s\n", name);
80         elm_list_item_append(data, name, NULL, NULL, click_cb, strdup(lbid));
81         free(name);
82         return 0;
83 }
84
85 static inline void livebox_list_create(void)
86 {
87         Evas_Object *list;
88
89         list = elm_list_add(s_info.window);
90         evas_object_resize(list, 720, 1000);
91         evas_object_show(list);
92
93         DbgPrint("Get Package list\n");
94         livebox_service_get_pkglist(append_livebox_cb, list);
95         scroller_append(s_info.scroller, list);
96         elm_list_go(list);
97 }
98
99 static bool app_create(void *data)
100 {
101         Evas_Object *bg;
102         Evas_Object *conformant;
103         Evas_Object *box;
104         DbgPrint("create");
105         lb_init();
106
107         s_info.window = elm_win_add(NULL, "Box viewer", ELM_WIN_BASIC);
108         if (!s_info.window) {
109                 ErrPrint("Failed to create a window\n");
110                 return false;
111         }
112         elm_win_autodel_set(s_info.window, EINA_TRUE);
113
114         bg = elm_bg_add(s_info.window);
115         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
116         elm_win_resize_object_add(s_info.window, bg);
117         evas_object_show(bg);
118
119         evas_object_resize(s_info.window, 720, 1280);
120         evas_object_show(s_info.window);
121
122         conformant = elm_conformant_add(s_info.window);
123         evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124         elm_win_resize_object_add(s_info.window, conformant);
125         evas_object_show(conformant);
126
127         box = elm_box_add(s_info.window);
128         s_info.scroller = scroller_create(s_info.window);
129         if (!s_info.scroller) {
130                 evas_object_del(s_info.window);
131                 s_info.window = NULL;
132                 ErrPrint("Failed to create a scroller\n");
133                 return false;
134         }
135         livebox_list_create();
136         evas_object_size_hint_min_set(s_info.scroller, 720, 1000);
137         evas_object_resize(s_info.scroller, 720, 1000);
138         evas_object_show(s_info.scroller);
139
140         elm_box_pack_end(box, s_info.scroller);
141         evas_object_size_hint_min_set(box, 720, 1000);
142         evas_object_resize(box, 720, 1000);
143         evas_object_show(box);
144
145         elm_object_content_set(conformant, box);
146         elm_win_indicator_mode_set(s_info.window, ELM_WIN_INDICATOR_SHOW);
147
148         return true;
149 }
150
151 static void app_terminate(void *data)
152 {
153         DbgPrint("terminate");
154         lb_fini();
155         /*!
156          * \TODO
157          * Delete all objects from the scroller.
158          */
159
160         scroller_destroy(s_info.scroller);
161         evas_object_del(s_info.window);
162         s_info.window = NULL;
163 }
164
165 static void app_pause(void *data)
166 {
167         DbgPrint("pause");
168 }
169
170 static void app_resume(void *data)
171 {
172         DbgPrint("resume");
173 }
174
175 static void app_reset(service_h service, void *data)
176 {
177         DbgPrint("reset");
178 }
179
180 int main(int argc, char *argv[])
181 {
182         app_event_callback_s event_callback;
183
184         setenv("ELM_ENGINE", "gl", 0);
185         event_callback.create = app_create;
186         event_callback.terminate = app_terminate;
187         event_callback.pause = app_pause;
188         event_callback.resume = app_resume;
189         event_callback.service = app_reset;
190         event_callback.low_memory = NULL;
191         event_callback.low_battery = NULL;
192         event_callback.device_orientation = NULL;
193         event_callback.language_changed = NULL;
194
195         return app_efl_main(&argc, &argv, &event_callback, NULL);
196 }
197
198 /* End of a file */