// -*- c++ -*-

/*
 *  Copyright (C) 2003, Richard J. Moore <rich@kde.org>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 */

#include <qfile.h>
#include <qtextstream.h>
#include <kdebug.h>

#include "textstream_imp.h"
#include "textstream_imp.moc"

namespace KJSEmbed {
namespace Bindings {

TextStream::TextStream( QObject *parent, const char *name, QTextStream *t )
    : QObject( parent, name ), ts(t)
{
    kdFatal( !ts ) << "TextStream: Received a null textstream" << endl;
}

TextStream::~TextStream()
{
    delete ts;
}

bool TextStream::isReadable() const
{
    return (ts->device()->mode() == IO_ReadOnly)
	|| (ts->device()->mode() == IO_ReadWrite);
}

bool TextStream::isWritable() const
{
    return (ts->device()->mode() == IO_WriteOnly)
	|| (ts->device()->mode() == IO_ReadWrite);
}

QString TextStream::current() const
{
    if ( !isReadable() )
	return QString::null;
    return line;
}

void TextStream::print( const QString &msg )
{
    if ( !isWritable() )
	return;
    (*ts) << msg;
}

void TextStream::println( const QString &msg )
{
    if ( !isWritable() )
	return;
    (*ts) << msg << endl;
}

QString TextStream::readLine()
{
    if ( isReadable() )
	line = ts->readLine();
    else
	line = QString::null;
    return line;
}

} // namespace Bindings
}; // namespace KJSEmbed

