From cacc7e74cd20ba392c8670e62cc73d74afd3f4ec Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 24 Jan 2011 15:13:27 -0500 Subject: [PATCH] Filter links in a ObtLinkbase by environments. Store a set of active environments in a linkbase and only include links in the linkbase that 1) want to be displayed, 2) pass TryExec, 3) match environment requirements and restrictions. --- obt/link.c | 13 +++++++++++++ obt/link.h | 7 +++---- obt/linkbase.c | 34 ++++++++++++++++++++++++---------- obt/linkbase.h | 5 ++++- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/obt/link.c b/obt/link.c index c54b7826..de665f07 100644 --- a/obt/link.c +++ b/obt/link.c @@ -252,3 +252,16 @@ gchar* obt_link_id_from_ddfile(const gchar *filename) { return obt_ddparse_file_to_id(filename); } + +gboolean obt_link_display(ObtLink *e, const guint environments) +{ + return + /* display if the link wants to be displayed and TryExec passed */ + e->display && + /* display if no environment is required, or we match at least one of + the requirements */ + (!e->env_required || (e->env_required & environments)) && + /* display if no environment is restricted, or we do not match any of + the restrictions */ + (!e->env_restricted || !(e->env_restricted & environments)); +} diff --git a/obt/link.h b/obt/link.h index 749514de..973f1132 100644 --- a/obt/link.h +++ b/obt/link.h @@ -97,10 +97,9 @@ ObtLinkType obt_link_type (ObtLink *e); /*! Returns TRUE if the .desktop file should be displayed to users, given the current environment. If FALSE, the .desktop file should not be showed. This also uses the TryExec option if it is present. - @env A semicolon-deliminated list of environemnts. Can be one or more of: - GNOME, KDE, ROX, XFCE. Other environments not listed here may also - be supported. This can be null also if not listing any environment. */ -gboolean obt_link_display(ObtLink *e, const gchar *env); + @param environments A bitflags of values from ObtLinkEnvFlags indicating + the active environments. */ +gboolean obt_link_display(ObtLink *e, const guint environments); const gchar* obt_link_name (ObtLink *e); const gchar* obt_link_generic_name (ObtLink *e); diff --git a/obt/linkbase.c b/obt/linkbase.c index 702a598a..af4c29a6 100644 --- a/obt/linkbase.c +++ b/obt/linkbase.c @@ -38,6 +38,10 @@ struct _ObtLinkBaseEntry { struct _ObtLinkBase { gint ref; + /*! A bitflag of values from ObtLinkEnvFlags indicating which environments + are to be considered active. */ + guint environments; + const gchar *language; const gchar *country; const gchar *modifier; @@ -142,22 +146,31 @@ static void update(ObtWatch *w, const gchar *base_path, } if (add) { - ObtLinkBaseEntry *e = g_slice_new(ObtLinkBaseEntry); - e->priority = *priority; - e->link = obt_link_from_ddfile(full_path, self->paths, - self->language, self->country, - self->modifier); - list = g_slist_insert_before(list, it, e); + ObtLink *link; - /* this will free 'id' */ - g_hash_table_insert(self->base, id, list); - id = NULL; + link = obt_link_from_ddfile(full_path, self->paths, + self->language, self->country, + self->modifier); + if (!obt_link_display(link, self->environments)) { + obt_link_unref(link); + } + else { + ObtLinkBaseEntry *e = g_slice_new(ObtLinkBaseEntry); + e->priority = *priority; + e->link = link; + list = g_slist_insert_before(list, it, e); + + /* this will free 'id' */ + g_hash_table_insert(self->base, id, list); + id = NULL; + } } g_free(id); } -ObtLinkBase* obt_linkbase_new(ObtPaths *paths, const gchar *locale) +ObtLinkBase* obt_linkbase_new(ObtPaths *paths, const gchar *locale, + guint environments) { ObtLinkBase *self; GSList *it; @@ -165,6 +178,7 @@ ObtLinkBase* obt_linkbase_new(ObtPaths *paths, const gchar *locale) gint i; self = g_slice_new0(ObtLinkBase); + self->environments = environments; self->watch = obt_watch_new(); self->base = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)base_entry_list_free); diff --git a/obt/linkbase.h b/obt/linkbase.h index 57602788..4d2b7c44 100644 --- a/obt/linkbase.h +++ b/obt/linkbase.h @@ -30,8 +30,11 @@ typedef struct _ObtLinkBase ObtLinkBase; /*! Create a new database of ObtLinks. @param paths An ObtPaths structure. @param locale The value of LC_MESSAGES. + @param environments A bitflag of values from ObtLinkEnvFlags indicating + which environments are to be considered active. */ -ObtLinkBase* obt_linkbase_new(struct _ObtPaths *paths, const gchar *locale); +ObtLinkBase* obt_linkbase_new(struct _ObtPaths *paths, const gchar *locale, + guint environments); void obt_linkbase_ref(ObtLinkBase *lb); void obt_linkbase_unref(ObtLinkBase *lb); -- 2.34.1