Bring it a bit more up to scratch, and a better match for what is

required in e_apps.c.

API breakage.


SVN revision: 24710
This commit is contained in:
David Walter Seikel 2006-08-14 21:42:53 +00:00
parent 03c0e9c47c
commit 3a1d70fb06
4 changed files with 141 additions and 18 deletions

View File

@ -1,8 +1,9 @@
#ifndef _ECORE_DESKTOP_H
# define _ECORE_DESKTOP_H
/* FIXME: No unnecessary includes in exported headers. */
/* FIXME: No unnecessary includes in exported headers, when things settle down and we know what is unnecessary. */
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -35,7 +36,7 @@
#define MAX_PATH 4096
/* FIXME: No unnecessary macros in exported headers. */
/* FIXME: No unnecessary macros in exported headers, when things settle down and we know what is unnecessary. */
#define E_FN_DEL(_fn, _h) if (_h) { _fn(_h); _h = NULL; }
#define E_REALLOC(p, s, n) p = (s *)realloc(p, sizeof(s) * n)
#define E_NEW(s, n) (s *)calloc(n, sizeof(s))
@ -52,6 +53,7 @@ Ecore_List *ecore_desktop_paths_kde_legacy;
struct _Ecore_Desktop
{
Ecore_Hash *data, *group, *Categories, *OnlyShowIn, *NotShowIn;
char *eap_name;
char *name;
char *generic;
char *comment;
@ -59,6 +61,7 @@ struct _Ecore_Desktop
char *categories;
char *exec;
char *icon;
char *icon_class;
char *icon_path;
char *path;
char *deletiondate;
@ -100,7 +103,7 @@ extern "C"
# endif
/* Function Prototypes */
void ecore_desktop_paths_init(void);
EAPI int ecore_desktop_paths_init(void);
char *ecore_desktop_paths_file_find(Ecore_List * paths,
char *file, int sub,
int (*func) (const
@ -119,15 +122,15 @@ extern "C"
char
*path),
const void *data);
void ecore_desktop_paths_shutdown(void);
EAPI int ecore_desktop_paths_shutdown(void);
Ecore_Hash *ecore_desktop_paths_to_hash(char *paths);
Ecore_List *ecore_desktop_paths_to_list(char *paths);
void ecore_desktop_init(void);
void ecore_desktop_shutdown(void);
Ecore_Hash *ecore_desktop_ini_get(char *file);
Ecore_Desktop *ecore_desktop_get(char *file);
EAPI int ecore_desktop_init(void);
EAPI int ecore_desktop_shutdown(void);
Ecore_Hash *ecore_desktop_ini_get(const char *file);
Ecore_Desktop *ecore_desktop_get(const char *file, const char *lang);
void ecore_desktop_destroy(Ecore_Desktop * desktop);
char *ecore_desktop_icon_find(char *icon, char *icon_size,

View File

@ -1,8 +1,12 @@
#include <ctype.h>
#include "Ecore_Desktop.h"
#include "ecore_desktop_private.h"
extern int reject_count, not_over_count;
static int init_count = 0;
static Ecore_Hash *ini_file_cache;
static Ecore_Hash *desktop_cache;
@ -28,7 +32,7 @@ static Ecore_Hash *desktop_cache;
* @ingroup Ecore_Desktop_Main_Group
*/
Ecore_Hash *
ecore_desktop_ini_get(char *file)
ecore_desktop_ini_get(const char *file)
{
Ecore_Hash *result;
@ -138,15 +142,16 @@ ecore_desktop_ini_get(char *file)
* Use ecore_desktop_destroy() to free this structure.
*
* @param file Full path to the .desktop file.
* @param lang Language to use, or NULL for default.
* @return An Ecore_Desktop containing the files contents.
* @ingroup Ecore_Desktop_Main_Group
*/
Ecore_Desktop *
ecore_desktop_get(char *file)
ecore_desktop_get(const char *file, const char *lang)
{
Ecore_Desktop *result;
result = (Ecore_Desktop *) ecore_hash_get(desktop_cache, file);
result = (Ecore_Desktop *) ecore_hash_get(desktop_cache, (char *) file);
if (!result)
{
result = calloc(1, sizeof(Ecore_Desktop));
@ -165,6 +170,22 @@ ecore_desktop_get(char *file)
if (result->group)
{
char *value;
char *eap_name = NULL;
char *exe = NULL;
char *categories = NULL;
int size = 0;
value = (char *) ecore_file_get_file(file);
if (value)
{
char *temp = strrchr(value, '.');
if (temp)
*temp = '\0';
result->eap_name = malloc(strlen(value) + 5);
if (result->eap_name)
sprintf(result->eap_name, "%s.eap", value);
}
eap_name = result->eap_name;
result->name =
(char *)ecore_hash_get(result->group, "Name");
@ -176,9 +197,36 @@ ecore_desktop_get(char *file)
(char *)ecore_hash_get(result->group, "Type");
result->exec =
(char *)ecore_hash_get(result->group, "Exec");
result->window_class =
// FIXME: Handle the fdo %x replacable params. Some should be stripped, some should be expanded.
exe = result->exec;
value =
(char *)ecore_hash_get(result->group,
"StartupWMClass");
if (value)
result->window_class = strdup(value);
else if (result->exec)
{
char *tmp;
/* Guess - exe name with first letter capitalized. */
tmp = strdup(result->exec);
if (tmp)
{
char *p;
value = (char *) ecore_file_get_file(tmp); /* In case the exe included a path. */
p = value;
while ((*p != '\0') && (*p != ' '))
{
*p = tolower(*p);
p++;
}
*p = '\0';
*value = toupper(*value);
result->window_class = strdup(value);
free(tmp);
}
}
result->icon =
(char *)ecore_hash_get(result->group, "Icon");
result->categories =
@ -186,6 +234,7 @@ ecore_desktop_get(char *file)
if (result->categories)
result->Categories =
ecore_desktop_paths_to_hash(result->categories);
categories = result->categories;
value =
(char *)ecore_hash_get(result->group, "OnlyShowIn");
if (value)
@ -208,6 +257,49 @@ ecore_desktop_get(char *file)
if (value)
result->startup =
(!strcmp(value, "true")) ? "1" : "0";
/*
* icon/class is a list of standard icons from the theme that can override the icon created above.
* Use (from .desktop) eap name,exe name,categories. It's case sensitive, the reccomendation is to lowercase it.
* It should be most specific to most generic. firefox,browser,internet for instance
*/
if (eap_name) size += strlen(eap_name);
if (exe) size += strlen(exe);
if (categories) size += strlen(categories);
result->icon_class = malloc(size + 3);
if (result->icon_class)
{
char *p;
int done = 0;
result->icon_class[0] = '\0';
if (eap_name)
{
strcat(result->icon_class, eap_name);
done = 1;
}
if (exe)
{
if (done)
strcat(result->icon_class, ",");
strcat(result->icon_class, exe);
}
if (categories)
{
if (done)
strcat(result->icon_class, ",");
strcat(result->icon_class, categories);
}
p = result->icon_class;
while (*p != '\0')
{
if (*p == ';')
*p = ',';
else
*p = tolower(*p);
p++;
}
}
}
else
{
@ -245,9 +337,13 @@ ecore_desktop_get(char *file)
*
* @ingroup Ecore_Desktop_Main_Group
*/
void
EAPI int
ecore_desktop_init()
{
if (++init_count != 1) 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);
@ -268,6 +364,8 @@ ecore_desktop_init()
(Ecore_Free_Cb) ecore_desktop_destroy);
}
}
return init_count;
}
/**
@ -278,9 +376,11 @@ ecore_desktop_init()
*
* @ingroup Ecore_Desktop_Main_Group
*/
void
EAPI int
ecore_desktop_shutdown()
{
if (--init_count != 0) return init_count;
if (ini_file_cache)
{
ecore_hash_destroy(ini_file_cache);
@ -291,6 +391,10 @@ ecore_desktop_shutdown()
ecore_hash_destroy(desktop_cache);
desktop_cache = NULL;
}
ecore_desktop_paths_shutdown();
return init_count;
}
/**
@ -305,6 +409,12 @@ ecore_desktop_shutdown()
void
ecore_desktop_destroy(Ecore_Desktop * desktop)
{
if (desktop->eap_name)
free(desktop->eap_name);
if (desktop->icon_class)
free(desktop->icon_class);
if (desktop->window_class)
free(desktop->window_class);
if (desktop->NotShowIn)
ecore_hash_destroy(desktop->NotShowIn);
if (desktop->OnlyShowIn)

View File

@ -10,7 +10,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <libgen.h>
#include <strings.h>
#include <Ecore.h>
@ -1443,7 +1442,8 @@ _ecore_desktop_menu_select_app(void *value, void *user_data)
key = (char *)node->key;
app = (char *)node->value;
desktop = ecore_desktop_get(app);
/* FIXME: pass an actualy language parameter. */
desktop = ecore_desktop_get(app, NULL);
if ((generate_data->unallocated) && (desktop->allocated))
return;

View File

@ -32,6 +32,8 @@
* and correct those guesses.
*/
static int init_count = 0;
static Ecore_List *_ecore_desktop_paths_get(char *before, char *env_home,
char *env, char *env_home_default,
@ -67,9 +69,11 @@ static Ecore_Event_Handler *exit_handler = NULL;
#endif
void
EAPI int
ecore_desktop_paths_init()
{
if (++init_count != 1) return init_count;
/* FIXME: Keep track of any loose strdups in a list, so that we can free them at shutdown time. */
#if defined GNOME_SUPPORT || defined KDE_SUPPORT
@ -222,15 +226,21 @@ ecore_desktop_paths_init()
if (exit_handler)
ecore_event_handler_del(exit_handler);
#endif
return init_count;
}
void
EAPI int
ecore_desktop_paths_shutdown()
{
if (--init_count != 0) return init_count;
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_menus);
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_directories);
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_desktops);
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_icons);
return init_count;
}
/** Search for a file in fdo compatible locations.