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 */
39 gchar *exec; /*!< Executable to run for the app */
40 gchar *wdir; /*!< Working dir to run the app in */
41 gboolean term; /*!< Run the app in a terminal or not */
44 /* XXX gchar**? or something better, a mime struct.. maybe
45 glib has something i can use. */
46 gchar **mime; /*!< Mime types the app can open */
48 ObtLinkAppStartup startup;
49 gchar *startup_wmclass;
59 ObtLink* obt_link_from_ddfile(const gchar *ddname, GSList *paths,
63 GHashTable *groups, *keys;
65 ObtDDParseValue *v, *type, *name, *target;
67 groups = obt_ddparse_file(ddname, paths);
68 if (!groups) return NULL;
69 g = g_hash_table_lookup(groups, "Desktop Entry");
71 g_hash_table_destroy(groups);
75 keys = obt_ddparse_group_keys(g);
77 /* check that required keys exist */
79 if (!(type = g_hash_table_lookup(keys, "Type")))
80 { g_hash_table_destroy(groups); return NULL; }
81 if (!(name = g_hash_table_lookup(keys, "Name")))
82 { g_hash_table_destroy(groups); return NULL; }
84 if (type->value.enumerable == OBT_LINK_TYPE_APPLICATION) {
85 if (!(target = g_hash_table_lookup(keys, "Exec")))
86 { g_hash_table_destroy(groups); return NULL; }
88 else if (type->value.enumerable == OBT_LINK_TYPE_URL) {
89 if (!(target = g_hash_table_lookup(keys, "URL")))
90 { g_hash_table_destroy(groups); return NULL; }
95 /* parse all the optional keys and build ObtLink (steal the strings) */
96 link = g_slice_new0(ObtLink);
98 link->type = type->value.enumerable;
99 if (link->type == OBT_LINK_TYPE_APPLICATION)
100 link->d.app.exec = target->value.string, target->value.string = NULL;
101 else if (link->type == OBT_LINK_TYPE_URL)
102 link->d.url.addr = target->value.string, target->value.string = NULL;
103 link->display = TRUE;
105 if ((v = g_hash_table_lookup(keys, "Hidden")))
106 link->deleted = v->value.boolean;
108 if ((v = g_hash_table_lookup(keys, "NoDisplay")))
109 link->display = !v->value.boolean;
111 if ((v = g_hash_table_lookup(keys, "GenericName")))
112 link->generic = v->value.string, v->value.string = NULL;
114 if ((v = g_hash_table_lookup(keys, "Comment")))
115 link->comment = v->value.string, v->value.string = NULL;
117 if ((v = g_hash_table_lookup(keys, "Icon")))
118 link->icon = v->value.string, v->value.string = NULL;
120 /* XXX handle Only/NotShowIn, better know the current environment */
122 if (link->type == OBT_LINK_TYPE_APPLICATION) {
123 if ((v = g_hash_table_lookup(keys, "TryExec"))) {
124 /* XXX spawn a thread to check TryExec? */
125 link->display = link->display &&
126 obt_paths_try_exec(p, v->value.string);
129 /* XXX there's more app specific stuff */
132 else if (link->type == OBT_LINK_TYPE_URL) {
133 /* XXX there's URL specific stuff */
139 void obt_link_ref(ObtLink *dd)
144 void obt_link_unref(ObtLink *dd)
147 g_slice_free(ObtLink, dd);