/***************************************************************************
*   Copyright (C) 2006-2008 by Ian Reinhart Geiser                        *
*   geiseri@yahoo.com                                                     *
*                                                                         *
*   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.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#include "slideproperties.h"
#include "ui_slideproperties.h"
#include "mindmap.h"

#include <QFileDialog>

SlideProperties::SlideProperties(MindMap *mindmap, QWidget *parent)
    :QDialog(parent), m_mindmap(mindmap)
{
	m_ui = new Ui::SlideProperties;
	m_ui->setupUi(this);
	m_ui->backgroundURI->setProperty( "text", m_mindmap->getProperty("slides.background") );
	m_ui->templateURI->setProperty( "text", m_mindmap->getProperty("slides.template") );
	m_ui->outputFile->setProperty( "text", m_mindmap->getProperty("slides.output", m_mindmap->generateFilePath("pdf")) );
	m_ui->date->setProperty( "date", m_mindmap->getProperty("document.date", QDate::currentDate() ));
	m_ui->footerText->setProperty( "text", m_mindmap->getProperty("document.footer") );
}

SlideProperties::~ SlideProperties( )
{
	delete m_ui;
}

void SlideProperties::on_backgroundPicker_clicked( )
{
	QString fileName = QFileDialog::getOpenFileName(
		QApplication::activeWindow(), tr("Select an background image..."),
		m_ui->backgroundURI->text(),
		tr("Image Files (*.png)"));
	if( !fileName.isEmpty() )
		m_ui->backgroundURI->setText( fileName );
}

void SlideProperties::on_templatePicker_clicked( )
{
	QString fileName = QFileDialog::getOpenFileName(
		QApplication::activeWindow(), tr("Select a template..."),
		m_ui->templateURI->text(),
		tr("Template Files (*.template)"));
	if( !fileName.isEmpty() )
		m_ui->templateURI->setText( fileName );
}

void SlideProperties::on_outputFilePicker_clicked( )
{
	QString fileName = QFileDialog::getSaveFileName(
		QApplication::activeWindow(), tr("Select an output file..."),
		m_ui->outputFile->text(),
		tr("PDF Files (*.pdf)"));
	if( !fileName.isEmpty() )
		m_ui->outputFile->setText( fileName );
}

void SlideProperties::accept( )
{
	m_mindmap->setProperty("slides.background", m_ui->backgroundURI->property("text") );
	m_mindmap->setProperty("slides.template", m_ui->templateURI->property("text") );
	m_mindmap->setProperty("slides.output", m_ui->outputFile->property("text") );
	m_mindmap->setProperty("document.date", m_ui->date->property("date") );
	m_mindmap->setProperty("document.footer", m_ui->footerText->property("text"));
	m_mindmap->setModified(true);
	QDialog::accept();
}


