From 0c8c9caba6f529c11b04643d24a5a503f49a245b Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 21 May 2010 20:03:21 -0400 Subject: [PATCH] parse OnlyShowIn/NotShowIn --- obt/ddparse.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ obt/ddparse.h | 2 ++ obt/link.c | 14 ++++++++++- obt/link.h | 12 +++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) diff --git a/obt/ddparse.c b/obt/ddparse.c index 6aee25e7..c4be8e1e 100644 --- a/obt/ddparse.c +++ b/obt/ddparse.c @@ -80,6 +80,7 @@ static void parse_value_free(ObtDDParseValue *v) case OBT_DDPARSE_BOOLEAN: case OBT_DDPARSE_NUMERIC: case OBT_DDPARSE_ENUM_APPLICATION: + case OBT_DDPARSE_ENVIRONMENTS: break; default: g_assert_not_reached(); @@ -183,6 +184,69 @@ static gchar* parse_value_string(const gchar *in, return o; } +static guint parse_value_environments(const gchar *in, + const ObtDDParse *const parse, + gboolean *error) +{ + const gchar *s; + int i; + guint mask = 0; + + s = in; + while (*s) { + switch (*(s++)) { + case 'G': + if (strcmp(s, "NOME") == 0) { + mask |= OBT_LINK_ENV_GNOME; + s += 4; + } + break; + case 'K': + if (strcmp(s, "DE") == 0) { + mask |= OBT_LINK_ENV_KDE; + s += 2; + } + break; + case 'L': + if (strcmp(s, "XDE") == 0) { + mask |= OBT_LINK_ENV_LXDE; + s += 3; + } + break; + case 'R': + if (strcmp(s, "OX") == 0) { + mask |= OBT_LINK_ENV_ROX; + s += 2; + } + break; + case 'X': + if (strcmp(s, "FCE") == 0) { + mask |= OBT_LINK_ENV_XFCE; + s += 3; + } + break; + case 'O': + switch (*(s++)) { + case 'l': + if (strcmp(s, "d") == 0) { + mask |= OBT_LINK_ENV_OLD; + s += 1; + } + break; + case 'P': + if (strcmp(s, "ENBOX") == 0) { + mask |= OBT_LINK_ENV_OPENBOX; + s += 5; + } + break; + } + } + /* find the next string, or the end of the sequence */ + while (*s && *s != ';') ++s; + } + return mask; +} + static gboolean parse_value_boolean(const gchar *in, const ObtDDParse *const parse, gboolean *error) @@ -559,6 +623,9 @@ static gboolean parse_desktop_entry_value(gchar *key, const gchar *val, return FALSE; } break; + case OBT_DDPARSE_ENVIRONMENTS: + v.value.environments = parse_value_environments(val, parse, error); + break; default: g_assert_not_reached(); } diff --git a/obt/ddparse.h b/obt/ddparse.h index d409eb5f..d33fe72a 100644 --- a/obt/ddparse.h +++ b/obt/ddparse.h @@ -28,6 +28,7 @@ typedef enum { OBT_DDPARSE_BOOLEAN, OBT_DDPARSE_NUMERIC, OBT_DDPARSE_ENUM_APPLICATION, + OBT_DDPARSE_ENVIRONMENTS, OBT_DDPARSE_NUM_VALUE_TYPES } ObtDDParseValueType; @@ -42,6 +43,7 @@ typedef struct _ObtDDParseValue { gboolean boolean; gfloat numeric; guint enumerable; + guint environments; /*!< A mask of flags from ObtLinkEnvMask */ } value; } ObtDDParseValue; diff --git a/obt/link.c b/obt/link.c index 9a053707..61369ecb 100644 --- a/obt/link.c +++ b/obt/link.c @@ -33,6 +33,10 @@ struct _ObtLink { gchar *generic; /*!< Generic name for the object (eg Web Browser) */ gchar *comment; /*!< Comment/description to display for the object */ gchar *icon; /*!< Name/path for an icon for the object */ + guint env_required; /*!< The environments that must be present to use this + link. */ + guint env_restricted; /*!< The environments that must _not_ be present to + use this link. */ union _ObtLinkData { struct _ObtLinkApp { @@ -117,7 +121,15 @@ ObtLink* obt_link_from_ddfile(const gchar *ddname, GSList *paths, if ((v = g_hash_table_lookup(keys, "Icon"))) link->icon = v->value.string, v->value.string = NULL; - /* XXX handle Only/NotShowIn, better know the current environment */ + if ((v = g_hash_table_lookup(keys, "OnlyShowIn"))) + link->env_required = v->value.environments; + else + link->env_required = 0; + + if ((v = g_hash_table_lookup(keys, "NotShowIn"))) + link->env_restricted = v->value.environments; + else + link->env_restricted = 0; if (link->type == OBT_LINK_TYPE_APPLICATION) { if ((v = g_hash_table_lookup(keys, "TryExec"))) { diff --git a/obt/link.h b/obt/link.h index b0193297..4c1fb8aa 100644 --- a/obt/link.h +++ b/obt/link.h @@ -37,6 +37,18 @@ typedef enum { OBT_LINK_APP_STARTUP_LEGACY_SUPPORT } ObtLinkAppStartup; +/*! These bit flags are environments for links. Some links are used or not + used in various environments. */ +typedef enum { + OBT_LINK_ENV_OPENBOX = 1 << 0, + OBT_LINK_ENV_GNOME = 1 << 1, + OBT_LINK_ENV_KDE = 1 << 2, + OBT_LINK_ENV_LXDE = 1 << 3, + OBT_LINK_ENV_ROX = 1 << 4, + OBT_LINK_ENV_XFCE = 1 << 5, + OBT_LINK_ENV_OLD = 1 << 6 +} ObtLinkEnvFlags; + typedef enum { /*! The app can be launched with a single local file */ OBT_LINK_APP_SINGLE_LOCAL = 1 << 0, -- 2.45.2