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