/*****************************************************************************
 *
 *  playercapabilitydialog.cpp -- Show player capabilities.
 *
 *  Copyright (C) 2010 Starbuck <starbuck@labdv.com>
 *  All rights reserved.
 *
 *  This file is part of the Gui4 module of the DVDx 4 application.
 *
 *  GNU Lesser General Public License Usage
 *  This file may be used under the terms of the GNU Lesser General
 *  Public License version 2.1 as published by the Free Software
 *  Foundation and appearing in the file LICENSE.LGPL included in the
 *  packaging of this file.  Please review the following information to
 *  ensure the GNU Lesser General Public License version 2.1 requirements
 *  will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 *
 *  GNU General Public License Usage
 *  Alternatively, this file may be used under the terms of the GNU
 *  General Public License version 3.0 as published by the Free Software
 *  Foundation and appearing in the file LICENSE.GPL included in the
 *  packaging of this file.  Please review the following information to
 *  ensure the GNU General Public License version 3.0 requirements will be
 *  met: http://www.gnu.org/copyleft/gpl.html.
 *
 *****************************************************************************/

#include "playercapabilitydialog.h"
#include "../video/video_functions.h"
#include <QLayout>
#include <QListWidget>
#include <QGroupBox>

PlayerCapabilityDialog::PlayerCapabilityDialog(player_engine_capability_t *capability, QWidget *parent)
	: QDialog(parent)
{
	setWindowTitle( tr("Player backend capabilities") );
	
	int i, Nvideo, Naudio;
	
	// Video
	QListWidget *videoList = new QListWidget(this);

	Nvideo = capability->video->count();

	QMapIterator<QString, QString> v(*capability->video);
	i = 0;
	while (v.hasNext()) 
	{
		v.next();
		availableVideo << new QListWidgetItem( " - " + v.key() );
		availableVideo[i]->setToolTip( v.value() );
		videoList->addItem( availableVideo[i] );
		i++;
	}

	videoList->sortItems(Qt::AscendingOrder);

	QVBoxLayout *videoTable = new QVBoxLayout;
	videoTable->addWidget(videoList);

	QGroupBox *videoGroup = new QGroupBox(tr("Available video drivers"));
	videoGroup->setLayout(videoTable);

	QVBoxLayout *videoLayout = new QVBoxLayout;
	videoLayout->addWidget(videoGroup);

	// Audio
	QListWidget *audioList = new QListWidget(this);

	Naudio = capability->audio->count();
	
	QMapIterator<QString, QString> a(*capability->audio);
	i = 0;
	while (a.hasNext()) 
	{
		a.next();
		availableAudio << new QListWidgetItem( " - " + a.key() );
		availableAudio[i]->setToolTip( a.value() );
		audioList->addItem( availableAudio[i] );
		i++;
	}
	
	audioList->sortItems(Qt::AscendingOrder);

	QVBoxLayout *audioTable = new QVBoxLayout;
	audioTable->addWidget(audioList);

	QGroupBox *audioGroup = new QGroupBox(tr("Available audio drivers"));
	audioGroup->setLayout(audioTable);

	QVBoxLayout *audioLayout = new QVBoxLayout;
	audioLayout->addWidget(audioGroup);

	// Buttons
	buttonBox = new QDialogButtonBox(this);
	buttonBox->setFocusPolicy(Qt::StrongFocus);
	buttonBox->setOrientation(Qt::Horizontal);
	buttonBox->setStandardButtons(QDialogButtonBox::Ok);
	buttonBox->setCenterButtons(true);

	// Tabs
	tabWidget = new QTabWidget(this);
	tabWidget->setMovable(false);

	videoTab = new QWidget();
	audioTab = new QWidget();

	tabWidget->addTab(videoTab, QString(tr("Video")));

	if ( Naudio )
	{
		tabWidget->addTab(audioTab, QString(tr("Audio")));
	}

	tabWidget->setCurrentIndex(0);

	QVBoxLayout *tabVLayout = new QVBoxLayout;
	tabVLayout->addWidget(tabWidget);
	tabVLayout->addWidget(buttonBox);

	videoTab->setLayout(videoLayout);
	audioTab->setLayout(audioLayout);

	setLayout(tabVLayout);

	connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
	connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

	setAttribute(Qt::WA_AlwaysShowToolTips);
	setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
	setMinimumWidth( 260 );
}
