]> Dogcows Code - chaz/openbox/commitdiff
parse some of the .desktop stuff into an ObtLink structure
authorDana Jansens <danakj@orodu.net>
Tue, 30 Mar 2010 02:38:05 +0000 (22:38 -0400)
committerDana Jansens <danakj@orodu.net>
Tue, 30 Mar 2010 02:38:05 +0000 (22:38 -0400)
localized names still don't work.
most of the app-specific stuff isn't done yet.
categories aren't handled yet (to only show in/not show in some category)

obt/ddparse.c
obt/ddparse.h
obt/link.c
obt/link.h

index fe7feb93cc3eea25440c8c4ccb416c060b561e1c..6aee25e72ec5f4a8606bd815746846df592cf5cf 100644 (file)
@@ -17,6 +17,7 @@
 */
 
 #include "obt/ddparse.h"
+#include "obt/link.h"
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
@@ -77,8 +78,8 @@ static void parse_value_free(ObtDDParseValue *v)
         v->value.strings.n = 0;
         break;
     case OBT_DDPARSE_BOOLEAN:
-        break;
     case OBT_DDPARSE_NUMERIC:
+    case OBT_DDPARSE_ENUM_APPLICATION:
         break;
     default:
         g_assert_not_reached();
@@ -546,6 +547,18 @@ static gboolean parse_desktop_entry_value(gchar *key, const gchar *val,
     case OBT_DDPARSE_NUMERIC:
         v.value.numeric = parse_value_numeric(val, parse, error);
         break;
+    case OBT_DDPARSE_ENUM_APPLICATION:
+        if (val[0] == 'A' && strcmp(val+1, "pplication") == 0)
+            v.value.enumerable = OBT_LINK_TYPE_APPLICATION;
+        else if (val[0] == 'L' && strcmp(val+1, "ink") == 0)
+            v.value.enumerable = OBT_LINK_TYPE_URL;
+        else if (val[0] == 'D' && strcmp(val+1, "irectory") == 0)
+            v.value.enumerable = OBT_LINK_TYPE_DIRECTORY;
+        else {
+            parse_error("Unknown Type", parse, error);
+            return FALSE;
+        }
+        break;
     default:
         g_assert_not_reached();
     }
index b4e0bf412c4a0f0f1bdd3d13f365c26678daad35..d409eb5ff0d6016817723d0ffdb8a8cf971cf4f5 100644 (file)
@@ -27,6 +27,7 @@ typedef enum {
     OBT_DDPARSE_LOCALESTRINGS,
     OBT_DDPARSE_BOOLEAN,
     OBT_DDPARSE_NUMERIC,
+    OBT_DDPARSE_ENUM_APPLICATION,
     OBT_DDPARSE_NUM_VALUE_TYPES
 } ObtDDParseValueType;
 
@@ -40,6 +41,7 @@ typedef struct _ObtDDParseValue {
         } strings;
         gboolean boolean;
         gfloat numeric;
+        guint enumerable;
     } value;
 } ObtDDParseValue;
 
index 8249118d210a8e8e19d08cb9d2247cf30f828477..9a05370716e39758a3bb677f4e27c229e0bbfb65 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "obt/link.h"
 #include "obt/ddparse.h"
+#include "obt/paths.h"
 #include <glib.h>
 
 struct _ObtLink {
@@ -25,6 +26,10 @@ struct _ObtLink {
 
     ObtLinkType type;
     gchar *name; /*!< Specific name for the object (eg Firefox) */
+    gboolean display; /*<! When false, do not display this link in menus or
+                           launchers, etc */
+    gboolean deleted; /*<! When true, the Link could exist but is deleted
+                           for the current user */
     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 */
@@ -44,20 +49,22 @@ struct _ObtLink {
             gchar *startup_wmclass;
         } app;
         struct _ObtLinkLink {
-            gchar *url;
-        } link;
+            gchar *addr;
+        } url;
         struct _ObtLinkDir {
         } dir;
     } d;
 };
 
