3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.tizenopensource.org/license
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
22 #include <supplement.h>
24 #include "memo_string.h"
27 static void _on_response_cb(void *data, Evas_Object *obj, void *event_info);
29 static GString *get_shared_text(Eina_List *list)
32 struct memo_data *md = NULL;
33 GString *buf = g_string_new("");
35 EINA_LIST_FOREACH(list, l, md) {
36 if ((md != NULL) && !(md->has_doodle)) {
37 g_string_append_printf(buf, "%s", md->content);
44 static GString *get_shared_attachment(Eina_List *list)
47 struct memo_data *md = NULL;
48 GString *buf = g_string_new("");
50 EINA_LIST_FOREACH(list, l, md) {
51 if ((md != NULL) && (md->has_doodle)) {
52 g_string_append_printf(buf, DOODLEDIR "/%d.png\n", (int)md->id);
59 static void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
61 Evas_Object *base, *win;
62 base = (Evas_Object *)ug_get_layout(ug);
67 win = ug_get_window();
69 case UG_MODE_FULLVIEW:
70 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
71 elm_win_resize_object_add(win, base);
73 //ug_disable_effect(ug);
74 evas_object_show(base);
81 static void _ug_result_cb(ui_gadget_h ug, service_h service, void *priv)
83 service_dump(service);
86 static void _ug_destroy_cb(ui_gadget_h ug, void *priv)
97 * This is a basic function which designed to invoke any ui gadget.
99 * @param[in] service a service type which will send to ug directly
100 * @param[in] ug_name UG name marco defined in memo_ug.h
103 void ug_launch_common(service_h service, char *ug_name)
107 cbs.layout_cb = _ug_layout_cb;
108 cbs.destroy_cb = _ug_destroy_cb;
109 cbs.result_cb = _ug_result_cb;
112 service_dump(service);
113 ug_create(NULL, ug_name, UG_MODE_FULLVIEW, service, &cbs);
114 service_destroy(service);
118 * ug_launch_common_var
121 * This function supply a variadic version of ug_launch_common_var.
122 * The first and only required variable is the ug_name.
123 * Its type is string, but the caller should use the macro name which defined in memo_ug.h
124 * The other variables are optional, it should appear for key-value pair
125 * The end of optional variables must be NULL.
127 * @param[in] ug_name UG name marco defined in memo_ug.h
128 * @param[in] ... pair of key and value, end with NULL
131 void ug_launch_common_var(char *ug_name, ...)
135 service_h service = NULL;
136 service_create(&service);
139 va_start(ap, ug_name);
141 key = va_arg(ap, char *);
142 val = va_arg(ap, char *);
144 if (key == NULL || val == NULL) {
147 service_add_extra_data(service, key, val);
151 ug_launch_common(service, ug_name);
154 void ug_launch_message(Eina_List *list)
156 GString *text = get_shared_text(list);
157 GString *attachment = get_shared_attachment(list);
158 service_h service = NULL;
159 service_create(&service);
160 service_add_extra_data(service, "BODY", text->str);
161 service_add_extra_data(service, "ATTACHFILE", attachment->len == 0 ? NULL : attachment->str);
163 ug_launch_common(service, UG_NAME_MESSAGE);
165 g_string_free(text, TRUE);
166 g_string_free(attachment, TRUE);
169 void ug_launch_email(Eina_List *list)
171 GString *text = get_shared_text(list);
172 GString *attachment = get_shared_attachment(list);
174 service_h service = NULL;
175 service_create(&service);
176 service_add_extra_data(service, "RUN_TYPE", "5");
177 service_add_extra_data(service, "TO", "");
178 service_add_extra_data(service, "CC", "");
179 service_add_extra_data(service, "BCC", NULL);
180 service_add_extra_data(service, "SUBJECT", "");
181 service_add_extra_data(service, "BODY", text->str);
182 service_add_extra_data(service, "ATTACHMENT", attachment->len == 0 ? NULL : attachment->str);
184 ug_launch_common(service, UG_NAME_EMAIL);
186 g_string_free(text, TRUE);
187 g_string_free(attachment, TRUE);
190 void ug_launch_calender(Eina_List *list)
192 GString *text = get_shared_text(list);
194 service_h service = NULL;
195 service_create(&service);
196 service_add_extra_data(service, "index", "0");
197 service_add_extra_data(service, "note", text->str);
199 ug_launch_common(service, UG_NAME_CALENDAR);
201 g_string_free(text, TRUE);
204 void ug_launch_facebook(Eina_List *list)
206 GString *text = get_shared_text(list);
207 service_h service = NULL;
208 service_create(&service);
209 service_add_extra_data(service, "feature", "status_post");
210 service_add_extra_data(service, "text", text->str);
211 ug_launch_common(service, "facebook-efl");
212 g_string_free(text, TRUE);
215 void ug_launch_nfc(Eina_List *list)
217 GString *text = get_shared_text(list);
218 service_h service = NULL;
219 service_create(&service);
220 service_add_extra_data(service, "count", "1"); /* only one buffer suppored */
221 service_add_extra_data(service, "request_type", "data_buffer");
222 service_add_extra_data(service, "request_data", text->str);
223 ug_launch_common(service, UG_NAME_NFC);
224 g_string_free(text, TRUE);
227 void memo_ug_init(Evas_Object *win)
229 enum ug_option opt = UG_OPT_INDICATOR_ENABLE;
230 UG_INIT_EFL(win, opt);
233 /* BEGIN SHARE POPUP */
235 typedef struct _share_popup_data {
237 Eina_List *list; /* records of memo */
240 static void _share_messge_selected_cb(void *data, Evas_Object *obj, void *event_info)
242 share_popup_data *spd = (share_popup_data *)data;
243 ug_launch_message(spd->list);
244 _on_response_cb(spd, spd->popup, NULL);
247 static void _share_email_selected_cb(void *data, Evas_Object *obj, void *event_info)
249 share_popup_data *spd = (share_popup_data *)data;
250 ug_launch_email(spd->list);
251 _on_response_cb(spd, spd->popup, NULL);
254 static void _share_calender_selected_cb(void *data, Evas_Object *obj, void *event_info)
256 share_popup_data *spd = (share_popup_data *)data;
257 ug_launch_calender(spd->list);
258 _on_response_cb(spd, spd->popup, NULL);
261 static void _share_facebook_selected_cb(void *data, Evas_Object *obj, void *event_info)
263 share_popup_data *spd = (share_popup_data *)data;
264 ug_launch_facebook(spd->list);
265 _on_response_cb(spd, spd->popup, NULL);
268 static void _share_nfc_selected_cb(void *data, Evas_Object *obj, void *event_info)
270 share_popup_data *spd = (share_popup_data *)data;
271 ug_launch_nfc(spd->list);
272 _on_response_cb(spd, spd->popup, NULL);
275 static void _on_response_cb(void *data, Evas_Object *obj, void *event_info)
277 share_popup_data *spd = (share_popup_data *)data;
278 if (spd->popup != NULL) {
279 evas_object_del(spd->popup);
282 if (spd->list != NULL) {
283 memo_data_t *md = NULL;
284 EINA_LIST_FREE(spd->list, md) {
291 static char *_gl_label_get(void *data, Evas_Object *obj, const char *part)
293 char *label = (char *)data;
294 if (strcmp(part, "elm.text") == 0) {
295 return strdup(label);
300 void memo_share(Evas_Object *parent, int *indexes, int n)
302 share_popup_data *spd = SMALLOC(share_popup_data);
308 Evas_Object *box = NULL;
309 Eina_Bool has_doodle = EINA_FALSE;
310 memo_data_t *md = NULL;
311 for (i=0; i<n ; i++) { /* retrieve records */
312 md = memo_get_data(indexes[i]);
313 if (md->has_doodle) {
314 has_doodle = EINA_TRUE;
316 spd->list = eina_list_append(spd->list, md);
319 static Elm_Genlist_Item_Class itc;
320 memset(&itc, 0, sizeof(Elm_Genlist_Item_Class));
321 itc.item_style = "1text";
322 itc.func.text_get = _gl_label_get;
324 Evas_Object *popup = elm_popup_add(parent);
326 elm_object_style_set(popup, "min_menustyle");
327 elm_object_part_text_set(popup, "title,text", MEMO_I18N_SHARE);
328 Evas_Object *btn1 = elm_button_add(popup);
329 elm_object_text_set(btn1, MEMO_I18N_CLOSE);
330 elm_object_part_content_set(popup, "button1", btn1);
331 evas_object_smart_callback_add(btn1, "clicked", _on_response_cb, spd);
332 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
334 Evas_Object *genlist = elm_genlist_add(popup);
335 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
336 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
339 elm_genlist_item_append(genlist, &itc, MEMO_I18N_MESSAGE,
340 NULL, ELM_GENLIST_ITEM_NONE, _share_messge_selected_cb, spd);
344 elm_genlist_item_append(genlist, &itc, MEMO_I18N_EMAIL,
345 NULL, ELM_GENLIST_ITEM_NONE, _share_email_selected_cb, spd);
350 elm_genlist_item_append(genlist, &itc, MEMO_I18N_CALENDAR,
351 NULL, ELM_GENLIST_ITEM_NONE, _share_calender_selected_cb, spd);
354 elm_genlist_item_append(genlist, &itc, MEMO_I18N_FACEBOOK,
355 NULL, ELM_GENLIST_ITEM_NONE, _share_facebook_selected_cb, spd);
358 if (!vconf_get_bool(VCONFKEY_NFC_FEATURE, &nfc_enable)) {
359 if(nfc_enable == VCONFKEY_NFC_FEATURE_ON) {
360 elm_genlist_item_append(genlist, &itc, MEMO_I18N_NFC,
361 NULL, ELM_GENLIST_ITEM_NONE, _share_nfc_selected_cb, spd);
366 evas_object_show(genlist);
367 box = elm_box_add(popup);
368 evas_object_size_hint_min_set(box, 0, (c>3 ? 3 : c)*113*elm_config_scale_get());
369 elm_box_pack_end(box, genlist);
370 evas_object_show(box);
371 elm_object_content_set(popup, box);
372 evas_object_show(popup);