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