]> Dogcows Code - chaz/openbox/blobdiff - obt/link.c
Add another BSEARCH function that lets you search through an array of objects.
[chaz/openbox] / obt / link.c
index a1d08270ba6e5a21652d868ab9b0f94bfeb154aa..9cc2bac96d7cb3bdcf180d52711d739ed6898590 100644 (file)
@@ -45,12 +45,11 @@ struct _ObtLink {
             gboolean term; /*!< Run the app in a terminal or not */
             ObtLinkAppOpen open;
 
-            /* XXX gchar**? or something better, a mime struct.. maybe
-               glib has something i can use. */
             gchar **mime; /*!< Mime types the app can open */
 
             GQuark *categories; /*!< Array of quarks representing the
                                   application's categories */
+            gulong  n_categories; /*!< Number of categories for the app */
 
             ObtLinkAppStartup startup;
             gchar *startup_wmclass;
@@ -128,15 +127,17 @@ ObtLink* obt_link_from_ddfile(const gchar *ddname, GSList *paths,
         /* parse link->d.app.exec to determine link->d.app.open */
         percent = FALSE;
         for (c = link->d.app.exec; *c; ++c) {
-            if (*c == '%') percent = !percent;
             if (percent) {
                 switch (*c) {
                 case 'f': link->d.app.open = OBT_LINK_APP_SINGLE_LOCAL; break;
                 case 'F': link->d.app.open = OBT_LINK_APP_MULTI_LOCAL; break;
                 case 'u': link->d.app.open = OBT_LINK_APP_SINGLE_URL; break;
                 case 'U': link->d.app.open = OBT_LINK_APP_MULTI_URL; break;
+                default: percent = FALSE;
                 }
+                if (percent) break; /* found f/F/u/U */
             }
+            else if (*c == '%') percent = TRUE;
         }
 
         if ((v = g_hash_table_lookup(keys, "TryExec"))) {
@@ -172,16 +173,21 @@ ObtLink* obt_link_from_ddfile(const gchar *ddname, GSList *paths,
             gchar *end;
 
             link->d.app.categories = g_new(GQuark, v->value.strings.n);
+            link->d.app.n_categories = v->value.strings.n;
 
-            c = end = v->value.strings.s;
             for (i = 0; i < v->value.strings.n; ++i) {
-                while (*end) ++end;
-                link->d.app.categories[i] = g_quark_from_string(c);
+                link->d.app.categories[i] =
+                    g_quark_from_string(v->value.strings.a[i]);
                 c = end = end+1; /* next */
             }
         }
 
-        /* XXX do something with mime types */
+        if ((v = g_hash_table_lookup(keys, "MimeType"))) {
+            /* steal the string array */
+            link->d.app.mime = v->value.strings.a;
+            v->value.strings.a = NULL;
+            v->value.strings.n = 0;
+        }
     }
     else if (link->type == OBT_LINK_TYPE_URL) {
         v = g_hash_table_lookup(keys, "URL");
@@ -211,6 +217,7 @@ void obt_link_unref(ObtLink *dd)
         if (dd->type == OBT_LINK_TYPE_APPLICATION) {
             g_free(dd->d.app.exec);
             g_free(dd->d.app.wdir);
+            g_strfreev(dd->d.app.mime);
             g_free(dd->d.app.categories);
             g_free(dd->d.app.startup_wmclass);
         }
@@ -219,3 +226,13 @@ void obt_link_unref(ObtLink *dd)
         g_slice_free(ObtLink, dd);
     }
 }
+
+const GQuark* obt_link_app_categories(ObtLink *e, gulong *n)
+{
+    g_return_val_if_fail(e != NULL, NULL);
+    g_return_val_if_fail(e->type == OBT_LINK_TYPE_APPLICATION, NULL);
+    g_return_val_if_fail(n != NULL, NULL);
+
+    *n = e->d.app.n_categories;
+    return e->d.app.categories;
+}
This page took 0.024109 seconds and 4 git commands to generate.