parse OnlyShowIn/NotShowIn

This commit is contained in:
Dana Jansens 2010-05-21 20:03:21 -04:00
parent 632eb08227
commit 0c8c9caba6
4 changed files with 94 additions and 1 deletions

View file

@ -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();
}

View file

@ -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;

View file

@ -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"))) {

View file

@ -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,