Commit 45e7c85f authored by Jesse van den Kieboom's avatar Jesse van den Kieboom

Added gedit_message_bus_foreach and

	* gedit/gedit-message-bus.c:
	* gedit/gedit-message-bus.h:
	* gedit/gedit-message-type.c:
	* gedit/gedit-message-type.h:
	* docs/reference/gedit-sections.txt:
	
	Added gedit_message_bus_foreach and 
	gedit_message_type_is_valid_object_path API. Added checks for valid
	object paths.

svn path=/trunk/; revision=6807
parent 5eda1108
2009-01-05 Jesse van den Kieboom <jesse@icecrew.nl>
* gedit/gedit-message-bus.c:
* gedit/gedit-message-bus.h:
* gedit/gedit-message-type.c:
* gedit/gedit-message-type.h:
* docs/reference/gedit-sections.txt:
Added gedit_message_bus_foreach and
gedit_message_type_is_valid_object_path API. Added checks for valid
object paths.
2009-01-04 Ignacio Casal Quinteiro <nacho.resa@gmail.com>
* plugins/spell/gedit-spell-checker-language.c:
......
......@@ -142,6 +142,7 @@ gedit_message_bus_register
gedit_message_bus_unregister
gedit_message_bus_unregister_all
gedit_message_bus_is_registered
gedit_message_bus_foreach
gedit_message_bus_connect
gedit_message_bus_disconnect
gedit_message_bus_disconnect_by_func
......@@ -170,6 +171,7 @@ GeditMessageType
gedit_message_type_get_type
gedit_message_type_is_supported
gedit_message_type_identifier
gedit_message_type_is_valid_object_path
gedit_message_type_new
gedit_message_type_new_valist
gedit_message_type_ref
......
......@@ -624,6 +624,7 @@ gedit_message_bus_register (GeditMessageBus *bus,
GeditMessageType *message_type;
g_return_val_if_fail (GEDIT_IS_MESSAGE_BUS (bus), NULL);
g_return_val_if_fail (gedit_message_type_is_valid_object_path (object_path), NULL);
if (gedit_message_bus_is_registered (bus, object_path, method))
{
......@@ -642,11 +643,15 @@ gedit_message_bus_register (GeditMessageBus *bus,
va_end (var_args);
if (message_type)
{
g_hash_table_insert (bus->priv->types, identifier, message_type);
g_signal_emit (bus, message_bus_signals[REGISTERED], 0, message_type);
}
else
{
g_free (identifier);
}
g_signal_emit (bus, message_bus_signals[REGISTERED], 0, message_type);
return message_type;
}
......@@ -758,6 +763,44 @@ gedit_message_bus_is_registered (GeditMessageBus *bus,
return ret;
}
typedef struct
{
GeditMessageBusForeach func;
gpointer userdata;
} ForeachInfo;
static void
foreach_type (const gchar *key,
GeditMessageType *message_type,
ForeachInfo *info)
{
gedit_message_type_ref (message_type);
info->func (message_type, info->userdata);
gedit_message_type_unref (message_type);
}
/**
* gedit_message_bus_foreach:
* @bus: the #GeditMessagebus
* @func: the callback function
* @userdata: the user data to supply to the callback function
*
* Calls @func for each message type registered on the bus
*
*/
void
gedit_message_bus_foreach (GeditMessageBus *bus,
GeditMessageBusForeach func,
gpointer userdata)
{
ForeachInfo info = {func, userdata};
g_return_if_fail (GEDIT_IS_MESSAGE_BUS (bus));
g_return_if_fail (func != NULL);
g_hash_table_foreach (bus->priv->types, (GHFunc)foreach_type, &info);
}
/**
* gedit_message_bus_connect:
* @bus: a #GeditMessageBus
......
......@@ -28,7 +28,7 @@ struct _GeditMessageBus {
struct _GeditMessageBusClass {
GObjectClass parent_class;
void (*dispatch) (GeditMessageBus *bus,
void (*dispatch) (GeditMessageBus *bus,
GeditMessage *message);
void (*registered) (GeditMessageBus *bus,
GeditMessageType *message_type);
......@@ -36,10 +36,13 @@ struct _GeditMessageBusClass {
GeditMessageType *message_type);
};
typedef void (* GeditMessageCallback) (GeditMessageBus *bus,
typedef void (* GeditMessageCallback) (GeditMessageBus *bus,
GeditMessage *message,
gpointer userdata);
typedef void (* GeditMessageBusForeach) (GeditMessageType *message_type,
gpointer userdata);
GType gedit_message_bus_get_type (void) G_GNUC_CONST;
GeditMessageBus *gedit_message_bus_get_default (void);
......@@ -61,10 +64,13 @@ void gedit_message_bus_unregister (GeditMessageBus *bus,
void gedit_message_bus_unregister_all (GeditMessageBus *bus,
const gchar *object_path);
gboolean gedit_message_bus_is_registered (GeditMessageBus *bus,
gboolean gedit_message_bus_is_registered (GeditMessageBus *bus,
const gchar *object_path,
const gchar *method);
void gedit_message_bus_foreach (GeditMessageBus *bus,
GeditMessageBusForeach func,
gpointer userdata);
/* connecting to message events */
......
......@@ -136,6 +136,45 @@ gedit_message_type_identifier (const gchar *object_path,
return g_strconcat (object_path, ".", method, NULL);
}
/**
* gedit_message_type_is_valid_object_path:
* @object_path: the object path
*
* Returns whether @object_path is a valid object path
*
* Return value: %TRUE if @object_path is a valid object path
*
*/
gboolean
gedit_message_type_is_valid_object_path (const gchar *object_path)
{
if (!object_path)
return FALSE;
/* needs to start with / */
if (*object_path != '/')
return FALSE;
while (*object_path)
{
if (*object_path == '/')
{
++object_path;
if (!*object_path || !(g_ascii_isalpha (*object_path) || *object_path == '_'))
return FALSE;
}
else if (!(g_ascii_isalnum (*object_path) || *object_path == '_'))
{
return FALSE;
}
++object_path;
}
return TRUE;
}
/**
* gedit_message_type_is_supported:
* @type: the #GType
......@@ -209,6 +248,7 @@ gedit_message_type_new_valist (const gchar *object_path,
g_return_val_if_fail (object_path != NULL, NULL);
g_return_val_if_fail (method != NULL, NULL);
g_return_val_if_fail (gedit_message_type_is_valid_object_path (object_path), NULL);
message_type = g_new0(GeditMessageType, 1);
......
......@@ -18,46 +18,47 @@ typedef void (*GeditMessageTypeForeach) (const gchar *key,
typedef struct _GeditMessageType GeditMessageType;
GType gedit_message_type_get_type (void) G_GNUC_CONST;
GType gedit_message_type_get_type (void) G_GNUC_CONST;
gboolean gedit_message_type_is_supported (GType type);
gchar *gedit_message_type_identifier (const gchar *object_path,
const gchar *method);
gboolean gedit_message_type_is_supported (GType type);
gchar *gedit_message_type_identifier (const gchar *object_path,
const gchar *method);
gboolean gedit_message_type_is_valid_object_path (const gchar *object_path);
GeditMessageType *gedit_message_type_new (const gchar *object_path,
const gchar *method,
guint num_optional,
...) G_GNUC_NULL_TERMINATED;
GeditMessageType *gedit_message_type_new_valist (const gchar *object_path,
const gchar *method,
guint num_optional,
va_list va_args);
GeditMessageType *gedit_message_type_new (const gchar *object_path,
const gchar *method,
guint num_optional,
...) G_GNUC_NULL_TERMINATED;
GeditMessageType *gedit_message_type_new_valist (const gchar *object_path,
const gchar *method,
guint num_optional,
va_list va_args);
void gedit_message_type_set (GeditMessageType *message_type,
guint num_optional,
...) G_GNUC_NULL_TERMINATED;
void gedit_message_type_set_valist (GeditMessageType *message_type,
guint num_optional,
va_list va_args);
void gedit_message_type_set (GeditMessageType *message_type,
guint num_optional,
...) G_GNUC_NULL_TERMINATED;
void gedit_message_type_set_valist (GeditMessageType *message_type,
guint num_optional,
va_list va_args);
GeditMessageType *gedit_message_type_ref (GeditMessageType *message_type);
void gedit_message_type_unref (GeditMessageType *message_type);
GeditMessageType *gedit_message_type_ref (GeditMessageType *message_type);
void gedit_message_type_unref (GeditMessageType *message_type);
GeditMessage *gedit_message_type_instantiate_valist (GeditMessageType *message_type,
va_list va_args);
GeditMessage *gedit_message_type_instantiate (GeditMessageType *message_type,
...) G_GNUC_NULL_TERMINATED;
GeditMessage *gedit_message_type_instantiate (GeditMessageType *message_type,
...) G_GNUC_NULL_TERMINATED;
const gchar *gedit_message_type_get_object_path (GeditMessageType *message_type);
const gchar *gedit_message_type_get_method (GeditMessageType *message_type);
const gchar *gedit_message_type_get_object_path (GeditMessageType *message_type);
const gchar *gedit_message_type_get_method (GeditMessageType *message_type);
GType gedit_message_type_lookup (GeditMessageType *message_type,
const gchar *key);
GType gedit_message_type_lookup (GeditMessageType *message_type,
const gchar *key);
void gedit_message_type_foreach (GeditMessageType *message_type,
GeditMessageTypeForeach func,
gpointer user_data);
void gedit_message_type_foreach (GeditMessageType *message_type,
GeditMessageTypeForeach func,
gpointer user_data);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment