/***************************************************************************
 * logger.cpp: implementation of Logger class
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2006- the KTabEdit development team <mrgwen@gmail.com>
 ***************************************************************************/

/***************************************************************************
 * 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 the file COPYING for more information.
 ***************************************************************************/

#include "logger.h"

#include <QColor>
#include <QDir>

ktabedit::Logger ktabLog;

bool ktabedit::Logger::inst = false;

ktabedit::Logger::Logger()
{
	if (inst)
		return ;
	
	QDir homeDir(QDir::home());
	
	// Create ktabedit dir where the the file is 
	// unzip, the file is deleted after the parsing.
	//
	if (!homeDir.cd(".ktabedit"))
		if (homeDir.mkdir(".ktabedit") == false)
			throw "Unable to create .ktabedit directory";
	
	file.setFileName(homeDir.absolutePath() + "/ktabedit.log");
	
	inst = true;
	
	if (file.open(QIODevice::WriteOnly))
		stream.setDevice(&file);
	else
		return ;
}

ktabedit::Logger::~Logger()
{
	file.close();
}

ktabedit::Logger& ktabedit::Logger::operator<<(QChar c)
{
	stream << c;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(char c)
{
	stream << c;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(signed short i)
{
	stream << i;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(unsigned short i)
{
	stream << i;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(signed int i)
{
	stream << i;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(unsigned int i)
{
	stream << i;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(signed long i)
{
	stream << i;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(unsigned long i)
{
	stream << i;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(float f)
{
	stream << f;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(double f)
{
	stream << f;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(const char *s)
{
	stream << s;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(const QString &s)
{
	stream << s;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(void *ptr)
{
	stream << ptr;
	
	return *this;
}

ktabedit::Logger& ktabedit::Logger::operator<<(const QColor &color)
{
	stream << color.red() << " " << color.green() << " " << color.blue();
	
	return *this;
}
