/*
 *  Copyright (C) 2007-2008 CMM Sigma Andrzej Chmielowiec <cmmsigma@cmmsigma.eu>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3
 *  as published by the Free Software Foundation.
 *
 *  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.
 */

#include "FileDialogWPR.h"

QString 
FileDialogWPR::getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, 
	const QString &filter, QString *selectedFilter, QFileDialog::Options options)
{
	static QString lastDir = QDir::homePath();
	QString fileName;
	
	if (dir != QString())
		lastDir = dir;
	
	fileName = QFileDialog::getOpenFileName(parent, caption, lastDir, 
		filter, selectedFilter, options);
	
	if (fileName != QString())
		lastDir = QFileInfo(fileName).dir().path();
	
	return fileName;
}

QStringList
FileDialogWPR::getOpenFileNames(QWidget *parent, const QString &caption, const QString &dir, 
	const QString &filter, QString *selectedFilter, QFileDialog::Options options)
{
	static QString lastDir = QDir::homePath();
	QStringList fileList;
	
	if (dir != QString())
		lastDir = dir;
	
	fileList = QFileDialog::getOpenFileNames(parent, caption, lastDir, 
		filter, selectedFilter, options);
	
	if ((0 < fileList.count()) && (fileList[0] != QString()))
		lastDir = QFileInfo(fileList[0]).dir().path();
	
	return fileList;
}

QString 
FileDialogWPR::getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, 
	const QString &filter, QString *selectedFilter, QFileDialog::Options options)
{
	static QString lastDir = QDir::homePath();
	QString fileName;
	
	if (dir != QString())
		lastDir = dir;
	
	fileName = QFileDialog::getSaveFileName(parent, caption, lastDir, 
		filter, selectedFilter, options);
	
	if (fileName != QString())
		lastDir = QFileInfo(fileName).dir().path();
	
	return fileName;
}

