summaryrefslogtreecommitdiff
path: root/src/util.c
blob: 64d7e9efd0743bb8392a4bd1fb1fe49ea1091680 (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
/*
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
 *
 * 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 <Elementary.h>
#include <app_debug.h>
#include <notification.h>
#include <inputmgr.h>
#include <app_contents.h>

#include "define.h"

enum _button_id {
	BUTTON_OK,
	BUTTON_CANCEL,
};

static void _key_up_cb(int id, void *data, Evas *e, Evas_Object *obj,
		Evas_Event_Key_Up *ev);
static void _clicked(int id, void *data, Evas_Object *obj);

static input_handler popup_handler = {
	.key_up = _key_up_cb,
	.clicked = _clicked,
};

static void _key_up_cb(int id, void *data, Evas *e, Evas_Object *obj,
		Evas_Event_Key_Up *ev)
{
	if (!data)
		return;

	if (!strcmp(ev->keyname, KEY_BACK) ||
			!strcmp(ev->keyname, KEY_ESC)) {
		inputmgr_remove_callback(data, &popup_handler);
		evas_object_del(data);
	}
}

static void _clicked(int id, void *data, Evas_Object *obj)
{
	if (!data)
		return;

	switch (id) {
	case BUTTON_OK:
		inputmgr_remove_callback(data, &popup_handler);
		evas_object_del(data);
		break;
	}
}

Evas_Object *util_show_notification_popup(
		Evas_Object *base, notification_h noti)
{
	Evas_Object *popup, *btn1;
	char *title = NULL;
	char *content = NULL;

	popup = elm_popup_add(base);
	if (!popup) {
		_ERR("create popup failed");
		return NULL;
	}
	evas_object_show(popup);

	notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &title);
	elm_object_part_text_set(popup, "title,text", title);

	notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
	elm_object_text_set(popup, content);

	evas_object_data_set(popup, KEY_NOTI, noti);

	btn1 = elm_button_add(popup);
	elm_object_text_set(btn1, "OK");
	elm_object_part_content_set(popup, "button1", btn1);
	inputmgr_add_callback(btn1,
			BUTTON_OK, &popup_handler, popup);
	evas_object_show(btn1);
	elm_object_focus_set(btn1, EINA_TRUE);

	return popup;
}

void util_clear_notification(void)
{
	notification_list_h noti_list = NULL;
	notification_h noti;

	notification_get_list(NOTIFICATION_TYPE_NOTI, -1, &noti_list);
	if (!noti_list)
		return;

	while (noti_list != NULL) {
		noti = notification_list_get_data(noti_list);
		notification_delete(noti);

		noti_list = notification_list_remove(noti_list, noti);
		notification_free(noti);
	}
}

Evas_Object *util_add_icon(Evas_Object *parent, const char *file,
		const char *part)
{
	Evas_Object *ic;

	if (!parent) {
		_ERR("failed to get parent");
		return NULL;
	}

	ic = elm_icon_add(parent);
	if (!ic) {
		_ERR("failed to create icon");
		return NULL;
	}

	if (file)
		elm_image_file_set(ic, file, NULL);

	if (part)
		elm_object_part_content_set(parent, part, ic);

	elm_image_fill_outside_set(ic, EINA_TRUE);

	evas_object_show(ic);

	return ic;
}

Evas_Object *util_add_button(Evas_Object *parent, const char *part,
		const char *text, const char *style)
{
	Evas_Object *btn;

	if (!parent) {
		_ERR("Invalid argument.");
		return NULL;
	}

	btn = elm_button_add(parent);
	if (!btn) {
		_ERR("elm_button_add failed.");
		return NULL;
	}

	if (part)
		elm_object_part_content_set(parent, part, btn);
	if (text)
		elm_object_text_set(btn, text);
	if (style)
		elm_object_style_set(btn, style);

	evas_object_show(btn);

	return btn;
}

void util_set_last_viewed(void)
{
	int r;

	r = app_contents_set_basis_time(CONTENTS_NOTI);
	if (r != APP_CONTENTS_ERROR_NONE)
		_ERR("failed to set basis time");
}