/*****************************************************************************
 *
 *  targetdialog.cpp -- Input the target basefilename.
 *
 *  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 "targetdialog.h"
#include <QtGui>

TargetDialog::TargetDialog(QString *target, QWidget *parent)
	: QDialog(parent)
{
	setAttribute(Qt::WA_AlwaysShowToolTips);

	setWindowTitle(tr("Set output target name"));
	
	buttonBox = new QDialogButtonBox(this);
	buttonBox->setOrientation(Qt::Horizontal);
	buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
	
	label = new QLabel(this);
	label->setText(tr("Enter output file name (without extension):"));
	QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	sizePolicy.setHorizontalStretch(0);
	sizePolicy.setVerticalStretch(0);
	sizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
	label->setSizePolicy(sizePolicy);
	
	lineEdit = new QLineEdit(this);
	lineEdit->setText(*target);

	QVBoxLayout *layout = new QVBoxLayout(this);
	layout->addWidget(label);
	layout->addWidget(lineEdit);
	layout->addWidget(buttonBox);

	setLayout(layout);

	connect(buttonBox, SIGNAL(accepted()), this, SLOT(storeInput()));
	connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));

	Q_CHECK_PTR(&target);
	targetStore = target;  // to store the user input before closing

	lineEdit->setFocus();
}

void TargetDialog::storeInput()
{
	*targetStore = lineEdit->text();

	close();
}
