1
/*
2
 * This file is part of libhildondesktop
3
 *
4
 * Copyright (C) 2008 Nokia Corporation.
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public License
8
 * as published by the Free Software Foundation; either version 2.1 of
9
 * the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful, but
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19
 * 02110-1301 USA
20
 *
21
 */
22
23
#ifdef HAVE_CONFIG_H
24
#include <config.h>
25
#endif
26
27
#include "hd-plugin-module.h"
28
29
#include "hd-plugin-item.h"
30
31
/** 
32
 * SECTION:hd-plugin-item
33
 * @short_description: Base interface for plugable items.
34
 * @include: libhildondesktop/libhildondesktop.h
35
 *
36
 * #HDPluginItem is a base interface for plugable items. It defines functions properties
37
 * which are basically only useful for the Hildon desktop itself and not for widget/plugin
38
 * developers.
39
 *
40
 * It defines a hd_plugin_item_get_dl_filename() function which returns the filename of
41
 * the dynamic library for debugging purposes.
42
 *
43
 * It defines the #HDPluginItem::plugin-id property
44
 * for the unique plugin ID which is used internally by the Hildon Desktop to identify widget/plugins. It is
45
 * usually not used by widget/plugin developers.
46
 *
47
 * And it defines a hd_plugin_item_load_desktop_file() function for internal use by the Hildon desktop. 
48
 **/
49
50
static void
51
hd_plugin_item_class_init (gpointer g_iface)
52
{
53
  g_object_interface_install_property (g_iface,
54
                                       g_param_spec_string ("plugin-id",
55
                                                            "Plugin id",
56
                                                            "The id to identify the plugin item (used " \
57
                                                            "internally by the Hildon desktop to identify " \
58
                                                            "widgets/plugins. It is usually not used by " \
59
                                                            "widget/plugin developers)",
60
                                                            NULL,
61
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
62
}
63
64
GType
65
hd_plugin_item_get_type (void)
66
{
67
  static GType plugin_item_type = 0;
68
69
  if (!plugin_item_type)
70
    {
71
      plugin_item_type = g_type_register_static_simple (G_TYPE_INTERFACE,
72
                                                        "HDPluginItem",
73
                                                        sizeof (HDPluginItemIface),
74
                                                        (GClassInitFunc) hd_plugin_item_class_init,
75
                                                        0, NULL, 0);
76
77
      g_type_interface_add_prerequisite (plugin_item_type, G_TYPE_OBJECT);
78
    }
79
80
  return plugin_item_type;
81
}
82
83
/**
84
 * hd_plugin_item_get_plugin_id:
85
 * @item: a #HDPluginItem.
86
 *
87
 * Returns the unique plugin ID of @item.
88
 *
89
 * It is used internally by the Hildon desktop to identify widgets/plugins. It is usually 
90
 * not used by widget/plugin developers.
91
 * 
92
 * Returns: the plugin ID. The result should be freed if no longer used.
93
 **/
94
gchar *
95
hd_plugin_item_get_plugin_id (HDPluginItem *item)
96
{
97
  gchar *plugin_id;
98
99
  g_return_val_if_fail (HD_IS_PLUGIN_ITEM (item), NULL);
100
101
  g_object_get (G_OBJECT (item),
102
                "plugin-id", &plugin_id,
103
                NULL);
104
105
  return plugin_id;
106
}
107
108
/**
109
 * hd_plugin_item_get_dl_filename:
110
 * @item: a #HDPluginItem.
111
 *
112
 * Returns the filename of the dynamic library file from which this item was loaded.
113
 * Useful for debugging purposes.
114
 *
115
 * Returns: filename of the dynamic library file. The result must not be freed. 
116
 **/
117
const gchar *
118
hd_plugin_item_get_dl_filename (HDPluginItem *item)
119
{
120
  static GQuark dl_filename_quark = 0;
121
  GType type;
122
123
  g_return_val_if_fail (HD_IS_PLUGIN_ITEM (item), NULL);
124
125
  /* Create hd-plugin-module-dl-filename quark */
126
  if (G_UNLIKELY (!dl_filename_quark))
127
    dl_filename_quark = g_quark_from_static_string (HD_PLUGIN_MODULE_DL_FILENAME);
128
129
  /* The dl filename is stored in the type data */
130
  type = G_TYPE_FROM_INSTANCE (item);
131
  return g_type_get_qdata (type, dl_filename_quark);
132
}
133
134
/**
135
 * hd_plugin_item_load_desktop_file:
136
 * @item: a #HDPluginItem.
137
 * @key_file: the plugins .desktop #GKeyFile
138
 *
139
 * Used internally by the Hildon desktop to load additional keys from
140
 * the plugins .desktop file.
141
 **/
142
void
143
hd_plugin_item_load_desktop_file (HDPluginItem *item,
144
                                  GKeyFile     *key_file)
145
{
146
  HDPluginItemIface *iface;
147
148
  g_return_if_fail (HD_IS_PLUGIN_ITEM (item));
149
  
150
  iface = HD_PLUGIN_ITEM_GET_IFACE (item);
151
152
  if (iface->load_desktop_file)
153
    iface->load_desktop_file (item, key_file);
154
}