exportoofiledialog.cpp
author insilmaril
Mon, 31 Jul 2006 12:13:53 +0000
changeset 361 a784c102bbed
parent 357 64819498efbf
child 365 1cc73bd7ee1f
permissions -rw-r--r--
added vym2kdebookmarks.xsl
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@357
    15
bool ExportOOFileDialog::foundConfig()
insilmaril@357
    16
{
insilmaril@357
    17
	return !filters.isEmpty();
insilmaril@357
    18
}
insilmaril@357
    19
insilmaril@181
    20
QString ExportOOFileDialog::selectedConfig()
insilmaril@181
    21
{
insilmaril@181
    22
	QStringList::Iterator itpath=configPaths.begin();
insilmaril@181
    23
	QStringList::Iterator itf=filters.begin();
insilmaril@181
    24
	while (itf != filters.end()) 
insilmaril@181
    25
	{
insilmaril@181
    26
		if (*itf==lastFilter) return *itpath;
insilmaril@181
    27
		itpath++;	
insilmaril@181
    28
		itf++;
insilmaril@181
    29
    }
insilmaril@181
    30
	qWarning ("ExportOOFileDialog::selectedConfig  No filter found!");
insilmaril@181
    31
	return "";
insilmaril@181
    32
}
insilmaril@181
    33
insilmaril@181
    34
void ExportOOFileDialog::newConfigPath(const QString &s)
insilmaril@181
    35
{
insilmaril@181
    36
	lastFilter=s;
insilmaril@181
    37
}
insilmaril@181
    38
insilmaril@181
    39
QString ExportOOFileDialog::selectedFile()
insilmaril@181
    40
{
insilmaril@181
    41
	return QFileDialog::selectedFile();
insilmaril@181
    42
}
insilmaril@181
    43
insilmaril@181
    44
insilmaril@181
    45
void ExportOOFileDialog::addFilter(const QString &f)
insilmaril@181
    46
{
insilmaril@181
    47
	lastFilter=f;
insilmaril@181
    48
	filters.append (f);
insilmaril@181
    49
	QFileDialog::addFilter (f);
insilmaril@181
    50
}
insilmaril@181
    51
insilmaril@181
    52
void ExportOOFileDialog::init()
insilmaril@181
    53
{
insilmaril@198
    54
	setMode( QFileDialog::AnyFile );
insilmaril@181
    55
	QDir d;
insilmaril@181
    56
	d.setPath ("/usr/share/vym/exports");
insilmaril@181
    57
	scanExportConfigs(d);
insilmaril@196
    58
	d.setPath (d.homeDirPath()+"/.vym/exports");
insilmaril@181
    59
	scanExportConfigs(d);
insilmaril@181
    60
	d.setPath ("exports");
insilmaril@181
    61
	scanExportConfigs(d);
insilmaril@181
    62
insilmaril@181
    63
	connect (
insilmaril@181
    64
		this,SIGNAL (filterSelected(const QString&)),
insilmaril@181
    65
		this, SLOT( newConfigPath(const QString &)));
insilmaril@181
    66
}
insilmaril@181
    67
insilmaril@181
    68
void ExportOOFileDialog::scanExportConfigs(QDir d)
insilmaril@181
    69
{
insilmaril@181
    70
	// Scan existing export configurations
insilmaril@181
    71
	SimpleSettings set;
insilmaril@181
    72
	QFile f;
insilmaril@181
    73
	if (d.exists())
insilmaril@181
    74
	{
insilmaril@181
    75
		// Traverse files
insilmaril@181
    76
		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
insilmaril@181
    77
		const QFileInfoList *filelist = d.entryInfoList();
insilmaril@181
    78
		QFileInfoListIterator itfile( *filelist );
insilmaril@181
    79
		QFileInfo *fi;
insilmaril@181
    80
insilmaril@181
    81
		while ( (fi = itfile.current()) != 0 ) 
insilmaril@181
    82
		{
insilmaril@181
    83
			if (fi->fileName().endsWith(".conf") )
insilmaril@181
    84
			{
insilmaril@181
    85
				configPaths.append (fi->absFilePath());
insilmaril@181
    86
				set.clear();
insilmaril@181
    87
				set.readSettings (fi->absFilePath());
insilmaril@181
    88
				addFilter (set.readEntry("Name") + " (*.odp)");
insilmaril@181
    89
			}		
insilmaril@181
    90
			++itfile;
insilmaril@181
    91
		}	
insilmaril@181
    92
	}		
insilmaril@181
    93
}