JS_EXPORT_API char* desktop_get_rich_dir_icon(GFile* _dir) { char* icons[4] = {NULL, NULL, NULL, NULL}; char* bad_icons[4] = {NULL, NULL, NULL, NULL}; char* dir_path = g_file_get_path(_dir); GDir* dir = g_dir_open(dir_path, 0, NULL); const char* child_name = NULL; int i=0, j=0; for (; NULL != (child_name = g_dir_read_name(dir));) { if (g_str_has_suffix(child_name, ".desktop")) { char* path = g_build_filename(dir_path, child_name, NULL); Entry* entry = dentry_create_by_path(path); char* icon_path = dentry_get_icon_path(entry); if (icon_path == NULL) { g_warning("richdir dentry %d get_icon is null use %s.png instead",i,APP_DEFAULT_ICON); icon_path = dcore_get_theme_icon(APP_DEFAULT_ICON, 48); g_debug("icon_path %d :---%s---",i,icon_path); } icons[i++] = icon_path; g_object_unref(entry); g_free(path); } else if (j<4) { char* path = g_build_filename(dir_path, child_name, NULL); Entry* entry = dentry_create_by_path(path); bad_icons[j++] = dentry_get_icon_path(entry); g_object_unref(entry); g_free(path); } if (i >= 4) break; } g_dir_close(dir); g_free(dir_path); char* ret = generate_directory_icon( icons[0] ? icons[0] : bad_icons[0], icons[1] ? icons[1] : bad_icons[1], icons[2] ? icons[2] : bad_icons[2], icons[3] ? icons[3] : bad_icons[3]); for (int i=0; i<4; i++) { g_free(icons[i]); g_free(bad_icons[i]); } return ret; }
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); } }
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); }
JS_EXPORT_API JSObjectRef desktop_get_desktop_entries() { JSObjectRef array = json_array_create(); GDir* dir = g_dir_open(DESKTOP_DIR(), 0, NULL); const char* file_name = NULL; for (int i=0; NULL != (file_name = g_dir_read_name(dir));) { if(desktop_file_filter(file_name)) continue; char* path = g_build_filename(DESKTOP_DIR(), file_name, NULL); Entry* e = dentry_create_by_path(path); g_free(path); json_array_insert_nobject(array, i++, e, g_object_ref, g_object_unref); g_object_unref(e); } g_dir_close(dir); return array; }
JS_EXPORT_API Entry* dentry_get_desktop() { return dentry_create_by_path(DESKTOP_DIR()); }