/* 
 * 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 <qlabel.h>
#include <qlayout.h>
#include <qprocess.h>

#include <klocale.h>
#include <kglobal.h>
#include <kparts/genericfactory.h>

#include <dbsdglobal.h>
#include <dbsdiconloader.h>
#include <dbsdinitglobal.h>

#include "dbsdpackages.h"

typedef KGenericFactory<DBSDPackages, QWidget> DBSDPackagesFactory;
K_EXPORT_COMPONENT_FACTORY(kcm_DBSDPackages, DBSDPackagesFactory("kcm_dbsdpackages"))

extern "C"
{
	KCModule *create_dbsdpackages(QWidget  *parent, const char  *name)
	{
		DBSDGlobalInitializer::initGlobal();
		return	new DBSDPackages(parent, name);
	};
}

DBSDPackages::DBSDPackages(QWidget *parent, const char *name,  __unused const QStringList &  list)
{
	(new QHBoxLayout(this))->setAutoAdd(true);
	pix = new QLabel(this, NULL, 0);
	pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
	pix->setPixmap(DBSDGlobal::getIconLoader()->loadIcon("window_new", DBSDIconLoader::Size32x32));
   lbl = new QLabel(tr("Opened in a new window."), this);
   lbl->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
   lbl->show();

   QProcess process(QString("/usr/local/bin/dbsd-pkgmgr"));
	if(!process.start()) {
		lbl->setText(tr("Couldn't launch Software Manager."));
		pix->setPixmap(DBSDGlobal::getIconLoader()->loadIcon("error", DBSDIconLoader::Size32x32));
	}
}

DBSDPackages::~ DBSDPackages() {
  delete lbl;
}

