exportoofiledialog.cpp
author insilmaril
Tue, 04 Jul 2006 12:10:56 +0000
branchqt4-port
changeset 7 84f76a3876d7
parent 2 608f976aa7bb
child 9 f94317a94db1
permissions -rw-r--r--
fixed recent maps and xlinks
     1 #include <iostream>
     2 
     3 #include "exportoofiledialog.h"
     4 
     5 ExportOOFileDialog::ExportOOFileDialog():Q3FileDialog()
     6 {
     7 	init();
     8 }
     9 
    10 ExportOOFileDialog::ExportOOFileDialog (QWidget * parent, const char* name, bool modal):Q3FileDialog(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 Q3FileDialog::selectedFile();
    37 }
    38 
    39 
    40 void ExportOOFileDialog::addFilter(const QString &f)
    41 {
    42 	lastFilter=f;
    43 	filters.append (f);
    44 	Q3FileDialog::addFilter (f);
    45 }
    46 
    47 void ExportOOFileDialog::init()
    48 {
    49 	setMode( Q3FileDialog::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 dir)
    64 {
    65 	// Scan existing export configurations
    66 	SimpleSettings set;
    67 	QFile f;
    68 	if (dir.exists())
    69 	{
    70 		// Traverse files
    71         QDir dir;
    72         dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    73 
    74         QFileInfoList list = dir.entryInfoList();
    75         for (int i = 0; i < list.size(); ++i) {
    76             QFileInfo fi = list.at(i);
    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         }
    86 	}		
    87 }