static int init = 0;
+/**
+ * @internal
+ * Information about custom types
+ */
+typedef struct Efreet_Desktop_Type_Info Efreet_Desktop_Type_Info;
+struct Efreet_Desktop_Type_Info
+{
+ char *type;
+ Efreet_Desktop_Type_Parse_Cb parse_func;
+ Efreet_Desktop_Type_Free_Cb free_func;
+};
+
static Efreet_Desktop *efreet_desktop_new(const char *file);
static Efreet_Desktop_Type efreet_desktop_type_parse(const char *type_str);
static Ecore_List *efreet_desktop_string_list_parse(const char *string);
static void efreet_desktop_exec_cb(void *data, Efreet_Desktop *desktop,
char *exec, int remaining);
+static void efreet_desktop_type_info_free(Efreet_Desktop_Type_Info *info);
+
/**
* @internal
* @return Returns > 0 on success or 0 on failure
ECORE_FREE_CB(efreet_desktop_free));
efreet_desktop_types = ecore_list_new();
- ecore_list_set_free_cb(efreet_desktop_types, ECORE_FREE_CB(free));
+ ecore_list_set_free_cb(efreet_desktop_types, ECORE_FREE_CB(efreet_desktop_type_info_free));
return init;
}
}
else if (desktop->type >= (EFREET_DESKTOP_TYPE_MAX + 1))
{
- /* XXX which user fields should we be parsing? */
+ Efreet_Desktop_Type_Info *info;
+ info = ecore_list_goto_index(efreet_desktop_types,
+ (desktop->type - (EFREET_DESKTOP_TYPE_MAX + 1)));
+ if (info->parse_func)
+ desktop->type_data = info->parse_func(desktop, ini);
}
else
error = 1;
}
else if (desktop->type > EFREET_DESKTOP_TYPE_MAX + 1)
{
- ecore_list_goto_index(efreet_desktop_types,
+ Efreet_Desktop_Type_Info *info;
+ info = ecore_list_goto_index(efreet_desktop_types,
(desktop->type - (EFREET_DESKTOP_TYPE_MAX + 1)));
- efreet_ini_string_set(ini, "Type",
- (char *)ecore_list_current(efreet_desktop_types));
+ if (info)
+ efreet_ini_string_set(ini, "Type", info->type);
}
else
ok = 0;
IF_FREE_HASH(desktop->x);
+ if (desktop->type >= EFREET_DESKTOP_TYPE_MAX + 1 && desktop->type_data)
+ {
+ Efreet_Desktop_Type_Info *info;
+ info = ecore_list_goto_index(efreet_desktop_types,
+ (desktop->type - (EFREET_DESKTOP_TYPE_MAX + 1)));
+ if (info->free_func)
+ info->free_func(desktop->type_data);
+ }
+
FREE(desktop);
}
/**
* @param type: The type to add to the list of matching types
- * @return Returns no value
+ * @param parse_func: a function to parse out custom fields
+ * @param free_func: a function to free data returned from @a parse_func
+ * @return Returns the id of the new type
* @brief Adds the given type to the list of types in the system
*/
int
-efreet_desktop_type_add(const char *type)
+efreet_desktop_type_add(const char *type, Efreet_Desktop_Type_Parse_Cb parse_func,
+ Efreet_Desktop_Type_Free_Cb free_func)
{
int id;
+ Efreet_Desktop_Type_Info *info;
+
+ info = NEW(Efreet_Desktop_Type_Info, 1);
+ if (!info) return 0;
+
+ info->type = strdup(type);
+ info->parse_func = parse_func;
+ info->free_func = free_func;
id = ecore_list_nodes(efreet_desktop_types);
- ecore_list_append(efreet_desktop_types, strdup(type));
+ ecore_list_append(efreet_desktop_types, info);
return (id + EFREET_DESKTOP_TYPE_MAX + 1);
}
/**
* @internal
+ * @brief Free an Efreet Desktop_Type_Info struct
+ */
+static void
+efreet_desktop_type_info_free(Efreet_Desktop_Type_Info *info)
+{
+ if (!info) return;
+ IF_FREE(info->type);
+ free(info);
+}
+
+/**
+ * @brief get type specific data for custom desktop types
+ * @param desktop the desktop
+ * @return type specific data, or NULL if there is none
+ */
+void *
+efreet_desktop_type_data_get(Efreet_Desktop *desktop)
+{
+ return desktop->type_data;
+}
+
+/**
+ * @internal
* @param type_str: the type as a string
* @return the parsed type
* @brief parse the type string into an Efreet_Desktop_Type
static Efreet_Desktop_Type
efreet_desktop_type_parse(const char *type_str)
{
- char *str;
+ Efreet_Desktop_Type_Info *info;
int count = 0;
if (!type_str) return EFREET_DESKTOP_TYPE_UNKNOWN;
/* check the user added types */
ecore_list_goto_first(efreet_desktop_types);
- while ((str = ecore_list_next(efreet_desktop_types)))
+ while ((info = ecore_list_next(efreet_desktop_types)))
{
- if (!strcmp(str, type_str))
+ if (!strcmp(info->type, type_str))
return (count + EFREET_DESKTOP_TYPE_MAX + 1);
count ++;
}
#ifndef EFREET_DESKTOP_H
#define EFREET_DESKTOP_H
+#include "efreet_ini.h"
+
/**
* @file efreet_desktop.h
* @brief Contains the structures and methods used to support the
typedef int (*Efreet_Desktop_Progress_Cb) (void *data, Efreet_Desktop *desktop, char *uri, long int total, long int current);
/**
+ * A callback used to parse data for custom types
+ */
+typedef void *(*Efreet_Desktop_Type_Parse_Cb) (Efreet_Desktop *desktop, Efreet_Ini *ini);
+
+/**
+ * A callback used to free data for custom types
+ */
+typedef void *(*Efreet_Desktop_Type_Free_Cb) (void *data);
+
+/**
* Efreet_Desktop
* @brief a parsed representation of a .desktop file
*/
unsigned char startup_notify:1; /**< The starup notify settings of the app */
Ecore_Hash *x; /**< Keep track of all user extensions, keys that begin with X- */
+ void *type_data; /**< Type specific data for custom types */
};
Efreet_Desktop *efreet_desktop_get(const char *file);
int efreet_desktop_category_del(Efreet_Desktop *desktop,
const char *category);
-int efreet_desktop_type_add(const char *type);
+int efreet_desktop_type_add(const char *type, Efreet_Desktop_Type_Parse_Cb parse_func, Efreet_Desktop_Type_Free_Cb free_func);
/**
* @}