/***************************************************************************
 *   Copyright (C) 2004 by Christoph Thielecke                             *
 *   crissi99@gmx.de                                                       *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "logviewerdialog.h"
#include <klocale.h>
#include <klistview.h>
#include <qpixmap.h>
#include <kglobal.h>
#include <qstring.h>
#include <kiconloader.h>
#include <kstddirs.h>
#include <ktextbrowser.h>
#include <iostream>
#include <kvpnc.h>
#include <qfile.h>
#include <qtextstream.h>
#include "logviewerdialog.moc"

LogViewerDialog::LogViewerDialog(QWidget *parent, QApplication *app, KVpncConfig *GlobalConfig,const QString& caption) : KDialogBase( parent, "Show_log", false, caption,
KDialogBase::Ok|KDialogBase::Cancel,KDialogBase::Ok, true )
{
	main = new LogViewerDialogBase (this);
	setMainWidget(main);
	//	main->setMinimumSize(main->sizeHint());
	main->setMinimumSize(400,300);

	this->GlobalConfig = GlobalConfig;
	this->app = app;

	// 	QPixmap info_icon = KGlobal::iconLoader()->loadIcon( "button_ok", KIcon::NoGroup, 16 );
	// 	QPixmap debug_icon = KGlobal::iconLoader()->loadIcon( "button_cancel", KIcon::NoGroup, 16 );
	// 	QPixmap error_icon = KGlobal::iconLoader()->loadIcon( "button_ok", KIcon::NoGroup, 16 );
	// 	QPixmap debug_icon = KGlobal::iconLoader()->loadIcon( "button_cancel", KIcon::NoGroup, 16 );

	//	InfoListView->setSorting(1);
	KStandardDirs *dirs = KGlobal::dirs();
	QString logfileName = dirs->saveLocation( "data" );
	logfileName += "/kvpnc/kvpnc.log";
	QFile logfile;
	//std::cout << "file exists: " << logfile.exists() << std::endl;
	logfile.setName( logfileName );
	if (logfile.open(IO_ReadOnly ))
	{
// 		QTextStream stream( &logfile );
// 		QString line;
// 		QString lines;
// 		QString prefix;
// 		QString postfix;
// 		int i = 1;
// 		int type;
// 		while ( !stream.atEnd() )
// 		{
// 			line = stream.readLine(); // line of text excluding '\n'
// 			if (line.find("info",0, FALSE) > -1 )
// 			{
// 				type = KVpncConfig::info;
// 			}
// 			else			if (line.find("debug",0, FALSE) > -1 )
// 			{
// 				type = KVpncConfig::debug;
// 			}
// 			// 			else
// 			// 			if (line.find("remote",0, FALSE) > -1 )
// 			// 			{
// 			// 				type = KVpncConfig::remote;
// 			// 			}
// 			else
// 				if (line.find("error",0, FALSE) > -1 )
// 				{
// 					type = KVpncConfig::error;
// 				}
// 			// 			else
// 			// 			if (line.find("success",0, FALSE) > -1 )
// 			// 			{
// 			// 				type = KVpncConfig::success;
// 			// 			}
// 
// 
// 			prefix+="<font color=\"";
// 
// 			switch ( type )
// 			{
// 					case KVpncConfig::info:
// 					prefix+=GlobalConfig->InfoLogColor.name();
// 					prefix+="\">";
// 					prefix+=i18n("info")+": ";
// 					break;
// 					case KVpncConfig::remote:
// 					prefix+=GlobalConfig->RemoteLogColor.name();
// 					prefix+="\">";
// 					prefix+=i18n("remote")+": ";
// 					break;
// 					case KVpncConfig::error:
// 					prefix+=GlobalConfig->ErrorLogColor.name();
// 					prefix+="\">";
// 					prefix+=i18n("error")+": ";
// 					break;
// 					case KVpncConfig::success:
// 					prefix+=GlobalConfig->SuccessLogColor.name();
// 					prefix+="\">";
// 					prefix+=i18n("success")+": ";
// 					break;
// 					case KVpncConfig::debug:
// 					prefix+=GlobalConfig->DebugLogColor.name();
// 					prefix+="\">";
// 					prefix+=i18n("debug")+": ";
// 					break;
// 			}
// 
// 			postfix+="</font>";
// 			main->LogTextBrowser->append( prefix+line+postfix );
// 			prefix="";
// 			postfix="";
// 			app->processEvents();
// 		}
			QString Log= QString(logfile.readAll());
			main->LogTextBrowser->setText( Log );
		logfile.close();
	}
}


LogViewerDialog::~LogViewerDialog()
{}

void LogViewerDialog::accept()
{
	QDialog::accept();
}

