forked from enlightenment/efl
parent
a65d40c050
commit
343a6d9ab2
|
@ -63,6 +63,7 @@ struct _Ecore_Desktop
|
||||||
unsigned char hidden : 1;
|
unsigned char hidden : 1;
|
||||||
unsigned char no_display : 1;
|
unsigned char no_display : 1;
|
||||||
unsigned char allocated : 1;
|
unsigned char allocated : 1;
|
||||||
|
unsigned char ondisk : 1;
|
||||||
/* Actually calling this st_mtime causes compile issues, must be some strange macros at work. */
|
/* Actually calling this st_mtime causes compile issues, must be some strange macros at work. */
|
||||||
time_t mtime; /* For checking if the cache is valid. */
|
time_t mtime; /* For checking if the cache is valid. */
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,10 +20,12 @@ extern int reject_count, not_over_count;
|
||||||
|
|
||||||
static int init_count = 0;
|
static int init_count = 0;
|
||||||
|
|
||||||
static Ecore_Hash *ini_file_cache;
|
|
||||||
static Ecore_Hash *desktop_cache;
|
static Ecore_Hash *desktop_cache;
|
||||||
|
|
||||||
|
Ecore_Desktop *_ecore_desktop_get(const char *file, const char *lang);
|
||||||
void _ecore_desktop_destroy(Ecore_Desktop * desktop);
|
void _ecore_desktop_destroy(Ecore_Desktop * desktop);
|
||||||
|
#define IFGETDUP(src, key, dst) src = (char *)ecore_hash_get(result->group, key); if (src) dst = strdup(src); else dst = NULL;
|
||||||
|
#define IFFREE(src) if (src) free(src); src = NULL;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +53,6 @@ ecore_desktop_ini_get(const char *file)
|
||||||
{
|
{
|
||||||
Ecore_Hash *result;
|
Ecore_Hash *result;
|
||||||
|
|
||||||
/* FIXME: should probably look in ini_file_cache first. */
|
|
||||||
result = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
result = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
@ -145,7 +146,6 @@ ecore_desktop_ini_get(const char *file)
|
||||||
buffer[0] = (char)0;
|
buffer[0] = (char)0;
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
ecore_hash_set(ini_file_cache, strdup(file), result);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -153,12 +153,6 @@ ecore_desktop_ini_get(const char *file)
|
||||||
/**
|
/**
|
||||||
* Get the contents of a .desktop file.
|
* Get the contents of a .desktop file.
|
||||||
*
|
*
|
||||||
* Everything that is in the .desktop file is returned in the
|
|
||||||
* data member of the Ecore_Desktop structure, it's an Ecore_Hash
|
|
||||||
* as returned by ecore_desktop_ini_get(). Some of the data in the
|
|
||||||
* .desktop file is decoded into specific members of the returned
|
|
||||||
* structure.
|
|
||||||
*
|
|
||||||
* Use ecore_desktop_destroy() to free this structure.
|
* Use ecore_desktop_destroy() to free this structure.
|
||||||
*
|
*
|
||||||
* @param file Full path to the .desktop file.
|
* @param file Full path to the .desktop file.
|
||||||
|
@ -168,9 +162,30 @@ ecore_desktop_ini_get(const char *file)
|
||||||
*/
|
*/
|
||||||
Ecore_Desktop *
|
Ecore_Desktop *
|
||||||
ecore_desktop_get(const char *file, const char *lang)
|
ecore_desktop_get(const char *file, const char *lang)
|
||||||
|
{
|
||||||
|
Ecore_Desktop *result;
|
||||||
|
|
||||||
|
result = _ecore_desktop_get(file, lang);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
/* Kill the hash, it takes up way too much memory. */
|
||||||
|
if (result->data)
|
||||||
|
{
|
||||||
|
ecore_hash_destroy(result->data);
|
||||||
|
result->data = NULL;
|
||||||
|
}
|
||||||
|
result->group = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ecore_Desktop *
|
||||||
|
_ecore_desktop_get(const char *file, const char *lang)
|
||||||
{
|
{
|
||||||
Ecore_Desktop *result;
|
Ecore_Desktop *result;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
char *value;
|
||||||
int stated = 0;
|
int stated = 0;
|
||||||
|
|
||||||
result = (Ecore_Desktop *) ecore_hash_get(desktop_cache, (char *) file);
|
result = (Ecore_Desktop *) ecore_hash_get(desktop_cache, (char *) file);
|
||||||
|
@ -192,6 +207,7 @@ ecore_desktop_get(const char *file, const char *lang)
|
||||||
result = calloc(1, sizeof(Ecore_Desktop));
|
result = calloc(1, sizeof(Ecore_Desktop));
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
result->ondisk = 1;
|
||||||
result->original_path = strdup(file);
|
result->original_path = strdup(file);
|
||||||
if (lang)
|
if (lang)
|
||||||
result->original_lang = strdup(lang);
|
result->original_lang = strdup(lang);
|
||||||
|
@ -213,7 +229,6 @@ ecore_desktop_get(const char *file, const char *lang)
|
||||||
"KDE Desktop Entry");
|
"KDE Desktop Entry");
|
||||||
if (result->group)
|
if (result->group)
|
||||||
{
|
{
|
||||||
char *value;
|
|
||||||
char *eap_name = NULL;
|
char *eap_name = NULL;
|
||||||
char *exe = NULL;
|
char *exe = NULL;
|
||||||
char *categories = NULL;
|
char *categories = NULL;
|
||||||
|
@ -233,24 +248,16 @@ ecore_desktop_get(const char *file, const char *lang)
|
||||||
}
|
}
|
||||||
eap_name = result->eap_name;
|
eap_name = result->eap_name;
|
||||||
|
|
||||||
result->name =
|
IFGETDUP(value, "Name", result->name);
|
||||||
(char *)ecore_hash_get(result->group, "Name");
|
IFGETDUP(value, "GenericName", result->generic);
|
||||||
result->generic =
|
IFGETDUP(value, "Comment", result->comment);
|
||||||
(char *)ecore_hash_get(result->group, "GenericName");
|
IFGETDUP(value, "Type", result->type);
|
||||||
result->comment =
|
|
||||||
(char *)ecore_hash_get(result->group, "Comment");
|
|
||||||
result->type =
|
|
||||||
(char *)ecore_hash_get(result->group, "Type");
|
|
||||||
|
|
||||||
result->path =
|
IFGETDUP(value, "Path", result->path);
|
||||||
(char *)ecore_hash_get(result->group, "Path");
|
IFGETDUP(value, "URL", result->URL);
|
||||||
result->URL =
|
IFGETDUP(value, "File", result->file);
|
||||||
(char *)ecore_hash_get(result->group, "URL");
|
|
||||||
result->file =
|
|
||||||
(char *)ecore_hash_get(result->group, "File");
|
|
||||||
|
|
||||||
result->exec =
|
IFGETDUP(value, "Exec", result->exec);
|
||||||
(char *)ecore_hash_get(result->group, "Exec");
|
|
||||||
if (result->exec)
|
if (result->exec)
|
||||||
{
|
{
|
||||||
exe = strchr(result->exec, ' ');
|
exe = strchr(result->exec, ' ');
|
||||||
|
@ -262,12 +269,8 @@ ecore_desktop_get(const char *file, const char *lang)
|
||||||
exe = result->exec;
|
exe = result->exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
value =
|
IFGETDUP(value, "StartupWMClass", result->window_class);
|
||||||
(char *)ecore_hash_get(result->group,
|
if ((!value) && (result->exec))
|
||||||
"StartupWMClass");
|
|
||||||
if (value)
|
|
||||||
result->window_class = strdup(value);
|
|
||||||
else if (result->exec)
|
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
|
@ -290,24 +293,15 @@ ecore_desktop_get(const char *file, const char *lang)
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result->window_name =
|
IFGETDUP(value, "X-Enlightenment-WindowName", result->window_name);
|
||||||
(char *)ecore_hash_get(result->group, "X-Enlightenment-WindowName");
|
IFGETDUP(value, "X-Enlightenment-WindowTitle", result->window_title);
|
||||||
result->window_title =
|
IFGETDUP(value, "X-Enlightenment-WindowRole", result->window_role);
|
||||||
(char *)ecore_hash_get(result->group, "X-Enlightenment-WindowTitle");
|
|
||||||
result->window_role =
|
|
||||||
(char *)ecore_hash_get(result->group, "X-Enlightenment-WindowRole");
|
|
||||||
|
|
||||||
|
IFGETDUP(value, "Icon", result->icon);
|
||||||
result->icon =
|
|
||||||
(char *)ecore_hash_get(result->group, "Icon");
|
|
||||||
if (result->icon)
|
if (result->icon)
|
||||||
result->original_icon = strdup(result->icon);
|
result->original_icon = strdup(result->icon);
|
||||||
result->icon_class =
|
IFGETDUP(value, "X-Enlightenment-IconClass", result->icon_class);
|
||||||
(char *)ecore_hash_get(result->group, "X-Enlightenment-IconClass");
|
IFGETDUP(value, "X-Enlightenment-IconPath", result->icon_path);
|
||||||
value =
|
|
||||||
(char *)ecore_hash_get(result->group, "X-Enlightenment-IconPath");
|
|
||||||
if (value)
|
|
||||||
result->icon_path = strdup(value);
|
|
||||||
|
|
||||||
if ((result->icon != NULL) && (result->icon_path == NULL) && (strchr(result->icon, '/') != NULL))
|
if ((result->icon != NULL) && (result->icon_path == NULL) && (strchr(result->icon, '/') != NULL))
|
||||||
{
|
{
|
||||||
|
@ -339,12 +333,12 @@ ecore_desktop_get(const char *file, const char *lang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result->categories =
|
IFGETDUP(value, "Categories", result->categories);
|
||||||
(char *)ecore_hash_get(result->group, "Categories");
|
|
||||||
if (result->categories)
|
if (result->categories)
|
||||||
result->Categories =
|
result->Categories =
|
||||||
ecore_desktop_paths_to_hash(result->categories);
|
ecore_desktop_paths_to_hash(result->categories);
|
||||||
categories = result->categories;
|
categories = result->categories;
|
||||||
|
|
||||||
value =
|
value =
|
||||||
(char *)ecore_hash_get(result->group, "OnlyShowIn");
|
(char *)ecore_hash_get(result->group, "OnlyShowIn");
|
||||||
if (value)
|
if (value)
|
||||||
|
@ -473,11 +467,8 @@ ecore_desktop_get(const char *file, const char *lang)
|
||||||
"Trash Info");
|
"Trash Info");
|
||||||
if (result->group)
|
if (result->group)
|
||||||
{
|
{
|
||||||
result->path =
|
IFGETDUP(value, "Path", result->path);
|
||||||
(char *)ecore_hash_get(result->group, "Path");
|
IFGETDUP(value, "DeletionDate", result->deletiondate);
|
||||||
result->deletiondate =
|
|
||||||
(char *)ecore_hash_get(result->group,
|
|
||||||
"DeletionDate");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,8 +488,23 @@ void
|
||||||
ecore_desktop_save(Ecore_Desktop * desktop)
|
ecore_desktop_save(Ecore_Desktop * desktop)
|
||||||
{
|
{
|
||||||
char *temp;
|
char *temp;
|
||||||
|
int trash = 0;
|
||||||
|
|
||||||
if (!desktop->group)
|
if (!desktop->group)
|
||||||
|
{
|
||||||
|
if ((desktop->ondisk) && (desktop->original_path))
|
||||||
|
{
|
||||||
|
desktop->data = ecore_desktop_ini_get(desktop->original_path);
|
||||||
|
desktop->group = (Ecore_Hash *) ecore_hash_get(desktop->data, "Desktop Entry");
|
||||||
|
if (!desktop->group)
|
||||||
|
desktop->group = (Ecore_Hash *) ecore_hash_get(desktop->data, "KDE Desktop Entry");
|
||||||
|
if (!desktop->group)
|
||||||
|
{
|
||||||
|
trash = 1;
|
||||||
|
desktop->group = (Ecore_Hash *) ecore_hash_get(desktop->data, "Trash Info");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
desktop->group = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
desktop->group = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
||||||
if (desktop->group)
|
if (desktop->group)
|
||||||
|
@ -507,6 +513,7 @@ ecore_desktop_save(Ecore_Desktop * desktop)
|
||||||
ecore_hash_set_free_value(desktop->group, free);
|
ecore_hash_set_free_value(desktop->group, free);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (desktop->group)
|
if (desktop->group)
|
||||||
{
|
{
|
||||||
|
@ -575,6 +582,9 @@ ecore_desktop_save(Ecore_Desktop * desktop)
|
||||||
list = ecore_hash_keys(desktop->group);
|
list = ecore_hash_keys(desktop->group);
|
||||||
if ((!f) || (!list)) return;
|
if ((!f) || (!list)) return;
|
||||||
|
|
||||||
|
if (trash)
|
||||||
|
fprintf(f, "[Trash Info]\n");
|
||||||
|
else
|
||||||
fprintf(f, "[Desktop Entry]\n");
|
fprintf(f, "[Desktop Entry]\n");
|
||||||
ecore_list_goto_first(list);
|
ecore_list_goto_first(list);
|
||||||
while ((key = (char *) ecore_list_next(list)))
|
while ((key = (char *) ecore_list_next(list)))
|
||||||
|
@ -587,6 +597,15 @@ ecore_desktop_save(Ecore_Desktop * desktop)
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (desktop->data)
|
||||||
|
{
|
||||||
|
ecore_hash_destroy(desktop->data);
|
||||||
|
desktop->data = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ecore_hash_destroy(desktop->group);
|
||||||
|
desktop->group = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,16 +626,6 @@ ecore_desktop_init()
|
||||||
|
|
||||||
if (!ecore_desktop_paths_init()) return --init_count;
|
if (!ecore_desktop_paths_init()) return --init_count;
|
||||||
|
|
||||||
if (!ini_file_cache)
|
|
||||||
{
|
|
||||||
ini_file_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
|
||||||
if (ini_file_cache)
|
|
||||||
{
|
|
||||||
ecore_hash_set_free_key(ini_file_cache, free);
|
|
||||||
ecore_hash_set_free_value(ini_file_cache,
|
|
||||||
(Ecore_Free_Cb) ecore_hash_destroy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!desktop_cache)
|
if (!desktop_cache)
|
||||||
{
|
{
|
||||||
desktop_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
desktop_cache = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
||||||
|
@ -648,11 +657,6 @@ ecore_desktop_shutdown()
|
||||||
|
|
||||||
ecore_desktop_icon_shutdown();
|
ecore_desktop_icon_shutdown();
|
||||||
|
|
||||||
if (ini_file_cache)
|
|
||||||
{
|
|
||||||
ecore_hash_destroy(ini_file_cache);
|
|
||||||
ini_file_cache = NULL;
|
|
||||||
}
|
|
||||||
if (desktop_cache)
|
if (desktop_cache)
|
||||||
{
|
{
|
||||||
ecore_hash_destroy(desktop_cache);
|
ecore_hash_destroy(desktop_cache);
|
||||||
|
@ -683,26 +687,37 @@ ecore_desktop_destroy(Ecore_Desktop * desktop)
|
||||||
void
|
void
|
||||||
_ecore_desktop_destroy(Ecore_Desktop * desktop)
|
_ecore_desktop_destroy(Ecore_Desktop * desktop)
|
||||||
{
|
{
|
||||||
if (desktop->original_path)
|
IFFREE(desktop->original_path)
|
||||||
free(desktop->original_path);
|
IFFREE(desktop->original_lang)
|
||||||
if (desktop->icon_path)
|
IFFREE(desktop->eap_name)
|
||||||
free(desktop->icon_path);
|
IFFREE(desktop->name)
|
||||||
if (desktop->original_lang)
|
IFFREE(desktop->generic)
|
||||||
free(desktop->original_lang);
|
IFFREE(desktop->comment)
|
||||||
if (desktop->eap_name)
|
IFFREE(desktop->type)
|
||||||
free(desktop->eap_name);
|
IFFREE(desktop->exec)
|
||||||
if (desktop->original_icon)
|
IFFREE(desktop->exec_params)
|
||||||
free(desktop->original_icon);
|
IFFREE(desktop->categories)
|
||||||
if (desktop->icon_class)
|
IFFREE(desktop->icon)
|
||||||
free(desktop->icon_class);
|
IFFREE(desktop->original_icon)
|
||||||
if (desktop->window_class)
|
IFFREE(desktop->icon_class)
|
||||||
free(desktop->window_class);
|
IFFREE(desktop->icon_path)
|
||||||
if (desktop->NotShowIn)
|
IFFREE(desktop->path)
|
||||||
ecore_hash_destroy(desktop->NotShowIn);
|
IFFREE(desktop->URL)
|
||||||
if (desktop->OnlyShowIn)
|
IFFREE(desktop->file)
|
||||||
ecore_hash_destroy(desktop->OnlyShowIn);
|
IFFREE(desktop->deletiondate)
|
||||||
if (desktop->Categories)
|
IFFREE(desktop->window_class)
|
||||||
ecore_hash_destroy(desktop->Categories);
|
IFFREE(desktop->window_name)
|
||||||
|
IFFREE(desktop->window_title)
|
||||||
|
IFFREE(desktop->window_role)
|
||||||
|
IFFREE(desktop->NotShowIn)
|
||||||
|
IFFREE(desktop->OnlyShowIn)
|
||||||
|
IFFREE(desktop->Categories)
|
||||||
|
if (desktop->data)
|
||||||
|
{
|
||||||
|
ecore_hash_destroy(desktop->data);
|
||||||
|
desktop->data = NULL;
|
||||||
|
}
|
||||||
|
desktop->group = NULL;
|
||||||
free(desktop);
|
free(desktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue