From e5143ec877bab2e6230b898cc09f13696851537d Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 27 Jan 2011 17:28:12 -0500 Subject: [PATCH] specify the encoding of filesystem paths, and include a comparator function the comparator compares two ObtLink** objects by their names. if the names are equal it uses the path of the source as a tie-breaker. --- obt/link.c | 40 +++++++++++++++++++++++++++++++++++++--- obt/link.h | 10 +++++++++- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/obt/link.c b/obt/link.c index ab215b50..9eb912c9 100644 --- a/obt/link.c +++ b/obt/link.c @@ -30,10 +30,12 @@ struct _ObtLink { guint ref; - gchar *path; /*!< The path to the file where the link came from */ + gchar *path; /*!< The path to the file where the link came from. + Encoded in UTF-8. */ ObtLinkType type; gchar *name; /*!< Specific name for the object (eg Firefox) */ + gchar *collate_key; /*!< Internal key for sorting by name. */ gboolean display; /*type = v->value.enumerable; + v = g_hash_table_lookup(keys, "Name"); + g_assert(v); + link->name = v->value.string, v->value.string = NULL; /* steal it */ + link->collate_key = g_utf8_collate_key(link->name, -1); + if ((v = g_hash_table_lookup(keys, "Hidden"))) link->deleted = v->value.boolean; @@ -221,6 +230,7 @@ void obt_link_unref(ObtLink *dd) { if (--dd->ref < 1) { g_free(dd->name); + g_free(dd->collate_key); g_free(dd->generic); g_free(dd->comment); g_free(dd->icon); @@ -264,6 +274,21 @@ gchar* obt_link_id_from_ddfile(const gchar *filename) return obt_ddparse_file_to_id(filename); } +const gchar* obt_link_name(ObtLink *e) +{ + return e->name; +} + +const gchar* obt_link_generic_name(ObtLink *e) +{ + return e->generic; +} + +const gchar* obt_link_comment(ObtLink *e) +{ + return e->comment; +} + gboolean obt_link_display(ObtLink *e, const guint environments) { return @@ -276,3 +301,12 @@ gboolean obt_link_display(ObtLink *e, const guint environments) the restrictions */ (!e->env_restricted || !(e->env_restricted & environments)); } + +int obt_link_cmp_by_name(const void *a, const void *b) +{ + const ObtLink *const la = *(ObtLink**)a, *const lb = *(ObtLink**)b; + int r = strcmp(la->collate_key, lb->collate_key); + if (r) return r; + /* fallback to differentiating on the path */ + return strcmp(la->path, lb->path); +} diff --git a/obt/link.h b/obt/link.h index 6577d8a3..25f19e27 100644 --- a/obt/link.h +++ b/obt/link.h @@ -63,7 +63,7 @@ typedef enum { typedef struct _ObtLink ObtLink; /*! Parse a .desktop (dd) file. - @param path The full path to the .desktop file. + @param path The full path to the .desktop file, encoded in UTF-8. @param o An ObtPaths structure, which contains the executable paths. */ ObtLink* obt_link_from_ddfile(const gchar *path, @@ -131,6 +131,14 @@ ObtLinkAppOpen obt_link_app_open(ObtLink *e); ObtLinkAppStartup obt_link_app_startup_notify(ObtLink *e); const gchar* obt_link_app_startup_wmclass(ObtLink *e); +/*! Compares two ObtLink objects. + @param a An ObtLink** (pointer to a pointer) + @param b An ObtLink** (pointer to a pointer) + @return Returns 0 if their names are the same, a number < 0 if a has a name + which comes first, and a number > 0 if b has a name which comes first. +*/ +int obt_link_cmp_by_name(const void *a, const void *b); + G_END_DECLS -- 2.39.2