JS_EXPORT_API JSObjectRef greeter_get_sessions () { JSObjectRef array = json_array_create (); guint i; if (sessions == NULL) { sessions = lightdm_get_sessions (); } for (i = 0; i < g_list_length (sessions); ++i) { gchar *key = NULL; LightDMSession *session = (LightDMSession *)g_list_nth_data(sessions, i); key = g_strdup (lightdm_session_get_key (session)); json_array_insert(array, i, jsvalue_from_cstr(get_global_context(), g_strdup(key))); g_free (key); } return array; }
JS_EXPORT_API JSObjectRef launcher_get_items_by_category(double _id) { int id = _id; if (id == ALL_CATEGORY_ID) return _init_category_table(); JSObjectRef items = json_array_create(); GHashTable* l = (GHashTable*)g_hash_table_lookup(_category_table, GINT_TO_POINTER(id)); if (l == NULL) { return items; } JSContextRef cxt = get_global_context(); GHashTableIter iter; gpointer value = NULL; g_hash_table_iter_init(&iter, l); for (int i = 0; g_hash_table_iter_next(&iter, &value, NULL); ++i) { char const* path = (char const*)value; json_array_insert(items, i, jsvalue_from_cstr(cxt, path)); } return items; }
JS_EXPORT_API JSObjectRef installer_get_system_users() { GRAB_CTX (); JSObjectRef array = json_array_create (); struct passwd *user; gchar *username = NULL; int i = 0; while ((user = getpwent ()) != NULL){ if (user->pw_uid >= 1000 || g_strcmp0 ("deepin", user->pw_name) == 0) { continue; } username = g_strdup (user->pw_name); json_array_insert(array, i, jsvalue_from_cstr (get_global_context(), username)); i++; g_free (username); } endpwent (); UNGRAB_CTX (); return array; }
JS_EXPORT_API JSObjectRef greeter_get_users () { JSObjectRef array = json_array_create (); LightDMUser *user = NULL; guint i; if (users == NULL) { LightDMUserList *user_list = lightdm_user_list_get_instance (); if (user_list == NULL) { g_warning ("get users:user list is NULL\n"); return array; } users = lightdm_user_list_get_users (user_list); } for (i = 0; i < g_list_length (users); ++i) { gchar *username = NULL; user = (LightDMUser *) g_list_nth_data (users, i); username = g_strdup (lightdm_user_get_name (user)); json_array_insert (array, i, jsvalue_from_cstr (get_global_context (), g_strdup (username))); g_free (username); } return array; }
void trans_to_js_array(char** strv, gsize length, JSObjectRef json) { JSContextRef ctx = get_global_context(); for (guint i = 0; strv[i] != NULL || i < length; ++i) { json_array_insert(json, i, jsvalue_from_cstr(ctx, strv[i])); } }
void scan_plugin_dir(char const* path, char const* app_name, JSObjectRef array) { if (!g_file_test(path, G_FILE_TEST_EXISTS)) { return; } JSContextRef ctx = get_global_context(); GDir* dir = g_dir_open(path, 0, NULL); if (dir != NULL) { const char* file_name = NULL; for (int i=0; NULL != (file_name = g_dir_read_name(dir)); ) { char* full_path = g_build_filename(path, file_name, NULL); if (IS_DIR(full_path) && is_plugin(full_path)) { char* js_name = g_strconcat(file_name, ".js", NULL); char* js_path = g_build_filename(full_path, js_name, NULL); g_free(js_name); char* key = g_strconcat(app_name, ":", file_name, NULL); if (g_hash_table_contains(enabled_plugins, key)) { JSValueRef v = jsvalue_from_cstr(ctx, js_path); json_array_insert(array, i++, v); } g_free(key); g_free(js_path); } g_free(full_path); } g_dir_close(dir); } }
JS_EXPORT_API JSObjectRef installer_get_timezone_list () { GRAB_CTX (); gsize index = 0; GError *error = NULL; GFile *file = NULL; GFileInputStream *input = NULL; GDataInputStream *data_input = NULL; JSObjectRef timezones = json_array_create (); file = g_file_new_for_path ("/usr/share/zoneinfo/zone.tab"); if (!g_file_query_exists (file, NULL)) { g_warning ("get timezone list:zone.tab not exists\n"); goto out; } input = g_file_read (file, NULL, &error); if (error != NULL){ g_warning ("get timezone list:read zone.tab error->%s", error->message); goto out; } data_input = g_data_input_stream_new ((GInputStream *) input); if (data_input == NULL) { g_warning ("get timezone list:get data input stream failed\n"); goto out; } char *data = (char *) 1; while (data) { data = g_data_input_stream_read_line (data_input, NULL, NULL, NULL); if (data == NULL) { break; } if (g_str_has_prefix (data, "#")){ g_debug ("get timezone list:comment line, just pass"); continue; } else { gchar **line = g_strsplit (data, "\t", -1); if (line == NULL) { g_warning ("get timezone list:split %s failed\n", data); } else { json_array_insert (timezones, index, jsvalue_from_cstr (get_global_context (), line[2])); index++; g_strfreev (line); } } } goto out; out: if (file != NULL) { g_object_unref (file); } if (data_input != NULL) { g_object_unref (data_input); } if (input != NULL) { g_object_unref (input); } if (error != NULL) { g_error_free (error); error = NULL; } UNGRAB_CTX (); return timezones; }