mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-16 12:28:48 +02:00
Add properties to make bindings happy. (#517676, Samuel Cormier-Iijima)
2008-03-10 Matthias Clasen <mclasen@redhat.com> * gthemedicon.c: Add properties to make bindings happy. (#517676, Samuel Cormier-Iijima) svn path=/trunk/; revision=6655
This commit is contained in:
parent
b85f7190da
commit
83ba7b5fba
@ -1,3 +1,8 @@
|
|||||||
|
2008-03-10 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* gthemedicon.c: Add properties to make bindings happy. (#517676,
|
||||||
|
Samuel Cormier-Iijima)
|
||||||
|
|
||||||
2008-03-08 Tor Lillqvist <tml@novell.com>
|
2008-03-08 Tor Lillqvist <tml@novell.com>
|
||||||
|
|
||||||
* glocalfile.c: Define FILE_READ_ONLY_VOLUME if it is missing from
|
* glocalfile.c: Define FILE_READ_ONLY_VOLUME if it is missing from
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "gthemedicon.h"
|
#include "gthemedicon.h"
|
||||||
|
#include "glibintl.h"
|
||||||
|
|
||||||
#include "gioalias.h"
|
#include "gioalias.h"
|
||||||
|
|
||||||
@ -49,7 +50,8 @@ struct _GThemedIcon
|
|||||||
{
|
{
|
||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
|
|
||||||
char **names;
|
char **names;
|
||||||
|
gboolean use_default_fallbacks;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GThemedIconClass
|
struct _GThemedIconClass
|
||||||
@ -57,10 +59,106 @@ struct _GThemedIconClass
|
|||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_NAME,
|
||||||
|
PROP_NAMES,
|
||||||
|
PROP_USE_DEFAULT_FALLBACKS
|
||||||
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (GThemedIcon, g_themed_icon, G_TYPE_OBJECT,
|
G_DEFINE_TYPE_WITH_CODE (GThemedIcon, g_themed_icon, G_TYPE_OBJECT,
|
||||||
G_IMPLEMENT_INTERFACE (G_TYPE_ICON,
|
G_IMPLEMENT_INTERFACE (G_TYPE_ICON,
|
||||||
g_themed_icon_icon_iface_init))
|
g_themed_icon_icon_iface_init))
|
||||||
|
|
||||||
|
static void
|
||||||
|
g_themed_icon_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GThemedIcon *icon = G_THEMED_ICON (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_NAMES:
|
||||||
|
g_value_set_boxed (value, icon->names);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
g_themed_icon_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GThemedIcon *icon = G_THEMED_ICON (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_NAME:
|
||||||
|
if (icon->names)
|
||||||
|
g_strfreev (icon->names);
|
||||||
|
icon->names = g_new (char *, 2);
|
||||||
|
icon->names[0] = g_value_dup_string (value);
|
||||||
|
icon->names[1] = NULL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_NAMES:
|
||||||
|
if (icon->names)
|
||||||
|
g_strfreev (icon->names);
|
||||||
|
icon->names = g_value_dup_boxed (value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_USE_DEFAULT_FALLBACKS:
|
||||||
|
icon->use_default_fallbacks = g_value_get_boolean (value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
g_themed_icon_constructed (GObject *object)
|
||||||
|
{
|
||||||
|
GThemedIcon *themed = G_THEMED_ICON (object);
|
||||||
|
|
||||||
|
g_return_if_fail (themed->names != NULL && themed->names[0] != NULL);
|
||||||
|
|
||||||
|
if (themed->use_default_fallbacks)
|
||||||
|
{
|
||||||
|
int i = 0, dashes = 0;
|
||||||
|
const char *p;
|
||||||
|
char *dashp;
|
||||||
|
char *last;
|
||||||
|
|
||||||
|
p = themed->names[0];
|
||||||
|
while (*p)
|
||||||
|
{
|
||||||
|
if (*p == '-')
|
||||||
|
dashes++;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
last = g_strdup (themed->names[0]);
|
||||||
|
|
||||||
|
g_strfreev (themed->names);
|
||||||
|
|
||||||
|
themed->names = g_new (char *, dashes + 1 + 1);
|
||||||
|
themed->names[i++] = last;
|
||||||
|
|
||||||
|
while ((dashp = strrchr (last, '-')) != NULL)
|
||||||
|
themed->names[i++] = last = g_strndup (last, dashp - last);
|
||||||
|
|
||||||
|
themed->names[i++] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_themed_icon_finalize (GObject *object)
|
g_themed_icon_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
@ -80,11 +178,65 @@ g_themed_icon_class_init (GThemedIconClass *klass)
|
|||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
gobject_class->finalize = g_themed_icon_finalize;
|
gobject_class->finalize = g_themed_icon_finalize;
|
||||||
|
gobject_class->constructed = g_themed_icon_constructed;
|
||||||
|
gobject_class->set_property = g_themed_icon_set_property;
|
||||||
|
gobject_class->get_property = g_themed_icon_get_property;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GThemedIcon:name:
|
||||||
|
*
|
||||||
|
* The icon name.
|
||||||
|
*/
|
||||||
|
g_object_class_install_property (gobject_class, PROP_NAMES,
|
||||||
|
g_param_spec_string ("name",
|
||||||
|
_("name"),
|
||||||
|
_("The name of the icon"),
|
||||||
|
NULL,
|
||||||
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GThemedIcon:names:
|
||||||
|
*
|
||||||
|
* A %NULL-terminated array of icon names.
|
||||||
|
*/
|
||||||
|
g_object_class_install_property (gobject_class, PROP_NAMES,
|
||||||
|
g_param_spec_boxed ("names",
|
||||||
|
_("names"),
|
||||||
|
_("An array containing the icon names"),
|
||||||
|
G_TYPE_STRV,
|
||||||
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GThemedIcon:use-default-fallbacks:
|
||||||
|
*
|
||||||
|
* Whether to use the default fallbacks found by shortening the icon name
|
||||||
|
* at '-' characters. If the "names" array has more than one element,
|
||||||
|
* ignores any past the first.
|
||||||
|
*
|
||||||
|
* For example, if the icon name was "gnome-dev-cdrom-audio", the array
|
||||||
|
* would become
|
||||||
|
* |[
|
||||||
|
* {
|
||||||
|
* "gnome-dev-cdrom-audio",
|
||||||
|
* "gnome-dev-cdrom",
|
||||||
|
* "gnome-dev",
|
||||||
|
* "gnome",
|
||||||
|
* NULL
|
||||||
|
* };
|
||||||
|
* ]|
|
||||||
|
*/
|
||||||
|
g_object_class_install_property (gobject_class, PROP_USE_DEFAULT_FALLBACKS,
|
||||||
|
g_param_spec_boolean ("use-default-fallbacks",
|
||||||
|
_("use default fallbacks"),
|
||||||
|
_("Whether to use default fallbacks found by shortening the name at '-' characters. Ignores names after the first if multiple names are given."),
|
||||||
|
FALSE,
|
||||||
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_themed_icon_init (GThemedIcon *themed)
|
g_themed_icon_init (GThemedIcon *themed)
|
||||||
{
|
{
|
||||||
|
themed->names = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,49 +250,49 @@ g_themed_icon_init (GThemedIcon *themed)
|
|||||||
GIcon *
|
GIcon *
|
||||||
g_themed_icon_new (const char *iconname)
|
g_themed_icon_new (const char *iconname)
|
||||||
{
|
{
|
||||||
GThemedIcon *themed;
|
|
||||||
|
|
||||||
g_return_val_if_fail (iconname != NULL, NULL);
|
g_return_val_if_fail (iconname != NULL, NULL);
|
||||||
|
|
||||||
themed = g_object_new (G_TYPE_THEMED_ICON, NULL);
|
return G_ICON (g_object_new (G_TYPE_THEMED_ICON, "name", iconname, NULL));
|
||||||
themed->names = g_new (char *, 2);
|
|
||||||
themed->names[0] = g_strdup (iconname);
|
|
||||||
themed->names[1] = NULL;
|
|
||||||
|
|
||||||
return G_ICON (themed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_themed_icon_new_from_names:
|
* g_themed_icon_new_from_names:
|
||||||
* @iconnames: an array of strings containing icon names.
|
* @iconnames: an array of strings containing icon names.
|
||||||
* @len: the number of elements in the @iconnames array.
|
* @len: the length of the @iconnames array, or -1 if @iconnames is
|
||||||
|
* %NULL-terminated
|
||||||
*
|
*
|
||||||
* Creates a new themed icon for @iconnames.
|
* Creates a new themed icon for @iconnames.
|
||||||
*
|
*
|
||||||
* Returns: a new #GThemedIcon.
|
* Returns: a new #GThemedIcon
|
||||||
**/
|
**/
|
||||||
GIcon *
|
GIcon *
|
||||||
g_themed_icon_new_from_names (char **iconnames,
|
g_themed_icon_new_from_names (char **iconnames,
|
||||||
int len)
|
int len)
|
||||||
{
|
{
|
||||||
GThemedIcon *themed;
|
GIcon *icon = icon;
|
||||||
int i;
|
|
||||||
|
|
||||||
g_return_val_if_fail (iconnames != NULL, NULL);
|
g_return_val_if_fail (iconnames != NULL, NULL);
|
||||||
|
|
||||||
themed = g_object_new (G_TYPE_THEMED_ICON, NULL);
|
if (len >= 0)
|
||||||
if (len == -1)
|
|
||||||
themed->names = g_strdupv (iconnames);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
themed->names = g_new (char *, len + 1);
|
char **names;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
names = g_malloc (len + 1);
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
themed->names[i] = g_strdup (iconnames[i]);
|
names[i] = iconnames[i];
|
||||||
themed->names[i] = NULL;
|
|
||||||
|
names[i] = NULL;
|
||||||
|
|
||||||
|
icon = G_ICON (g_object_new (G_TYPE_THEMED_ICON, "names", names, NULL));
|
||||||
|
|
||||||
|
g_free (names);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
icon = G_ICON (g_object_new (G_TYPE_THEMED_ICON, "names", iconnames, NULL));
|
||||||
return G_ICON (themed);
|
|
||||||
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,35 +320,9 @@ g_themed_icon_new_from_names (char **iconnames,
|
|||||||
GIcon *
|
GIcon *
|
||||||
g_themed_icon_new_with_default_fallbacks (const char *iconname)
|
g_themed_icon_new_with_default_fallbacks (const char *iconname)
|
||||||
{
|
{
|
||||||
GThemedIcon *themed;
|
|
||||||
int i, dashes;
|
|
||||||
const char *p;
|
|
||||||
char *dashp;
|
|
||||||
char *last;
|
|
||||||
|
|
||||||
g_return_val_if_fail (iconname != NULL, NULL);
|
g_return_val_if_fail (iconname != NULL, NULL);
|
||||||
|
|
||||||
themed = g_object_new (G_TYPE_THEMED_ICON, NULL);
|
|
||||||
|
|
||||||
dashes = 0;
|
return G_ICON (g_object_new (G_TYPE_THEMED_ICON, "name", iconname, "use-default-fallbacks", TRUE, NULL));
|
||||||
p = iconname;
|
|
||||||
while (*p)
|
|
||||||
{
|
|
||||||
if (*p == '-')
|
|
||||||
dashes++;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
themed->names = g_new (char *, dashes + 1 + 1);
|
|
||||||
i = 0;
|
|
||||||
themed->names[i++] = last = g_strdup (iconname);
|
|
||||||
|
|
||||||
while ((dashp = strrchr (last, '-')) != NULL)
|
|
||||||
themed->names[i++] = last = g_strndup (last, dashp - last);
|
|
||||||
|
|
||||||
themed->names[i++] = NULL;
|
|
||||||
|
|
||||||
return G_ICON (themed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -221,6 +347,11 @@ g_themed_icon_get_names (GThemedIcon *icon)
|
|||||||
* @iconname: name of icon to append to list of icons from within @icon.
|
* @iconname: name of icon to append to list of icons from within @icon.
|
||||||
*
|
*
|
||||||
* Append a name to the list of icons from within @icon.
|
* Append a name to the list of icons from within @icon.
|
||||||
|
*
|
||||||
|
* <note><para>
|
||||||
|
* Note that doing so invalidates the hash computed by prior calls
|
||||||
|
* to g_icon_hash().
|
||||||
|
* </para></note>
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
g_themed_icon_append_name (GThemedIcon *icon, const char *iconname)
|
g_themed_icon_append_name (GThemedIcon *icon, const char *iconname)
|
||||||
@ -234,6 +365,8 @@ g_themed_icon_append_name (GThemedIcon *icon, const char *iconname)
|
|||||||
icon->names = g_realloc (icon->names, sizeof (char*) * (num_names + 2));
|
icon->names = g_realloc (icon->names, sizeof (char*) * (num_names + 2));
|
||||||
icon->names[num_names] = g_strdup (iconname);
|
icon->names[num_names] = g_strdup (iconname);
|
||||||
icon->names[num_names + 1] = NULL;
|
icon->names[num_names + 1] = NULL;
|
||||||
|
|
||||||
|
g_object_notify (G_OBJECT (icon), "names");
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint
|
static guint
|
||||||
|
Loading…
x
Reference in New Issue
Block a user