Change memo menu icon
[apps/home/memo.git] / src / memo_ug.c
index 753e5fb..3281ea9 100644 (file)
@@ -1,19 +1,20 @@
 /*
-  * Copyright 2012  Samsung Electronics Co., Ltd
-  * 
-  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
-  * 
-  * 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.
-  */
-
+*
+* Copyright 2012  Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+*
+* 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 <Ecore_X.h>
 #include <aul.h>
 #include <appsvc.h>
@@ -21,6 +22,9 @@
 #include <supplement.h>
 #include "memo_ug.h"
 #include "memo_string.h"
+#include <vconf.h>
+
+static void _on_response_cb(void *data, Evas_Object *obj, void *event_info);
 
 static GString *get_shared_text(Eina_List *list)
 {
@@ -37,7 +41,22 @@ static GString *get_shared_text(Eina_List *list)
     return buf;
 }
 
-static void _ug_layout_cb(ui_gadget_t *ug, enum ug_mode mode, void *priv)
+static GString *get_shared_attachment(Eina_List *list)
+{
+    Eina_List *l = NULL;
+    struct memo_data *md = NULL;
+    GString *buf = g_string_new("");
+
+    EINA_LIST_FOREACH(list, l, md) {
+        if ((md != NULL) && (md->has_doodle)) {
+            g_string_append_printf(buf, DOODLEDIR "/%d.png\n", (int)md->id);
+        }
+    }
+
+    return buf;
+}
+
+static void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
 {
     Evas_Object *base, *win;
     base = (Evas_Object *)ug_get_layout(ug);
@@ -59,12 +78,12 @@ static void _ug_layout_cb(ui_gadget_t *ug, enum ug_mode mode, void *priv)
     }
 }
 
-static void _ug_result_cb(ui_gadget_t *ug, bundle *result, void *priv)
+static void _ug_result_cb(ui_gadget_h ug, service_h service, void *priv)
 {
-    bundle_dump(result);
+    service_dump(service);
 }
 
