int message_popup(const char *message, int flags) { prop_t *p; int rval; p = prop_create_root(NULL); prop_set_string(prop_create(p, "type"), "message"); prop_set_string_ex(prop_create(p, "message"), NULL, message, flags & MESSAGE_POPUP_RICH_TEXT ? PROP_STR_RICH : PROP_STR_UTF8); if(flags & MESSAGE_POPUP_CANCEL) prop_set_int(prop_create(p, "cancel"), 1); if(flags & MESSAGE_POPUP_OK) prop_set_int(prop_create(p, "ok"), 1); event_t *e = popup_display(p); prop_destroy(p); if(event_is_action(e, ACTION_OK)) rval = MESSAGE_POPUP_OK; else if(event_is_action(e, ACTION_CANCEL)) rval = MESSAGE_POPUP_CANCEL; else rval = 0; event_release(e); return rval; }
int message_popup(const char *message, int flags, const char **extra) { prop_t *p; int rval; p = prop_ref_inc(prop_create_root(NULL)); TRACE(TRACE_DEBUG, "Notification", "%s", message); prop_set_string(prop_create(p, "type"), "message"); prop_set_string_ex(prop_create(p, "message"), NULL, message, flags & MESSAGE_POPUP_RICH_TEXT ? PROP_STR_RICH : PROP_STR_UTF8); if(extra) { int cnt = 1; prop_t *btns = prop_create(p, "buttons"); while(*extra) { prop_t *b = prop_create_root(NULL); prop_set_string(prop_create(b, "title"), *extra); char action[10]; snprintf(action, sizeof(action), "btn%d", cnt); prop_set_string(prop_create(b, "action"), action); if(prop_set_parent(b, btns)) abort(); cnt++; extra++; } } if(flags & MESSAGE_POPUP_CANCEL) prop_set_int(prop_create(p, "cancel"), 1); if(flags & MESSAGE_POPUP_OK) prop_set_int(prop_create(p, "ok"), 1); event_t *e = popup_display(p); prop_destroy(p); prop_ref_dec(p); const event_payload_t *ep = (const event_payload_t *)e; if(event_is_action(e, ACTION_OK)) rval = MESSAGE_POPUP_OK; else if(event_is_action(e, ACTION_CANCEL)) rval = MESSAGE_POPUP_CANCEL; else if(event_is_type(e, EVENT_DYNAMIC_ACTION) && !strncmp(ep->payload, "btn", 3)) rval = atoi(ep->payload + 3); else rval = 0; event_release(e); return rval; }
static void updatestr(glw_keyintercept_t *ki) { char str[KI_BUF_LEN * 5 + 1]; char *q; int i; q = str; for(i = 0; i < ki->buflen - 6; i++) q += utf8_put(q, ki->buf[i]); *q = 0; if(ki->prop != NULL) prop_set_string_ex(ki->prop, ki->sub, str, PROP_STR_UTF8); }
void js_prop_set_from_jsval(JSContext *cx, prop_t *p, jsval value) { JSBool b; if(JSVAL_IS_INT(value)) { prop_set_int(p, JSVAL_TO_INT(value)); } else if(JSVAL_IS_BOOLEAN(value)) { prop_set_int(p, JSVAL_TO_BOOLEAN(value)); } else if(JSVAL_IS_NULL(value) || JSVAL_IS_VOID(value)) { prop_set_void(p); } else if(JSVAL_IS_DOUBLE(value)) { double d; if(JS_ValueToNumber(cx, value, &d)) prop_set_float(p, d); } else if(JS_HasInstance(cx, RichText, value, &b) && b) { JSObject *o = JSVAL_TO_OBJECT(value); jsval v2; if(!JS_EnterLocalRootScope(cx)) return; if(!JS_GetProperty(cx, o, "text", &v2)) { JS_LeaveLocalRootScope(cx); return; } prop_set_string_ex(p, NULL, JS_GetStringBytes(JS_ValueToString(cx, v2)), PROP_STR_RICH); JS_LeaveLocalRootScope(cx); } else if(JSVAL_IS_STRING(value)) { js_prop_from_str(cx, p, value); } else if(JSVAL_IS_OBJECT(value)) { JSObject *obj = JSVAL_TO_OBJECT(value); JSClass *c = JS_GetClass(cx, obj); if(!strcmp(c->name, "XML")) // Treat some classes special js_prop_from_str(cx, p, value); else js_prop_from_object(cx, obj, p); } else { prop_set_void(p); } }
int text_dialog_kbrd(const char *message, char** answer, int flags) { htsmsg_t *m; rstr_t *r; prop_t *p = prop_create_root(NULL); prop_set_string(prop_create(p, "type"), "textDialogKbrd"); prop_set_string_ex(prop_create(p, "message"), NULL, message, flags & MESSAGE_POPUP_RICH_TEXT ? PROP_STR_RICH : PROP_STR_UTF8); prop_t *string = prop_create(p, "input"); if(flags & MESSAGE_POPUP_CANCEL) prop_set_int(prop_create(p, "cancel"), 1); if(flags & MESSAGE_POPUP_OK) prop_set_int(prop_create(p, "ok"), 1); event_t *e = popup_display_kbrd(p, string); if (event_is_action(e, ACTION_OK)) { m = htsmsg_create_map(); r = prop_get_string(string); htsmsg_add_str(m, "input", r ? rstr_get(r) : ""); rstr_release(r); htsmsg_get_str(m, "input"); setstr(answer, m, "input"); } prop_destroy(p); if(event_is_action(e, ACTION_CANCEL)){ event_release(e); return -1; } event_release(e); return 0; }
int text_dialog(const char *message, char **answer, int flags) { rstr_t *r; *answer = NULL; prop_t *p = prop_ref_inc(prop_create_root(NULL)); prop_set_string(prop_create(p, "type"), "textDialog"); prop_set_string_ex(prop_create(p, "message"), NULL, message, flags & MESSAGE_POPUP_RICH_TEXT ? PROP_STR_RICH : PROP_STR_UTF8); prop_t *string = prop_create(p, "input"); if(flags & MESSAGE_POPUP_CANCEL) prop_set_int(prop_create(p, "cancel"), 1); if(flags & MESSAGE_POPUP_OK) prop_set_int(prop_create(p, "ok"), 1); event_t *e = popup_display(p); if(event_is_action(e, ACTION_OK)) { r = prop_get_string(string, NULL); if(r) *answer = strdup(rstr_get(r)); rstr_release(r); } prop_destroy(p); prop_ref_dec(p); if(event_is_action(e, ACTION_CANCEL)) { event_release(e); return -1; } event_release(e); return 0; }
void js_prop_set_from_jsval(JSContext *cx, prop_t *p, jsval value, int recurse) { JSBool b; if(JSVAL_IS_INT(value)) { prop_set_int(p, JSVAL_TO_INT(value)); } else if(JSVAL_IS_BOOLEAN(value)) { prop_set_int(p, JSVAL_TO_BOOLEAN(value)); } else if(JSVAL_IS_DOUBLE(value)) { double d; if(JS_ValueToNumber(cx, value, &d)) prop_set_float(p, d); } else if(JS_HasInstance(cx, RichText, value, &b) && b) { JSObject *o = JSVAL_TO_OBJECT(value); jsval v2; if(!JS_EnterLocalRootScope(cx)) return; if(!JS_GetProperty(cx, o, "text", &v2)) { JS_LeaveLocalRootScope(cx); return; } prop_set_string_ex(p, NULL, JS_GetStringBytes(JS_ValueToString(cx, v2)), PROP_STR_RICH); JS_LeaveLocalRootScope(cx); } else if(JSVAL_IS_VOID(value) || JSVAL_IS_NULL(value)) { prop_set_void(p); } else if(recurse && JSVAL_IS_OBJECT(value)) { js_prop_from_object(cx, JSVAL_TO_OBJECT(value), p, recurse); } else { prop_set_string(p, JS_GetStringBytes(JS_ValueToString(cx, value))); } }