EAPI void efreet_desktop_category_add(Efreet_Desktop *desktop, const char *category) { EINA_SAFETY_ON_NULL_RETURN(desktop); EINA_SAFETY_ON_NULL_RETURN(category); if (eina_list_search_unsorted(desktop->categories, EINA_COMPARE_CB(strcmp), category)) return; desktop->categories = eina_list_append(desktop->categories, (void *)eina_stringshare_add(category)); }
/** * @param file: The file to get the Efreet_Desktop from * @return Returns a reference to a cached Efreet_Desktop on success, NULL * on failure. This reference should not be freed. * @brief Gets a reference to an Efreet_Desktop structure representing the * contents of @a file or NULL if @a file is not a valid .desktop file. * * By using efreet_desktop_get the Efreet_Desktop will be saved in an internal * cache, and changes will be signalled by events. * * Efreet will also try to save all files fetched by efreet_desktop_get in a * cache to speed up further requests. */ EAPI Efreet_Desktop * efreet_desktop_get(const char *file) { /* TODO: Check if we need to differentiate between desktop_new and desktop_get */ Efreet_Desktop *desktop; if (!file) return NULL; if (efreet_desktop_cache) { char rp[PATH_MAX]; if (!realpath(file, rp)) return NULL; desktop = eina_hash_find(efreet_desktop_cache, rp); if (desktop) { if (efreet_desktop_cache_check(desktop)) { desktop->ref++; return desktop; } desktop->cached = 0; eina_hash_del_by_key(efreet_desktop_cache, rp); } } desktop = efreet_desktop_new(file); if (!desktop) return NULL; if (!desktop->eet) { char buf[PATH_MAX]; char *p; /* * Read file from disk, save path in cache so it will be included in next * cache update */ strncpy(buf, desktop->orig_path, PATH_MAX); buf[PATH_MAX - 1] = '\0'; p = dirname(buf); if (!eina_list_search_unsorted(efreet_desktop_dirs, EINA_COMPARE_CB(strcmp), p)) efreet_desktop_dirs = eina_list_append(efreet_desktop_dirs, eina_stringshare_add(p)); efreet_desktop_update_cache(); } if (efreet_desktop_cache) eina_hash_add(efreet_desktop_cache, desktop->orig_path, desktop); desktop->cached = 1; return desktop; }
EAPI int efreet_desktop_category_del(Efreet_Desktop *desktop, const char *category) { char *found = NULL; if (!desktop || !desktop->categories) return 0; if ((found = eina_list_search_unsorted(desktop->categories, EINA_COMPARE_CB(strcmp), category))) { eina_stringshare_del(found); desktop->categories = eina_list_remove(desktop->categories, found); return 1; } return 0; }
/** * Find all desktop categories * This list must be freed using EINA_LIST_FREE * * @return an Eina_List of category names (const char *) */ EAPI Eina_List * efreet_util_desktop_categories_list(void) { char **keys; int num, i; Eina_List *ret = NULL; if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL; keys = eet_list(cache, "*::ca", &num); if (!keys) return NULL; for (i = 0; i < num; i++) { const char *data; int size; data = eet_read_direct(cache, keys[i], &size); if (!data) continue; if (eina_list_search_unsorted(ret, EINA_COMPARE_CB(strcmp), data)) continue; ret = eina_list_append(ret, data); } free(keys); return ret; }
static void _fill_list (Evasxx::Object *obj) { DIR *d; struct dirent *de; Eina_List *dirs = NULL, *l; char *real; if (!(d = opendir(getenv("HOME")))) return; while ((de = readdir(d)) != NULL) { char buff[PATH_MAX]; if (de->d_name[0] == '.') continue; snprintf(buff, sizeof(buff), "%s/%s", getenv("HOME"), de->d_name); if (!ecore_file_is_dir(buff)) continue; real = ecore_file_realpath(buff); dirs = eina_list_append(dirs, real); } closedir(d); dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll)); #if 0 EINA_LIST_FOREACH(dirs, l, real) { Eina_Bool result = EINA_FALSE; result = _dir_has_subs(real); if (!result) elm_genlist_item_append(obj, &itc, eina_stringshare_add(real), NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); else elm_genlist_item_append(obj, &itc, eina_stringshare_add(real), NULL, ELM_GENLIST_ITEM_TREE, NULL, NULL); free(real); }
int main(int argc, char **argv) { /* TODO: * - Add file monitor on files, so that we catch changes on files * during whilst this program runs. * - Maybe linger for a while to reduce number of cache re-creates. */ Efreet_Cache_Hash hash; Efreet_Cache_Version version; Eina_List *dirs = NULL; Eina_List *systemdirs = NULL; Eina_List *extra_dirs = NULL; Eina_List *l = NULL; Eina_Inarray *stack = NULL; int priority = 0; char *dir = NULL; char *path; int lockfd = -1, tmpfd; int changed = 0; int i; char file[PATH_MAX] = { '\0' }; char util_file[PATH_MAX] = { '\0' }; mode_t um; if (!eina_init()) goto eina_error; _efreet_desktop_cache_log_dom = eina_log_domain_register("efreet_desktop_cache", EFREET_DEFAULT_LOG_COLOR); if (_efreet_desktop_cache_log_dom < 0) { EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_desktop_cache."); return -1; } for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-v")) eina_log_domain_level_set("efreet_desktop_cache", EINA_LOG_LEVEL_DBG); else if ((!strcmp(argv[i], "-h")) || (!strcmp(argv[i], "-help")) || (!strcmp(argv[i], "--h")) || (!strcmp(argv[i], "--help"))) { printf("Options:\n"); printf(" -v Verbose mode\n"); printf(" -d dir1 dir2 Extra dirs\n"); exit(0); } else if (!strcmp(argv[i], "-d")) { while ((i < (argc - 1)) && (argv[(i + 1)][0] != '-')) extra_dirs = eina_list_append(extra_dirs, argv[++i]); } } extra_dirs = eina_list_sort(extra_dirs, -1, EINA_COMPARE_CB(strcmp)); #ifdef HAVE_SYS_RESOURCE_H setpriority(PRIO_PROCESS, 0, 19); #elif _WIN32 SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); #endif /* init external subsystems */ if (!eet_init()) goto eet_error; if (!ecore_init()) goto ecore_error; efreet_cache_update = 0; /* finish efreet init */ if (!efreet_init()) goto efreet_error; /* create homedir */ snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get()); if (!ecore_file_exists(file)) { if (!ecore_file_mkpath(file)) goto efreet_error; efreet_setowner(file); } /* lock process, so that we only run one copy of this program */ lockfd = cache_lock_file(); if (lockfd == -1) goto efreet_error; edd = efreet_desktop_edd(); if (!edd) goto edd_error; /* read user dirs from old cache */ ef = eet_open(efreet_desktop_util_cache_file(), EET_FILE_MODE_READ); if (ef) { old_file_ids = eet_data_read(ef, efreet_hash_string_edd(), "file_id"); eet_close(ef); } /* create cache */ snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file()); /* set secure umask for temporary files */ um = umask(0077); tmpfd = mkstemp(file); umask(um); if (tmpfd < 0) goto error; close(tmpfd); ef = eet_open(file, EET_FILE_MODE_READ_WRITE); if (!ef) goto error; snprintf(util_file, sizeof(util_file), "%s.XXXXXX", efreet_desktop_util_cache_file()); /* set secure umask for temporary files */ um = umask(0077); tmpfd = mkstemp(util_file); umask(um); if (tmpfd < 0) goto error; close(tmpfd); util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE); if (!util_ef) goto error; /* write cache version */ version.major = EFREET_DESKTOP_UTILS_CACHE_MAJOR; version.minor = EFREET_DESKTOP_UTILS_CACHE_MINOR; eet_data_write(util_ef, efreet_version_edd(), EFREET_CACHE_VERSION, &version, 1); version.major = EFREET_DESKTOP_CACHE_MAJOR; version.minor = EFREET_DESKTOP_CACHE_MINOR; eet_data_write(ef, efreet_version_edd(), EFREET_CACHE_VERSION, &version, 1); desktops = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_desktop_free)); file_ids = eina_hash_string_superfast_new(NULL); paths = eina_hash_string_superfast_new(NULL); mime_types = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free)); categories = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free)); startup_wm_class = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free)); name = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free)); generic_name = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free)); comment = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free)); exec = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free)); dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(), "applications"); if (!dirs) goto error; stack = eina_inarray_new(sizeof(struct stat), 16); if (!stack) goto error; EINA_LIST_FREE(dirs, path) { char file_id[PATH_MAX] = { '\0' }; eina_inarray_flush(stack); if (!cache_scan(stack, path, file_id, priority++, 1, &changed)) goto error; systemdirs = eina_list_append(systemdirs, path); }
int main(int argc, char ** argv) { int i, passed = 0, num_tests = 0; Eina_List *run = NULL; double total; char *env; eina_init(); ecore_init(); total = ecore_time_get(); if (argc > 1) { for (i = 1; i < argc; i++) { if ((!strcmp(argv[i], "-h")) || (!strcmp(argv[i], "--help"))) { for (i = 0; tests[i].name; i++) { printf("%s\n", tests[i].name); } return 1; } run = eina_list_append(run, argv[i]); } } environment_store(); for (i = 0; tests[i].name; i++) { int ret; double start; /* we've been given specific tests and it isn't in the list */ if (run && !eina_list_search_unsorted(run, EINA_COMPARE_CB(strcasecmp), tests[i].name)) continue; if (!efreet_init()) { printf("Error initializing Efreet\n"); continue; } num_tests ++; printf("%s:\t\t", tests[i].name); fflush(stdout); start = ecore_time_get(); ret = tests[i].cb(); printf("%s in %.3f seconds\n", (ret ? "PASSED" : "FAILED"), ecore_time_get() - start); passed += ret; efreet_shutdown(); environment_restore(); } printf("\n-----------------\n"); clearenv(); EINA_LIST_FREE(environment, env) free(env); printf("Passed %d of %d tests.\n", passed, num_tests); while (run) run = eina_list_remove_list(run, run); printf("Total run: %.3f seconds\n", ecore_time_get() - total); ecore_shutdown(); eina_shutdown(); return 0; }
int ef_cb_efreet_config_dirs(void) { Eina_List *tmp, *l; int ret = 1; unsigned int i; unsigned int ok; char dirs[128], *val; char *vals[] = {"/var/tmp/a", "/tmp/b", "/usr/local/share", "/etc", NULL}; char *def_vals[] = {"/etc/xdg", NULL}; dirs[0] = '\0'; for (i = 0; vals[i]; i++) { if (i > 0) strcat(dirs, ":"); strcat(dirs, vals[i]); } efreet_shutdown(); setenv("XDG_CONFIG_DIRS", dirs, 1); efreet_init(); ok = 0; tmp = efreet_config_dirs_get(); for (i = 0; vals[i]; i++) { char *found; found = eina_list_search_unsorted(tmp, EINA_COMPARE_CB(strcmp), vals[i]); if (!ecore_file_exists(vals[i]) && found) { printf("efreet_data_dirs_get() includes non-existing dir (%s) when " "%s set\n", vals[i], dirs); ret = 0; continue; } if (ecore_file_exists(vals[i]) && !found) { printf("efreet_data_dirs_get() is missing dir (%s) when " "%s set\n", vals[i], dirs); ret = 0; continue; } if (ecore_file_exists(vals[i]) && found) ok++; } if (eina_list_count(tmp) != ok) { printf("efreet_data_dirs_get() returned more values then it " "should have given %s as input\n", dirs); ret = 0; } efreet_shutdown(); unsetenv("XDG_CONFIG_DIRS"); efreet_init(); i = 0; tmp = efreet_config_dirs_get(); EINA_LIST_FOREACH(tmp, l, val) { if (!def_vals[i]) { printf("efreet_config_dirs_get() returned more values then it " "should have given %s as input\n", dirs); ret = 0; break; } if (strcmp(val, def_vals[i])) { printf("efreet_config_dirs_get() returned incorrect value (%s) when " "XDG_CONFIG_DIRS= is set\n", val); ret = 0; } i++; } return ret; }