1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 obt/link.c for the Openbox window manager
4 Copyright (c) 2009 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
20 #include "obt/ddparse.h"
21 #include "obt/paths.h"
28 gchar *name; /*!< Specific name for the object (eg Firefox) */
29 gboolean display; /*<! When false, do not display this link in menus or
31 gboolean deleted; /*<! When true, the Link could exist but is deleted
32 for the current user */
33 gchar *generic; /*!< Generic name for the object (eg Web Browser) */
34 gchar *comment; /*!< Comment/description to display for the object */
35 gchar *icon; /*!< Name/path for an icon for the object */
36 guint env_required; /*!< The environments that must be present to use this
38 guint env_restricted; /*!< The environments that must _not_ be present to
43 gchar *exec; /*!< Executable to run for the app */
44 gchar *wdir; /*!< Working dir to run the app in */
45 gboolean term; /*!< Run the app in a terminal or not */
48 /* XXX gchar**? or something better, a mime struct.. maybe
49 glib has something i can use. */
50 gchar **mime; /*!< Mime types the app can open */
52 ObtLinkAppStartup startup;
53 gchar *startup_wmclass;
63 ObtLink* obt_link_from_ddfile(const gchar *ddname, GSList *paths,
67 GHashTable *groups, *keys;
69 ObtDDParseValue *v, *type, *name, *target;
71 groups = obt_ddparse_file(ddname, paths);
72 if (!groups) return NULL;
73 g = g_hash_table_lookup(groups, "Desktop Entry");
75 g_hash_table_destroy(groups);
79 keys = obt_ddparse_group_keys(g);
81 /* check that required keys exist */
83 if (!(type = g_hash_table_lookup(keys, "Type")))
84 { g_hash_table_destroy(groups); return NULL; }
85 if (!(name = g_hash_table_lookup(keys, "Name")))
86 { g_hash_table_destroy(groups); return NULL; }
88 if (type->value.enumerable == OBT_LINK_TYPE_APPLICATION) {
89 if (!(target = g_hash_table_lookup(keys, "Exec")))
90 { g_hash_table_destroy(groups); return NULL; }
92 else if (type->value.enumerable == OBT_LINK_TYPE_URL) {
93 if (!(target = g_hash_table_lookup(keys, "URL")))
94 { g_hash_table_destroy(groups); return NULL; }
99 /* parse all the optional keys and build ObtLink (steal the strings) */
100 link = g_slice_new0(ObtLink);
102 link->type = type->value.enumerable;
103 if (link->type == OBT_LINK_TYPE_APPLICATION)
104 link->d.app.exec = target->value.string, target->value.string = NULL;
105 else if (link->type == OBT_LINK_TYPE_URL)
106 link->d.url.addr = target->value.string, target->value.string = NULL;
107 link->display = TRUE;
109 if ((v = g_hash_table_lookup(keys, "Hidden")))
110 link->deleted = v->value.boolean;
112 if ((v = g_hash_table_lookup(keys, "NoDisplay")))
113 link->display = !v->value.boolean;
115 if ((v = g_hash_table_lookup(keys, "GenericName")))
116 link->generic = v->value.string, v->value.string = NULL;
118 if ((v = g_hash_table_lookup(keys, "Comment")))
119 link->comment = v->value.string, v->value.string = NULL;
121 if ((v = g_hash_table_lookup(keys, "Icon")))
122 link->icon = v->value.string, v->value.string = NULL;
124 if ((v = g_hash_table_lookup(keys, "OnlyShowIn")))
125 link->env_required = v->value.environments;
127 link->env_required = 0;
129 if ((v = g_hash_table_lookup(keys, "NotShowIn")))
130 link->env_restricted = v->value.environments;
132 link->env_restricted = 0;
134 if (link->type == OBT_LINK_TYPE_APPLICATION) {
135 if ((v = g_hash_table_lookup(keys, "TryExec"))) {
136 /* XXX spawn a thread to check TryExec? */
137 link->display = link->display &&
138 obt_paths_try_exec(p, v->value.string);
141 /* XXX there's more app specific stuff */
144 else if (link->type == OBT_LINK_TYPE_URL) {
145 /* XXX there's URL specific stuff */
151 void obt_link_ref(ObtLink *dd)
156 void obt_link_unref(ObtLink *dd)
159 g_slice_free(ObtLink, dd);