medit/moo/mooterm/mootermpt.c

206 lines
6.1 KiB
C
Raw Normal View History

2005-06-22 11:20:32 -07:00
/*
2005-07-07 04:06:23 -07:00
* mooterm/mootermpt.c
2005-06-22 11:20:32 -07:00
*
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
#define MOOTERM_COMPILATION
#include "mooterm/mooterm-private.h"
2005-06-22 15:13:12 -07:00
#include "mooutils/moomarshals.h"
#include "mooutils/moocompat.h"
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
static void moo_term_pt_set_property (GObject *object,
2005-06-22 11:20:32 -07:00
guint prop_id,
const GValue *value,
GParamSpec *pspec);
2005-07-07 04:06:23 -07:00
static void moo_term_pt_get_property (GObject *object,
2005-06-22 11:20:32 -07:00
guint prop_id,
GValue *value,
GParamSpec *pspec);
2005-07-07 04:06:23 -07:00
static void moo_term_pt_finalize (GObject *object);
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
/* MOO_TYPE_TERM_PT */
G_DEFINE_TYPE (MooTermPt, moo_term_pt, G_TYPE_OBJECT)
2005-06-22 11:20:32 -07:00
enum {
2005-06-22 15:13:12 -07:00
CHILD_DIED,
2005-06-22 11:20:32 -07:00
LAST_SIGNAL
};
enum {
PROP_0,
PROP_BUFFER
};
2005-06-22 15:13:12 -07:00
static guint signals[LAST_SIGNAL];
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
static void moo_term_pt_class_init (MooTermPtClass *klass)
2005-06-22 11:20:32 -07:00
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
2005-07-07 04:06:23 -07:00
gobject_class->set_property = moo_term_pt_set_property;
gobject_class->get_property = moo_term_pt_get_property;
gobject_class->finalize = moo_term_pt_finalize;
2005-06-22 11:20:32 -07:00
2005-06-22 15:13:12 -07:00
klass->set_size = NULL;
klass->fork_command = NULL;
klass->write = NULL;
2005-06-22 15:13:12 -07:00
klass->kill_child = NULL;
klass->child_died = NULL;
signals[CHILD_DIED] =
g_signal_new ("child-died",
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST,
2005-07-07 04:06:23 -07:00
G_STRUCT_OFFSET (MooTermPtClass, child_died),
2005-06-22 15:13:12 -07:00
NULL, NULL,
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
2005-06-22 11:20:32 -07:00
g_object_class_install_property (gobject_class,
PROP_BUFFER,
g_param_spec_object ("buffer",
"buffer",
"buffer",
MOO_TYPE_TERM_BUFFER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
2005-07-07 04:06:23 -07:00
static void moo_term_pt_init (MooTermPt *pt)
2005-06-22 11:20:32 -07:00
{
2005-07-07 04:06:23 -07:00
pt->priv = g_new0 (MooTermPtPrivate, 1);
pt->priv->pending_write = g_queue_new ();
2005-06-22 11:20:32 -07:00
}
2005-07-07 04:06:23 -07:00
static void moo_term_pt_finalize (GObject *object)
2005-06-22 11:20:32 -07:00
{
2005-07-07 04:06:23 -07:00
MooTermPt *pt = MOO_TERM_PT (object);
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
if (pt->priv->buffer)
g_object_unref (pt->priv->buffer);
2005-07-07 04:06:23 -07:00
pt_flush_pending_write (pt);
g_queue_free (pt->priv->pending_write);
2005-07-07 04:06:23 -07:00
g_free (pt->priv);
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
G_OBJECT_CLASS (moo_term_pt_parent_class)->finalize (object);
2005-06-22 11:20:32 -07:00
}
2005-07-07 04:06:23 -07:00
static void moo_term_pt_set_property (GObject *object,
2005-06-22 11:20:32 -07:00
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
2005-07-07 04:06:23 -07:00
MooTermPt *pt = MOO_TERM_PT (object);
2005-06-22 11:20:32 -07:00
switch (prop_id) {
case PROP_BUFFER:
2005-07-07 04:06:23 -07:00
moo_term_pt_set_buffer (pt, g_value_get_object (value));
2005-06-22 11:20:32 -07:00
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
2005-07-07 04:06:23 -07:00
static void moo_term_pt_get_property (GObject *object,
2005-06-22 11:20:32 -07:00
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
2005-07-07 04:06:23 -07:00
MooTermPt *pt = MOO_TERM_PT (object);
2005-06-22 11:20:32 -07:00
switch (prop_id) {
case PROP_BUFFER:
2005-07-07 04:06:23 -07:00
g_value_set_object (value, pt->priv->buffer);
2005-06-22 11:20:32 -07:00
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
2005-07-07 04:06:23 -07:00
void moo_term_pt_set_buffer (MooTermPt *pt,
2005-06-22 11:20:32 -07:00
MooTermBuffer *buffer)
{
2005-07-07 04:06:23 -07:00
if (pt->priv->buffer == buffer)
2005-06-22 11:20:32 -07:00
return;
2005-07-07 04:06:23 -07:00
if (pt->priv->buffer)
g_object_unref (pt->priv->buffer);
pt->priv->buffer = buffer;
if (pt->priv->buffer)
g_object_ref (pt->priv->buffer);
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
g_object_notify (G_OBJECT (pt), "buffer");
2005-06-22 11:20:32 -07:00
}
2005-07-07 04:06:23 -07:00
MooTermBuffer *moo_term_pt_get_buffer (MooTermPt *pt)
2005-06-22 11:20:32 -07:00
{
2005-07-07 04:06:23 -07:00
return pt->priv->buffer;
2005-06-22 11:20:32 -07:00
}
2005-07-07 04:06:23 -07:00
MooTermPt *moo_term_pt_new (void)
2005-06-22 11:20:32 -07:00
{
2005-06-22 15:13:12 -07:00
#ifdef __WIN32__
2005-07-07 04:06:23 -07:00
return g_object_new (MOO_TYPE_TERM_PT_WIN, NULL);
2005-06-22 15:13:12 -07:00
#else /* !__WIN32__ */
2005-07-07 04:06:23 -07:00
return g_object_new (MOO_TYPE_TERM_PT_UNIX, NULL);
2005-06-22 15:13:12 -07:00
#endif /* !__WIN32__ */
}
2005-07-07 04:06:23 -07:00
void moo_term_pt_set_size (MooTermPt *pt,
guint width,
guint height)
2005-06-22 15:13:12 -07:00
{
2005-07-07 04:06:23 -07:00
g_return_if_fail (MOO_IS_TERM_PT (pt));
MOO_TERM_PT_GET_CLASS(pt)->set_size (pt, width, height);
2005-06-22 15:13:12 -07:00
}
2005-07-07 04:06:23 -07:00
gboolean moo_term_pt_fork_command (MooTermPt *pt,
2005-06-22 15:13:12 -07:00
const char *cmd,
const char *working_dir,
char **envp)
{
2005-07-07 04:06:23 -07:00
g_return_val_if_fail (MOO_IS_TERM_PT (pt), FALSE);
return MOO_TERM_PT_GET_CLASS(pt)->fork_command (pt, cmd, working_dir, envp);
2005-06-22 15:13:12 -07:00
}
2005-07-07 04:06:23 -07:00
void moo_term_pt_kill_child (MooTermPt *pt)
2005-06-22 15:13:12 -07:00
{
2005-07-07 04:06:23 -07:00
g_return_if_fail (MOO_IS_TERM_PT (pt));
MOO_TERM_PT_GET_CLASS(pt)->kill_child (pt);
2005-06-22 11:20:32 -07:00
}
2005-07-07 04:06:23 -07:00
void moo_term_pt_write (MooTermPt *pt,
2005-06-22 15:13:12 -07:00
const char *data,
gssize len)
2005-06-22 11:20:32 -07:00
{
2005-07-07 04:06:23 -07:00
g_return_if_fail (MOO_IS_TERM_PT (pt));
MOO_TERM_PT_GET_CLASS(pt)->write (pt, data, len);
2005-06-22 11:20:32 -07:00
}