exportoofiledialog.cpp
changeset 181 bd530b01f77f
child 196 a9493dcaa306
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/exportoofiledialog.cpp	Tue Jan 24 15:09:48 2006 +0000
     1.3 @@ -0,0 +1,87 @@
     1.4 +#include <iostream>
     1.5 +
     1.6 +#include "exportoofiledialog.h"
     1.7 +
     1.8 +ExportOOFileDialog::ExportOOFileDialog():QFileDialog()
     1.9 +{
    1.10 +	init();
    1.11 +}
    1.12 +
    1.13 +ExportOOFileDialog::ExportOOFileDialog (QWidget * parent, const char* name, bool modal):QFileDialog(parent, name,modal)
    1.14 +{
    1.15 +	init();
    1.16 +}
    1.17 +
    1.18 +QString ExportOOFileDialog::selectedConfig()
    1.19 +{
    1.20 +	QStringList::Iterator itpath=configPaths.begin();
    1.21 +	QStringList::Iterator itf=filters.begin();
    1.22 +	while (itf != filters.end()) 
    1.23 +	{
    1.24 +		if (*itf==lastFilter) return *itpath;
    1.25 +		itpath++;	
    1.26 +		itf++;
    1.27 +    }
    1.28 +	qWarning ("ExportOOFileDialog::selectedConfig  No filter found!");
    1.29 +	return "";
    1.30 +}
    1.31 +
    1.32 +void ExportOOFileDialog::newConfigPath(const QString &s)
    1.33 +{
    1.34 +	lastFilter=s;
    1.35 +}
    1.36 +
    1.37 +QString ExportOOFileDialog::selectedFile()
    1.38 +{
    1.39 +	return QFileDialog::selectedFile();
    1.40 +}
    1.41 +
    1.42 +
    1.43 +void ExportOOFileDialog::addFilter(const QString &f)
    1.44 +{
    1.45 +	lastFilter=f;
    1.46 +	filters.append (f);
    1.47 +	QFileDialog::addFilter (f);
    1.48 +}
    1.49 +
    1.50 +void ExportOOFileDialog::init()
    1.51 +{
    1.52 +	QDir d;
    1.53 +	d.setPath ("/usr/share/vym/exports");
    1.54 +	scanExportConfigs(d);
    1.55 +	d.setPath (d.homeDirPath()+"/exports");
    1.56 +	scanExportConfigs(d);
    1.57 +	d.setPath ("exports");
    1.58 +	scanExportConfigs(d);
    1.59 +
    1.60 +	connect (
    1.61 +		this,SIGNAL (filterSelected(const QString&)),
    1.62 +		this, SLOT( newConfigPath(const QString &)));
    1.63 +}
    1.64 +
    1.65 +void ExportOOFileDialog::scanExportConfigs(QDir d)
    1.66 +{
    1.67 +	// Scan existing export configurations
    1.68 +	SimpleSettings set;
    1.69 +	QFile f;
    1.70 +	if (d.exists())
    1.71 +	{
    1.72 +		// Traverse files
    1.73 +		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
    1.74 +		const QFileInfoList *filelist = d.entryInfoList();
    1.75 +		QFileInfoListIterator itfile( *filelist );
    1.76 +		QFileInfo *fi;
    1.77 +
    1.78 +		while ( (fi = itfile.current()) != 0 ) 
    1.79 +		{
    1.80 +			if (fi->fileName().endsWith(".conf") )
    1.81 +			{
    1.82 +				configPaths.append (fi->absFilePath());
    1.83 +				set.clear();
    1.84 +				set.readSettings (fi->absFilePath());
    1.85 +				addFilter (set.readEntry("Name") + " (*.odp)");
    1.86 +			}		
    1.87 +			++itfile;
    1.88 +		}	
    1.89 +	}		
    1.90 +}