grim/guifications3

removed some ENABLE_NLS wrappers

2011-05-17, Gary Kramlich
f31281edef1c
removed some ENABLE_NLS wrappers
/*
* Guifications - The end-all, be-all notification framework
* Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
*
* 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 3 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <gflib/gf_intl.h>
#include <gflib-ui/gf_theme.h>
#define GF_THEME_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GF_TYPE_THEME, GfThemePrivate))
/******************************************************************************
* Structs
*****************************************************************************/
typedef struct {
gchar *filename;
gchar *path;
GfThemeInfo *info;
GfThemeOptions *options;
GList *notifications;
} GfThemePrivate;
/******************************************************************************
* Enums
*****************************************************************************/
enum {
PROP_ZERO = 0,
PROP_FILENAME,
PROP_PATH,
PROP_INFO,
PROP_OPTIONS,
PROP_LAST
};
/******************************************************************************
* Globals
*****************************************************************************/
static GfObjectClass *parent_class = NULL;
/******************************************************************************
* Object stuff
*****************************************************************************/
static void
gf_theme_get_property(GObject *obj, guint param_id, GValue *value,
GParamSpec *psec)
{
GfTheme *theme = GF_THEME(obj);
switch(param_id) {
case PROP_FILENAME:
g_value_set_string(value, gf_theme_get_filename(theme));
break;
case PROP_PATH:
g_value_set_string(value, gf_theme_get_path(theme));
break;
case PROP_INFO:
g_value_set_object(value, gf_theme_get_theme_info(theme));
break;
case PROP_OPTIONS:
g_value_set_object(value, gf_theme_get_theme_options(theme));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
break;
}
}
static void
gf_theme_set_property(GObject *obj, guint param_id, const GValue *value,
GParamSpec *psec)
{
GfTheme *theme = GF_THEME(obj);
switch(param_id) {
case PROP_FILENAME:
gf_theme_set_filename(theme, g_value_get_string(value));
break;
case PROP_PATH:
gf_theme_set_path(theme, g_value_get_string(value));
break;
case PROP_INFO:
gf_theme_set_theme_info(theme, g_value_get_object(value));
break;
case PROP_OPTIONS:
gf_theme_set_theme_options(theme, g_value_get_object(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, psec);
break;
}
}
static void
gf_theme_finalize(GObject *obj) {
GfThemePrivate *priv = GF_THEME_GET_PRIVATE(obj);
GfNotification *notification;
GList *l;
for(l = priv->notifications; l; l = l->next) {
notification = GF_NOTIFICATION(l->data);
g_object_unref(G_OBJECT(notification));
}
g_free(priv->filename);
g_free(priv->path);
g_free(priv);
G_OBJECT_CLASS(parent_class)->finalize(obj);
}
static void
gf_theme_class_init(GfThemeClass *klass) {
GObjectClass *obj_class = G_OBJECT_CLASS(klass);
GParamSpec *pspec;
parent_class = g_type_class_peek_parent(klass);
obj_class->finalize = gf_theme_finalize;
obj_class->get_property = gf_theme_get_property;
obj_class->set_property = gf_theme_set_property;
g_type_class_add_private(klass, sizeof(GfThemePrivate));
pspec = g_param_spec_string("filename", P_("The theme filename"),
_("The filename for the theme."),
NULL, G_PARAM_READWRITE);
g_object_class_install_property(obj_class, PROP_FILENAME, pspec);
pspec = g_param_spec_string("path", P_("The path for the theme"),
P_("The path for the theme."),
NULL, G_PARAM_READWRITE);
g_object_class_install_property(obj_class, PROP_PATH, pspec);
pspec = g_param_spec_object("info", P_("The theme info"),
P_("The theme info."),
GF_TYPE_THEME_INFO, G_PARAM_READWRITE);
g_object_class_install_property(obj_class, PROP_INFO, pspec);
pspec = g_param_spec_object("options", P_("The theme options"),
P_("The theme options."),
GF_TYPE_THEME_OPTIONS, G_PARAM_READWRITE);
g_object_class_install_property(obj_class, PROP_OPTIONS, pspec);
}
/******************************************************************************
* API
*****************************************************************************/
GType
gf_theme_get_gtype(void) {
static GType type = 0;
if(type == 0) {
static const GTypeInfo info = {
sizeof(GfThemeClass),
NULL,
NULL,
(GClassInitFunc)gf_theme_class_init,
NULL,
NULL,
sizeof(GfTheme),
0,
NULL,
};
type = g_type_register_static(GF_TYPE_OBJECT,
"GfTheme",
&info, 0);
}
return type;
}
/**
* gf_theme_new:
*
* Creates a new #GfTheme instance.
*
* Return Value: The new #GfTheme instance.
*/
GfTheme *
gf_theme_new() {
return g_object_new(GF_TYPE_THEME, NULL);
}
/**
* gf_theme_set_filename:
* @theme : The #GfTheme instance.
* @filename : The new filename.
*
* Sets the filename for @theme.
*/
void
gf_theme_set_filename(GfTheme *theme, const gchar *filename) {
GfThemePrivate *priv = NULL;
g_return_if_fail(GF_IS_THEME(theme));
priv = GF_THEME_GET_PRIVATE(theme);
if(priv->filename)
g_free(priv->filename);
priv->filename = (filename) ? g_strdup(filename) : NULL;
g_object_notify(G_OBJECT(theme), "filename");
}
/**
* gf_theme_get_filename:
* @theme : The #GfTheme instance.
*
* Gets the filename for @theme.
*
* Return Value: The filename for @theme.
*/
const gchar *
gf_theme_get_filename(const GfTheme *theme) {
GfThemePrivate *priv = NULL;
g_return_val_if_fail(GF_IS_THEME(theme), NULL);
priv = GF_THEME_GET_PRIVATE(theme);
return priv->filename;
}
/**
* gf_theme_set_path:
* @theme : The #GfTheme instance.
* @path : The new path.
*
* Sets the path for @theme.
*/
void
gf_theme_set_path(GfTheme *theme, const gchar *path) {
GfThemePrivate *priv = NULL;
g_return_if_fail(GF_IS_THEME(theme));
priv = GF_THEME_GET_PRIVATE(theme);
if(priv->path)
g_free(priv->path);
priv->path = (path) ? g_strdup(path) : NULL;
g_object_notify(G_OBJECT(theme), "path");
}
/**
* gf_theme_get_path:
* @theme : The #GfTheme instance.
*
* Gets the path for @theme.
*
* Return Value: The path for @theme.
*/
const gchar *
gf_theme_get_path(const GfTheme *theme) {
GfThemePrivate *priv = NULL;
g_return_val_if_fail(GF_IS_THEME(theme), NULL);
priv = GF_THEME_GET_PRIVATE(theme);
return priv->path;
}
/**
* gf_theme_set_theme_info:
* @theme : The #GfTheme instance.
* @theme_info : The #GfThemeInfo instance.
*
* Sets the #GfThemeInfo for @theme.
*/
void
gf_theme_set_theme_info(GfTheme *theme, GfThemeInfo *theme_info) {
GfThemePrivate *priv = NULL;
g_return_if_fail(GF_IS_THEME(theme));
priv = GF_THEME_GET_PRIVATE(theme);
if(priv->info == theme_info)
return;
if(GF_IS_THEME_INFO(priv->info))
g_object_unref(G_OBJECT(priv->info));
priv->info = theme_info;
if(GF_IS_THEME_INFO(priv->info))
g_object_ref(G_OBJECT(priv->info));
g_object_notify(G_OBJECT(theme), "info");
}
/**
* gf_theme_get_theme_info:
* @theme : The #GfTheme instance.
*
* Gets the #GfThemeInfo for @theme.
*
* Return Value: The #GfThemeInfo for @theme.
*/
GfThemeInfo *
gf_theme_get_theme_info(const GfTheme *theme) {
GfThemePrivate *priv = NULL;
g_return_val_if_fail(GF_IS_THEME(theme), NULL);
priv = GF_THEME_GET_PRIVATE(theme);
return priv->info;
}
/**
* gf_theme_set_theme_options:
* @theme : The #GfTheme instance.
* @theme_options : The #GfThemeOptions instance.
*
* Sets the #GfThemeOptions for @theme.
*/
void
gf_theme_set_theme_options(GfTheme *theme, GfThemeOptions *theme_options) {
GfThemePrivate *priv = NULL;
g_return_if_fail(GF_IS_THEME(theme));
priv = GF_THEME_GET_PRIVATE(theme);
if(priv->options == theme_options)
return;
if(GF_IS_THEME_OPTIONS(priv->options))
g_object_unref(priv->options);
priv->options = theme_options;
if(GF_IS_THEME_OPTIONS(priv->options))
g_object_ref(priv->options);
g_object_notify(G_OBJECT(theme), "options");
}
/**
* gf_theme_get_theme_options:
* @theme : The #GfTheme instance.
*
* Gets the #GfThemeOptions for @theme.
*
* Return Value: The #GfThemeOptions for @theme.
*/
GfThemeOptions *
gf_theme_get_theme_options(const GfTheme *theme) {
GfThemePrivate *priv = NULL;
g_return_val_if_fail(GF_IS_THEME(theme), NULL);
priv = GF_THEME_GET_PRIVATE(theme);
return priv->options;
}
/**
* gf_theme_add_notification:
* @theme : The #GfTheme instance.
* @notification : The #GfNotification instance.
*
* Adds a #GfNotification to @theme.
*
* Note: @theme will add a reference to @notification, it will not inherit
* your reference!
*/
void
gf_theme_add_notification(GfTheme *theme, GfNotification *notification) {
GfThemePrivate *priv = NULL;
g_return_if_fail(GF_IS_THEME(theme));
g_return_if_fail(GF_IS_NOTIFICATION(notification));
priv = GF_THEME_GET_PRIVATE(theme);
priv->notifications = g_list_append(priv->notifications, notification);
g_object_ref(G_OBJECT(notification));
}
/**
* gf_theme_remove_notification:
* @theme : The #GfTheme instance.
* @notification : The #GfNotification instance.
*
* Removes a #GfNotification from @theme.
*
* Note: @theme will remove it's reference to @notification, which could cause
* @notification to be destoryed. If you want to keep @notification
* around longer, you will need to reference it.
*/
void
gf_theme_remove_notification(GfTheme *theme, GfNotification *notification) {
GfThemePrivate *priv = NULL;
g_return_if_fail(GF_IS_THEME(theme));
g_return_if_fail(GF_IS_NOTIFICATION(notification));
priv = GF_THEME_GET_PRIVATE(theme);
if(g_list_find(priv->notifications, notification)) {
priv->notifications = g_list_remove(priv->notifications, notification);
g_object_unref(G_OBJECT(notification));
}
}
void
gf_theme_enum_notifications(GfTheme *theme,
GfThemeEnumNotificationsCB callback)
{
GfThemePrivate *priv = NULL;
GfNotification *notification;
GList *l;
g_return_if_fail(GF_IS_THEME(theme));
priv = GF_THEME_GET_PRIVATE(theme);
for(l = priv->notifications; l; l = l->next) {
notification = GF_NOTIFICATION(l->data);
callback(theme, notification);
}
}