90e962c2e976bf11ddd24007c236dd2eb3eaaa9e
[apps/home/ug-memo-efl.git] / src / memo_ug.c
1 /*
2  * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
3  * 
4  * This file is part of the ug-memo-efl
5  * Written by Zhibin Zhou <zhibin.zhou@samsung.com>, Canjiang Lu <canjiang.lu@samsung.com>,
6  *            Feng Li <feng.li@samsung.com>
7  *
8  * PROPRIETARY/CONFIDENTIAL
9  *
10  * This software is the confidential and proprietary information of
11  * SAMSUNG ELECTRONICS ("Confidential Information").
12  * You shall not disclose such Confidential Information and shall
13  * use it only in accordance with the terms of the license agreement
14  * you entered into with SAMSUNG ELECTRONICS.  SAMSUNG make no
15  * representations or warranties about the suitability
16  * of the software, either express or implied, including but not
17  * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-
18  * infringement. SAMSUNG shall not be liable for any damages suffered by licensee as
19  * a result of using, modifying or distributing this software or its derivatives.
20  *
21  */
22 #include <ui-gadget.h>
23 #include <Ecore_X.h>
24 #include <aul.h>
25 #include <supplement.h>
26 #include <memo-db.h>
27 #include "memo_ug.h"
28
29 static void _ug_layout_cb(struct ui_gadget *ug, enum ug_mode mode, void *priv)
30 {
31     Evas_Object *base, *win;
32     base = (Evas_Object *)ug_get_layout(ug);
33     if (base == NULL) {
34         return;
35     }
36
37     win = ug_get_window();
38     switch (mode) {
39     case UG_MODE_FULLVIEW:
40         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
41         elm_win_resize_object_add(win, base);
42         /* disable effect */
43         //ug_disable_effect(ug);
44         evas_object_show(base);
45         break;
46     default:
47         break;
48     }
49 }
50
51 static void _ug_result_cb(ui_gadget_t *ug, bundle *result, void *priv)
52 {
53     bundle_dump(result);
54 }
55
56 static void _ug_destroy_cb(struct ui_gadget *ug, void *priv)
57 {
58     if (ug != NULL) {
59         ug_destroy(ug);
60     }
61 }
62
63 /**
64  * ug_launch_common
65  *
66  * @description
67  *  This is a basic function which designed to invoke any ui gadget.
68  *
69  * @param[in]   bd         a bundle type which will send to ug directly
70  * @param[in]   ug_name    UG name marco defined in memo_ug.h
71  * @return      void
72  */
73 void ug_launch_common(bundle *bd, char *ug_name)
74 {
75     ug_cbs_t cbs={0, };
76
77     cbs.layout_cb = _ug_layout_cb;
78     cbs.destroy_cb = _ug_destroy_cb;
79     cbs.result_cb = _ug_result_cb;
80     cbs.priv = NULL;
81
82     ug_create(NULL, ug_name, UG_MODE_FULLVIEW, bd, &cbs);
83     bundle_free(bd);
84 }
85
86 /**
87  * ug_launch_common_var
88  *
89  * @description
90  *  This function supply a variadic version of ug_launch_common_var.
91  *  The first and only required variable is the ug_name.
92  *  Its type is string, but the caller should use the macro name which defined in memo_ug.h
93  *  The other variables are optional, it should appear for key-value pair
94  *  The end of optional variables must be NULL.
95  *
96  * @param[in]   ug_name    UG name marco defined in memo_ug.h
97  * @param[in]   ...        pair of key and value, end with NULL
98  * @return      void
99  */
100 void ug_launch_common_var(char *ug_name, ...)
101 {
102     char *key = NULL;
103     char *val = NULL;
104     bundle *bd = bundle_create();
105
106     va_list ap;
107     va_start(ap, ug_name);
108     while (1) {
109         key = va_arg(ap, char *);
110         val = va_arg(ap, char *);
111
112         if (key == NULL || val == NULL) {
113             break;
114         }
115         bundle_add(bd, key, val);
116     }
117     va_end(ap);
118
119     ug_launch_common(bd, ug_name);
120 }
121