Example #1
0
//TODO:
JS_EXPORT_API
JSObjectRef dentry_get_flags (Entry* e)
{
    JSObjectRef json = json_array_create();
    GFile* f;
    if (!G_IS_FILE(e)) {
        return json;
    }
    f = e;

    GFileInfo* info = g_file_query_info (f,
            "standard::*,access::*",
            G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
            NULL,
            NULL);

    if (info != NULL)
    {
        gboolean is_read_only = FALSE;
        gboolean is_symlink = FALSE;
        gboolean is_unreadable = FALSE;
        is_unreadable = !g_file_info_get_attribute_boolean(info, "access::can-read");
        is_read_only = !g_file_info_get_attribute_boolean(info, "access::can-write");
        is_symlink = g_file_info_get_is_symlink(info);
        g_object_unref(info);
        json_append_number(json, "read_only", is_read_only);
        json_append_number(json, "symbolic_link", is_symlink);
        json_append_number(json, "unreadable", is_unreadable);
    }

    return json;
}
Example #2
0
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;
}
Example #3
0
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);
}
Example #4
0
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);
}
Example #5
0
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);
}
Example #6
0
/* Serialise Lua data into JSON string. */
static void json_append_data(lua_State *l, struct luaL_serializer *cfg,
                             int current_depth, strbuf_t *json)
{
    struct luaL_field field;
    luaL_checkfield(l, cfg, -1, &field);
    switch (field.type) {
    case MP_UINT:
        return json_append_uint(cfg, json, field.ival);
    case MP_STR:
    case MP_BIN:
        return json_append_string(cfg, json, field.sval.data, field.sval.len);
    case MP_INT:
        return json_append_int(cfg, json, field.ival);
    case MP_FLOAT:
        return json_append_number(cfg, json, field.fval);
    case MP_DOUBLE:
        return json_append_number(cfg, json, field.dval);
    case MP_BOOL:
    if (field.bval)
        strbuf_append_mem(json, "true", 4);
    else
        strbuf_append_mem(json, "false", 5);
    break;
    case MP_NIL:
    json_append_nil(cfg, json);
    break;
    case MP_MAP:
    if (current_depth >= cfg->encode_max_depth)
        return json_append_nil(cfg, json); /* Limit nested maps */
    json_append_object(l, cfg, current_depth, json);
    return;
    case MP_ARRAY:
    /* Array */
    if (current_depth >= cfg->encode_max_depth)
        return json_append_nil(cfg, json); /* Limit nested arrays */
    json_append_array(l, cfg, current_depth, json, field.size);
    return;
    case MP_EXT:
    /* handled by luaL_convertfield */
    assert(false);
    return;
    }
}
Example #7
0
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);
}
Example #8
0
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;
}
Example #9
0
static void json_append_object(lua_State *l, json_config_t *cfg,
                               strbuf_t *json)
{
    int comma, keytype;

    json_encode_descend(l, cfg);

    /* Object */
    strbuf_append_char(json, '{');

    lua_pushnil(l);
    /* table, startkey */
    comma = 0;
    while (lua_next(l, -2) != 0) {
        if (comma)
            strbuf_append_char(json, ',');
        else
            comma = 1;

        /* table, key, value */
        keytype = lua_type(l, -2);
        if (keytype == LUA_TNUMBER) {
            strbuf_append_char(json, '"');
            json_append_number(l, json, -2, cfg);
            strbuf_append_mem(json, "\":", 2);
        } else if (keytype == LUA_TSTRING) {
            json_append_string(l, json, -2);
            strbuf_append_char(json, ':');
        } else {
            json_encode_exception(l, cfg, -2,
                                  "table key must be a number or string");
            /* never returns */
        }

        /* table, key, value */
        json_append_data(l, cfg, json);
        lua_pop(l, 1);
        /* table, key */
    }

    strbuf_append_char(json, '}');

    cfg->current_depth--;
}
Example #10
0
/* Serialise Lua data into JSON string. */
static void json_append_data(lua_State *l, json_config_t *cfg,
                             int current_depth, strbuf_t *json)
{
    int len;

    switch (lua_type(l, -1)) {
    case LUA_TSTRING:
        json_append_string(l, json, -1);
        break;
    case LUA_TNUMBER:
        json_append_number(l, cfg, json, -1);
        break;
    case LUA_TBOOLEAN:
        if (lua_toboolean(l, -1))
            strbuf_append_mem(json, "true", 4);
        else
            strbuf_append_mem(json, "false", 5);
        break;
    case LUA_TTABLE:
        current_depth++;
        json_check_encode_depth(l, cfg, current_depth, json);
        len = lua_array_length(l, cfg, json);
        if (len > 0)
            json_append_array(l, cfg, current_depth, json, len);
        else
            json_append_object(l, cfg, current_depth, json);
        break;
    case LUA_TNIL:
        strbuf_append_mem(json, "null", 4);
        break;
    case LUA_TLIGHTUSERDATA:
        if (lua_touserdata(l, -1) == NULL) {
            strbuf_append_mem(json, "null", 4);
            break;
        }
    default:
        /* Remaining types (LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD,
         * and LUA_TLIGHTUSERDATA) cannot be serialised */
        json_encode_exception(l, cfg, json, -1, "type not supported");
        /* never returns */
    }
}
Example #11
0
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;
}
Example #12
0
PRIVATE
void _change_to_json(gpointer key, gpointer value, gpointer user_data)
{
    json_append_number((JSObjectRef)user_data, key, GPOINTER_TO_INT(value));
}