diff --git a/src/gm-world.c b/src/gm-world.c index ef92717..2d0365f 100644 --- a/src/gm-world.c +++ b/src/gm-world.c @@ -12,7 +12,8 @@ #include "gm-support.h" #include "gm-debug.h" -#define GM_WORLD_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GM_TYPE_WORLD, GmWorldPrivate)) +#define GM_WORLD_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), \ + GM_TYPE_WORLD, GmWorldPrivate)) void gm_world_save_input_history(GmWorld *world); void gm_world_load_input_history(GmWorld *world); @@ -33,6 +34,7 @@ struct _GmWorldPrivate { gboolean active; guint activity; gchar *buffer; + gchar *status; GmOptions *options; GmTriggers *triggers; @@ -58,7 +60,7 @@ enum { NAME_CHANGED, ACTIVE_CHANGED, ACTIVITY_CHANGED, - DELETE, + STATUS_CHANGED, NUM_SIGNALS }; @@ -86,7 +88,7 @@ gm_world_finalize(GObject *object) { g_free(world->priv->path); g_free(world->priv->buffer); - + g_free(world->priv->status); g_free(world->priv->editing_info.name); g_free(world->priv->editing_info.upload); g_list_free(world->priv->editing_info.lines); @@ -224,6 +226,17 @@ gm_world_class_init(GmWorldClass *klass) { 1, G_TYPE_INT); + world_signals[STATUS_CHANGED] = + g_signal_new("status_changed", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GmWorldClass, status_changed), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); + g_type_class_add_private(object_class, sizeof(GmWorldPrivate)); } @@ -261,6 +274,7 @@ gm_world_init(GmWorld *world) { world->priv->mcp = gm_mcp_session_new(G_OBJECT(world)); world->priv->buffer = NULL; world->priv->editing_info.is_editing = FALSE; + world->priv->status = NULL; g_signal_connect(world->priv->net, "state_changing", G_CALLBACK(on_gm_world_net_state_changing), world); @@ -641,8 +655,10 @@ gm_world_process_line(GmWorld *world, gchar *line) { gm_world_log(world, LOG_IN, non_text_start + 3); g_signal_emit(world, world_signals[TEXT_RECEIVED], 0, non_text_start + 3); + g_signal_emit(world, world_signals[TEXT_RECEIVED], 0, "\n"); } else { g_signal_emit(world, world_signals[TEXT_RECEIVED], 0, line); + g_signal_emit(world, world_signals[TEXT_RECEIVED], 0, "\n"); gm_world_log(world, LOG_IN, line); } } @@ -798,6 +814,20 @@ gm_world_name_changed(GmWorld *world) { gm_options_get(world->priv->options, "name")); } +void +gm_world_set_status(GmWorld *world, gchar const *status) { + g_free(world->priv->status); + world->priv->status = g_strdup(status); + + g_signal_emit(world, world_signals[STATUS_CHANGED], 0, + world->priv->status); +} + +gchar const * +gm_world_get_status(GmWorld *world) { + return world->priv->status; +} + /* Callbacks */ void @@ -834,6 +864,7 @@ on_gm_world_net_bytes_recv(GmNet *net, gchar *text, gint len, all = utext; } + // TODO: UTF-8 compliant line = (gchar *)(malloc((strlen(all) * sizeof(gchar)) + 1)); i = 0; p = all; @@ -841,7 +872,7 @@ on_gm_world_net_bytes_recv(GmNet *net, gchar *text, gint len, /* Find lines in `all' and process them */ for (ptr = all; *ptr != '\0'; ptr++) { if (*ptr == '\n') { - line[i] = '\n'; + line[i] = '\0'; line[i + 1] = '\0'; gm_world_process_line(world, line); diff --git a/src/gm-world.h b/src/gm-world.h index ab6898e..5c0b0e7 100644 --- a/src/gm-world.h +++ b/src/gm-world.h @@ -86,13 +86,14 @@ struct _GmWorldClass { void (* load) (GmWorld *world); void (* unload) (GmWorld *world); void (* state_changing) (GmWorld *world, guint state); - void (* world_error) (GmWorld *world, gchar *error, gint code); - void (* text_received) (GmWorld *world, gchar *text); + void (* world_error) (GmWorld *world, gchar const *error, gint code); + void (* text_received) (GmWorld *world, gchar const *text); void (* editor_added) (GmWorld *world, GObject *editor); void (* editor_removed) (GmWorld *world, GObject *editor); - void (* name_changed) (GmWorld *world, gchar *name); + void (* name_changed) (GmWorld *world, gchar const *name); void (* active_changed) (GmWorld *world, gboolean active); void (* activity_changed) (GmWorld *world, gint activity); + void (* status_changed) (GmWorld *world, gchar const *status); }; GType gm_world_get_type(void) G_GNUC_CONST; @@ -117,6 +118,8 @@ const gchar *gm_world_current_port(GmWorld *world); void gm_world_set_name(GmWorld *world, const gchar *name); void gm_world_set_activity(GmWorld *world, gint activity); void gm_world_set_active(GmWorld *world, gboolean active); +void gm_world_set_status(GmWorld *world, gchar const *status); +gchar const *gm_world_get_status(GmWorld *world); gboolean gm_world_loaded(GmWorld *world); GmNetState gm_world_state(GmWorld *world);