-ObtLink* obt_link_from_ddfile(const gchar *name, GSList *paths)
+ObtLink* obt_link_from_ddfile(const gchar *ddname, GSList *paths,
+                              ObtPaths *p)
 {
-    ObtLink *lnk;
+    ObtLink *link;
     GHashTable *groups, *keys;
     ObtDDParseGroup *g;
+    ObtDDParseValue *v, *type, *name, *target;
 
-    groups = obt_ddparse_file(name, paths);
+    groups = obt_ddparse_file(ddname, paths);
     if (!groups) return NULL;
     g = g_hash_table_lookup(groups, "Desktop Entry");
     if (!g) {
@@ -67,11 +74,66 @@ ObtLink* obt_link_from_ddfile(const gchar *name, GSList *paths)
 
     keys = obt_ddparse_group_keys(g);
 
-    lnk = g_slice_new(ObtLink);
-    lnk->ref = 1;
-    /* XXX turn the values in the .desktop file into an ObtLink */
+    /* check that required keys exist */
 
-    return lnk;
+    if (!(type = g_hash_table_lookup(keys, "Type")))
+    { g_hash_table_destroy(groups); return NULL; }
+    if (!(name = g_hash_table_lookup(keys, "Name")))
+    { g_hash_table_destroy(groups); return NULL; }
+
+    if (type->value.enumerable == OBT_LINK_TYPE_APPLICATION) {
+        if (!(target = g_hash_table_lookup(keys, "Exec")))
+        { g_hash_table_destroy(groups); return NULL; }
+    }
+    else if (type->value.enumerable == OBT_LINK_TYPE_URL) {
+        if (!(target = g_hash_table_lookup(keys, "URL")))
+        { g_hash_table_destroy(groups); return NULL; }
+    }
+    else
+        target = NULL;
+
+    /* parse all the optional keys and build ObtLink (steal the strings) */
+    link = g_slice_new0(ObtLink);
+    link->ref = 1;
+    link->type = type->value.enumerable;
+    if (link->type == OBT_LINK_TYPE_APPLICATION)
+        link->d.app.exec = target->value.string, target->value.string = NULL;
+    else if (link->type == OBT_LINK_TYPE_URL)
+        link->d.url.addr = target->value.string, target->value.string = NULL;
+    link->display = TRUE;
+
+    if ((v = g_hash_table_lookup(keys, "Hidden")))
+        link->deleted = v->value.boolean;
+
+    if ((v = g_hash_table_lookup(keys, "NoDisplay")))
+        link->display = !v->value.boolean;
+
+    if ((v = g_hash_table_lookup(keys, "GenericName")))
+        link->generic = v->value.string, v->value.string = NULL;
+
+    if ((v = g_hash_table_lookup(keys, "Comment")))
+        link->comment = v->value.string, v->value.string = NULL;
+
+    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 (link->type == OBT_LINK_TYPE_APPLICATION) {
+        if ((v = g_hash_table_lookup(keys, "TryExec"))) {
+            /* XXX spawn a thread to check TryExec? */
+            link->display = link->display &&
+                obt_paths_try_exec(p, v->value.string);
+        }
+
+        /* XXX there's more app specific stuff */
+    }
+
+    else if (link->type == OBT_LINK_TYPE_URL) {
+        /* XXX there's URL specific stuff */
+    }
+
+    return link;
 }
 
 void obt_link_ref(ObtLink *dd)
index bcac9d992f66dbc6479a324ff7b6f8337168eda3..b0193297f39c75717c0f9af6b932e6b7574e8be0 100644 (file)
@@ -23,6 +23,8 @@
 
 G_BEGIN_DECLS
 
+struct _ObtPaths;
+
 typedef enum {
        OBT_LINK_TYPE_APPLICATION = 1,
        OBT_LINK_TYPE_URL         = 2,
@@ -48,7 +50,8 @@ typedef enum {
 
 typedef struct _ObtLink     ObtLink;
 
-ObtLink* obt_link_from_ddfile(const gchar *name, GSList *paths);
+ObtLink* obt_link_from_ddfile(const gchar *name, GSList *paths,
+                              struct _ObtPaths *p);
 
 void obt_link_ref(ObtLink *e);
 void obt_link_unref(ObtLink *e);
This page took 0.032915 seconds and 4 git commands to generate.