2009-04-20 16:20:40 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2010-12-02 00:34:07 -08:00
|
|
|
/* TODO: move eet file handling to eet_cache.c */
|
2010-12-09 04:19:13 -08:00
|
|
|
/* TODO: add no_display check, as we might want only displayable items */
|
2011-01-31 03:32:34 -08:00
|
|
|
/* TODO: Keep data read from eet in mem for a while, to make subsequent searches faster, nice for exebuf */
|
2010-12-02 00:34:07 -08:00
|
|
|
|
2010-11-25 15:48:59 -08:00
|
|
|
#undef alloca
|
|
|
|
#ifdef HAVE_ALLOCA_H
|
|
|
|
# include <alloca.h>
|
|
|
|
#elif defined __GNUC__
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
#elif defined _AIX
|
|
|
|
# define alloca __alloca
|
|
|
|
#elif defined _MSC_VER
|
|
|
|
# include <malloc.h>
|
|
|
|
# define alloca _alloca
|
|
|
|
#else
|
|
|
|
# include <stddef.h>
|
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
# endif
|
|
|
|
void *alloca (size_t);
|
|
|
|
#endif
|
|
|
|
|
2009-04-20 16:20:40 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fnmatch.h>
|
2010-01-10 14:42:34 -08:00
|
|
|
#include <limits.h>
|
2009-04-20 16:20:40 -07:00
|
|
|
|
2010-11-26 09:05:16 -08:00
|
|
|
#include <Eet.h>
|
2010-11-25 15:52:57 -08:00
|
|
|
#include <Ecore_File.h>
|
|
|
|
|
2007-02-06 17:13:08 -08:00
|
|
|
#include "Efreet.h"
|
|
|
|
#include "efreet_private.h"
|
2010-12-02 00:34:07 -08:00
|
|
|
#include "efreet_cache_private.h"
|
2007-02-06 17:13:08 -08:00
|
|
|
|
2009-09-21 09:36:29 -07:00
|
|
|
/* define macros and variable for using the eina logging system */
|
|
|
|
|
2010-05-16 12:36:42 -07:00
|
|
|
#ifdef EFREET_MODULE_LOG_DOM
|
2009-09-21 09:36:29 -07:00
|
|
|
#undef EFREET_MODULE_LOG_DOM
|
|
|
|
#endif
|
|
|
|
#define EFREET_MODULE_LOG_DOM _efreet_utils_log_dom
|
|
|
|
static int _efreet_utils_log_dom = -1;
|
|
|
|
|
2007-11-04 01:32:35 -08:00
|
|
|
static char *efreet_util_path_in_default(const char *section, const char *path);
|
|
|
|
|
2007-04-04 01:48:29 -07:00
|
|
|
static int efreet_util_glob_match(const char *str, const char *glob);
|
2007-03-25 12:01:45 -07:00
|
|
|
|
2010-03-13 10:35:29 -08:00
|
|
|
static Eina_List *efreet_util_menus_find_helper(Eina_List *menus, const char *config_dir);
|
2007-04-04 03:09:20 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
static Efreet_Desktop *efreet_util_cache_find(const char *search, const char *what1, const char *what2);
|
|
|
|
static Eina_List *efreet_util_cache_list(const char *search, const char *what);
|
|
|
|
static Eina_List *efreet_util_cache_glob_list(const char *search, const char *what);
|
2007-06-03 11:07:23 -07:00
|
|
|
|
2008-12-17 07:33:43 -08:00
|
|
|
static Eina_Hash *file_id_by_desktop_path = NULL;
|
2010-03-13 10:34:30 -08:00
|
|
|
static const char *cache_file = NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
static Eet_File *cache = NULL;
|
2007-04-04 03:09:20 -07:00
|
|
|
|
2007-04-09 05:16:09 -07:00
|
|
|
static int init = 0;
|
|
|
|
|
2010-03-27 12:57:47 -07:00
|
|
|
int
|
2007-03-25 03:42:28 -07:00
|
|
|
efreet_util_init(void)
|
|
|
|
{
|
2007-04-09 05:16:09 -07:00
|
|
|
if (init++) return init;
|
2010-10-07 15:22:33 -07:00
|
|
|
_efreet_utils_log_dom = eina_log_domain_register
|
|
|
|
("efreet_util", EFREET_DEFAULT_LOG_COLOR);
|
2010-02-04 01:12:35 -08:00
|
|
|
if (_efreet_utils_log_dom < 0)
|
|
|
|
{
|
|
|
|
ERROR("Efreet: Could not create a log domain for efreet_util");
|
2010-03-25 22:33:12 -07:00
|
|
|
return 0;
|
2010-02-04 01:12:35 -08:00
|
|
|
}
|
2007-06-03 11:07:23 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
file_id_by_desktop_path = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
|
2007-03-25 05:47:59 -07:00
|
|
|
|
2007-04-09 05:16:09 -07:00
|
|
|
return init;
|
2007-03-25 03:42:28 -07:00
|
|
|
}
|
|
|
|
|
2010-03-27 12:57:47 -07:00
|
|
|
int
|
2007-03-25 03:42:28 -07:00
|
|
|
efreet_util_shutdown(void)
|
|
|
|
{
|
2007-04-09 05:16:09 -07:00
|
|
|
if (--init) return init;
|
2010-05-16 12:36:42 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
eina_log_domain_unregister(_efreet_utils_log_dom);
|
|
|
|
IF_FREE_HASH(file_id_by_desktop_path);
|
2010-12-02 00:34:07 -08:00
|
|
|
cache = efreet_cache_close(cache);
|
2010-03-13 10:34:30 -08:00
|
|
|
IF_RELEASE(cache_file);
|
2010-03-01 10:16:32 -08:00
|
|
|
return init;
|
|
|
|
}
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
/*
|
|
|
|
* Needs EAPI because of helper binaries
|
|
|
|
*/
|
|
|
|
EAPI const char *
|
2010-03-03 04:28:40 -08:00
|
|
|
efreet_desktop_util_cache_file(void)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
|
|
|
char tmp[PATH_MAX] = { '\0' };
|
2010-12-04 08:02:20 -08:00
|
|
|
const char *cache_dir, *lang, *country, *modifier;
|
2007-03-25 05:47:59 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
if (cache_file) return cache_file;
|
2007-04-04 03:09:20 -07:00
|
|
|
|
2010-12-04 08:02:20 -08:00
|
|
|
cache_dir = efreet_cache_home_get();
|
2010-03-01 10:16:32 -08:00
|
|
|
lang = efreet_lang_get();
|
|
|
|
country = efreet_lang_country_get();
|
|
|
|
modifier = efreet_lang_modifier_get();
|
2007-06-03 11:07:23 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
if (lang && country && modifier)
|
2010-12-04 08:02:20 -08:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s_%s@%s.eet", cache_dir, efreet_hostname_get(), lang, country, modifier);
|
2010-03-01 10:16:32 -08:00
|
|
|
else if (lang && country)
|
2010-12-04 08:02:20 -08:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s_%s.eet", cache_dir, efreet_hostname_get(), lang, country);
|
2010-03-01 10:16:32 -08:00
|
|
|
else if (lang)
|
2010-12-04 08:02:20 -08:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s.eet", cache_dir, efreet_hostname_get(), lang);
|
2010-03-01 10:16:32 -08:00
|
|
|
else
|
2010-12-04 08:02:20 -08:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s.eet", cache_dir, efreet_hostname_get());
|
2010-03-01 10:16:32 -08:00
|
|
|
|
2010-03-13 10:34:30 -08:00
|
|
|
cache_file = eina_stringshare_add(tmp);
|
2010-03-01 10:16:32 -08:00
|
|
|
return cache_file;
|
2007-03-25 03:42:28 -07:00
|
|
|
}
|
|
|
|
|
2007-11-04 01:32:35 -08:00
|
|
|
static char *
|
2007-02-06 17:13:08 -08:00
|
|
|
efreet_util_path_in_default(const char *section, const char *path)
|
|
|
|
{
|
2009-02-25 08:46:51 -08:00
|
|
|
Eina_List *dirs;
|
2007-02-06 18:14:46 -08:00
|
|
|
char *ret = NULL;
|
2007-02-06 17:13:08 -08:00
|
|
|
char *dir;
|
|
|
|
|
|
|
|
dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
|
2010-05-16 10:11:38 -07:00
|
|
|
section);
|
2007-02-06 17:13:08 -08:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FREE(dirs, dir)
|
2007-02-06 17:13:08 -08:00
|
|
|
{
|
|
|
|
if (!strncmp(path, dir, strlen(dir)))
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
ret = dir;
|
2010-03-01 10:16:32 -08:00
|
|
|
else
|
2010-03-29 13:14:43 -07:00
|
|
|
eina_stringshare_del(dir);
|
2007-02-06 17:13:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-06 18:14:46 -08:00
|
|
|
|
2007-11-04 02:16:02 -08:00
|
|
|
EAPI const char *
|
2007-03-25 03:49:04 -07:00
|
|
|
efreet_util_path_to_file_id(const char *path)
|
2007-02-06 18:14:46 -08:00
|
|
|
{
|
2010-04-03 09:26:03 -07:00
|
|
|
size_t len, len2;
|
2010-03-30 05:22:15 -07:00
|
|
|
char *tmp, *p;
|
2007-03-25 03:49:04 -07:00
|
|
|
char *base;
|
2010-03-01 10:16:32 -08:00
|
|
|
const char *file_id;
|
2007-03-25 03:49:04 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
/* TODO: Check if searching in cache is fast enough */
|
2010-05-16 12:36:42 -07:00
|
|
|
if (!path) return NULL;
|
2008-12-17 07:33:43 -08:00
|
|
|
file_id = eina_hash_find(file_id_by_desktop_path, path);
|
2007-03-25 05:47:59 -07:00
|
|
|
if (file_id) return file_id;
|
|
|
|
|
2007-03-25 03:49:04 -07:00
|
|
|
base = efreet_util_path_in_default("applications", path);
|
|
|
|
if (!base) return NULL;
|
2007-02-06 18:14:46 -08:00
|
|
|
|
|
|
|
len = strlen(base);
|
2007-03-25 03:49:04 -07:00
|
|
|
if (strlen(path) <= len)
|
|
|
|
{
|
2010-03-29 13:14:43 -07:00
|
|
|
eina_stringshare_del(base);
|
2007-03-25 03:49:04 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (strncmp(path, base, len))
|
|
|
|
{
|
2010-03-29 13:14:43 -07:00
|
|
|
eina_stringshare_del(base);
|
2007-03-25 03:49:04 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-02-06 18:14:46 -08:00
|
|
|
|
2010-04-03 09:26:03 -07:00
|
|
|
len2 = strlen(path + len + 1) + 1;
|
|
|
|
tmp = alloca(len2);
|
|
|
|
memcpy(tmp, path + len + 1, len2);
|
2007-03-25 06:10:09 -07:00
|
|
|
p = tmp;
|
2007-02-06 18:14:46 -08:00
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (*p == '/') *p = '-';
|
|
|
|
p++;
|
|
|
|
}
|
2010-03-29 13:14:43 -07:00
|
|
|
eina_stringshare_del(base);
|
2008-10-15 07:48:03 -07:00
|
|
|
file_id = eina_stringshare_add(tmp);
|
2008-12-17 07:33:43 -08:00
|
|
|
eina_hash_add(file_id_by_desktop_path, path, (void *)file_id);
|
2007-03-25 05:47:59 -07:00
|
|
|
return file_id;
|
2007-02-06 18:14:46 -08:00
|
|
|
}
|
2007-03-24 14:59:34 -07:00
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find all desktops for a given mime type
|
|
|
|
*
|
|
|
|
* This list must be freed using EINA_LIST_FREE / efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param mime the mime type
|
|
|
|
* @return a list of desktops
|
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EAPI Eina_List *
|
2007-03-25 11:17:34 -07:00
|
|
|
efreet_util_desktop_mime_list(const char *mime)
|
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
return efreet_util_cache_list("mime_types", mime);
|
2007-03-25 11:17:34 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find all desktops for a given wm class
|
|
|
|
*
|
|
|
|
* This list must be freed using EINA_LIST_FREE / efreet_desktop_free
|
|
|
|
*
|
2011-01-27 09:43:27 -08:00
|
|
|
* @param wmname the wm name
|
2010-03-25 22:33:37 -07:00
|
|
|
* @param wmclass the wm class
|
|
|
|
* @return a list of desktops
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI Efreet_Desktop *
|
2007-03-25 09:17:19 -07:00
|
|
|
efreet_util_desktop_wm_class_find(const char *wmname, const char *wmclass)
|
2007-03-25 08:52:18 -07:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
return efreet_util_cache_find("startup_wm_class", wmname, wmclass);
|
2007-03-25 08:52:18 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find a desktop by file id
|
|
|
|
*
|
|
|
|
* return value must be freed by efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param file_id the file id
|
|
|
|
* @return a desktop
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI Efreet_Desktop *
|
2007-03-25 05:57:49 -07:00
|
|
|
efreet_util_desktop_file_id_find(const char *file_id)
|
2007-03-24 14:59:34 -07:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Hash *hash;
|
|
|
|
Efreet_Desktop *ret = NULL;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
if (!file_id) return NULL;
|
|
|
|
if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL;
|
|
|
|
|
|
|
|
hash = eet_data_read(cache, efreet_hash_string_edd(), "file_id");
|
|
|
|
if (!hash) return NULL;
|
|
|
|
str = eina_hash_find(hash->hash, file_id);
|
|
|
|
if (str)
|
|
|
|
ret = efreet_desktop_get(str);
|
|
|
|
eina_hash_free(hash->hash);
|
|
|
|
free(hash);
|
|
|
|
return ret;
|
2007-03-24 14:59:34 -07:00
|
|
|
}
|
2007-03-25 05:47:59 -07:00
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find a desktop by exec
|
|
|
|
*
|
|
|
|
* return value must be freed by efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param exec the exec name
|
|
|
|
* @return a desktop
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI Efreet_Desktop *
|
2007-03-25 05:57:49 -07:00
|
|
|
efreet_util_desktop_exec_find(const char *exec)
|
2007-03-25 05:47:59 -07:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Hash *hash;
|
2010-03-01 10:16:32 -08:00
|
|
|
Efreet_Desktop *ret = NULL;
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Array_String *names = NULL;
|
|
|
|
unsigned int i;
|
2007-03-25 05:47:59 -07:00
|
|
|
|
2010-12-02 00:34:07 -08:00
|
|
|
if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL;
|
2007-03-25 05:47:59 -07:00
|
|
|
if (!exec) return NULL;
|
2008-12-17 07:33:43 -08:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
names = eet_data_read(cache, efreet_array_string_edd(), "exec_list");
|
|
|
|
if (!names) goto error;
|
|
|
|
for (i = 0; i < names->array_count; i++)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
const char *file;
|
2010-03-01 10:16:32 -08:00
|
|
|
char *exe;
|
2011-01-31 03:32:34 -08:00
|
|
|
unsigned int j;
|
|
|
|
Efreet_Cache_Array_String *array;
|
2010-03-01 10:16:32 -08:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
exe = ecore_file_app_exe_get(names->array[i]);
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!exe) continue;
|
|
|
|
file = ecore_file_file_get(exe);
|
|
|
|
if (!file) continue;
|
|
|
|
if (strcmp(exec, exe) && strcmp(exec, file))
|
|
|
|
{
|
|
|
|
free(exe);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
free(exe);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
if (!hash)
|
|
|
|
hash = eet_data_read(cache, efreet_hash_array_string_edd(), "exec_hash");
|
|
|
|
if (!hash) goto error;
|
|
|
|
array = eina_hash_find(hash->hash, names->array[i]);
|
|
|
|
if (!array) continue;
|
|
|
|
for (j = 0; j < array->array_count; j++)
|
|
|
|
{
|
|
|
|
ret = efreet_desktop_get(array->array[j]);
|
|
|
|
if (ret) break;
|
|
|
|
}
|
2010-03-01 10:16:32 -08:00
|
|
|
if (ret) break;
|
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
error:
|
|
|
|
if (hash)
|
|
|
|
{
|
|
|
|
eina_hash_free(hash->hash);
|
|
|
|
free(hash);
|
|
|
|
}
|
|
|
|
if (names)
|
|
|
|
efreet_cache_array_string_free(names);
|
2010-03-01 10:16:32 -08:00
|
|
|
return ret;
|
2007-03-25 06:43:52 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find a desktop by name
|
|
|
|
*
|
|
|
|
* return value must be freed by efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param name the name
|
|
|
|
* @return a desktop
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI Efreet_Desktop *
|
2007-03-25 06:43:52 -07:00
|
|
|
efreet_util_desktop_name_find(const char *name)
|
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
return efreet_util_cache_find("name", name, NULL);
|
2007-03-25 06:43:52 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find a desktop by generic name
|
|
|
|
*
|
|
|
|
* return value must be freed by efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param generic_name the generic name
|
|
|
|
* @return a desktop
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI Efreet_Desktop *
|
2007-03-25 06:43:52 -07:00
|
|
|
efreet_util_desktop_generic_name_find(const char *generic_name)
|
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
return efreet_util_cache_find("generic_name", generic_name, NULL);
|
2007-03-25 05:47:59 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find all desktops where name matches a glob pattern
|
|
|
|
*
|
|
|
|
* This list must be freed using EINA_LIST_FREE / efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param glob the pattern to match
|
|
|
|
* @return a list of desktops
|
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EAPI Eina_List *
|
2007-03-25 12:01:45 -07:00
|
|
|
efreet_util_desktop_name_glob_list(const char *glob)
|
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
return efreet_util_cache_glob_list("name", glob);
|
2007-03-25 12:01:45 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find all desktops where exec matches a glob pattern
|
|
|
|
*
|
|
|
|
* This list must be freed using EINA_LIST_FREE / efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param glob the pattern to match
|
|
|
|
* @return a list of desktops
|
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EAPI Eina_List *
|
2007-03-25 12:01:45 -07:00
|
|
|
efreet_util_desktop_exec_glob_list(const char *glob)
|
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Hash *hash = NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
Eina_List *ret = NULL;
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Array_String *names = NULL;
|
|
|
|
unsigned int i;
|
2007-03-25 12:01:45 -07:00
|
|
|
|
2010-12-02 00:34:07 -08:00
|
|
|
if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!glob) return NULL;
|
2007-03-25 12:01:45 -07:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
names = eet_data_read(cache, efreet_array_string_edd(), "exec_list");
|
|
|
|
if (!names) goto error;
|
|
|
|
for (i = 0; i < names->array_count; i++)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Array_String *array;
|
|
|
|
unsigned int j;
|
2010-03-01 10:16:32 -08:00
|
|
|
char *exe;
|
|
|
|
Efreet_Desktop *desk;
|
2007-03-25 12:01:45 -07:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
exe = ecore_file_app_exe_get(names->array[i]);
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!exe) continue;
|
|
|
|
if (!efreet_util_glob_match(exe, glob))
|
|
|
|
{
|
|
|
|
free(exe);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
free(exe);
|
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
if (!hash)
|
|
|
|
hash = eet_data_read(cache, efreet_hash_array_string_edd(), "exec_hash");
|
|
|
|
if (!hash) goto error;
|
|
|
|
|
|
|
|
array = eina_hash_find(hash->hash, names->array[i]);
|
|
|
|
if (!array) continue;
|
|
|
|
for (j = 0; j < array->array_count; j++)
|
|
|
|
{
|
|
|
|
desk = efreet_desktop_get(array->array[j]);
|
|
|
|
if (desk)
|
|
|
|
ret = eina_list_append(ret, desk);
|
|
|
|
}
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
error:
|
|
|
|
if (hash)
|
|
|
|
{
|
|
|
|
eina_hash_free(hash->hash);
|
|
|
|
free(hash);
|
|
|
|
}
|
|
|
|
if (names)
|
|
|
|
efreet_cache_array_string_free(names);
|
2010-03-01 10:16:32 -08:00
|
|
|
return ret;
|
2007-03-25 12:01:45 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find all desktops where generic name matches a glob pattern
|
|
|
|
*
|
|
|
|
* This list must be freed using EINA_LIST_FREE / efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param glob the pattern to match
|
|
|
|
* @return a list of desktops
|
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EAPI Eina_List *
|
2007-03-25 12:01:45 -07:00
|
|
|
efreet_util_desktop_generic_name_glob_list(const char *glob)
|
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
return efreet_util_cache_glob_list("generic_name", glob);
|
2007-03-25 12:01:45 -07:00
|
|
|
}
|
|
|
|
|
2010-03-25 22:33:37 -07:00
|
|
|
/**
|
|
|
|
* Find all desktops where comment matches a glob pattern
|
|
|
|
*
|
|
|
|
* This list must be freed using EINA_LIST_FREE / efreet_desktop_free
|
|
|
|
*
|
|
|
|
* @param glob the pattern to match
|
|
|
|
* @return a list of desktops
|
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EAPI Eina_List *
|
2007-03-25 12:01:45 -07:00
|
|
|
efreet_util_desktop_comment_glob_list(const char *glob)
|
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
return efreet_util_cache_glob_list("comment", glob);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
}
|
|
|
|
|
2007-04-15 00:24:03 -07:00
|
|
|
/**
|
|
|
|
* Find all desktop categories
|
2009-03-26 10:54:50 -07:00
|
|
|
* This list must be freed using EINA_LIST_FREE
|
2007-04-15 00:24:03 -07:00
|
|
|
*
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
* @return an Eina_List of category names (const char *)
|
2007-04-15 00:24:03 -07:00
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EAPI Eina_List *
|
2007-06-27 03:57:54 -07:00
|
|
|
efreet_util_desktop_categories_list(void)
|
2007-04-15 00:24:03 -07:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Array_String *array;
|
2010-03-01 10:16:32 -08:00
|
|
|
Eina_List *ret = NULL;
|
2011-01-31 03:32:34 -08:00
|
|
|
unsigned int i;
|
2010-02-04 01:12:35 -08:00
|
|
|
|
2010-12-02 00:34:07 -08:00
|
|
|
if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL;
|
2010-02-04 01:12:35 -08:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
array = eet_data_read(cache, efreet_array_string_edd(), "categories_list");
|
|
|
|
if (!array) return NULL;
|
|
|
|
for (i = 0; i < array->array_count; i++)
|
|
|
|
ret = eina_list_append(ret, array->array[i]);
|
|
|
|
efreet_cache_array_string_free(array);
|
2010-03-01 10:16:32 -08:00
|
|
|
return ret;
|
2007-04-15 00:24:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find all desktops in a given category
|
2007-06-06 18:22:48 -07:00
|
|
|
*
|
2010-03-25 22:33:37 -07:00
|
|
|
* This list must be freed using EINA_LIST_FREE / efreet_desktop_free
|
|
|
|
*
|
2007-04-15 00:24:03 -07:00
|
|
|
* @param category the category name
|
|
|
|
* @return a list of desktops
|
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EAPI Eina_List *
|
2007-04-15 00:24:03 -07:00
|
|
|
efreet_util_desktop_category_list(const char *category)
|
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
return efreet_util_cache_list("categories", category);
|
2007-03-25 12:01:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-04-04 01:48:29 -07:00
|
|
|
efreet_util_glob_match(const char *str, const char *glob)
|
2007-03-25 12:01:45 -07:00
|
|
|
{
|
|
|
|
if (!str || !glob)
|
|
|
|
return 0;
|
2007-04-04 05:00:40 -07:00
|
|
|
if (glob[0] == '\0')
|
2007-03-25 12:01:45 -07:00
|
|
|
{
|
2007-04-04 05:00:40 -07:00
|
|
|
if (str[0] == '\0') return 1;
|
2007-03-25 12:01:45 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!strcmp(glob, "*")) return 1;
|
|
|
|
if (!fnmatch(glob, str, 0)) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-04-04 03:09:20 -07:00
|
|
|
|
2007-04-14 23:16:54 -07:00
|
|
|
/**
|
|
|
|
* Returns a list of .menu files found in the various config dirs.
|
2009-03-26 10:54:50 -07:00
|
|
|
* @return An eina list of menu file paths (const char *). This must be freed with EINA_LIST_FREE.
|
2007-04-14 23:16:54 -07:00
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EAPI Eina_List *
|
2007-06-27 03:57:54 -07:00
|
|
|
efreet_util_menus_find(void)
|
2007-04-14 23:16:54 -07:00
|
|
|
{
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *menus = NULL;
|
|
|
|
Eina_List *dirs, *l;
|
2007-04-14 23:16:54 -07:00
|
|
|
const char *dir;
|
|
|
|
|
2010-03-13 10:35:29 -08:00
|
|
|
menus = efreet_util_menus_find_helper(menus, efreet_config_home_get());
|
2007-04-14 23:16:54 -07:00
|
|
|
|
|
|
|
dirs = efreet_config_dirs_get();
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(dirs, l, dir)
|
2010-03-13 10:35:29 -08:00
|
|
|
menus = efreet_util_menus_find_helper(menus, dir);
|
2007-04-14 23:16:54 -07:00
|
|
|
|
|
|
|
return menus;
|
|
|
|
}
|
|
|
|
|
2010-03-13 10:35:29 -08:00
|
|
|
static Eina_List *
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
efreet_util_menus_find_helper(Eina_List *menus, const char *config_dir)
|
2007-04-14 23:16:54 -07:00
|
|
|
{
|
|
|
|
DIR *files = NULL;
|
|
|
|
struct dirent *file = NULL;
|
|
|
|
char dbuf[PATH_MAX], fbuf[PATH_MAX];
|
|
|
|
|
|
|
|
snprintf(dbuf, sizeof(dbuf), "%s/menus", config_dir);
|
|
|
|
files = opendir(dbuf);
|
2010-03-13 10:35:29 -08:00
|
|
|
if (!files) return menus;
|
2007-04-14 23:16:54 -07:00
|
|
|
while ((file = readdir(files))) {
|
|
|
|
const char *exten;
|
|
|
|
exten = strrchr(file->d_name, '.');
|
|
|
|
if (!exten) continue;
|
|
|
|
if (strcmp(".menu", exten)) continue;
|
|
|
|
|
2009-12-23 12:55:23 -08:00
|
|
|
snprintf(fbuf, sizeof(fbuf), "%s/%s", dbuf, file->d_name);
|
2007-04-14 23:16:54 -07:00
|
|
|
if (ecore_file_is_dir(fbuf)) continue;
|
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
menus = eina_list_append(menus, strdup(fbuf));
|
2007-04-14 23:16:54 -07:00
|
|
|
}
|
|
|
|
closedir(files);
|
2010-03-13 10:35:29 -08:00
|
|
|
return menus;
|
2007-04-14 23:16:54 -07:00
|
|
|
}
|
2007-06-03 11:07:23 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
static Efreet_Desktop *
|
|
|
|
efreet_util_cache_find(const char *search, const char *what1, const char *what2)
|
2007-06-03 11:07:23 -07:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Hash *hash;
|
2010-03-01 10:16:32 -08:00
|
|
|
Efreet_Desktop *ret = NULL;
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Array_String *array = NULL;
|
|
|
|
char key[256];
|
2010-02-04 01:12:35 -08:00
|
|
|
|
2010-12-02 00:34:07 -08:00
|
|
|
if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
if ((!what1) && (!what2)) return NULL;
|
2010-02-04 01:12:35 -08:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
snprintf(key, sizeof(key), "%s_hash", search);
|
|
|
|
hash = eet_data_read(cache, efreet_hash_array_string_edd(), key);
|
|
|
|
if (!hash) return NULL;
|
|
|
|
if (what1)
|
|
|
|
array = eina_hash_find(hash->hash, what1);
|
|
|
|
if (!array && what2) array = eina_hash_find(hash->hash, what2);
|
|
|
|
if (array)
|
2010-02-04 01:12:35 -08:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < array->array_count; i++)
|
|
|
|
{
|
|
|
|
ret = efreet_desktop_get(array->array[i]);
|
|
|
|
if (ret) break;
|
|
|
|
}
|
2010-02-04 01:12:35 -08:00
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
eina_hash_free(hash->hash);
|
|
|
|
free(hash);
|
2010-03-01 10:16:32 -08:00
|
|
|
return ret;
|
2007-06-03 11:07:23 -07:00
|
|
|
}
|
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
static Eina_List *
|
|
|
|
efreet_util_cache_list(const char *search, const char *what)
|
2007-06-03 11:07:23 -07:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Hash *hash;
|
|
|
|
Efreet_Cache_Array_String *array;
|
2010-03-01 10:16:32 -08:00
|
|
|
Eina_List *ret = NULL;
|
2011-01-31 03:32:34 -08:00
|
|
|
char key[256];
|
2010-02-04 01:12:35 -08:00
|
|
|
|
2010-12-02 00:34:07 -08:00
|
|
|
if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!what) return NULL;
|
2010-02-04 01:12:35 -08:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
snprintf(key, sizeof(key), "%s_hash", search);
|
|
|
|
hash = eet_data_read(cache, efreet_hash_array_string_edd(), key);
|
|
|
|
if (!hash) return NULL;
|
|
|
|
array = eina_hash_find(hash->hash, what);
|
|
|
|
if (array)
|
2010-02-04 01:12:35 -08:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
unsigned int i;
|
2010-03-01 10:16:32 -08:00
|
|
|
Efreet_Desktop *desk;
|
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
for (i = 0; i < array->array_count; i++)
|
|
|
|
{
|
|
|
|
desk = efreet_desktop_get(array->array[i]);
|
|
|
|
if (desk)
|
|
|
|
ret = eina_list_append(ret, desk);
|
|
|
|
}
|
2010-02-04 01:12:35 -08:00
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
eina_hash_free(hash->hash);
|
|
|
|
free(hash);
|
2010-03-01 10:16:32 -08:00
|
|
|
return ret;
|
2007-06-03 11:07:23 -07:00
|
|
|
}
|
2007-07-26 03:20:24 -07:00
|
|
|
|
2010-03-01 10:16:32 -08:00
|
|
|
static Eina_List *
|
|
|
|
efreet_util_cache_glob_list(const char *search, const char *what)
|
2007-07-26 03:20:24 -07:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Hash *hash = NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
Eina_List *ret = NULL;
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Array_String *names = NULL;
|
|
|
|
char key[256];
|
|
|
|
unsigned int i;
|
2007-07-26 03:20:24 -07:00
|
|
|
|
2010-12-02 00:34:07 -08:00
|
|
|
if (!efreet_cache_check(&cache, efreet_desktop_util_cache_file(), EFREET_DESKTOP_UTILS_CACHE_MAJOR)) return NULL;
|
2010-03-01 10:16:32 -08:00
|
|
|
if (!what) return NULL;
|
2007-07-26 15:04:16 -07:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
snprintf(key, sizeof(key), "%s_list", search);
|
|
|
|
names = eet_data_read(cache, efreet_array_string_edd(), key);
|
|
|
|
if (!names) goto error;
|
|
|
|
for (i = 0; i < names->array_count; i++)
|
2010-03-01 10:16:32 -08:00
|
|
|
{
|
2011-01-31 03:32:34 -08:00
|
|
|
Efreet_Cache_Array_String *array;
|
|
|
|
unsigned int j;
|
2010-03-01 10:16:32 -08:00
|
|
|
Efreet_Desktop *desk;
|
2007-07-26 15:04:16 -07:00
|
|
|
|
2011-01-31 03:32:34 -08:00
|
|
|
if (!efreet_util_glob_match(names->array[i], what)) continue;
|
|
|
|
|
|
|
|
if (!hash)
|
|
|
|
{
|
|
|
|
snprintf(key, sizeof(key), "%s_hash", search);
|
|
|
|
hash = eet_data_read(cache, efreet_hash_array_string_edd(), key);
|
|
|
|
}
|
|
|
|
if (!hash) goto error;
|
|
|
|
|
|
|
|
array = eina_hash_find(hash->hash, names->array[i]);
|
|
|
|
if (!array) continue;
|
|
|
|
for (j = 0; j < array->array_count; j++)
|
|
|
|
{
|
|
|
|
desk = efreet_desktop_get(array->array[j]);
|
|
|
|
if (desk)
|
|
|
|
ret = eina_list_append(ret, desk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error:
|
|
|
|
if (hash)
|
|
|
|
{
|
|
|
|
eina_hash_free(hash->hash);
|
|
|
|
free(hash);
|
2010-03-01 10:16:32 -08:00
|
|
|
}
|
2011-01-31 03:32:34 -08:00
|
|
|
if (names)
|
|
|
|
efreet_cache_array_string_free(names);
|
2010-03-01 10:16:32 -08:00
|
|
|
return ret;
|
2007-07-26 15:04:16 -07:00
|
|
|
}
|
2010-03-25 22:33:12 -07:00
|
|
|
|
2010-03-27 12:58:33 -07:00
|
|
|
void
|
2010-03-27 12:58:54 -07:00
|
|
|
efreet_util_desktop_cache_reload(void)
|
2010-03-25 22:33:12 -07:00
|
|
|
{
|
2010-12-02 00:34:07 -08:00
|
|
|
cache = efreet_cache_close(cache);
|
2010-03-25 22:33:12 -07:00
|
|
|
}
|
2010-12-08 13:39:43 -08:00
|
|
|
|
|
|
|
EAPI void
|
|
|
|
efreet_hash_free(Eina_Hash *hash, Eina_Free_Cb free_cb)
|
|
|
|
{
|
|
|
|
Eina_Iterator *it;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
it = eina_hash_iterator_data_new(hash);
|
|
|
|
EINA_ITERATOR_FOREACH(it, data)
|
|
|
|
(*free_cb)(data);
|
|
|
|
eina_iterator_free(it);
|
|
|
|
eina_hash_free(hash);
|
|
|
|
}
|
|
|
|
|