ComponentChooser::ComponentChooser(QWidget *parent):
    QWidget(parent), Ui::ComponentChooser_UI(), somethingChanged(false), configWidget(0)
{
	setupUi(this);
	static_cast<QGridLayout*>(layout())->setRowStretch(1, 1);

	const QStringList services=KGlobal::dirs()->findAllResources( "data","kcm_componentchooser/*.desktop",
															KStandardDirs::NoDuplicates);
	for (QStringList::const_iterator it=services.constBegin(); it!=services.constEnd(); ++it)
	{
		KConfig cfg(*it, KConfig::SimpleConfig);
		KConfigGroup cg = cfg.group(QByteArray());
		QListWidgetItem *item = new QListWidgetItem(
			QIcon::fromTheme(cg.readEntry("Icon",QString("preferences-desktop-default-applications"))), 
			cg.readEntry("Name",i18n("Unknown")));
		item->setData(Qt::UserRole, (*it));
		ServiceChooser->addItem(item);
	}
	ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20);
	ServiceChooser->sortItems();
	connect(ServiceChooser,SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),this,SLOT(slotServiceSelected(QListWidgetItem*)));
	ServiceChooser->setCurrentRow(0);
	slotServiceSelected(ServiceChooser->item(0));

}
ComponentChooser::ComponentChooser(QWidget *parent, const char *name) : ComponentChooser_UI(parent, name), configWidget(0)
{

    ComponentChooser_UILayout->setRowStretch(1, 1);
    somethingChanged = false;
    latestEditedService = "";

    QStringList dummy;
    QStringList services = KGlobal::dirs()->findAllResources("data", "kcm_componentchooser/*.desktop", false, true, dummy);
    for(QStringList::Iterator it = services.begin(); it != services.end(); ++it)
    {
        KSimpleConfig cfg(*it);
        ServiceChooser->insertItem(new MyListBoxItem(cfg.readEntry("Name", i18n("Unknown")), (*it)));
    }
    ServiceChooser->setFixedWidth(ServiceChooser->sizeHint().width());
    ServiceChooser->sort();
    connect(ServiceChooser, SIGNAL(highlighted(QListBoxItem *)), this, SLOT(slotServiceSelected(QListBoxItem *)));
    ServiceChooser->setSelected(0, true);
    slotServiceSelected(ServiceChooser->item(0));
}