exportoofiledialog.cpp
author insilmaril
Tue Jan 24 15:09:48 2006 +0000 (2006-01-24)
changeset 188 90969608255c
child 196 a9493dcaa306
permissions -rw-r--r--
Introduced basic export to Open Document format
     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 	QDir d;
    50 	d.setPath ("/usr/share/vym/exports");
    51 	scanExportConfigs(d);
    52 	d.setPath (d.homeDirPath()+"/exports");
    53 	scanExportConfigs(d);
    54 	d.setPath ("exports");
    55 	scanExportConfigs(d);
    56 
    57 	connect (
    58 		this,SIGNAL (filterSelected(const QString&)),
    59 		this, SLOT( newConfigPath(const QString &)));
    60 }
    61 
    62 void ExportOOFileDialog::scanExportConfigs(QDir d)
    63 {
    64 	// Scan existing export configurations
    65 	SimpleSettings set;
    66 	QFile f;
    67 	if (d.exists())
    68 	{
    69 		// Traverse files
    70 		d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
    71 		const QFileInfoList *filelist = d.entryInfoList();
    72 		QFileInfoListIterator itfile( *filelist );
    73 		QFileInfo *fi;
    74 
    75 		while ( (fi = itfile.current()) != 0 ) 
    76 		{
    77 			if (fi->fileName().endsWith(".conf") )
    78 			{
    79 				configPaths.append (fi->absFilePath());
    80 				set.clear();
    81 				set.readSettings (fi->absFilePath());
    82 				addFilter (set.readEntry("Name") + " (*.odp)");
    83 			}		
    84 			++itfile;
    85 		}	
    86 	}		
    87 }