view widgets/QueryResultsWidget.cpp @ 90:87495ac7710a

support audio source info from boca
author lbajardsilogic
date Thu, 28 Jun 2007 16:57:29 +0000
parents 5060939ca69d
children c26c73ca6d37
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*	Sound Access	
		EASAIER client application.	
		Silogic 2007. Laure Bajard. 
	
	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.  See the file    
	COPYING included with this distribution for more information.
*/

#include "QueryResultsWidget.h"

#include <QScrollArea>
#include <QLabel>
#include <QApplication>

#include <iostream>

#include "sv/main/MainWindow.h"

QueryResultsWidget::QueryResultsWidget() : QWidget(),
	m_ndResults(0)
{
	m_resultsLayout = new QGridLayout;
	
	QWidget *resultsWidget = new QWidget;
	resultsWidget->setLayout(m_resultsLayout);

	QScrollArea * scrollArea = new QScrollArea;
	scrollArea->setWidget(resultsWidget);
	scrollArea->setWidgetResizable(true);

	QVBoxLayout *mainLayout = new QVBoxLayout;
	mainLayout->addWidget(scrollArea);

	setLayout(mainLayout);
}

QueryResultsWidget::~QueryResultsWidget()
{}

void QueryResultsWidget::reset()
{
	m_ndResults = 0;

	QLayoutItem *child;
	while ((child = m_resultsLayout->takeAt(0)) != 0) {
		delete child->widget();
	}
}

void QueryResultsWidget::newResult()
{
	m_curResult.clear();
}

void QueryResultsWidget::addInfo(const QString& name, const QString& value)
{
	Info info;
	info.name = name;
	info.value = value;

	m_curResult.push_back(info);
}

void QueryResultsWidget::displayResult()
{
	std::vector<Info>::iterator iter;

	QLabel* result = new QLabel();

	QString text;
	QString uri = "";

	for (iter = m_curResult.begin(); iter != m_curResult.end(); iter++)
	{
		if ((*iter).name == "identification")
		{
			uri = (*iter).value;
			uri = uri.right(uri.length() - uri.lastIndexOf("#") - 1);
		}
	}

	for (iter = m_curResult.begin(); iter != m_curResult.end(); iter++)
	{
		if ((*iter).name != "identification")
		{
			text += "<br>" ;
			text += (*iter).name;
			text += " : " ;
			if ((*iter).name == "title")
			{
				text += "<a href=\"";
				text += uri;
				text += "\">";
				text += (*iter).value;
				text += "</a>";
			} else 
			{
				text += (*iter).value;
			}
			text += "</br>" ;
		}
	}
	
	connect(result, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(importEasaierFile(QString)));

	result->setText(text);

	m_resultsLayout->addWidget(result,m_ndResults,0);
	m_ndResults++;
	
}