-static void _ug_destroy_cb(ui_gadget_t *ug, void *priv)
+static void _ug_destroy_cb(ui_gadget_ug, void *priv)
 {
     if (ug != NULL) {
         ug_destroy(ug);
@@ -77,22 +96,22 @@ static void _ug_destroy_cb(ui_gadget_t *ug, void *priv)
  * @description
  *  This is a basic function which designed to invoke any ui gadget.
  *
- * @param[in]   bd         a bundle type which will send to ug directly
+ * @param[in]   service         a service type which will send to ug directly
  * @param[in]   ug_name    UG name marco defined in memo_ug.h
  * @return      void
  */
-void ug_launch_common(bundle *bd, char *ug_name)
+void ug_launch_common(service_h service, char *ug_name)
 {
-    ug_cbs_t cbs={0, };
+       ug_cbs_t cbs={0, };
 
-    cbs.layout_cb = _ug_layout_cb;
-    cbs.destroy_cb = _ug_destroy_cb;
-    cbs.result_cb = _ug_result_cb;
-    cbs.priv = NULL;
+       cbs.layout_cb = _ug_layout_cb;
+       cbs.destroy_cb = _ug_destroy_cb;
+       cbs.result_cb = _ug_result_cb;
+       cbs.priv = NULL;
 
-    bundle_dump(bd);
-    ug_create(NULL, ug_name, UG_MODE_FULLVIEW, bd, &cbs);
-    bundle_free(bd);
+       service_dump(service);
+       ug_create(NULL, ug_name, UG_MODE_FULLVIEW, service, &cbs);
+       service_destroy(service);
 }
 
 /**
@@ -111,37 +130,98 @@ void ug_launch_common(bundle *bd, char *ug_name)
  */
 void ug_launch_common_var(char *ug_name, ...)
 {
-    char *key = NULL;
-    char *val = NULL;
-    bundle *bd = bundle_create();
+       char *key = NULL;
+       char *val = NULL;
+       service_h service = NULL;
+       service_create(&service);
+
+       va_list ap;
+       va_start(ap, ug_name);
+       while (1) {
+               key = va_arg(ap, char *);
+               val = va_arg(ap, char *);
+
+               if (key == NULL || val == NULL) {
+                       break;
+               }
+               service_add_extra_data(service, key, val);
+       }
+       va_end(ap);
+
+       ug_launch_common(service, ug_name);
+}
 
-    va_list ap;
-    va_start(ap, ug_name);
-    while (1) {
-        key = va_arg(ap, char *);
-        val = va_arg(ap, char *);
+void ug_launch_message(Eina_List *list)
+{
+       GString *text = get_shared_text(list);
+       GString *attachment = get_shared_attachment(list);
+       service_h service = NULL;
+       service_create(&service);
+       service_add_extra_data(service, "BODY", text->str);
+       service_add_extra_data(service, "ATTACHFILE", attachment->len == 0 ? NULL : attachment->str);
 
-        if (key == NULL || val == NULL) {
-            break;
-        }
-        bundle_add(bd, key, val);
-    }
-    va_end(ap);
+       ug_launch_common(service, UG_NAME_MESSAGE);
 
-    ug_launch_common(bd, ug_name);
+       g_string_free(text, TRUE);
+       g_string_free(attachment, TRUE);
+}
+
+void ug_launch_email(Eina_List *list)
+{
+       GString *text = get_shared_text(list);
+       GString *attachment = get_shared_attachment(list);
+
+       service_h service = NULL;
+       service_create(&service);
+       service_add_extra_data(service, "RUN_TYPE", "5");
+       service_add_extra_data(service, "TO", "");
+       service_add_extra_data(service, "CC", "");
+       service_add_extra_data(service, "BCC", NULL);
+       service_add_extra_data(service, "SUBJECT", "");
+       service_add_extra_data(service, "BODY", text->str);
+       service_add_extra_data(service, "ATTACHMENT", attachment->len == 0 ? NULL : attachment->str);
+
+       ug_launch_common(service, UG_NAME_EMAIL);
+
+       g_string_free(text, TRUE);
+       g_string_free(attachment, TRUE);
 }
 
 void ug_launch_calender(Eina_List *list)
 {
-    GString *text = get_shared_text(list);
+       GString *text = get_shared_text(list);
+
+       service_h service = NULL;
+       service_create(&service);
+       service_add_extra_data(service, "index", "0");
+       service_add_extra_data(service, "note", text->str);
 
-    bundle *bd = bundle_create();
-    bundle_add(bd, "index", "0");
-    bundle_add(bd, "note", text->str);
+       ug_launch_common(service, UG_NAME_CALENDAR);
 
-    ug_launch_common(bd, UG_NAME_CALENDAR);
+       g_string_free(text, TRUE);
+}
 
-    g_string_free(text, TRUE);
+void ug_launch_facebook(Eina_List *list)
+{
+       GString *text = get_shared_text(list);
+       service_h service = NULL;
+       service_create(&service);
+       service_add_extra_data(service, "feature", "status_post");
+       service_add_extra_data(service, "text", text->str);
+       ug_launch_common(service, "facebook-efl");
+       g_string_free(text, TRUE);
+}
+
+void ug_launch_nfc(Eina_List *list)
+{
+       GString *text = get_shared_text(list);
+       service_h service = NULL;
+       service_create(&service);
+       service_add_extra_data(service, "count", "1");  /* only one buffer suppored */
+       service_add_extra_data(service, "request_type", "data_buffer");
+       service_add_extra_data(service, "request_data", text->str);
+       ug_launch_common(service, UG_NAME_NFC);
+       g_string_free(text, TRUE);
 }
 
 void memo_ug_init(Evas_Object *win)
@@ -155,10 +235,21 @@ void memo_ug_init(Evas_Object *win)
 typedef struct _share_popup_data {
     Evas_Object *popup;
     Eina_List *list; /* records of memo */
-    char *lib_path_facebook; /* lib path of facebook UG */
 }share_popup_data;
 
-static void _on_response_cb(void *data, Evas_Object *obj, void *event_info);
+static void _share_messge_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    share_popup_data *spd = (share_popup_data *)data;
+    ug_launch_message(spd->list);
+    _on_response_cb(spd, spd->popup, NULL);
+}
+
+static void _share_email_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    share_popup_data *spd = (share_popup_data *)data;
+    ug_launch_email(spd->list);
+    _on_response_cb(spd, spd->popup, NULL);
+}
 
 static void _share_calender_selected_cb(void *data, Evas_Object *obj, void *event_info)
 {
@@ -167,6 +258,20 @@ static void _share_calender_selected_cb(void *data, Evas_Object *obj, void *even
     _on_response_cb(spd, spd->popup, NULL);
 }
 
+static void _share_facebook_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    share_popup_data *spd = (share_popup_data *)data;
+    ug_launch_facebook(spd->list);
+    _on_response_cb(spd, spd->popup, NULL);
+}
+
+static void _share_nfc_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    share_popup_data *spd = (share_popup_data *)data;
+    ug_launch_nfc(spd->list);
+    _on_response_cb(spd, spd->popup, NULL);
+}
+
 static void _on_response_cb(void *data, Evas_Object *obj, void *event_info)
 {
     share_popup_data *spd = (share_popup_data *)data;
@@ -180,7 +285,6 @@ static void _on_response_cb(void *data, Evas_Object *obj, void *event_info)
             memo_free_data(md);
         }
     }
