/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *			(C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#include <installedpkglistviewitem.h>

#include <qprocess.h>
#include <qregexp.h>

#define	TERMINAL_COLS		80
#define	TERMINAL_MAXLINES	300

InstalledPkgListViewItem::InstalledPkgListViewItem(QListView *lv, QString a, QString b, QString c)
	:	QListViewItem(lv, a, b, c)
{
}

int InstalledPkgListViewItem::compare(QListViewItem *i, int col, bool asc) const {
	if(col >= 2) {
		const QRegExp  noNum("[^0123456789]");
		bool  thisOk, otherOk;

		long	a = text(col).remove(noNum).toLong(&thisOk),
				b = i->text(col).remove(noNum).toLong(&otherOk);

		if(!thisOk || !otherOk)
			return (!thisOk && !otherOk) ? 0 : (thisOk ? 1 : -1);

		return ((a == b) ? 0 : ((a > b) ? 1 : -1)) * (asc ? 1 : -1);
	}

	return QListViewItem::compare(i, col, asc);
}
