PRIVATE gboolean update_workarea_size(GSettings* dock_gsettings) { int x, y, width, height; get_workarea_size(&x, &y, &width, &height); if (width == 0 || height == 0) { g_timeout_add(200, (GSourceFunc)update_workarea_size, dock_gsettings); return FALSE; } int hide_mode = g_settings_get_enum (dock_gsettings, DOCK_HIDE_MODE); g_debug ("hide mode: %d", hide_mode); if ((hide_mode==HIDE_MODE_AUTOHIDDEN)|| (hide_mode==HIDE_MODE_INTELLIGENT)) { //reserve the bottom (60 x width) area even dock is not show int root_height = gdk_screen_get_height (gdk_screen_get_default ()); if (y + height + 60 > root_height) height = root_height - 60 -y; } JSObjectRef workarea_info = json_create(); json_append_number(workarea_info, "x", x); json_append_number(workarea_info, "y", y); json_append_number(workarea_info, "width", width); json_append_number(workarea_info, "height", height); js_post_message("workarea_changed", workarea_info); return FALSE; }
void handle_delete(GFile* f) { _remove_monitor_directory(f); JSObjectRef json = json_create(); json_append_nobject(json, "entry", f, g_object_ref, g_object_unref); js_post_message("item_delete", json); }
PRIVATE void _insert_category(JSObjectRef categories, int array_index, int id, const char* name) { JSObjectRef item = json_create(); json_append_number(item, "ID", id); json_append_string(item, "Name", name); json_array_insert(categories, array_index, item); }
DBUS_EXPORT_API void dock_bus_message_notify(gchar* appid, gchar* itemid) { JSObjectRef info = json_create(); json_append_string(info, "appid", appid); json_append_string(info, "itemid", itemid); js_post_message("message_notify", info); }
void trash_changed() { GFileInfo* info = g_file_query_info(_trash_can, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT, G_FILE_QUERY_INFO_NONE, NULL, NULL); int count = g_file_info_get_attribute_uint32(info, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT); g_object_unref(info); JSObjectRef value = json_create(); json_append_number(value, "value", count); js_post_message("trash_count_changed", value); }
void notify_primary_size() { struct DisplayInfo info; update_primary_info(&info); JSObjectRef size_info = json_create(); json_append_number(size_info, "x", info.x); json_append_number(size_info, "y", info.y); json_append_number(size_info, "width", info.width); json_append_number(size_info, "height", info.height); js_post_message("primary_size_changed", size_info); }
void _update_notify_area_width() { if (_fcitx_tray) _na_width = _deepin_tray_width + _fcitx_tray_width + DEFAULT_INTERVAL; else _na_width = _deepin_tray_width - DEFAULT_INTERVAL + _fcitx_tray_width; g_hash_table_foreach(_icons, (GHFunc)accumulate_na_width, NULL); JSObjectRef width = json_create(); json_append_number(width, "width", _na_width + 2 * DEFAULT_INTERVAL); js_post_message("tray_icon_area_changed", width); }
void handle_rename(GFile* old_f, GFile* new_f) { _add_monitor_directory(new_f); _remove_monitor_directory(old_f); char* path = g_file_get_path(new_f); Entry* entry = dentry_create_by_path(path); g_free(path); JSObjectRef json = json_create(); json_append_nobject(json, "old", old_f, g_object_ref, g_object_unref); json_append_nobject(json, "new", entry, g_object_ref, g_object_unref); js_post_message("item_rename", json); g_object_unref(entry); }
void handle_update(GFile* f) { // g_message("handle_update"); if (g_file_query_file_type(f, G_FILE_QUERY_INFO_NONE ,NULL) != G_FILE_TYPE_UNKNOWN) { char* path = g_file_get_path(f); Entry* entry = dentry_create_by_path(path); g_free(path); JSObjectRef json = json_create(); json_append_nobject(json, "entry", entry, g_object_ref, g_object_unref); js_post_message("item_update", json); desktop_item_update(); g_object_unref(entry); } }
static gboolean not_recognize_handler(gpointer data) { g_debug("[%s] not recognized", __func__); g_debug("[%s] send auth-failed signal", __func__); JSObjectRef json = json_create(); recognition_info.DELAY_TIME = 4.0; char* msg = g_strdup_printf(_("%sRetry automatically in %ds"), ERR_POST_PREFIX, (int)recognition_info.DELAY_TIME); json_append_string(json, "error", msg); g_free(msg); js_post_message("auth-failed", json); g_timer_start(recognition_info.timer); recognition_info.reco_state = NOT_START_RECOGNIZING; return G_SOURCE_REMOVE; }
JS_EXPORT_API JSObjectRef installer_get_installation_info () { GRAB_CTX (); JSObjectRef json = json_create (); json_append_string (json, "target", opt_target); json_append_string (json, "home", opt_home); json_append_string (json, "username", opt_username); json_append_string (json, "hostname", opt_hostname); json_append_string (json, "password", opt_password); json_append_string (json, "layout", opt_layout); json_append_string (json, "variant", opt_variant); json_append_string (json, "timezone", opt_timezone); json_append_string (json, "locale", opt_locale); json_append_string (json, "grub", opt_grub); UNGRAB_CTX (); return json; }
__USE_LIBASN int main(int argc, char *argv[]) { char buf[BUFSIZ]; mmatic *mm = mmatic_create(); xstr *xs = xstr_create("", mm); json *js = json_create(mm); while (fgets(buf, BUFSIZ, stdin)) xstr_append(xs, buf); ut *parsed = json_parse(js, xstr_string(xs)); if (ut_ok(parsed)) printf("%s", json_print(js, parsed)); else printf("%s\n", ut_err(parsed)); return 0; }
/** * \brief Callback of the HTTP client. * * \param[in] module_inst Module instance of HTTP client module. * \param[in] type Type of event. * \param[in] data Data structure of the event. \refer http_client_data */ static void http_client_callback(struct http_client_module *module_inst, int type, union http_client_data *data) { struct json_obj json, loc; switch (type) { case HTTP_CLIENT_CALLBACK_SOCK_CONNECTED: printf("Connected\r\n"); break; case HTTP_CLIENT_CALLBACK_REQUESTED: printf("Request complete\r\n"); break; case HTTP_CLIENT_CALLBACK_RECV_RESPONSE: printf("Received response %u data size %u\r\n", (unsigned int)data->recv_response.response_code, (unsigned int)data->recv_response.content_length); if (data->recv_response.content != NULL) { if (json_create(&json, data->recv_response.content, data->recv_response.content_length) == 0 && json_find(&json, "loc", &loc) == 0) { printf("Location : %s\r\n", loc.value.s); } } break; case HTTP_CLIENT_CALLBACK_DISCONNECTED: printf("Disconnected reason:%d\r\n", data->disconnected.reason); /* If disconnect reason is equals to -ECONNRESET(-104), * It means Server was disconnected your connection by the keep alive timeout. * This is normal operation. */ if (data->disconnected.reason == -EAGAIN) { /* Server has not responded. retry it immediately. */ http_client_send_request(&http_client_module_inst, MAIN_HTTP_CLIENT_TEST_URL, MAIN_HTTP_CLIENT_TEST_METHOD, NULL); } break; } }
/** Parse config file * @retval 0 success * @retval 1 syntax error * @retval 2 logic error * @retval 3 other error */ static int parse_config(struct mg *mg) { FILE *fp; xstr *xs; char buf[4096], *str; json *js; ut *cfg; /* read file contents, ignoring empty lines and comments */ fp = fopen(mg->options.conf_file, "r"); if (!fp) { dbg(0, "%s: fopen() failed: %s\n", mg->options.conf_file, strerror(errno)); return 3; } xs = xstr_create("{", mg->mmtmp); while (fgets(buf, sizeof buf, fp)) { str = pjf_trim(buf); if (!str || !str[0] || str[0] == '#') continue; xstr_append(xs, str); } xstr_append_char(xs, '}'); fclose(fp); /* parse config file as loose JSON */ js = json_create(mg->mmtmp); json_setopt(js, JSON_LOOSE, 1); cfg = json_parse(js, xstr_string(xs)); if (!ut_ok(cfg)) { dbg(0, "parsing config file failed: %s\n", ut_err(cfg)); return 1; } /* parse config */ return (parse_config_ut(mg, cfg) ? 2 : 0); }
void reco() { // RESOURCE_DIR defined in CMakeLists.txt char* args[] = {"/usr/bin/python", RESOURCE_DIR"/greeter/scripts/reco", recognition_info.current_username, NULL}; GError* err = NULL; char* is_same_person = NULL; g_spawn_sync(NULL, args, NULL, 0, NULL, NULL, &is_same_person, NULL, NULL, &err); if (err != NULL) { g_warning("[%s] %s", __func__, err->message); g_error_free(err); } g_debug("[%s] #%s#", __func__, is_same_person); if (g_strcmp0(is_same_person, "True") == 0) { recognition_info.reco_state = RECOGNIZED; g_free(is_same_person); } else { g_debug("[%s] not recognized", __func__); recognition_info.reco_times += 1; if (recognition_info.reco_times == MAX_RECO_TIME) { g_debug("[%s] reach the max recognition time", __func__); JSObjectRef json = json_create(); char* msg = g_strdup_printf("%s%s", ERR_POST_PREFIX, _("Please login with your password or click your picture to retry.")); json_append_string(json, "error", msg); g_free(msg); js_post_message("failed-too-much", json); recognition_info.detect_is_enabled = FALSE; recognition_info.reco_state = RECOGNIZE_FINISH; g_free(is_same_person); return; } recognition_info.reco_state = NOT_RECOGNIZED; } }
static bool readjson_len(struct req *req, int len) { char buf[BUFSIZ]; xstr *xs = xstr_create("", req); json *js; if (len < 0) { while (fgets(buf, sizeof(buf), stdin)) { if (!buf[0] || buf[0] == '\n') break; xstr_append(xs, buf); } } else { int r; while ((r = fread(buf, 1, MIN(len, sizeof(buf)), stdin))) { if (r < 0) { dbg(5, "fread() returned %d, len=%d\n", r, len); break; } /* always appends \0 */ xstr_append_size(xs, buf, r); len -= r; if (len <= 0) break; } } /* eof? */ if (xstr_length(xs) == 0) exit(0); js = json_create(req); req->params = json_parse(js, xstr_string(xs)); return common(req, false); }
JSObjectRef dominantcolor_get_color(const char* path, double _method) { double r, g, b; int method = _method; switch(method) { case 1: calc_dominant_color_by_path(path, &r, &g, &b, clamp1); break; case 2: calc_dominant_color_by_path(path, &r, &g, &b, clamp2); break; case 3: calc_dominant_color_by_path(path, &r, &g, &b, clamp3); break; case 4: calc_dominant_color_by_path(path, &r, &g, &b, clamp4); break; } JSObjectRef json = json_create(); json_append_number(json, "r", r * 256); json_append_number(json, "g", g * 256); json_append_number(json, "b", b * 256); return json; }
{ g_object_unref(trash_can); g_object_unref(m); } void trash_changed(GFileMonitor* monitor G_GNUC_UNUSED, GFile* file G_GNUC_UNUSED, GFile* other_file G_GNUC_UNUSED, GFileMonitorEvent event_type G_GNUC_UNUSED, gpointer data G_GNUC_UNUSED) { GFileInfo* info = g_file_query_info(trash_can, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT, G_FILE_QUERY_INFO_NONE, NULL, NULL); int count = g_file_info_get_attribute_uint32(info, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT); g_object_unref(info); JSObjectRef value = json_create(); json_append_number(value, "value", count); js_post_message("trash_count_changed", value); } GFileMonitor* monitor_trash() { atexit(destroy_monitor); trash_can = g_file_new_for_uri("trash:///"); m = g_file_monitor_directory(trash_can, G_FILE_MONITOR_SEND_MOVED, NULL, NULL); g_signal_connect(m, "changed", G_CALLBACK(trash_changed), NULL); return m; }
JS_EXPORT_API gboolean lock_try_unlock (const gchar *username,const gchar *password) { if (lock_is_guest()) { js_post_signal("auth-succeed"); gtk_main_quit(); return TRUE; } gboolean succeed = FALSE; GDBusProxy *lock_proxy = NULL; GVariant *lock_succeed = NULL; GError *error = NULL; lock_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, "com.deepin.dde.lock", "/com/deepin/dde/lock", "com.deepin.dde.lock", NULL, &error); if (error != NULL) { g_warning ("connect com.deepin.dde.lock failed"); g_error_free (error); } error = NULL; lock_succeed = g_dbus_proxy_call_sync (lock_proxy, "UnlockCheck", g_variant_new ("(ss)", username, password), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); //g_assert (lock_succeed != NULL); if (error != NULL) { g_warning ("try unlock:UnlockCheck %s\n", error->message); g_error_free (error); } error = NULL; g_variant_get (lock_succeed, "(b)", &succeed); g_variant_unref (lock_succeed); g_object_unref (lock_proxy); if (succeed) { js_post_signal("auth-succeed"); } else { JSObjectRef error_message = json_create(); json_append_string(error_message, "error", _("Wrong Password")); js_post_message("auth-failed", error_message); } return succeed; }
int main() { char in_file_name[] = "../data/radiopolska_obiekty.csv"; char out_file_name[] = "../data/stations.json"; transmitter_t *transmitter; char line_buffer[2 * 1024]; FILE *in_file; FILE *out_file; json_object *json; const char *json_str; char *read_result; in_file = fopen(in_file_name, "r"); if (in_file == NULL) { fputs("Input/Output error.", stderr); return -1; } out_file = fopen(out_file_name, "w"); if (out_file == NULL) { fputs("Input/Output error.", stderr); return -1; } do { read_result = fgets(line_buffer, 2 * 1024, in_file); if (read_result != NULL) { line_buffer[strlen(line_buffer) - 2] = '\0'; transmitter = transmitter_create(line_buffer, ","); json = json_create(transmitter); json_str = json_object_to_json_string(json); fputs(json_str, out_file); fputc(10, out_file); json_object_put(json); free(transmitter); } } while (read_result != NULL); fclose(in_file); fclose(out_file); return 0; }
PRIVATE void _change_to_json(gpointer key, gpointer value, gpointer user_data) { json_append_number((JSObjectRef)user_data, key, GPOINTER_TO_INT(value)); } PRIVATE void desktop_plugins_changed(GSettings* settings, char* key G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) { extern gchar * get_schema_id(GSettings* gsettings); extern void _init_state(gpointer key, gpointer value, gpointer user_data); g_hash_table_foreach(plugins_state, _init_state, plugins_state); get_enabled_plugins(settings, "enabled-plugins"); JSObjectRef json = json_create(); char* current_gsettings_schema_id = get_schema_id(settings); char* desktop_gsettings_schema_id = get_schema_id(desktop_gsettings); if (0 == g_strcmp0(current_gsettings_schema_id, desktop_gsettings_schema_id)) json_append_string(json, "app_name", "desktop"); g_free(desktop_gsettings_schema_id); g_free(current_gsettings_schema_id); g_hash_table_foreach(plugins_state, _change_to_json, (gpointer)json); js_post_message("plugins_changed", json); } JS_EXPORT_API gboolean desktop_get_config_boolean(const char* key_name) {
JS_EXPORT_API JSValueRef dcore_get_plugin_info(char const* path) { char* info_file_path = g_build_filename(path, "info.ini", NULL); GKeyFile* info_file = g_key_file_new(); g_key_file_load_from_file(info_file, info_file_path, G_KEY_FILE_NONE, NULL); g_free(info_file_path); JSObjectRef json = json_create(); char* id = g_key_file_get_string(info_file, "Plugin", "ID", NULL); json_append_string(json, "ID", id == NULL ? "" : id); g_free(id); char* name = g_key_file_get_string(info_file, "Plugin", "name", NULL); json_append_string(json, "name", name == NULL ? "" : name); g_free(name); char* description = g_key_file_get_string(info_file, "Plugin", "description", NULL); json_append_string(json, "description", description == NULL ? "" : description); g_free(description); int width = g_key_file_get_integer(info_file, "Plugin", "width", NULL); json_append_number(json, "width", width); int height = g_key_file_get_integer(info_file, "Plugin", "height", NULL); json_append_number(json, "height", height); GError* error = NULL; double x = g_key_file_get_double(info_file, "Plugin", "x", &error); if (error) { json_append_value(json, "x", jsvalue_null()); g_error_free(error); } else { json_append_number(json, "x", x); } error = NULL; double y = g_key_file_get_double(info_file, "Plugin", "y", &error); if (error) { json_append_value(json, "y", jsvalue_null()); g_error_free(error); } else { json_append_number(json, "y", y); } char* type = g_key_file_get_string(info_file, "Plugin", "type", NULL); json_append_string(json, "type", type == NULL ? "" : type); g_free(type); char* author = g_key_file_get_string(info_file, "Author", "author", NULL); json_append_string(json, "author", author == NULL ? "" : author); g_free(author); char* email = g_key_file_get_string(info_file, "Author", "email", NULL); json_append_string(json, "email", email == NULL ? "" : email); g_free(email); char* textdomain = g_key_file_get_string(info_file, "Locale", "textdomain", NULL); json_append_string(json, "textdomain", textdomain == NULL ? "" : textdomain); g_free(textdomain); gsize length = 0; char** js = g_key_file_get_string_list(info_file, "Resource", "js", &length, NULL); JSObjectRef js_arr = json_array_create(); trans_to_js_array(js, length, js_arr); json_append_value(json, "js", js_arr); g_strfreev(js); char** css = g_key_file_get_string_list(info_file, "Resource", "css", &length, NULL); JSObjectRef css_arr = json_array_create(); trans_to_js_array(css, length, css_arr); json_append_value(json, "css", css_arr); g_strfreev(css); char** screenshot = g_key_file_get_string_list(info_file, "Resource", "screenshot", &length, NULL); JSObjectRef ss_arr = json_array_create(); trans_to_js_array(screenshot, length, ss_arr); json_append_value(json, "screenshot", ss_arr); g_strfreev(screenshot); g_key_file_free(info_file); return json; }