-    SFREE(spd->lib_path_facebook);
     SFREE(spd);
 }
 
@@ -200,6 +304,7 @@ void memo_share(Evas_Object *parent, int *indexes, int n)
 
     int i = 0;
     int c = 0;
+    int nfc_enable = -1;
     Evas_Object *box = NULL;
     Eina_Bool has_doodle = EINA_FALSE;
     memo_data_t *md = NULL;
@@ -230,21 +335,37 @@ void memo_share(Evas_Object *parent, int *indexes, int n)
     evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
     evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
-    Elm_Object_Item *it = NULL;
-    it = elm_genlist_item_append(genlist, &itc, MEMO_I18N_EMAIL,
-            NULL, ELM_GENLIST_ITEM_NONE, NULL, spd);
-    elm_object_item_disabled_set(it, EINA_TRUE);
+    /* message */
+    elm_genlist_item_append(genlist, &itc, MEMO_I18N_MESSAGE,
+            NULL, ELM_GENLIST_ITEM_NONE, _share_messge_selected_cb, spd);
     c++;
-
+    /* email */
+    if (n == 1) {
+        elm_genlist_item_append(genlist, &itc, MEMO_I18N_EMAIL,
+                NULL, ELM_GENLIST_ITEM_NONE, _share_email_selected_cb, spd);
+        c++;
+    }
     if (!has_doodle) {
         /* calendar */
         elm_genlist_item_append(genlist, &itc, MEMO_I18N_CALENDAR,
                 NULL, ELM_GENLIST_ITEM_NONE, _share_calender_selected_cb, spd);
         c++;
+        /* facebook */
+        elm_genlist_item_append(genlist, &itc, MEMO_I18N_FACEBOOK,
+            NULL, ELM_GENLIST_ITEM_NONE, _share_facebook_selected_cb, spd);
+        c++;
+        /* NFC */
+        if (!vconf_get_bool(VCONFKEY_NFC_FEATURE, &nfc_enable)) {
+            if(nfc_enable == VCONFKEY_NFC_FEATURE_ON) {
+                elm_genlist_item_append(genlist, &itc, MEMO_I18N_NFC,
+                NULL, ELM_GENLIST_ITEM_NONE, _share_nfc_selected_cb, spd);
+                c++;
+            }
+        }
     }
     evas_object_show(genlist);
     box = elm_box_add(popup);
-    evas_object_size_hint_min_set(box, 0, (c>3 ? 3 : c)*71);
+    evas_object_size_hint_min_set(box, 0, (c>3 ? 3 : c)*113*elm_config_scale_get());
     elm_box_pack_end(box, genlist);
     evas_object_show(box);
     elm_object_content_set(popup, box);