2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
19 * @author Jungki Kwak (jungki.kwak@samsung.com)
20 * @brief main file for download manager
31 #include "app_service.h"
33 #include "download-manager-common.h"
34 #include "download-manager-view.h"
35 #include "download-manager-network.h"
36 #include "download-manager-downloadRequest.h"
37 #include "download-manager-history-db.h"
48 int __get_rotate_angle()
51 app_device_orientation_e rotation_state;
52 rotation_state = app_get_device_orientation();
54 DP_LOG("Rotate angle[%d]",rotation_state);
55 return rotation_state;
58 static void __rotate_changed_cb(app_device_orientation_e m, void *data)
61 DownloadView &view = DownloadView::getInstance();
62 angle = __get_rotate_angle();
63 view.rotateWindow(angle);
68 static void __lang_changed_cb(void *data)
70 DP_LOG("=== Language changed nofification ===");
74 static void __region_changed_cb(void *data)
76 DownloadView &view = DownloadView::getInstance();
78 DP_LOG("=== Region changed nofification ===");
82 static void __low_memory_cb(void *data)
84 DP_LOG("=== Low memory nofification ===");
88 static Eina_Bool __load_remained_history(void *data)
90 struct app_data_t *app_data = (struct app_data_t *)data;
91 if (app_data && app_data->load_count <= app_data->history_count) {
92 app_data->load_count += LOAD_HISTORY_COUNT;
93 DownloadHistoryDB::createRemainedItemsFromHistoryDB(
94 LOAD_HISTORY_COUNT, app_data->load_count);
95 return ECORE_CALLBACK_RENEW;
97 return ECORE_CALLBACK_CANCEL;
100 static bool __app_create(void *data)
103 #ifndef _TIZEN_PUBLIC
106 struct app_data_t *app_data = (struct app_data_t *)data;
107 DP_LOG_START("App Create");
109 DownloadView &view = DownloadView::getInstance();
110 Evas_Object *window = view.create();
112 DP_LOGE("Fail to create main window");
116 NetMgr &netObj = NetMgr::getInstance();
117 netObj.initNetwork();
119 #ifndef _TIZEN_PUBLIC
120 angle = __get_rotate_angle();
121 view.rotateWindow(angle);
123 #ifndef _SILENT_LAUNCH
124 evas_object_show(window);
128 DownloadHistoryDB::getCountOfHistory(&count);
130 DownloadHistoryDB::createItemsFromHistoryDB();
131 if (count > LOAD_HISTORY_COUNT) {
133 app_data->history_count = count;
134 app_data->idler = ecore_idler_add(__load_remained_history, app_data);
139 DP_LOG_END("App Create");
144 static void __app_terminate(void *data)
147 struct app_data_t *app_data = (struct app_data_t *)data;
148 NetMgr &netObj = NetMgr::getInstance();
149 netObj.deinitNetwork();
150 DownloadView &view = DownloadView::getInstance();
152 if (app_data && app_data->idler)
153 ecore_idler_del(app_data->idler);
161 static void __app_pause(void *data)
167 static void __app_resume(void *data)
172 static void __app_service(service_h s, void *data)
174 string s_url = std::string();
175 string s_cookie = std::string();
180 DownloadView &view = DownloadView::getInstance();
184 if (service_get_operation(s, &app_op) < 0) {
185 DP_LOGE("Fail to get service operation");
188 DP_LOG("operation[%s]", app_op);
190 if (service_get_uri(s, &url) < 0) {
191 DP_LOGE("Invalid URL");
193 DP_LOG("url[%s]",url);
198 if (service_get_extra_data(s, "cookie", &cookie) < 0) {
201 DP_LOG("cookie[%s]",cookie);
206 if (service_get_extra_data(s, "mode", &mode) < 0) {
209 DP_LOG("mode[%s]",mode);
210 if ( 0 == strncmp(mode, "view", strlen("view"))) {
212 view.activateWindow();
215 DP_LOGE("Invalid mode");
216 view.activateWindow();
221 view.activateWindow();
224 DownloadRequest request(s_url, s_cookie);
225 Item::create(request);
226 #ifndef _SILENT_LAUNCH
227 view.activateWindow();
233 int main(int argc, char *argv[])
235 app_event_callback_s evt_cb = {0,};
237 struct app_data_t *app_data = NULL;
239 app_data = (struct app_data_t *)calloc(1, sizeof(struct app_data_t));
241 DP_LOGE("Fail to calloc of app data");
245 evt_cb.create = __app_create;
246 evt_cb.terminate = __app_terminate;
247 evt_cb.pause = __app_pause;
248 evt_cb.resume = __app_resume;
249 evt_cb.service = __app_service;
250 evt_cb.low_memory = __low_memory_cb;
251 evt_cb.low_battery = NULL;
252 #ifndef _TIZEN_PUBLIC
253 evt_cb.device_orientation = __rotate_changed_cb;
255 evt_cb.device_orientation = NULL;
257 evt_cb.language_changed = __lang_changed_cb;
258 evt_cb.region_format_changed = __region_changed_cb;
260 ret = app_efl_main(&argc, &argv, &evt_cb, app_data);
261 DP_LOG("Main return");