grim/guifications3
Clone
Summary
Browse
Changes
Graph
moved guifications-gtk to cmake
cmake
2010-12-13, Gary Kramlich
36e02fafe588
moved guifications-gtk to cmake
/*
* 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/gf_event.h>
#define GF_EVENT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GF_TYPE_EVENT, GfEventPrivate))
/******************************************************************************
* Structs
*****************************************************************************/
typedef
struct
{
gchar
*
name
;
gchar
*
i18n
;
gchar
*
description
;
}
GfEventPrivate
;
/******************************************************************************
* Enums
*****************************************************************************/
enum
{
PROP_ZERO
=
0
,
PROP_NAME
,
PROP_I18N
,
PROP_DESCRIPTION
,
PROP_LAST
};
/******************************************************************************
* Globals
*****************************************************************************/
static
GfObjectClass
*
parent_class
=
NULL
;
/******************************************************************************
* Event stuff
*****************************************************************************/
static
gchar
*
gf_event_real_get_name
(
const
GfEvent
*
event
)
{
GfEventPrivate
*
priv
=
GF_EVENT_GET_PRIVATE
(
event
);
return
(
priv
->
name
)
?
g_strdup
(
priv
->
name
)
:
NULL
;
}
static
void
gf_event_set_name
(
GfEvent
*
event
,
const
gchar
*
name
)
{
GfEventPrivate
*
priv
=
GF_EVENT_GET_PRIVATE
(
event
);
priv
->
name
=
(
name
)
?
g_strdup
(
name
)
:
NULL
;
}
static
gchar
*
gf_event_real_get_i18n
(
const
GfEvent
*
event
)
{
GfEventPrivate
*
priv
=
GF_EVENT_GET_PRIVATE
(
event
);
return
(
priv
->
i18n
)
?
g_strdup
(
priv
->
i18n
)
:
NULL
;
}
static
void
gf_event_set_i18n
(
GfEvent
*
event
,
const
gchar
*
i18n
)
{
GfEventPrivate
*
priv
=
GF_EVENT_GET_PRIVATE
(
event
);
priv
->
i18n
=
(
i18n
)
?
g_strdup
(
i18n
)
:
NULL
;
}
static
gchar
*
gf_event_real_get_description
(
const
GfEvent
*
event
)
{
GfEventPrivate
*
priv
=
GF_EVENT_GET_PRIVATE
(
event
);
return
(
priv
->
description
)
?
g_strdup
(
priv
->
description
)
:
NULL
;
}
static
void
gf_event_set_description
(
GfEvent
*
event
,
const
gchar
*
description
)
{
GfEventPrivate
*
priv
=
GF_EVENT_GET_PRIVATE
(
event
);
priv
->
description
=
(
description
)
?
g_strdup
(
description
)
:
NULL
;
}
/******************************************************************************
* Object stuff
*****************************************************************************/
static
void
gf_event_get_property
(
GObject
*
obj
,
guint
param_id
,
GValue
*
value
,
GParamSpec
*
psec
)
{
GfEvent
*
event
=
GF_EVENT
(
obj
);
switch
(
param_id
)
{
case
PROP_NAME
:
g_value_set_string
(
value
,
gf_event_get_name
(
event
));
break
;
case
PROP_I18N
:
g_value_set_string
(
value
,
gf_event_get_i18n
(
event
));
break
;
case
PROP_DESCRIPTION
:
g_value_set_string
(
value
,
gf_event_get_description
(
event
));
break
;
default
:
G_OBJECT_WARN_INVALID_PROPERTY_ID
(
obj
,
param_id
,
psec
);
break
;
}
}
static
void
gf_event_set_property
(
GObject
*
obj
,
guint
param_id
,
const
GValue
*
value
,
GParamSpec
*
psec
)
{
GfEvent
*
event
=
GF_EVENT
(
obj
);
switch
(
param_id
)
{
case
PROP_NAME
:
gf_event_set_name
(
event
,
g_value_get_string
(
value
));
break
;
case
PROP_I18N
:
gf_event_set_i18n
(
event
,
g_value_get_string
(
value
));
break
;
case
PROP_DESCRIPTION
:
gf_event_set_description
(
event
,
g_value_get_string
(
value
));
break
;
default
:
G_OBJECT_WARN_INVALID_PROPERTY_ID
(
obj
,
param_id
,
psec
);
break
;
}
}
static
void
gf_event_finalize
(
GObject
*
obj
)
{
GfEventPrivate
*
priv
=
GF_EVENT_GET_PRIVATE
(
obj
);
g_free
(
priv
->
name
);
g_free
(
priv
->
i18n
);
g_free
(
priv
->
description
);
G_OBJECT_CLASS
(
parent_class
)
->
finalize
(
obj
);
}
static
void
gf_event_class_init
(
GfEventClass
*
klass
)
{
GObjectClass
*
obj_class
=
G_OBJECT_CLASS
(
klass
);
parent_class
=
g_type_class_peek_parent
(
klass
);
g_type_class_add_private
(
klass
,
sizeof
(
GfEventPrivate
));
obj_class
->
finalize
=
gf_event_finalize
;
obj_class
->
get_property
=
gf_event_get_property
;
obj_class
->
set_property
=
gf_event_set_property
;
klass
->
get_name
=
gf_event_real_get_name
;
klass
->
get_i18n
=
gf_event_real_get_i18n
;
klass
->
get_description
=
gf_event_real_get_description
;
g_object_class_install_property
(
obj_class
,
PROP_NAME
,
g_param_spec_string
(
"name"
,
P_
(
"name"
),
P_
(
"The name of the event"
),
NULL
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT_ONLY
));
g_object_class_install_property
(
obj_class
,
PROP_I18N
,
g_param_spec_string
(
"i18n"
,
P_
(
"i18n"
),
P_
(
"The translated name of the event."
),
NULL
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT_ONLY
));
g_object_class_install_property
(
obj_class
,
PROP_DESCRIPTION
,
g_param_spec_string
(
"description"
,
P_
(
"description"
),
P_
(
"The description for the event"
),
NULL
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT_ONLY
));
}
/******************************************************************************
* API
*****************************************************************************/
GType
gf_event_get_type
(
void
)
{
static
GType
type
=
0
;
if
(
type
==
0
)
{
static
const
GTypeInfo
info
=
{
sizeof
(
GfEventClass
),
NULL
,
NULL
,
(
GClassInitFunc
)
gf_event_class_init
,
NULL
,
NULL
,
sizeof
(
GfEvent
),
0
,
NULL
,
NULL
};
type
=
g_type_register_static
(
GF_TYPE_OBJECT
,
"GfEvent"
,
&
info
,
0
);
}
return
type
;
}
/**
* gf_event_new:
* @name : The name of the #GfEvent.
* @i18n : The translated version of @name.
* @description : The description of the #GfEvent.
*
* Creates a new #GfEvent.
*
* Return Value: The new #GfEvent or NULL.
*/
GfEvent
*
gf_event_new
(
const
gchar
*
name
,
const
gchar
*
i18n
,
const
gchar
*
description
)
{
g_return_val_if_fail
(
name
,
NULL
);
g_return_val_if_fail
(
i18n
,
NULL
);
return
g_object_new
(
GF_TYPE_EVENT
,
"name"
,
name
,
"i18n"
,
i18n
,
"description"
,
description
,
NULL
);
}
/**
* gf_event_get_name:
* @event : The #GfEvent instance.
*
* Gets the name from @event.
*
* Return Value: The name of @event or NULL.
*/
gchar
*
gf_event_get_name
(
const
GfEvent
*
event
)
{
GfEventClass
*
klass
=
NULL
;
g_return_val_if_fail
(
GF_IS_EVENT
(
event
),
NULL
);
klass
=
GF_EVENT_GET_CLASS
(
event
);
if
(
klass
&&
klass
->
get_name
)
return
klass
->
get_name
(
event
);
return
NULL
;
}
/**
* gf_event_get_i18n:
* @event : The #GfEvent instance.
*
* Gets the translated name from @event.
*
* Return Value: The translated name of @event or NULL.
*/
gchar
*
gf_event_get_i18n
(
const
GfEvent
*
event
)
{
GfEventClass
*
klass
=
NULL
;
g_return_val_if_fail
(
GF_IS_EVENT
(
event
),
NULL
);
klass
=
GF_EVENT_GET_CLASS
(
event
);
if
(
klass
&&
klass
->
get_i18n
)
return
klass
->
get_i18n
(
event
);
return
NULL
;
}
/**
* gf_event_get_description:
* @event : The #GfEvent instance.
*
* Gets the description of @event.
*
* Return Value: The description of @event or NULL.
*/
gchar
*
gf_event_get_description
(
const
GfEvent
*
event
)
{
GfEventClass
*
klass
=
NULL
;
g_return_val_if_fail
(
GF_IS_EVENT
(
event
),
NULL
);
klass
=
GF_EVENT_GET_CLASS
(
event
);
if
(
klass
&&
klass
->
get_description
)
return
klass
->
get_description
(
event
);
return
NULL
;
}
/**
* gf_event_freev:
* @events : The array of #GfEvent's to free.
*
* Frees and array of #GfEvent's.
*/
void
gf_event_freev
(
GfEvent
**
events
)
{
gint
i
;
for
(
i
=
0
;
events
[
i
];
i
++
)
{
if
(
GF_IS_EVENT
(
events
[
i
]))
g_object_unref
(
events
[
i
]);
}
g_free
(
events
);
}