ed1b8d16fa41ea125654f40c624b6ac851e1c059
[apps/home/ug-memo-efl.git] / src / memo_ug.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 <ui-gadget.h>
18 #include <Ecore_X.h>
19 #include <aul.h>
20 #include <supplement.h>
21 #include <memo-db.h>
22 #include "memo_ug.h"
23
24 static void _ug_layout_cb(struct ui_gadget *ug, enum ug_mode mode, void *priv)
25 {
26     Evas_Object *base, *win;
27     base = (Evas_Object *)ug_get_layout(ug);
28     if (base == NULL) {
29         return;
30     }
31
32     win = ug_get_window();
33     switch (mode) {
34     case UG_MODE_FULLVIEW:
35         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
36         elm_win_resize_object_add(win, base);
37         /* disable effect */
38         //ug_disable_effect(ug);
39         evas_object_show(base);
40         break;
41     default:
42         break;
43     }
44 }
45
46 static void _ug_result_cb(ui_gadget_t *ug, bundle *result, void *priv)
47 {
48     bundle_dump(result);
49 }
50
51 static void _ug_destroy_cb(struct ui_gadget *ug, void *priv)
52 {
53     if (ug != NULL) {
54         ug_destroy(ug);
55     }
56 }
57
58 /**
59  * ug_launch_common
60  *
61  * @description
62  *  This is a basic function which designed to invoke any ui gadget.
63  *
64  * @param[in]   bd         a bundle type which will send to ug directly
65  * @param[in]   ug_name    UG name marco defined in memo_ug.h
66  * @return      void
67  */
68 void ug_launch_common(bundle *bd, char *ug_name)
69 {
70     ug_cbs_t cbs={0, };
71
72     cbs.layout_cb = _ug_layout_cb;
73     cbs.destroy_cb = _ug_destroy_cb;
74     cbs.result_cb = _ug_result_cb;
75     cbs.priv = NULL;
76
77     ug_create(NULL, ug_name, UG_MODE_FULLVIEW, bd, &cbs);
78     bundle_free(bd);
79 }
80
81 /**
82  * ug_launch_common_var
83  *
84  * @description
85  *  This function supply a variadic version of ug_launch_common_var.
86  *  The first and only required variable is the ug_name.
87  *  Its type is string, but the caller should use the macro name which defined in memo_ug.h
88  *  The other variables are optional, it should appear for key-value pair
89  *  The end of optional variables must be NULL.
90  *
91  * @param[in]   ug_name    UG name marco defined in memo_ug.h
92  * @param[in]   ...        pair of key and value, end with NULL
93  * @return      void
94  */
95 void ug_launch_common_var(char *ug_name, ...)
96 {
97     char *key = NULL;
98     char *val = NULL;
99     bundle *bd = bundle_create();
100
101     va_list ap;
102     va_start(ap, ug_name);
103     while (1) {
104         key = va_arg(ap, char *);
105         val = va_arg(ap, char *);
106
107         if (key == NULL || val == NULL) {
108             break;
109         }
110         bundle_add(bd, key, val);
111     }
112     va_end(ap);
113
114     ug_launch_common(bd, ug_name);
115 }
116