]> Dogcows Code - chaz/openbox/commitdiff
parse OnlyShowIn/NotShowIn
authorDana Jansens <danakj@orodu.net>
Sat, 22 May 2010 00:03:21 +0000 (20:03 -0400)
committerDana Jansens <danakj@orodu.net>
Sat, 22 May 2010 00:03:21 +0000 (20:03 -0400)
obt/ddparse.c
obt/ddparse.h
obt/link.c
obt/link.h

index 6aee25e72ec5f4a8606bd815746846df592cf5cf..c4be8e1edbb85454df449b3b4b31ff7df5226238 100644 (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();
     }
index d409eb5ff0d6016817723d0ffdb8a8cf971cf4f5..d33fe72a48e38efd051e28eac62dc06eb6d0d23f 100644 (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;
 
index 9a05370716e39758a3bb677f4e27c229e0bbfb65..61369ecbfdde9aea2cab04f629c53887c6bfc8fb 100644 (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"))) {
index b0193297f39c75717c0f9af6b932e6b7574e8be0..4c1fb8aaf821f3228cc29b9ba6a314fa24842daa 100644 (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,
This page took 0.025028 seconds and 4 git commands to generate.