155 lines
4.7 KiB
C
155 lines
4.7 KiB
C
#include "gm-mcp-mud-moo-simpleedit.h"
|
|
#include "gm-mcp-session.h"
|
|
#include "gm-mcp.h"
|
|
#include "gm-debug.h"
|
|
#include "gm-world.h"
|
|
#include "gm-editor.h"
|
|
|
|
#define GM_MCP_MUD_MOO_SIMPLEEDIT_GET_PRIVATE(object)( \
|
|
G_TYPE_INSTANCE_GET_PRIVATE((object), \
|
|
GM_TYPE_MCP_MUD_MOO_SIMPLEEDIT, GmMcpMudMooSimpleeditPrivate))
|
|
|
|
struct _GmMcpMudMooSimpleeditPrivate {
|
|
gchar *ref;
|
|
gchar *name;
|
|
gchar *type;
|
|
};
|
|
|
|
/* Signals
|
|
|
|
enum {
|
|
PROTO
|
|
NUM_SIGNALS
|
|
};
|
|
|
|
static guint gm_mcp_mud_moo_simpleedit_signals[NUM_SIGNALS] = {0};*/
|
|
|
|
G_DEFINE_TYPE(GmMcpMudMooSimpleedit, gm_mcp_mud_moo_simpleedit, GM_TYPE_MCP_PACKAGE)
|
|
|
|
void gm_mcp_mud_moo_simpleedit_handle_simple(GmMcpPackage *package,
|
|
gchar *suffix, GList *fields);
|
|
gboolean gm_mcp_mud_moo_simpleedit_handle_multi(GmMcpPackage *package,
|
|
gchar const *data_tag, gchar const *key, gchar const *value,
|
|
GList *all_values);
|
|
void on_gm_mcp_mud_moo_simpleedit_editor_save(GmEditor *editor,
|
|
GmMcpMudMooSimpleedit *package);
|
|
|
|
static void
|
|
gm_mcp_mud_moo_simpleedit_finalize(GObject *object) {
|
|
GmMcpMudMooSimpleedit *obj = GM_MCP_MUD_MOO_SIMPLEEDIT(object);
|
|
|
|
g_free(obj->priv->ref);
|
|
g_free(obj->priv->name);
|
|
g_free(obj->priv->type);
|
|
|
|
G_OBJECT_CLASS(gm_mcp_mud_moo_simpleedit_parent_class)->finalize(object);
|
|
}
|
|
|
|
static void
|
|
gm_mcp_mud_moo_simpleedit_class_init(GmMcpMudMooSimpleeditClass *klass) {
|
|
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
|
GmMcpPackageClass *pklass = GM_MCP_PACKAGE_CLASS(klass);
|
|
|
|
object_class->finalize = gm_mcp_mud_moo_simpleedit_finalize;
|
|
|
|
/*gm_mcp_mud_moo_simpleedit_signals[PROTO] =
|
|
g_signal_new("proto",
|
|
G_OBJECT_CLASS_TYPE(object_class),
|
|
G_SIGNAL_RUN_LAST,
|
|
G_STRUCT_OFFSET(GmMcpMudMooSimpleeditClass, proto),
|
|
NULL, NULL,
|
|
g_cclosure_marshal_VOID__VOID,
|
|
G_TYPE_NONE,
|
|
0);*/
|
|
|
|
pklass->name = "dns-org-mud-moo-simpleedit";
|
|
pklass->handle_simple = &gm_mcp_mud_moo_simpleedit_handle_simple;
|
|
pklass->handle_multi = &gm_mcp_mud_moo_simpleedit_handle_multi;
|
|
|
|
g_type_class_add_private(object_class, sizeof(GmMcpMudMooSimpleeditPrivate));
|
|
}
|
|
|
|
static void
|
|
gm_mcp_mud_moo_simpleedit_init(GmMcpMudMooSimpleedit *obj) {
|
|
obj->priv = GM_MCP_MUD_MOO_SIMPLEEDIT_GET_PRIVATE(obj);
|
|
}
|
|
|
|
GmMcpMudMooSimpleedit *
|
|
gm_mcp_mud_moo_simpleedit_new() {
|
|
GmMcpMudMooSimpleedit *obj = GM_MCP_MUD_MOO_SIMPLEEDIT(g_object_new(GM_TYPE_MCP_MUD_MOO_SIMPLEEDIT, NULL));
|
|
|
|
return obj;
|
|
}
|
|
|
|
void
|
|
gm_mcp_mud_moo_simpleedit_handle_simple(GmMcpPackage *package,
|
|
gchar *suffix, GList *fields) {
|
|
gchar const *name, *ref, *type;
|
|
GmMcpMudMooSimpleedit *simpleedit = GM_MCP_MUD_MOO_SIMPLEEDIT(package);
|
|
|
|
if (g_strcasecmp(suffix, "content") == 0) {
|
|
if (!(name = gm_mcp_find_value(fields, "name"))) {
|
|
gm_debug_msg(DEBUG_MCP, "GmMcpMooMudSimpleedit.HandleSimple: "
|
|
"no name found, ignoring!");
|
|
} else if (!(ref = gm_mcp_find_value(fields, "reference"))) {
|
|
gm_debug_msg(DEBUG_MCP, "GmMcpMooMudSimpleedit.HandleSimple: "
|
|
"no reference found, ignoring!");
|
|
} else if (!(type = gm_mcp_find_value(fields, "type"))) {
|
|
gm_debug_msg(DEBUG_MCP, "GmMcpMooMudSimpleedit.HandleSimple: "
|
|
"no type found, ignoring!");
|
|
} else {
|
|
gm_debug_msg(DEBUG_MCP, "GmMcpMooMudSimpleedit.HandleSimple: "
|
|
"accept content: name = %s, reference = %s, type = %s",
|
|
name, ref, type);
|
|
simpleedit->priv->name = g_strdup(name);
|
|
simpleedit->priv->ref = g_strdup(ref);
|
|
simpleedit->priv->type = g_strdup(type);
|
|
}
|
|
} else {
|
|
gm_debug_msg(DEBUG_MCP, "GmMcpMooMudSimpleedit.HandleSimple: "
|
|
"unknown suffix: %s", suffix);
|
|
}
|
|
}
|
|
|
|
gboolean
|
|
gm_mcp_mud_moo_simpleedit_handle_multi(GmMcpPackage *package,
|
|
gchar const *data_tag, gchar const *key, gchar const *value,
|
|
GList *all_values) {
|
|
GmEditor *editor;
|
|
GmMcpMudMooSimpleedit *simpleedit = GM_MCP_MUD_MOO_SIMPLEEDIT(package);
|
|
|
|
if (key) {
|
|
return FALSE;
|
|
} else {
|
|
// All values arrived! Yeah!
|
|
editor = gm_editor_new_mcp(simpleedit->priv->name,
|
|
simpleedit->priv->ref, simpleedit->priv->type, all_values);
|
|
|
|
g_signal_connect(editor, "save",
|
|
G_CALLBACK(on_gm_mcp_mud_moo_simpleedit_editor_save), package);
|
|
gm_world_add_editor(GM_MCP_SESSION_WORLD(GM_MCP_PACKAGE_SESSION(
|
|
package)), editor);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/* Callbacks */
|
|
void
|
|
on_gm_mcp_mud_moo_simpleedit_editor_save(GmEditor *editor,
|
|
GmMcpMudMooSimpleedit *package) {
|
|
GmMcpSession *session = GM_MCP_PACKAGE_SESSION(package);
|
|
gchar *data_tag = gm_mcp_generate_data_tag();
|
|
|
|
if (session) {
|
|
gm_mcp_session_send_simple(session, "dns-org-mud-moo-simpleedit-set",
|
|
"reference", gm_editor_upload_cmd(editor), "type",
|
|
gm_editor_mcp_type(editor), "content*", "", "_data-tag",
|
|
data_tag, NULL);
|
|
gm_mcp_session_send_multiline(session, data_tag, "content",
|
|
gm_editor_lines(editor));
|
|
gm_editor_saved(editor);
|
|
}
|
|
|
|
g_free(data_tag);
|
|
}
|