/*
 * This file is a part of VyQChat.
 *
 * Copyright (C) 2002-2004 Pawel Stolowski <yogin@linux.bydg.org>
 *
 * VyQChat is free software; you can redestribute it and/or modify it
 * under terms of GNU General Public License by Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY. See GPL for more details.
 */

#include "history.h"
#include "settings.h"
#include <qsettings.h>

History::History(const QStringList &l, int max): size(max)/*{{{*/
{
	hlist = l;
}/*}}}*/

History::History(int max)/*{{{*/
{
	size = max;
}/*}}}*/

History::~History()/*{{{*/
{
}/*}}}*/

void History::append(const QString &txt)/*{{{*/
{
	QStringList::iterator it = hlist.find(txt);
	//
	// text not found on the list - append it
	if (it == hlist.end())
	{
		hlist.push_front(txt);
		//
		// remove last text item if history reached its max size
		if (hlist.count() > size)
			hlist.pop_back();
	}
	else //put the item to the front
	{
		hlist.push_front(txt);
		hlist.remove(it);
	}
}/*}}}*/

void History::set(const QStringList &l)/*{{{*/
{
	hlist = l;
}/*}}}*/

QString History::first()/*{{{*/
{
	return hlist.first(); 
}/*}}}*/

QStringList History::getAll() const/*{{{*/
{
	return hlist;
}/*}}}*/



syntax highlighted by Code2HTML, v. 0.9.1