From 194663e06c6b538638c527678e29b3d84383b547 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Thu, 21 Jan 2010 13:38:26 +0100 Subject: Rip most sbitem code into seperate file for refactoring --- src/sbitem.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/sbitem.c (limited to 'src/sbitem.c') diff --git a/src/sbitem.c b/src/sbitem.c new file mode 100644 index 0000000..a53949e --- /dev/null +++ b/src/sbitem.c @@ -0,0 +1,108 @@ +/** + * sbitem.c + * SpringBoard Item representation + * + * Copyright (C) 2009-2010 Nikias Bassen + * Copyright (C) 2009-2010 Martin Szulecki + * + * Licensed under the GNU General Public License Version 2 + * + * 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 profile. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include + +#include "sbitem.h" + +char *sbitem_get_display_name(SBItem *item) +{ + char *strval = NULL; + plist_t node = plist_dict_get_item(item->node, "displayName"); + if (node && plist_get_node_type(node) == PLIST_STRING) { + plist_get_string_val(node, &strval); + } + return strval; +} + + +char *sbitem_get_display_identifier(SBItem *item) +{ + char *strval = NULL; + plist_t node = plist_dict_get_item(item->node, "displayIdentifier"); + if (node && plist_get_node_type(node) == PLIST_STRING) { + plist_get_string_val(node, &strval); + } + return strval; +} + +SBItem *sbitem_new(plist_t icon_info) +{ + SBItem *item = NULL; + + if (plist_get_node_type(icon_info) != PLIST_DICT) { + return item; + } + + item = g_new0(SBItem, 1); + item->node = plist_copy(icon_info); + item->texture = NULL; + item->is_dock_item = FALSE; + + return item; +} + +void sbitem_free(SBItem *item) +{ + if (item) { + if (item->node) { + plist_free(item->node); + } + if (item->texture && CLUTTER_IS_ACTOR(item->texture)) { + ClutterActor *parent = clutter_actor_get_parent(item->texture); + if (parent) { + clutter_actor_destroy(parent); + item->texture = NULL; + item->label = NULL; + } else { + clutter_actor_destroy(item->texture); + item->texture = NULL; + } + } + if (item->label && CLUTTER_IS_ACTOR(item->label)) { + clutter_actor_destroy(item->label); + item->label = NULL; + } + free(item); + } +} + +void g_func_sbitem_free(SBItem *item, gpointer data) +{ + sbitem_free(item); +} + +char *sbitem_get_icon_filename(SBItem *item) +{ + char *value = sbitem_get_display_identifier(item); + if (!value) + return NULL; + + return g_strdup_printf("/tmp/%s.png", value); +} -- cgit v1.1-32-gdbae