initial tizen_2.0_beta
[apps/core/preloaded/music-player.git] / src / common / mp-ug-launch.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 <stdio.h>
18 #include <stdlib.h>
19 #include <glib.h>
20 #include <ui-gadget.h>
21
22 #include <sys/time.h>
23 #include <vconf.h>
24 #include <glib.h>
25 #include <fcntl.h>
26 #include <app.h>
27
28 #include "music.h"
29 #include "mp-item.h"
30 #include "mp-menu.h"
31 #include "mp-ug-launch.h"
32 #include "mp-define.h"
33
34 #include "music.h"
35 #include "mp-item.h"
36 #include "mp-player-debug.h"
37 #include "mp-play-view.h"
38 #include "mp-widget.h"
39
40 #ifdef MP_SOUND_PLAYER
41 #include "sp-view-manager.h"
42 #else
43 #include "mp-common.h"
44 #include "mp-group-view.h"
45 #include "mp-view-manager.h"
46 #endif
47
48 #define UG_EMAIL_NAME "email-composer-efl"
49 #define UG_BT_NAME "setting-bluetooth-efl"
50 #define UG_MUSIC_INFO "music-info-efl"
51 #define UG_MSG_NAME "msg-composer-efl"
52 #ifdef MP_FEATURE_WIFI_SHARE
53 #define UG_FTM_NAME "fileshare-efl"
54 #endif
55 #define UG_MUSIC_SETTINGS       "setting-music-player-efl"
56
57 #define MP_UG_INFO_PATH "path"
58 #define MP_UG_INFO_ALBUMART "albumart"
59 #define MP_UG_INFO_ARTIST "artist"
60 #define MP_UG_INFO_ID "id"
61 #define MP_UG_INFO_DESTROY "destroy"
62 #define MP_UG_INFO_BACK "back"
63 #define MP_UG_INFO_LOAD "load"
64 #define MP_UG_INFO_ALBUMART_CLICKED "albumart_clicked"
65 #define MP_UG_INFO_MEDIA_SVC_HANDLE     "media_service_handle"
66
67 /* for contact ug */
68 #define CT_UG_REQUEST_SAVE_RINGTONE 42
69 #define CT_UG_BUNDLE_TYPE "type"
70 #define CT_UG_BUNDLE_PATH "ct_path"
71 #define UG_CONTACTS_LIST "contacts-list-efl"
72
73 static void
74 _mp_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
75 {
76         startfunc;
77         Evas_Object *base, *win;
78
79         MP_CHECK(priv);
80         MP_CHECK(ug);
81
82         base = ug_get_layout(ug);
83         if (!base)
84                 return;
85
86         win = ug_get_window();
87
88         switch (mode)
89         {
90         case UG_MODE_FULLVIEW:
91                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
92                 elm_win_resize_object_add(win, base);
93                 evas_object_show(base);
94                 break;
95         default:
96                 break;
97         }
98
99         endfunc;
100 }
101
102
103 static void
104 _mp_ug_destroy(struct appdata *ad)
105 {
106         startfunc;
107
108         if (ad->ug) {
109                 ug_destroy(ad->ug);
110                 ad->ug = NULL;
111         }
112 }
113
114 static void
115 _mp_ug_destroy_cb(ui_gadget_h ug, void *priv)
116 {
117         startfunc;
118         if (!ug || !priv)
119                 return;
120
121         struct appdata *ad = priv;
122
123         _mp_ug_destroy(ad);
124         return;
125 }
126
127 static ui_gadget_h
128 _mp_ug_create_ug(struct appdata *ad, ui_gadget_h parent, const char *name, enum ug_mode mode, service_h  service,
129                  struct ug_cbs *cbs)
130 {
131         startfunc;
132         MP_CHECK_NULL(ad);
133
134         ui_gadget_h ug = NULL;
135
136         ug = ug_create(parent, name, mode, service, cbs);
137
138         if (!ug)
139         {
140                 ERROR_TRACE("unable to create ug %s", name);
141                 mp_widget_text_popup(ad, GET_SYS_STR("IDS_COM_BODY_APPLICATION_NOT_INSTALLED"));
142         }
143         endfunc;
144         return ug;
145 }
146
147 int
148 mp_ug_email_attatch_file(const char *filepath, void *user_data)
149 {
150         startfunc;
151         struct appdata *ad = NULL;
152         service_h service = NULL;
153         struct ug_cbs cbs = { 0, };
154         int option = 0;
155
156         mp_retvm_if(filepath == NULL, -1, "file path is NULL");
157         mp_retvm_if(user_data == NULL, -1, "appdata is NULL");
158
159         ad = (struct appdata *)user_data;
160         MP_CHECK_VAL(ad, -1);
161
162         if (ad->ug)
163         {
164                 ERROR_TRACE("Destory previous ui-gadget first !!!!");
165                 return -1;
166         }
167         option = UG_OPT_INDICATOR_ENABLE;
168
169         UG_INIT_EFL(ad->win_main, option);
170
171         if(service_create(&service) != SERVICE_ERROR_NONE)
172         {
173                 ERROR_TRACE("Error: service_create");
174                 return -1;
175         }
176
177         service_add_extra_data(service, "RUN_TYPE", "5");
178         service_add_extra_data(service, "ATTACHMENT", filepath);
179
180         cbs.priv = user_data;
181         cbs.layout_cb = _mp_ug_layout_cb;
182         cbs.result_cb = NULL;
183         cbs.destroy_cb = _mp_ug_destroy_cb;
184
185
186         ad->ug = _mp_ug_create_ug(ad, NULL, UG_EMAIL_NAME, UG_MODE_FULLVIEW, service, &cbs);
187
188         service_destroy(service);
189         endfunc;
190         return 0;
191 }
192
193 int
194 mp_ug_message_attatch_file(const char *filepath, void *user_data)
195 {
196         startfunc;
197         struct appdata *ad = NULL;
198         service_h service = NULL;
199         struct ug_cbs cbs = { 0, };
200         int option = 0;
201
202         mp_retvm_if(filepath == NULL, -1, "file path is NULL");
203         mp_retvm_if(user_data == NULL, -1, "appdata is NULL");
204
205         ad = (struct appdata *)user_data;
206         MP_CHECK_VAL(ad, -1);
207
208         if (ad->ug)
209         {
210                 ERROR_TRACE("Destory previous ui-gadget first !!!!");
211                 return -1;
212         }
213         option = UG_OPT_INDICATOR_ENABLE;
214
215         UG_INIT_EFL(ad->win_main, option);
216
217         if(service_create(&service) != SERVICE_ERROR_NONE)
218         {
219                 ERROR_TRACE("Error: service_create");
220                 return -1;
221         }
222         service_add_extra_data(service, "ATTACHFILE", filepath);
223
224         cbs.priv = user_data;
225         cbs.layout_cb = _mp_ug_layout_cb;
226         cbs.result_cb = NULL;
227         cbs.destroy_cb = _mp_ug_destroy_cb;
228
229         ad->ug = _mp_ug_create_ug(ad, NULL, UG_MSG_NAME, UG_MODE_FULLVIEW, service, &cbs);
230         service_destroy(service);
231         return 0;
232 }
233
234 int
235 mp_ug_bt_attatch_file(const char *filepath, int count, void *user_data)
236 {
237         startfunc;
238         struct appdata *ad = NULL;
239         service_h service = NULL;
240         struct ug_cbs cbs = { 0, };
241         int option = 0;
242         char *file_count = NULL;
243
244         mp_retvm_if(filepath == NULL, -1, "file path is NULL");
245         mp_retvm_if(user_data == NULL, -1, "appdata is NULL");
246
247         ad = user_data;
248         if (ad->ug)
249         {
250                 ERROR_TRACE("Destory previous ui-gadget first !!!!");
251                 return -1;
252         }
253
254         option = UG_OPT_INDICATOR_ENABLE;
255
256         UG_INIT_EFL(ad->win_main, option);
257
258         file_count = g_strdup_printf("%d", count);
259
260         if(service_create(&service) != SERVICE_ERROR_NONE)
261         {
262                 ERROR_TRACE("Error: service_create");
263                 return -1;
264         }
265         service_add_extra_data(service, "launch-type", "send");
266         service_add_extra_data(service, "filecount", file_count);
267         service_add_extra_data(service, "files", filepath);
268
269         cbs.priv = user_data;
270         cbs.layout_cb = _mp_ug_layout_cb;
271         cbs.result_cb = NULL;
272         cbs.destroy_cb = _mp_ug_destroy_cb;
273
274         ad->ug = _mp_ug_create_ug(ad, NULL, UG_BT_NAME, UG_MODE_FULLVIEW, service, &cbs);
275
276         service_destroy(service);
277         IF_FREE(file_count);
278
279         return 0;
280 }
281 #ifdef MP_FEATURE_WIFI_SHARE
282 int
283 mp_ug_wifi_attatch_file(const char *filepath, int count, void *user_data)
284 {
285         startfunc;
286         struct appdata *ad = NULL;
287         service_h service = NULL;
288         struct ug_cbs cbs = { 0, };
289         int option = 0;
290         char *file_count = NULL;
291
292         mp_retvm_if(filepath == NULL, -1, "file path is NULL");
293         mp_retvm_if(user_data == NULL, -1, "appdata is NULL");
294
295         ad = user_data;
296         if (ad->ug)
297         {
298                 ERROR_TRACE("Destory previous ui-gadget first !!!!");
299                 return -1;
300         }
301         option = UG_OPT_INDICATOR_ENABLE;
302         UG_INIT_EFL(ad->win_main, option);
303         file_count = g_strdup_printf("%d", count);
304         if(service_create(&service) != SERVICE_ERROR_NONE)
305         {
306                 ERROR_TRACE("Error: service_create");
307                 return -1;
308         }
309         service_add_extra_data(service, "filecount", file_count);
310         service_add_extra_data(service, "files", filepath);
311         cbs.priv = user_data;
312         cbs.layout_cb = _mp_ug_layout_cb;
313         cbs.result_cb = NULL;
314         cbs.destroy_cb = _mp_ug_destroy_cb;
315         ad->ug = _mp_ug_create_ug(ad, NULL, UG_FTM_NAME, UG_MODE_FULLVIEW, service, &cbs);
316         service_destroy(service);
317         IF_FREE(file_count);
318         return 0;
319 }
320 #endif
321
322 int
323 mp_ug_contact_user_sel(const char *filepath, void *user_data)
324 {
325         startfunc;
326         struct appdata *ad = NULL;
327         service_h service = NULL;
328         struct ug_cbs cbs = { 0, };
329         int option = 0;
330
331         mp_retvm_if(filepath == NULL, -1, "file path is NULL");
332         mp_retvm_if(user_data == NULL, -1, "appdata is NULL");
333         ad = user_data;
334
335         if (ad->ug)
336         {
337                 ERROR_TRACE("Destory previous ui-gadget first !!!!");
338                 return -1;
339         }
340
341         option = UG_OPT_INDICATOR_ENABLE;
342
343         UG_INIT_EFL(ad->win_main, option);
344
345         if(service_create(&service) != SERVICE_ERROR_NONE)
346         {
347                 ERROR_TRACE("Error: service_create");
348                 return -1;
349         }
350
351         char buf[16];
352
353         snprintf(buf, sizeof(buf), "%d", CT_UG_REQUEST_SAVE_RINGTONE);
354         service_add_extra_data(service, CT_UG_BUNDLE_TYPE, buf);
355         service_add_extra_data(service, CT_UG_BUNDLE_PATH, filepath);
356
357         cbs.priv = ad;
358         cbs.layout_cb = _mp_ug_layout_cb;
359         cbs.result_cb = NULL;
360         cbs.destroy_cb = _mp_ug_destroy_cb;
361
362         ad->ug = _mp_ug_create_ug(ad, NULL, UG_CONTACTS_LIST, UG_MODE_FULLVIEW, service, &cbs);
363
364         service_destroy(service);
365
366         return 0;
367 }
368
369
370 void
371 mp_ug_send_message(struct appdata *ad, mp_ug_message_t message)
372 {
373         startfunc;
374         ui_gadget_h ug = NULL;
375         char *id = NULL;
376         MP_CHECK(ad);
377
378         service_h service = NULL;
379
380         if(service_create(&service) != SERVICE_ERROR_NONE)
381         {
382                 ERROR_TRACE("Error: service_create");
383                 return;
384         }
385         MP_CHECK(service);
386
387         switch(message)
388         {
389         case MP_UG_MESSAGE_DEL:
390                 ug = ad->info_ug;
391                 service_add_extra_data(service, MP_UG_INFO_DESTROY, MP_UG_INFO_DESTROY);
392                 break;
393         case MP_UG_MESSAGE_BACK:
394                 ug = ad->info_ug;
395                 service_add_extra_data(service, MP_UG_INFO_BACK, MP_UG_INFO_BACK);
396                 break;
397         case MP_UG_MESSAGE_LOAD:
398         {
399                 ug = ad->info_ug;
400                 service_add_extra_data(service, MP_UG_INFO_LOAD, MP_UG_INFO_LOAD);
401                 music_list_item *item = mp_play_list_get_current_item(ad->playing_list);
402                 MP_CHECK_EXCEP(item);
403
404                 service_add_extra_data(service, MP_UG_INFO_PATH, item->filename);
405                 service_add_extra_data(service, MP_UG_INFO_ALBUMART, item->albumart);
406                 service_add_extra_data(service, MP_UG_INFO_ARTIST, item->artist);
407
408                 id = g_strdup(item->key_id);
409                 MP_CHECK_EXCEP(id);
410                 service_add_extra_data(service, MP_UG_INFO_ID, id);
411                 break;
412         }
413         default:
414                 service_destroy(service);
415                 return;
416         }
417         ug_send_message(ug, service);
418
419         mp_exception:
420         if(service)
421                 service_destroy(service);
422         IF_FREE(id);
423 }
424
425 void
426 mp_ug_destory_all(struct appdata *ad)
427 {
428         startfunc;
429         // ad->info_ug should not be destoryed!!
430         MP_CHECK(ad);
431         ug_destroy(ad->ug);
432         ad->ug = NULL;
433 }
434
435 bool
436 mp_ug_active(struct appdata *ad)
437 {
438         startfunc;
439         MP_CHECK_FALSE(ad);
440
441         if (ad->ug)
442         {
443                 return true;
444         }
445         else
446         {
447                 return false;
448         }
449 }
450
451