summaryrefslogtreecommitdiff
path: root/ugapp-wifidirect/src/wfd-ugapp-main.c
blob: b0d35d60505ebed8ee1883498e7b647bd10ce492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
*  WiFi-Direct UG
*
* 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.
*
*/

/**
 * This file implements wifi direct application main functions.
 *
 * @file    wfd-ug-app-main.c
 * @author  Dongwook Lee (dwmax.lee@samsung.com)
 * @version 0.1
 */

#include <ui-gadget-module.h>
#include <libintl.h>

#include "wfd-ugapp.h"
#include "wfd-ugapp-util.h"


wfd_appdata_t *g_wfd_ad = NULL;
static struct ug_cbs wifi_direct_cbs;

wfd_appdata_t *wfd_get_appdata()
{
    return g_wfd_ad;
}

void
_ug_layout_cb(struct ui_gadget *ug, enum ug_mode mode, void *priv)
{
	__WFD_APP_FUNC_ENTER__;

    Evas_Object *base = NULL;
    base = ug_get_layout(ug);

    if (!base)
    {
    	WFD_APP_LOG(WFD_APP_LOG_LOW,"ug_get_layout failed!");
        ug_destroy(ug);
        return;
    }

    switch (mode)
    {
        case UG_MODE_FULLVIEW:
            evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
            elm_win_resize_object_add(ug_get_window(), base);
            evas_object_show(base);
            break;
        default:
          break;
    }
}

void
_ug_destroy_cb(struct ui_gadget *ug, void *priv)
{
	__WFD_APP_FUNC_ENTER__;

    // TODO: free all memory allocation

    ug_destroy(ug);
    elm_exit();
}

void ug_result_cb(struct ui_gadget *ug, bundle * result, void *priv)
{
	__WFD_APP_FUNC_ENTER__;

    // TODO: free all memory allocation

}

static int load_wifi_direct_ug(struct ui_gadget *parent_ug, void *data)
{
	__WFD_APP_FUNC_ENTER__;
    wfd_appdata_t *ugd = (wfd_appdata_t *)data;
    bundle *param = NULL;

    UG_INIT_EFL(ugd->win, UG_OPT_INDICATOR_ENABLE);

    memset(&wifi_direct_cbs, 0, sizeof(struct ug_cbs));

    wifi_direct_cbs.layout_cb = _ug_layout_cb;
    wifi_direct_cbs.result_cb = ug_result_cb;
    wifi_direct_cbs.destroy_cb = _ug_destroy_cb;
    wifi_direct_cbs.priv = ugd;

    ugd->wifi_direct_ug = ug_create(parent_ug, "setting-wifidirect-efl", UG_MODE_FULLVIEW, param, &wifi_direct_cbs);
    if (ugd->wifi_direct_ug)
        return TRUE;
    else
        return FALSE;
}


static void _win_del(void *data, Evas_Object * obj, void *event)
{
    elm_exit();
}

static Evas_Object *_create_win(Evas_Object * parent, const char *name)
{
    Evas_Object *eo;
    int w, h;

    eo = elm_win_add(parent, name, ELM_WIN_BASIC);
    if (eo)
    {
        elm_win_title_set(eo, name);
        elm_win_borderless_set(eo, EINA_TRUE);
        elm_win_alpha_set(eo, EINA_TRUE);
        evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
        ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
        evas_object_resize(eo, w, h);
        evas_object_show(eo);
        //evas_object_raise(eo);
    }

    return eo;
}


static int _app_create(void *data)
{
    __WFD_APP_FUNC_ENTER__;

    wfd_appdata_t *ad = wfd_get_appdata();

    if (data == NULL)
    {
        WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter\n");
        return -1;
    }

    bindtextdomain(PACKAGE, LOCALEDIR);

    ad->win = _create_win(NULL, PACKAGE);
    elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);

    int r;

    if (!ecore_x_display_get())
        return -1;

    r = appcore_set_i18n(PACKAGE, NULL);
    if (r != 0)
    {
        WFD_APP_LOG(WFD_APP_LOG_LOW, "appcore_set_i18n error\n");
        return -1;
    }

    __WFD_APP_FUNC_EXIT__;

    return 0;
}

static int _app_terminate(void *data)
{
	__WFD_APP_FUNC_ENTER__;

	if (data == NULL)
	{
		WFD_APP_LOG(WFD_APP_LOG_ERROR, "Incorrect parameter\n");
		return -1;
	}

	wfd_appdata_t *ad = (wfd_appdata_t *) data;

	if (ad->win)
	{
		evas_object_del(ad->win);
		ad->win = NULL;
	}

	__WFD_APP_FUNC_EXIT__;

	return 0;
}

static int _app_pause(void *data)
{
    __WFD_APP_FUNC_ENTER__;
    __WFD_APP_FUNC_EXIT__;
    return 0;
}

static int _app_resume(void *data)
{
    __WFD_APP_FUNC_ENTER__;
    __WFD_APP_FUNC_EXIT__;
    return 0;
}

static int _app_reset(bundle * b, void *data)
{
    __WFD_APP_FUNC_ENTER__;

    wfd_appdata_t *ad = wfd_get_appdata();

    load_wifi_direct_ug(NULL, ad);

    __WFD_APP_FUNC_EXIT__;
    return 0;
}

int main(int argc, char *argv[])
{
    wfd_appdata_t ad;
    struct appcore_ops ops = {
        .create = _app_create,
        .terminate = _app_terminate,
        .pause = _app_pause,
        .resume = _app_resume,
        .reset = _app_reset,
    };

    memset(&ad, 0x0, sizeof(wfd_appdata_t));
    ops.data = &ad;
    g_wfd_ad = &ad;

    return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
}