4 * Copyright (c) 2013 Intel Corporation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 __free_user_data(struct bt_popup_appdata *ad)
25 if (ad->agent_proxy) {
26 g_object_unref(ad->agent_proxy);
27 ad->agent_proxy = NULL;
30 g_object_unref(ad->obex_proxy);
31 ad->obex_proxy = NULL;
37 __bluetooth_create_agent_proxy(DBusGConnection *sys_conn, const char *path)
39 return dbus_g_proxy_new_for_name ( sys_conn,
46 __bluetooth_create_obex_proxy(DBusGConnection *sys_conn)
48 return dbus_g_proxy_new_for_name( sys_conn,
49 "org.bluez.frwk_agent",
50 "/org/obex/ops_agent",
51 "org.openobex.Agent");
55 __gtk_pin_ok_cb(GtkWidget *widget, struct bt_popup_appdata *ad)
59 dbus_g_proxy_call_no_reply(ad->agent_proxy,
61 G_TYPE_UINT, BT_AGENT_ACCEPT,
62 G_TYPE_STRING, gtk_entry_get_text(GTK_ENTRY(ad->entry)),
63 G_TYPE_INVALID, G_TYPE_INVALID);
65 gtk_widget_destroy(GTK_WIDGET(ad->window));
70 __gtk_pin_cancel_cb(GtkWidget *widget, struct bt_popup_appdata *ad)
74 dbus_g_proxy_call_no_reply(ad->agent_proxy,
76 G_TYPE_UINT, BT_AGENT_CANCEL,
78 G_TYPE_INVALID, G_TYPE_INVALID);
80 gtk_widget_destroy(GTK_WIDGET(ad->window));
85 __gtk_passkey_ok_cb(GtkWidget *widget, struct bt_popup_appdata *ad)
89 dbus_g_proxy_call_no_reply(ad->agent_proxy,
91 G_TYPE_UINT, BT_AGENT_ACCEPT,
92 G_TYPE_STRING, gtk_entry_get_text(GTK_ENTRY(ad->entry)),
93 G_TYPE_INVALID, G_TYPE_INVALID);
95 gtk_widget_destroy(GTK_WIDGET(ad->window));
100 __gtk_passkey_cancel_cb(GtkWidget *widget, struct bt_popup_appdata *ad)
102 g_assert(ad != NULL);
104 dbus_g_proxy_call_no_reply(ad->agent_proxy,
106 G_TYPE_UINT, BT_AGENT_CANCEL,
108 G_TYPE_INVALID, G_TYPE_INVALID);
110 gtk_widget_destroy(GTK_WIDGET(ad->window));
111 __free_user_data(ad);
115 __notify_passkey_confirm_request_accept_cb(NotifyNotification *n, const char *action, struct bt_popup_appdata *ad)
117 g_assert(ad != NULL);
119 dbus_g_proxy_call_no_reply( ad->agent_proxy, "ReplyConfirmation",
120 G_TYPE_UINT, BT_AGENT_ACCEPT,
121 G_TYPE_INVALID, G_TYPE_INVALID);
123 notify_notification_close(n, NULL);
129 __notify_passkey_confirm_request_cancel_cb(NotifyNotification *n, const char *action, struct bt_popup_appdata *ad)
131 g_assert(ad != NULL);
133 dbus_g_proxy_call_no_reply( ad->agent_proxy, "ReplyConfirmation",
134 G_TYPE_UINT, BT_AGENT_CANCEL,
135 G_TYPE_INVALID, G_TYPE_INVALID);
137 notify_notification_close(n, NULL);
141 __notify_passkey_display_request_ok_cb(NotifyNotification *n, const char *action, struct bt_popup_appdata *ad)
143 g_assert(ad != NULL);
145 /* Close the popup */
146 notify_notification_close(n, NULL);
150 __notify_passkey_display_request_cancel_cb(NotifyNotification *n, const char *action, struct bt_popup_appdata *ad)
152 g_assert(ad != NULL);
154 bluetooth_cancel_bonding();
156 notify_notification_close(n, NULL);
160 __notify_push_authorize_request_accept_cb(NotifyNotification *n, const char *action, struct bt_popup_appdata *ad)
162 g_assert(ad != NULL);
164 dbus_g_proxy_call_no_reply( ad->obex_proxy, "ReplyAuthorize",
165 G_TYPE_UINT, BT_AGENT_ACCEPT,
166 G_TYPE_INVALID, G_TYPE_INVALID);
168 notify_notification_close(n, NULL);
172 __notify_push_authorize_request_cancel_cb(NotifyNotification *n, const char *action, struct bt_popup_appdata *ad)
174 g_assert(ad != NULL);
176 dbus_g_proxy_call_no_reply( ad->obex_proxy, "ReplyAuthorize",
177 G_TYPE_UINT, BT_AGENT_CANCEL,
178 G_TYPE_INVALID, G_TYPE_INVALID);
180 notify_notification_close(n, NULL);
184 __notify_authorize_request_accept_cb(NotifyNotification *n, const char *action, struct bt_popup_appdata *ad)
186 g_assert(ad != NULL);
188 dbus_g_proxy_call_no_reply( ad->agent_proxy, "ReplyAuthorize",
189 G_TYPE_UINT, BT_AGENT_ACCEPT,
190 G_TYPE_INVALID, G_TYPE_INVALID);
192 notify_notification_close(n, NULL);
196 __notify_authorize_request_cancel_cb(NotifyNotification *n, const char *action, struct bt_popup_appdata *ad)
198 g_assert(ad != NULL);
200 dbus_g_proxy_call_no_reply( ad->agent_proxy, "ReplyAuthorize",
201 G_TYPE_UINT, BT_AGENT_CANCEL,
202 G_TYPE_INVALID, G_TYPE_INVALID);
204 notify_notification_close(n, NULL);
208 __create_pixbuf(const gchar * filename)
211 GError *error = NULL;
212 pixbuf = gdk_pixbuf_new_from_file(filename, &error);
214 BT_ERR("%s\n", error->message);
222 __close_window(GtkWidget *widget, struct bt_popup_appdata *ad)
224 gtk_widget_destroy(GTK_WIDGET(ad->window));
228 __draw_input_view( const char *event_type,
229 struct bt_popup_appdata *ad,
236 if ((!event_type) && strcasecmp(event_type, "pin-request") && strcasecmp(event_type, "passkey-request"))
239 GtkWidget *text_wdgt;
242 GtkWidget *cancel_bt;
244 gtk_init(NULL, NULL);
245 ad->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
246 gtk_window_set_default_size(GTK_WINDOW(ad->window), 300, 100);
247 gtk_window_set_position(GTK_WINDOW(ad->window), GTK_WIN_POS_CENTER);
248 gtk_window_set_icon(GTK_WINDOW(ad->window), __create_pixbuf(NOTIFY_ICON));
249 gtk_window_set_title(GTK_WINDOW (ad->window), title);
251 layout = gtk_layout_new(NULL, NULL);
252 gtk_container_add(GTK_CONTAINER (ad->window), layout);
253 gtk_widget_show(layout);
255 image = gtk_image_new_from_file(NOTIFY_ICON);
256 gtk_layout_put(GTK_LAYOUT(layout), image, 0, 25);
258 text_wdgt = gtk_label_new(body);
259 gtk_layout_put(GTK_LAYOUT(layout), text_wdgt, 90, 0);
261 ad->entry = gtk_entry_new();
263 if(!strcasecmp(event_type, "pin-request"))
264 gtk_entry_set_max_length(GTK_ENTRY(ad->entry), BT_PIN_MLEN);
265 else if (!strcasecmp(event_type, "passkey-request"))
266 gtk_entry_set_max_length(GTK_ENTRY(ad->entry), BT_PK_MLEN);
268 gtk_layout_put(GTK_LAYOUT(layout), ad->entry, 90, 20);
270 ok_bt = gtk_button_new_with_label("Ok");
271 gtk_layout_put(GTK_LAYOUT(layout), ok_bt, 100, 50);
272 gtk_widget_set_size_request(ok_bt, 60, 35);
274 cancel_bt = gtk_button_new_with_label("Cancel");
275 gtk_layout_put(GTK_LAYOUT(layout), cancel_bt, 160, 50);
276 gtk_widget_set_size_request(cancel_bt, 60, 35);
278 g_signal_connect (ad->window, "destroy", G_CALLBACK(__close_window), ad);
279 g_signal_connect(ok_bt, "clicked", G_CALLBACK(ok_cb), ad);
280 g_signal_connect(cancel_bt, "clicked", G_CALLBACK(cancel_cb), ad);
282 gtk_widget_show_all(ad->window);
288 __notify_send_popup( struct bt_popup_appdata *ad,
291 NotifyActionCallback action1_cb,
293 NotifyActionCallback action2_cb)
295 NotifyNotification *n = NULL;
296 GError *error = NULL;
298 n = notify_notification_new( "Tizen Bluetooth",
302 __free_user_data(ad);
303 BT_ERR("failed to create new notification\n");
307 notify_notification_set_timeout(n, NOTIFY_EXPIRES_DEFAULT);
309 if (action1_name && action1_cb)
310 notify_notification_add_action( n, "action1", action1_name,
311 (NotifyActionCallback)action1_cb,
313 (GFreeFunc) __free_user_data);
314 if (action2_name && action2_cb)
315 notify_notification_add_action( n, "action2", action2_name,
316 (NotifyActionCallback)action2_cb,
318 (GFreeFunc) __free_user_data);
319 if (!notify_notification_show(n, &error)){
320 __free_user_data(ad);
321 BT_ERR("failed to send notification : %s\n", error->message);
328 notify_launch(bundle * user_data)
331 struct bt_popup_appdata *ad;
332 ad = (struct bt_popup_appdata*) malloc ( sizeof(struct bt_popup_appdata));
333 memset(ad, 0x0, sizeof(struct bt_popup_appdata));
334 DBusGConnection *sys_conn;
335 const char *device_name = NULL;
336 const char *passkey = NULL;
337 const char *file = NULL;
338 const char *agent_path;
339 const char *event_type = NULL;
343 if (!notify_is_initted())
344 if (!notify_init("Tizen Bluetooth-frwk")){
345 BT_ERR("notification init failed\n");
350 event_type = bundle_get_val(user_data, "event-type");
352 if(!strcasecmp(event_type, "pin-request")) {
353 device_name = (gchar*) bundle_get_val(user_data, "device-name");
354 agent_path = bundle_get_val(user_data, "agent-path");
356 sys_conn = _bt_get_system_gconn();
357 if (sys_conn == NULL) {
358 BT_ERR("ERROR: Can't get on system bus");
362 ad->agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
363 if (!ad->agent_proxy){
364 BT_ERR("create new agent_proxy failed\n");
368 title = g_strdup_printf("Bluetooth pairing request");
369 body = g_strdup_printf("Enter PIN to pair with %s (Try 0000 or 1234)", device_name);
371 ret = __draw_input_view(event_type, ad, title, body, &__gtk_pin_ok_cb, &__gtk_pin_cancel_cb);
374 } else if (!strcasecmp(event_type, "passkey-confirm-request")){
375 device_name = (gchar*) bundle_get_val(user_data, "device-name");
376 passkey = (gchar*) bundle_get_val(user_data, "passkey");
377 agent_path = bundle_get_val(user_data, "agent-path");
379 sys_conn = _bt_get_system_gconn();
380 if (sys_conn == NULL) {
381 BT_ERR("ERROR: Can't get on system bus");
385 ad->agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
386 if (!ad->agent_proxy){
387 BT_ERR("create new agent_proxy failed\n");
391 body = g_strdup_printf("Confirm passkey is %s to pair with %s", passkey, device_name);
393 ret = __notify_send_popup( ad,
396 (NotifyActionCallback) __notify_passkey_confirm_request_accept_cb,
398 (NotifyActionCallback) __notify_passkey_confirm_request_cancel_cb);
400 } else if (!strcasecmp(event_type, "passkey-request")) {
401 device_name = (gchar*) bundle_get_val(user_data, "device-name");
402 agent_path = bundle_get_val(user_data, "agent-path");
404 sys_conn = _bt_get_system_gconn();
405 if (sys_conn == NULL) {
406 BT_ERR("ERROR: Can't get on system bus");
410 ad->agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
411 if (!ad->agent_proxy){
412 BT_ERR("create new agent_proxy failed\n");
416 title = g_strdup_printf("Bluetooth pairing request");
417 body = g_strdup_printf("Enter PIN to pair with %s (Try 0000 or 1234)", device_name);
419 ret = __draw_input_view(event_type, ad, title, body, &__gtk_passkey_ok_cb, &__gtk_passkey_cancel_cb);
422 } else if (!strcasecmp(event_type, "passkey-display-request")) {
423 device_name = (gchar*) bundle_get_val(user_data, "device-name");
424 passkey = (gchar*) bundle_get_val(user_data, "passkey");
426 body = g_strdup_printf("Enter %s on %s to pair", passkey, device_name);
428 ret = __notify_send_popup( ad,
431 (NotifyActionCallback) __notify_passkey_display_request_ok_cb,
433 (NotifyActionCallback) __notify_passkey_display_request_cancel_cb);
435 } else if (!strcasecmp(event_type, "authorize-request")) {
436 device_name = (gchar*) bundle_get_val(user_data, "device-name");
437 agent_path = bundle_get_val(user_data, "agent-path");
439 sys_conn = _bt_get_system_gconn();
440 if (sys_conn == NULL) {
441 BT_ERR("ERROR: Can't get on system bus");
445 ad->agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
446 if (!ad->agent_proxy){
447 BT_ERR("create new agent_proxy failed\n");
451 body = g_strdup_printf("Allow %s to connect?", device_name);
453 ret = __notify_send_popup( ad,
456 (NotifyActionCallback) __notify_authorize_request_accept_cb,
458 (NotifyActionCallback) __notify_authorize_request_cancel_cb);
460 } else if (!strcasecmp(event_type, "app-confirm-request")) {
461 /* FIXME Seems to be an osp mechanism so not implemented to be confirmed */
462 BT_DBG("app-confirm-request even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed\n");
464 } else if (!strcasecmp(event_type, "push-authorize-request")) {
465 file = (gchar*) bundle_get_val(user_data, "file");
466 device_name = (gchar*) bundle_get_val(user_data, "device-name");
468 sys_conn = _bt_get_system_gconn();
469 if (sys_conn == NULL) {
470 BT_ERR("ERROR: Can't get on system bus");
474 ad->obex_proxy = __bluetooth_create_obex_proxy(sys_conn);
475 if (!ad->obex_proxy){
476 BT_ERR("create new obex_proxy failed\n");
480 body = g_strdup_printf("Receive %s from %s?", file, device_name);
482 ret = __notify_send_popup( ad,
485 (NotifyActionCallback) __notify_push_authorize_request_accept_cb,
487 (NotifyActionCallback) __notify_push_authorize_request_cancel_cb);
489 } else if (!strcasecmp(event_type, "confirm-overwrite-request")) {
490 /* FIXME Seems to be an osp mechanism so not implemented to be confirmed*/
491 BT_DBG("confirm-overwrite-request even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed\n");
493 } else if (!strcasecmp(event_type, "keyboard-passkey-request")) {
494 device_name = (gchar*) bundle_get_val(user_data, "device-name");
495 passkey = (gchar*) bundle_get_val(user_data, "passkey");
497 body = g_strdup_printf("Enter %s on %s to pair", passkey, device_name);
499 ret = __notify_send_popup( ad,
502 (NotifyActionCallback) __notify_passkey_display_request_ok_cb,
504 (NotifyActionCallback) __notify_passkey_display_request_cancel_cb);
506 } else if (!strcasecmp(event_type, "bt-information")) {
507 /* FIXME Seems to be an osp mechanism so not implemented to be confirmed */
508 BT_DBG("bt-information even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed\n");
510 } else if (!strcasecmp(event_type, "exchange-request")) {
511 device_name = (gchar*) bundle_get_val(user_data, "device-name");
512 agent_path = bundle_get_val(user_data, "agent-path");
514 sys_conn = _bt_get_system_gconn();
515 if (sys_conn == NULL) {
516 BT_ERR("ERROR: Can't get on system bus");
520 ad->agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
521 if (!ad->agent_proxy){
522 BT_ERR("create new agent_proxy failed\n");
526 body = g_strdup_printf("exchange-request from %s", device_name);
528 ret = __notify_send_popup( ad,
531 (NotifyActionCallback) __notify_authorize_request_accept_cb,
533 (NotifyActionCallback) __notify_authorize_request_cancel_cb);
535 } else if (!strcasecmp(event_type, "phonebook-request")) {
536 device_name = bundle_get_val(user_data, "device-name");
537 agent_path = bundle_get_val(user_data, "agent-path");
539 sys_conn = _bt_get_system_gconn();
540 if (sys_conn == NULL) {
541 BT_ERR("ERROR: Can't get on system bus");
545 ad->agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
546 if (!ad->agent_proxy){
547 BT_ERR("create new agent_proxy failed\n");
551 body = g_strdup_printf("Allow %s phonebook access", device_name);
553 ret = __notify_send_popup( ad,
556 (NotifyActionCallback) __notify_authorize_request_accept_cb,
558 (NotifyActionCallback) __notify_authorize_request_cancel_cb);
560 } else if (!strcasecmp(event_type, "message-request")) {
561 device_name = bundle_get_val(user_data, "device-name");
562 agent_path = bundle_get_val(user_data, "agent-path");
564 sys_conn = _bt_get_system_gconn();
565 if (sys_conn == NULL) {
566 BT_ERR("ERROR: Can't get on system bus");
570 ad->agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
571 if (!ad->agent_proxy){
572 BT_ERR("create new agent_proxy failed\n");
576 body = g_strdup_printf("Allow %s to access messages?", device_name);
578 ret = __notify_send_popup( ad,
581 (NotifyActionCallback) __notify_authorize_request_accept_cb,
583 (NotifyActionCallback) __notify_authorize_request_cancel_cb);