void install_monitor() { if (_inotify_fd == -1) { _inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC); _monitor_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)g_object_unref); g_timeout_add(50, (GSourceFunc)_inotify_poll, NULL); _desktop_file = g_file_new_for_commandline_arg(DESKTOP_DIR()); _trash_can = g_file_new_for_uri("trash:///"); GFileMonitor* m = g_file_monitor(_trash_can, G_FILE_MONITOR_NONE, NULL, NULL); g_signal_connect(m, "changed", G_CALLBACK(trash_changed), NULL); _add_monitor_directory(_desktop_file); GDir *dir = g_dir_open(DESKTOP_DIR(), 0, NULL); if (dir != NULL) { const char* filename = NULL; while ((filename = g_dir_read_name(dir)) != NULL) { GFile* f = g_file_get_child(_desktop_file, filename); _add_monitor_directory(f); g_object_unref(f); } g_dir_close(dir); } } }
void desktop_run_in_terminal(char* executable) { gboolean is_ok = FALSE; GSettings* s = g_settings_new("com.deepin.desktop.default-applications.terminal"); if (s != NULL) { char* terminal = g_settings_get_string(s, "exec"); g_object_unref(s); if (terminal != NULL && terminal[0] != '\0') { char* quoted_dir = g_shell_quote(DESKTOP_DIR()); char* exec = NULL; exec = g_strdup_printf("sh -c 'cd %s && %s'", quoted_dir, terminal); g_free(quoted_dir); g_free(terminal); is_ok = exec_app_info(exec, G_APP_INFO_CREATE_NONE); g_free(exec); if (!is_ok) { g_debug("exec app info failed!"); } return; } g_free(terminal); } is_ok = exec_app_info (executable, G_APP_INFO_CREATE_NEEDS_TERMINAL); if ( !is_ok ) { g_debug ("exec app info failed!"); /*exec_app_info (executable);*/ } return; }
GAppInfo *gen_app_info (const char* executable, GAppInfoCreateFlags flags) { GAppInfo *appinfo = NULL; GError* error = NULL; char* cmd_line = NULL; if (executable == NULL) { char* tmp1 = g_shell_quote(DESKTOP_DIR()); char* tmp2 = g_strdup_printf("cd %s && exec $SHELL", tmp1); g_free(tmp1); tmp1 = g_shell_quote(tmp2); g_free(tmp2); cmd_line = g_strconcat("sh -c ", tmp1, NULL); g_free(tmp1); } else { cmd_line = g_strdup(executable); } appinfo = g_app_info_create_from_commandline(cmd_line, NULL, flags, &error); g_free(cmd_line); if (error!=NULL) { g_debug("gen_app_info error: %s", error->message); g_error_free(error); return NULL; } error = NULL; return appinfo; }
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; }
GFile* _get_useable_file_templates(const char* basename,const char* name_add_before) { GFile* dir = g_file_new_for_path(DESKTOP_DIR()); char* name = g_strdup(basename); GFile* child = g_file_get_child(dir, name); for (int i=0; g_file_query_exists(child, NULL); i++) { g_object_unref(child); g_free(name); name = g_strdup_printf("%s(%d)%s",name_add_before, i,basename); child = g_file_get_child(dir, name); } g_object_unref(dir); return child; }
JS_EXPORT_API Entry* dentry_get_desktop() { return dentry_create_by_path(DESKTOP_DIR()); }
JS_EXPORT_API void guide_copy_file_to_desktop(const char* src) { const char* cmd = g_strdup_printf("cp %s %s/",src,DESKTOP_DIR()); guide_spawn_command_sync(cmd,true); }
JS_EXPORT_API const char* desktop_get_desktop_path() { return DESKTOP_DIR(); }