/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- obt/link.c for the Openbox window manager Copyright (c) 2009 Dana Jansens This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. See the COPYING file for a copy of the GNU General Public License. */ #include "obt/link.h" #include "obt/ddparse.h" #include "obt/paths.h" #include struct _ObtLink { guint ref; ObtLinkType type; gchar *name; /*!< Specific name for the object (eg Firefox) */ gboolean display; /*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) { ++dd->ref; } void obt_link_unref(ObtLink *dd) { if (--dd->ref < 1) { g_slice_free(ObtLink, dd); } }