exportoofiledialog.cpp
author insilmaril
Tue, 24 Jan 2006 15:09:48 +0000
changeset 184 138c2cdc02fd
parent 181 bd530b01f77f
child 196 a9493dcaa306
permissions -rw-r--r--
Introduced basic export to Open Document format
insilmaril@181
     1
#include <iostream>
insilmaril@181
     2
insilmaril@181
     3
#include "exportoofiledialog.h"
insilmaril@181
     4
insilmaril@181
     5
ExportOOFileDialog::ExportOOFileDialog():QFileDialog()
insilmaril@181
     6
{
insilmaril@181
     7
	init();
insilmaril@181
     8
}
insilmaril@181
     9
insilmaril@181
    10
ExportOOFileDialog::ExportOOFileDialog (QWidget * parent, const char* name, bool modal):QFileDialog(parent, name,modal)
insilmaril@181
    11
{
insilmaril@181
    12
	init();
insilmaril@181
    13
}
insilmaril@181
    14
insilmaril@181
    15
QString ExportOOFileDialog::selectedConfig()
insilmaril@181
    16
{
insilmaril@181
    17
	QStringList::Iterator itpath=configPaths.begin();
insilmaril@181
    18
	QStringList::Iterator itf=filters.begin();
insilmaril@181
    19
	while (itf != filters.end()) 
insilmaril@181
    20
	{
insilmaril@181
    21
		if (*itf==lastFilter) return *itpath;
insilmaril@181
    22
		itpath++;	
insilmaril@181
    23
		itf++;
insilmaril@181
    24
    }
insilmaril@181
    25
	qWarning ("ExportOOFileDialog::selectedConfig  No filter found!");
insilmaril@181
    26
	return "";
insilmaril@181
    27
}
insilmaril@181
    28
insilmaril@181
    29
void ExportOOFileDialog::newConfigPath(const QString &s)
insilmaril@181
    30
{
insilmaril@181
    31
	lastFilter=s;
insilmaril@181
    32
}
insilmaril@181
    33
insilmaril@181
    34
QString ExportOOFileDialog::selectedFile()
insilmaril@181
    35
{
insilmaril@181
    36
	return QFileDialog::selectedFile();
insilmaril@181
    37
}
insilmaril@181
    38
insilmaril@181
    39
insilmaril@181
    40
void ExportOOFileDialog::addFilter(const QString &f)
insilmaril@181
    41
{
insilmaril@181
    42
	lastFilter=f;
insilmaril@181
    43
	filters.append (f);
insilmaril@181
    44
	QFileDialog::addFilter (f);
insilmaril@181
    45
}
insilmaril@181
    46
insilmaril@181
    47
void ExportOOFileDialog::init()
insilmaril@181
    48
{
insilmaril@181
    49
	QDir d;
insilmaril@181
    50
	d.setPath ("/usr/share/vym/exports");
insilmaril@181
    51
	scanExportConfigs(d);
insilmaril@181
    52
	d.setPath (d.homeDirPath()+"/exports");
insilmaril@181
    53
	scanExportConfigs(d);
insilmaril@181
    54
	d.setPath ("exports");
insilmaril@181
    55
	scanExportConfigs(d);
insilmaril@181
    56
insilmaril@181
    57
	connect (
insilmaril@181
    58
		this,SIGNAL (filterSelected(const QString&)),
insilmaril@181
    59
		this, SLOT( newConfigPath(const QString &)));
insilmaril@181
    60
}
insilmaril@181
    61
insilmaril@181
    62
void ExportOOFileDialog::scanExportConfigs(QDir d)
insilmaril@181
    63
{
insilmaril@181
    64
	// Scan existing export configurations
insilmaril@181
    65
	SimpleSettings set;
insilmaril@181
    66
	QFile f;
insilmaril@181
    67
	if (d.exists())
insilmaril@181
    68
	{
insilmaril@181
    69
		// Traverse files
insilmaril@181
    70
		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
insilmaril@181
    71
		const QFileInfoList *filelist = d.entryInfoList();
insilmaril@181
    72
		QFileInfoListIterator itfile( *filelist );
insilmaril@181
    73
		QFileInfo *fi;
insilmaril@181
    74
insilmaril@181
    75
		while ( (fi = itfile.current()) != 0 ) 
insilmaril@181
    76
		{
insilmaril@181
    77
			if (fi->fileName().endsWith(".conf") )
insilmaril@181
    78
			{
insilmaril@181
    79
				configPaths.append (fi->absFilePath());
insilmaril@181
    80
				set.clear();
insilmaril@181
    81
				set.readSettings (fi->absFilePath());
insilmaril@181
    82
				addFilter (set.readEntry("Name") + " (*.odp)");
insilmaril@181
    83
			}		
insilmaril@181
    84
			++itfile;
insilmaril@181
    85
		}	
insilmaril@181
    86
	}		
insilmaril@181
    87
}