4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include <sys/types.h>
30 #include <Elementary.h>
33 #include <notification.h>
34 #include <notification_db.h>
35 #include <notification_noti.h>
36 #include <notification_debug.h>
37 #include <notification_private.h>
38 #include <notification_status.h>
40 #define PATH_NAME "/Org/Tizen/System/Notification/Status_message"
41 #define INTERFACE_NAME "org.tizen.system.notification.status_message"
42 #define MEMBER_NAME "status_message"
44 static Eina_List *toast_list;
45 static Eina_List *toast_popup;
47 struct _message_cb_data {
48 notification_status_message_cb callback;
50 E_DBus_Connection *dbus_connection;
51 E_DBus_Signal_Handler *dbus_hdlr;
54 static struct _message_cb_data md;
56 int _post_toast_message(char *message);
58 static void popup_timeout_cb(void *data, Evas_Object *obj, void *event_info)
63 evas_object_del(toast_popup);
65 evas_object_del((Evas_Object *)data);
67 count = eina_list_count(toast_list);
70 msg = (char *)eina_list_data_get(toast_list);
73 eina_list_free(toast_list);
75 } else if (count > 1) {
76 msg = (char *)eina_list_data_get(toast_list);
77 toast_list = eina_list_remove(toast_list, msg);
79 _post_toast_message((char *)eina_list_data_get(toast_list));
83 int _post_toast_message(char *message)
85 Evas_Object *toast_window;
88 double scale = elm_config_scale_get();
91 toast_window = elm_win_add(NULL, "toast", ELM_WIN_BASIC);
93 elm_win_alpha_set(toast_window, EINA_TRUE);
94 elm_win_title_set(toast_window, "toast");
96 elm_win_indicator_mode_set(toast_window, ELM_WIN_INDICATOR_SHOW);
97 elm_win_indicator_type_set(toast_window,ELM_WIN_INDICATOR_TYPE_1);
99 //elm_win_autodel_set(toast_win, EINA_TRUE);
100 if (elm_win_wm_rotation_supported_get(toast_window)) {
101 int rots[4] = { 0, 90, 180, 270 };
102 elm_win_wm_rotation_available_rotations_set(toast_window, (const int*)(&rots), 4);
105 e = evas_object_evas_get(toast_window);
106 ee = ecore_evas_ecore_evas_get(e);
107 ecore_evas_name_class_set(ee, "TOAST_POPUP", "SYSTEM_POPUP");
109 evas_object_resize(toast_window, (480 * scale), (650 * scale));
110 ecore_x_window_shape_input_rectangle_set(elm_win_xwindow_get(toast_window), 0, 0, (480 * scale), (650 * scale));
112 toast_popup = elm_popup_add(toast_window);
114 elm_object_style_set(toast_popup, "toast");
115 evas_object_size_hint_weight_set(toast_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
117 elm_object_text_set(toast_popup,message);
119 if (eina_list_count(toast_list) != 1) {
120 elm_popup_timeout_set(toast_popup, 1.0);
123 elm_popup_timeout_set(toast_popup, 3.0);
125 evas_object_smart_callback_add(toast_popup, "timeout", popup_timeout_cb, (void *)toast_window);
127 elm_win_prop_focus_skip_set(toast_window, EINA_TRUE);
129 evas_object_show(toast_window);
130 evas_object_show(toast_popup);
135 int notification_noti_post_toast_message(const char *message)
141 msg = (char *)calloc(strlen(message) + 1, sizeof(char));
142 strcpy(msg, message);
144 count = eina_list_count(toast_list);
146 toast_list = eina_list_append(toast_list, msg);
147 let = _post_toast_message(msg);
149 else if (count == 1) {
150 if (strcmp(msg, (char *)eina_list_nth(toast_list, count - 1)) == 0) {
151 elm_popup_timeout_set(toast_popup, 3.0);
154 toast_list = eina_list_append(toast_list, msg);
155 elm_popup_timeout_set(toast_popup, 1.0);
158 else if (count >= 2) {
159 if (strcmp(msg, (char *)eina_list_nth(toast_list, count - 1)) == 0) {
164 toast_list = eina_list_append(toast_list, msg);
171 static void __notification_status_message_dbus_callback(void *data, DBusMessage *msg)
175 char *message = NULL;
177 if(data==NULL||msg==NULL)
179 NOTIFICATION_ERR("message is NULL");
183 dbus_error_init(&err);
184 ret = dbus_message_get_args(msg, &err,
185 DBUS_TYPE_STRING, &message,
189 NOTIFICATION_ERR("dbus_message_get_args error");
193 if (dbus_error_is_set(&err)) {
194 NOTIFICATION_ERR("Dbus err: %s", err.message);
195 dbus_error_free(&err);
201 if (strlen(message) <= 0){
202 NOTIFICATION_ERR("message has only NULL");
206 md.callback(message, md.data);*/
208 notification_noti_post_toast_message(message);
212 int notification_status_message_post(const char *message)
214 DBusConnection *connection = NULL;
215 DBusMessage *signal = NULL;
220 NOTIFICATION_ERR("message is NULL");
221 return NOTIFICATION_ERROR_INVALID_PARAMETER;
224 if (strlen(message) <= 0) {
225 NOTIFICATION_ERR("message has only NULL");
226 return NOTIFICATION_ERROR_INVALID_PARAMETER;
229 dbus_error_init(&err);
230 connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
232 NOTIFICATION_ERR("Fail to dbus_bus_get");
233 return NOTIFICATION_ERROR_FROM_DBUS;
237 dbus_message_new_signal(PATH_NAME, INTERFACE_NAME,
240 NOTIFICATION_ERR("Fail to dbus_message_new_signal");
241 return NOTIFICATION_ERROR_FROM_DBUS;
244 ret = dbus_message_append_args(signal,
245 DBUS_TYPE_STRING, &message,
248 ret = dbus_connection_send(connection, signal, NULL);
251 dbus_connection_flush(connection);
255 dbus_message_unref(signal);
256 dbus_connection_unref(connection);
258 return NOTIFICATION_ERROR_NONE;
262 int notification_status_monitor_message_cb_set(notification_status_message_cb callback, void *user_data)
265 return NOTIFICATION_ERROR_INVALID_PARAMETER;
266 E_DBus_Connection *dbus_connection;
267 E_DBus_Signal_Handler *dbus_handler_size = NULL;
270 dbus_connection = e_dbus_bus_get(DBUS_BUS_SYSTEM);
271 if (dbus_connection == NULL) {
272 NOTIFICATION_ERR("noti register : failed to get dbus bus");
273 return NOTIFICATION_ERROR_FROM_DBUS;
276 e_dbus_signal_handler_add(dbus_connection, NULL,
278 INTERFACE_NAME, MEMBER_NAME,
279 __notification_status_message_dbus_callback,
281 if (dbus_handler_size == NULL)
283 NOTIFICATION_ERR("fail to add size signal");
284 return NOTIFICATION_ERROR_FROM_DBUS;
288 md.callback = callback;
290 md.dbus_connection = dbus_connection;
291 md.dbus_hdlr = dbus_handler_size;
293 return NOTIFICATION_ERROR_NONE;
297 int notification_status_monitor_message_cb_unset(void)
299 if (md.dbus_hdlr != NULL) {
300 e_dbus_signal_handler_del(md.dbus_connection,
304 if (md.dbus_connection != NULL) {
305 e_dbus_connection_close(md.dbus_connection);
306 md.dbus_connection = NULL;
313 return NOTIFICATION_ERROR_NONE;